0.1.0 • Published 4 years ago
@prodclay/node-sdk v0.1.0
Node Prodclay SDK
Note: This SDK is fully compliant with TS and exports required types
Table of contents
Usage Guide
Installing SDK
npm install @prodclay/node-sdk
For those using yarn
yarn add @prodclay/node-sdk
Initialising SDK
// Import SDK initialization method as default export from `@prodclay/node-sdk`
import initAndGetProdclayInstance from "@prodclay/node-sdk";
// Call initializor method which return the
const sdkInstance = initAndGetProdclayInstance(SDKInitOptions: {
sdkKey: string;
onSDKStatusChange: (updatedSDKState) => void
})
Get control value
// simply call `getValue` over the SDK instance returned in previous step.
// `getValue` requires control as first argument, second argument is an needed object
// `params` object must be called with a default-value
// optional `referenceId` of instance can also be provided to `params`
const control: string = sdkInstance.getValue<ValueType>(controlKey: string, params: {
referenceId<optional>: string;
defaultValue: ValueType;
})
Check SDK state
// calling `getSDKStatus` returns one of the values from enum SDK_STATES (see more in API reference)
const state = sdkInstance.getSDKStatus()
API Reference
initAndGetProdclayInstance
Function to initialize sdk with required auth credentials
(SDKInitOptions) => ProdclaySDK
SDK_STATES
Enum to compare sdk's current state against
enum SDK_STATES {
READY = 'READY',
INITIALIZING = 'INITIALIZING',
FAILED_INIT = 'FAILED_INIT',
FAILED_SYNC = 'FAILED_SYNC',
}
class ProdclaySDK
Shape of sdk Instance to determine the actions available on sdk
interface ProdclaySDK {
readonly getValue: <ValueType>(
controlKey: string,
options: { referenceId?: string; defaultValue: ValueType }
) => ValueType;
readonly getSDKStatus: () => SDK_STATES;
}
Note: TS users can use `ValueType` generix on `getValue` method to type-safe returned value
class SDKInitOptions
{
sdkKey: string; // Copied from Prodclay Studio
onSDKStatusChange?: (updatedSDKState) => void // callback listener
}
sdkKey
is a required field