Skip to main content

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
CallReturnsServices
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 helperlogin 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​

ServiceClassReference
CustomersCustomersService with Entity, Entities, OU, Person, Group, JournalCustomers
InsightsInsightsService with Source(name), Sources(names)Insights
FilesFilesServiceFiles
Auth (admin)AuthService with Users, UserGroupsAuth admin
Profile (user)ProfileProfile

Return values​

{ status: number, result: any }
  • result is the parsed JSON body, or undefined if empty (204).
  • Non-2xx responses resolve, they do not throw. See Error handling.

Other exports​

ExportDescription
initScenid, sdk (also the default export)Setup and facade
SERVICES, resolveServiceUrlService names and URL derivation
AuthenticationError, checkIsUser, checkIsOwner, checkIsAdmin, checkIsService, checkHasClaim, checkHasClaims, checkIsProductUser, checkIsProductAdmin, oneOf, hasResourcePermission, checkHasResourcePermissionGuards
fromDisk, fromBase64, fromBlob, fromMultiPartFile 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.