@inploi/sdk
TypeScript icon, indicating that this package has built-in type declarations

1.14.4 • Public • Published

@inploi/sdk

This package contains the core functionality for the inploi SDK.

Installation

npm install @inploi/sdk

Usage

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',
});

Plugins

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,
	};
});

External dependencies

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,
    };
  });

Using plugins

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();

Readme

Keywords

none

Package Sidebar

Install

npm i @inploi/sdk

Weekly Downloads

253

Version

1.14.4

License

MIT

Unpacked Size

73.5 kB

Total Files

9

Last publish

Collaborators

  • fredericoo
  • alexhansonsmith