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

@integration-app/sdk

Package Overview
Dependencies
Maintainers
3
Versions
444
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@integration-app/sdk - npm Package Compare versions

Comparing version 0.1.17 to 0.1.18

.editorconfig

9

data-composer.d.ts

@@ -0,1 +1,2 @@

import { JSONSchema } from './json-schema';
export declare enum DataLocatorStepType {

@@ -61,1 +62,9 @@ OBJECT_PROPERTY = "object_property",

export declare function makeRecipeValue(recipe: DataComposerRecipe): any;
export declare function getSchemaByLocator(schema: any, locator: DataLocator): any;
export declare function makeSchemaForLocator(locator: DataLocator, locatorSchema: JSONSchema): any;
interface SchemaStep {
schema: any;
title?: string;
}
export declare function walkSchema(schema: any, locator: any): SchemaStep[];
export {};

122

data-composer.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeRecipeValue = exports.getRecipe = exports.isRecipe = exports.DataComposerRecipeArray = exports.DataComposerRecipeObject = exports.DataComposerRecipeLiteral = exports.DataComposerRecipePlain = exports.DataComposerRecipeRef = exports.DataComposerRecipeBase = exports.DataComposerRecipeType = exports.DataLocatorAnyOfOption = exports.DataLocatorCurrentArrayItem = exports.DataLocatorArrayItem = exports.DataLocatorObjectProperty = exports.DataLocatorStep = exports.DataLocatorStepType = void 0;
exports.walkSchema = exports.makeSchemaForLocator = exports.getSchemaByLocator = exports.makeRecipeValue = exports.getRecipe = exports.isRecipe = exports.DataComposerRecipeArray = exports.DataComposerRecipeObject = exports.DataComposerRecipeLiteral = exports.DataComposerRecipePlain = exports.DataComposerRecipeRef = exports.DataComposerRecipeBase = exports.DataComposerRecipeType = exports.DataLocatorAnyOfOption = exports.DataLocatorCurrentArrayItem = exports.DataLocatorArrayItem = exports.DataLocatorObjectProperty = exports.DataLocatorStep = exports.DataLocatorStepType = void 0;
const json_schema_1 = require("./json-schema");
var DataLocatorStepType;

@@ -111,2 +112,121 @@ (function (DataLocatorStepType) {

exports.makeRecipeValue = makeRecipeValue;
function getSchemaByLocator(schema, locator) {
if (schema) {
const schemaSteps = walkSchema(schema, locator);
if (schemaSteps) {
if (schemaSteps.length > 0) {
return schemaSteps[schemaSteps.length - 1].schema;
}
else {
return schema;
}
}
else {
return undefined;
}
}
else {
return undefined;
}
}
exports.getSchemaByLocator = getSchemaByLocator;
function makeSchemaForLocator(locator, locatorSchema) {
const schema = {};
let curSchema = schema;
for (const locatorStep of locator) {
if (locatorStep.type == DataLocatorStepType.OBJECT_PROPERTY) {
curSchema.type = json_schema_1.JSONSchemaType.Object;
const propertyName = locatorStep
.propertyName;
curSchema.properties = {
[propertyName]: {},
};
curSchema = curSchema.properties[propertyName];
}
else if (locatorStep.type == DataLocatorStepType.ARRAY_ITEM ||
locatorStep.type == DataLocatorStepType.CURRENT_ARRAY_ITEM) {
curSchema.type = json_schema_1.JSONSchemaType.Array;
curSchema.items = {};
curSchema = curSchema.items;
}
else if (locatorStep.type == DataLocatorStepType.ANY_OF_OPTION) {
curSchema.anyOf = [{}];
curSchema = curSchema.anyOf[0];
}
else {
throw new Error(`Unexpected locator step type: ${locatorStep.type}`);
}
}
for (const [key, value] of Object.entries(locatorSchema !== null && locatorSchema !== void 0 ? locatorSchema : {})) {
curSchema[key] = value;
}
return schema;
}
exports.makeSchemaForLocator = makeSchemaForLocator;
function walkSchema(schema, locator) {
const schemaSteps = [];
let curSchema = schema;
function reportError(err) {
console.error(err, schema, locator);
throw new Error(err);
}
for (let idx = 0; idx < locator.length; ++idx) {
const schemaStep = {};
const step = locator[idx];
let defaultTitle;
if (!curSchema) {
reportError(`Trying to use locator ${locator.type} on an empty schema`);
}
if (step.type == DataLocatorStepType.OBJECT_PROPERTY) {
if (curSchema.type == 'object') {
curSchema =
curSchema.properties[step.propertyName];
defaultTitle = step.propertyName;
}
else {
reportError(`Trying to use OBJECT_PROPERTY locator step on schema with type ${curSchema.type}`);
}
}
else if (step.type == DataLocatorStepType.ARRAY_ITEM) {
if (curSchema.type == 'array') {
curSchema = curSchema.items;
defaultTitle = `Item #${step.index + 1}`;
}
else {
reportError(`Trying to use ARRAY_ITEM locator step on schema with type ${curSchema.type}`);
}
}
else if (step.type == DataLocatorStepType.CURRENT_ARRAY_ITEM) {
if (curSchema.type == 'array') {
curSchema = curSchema.items;
defaultTitle = 'Current Item';
}
else {
reportError(`Trying to use CURRENT_ARRAY_ITEM locator step on schema with type ${curSchema.type}`);
}
}
else if (step.type == DataLocatorStepType.ANY_OF_OPTION) {
if (curSchema.anyOf) {
const index = step.index;
if (curSchema.anyOf.length > index) {
curSchema = curSchema.anyOf[index];
}
else {
reportError('Index of ANY_OF_OPTION data locator is out of bounds');
}
}
else {
reportError('Trying to use ANY_OF_OPTION locator step on schema without anyOf');
}
}
if (!curSchema) {
return undefined;
}
schemaStep.schema = JSON.parse(JSON.stringify(curSchema));
schemaStep.title = schemaStep.schema.title || defaultTitle;
schemaSteps.push(schemaStep);
}
return schemaSteps;
}
exports.walkSchema = walkSchema;
//# sourceMappingURL=data-composer.js.map

3

endpoint-data-response.d.ts

@@ -11,4 +11,3 @@ import { JSONSchema } from './json-schema';

payload?: any;
inputSchema: JSONSchema;
input?: any;
inputSchema?: JSONSchema;
}

@@ -15,0 +14,0 @@ export declare class DataLinksResponse {

@@ -1,2 +0,2 @@

export declare enum ValueType {
export declare enum JSONSchemaType {
Null = "null",

@@ -11,3 +11,3 @@ Boolean = "boolean",

export declare type JSONSchema = {
type?: ValueType | ValueType[];
type?: JSONSchemaType | JSONSchemaType[];
items?: JSONSchema;

@@ -23,1 +23,2 @@ maxItems?: number;

};
export declare function schemaDiff(first: JSONSchema, second: JSONSchema): JSONSchema;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValueType = void 0;
var ValueType;
(function (ValueType) {
ValueType["Null"] = "null";
ValueType["Boolean"] = "boolean";
ValueType["Integer"] = "integer";
ValueType["Number"] = "number";
ValueType["String"] = "string";
ValueType["Object"] = "object";
ValueType["Array"] = "array";
})(ValueType = exports.ValueType || (exports.ValueType = {}));
exports.schemaDiff = exports.JSONSchemaType = void 0;
var JSONSchemaType;
(function (JSONSchemaType) {
JSONSchemaType["Null"] = "null";
JSONSchemaType["Boolean"] = "boolean";
JSONSchemaType["Integer"] = "integer";
JSONSchemaType["Number"] = "number";
JSONSchemaType["String"] = "string";
JSONSchemaType["Object"] = "object";
JSONSchemaType["Array"] = "array";
})(JSONSchemaType = exports.JSONSchemaType || (exports.JSONSchemaType = {}));
function schemaDiff(first, second) {
if (!first) {
return null;
}
else if (first.type == JSONSchemaType.Object && first.properties) {
if ((second === null || second === void 0 ? void 0 : second.type) == JSONSchemaType.Object && second.properties) {
const diff = {
type: JSONSchemaType.Object,
properties: {},
};
Object.keys(first.properties).forEach((key) => {
const keyDiff = schemaDiff(first.properties[key], second.properties[key]);
if (keyDiff) {
diff.properties[key] = keyDiff;
}
});
return Object.keys(diff.properties).length > 0 ? diff : null;
}
else {
return first;
}
}
else if (first.type == JSONSchemaType.Array && first.items) {
if ((second === null || second === void 0 ? void 0 : second.type) == JSONSchemaType.Array && second.items) {
const itemsDiff = schemaDiff(first.items, second.items);
if (itemsDiff) {
return {
type: JSONSchemaType.Array,
items: itemsDiff,
};
}
else {
return null;
}
}
else {
return first;
}
}
else {
if (second) {
return null;
}
else {
return first;
}
}
}
exports.schemaDiff = schemaDiff;
//# sourceMappingURL=json-schema.js.map
{
"name": "@integration-app/sdk",
"version": "0.1.17",
"version": "0.1.18",
"description": "JavaScript SDK for Integration.app",

@@ -9,13 +9,12 @@ "main": "index.js",

"build": "npm run cleanup && npm run build:compile && npm run build:bundle",
"cleanup": "rm *.js.map && rm *.d.ts && find . -type f -name \"*.js\" -depth 1 -not -name \"rollup.config.js\" -not -name \".eslintrc.js\" -delete",
"cleanup": "rm -f *.js.map && rm -f *.d.ts && find . -type f -name \"*.js\" -depth 1 -not -name \"rollup.config.js\" -not -name \".eslintrc.js\" -delete",
"build:compile": "tsc",
"build:bundle": "rollup -c rollup.config.js",
"watch": "tsc --watch"
"watch": "tsc --watch",
"test": "jest",
"test:watch": "jest --watch"
},
"devDependencies": {
"@types/insert-css": "^2.0.0",
"rollup": "^2.52.8",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^4.29.1",

@@ -27,3 +26,9 @@ "@typescript-eslint/parser": "^4.29.1",

"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.3.1",
"prettier": "^2.3.2",
"rollup": "^2.52.8",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"ts-jest": "^27.0.7",
"ts-node": "^10.2.0",

@@ -39,3 +44,20 @@ "tsconfig-paths": "^3.10.1",

"pusher-js": "^7.0.3"
},
"jest": {
"moduleFileExtensions": [
"ts",
"json",
"js"
],
"rootDir": "src",
"testRegex": ".*\\.test\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "./coverage",
"testEnvironment": "node"
}
}

@@ -45,2 +45,3 @@ import Pusher, { Channel } from 'pusher-js'

export class IntegrationEngineClient {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore no-unused-variables

@@ -47,0 +48,0 @@ private initialized = false

@@ -0,1 +1,3 @@

import { JSONSchema, JSONSchemaType } from './json-schema'
export enum DataLocatorStepType {

@@ -109,1 +111,147 @@ OBJECT_PROPERTY = 'object_property', // Points to a property inside `object` schema

}
/*
Extract sub-schema that pointer points at.
*/
export function getSchemaByLocator(schema: any, locator: DataLocator): any {
if (schema) {
const schemaSteps = walkSchema(schema, locator)
if (schemaSteps) {
if (schemaSteps.length > 0) {
return schemaSteps[schemaSteps.length - 1].schema
} else {
return schema
}
} else {
return undefined
}
} else {
return undefined
}
}
/**
* Returns minimal JSONSchema that contains `locatorSchema` at a given locator position.
* For example, for locator '$.name' and locatorSchema `{type: 'string'}
* it will return
* {
* type: 'object',
* properties: {
* name: {type: 'string'}
* }
* }
* @param locator
*/
export function makeSchemaForLocator(
locator: DataLocator,
locatorSchema: JSONSchema,
): any {
const schema = {} as JSONSchema
let curSchema = schema
for (const locatorStep of locator) {
if (locatorStep.type == DataLocatorStepType.OBJECT_PROPERTY) {
curSchema.type = JSONSchemaType.Object
const propertyName = (locatorStep as DataLocatorObjectProperty)
.propertyName
curSchema.properties = {
[propertyName]: {},
}
curSchema = curSchema.properties[propertyName]
} else if (
locatorStep.type == DataLocatorStepType.ARRAY_ITEM ||
locatorStep.type == DataLocatorStepType.CURRENT_ARRAY_ITEM
) {
curSchema.type = JSONSchemaType.Array
curSchema.items = {}
curSchema = curSchema.items
} else if (locatorStep.type == DataLocatorStepType.ANY_OF_OPTION) {
curSchema.anyOf = [{}]
curSchema = curSchema.anyOf[0]
} else {
throw new Error(`Unexpected locator step type: ${locatorStep.type}`)
}
}
// Put locatorSchema into the current schema placeholder
for (const [key, value] of Object.entries(locatorSchema ?? {})) {
curSchema[key] = value
}
return schema
}
interface SchemaStep {
schema: any
title?: string
}
export function walkSchema(schema, locator): SchemaStep[] {
const schemaSteps: SchemaStep[] = []
let curSchema = schema
function reportError(err) {
console.error(err, schema, locator)
throw new Error(err)
}
for (let idx = 0; idx < locator.length; ++idx) {
const schemaStep = {} as SchemaStep
const step = locator[idx]
let defaultTitle
if (!curSchema) {
reportError(`Trying to use locator ${locator.type} on an empty schema`)
}
if (step.type == DataLocatorStepType.OBJECT_PROPERTY) {
if (curSchema.type == 'object') {
curSchema =
curSchema.properties[(step as DataLocatorObjectProperty).propertyName]
defaultTitle = step.propertyName
} else {
reportError(
`Trying to use OBJECT_PROPERTY locator step on schema with type ${curSchema.type}`,
)
}
} else if (step.type == DataLocatorStepType.ARRAY_ITEM) {
if (curSchema.type == 'array') {
curSchema = curSchema.items
defaultTitle = `Item #${step.index + 1}`
} else {
reportError(
`Trying to use ARRAY_ITEM locator step on schema with type ${curSchema.type}`,
)
}
} else if (step.type == DataLocatorStepType.CURRENT_ARRAY_ITEM) {
if (curSchema.type == 'array') {
curSchema = curSchema.items
defaultTitle = 'Current Item'
} else {
reportError(
`Trying to use CURRENT_ARRAY_ITEM locator step on schema with type ${curSchema.type}`,
)
}
} else if (step.type == DataLocatorStepType.ANY_OF_OPTION) {
if (curSchema.anyOf) {
const index = (step as DataLocatorAnyOfOption).index
if (curSchema.anyOf.length > index) {
curSchema = curSchema.anyOf[index]
} else {
reportError('Index of ANY_OF_OPTION data locator is out of bounds')
}
} else {
reportError(
'Trying to use ANY_OF_OPTION locator step on schema without anyOf',
)
}
}
if (!curSchema) {
// This locator is not pointing anywhere - return empty steps
return undefined
}
schemaStep.schema = JSON.parse(JSON.stringify(curSchema))
schemaStep.title = schemaStep.schema.title || defaultTitle
schemaSteps.push(schemaStep)
}
return schemaSteps
}

@@ -30,11 +30,8 @@ import { JSONSchema } from './json-schema'

// Value that may include $compose keywords.
// Takes input matching `inputSchema`.
// If value is empty, the input data will be returned.
// Can use Data Composer recipes inside using variables
// described by `inputSchema`.
payload?: any
// Schema for data the recipe needs to work.
inputSchema: JSONSchema
// Current value of the parameters
input?: any
// Schema for variables used in the payload.
inputSchema?: JSONSchema
}

@@ -41,0 +38,0 @@

@@ -1,2 +0,2 @@

export enum ValueType {
export enum JSONSchemaType {
Null = 'null',

@@ -12,3 +12,3 @@ Boolean = 'boolean',

export type JSONSchema = {
type?: ValueType | ValueType[]
type?: JSONSchemaType | JSONSchemaType[]
items?: JSONSchema

@@ -25,1 +25,58 @@ maxItems?: number // Maximum observed number of items in an array

}
/**
* Returns fields that are present in the `first` schema, but absent in the `second` schema.
* Does not distinguish between types, i.e. schemaDiff({type: 'string'}, {type: 'number'}) === null.
*
* @param first
* @param second
*/
export function schemaDiff(first: JSONSchema, second: JSONSchema): JSONSchema {
if (!first) {
return null
} else if (first.type == JSONSchemaType.Object && first.properties) {
if (second?.type == JSONSchemaType.Object && second.properties) {
const diff: JSONSchema = {
type: JSONSchemaType.Object,
properties: {},
}
Object.keys(first.properties).forEach((key) => {
const keyDiff = schemaDiff(
first.properties[key],
second.properties[key],
)
if (keyDiff) {
diff.properties[key] = keyDiff
}
})
return Object.keys(diff.properties).length > 0 ? diff : null
} else {
// `first` is object ,but `second` is not object,
// so the whole `first` is missing.
return first
}
} else if (first.type == JSONSchemaType.Array && first.items) {
if (second?.type == JSONSchemaType.Array && second.items) {
const itemsDiff = schemaDiff(first.items, second.items)
if (itemsDiff) {
return {
type: JSONSchemaType.Array,
items: itemsDiff,
}
} else {
return null
}
} else {
return first
}
} else {
// Neither object nor array.
if (second) {
// As long as second is not empty, there is no difference.
return null
} else {
// Otherwise the whole `first` is a difference
return first
}
}
}

@@ -31,7 +31,10 @@ {

"outDir": "./",
"baseUrl": "."
"baseUrl": "./src"
},
"exclude": [
"node_modules",
"./*.ts",
"./*.d.ts",
"./*.js"
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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