NodeJs SDK
Source code with detailed examples can be found here.

Installation

We have first-class TypeScript support, but this library can also be used in a javascript project. We provide a useful function to prevent errors in input config variables.
npm
1
npm install @aidbox/node-server-sdk
Copied!
yarn
1
yarn add @aidbox/node-server-sdk
Copied!

Requirements

To start working with the backend application you should enter the required env variables:
Client id with basic auth grant type to work with aidbox:
AIDBOX_CLIENT_ID=
Client secret:
AIDBOX_CLIENT_SECRET=secret
Your aidbox url:
AIDBOX_URL=http://0.0.0.0:8085​
Toggle debug mode:
APP_DEBUG=false
App name to identify the application in aidbox:
APP_ID=you-business-app
Secret for use application (aidbox will use it):
APP_SECRET=secret
Backend application url (aidbox will send a request to this base url):
APP_URL=http://0.0.0.0:8090​
Port for your backend application:
APP_PORT=8090

App example

Typescript usage

Firstly, you should create a config object. By default, we use env variables but you can optionally enter process.env as an input parameter.
1
import { createConfig } from '@aidbox/node-server-sdk/lib/config';
2
​
3
const config = createConfig();
Copied!
(optional) Add your specific context helpers
1
type TContextHelpers = {
2
greet(name: string): void;
3
};
4
​
5
const contextHelpers: TContextHelpers = {
6
greet: (name: string) => {
7
console.log(`Hello, ${name}`);
8
},
9
};
Copied!
Next step is defining the manifest object. For example:
1
import { TRawManifest } from '../src/types';
2
​
3
// pass type if your define your specific context helpers
4
const manifest: TRawManifest<TContextHelpers> = {
5
resources: {
6
AccessPolicy: {},
7
},
8
entities: {},
9
operations: {
10
test: {
11
method: 'GET',
12
path: ['$test-operation'],
13
handler: async (context) => {
14
context.greet('Alice'); // your specific context helper
15
return { resource: { work: true } };
16
},
17
},
18
},
19
subscriptions: {
20
Patient: {
21
handler: () => {
22
console.log('qwerty');
23
return true;
24
},
25
},
26
},
27
};
Copied!
After you prepare the config object and define the manifest, you can run your backend application. Typescript won't let you miss any required config keys. There are additional check input parameters before the app is created:
1
import { createApp, startApp } from '@aidbox/node-server-sdk';
2
​
3
const app = createApp<TContextHelpers>(config, manifest, contextHelpers);
4
if (!app) {
5
console.error(`Unable to create app. Check config/manifest errors.`);
6
process.exit(1);
7
}
8
​
9
await startApp(app);
Copied!
Then you can go to your Aidbox. There you will find your new application in the Apps menu. To test the app, run this request in the Aidbox Rest Console:
Request
1
GET /$test-operation
Copied!
Response
1
work: true
Copied!
Last modified 6mo ago