@integration-app/sdk
Advanced tools
Comparing version 0.1.22 to 0.1.23
@@ -0,1 +1,2 @@ | ||
import { ConnectionsQuery } from './connections'; | ||
declare enum FlowRunState { | ||
@@ -38,3 +39,3 @@ RUNNING = "running", | ||
findIntegratedApps(): Promise<any>; | ||
findConnections(): Promise<any>; | ||
findConnections(query?: ConnectionsQuery): Promise<any>; | ||
findFlows(options: FindFlowsOptions): Promise<any>; | ||
@@ -53,3 +54,3 @@ deleteConnection(id: string): Promise<any>; | ||
private getPusherInstance; | ||
get(uri: string): Promise<any>; | ||
get(uri: string, queryParams?: Record<string, string>): Promise<any>; | ||
post(uri: string, data: any): Promise<any>; | ||
@@ -56,0 +57,0 @@ put(uri: string, data: any): Promise<any>; |
@@ -37,4 +37,4 @@ "use strict"; | ||
} | ||
async findConnections() { | ||
return this.get('connections'); | ||
async findConnections(query) { | ||
return this.get('connections', query); | ||
} | ||
@@ -256,3 +256,6 @@ async findFlows(options) { | ||
} | ||
async get(uri) { | ||
async get(uri, queryParams) { | ||
if (queryParams) { | ||
uri += `?${new URLSearchParams(queryParams).toString()}`; | ||
} | ||
return this.makeApiRequest('GET', { url: uri }); | ||
@@ -259,0 +262,0 @@ } |
@@ -38,5 +38,5 @@ import { JSONSchema } from './json-schema'; | ||
export declare class DataComposerRecipeRef extends DataComposerRecipeBase { | ||
locator: DataLocator | string; | ||
locator: DataLocator; | ||
items?: any; | ||
constructor(locator: DataLocator | string, items?: any); | ||
constructor(locator: DataLocator, items?: any); | ||
} | ||
@@ -63,2 +63,3 @@ export declare class DataComposerRecipePlain extends DataComposerRecipeBase { | ||
export declare function makeRecipeValue(recipe: DataComposerRecipe): any; | ||
export declare function transformToDataLocator(sourceLocator: string | DataLocator): DataLocator; | ||
export declare function getSchemaByLocator(schema: any, locator: DataLocator): any; | ||
@@ -65,0 +66,0 @@ export declare function makeSchemaForLocator(locator: DataLocator, locatorSchema: JSONSchema): any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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; | ||
exports.walkSchema = exports.makeSchemaForLocator = exports.getSchemaByLocator = exports.transformToDataLocator = 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 tslib_1 = require("tslib"); | ||
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash")); | ||
const json_schema_1 = require("./json-schema"); | ||
@@ -112,2 +114,32 @@ var DataLocatorStepType; | ||
exports.makeRecipeValue = makeRecipeValue; | ||
function transformToDataLocator(sourceLocator) { | ||
if (typeof sourceLocator !== 'string') | ||
return sourceLocator; | ||
const locators = []; | ||
const parts = sourceLocator.split('.').slice(1); | ||
lodash_1.default.each(parts, (p) => { | ||
if (p === '$current') { | ||
locators.push(new DataLocatorCurrentArrayItem()); | ||
return; | ||
} | ||
const lowestOpeningIndex = lodash_1.default.min(lodash_1.default.filter([p.indexOf('<'), p.indexOf('[')], (e) => e > 0)); | ||
locators.push(new DataLocatorObjectProperty(lowestOpeningIndex ? p.slice(0, lowestOpeningIndex) : p)); | ||
if (p.indexOf('<') > -1) { | ||
const openingIndex = p.indexOf('<'); | ||
const closingIndex = p.indexOf('>', openingIndex); | ||
const anyOfIndex = +p.slice(openingIndex + 1, closingIndex); | ||
locators.push(new DataLocatorAnyOfOption(anyOfIndex)); | ||
} | ||
let indexCursor = 0; | ||
while (p.indexOf('[', indexCursor) > -1) { | ||
const openingIndex = p.indexOf('[', indexCursor); | ||
const closingIndex = p.indexOf(']', openingIndex); | ||
indexCursor = closingIndex; | ||
const arrayIndex = +p.slice(openingIndex + 1, closingIndex); | ||
locators.push(new DataLocatorArrayItem(arrayIndex)); | ||
} | ||
}); | ||
return locators; | ||
} | ||
exports.transformToDataLocator = transformToDataLocator; | ||
function getSchemaByLocator(schema, locator) { | ||
@@ -114,0 +146,0 @@ if (schema) { |
@@ -122,3 +122,46 @@ "use strict"; | ||
}); | ||
describe('transformToDataLocator', () => { | ||
it('should extract locators from simple string locator', () => { | ||
expect((0, data_composer_1.transformToDataLocator)('$.name')).toEqual([ | ||
new data_composer_1.DataLocatorObjectProperty('name'), | ||
]); | ||
}); | ||
it('should extract locators from string locator with $current', () => { | ||
expect((0, data_composer_1.transformToDataLocator)('$.$current.name')).toEqual([ | ||
new data_composer_1.DataLocatorCurrentArrayItem(), | ||
new data_composer_1.DataLocatorObjectProperty('name'), | ||
]); | ||
}); | ||
it('should extract locators from string locator with array item index: prop[N]', () => { | ||
expect((0, data_composer_1.transformToDataLocator)('$.users[52].name')).toEqual([ | ||
new data_composer_1.DataLocatorObjectProperty('users'), | ||
new data_composer_1.DataLocatorArrayItem(52), | ||
new data_composer_1.DataLocatorObjectProperty('name'), | ||
]); | ||
}); | ||
it('should extract locators from string locator with nested arrays: prop[N][N]', () => { | ||
expect((0, data_composer_1.transformToDataLocator)('$.users[52][10].name')).toEqual([ | ||
new data_composer_1.DataLocatorObjectProperty('users'), | ||
new data_composer_1.DataLocatorArrayItem(52), | ||
new data_composer_1.DataLocatorArrayItem(10), | ||
new data_composer_1.DataLocatorObjectProperty('name'), | ||
]); | ||
}); | ||
it('should extract locators from string locator with anyOf', () => { | ||
expect((0, data_composer_1.transformToDataLocator)('$.users<1>.name')).toEqual([ | ||
new data_composer_1.DataLocatorObjectProperty('users'), | ||
new data_composer_1.DataLocatorAnyOfOption(1), | ||
new data_composer_1.DataLocatorObjectProperty('name'), | ||
]); | ||
}); | ||
it('should extract locators from complex string locator', () => { | ||
expect((0, data_composer_1.transformToDataLocator)('$.field<10>[0].subfield')).toEqual([ | ||
new data_composer_1.DataLocatorObjectProperty('field'), | ||
new data_composer_1.DataLocatorAnyOfOption(10), | ||
new data_composer_1.DataLocatorArrayItem(0), | ||
new data_composer_1.DataLocatorObjectProperty('subfield'), | ||
]); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=data-composer.test.js.map |
@@ -1,4 +0,1 @@ | ||
export declare enum EndpointConnectionMode { | ||
POPUP = "popup", | ||
IFRAME = "iframe" | ||
} | ||
export * from './endpoints'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EndpointConnectionMode = void 0; | ||
var EndpointConnectionMode; | ||
(function (EndpointConnectionMode) { | ||
EndpointConnectionMode["POPUP"] = "popup"; | ||
EndpointConnectionMode["IFRAME"] = "iframe"; | ||
})(EndpointConnectionMode = exports.EndpointConnectionMode || (exports.EndpointConnectionMode = {})); | ||
const tslib_1 = require("tslib"); | ||
(0, tslib_1.__exportStar)(require("./endpoints"), exports); | ||
//# sourceMappingURL=endpoint.js.map |
{ | ||
"name": "@integration-app/sdk", | ||
"version": "0.1.22", | ||
"version": "0.1.23", | ||
"description": "JavaScript SDK for Integration.app", | ||
@@ -40,2 +40,3 @@ "main": "index.js", | ||
"insert-css": "^2.0.0", | ||
"lodash": "^4.17.21", | ||
"penpal": "^5.3.0", | ||
@@ -42,0 +43,0 @@ "pusher-js": "^7.0.3" |
import Pusher, { Channel } from 'pusher-js' | ||
import Axios, { AxiosRequestConfig } from 'axios' | ||
import { openIframe } from './iframe' | ||
import { ConnectionsQuery } from './connections' | ||
@@ -68,4 +69,4 @@ const DEFAULT_API_URI = 'https://engine-api.integration.app' | ||
public async findConnections() { | ||
return this.get('connections') | ||
public async findConnections(query?: ConnectionsQuery) { | ||
return this.get('connections', query as Record<string, string>) | ||
} | ||
@@ -339,3 +340,6 @@ | ||
public async get(uri: string) { | ||
public async get(uri: string, queryParams?: Record<string, string>) { | ||
if (queryParams) { | ||
uri += `?${new URLSearchParams(queryParams).toString()}` | ||
} | ||
return this.makeApiRequest('GET', { url: uri }) | ||
@@ -342,0 +346,0 @@ } |
@@ -8,2 +8,3 @@ import { | ||
makeSchemaForLocator, | ||
transformToDataLocator, | ||
} from './data-composer' | ||
@@ -169,2 +170,51 @@ import { JSONSchemaType } from './json-schema' | ||
}) | ||
describe('transformToDataLocator', () => { | ||
it('should extract locators from simple string locator', () => { | ||
expect(transformToDataLocator('$.name')).toEqual([ | ||
new DataLocatorObjectProperty('name'), | ||
]) | ||
}) | ||
it('should extract locators from string locator with $current', () => { | ||
expect(transformToDataLocator('$.$current.name')).toEqual([ | ||
new DataLocatorCurrentArrayItem(), | ||
new DataLocatorObjectProperty('name'), | ||
]) | ||
}) | ||
it('should extract locators from string locator with array item index: prop[N]', () => { | ||
expect(transformToDataLocator('$.users[52].name')).toEqual([ | ||
new DataLocatorObjectProperty('users'), | ||
new DataLocatorArrayItem(52), | ||
new DataLocatorObjectProperty('name'), | ||
]) | ||
}) | ||
it('should extract locators from string locator with nested arrays: prop[N][N]', () => { | ||
expect(transformToDataLocator('$.users[52][10].name')).toEqual([ | ||
new DataLocatorObjectProperty('users'), | ||
new DataLocatorArrayItem(52), | ||
new DataLocatorArrayItem(10), | ||
new DataLocatorObjectProperty('name'), | ||
]) | ||
}) | ||
it('should extract locators from string locator with anyOf', () => { | ||
expect(transformToDataLocator('$.users<1>.name')).toEqual([ | ||
new DataLocatorObjectProperty('users'), | ||
new DataLocatorAnyOfOption(1), | ||
new DataLocatorObjectProperty('name'), | ||
]) | ||
}) | ||
it('should extract locators from complex string locator', () => { | ||
expect(transformToDataLocator('$.field<10>[0].subfield')).toEqual([ | ||
new DataLocatorObjectProperty('field'), | ||
new DataLocatorAnyOfOption(10), | ||
new DataLocatorArrayItem(0), | ||
new DataLocatorObjectProperty('subfield'), | ||
]) | ||
}) | ||
}) | ||
}) |
@@ -0,1 +1,2 @@ | ||
import _ from 'lodash' | ||
import { JSONSchema, JSONSchemaType } from './json-schema' | ||
@@ -57,3 +58,3 @@ | ||
export class DataComposerRecipeRef extends DataComposerRecipeBase { | ||
constructor(public locator: DataLocator | string, public items?: any) { | ||
constructor(public locator: DataLocator, public items?: any) { | ||
super() | ||
@@ -113,2 +114,56 @@ this.type = DataComposerRecipeType.REF | ||
/** | ||
* Transforms parameter to data locator array | ||
* If parameter is already a data locator array - just return it | ||
* '$.name' => [new DataLocatorObjectProperty('name')] | ||
* [new DataLocatorObjectProperty('name')] => [new DataLocatorObjectProperty('name')] | ||
* @param sourceLocator | ||
* @returns locators | ||
*/ | ||
export function transformToDataLocator( | ||
sourceLocator: string | DataLocator, | ||
): DataLocator { | ||
if (typeof sourceLocator !== 'string') return sourceLocator | ||
const locators = [] | ||
// skip $ because it's not used for locator | ||
const parts = sourceLocator.split('.').slice(1) | ||
_.each(parts, (p) => { | ||
if (p === '$current') { | ||
locators.push(new DataLocatorCurrentArrayItem()) | ||
return | ||
} | ||
// used to remove <N> and [N] from object property name | ||
const lowestOpeningIndex = _.min( | ||
_.filter([p.indexOf('<'), p.indexOf('[')], (e) => e > 0), | ||
) | ||
locators.push( | ||
new DataLocatorObjectProperty( | ||
lowestOpeningIndex ? p.slice(0, lowestOpeningIndex) : p, | ||
), | ||
) | ||
if (p.indexOf('<') > -1) { | ||
const openingIndex = p.indexOf('<') | ||
const closingIndex = p.indexOf('>', openingIndex) | ||
const anyOfIndex = +p.slice(openingIndex + 1, closingIndex) | ||
locators.push(new DataLocatorAnyOfOption(anyOfIndex)) | ||
} | ||
let indexCursor = 0 | ||
while (p.indexOf('[', indexCursor) > -1) { | ||
const openingIndex = p.indexOf('[', indexCursor) | ||
const closingIndex = p.indexOf(']', openingIndex) | ||
indexCursor = closingIndex | ||
const arrayIndex = +p.slice(openingIndex + 1, closingIndex) | ||
locators.push(new DataLocatorArrayItem(arrayIndex)) | ||
} | ||
}) | ||
return locators | ||
} | ||
/* | ||
@@ -115,0 +170,0 @@ Extract sub-schema that pointer points at. |
@@ -1,4 +0,5 @@ | ||
export enum EndpointConnectionMode { | ||
POPUP = 'popup', | ||
IFRAME = 'iframe', | ||
} | ||
/** | ||
* DEPRECATED | ||
* ToDo: Remove | ||
*/ | ||
export * from './endpoints' |
@@ -31,3 +31,3 @@ { | ||
"outDir": "./", | ||
"baseUrl": "./src" | ||
"baseUrl": "./" | ||
}, | ||
@@ -34,0 +34,0 @@ "exclude": [ |
Sorry, the diff of this file is too big to display
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
Sorry, the diff of this file is not supported yet
945811
103
10542
5
+ Addedlodash@^4.17.21
+ Addedlodash@4.17.21(transitive)