The SmoothIntegration Node library provides convenient access to the SmoothIntegration API from applications written in server-side JavaScript.
By https://smooth-integration.com
See the @smooth-integration/sdk-node
API docs for Node.js.
Node.js version 18 or higher, or Deno version 1.0.0 or higher.
Install the package with:
npm install @smooth-integration/sdk-node
yarn add @smooth-integration/sdk-node
pnpm install @smooth-integration/sdk-node
deno add jsr:@smooth-integration/sdk-node
This library is dependency free.
If you require a lower version of Node.js, you will need to provide a shim for fetch
.
The package needs to be configured with your client id and client secret, which are available in the SmoothIntegration Dashboard. Require it with values:
const client = require('@smooth-integration/sdk-node')({
clientId: '<your_client_id>',
clientSecret: '<your_client_secret>',
});
client.cdc
.get({
structure: 'normalised',
})
.then((events) => console.log(events))
.catch((error) => console.error(error));
Or using ES modules and async
/await
:
import Client from '@smooth-integration/sdk-node';
const client = new Client({
clientId: '<your_client_id>',
clientSecret: '<your_client_secret>',
});
const events = await client.cdc.get({
structure: 'normalised',
});
console.log(events);
import Client, { CDCConfig, Event } from '@smooth-integration/sdk-node';
const client: Client = new Client({
clientId: '<your_client_id>',
clientSecret: '<your_client_secret>',
});
const logEvents = async () => {
const config: CDCConfig = {
structure: 'normalised',
};
const events: Event[] = await client.cdc.get(config);
console.log(events);
};
logEvents();
SmoothIntegration is available on JSR, so you can import without a npm specifier.
import Client from '@smooth-integration/sdk-node';
If you want to receive new events as they come in, we recommend to use the built-in client.cdc.stream
rather than
polling using client.cdc.get
yourself.
import Client, { Event } from '@smooth-integration/sdk-node';
const client: Client = new Client({
clientId: '<your_client_id>',
clientSecret: '<your_client_secret>',
});
const onEvent = async (event: Event): Promise<void> => {
console.log('Received event', event.event_id, event.document_id, event);
};
client.cdc.stream({
onEvent: onEvent,
structure: 'normalised',
onFailure: 'log',
});
We've provided some examples in the examples
directory.
To run them, you'll need to set your client id and client secret.
Additionally, you will also need to create a DataSource in the SmoothIntegration dashboard and set the
dataSourceId
in the examples.
Example TS | Description |
---|---|
Minimal TS | Minimal example using NodeJS & TypeScript. |
Minimal Deno | Minimal example using Deno & TypeScript |
Development is done in NodeJS 23 using PNPM. Alternative environments may work, but are not tested. If you do not have PNPM installed, https://pnpm.io/installation.
Run all tests:
$ pnpm install
$ pnpm test