# Publishing

The library must be available in two different locations:
* `npm registry`
* `CDN`

Applications will always get their instance from the `npm registry`. Then, the dynamic loading mechanism will download a `patch-compatible` version, according to [Semantic versioning rules](https://semver.org/) from the CDN.


### Publishing to npm

To make the library available in an `npm` repository, follow next steps:

1) update the version in `package.json`
2) run `npm run build`, to create the target files. It will appear in the `lib` folder
3) run `npm publish` to publish the package to the npm repository

> :warning: make sure you run `npm run build` **after** updating the `package.json version`. Otherwise, the logs sent by the library will contain an erroneous version number

Some useful command regarding `npm` usage:
* Check current user: `npm whoami`
* If not logged: `npm login`
* Check current configured `npm registry`: `npm config get registry`

### Publishing to CDN

To publish the target files to the CDN, just add them to the repository https://github.com/causalfoundry/cdn. There, there will be a Github Action that copy the whole repository into an Azure Static Page, available in: https://cdn.causalfoundry.ai

It is also required to update the `manifest.json` file, which has this format:

```js
{
    "lastUpdate":1124134,
    "files":[
        "sdk-1.0.0-beta.7.9.4.js",
        "sdk-1.0.0-beta.7.9.11.js"
    ]
}
```

Currently, this step is performed automatically by a Github Action in the `js-sdk` repository: https://github.com/causalfoundry/js-sdk/blob/develop/.github/workflows/cdn-publisher.yml

[Back](./Readme.md)