Cloud SDK
@scenid/cloud-sdk is a Node.js library for the Scenid Cloud services. It takes care of:
- requesting and caching access tokens;
- deriving the service URLs from your service key;
- resolving source names and group names to ids (cached for five minutes);
- uniform
{ status, result }responses.
Version documented here: 1.22. Node 18+. ESM and CommonJS. No TypeScript types.
The entry point
import sdk, { initScenid } from '@scenid/cloud-sdk'
initScenid(serviceKey) // once at startup
sdk.asAdmin() // act as the app
sdk.asUser(idToken) // act as a signed-in user
sdk.Auth() // login flow and token verification
| Call | Returns | Services |
|---|---|---|
sdk.asAdmin(), alias sdk.asApp() | { Auth(), Customers(), Files(), Insights() } | machine token |
sdk.asUser(idToken) | { Customers(), Files(), Insights(), Profile() } | exchanged user token |
sdk.Auth() | the Auth helper | login flow, verify, middleware |
Every method throws sdk: call initScenid() before using the SDK if initScenid has not been called. Every call to asAdmin(), Customers(), … creates a cheap wrapper, tokens and caches are shared.
Service map
| Service | Class | Reference |
|---|---|---|
| Customers | CustomersService with Entity, Entities, OU, Person, Group, Journal | Customers |
| Insights | InsightsService with Source(name), Sources(names) | Insights |
| Files | FilesService | Files |
| Auth (admin) | AuthService with Users, UserGroups | Auth admin |
| Profile (user) | Profile | Profile |
Return values
{ status: number, result: any }
resultis the parsed JSON body, orundefinedif empty (204).- Non-2xx responses resolve, they do not throw. See Error handling.
Other exports
| Export | Description |
|---|---|
initScenid, sdk (also the default export) | Setup and facade |
SERVICES, resolveServiceUrl | Service names and URL derivation |
AuthenticationError, checkIsUser, checkIsOwner, checkIsAdmin, checkIsService, checkHasClaim, checkHasClaims, checkIsProductUser, checkIsProductAdmin, oneOf, hasResourcePermission, checkHasResourcePermission | Guards |
fromDisk, fromBase64, fromBlob, fromMultiPart | File sources |
sdk.asScript also exists, but it is only for code running inside Insights functions and cannot be used outside that context.
Not in the SDK
- Creating and configuring Insights sources (use the Insights app).
- Bulk entity creation for Customers.
- Downloading and deleting files.
- Browser usage. Keep the client secret on your server.
For those, see the REST API or the apps.