This package contains the core functionality for the inploi SDK.
npm install @inploi/sdk
You can initialise the SDK by calling initialiseInploiSdk
with the following options:
import { initialiseInploiSdk } from '@inploi/sdk';
const sdk = initialiseInploiSdk({
publishableKey: 'your-publishable-key',
env: 'sandbox',
});
You can write custom plugins via the createPlugin
function. The plugin will have two dependencies injected: a logger
service and a an apiClient
service, which can be used to make requests to the inploi API.
Example:
export const myCounterPlugin = createPlugin(({ logger, apiClient }) => {
let count = 0;
logger.info('myCounterPlugin initialised');
return {
add: () => {
count++;
logger.info(`count is now ${count}`);
},
getCount: () => count,
};
});
If your plugin requires external dependencies, you may want to wrap the createPlugin
function with whatever it takes, to then generate a function that returns a plugin:
import { createPlugin } from '@inploi/sdk';
type CounterExternalDeps = {onUpdate: (newCounter: number) => void};
export const myCounterPlugin = ({onUpdate}: CounterExternalDeps) =>
createPlugin(({ logger, apiClient }) => {
let count = 0;
logger.info('myCounterPlugin initialised');
return {
add: () => {
count++;
logger.info(`count is now ${count}`);
onUpdate(count);
},
getCount: () => count,
};
});
Users of the SDK may invoke sdk.registerPlugin
with a plugin to register it. The plugin will be initialised with the dependencies it requires, and the returned object will be returned to the user.
const sdk = initialiseInploiSdk({
publishableKey: 'your-publishable-key',
env: 'sandbox',
});
const mySimplePlugin = sdk.registerPlugin(mySimplePlugin);
const myCounterPlugin = sdk.registerPlugin(myPluginWithDeps({ onUpdate: newCounter => console.log(newCounter) }));
myCounterPlugin.add();