npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chec/integration-configuration-sdk

v0.0.8

Published

This SDK is available to help build custom configuration apps for integrations that work with Commerce.js infrastructure and appear within the Chec Dashboard.

Downloads

12

Readme

Integration Configuration App SDK

This SDK is available to help build custom configuration apps for integrations that work with Commerce.js infrastructure and appear within the Chec Dashboard.

Installation

yarn add @chec/integration-configuration-sdk

Usage

There are two options for controlling the configuration of an integration. You can either choose to create a completely custom web app that will appear within the Chec Dashboard (the "frame" option), or you can dynamically update the form schema of the integration template, and react to input and events triggered by the user (the "controlled" option).

Establishing a connection to the Chec Dashboard

As your app will be brought in and shown during a user session in the Chec Dashboard, the app will need to establish a connection to the dashboard:

import { createSDK, ConfigSDK } from '@chec/integration-configuration-sdk';

createSDK().then((sdk: ConfigSDK) => {
  // Typescript is shown, but you can remove the references to `ConfigSDK` to convert to native JS
})

Next, you will need to decide how you will influence the configuration screen by choosing one of the options detailed above.

"Controlled" option

This option does not require your app to product any user interface. Instead, you can use the SDK to update the form schema that the Chec Dashboard uses to display a form:

import { createSDK, SchemaFieldTypes } from '@chec/integration-configuration-sdk';

(async () => {
  const sdk = await createSDK();

  sdk.setSchema([
    {
      key: 'name',
      type: SchemaFieldTypes.ShortText,
      label: 'Your name',
    },
  ]);
})();

When the configuration screen renders in the Chec Dashboard, a form will display that matches the schema set by your app. As the user fills in the form, the integration config is updated as usual.

Watching for events

You can register an event handler that is called when the configuration changes:

import { createSDK } from '@chec/integration-configuration-sdk';

(async () => {
  const sdk = await createSDK();

  sdk.onConfigUpdate((config: object) => {
    console.log(config);
  });
})();

You can render buttons and watch for clicks:

import { createSDK, SchemaFieldTypes } from '@chec/integration-configuration-sdk';

(async () => {
  const sdk = await createSDK();

  sdk.setSchema([
    {
      key: 'my_button',
      type: SchemaFieldTypes.Button,
      label: 'Click me',
    },
  ]);

  sdk.on('click', 'my_button', () => {
    console.log('Clicked!');
  });
})();

You can also set config attributes directly using setConfig. Configuration set this way is merged with existing configuration.

import { createSDK } from '@chec/integration-configuration-sdk';

(async () => {
  const sdk = await createSDK();

  sdk.setConfig({
    my_custom_option: 'Hello world!',
  });
})();

Using typescript to ensure form schema matches configuration

This SDK provides types for form schema to help create valid form schemas for the Chec Dashboard. Additionally, you can provide a type definition for your configuration to perform type checking on the schema to ensure it matches the configuration you're expecting. For example, say you want to configure your integration with the following config:

export default interface MyIntegrationConfiguration {
  customerMessage: string
}

You may choose to create this in it's own file at the root of the project so it can be shared by the configuration app and the integration, that will have access to the config with (await context.integration()).config.

Then you can create a schema like so:

import { Schema, SchemaFieldTypes } from '@chec/integration-configuration-sdk';
import MyIntegrationConfiguration from '../config';

const schema: Schema<MyIntegrationConfiguration> = [
  {
    key: 'customerMessage',
    label: 'Message to display to the customer',
    type: SchemaFieldTypes.ShortText,
  }
];

Typescript with throw an error if the value for key does not exist in your configuration interface, avoiding potential typos and mistakes. Additionally, you can ensure the schema matches your configuration only when you set it:

import { createSDK } from '@chec/integration-configuration-sdk';
import MyIntegrationConfiguration from '../config';

(async () => {
  const sdk = await createSDK<MyIntegrationConfiguration>();

  sdk.setSchema([
    {
      key: 'customerMessage',
      label: 'Message to display to the customer',
      type: SchemaFieldTypes.ShortText,
    }
  ]);
})();

"Frame" option

You can build a custom UI to configure your app, and set the resulting configuration using the sdk.setConfig API detailed above. The Chec dashboard will render your app in the configuration panel, even when using the "controlled" option, but your app is hidden until the dashboard knows the height of the content that your app renders. You can report the height of your app using the SDK, or turn on the automatic height detection system:

(async () => {
  document.body.innerText = 'Hello world!';

  const sdk = await createSDK();

  sdk.setHeight(20); // In pixels
  // OR
  sdk.enableAutoResize();
})();

The UI library used by the Chec dashboard is open source and available for use by your app if you're building with Vue:

https://github.com/chec/ui-library - Storybook (demo site)