Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chec/integration-configuration-sdk

Package Overview
Dependencies
Maintainers
6
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chec/integration-configuration-sdk - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

24

index.js

@@ -39,9 +39,6 @@ import Postmate from 'postmate';

this.configWatchers = [];
// Fill in some defaults provided by the dashboard through Postmate. The ts-ignores are here as the Postmate types
// provided by the community don't include a definition for `childApi.model`, maybe because it's not completely
// clear if this is intended to be a public API by Postmate.
// @ts-ignore
// Fill in some defaults provided by the dashboard through Postmate.
this.config = childApi.model.config || {};
// @ts-ignore
this.editMode = Boolean(childApi.model.editMode);
this.template = childApi.model.code;
this.eventBus.pushHandler((event) => {

@@ -68,3 +65,5 @@ if (event.event !== 'set-config') {

const rect = document.body.getBoundingClientRect();
return rect.y + rect.height;
// Assume top margins match bottom margins. This isn't ideal but getting the real height of the contents of the
// document body is very non-trivial
return (2 * rect.y) + rect.height;
};

@@ -135,2 +134,10 @@ // Create a resize observer to watch changes in body height

}
/**
* Indicate that the integration is savable in the current state.
*
* @param savable
*/
setSavable(savable) {
this.parent.emit('set-savable', savable);
}
}

@@ -141,3 +148,3 @@ /**

*/
export async function createSDK() {
export async function createSDK(savable = true) {
// Create an event bus to handle events

@@ -149,4 +156,5 @@ const bus = new EventBus();

bus.trigger(event);
}
},
savable,
}), bus);
}

@@ -8,3 +8,2 @@ import Postmate, { ChildAPI } from 'postmate';

/**

@@ -38,25 +37,52 @@ * Creates a type from a config type that removes any keys that don't have object type definitions, essentially just

export interface SchemaItem<T = Config> {
default?: string|boolean|number|Array<string>
interface KeyableSchemaItem<T = Config> {
key: KeysOfUnion<T>
}
interface InputSchemaItem<InputType, T = Config> extends KeyableSchemaItem<T> {
default?: InputType
description?: string
disabled?: boolean
key: KeysOfUnion<T>
label: string
required?: boolean
type: SchemaFieldTypes
}
export interface TextSchemaItem<T = Config> extends InputSchemaItem<string, T> {
type: SchemaFieldTypes.ShortText | SchemaFieldTypes.LongText | SchemaFieldTypes.Wysiwyg | SchemaFieldTypes.ApiKey | SchemaFieldTypes.Password
}
export interface NumberSchemaItem<T = Config> extends InputSchemaItem<number, T> {
type: SchemaFieldTypes.Number,
}
export interface BooleanSchemaItem<T = Config> extends InputSchemaItem<boolean, T> {
type: SchemaFieldTypes.Boolean,
}
export interface HtmlSchemaItem<T = Config> {
type: SchemaFieldTypes.Html
content: string
type: SchemaFieldTypes.Html
}
export interface SelectSchemaItem<T = Config> extends SchemaItem<T> {
export interface ButtonSchemaItem {
type: SchemaFieldTypes.Button
// Note that "key" here does not reference a key in config like other items, but is given in an event payload
key: string
label: string
disabled?: boolean
}
export interface LinkSchemaItem {
type: SchemaFieldTypes.Link
label: string
href: string
}
export interface SelectSchemaItem<T = Config> extends InputSchemaItem<string | Array<string>, T> {
type: SchemaFieldTypes.Select,
multiselect?: boolean
options: Array<{ value: string, label: string }>
type: SchemaFieldTypes.Select,
}
export interface SubSchemaItem<T = Config> {
key: KeysOfUnion<T>
export interface SubSchemaItem<T = Config> extends KeyableSchemaItem<T> {
label: string

@@ -67,4 +93,7 @@ description?: string

export type Schema<T = Config> = Array<SchemaItem<T>|SelectSchemaItem<T>|HtmlSchemaItem<T>|SubSchemaItem<T>>
export type UsableSchemaItems = TextSchemaItem | NumberSchemaItem | BooleanSchemaItem | HtmlSchemaItem
| ButtonSchemaItem | LinkSchemaItem | SelectSchemaItem | SubSchemaItem;
export type Schema<T = Config> = Array<UsableSchemaItems>
/**

@@ -75,3 +104,3 @@ * Represents an event relayed to the SDK from the dashboard

event: string,
field: SchemaItem<T>|null,
field: KeyableSchemaItem<T> | ButtonSchemaItem | null,
payload: any,

@@ -110,2 +139,14 @@ }

/**
* Extends the types provided by the 3rd party type definitions as they don't include a definition for `childApi.model`,
* maybe because it's not completely clear if this is intended to be a public API by Postmate.
*/
interface ModelledChildApi<T> extends ChildAPI {
model: {
config?: T
editMode: boolean,
code: string,
}
}
/**
* Represents a connection with the Chec dashboard when this app is rendered within the Chec dashboard, and provides

@@ -115,3 +156,3 @@ * API to community with the dashboard.

export class ConfigSDK<T = Config> {
parent: ChildAPI;
parent: ModelledChildApi<T>;
eventBus: EventBus;

@@ -121,4 +162,5 @@ config: T;

editMode: boolean
template: string
constructor(childApi: ChildAPI, eventBus: EventBus) {
constructor(childApi: ModelledChildApi<T>, eventBus: EventBus) {
this.parent = childApi;

@@ -128,9 +170,6 @@ this.eventBus = eventBus;

// Fill in some defaults provided by the dashboard through Postmate. The ts-ignores are here as the Postmate types
// provided by the community don't include a definition for `childApi.model`, maybe because it's not completely
// clear if this is intended to be a public API by Postmate.
// @ts-ignore
this.config = childApi.model.config || {};
// @ts-ignore
// Fill in some defaults provided by the dashboard through Postmate.
this.config = childApi.model.config || {} as T;
this.editMode = Boolean(childApi.model.editMode);
this.template = childApi.model.code;

@@ -162,3 +201,5 @@ this.eventBus.pushHandler((event: DashboardEvent) => {

const rect = document.body.getBoundingClientRect();
return rect.y + rect.height;
// Assume top margins match bottom margins. This isn't ideal but getting the real height of the contents of the
// document body is very non-trivial
return (2 * rect.y) + rect.height;
}

@@ -227,3 +268,3 @@

*/
setConfig(config: T) {
setConfig(config: T): void {
this.parent.emit('save', config);

@@ -238,5 +279,14 @@ }

*/
setSchema<OverrideType extends T>(schema: Schema<OverrideType>) {
setSchema<OverrideType extends T>(schema: Schema<OverrideType>): void {
this.parent.emit('set-schema', schema);
}
/**
* Indicate that the integration is savable in the current state.
*
* @param savable
*/
setSavable(savable: boolean): void {
this.parent.emit('set-savable', savable);
}
}

@@ -248,3 +298,3 @@

*/
export async function createSDK<T = Config>(): Promise<ConfigSDK<T>> {
export async function createSDK<T = Config>(savable: boolean = true): Promise<ConfigSDK<T>> {
// Create an event bus to handle events

@@ -258,6 +308,7 @@ const bus = new EventBus();

bus.trigger(event);
}
}),
},
savable,
}) as ModelledChildApi<T>,
bus
);
}
{
"name": "@chec/integration-configuration-sdk",
"repository": "https://github.com/chec/integration-configuration-sdk",
"version": "0.0.7",
"version": "0.0.8",
"main": "index.js",

@@ -6,0 +6,0 @@ "license": "BSD-3-Clause",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc