@integration-app/sdk
Advanced tools
Comparing version 0.0.4 to 0.0.5
export declare function init(options: InitOptions): void; | ||
export declare function getFlowsUri(options: FlowsUriOptions): string; | ||
export declare function getNewFlowUri(options: NewFlowUriOptions): string; | ||
export declare function setImportDataCallback(callback: DataImportCallbackFunction): void; | ||
export declare function openNewFlow(options: NewFlowUriOptions): void; | ||
interface InitOptions { | ||
apiUri: string; | ||
uiUri: string; | ||
userAccessToken: string; | ||
} | ||
interface OptionalInitOptions { | ||
apiUri?: string; | ||
uiUri?: string; | ||
appKey?: string; | ||
userAccessToken?: string; | ||
} | ||
interface FlowsUriOptions extends OptionalInitOptions { | ||
interface NewFlowUriOptions extends InitOptions { | ||
blueprintKey: string; | ||
} | ||
interface NewFlowUriOptions extends OptionalInitOptions { | ||
blueprintKey: string; | ||
flowConfig?: any; | ||
onData: (...args: any) => void; | ||
} | ||
declare type DataImportCallbackFunction = (data: any[]) => void; | ||
export {}; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setImportDataCallback = exports.getNewFlowUri = exports.getFlowsUri = exports.init = void 0; | ||
exports.openNewFlow = exports.init = void 0; | ||
const iframe_1 = require("./iframe"); | ||
const DEFAULT_UI_URI = 'https://ui.integration.app'; | ||
// Global values set in .init | ||
let appKey; | ||
let uiUri; | ||
let userAccessToken; | ||
function init(options) { | ||
apiUri = options.apiUri; | ||
uiUri = options.uiUri; | ||
userAccessToken = options.userAccessToken; | ||
; | ||
({ uiUri, userAccessToken, appKey } = options); | ||
} | ||
exports.init = init; | ||
function getFlowsUri(options) { | ||
return getEmbedUri('flows', options, { | ||
function openNewFlow(options) { | ||
const uri = getEmbedUri('flows/new', options, { | ||
blueprintKey: options.blueprintKey, | ||
}); | ||
} | ||
exports.getFlowsUri = getFlowsUri; | ||
function getNewFlowUri(options) { | ||
return getEmbedUri('flows/new', options, { | ||
blueprintKey: options.blueprintKey, | ||
flowConfig: options.flowConfig | ||
@@ -32,29 +22,21 @@ ? JSON.stringify(options.flowConfig) | ||
}); | ||
} | ||
exports.getNewFlowUri = getNewFlowUri; | ||
function setImportDataCallback(callback) { | ||
if (dataImportCallback) { | ||
window.removeEventListener('message', dataImportCallback); | ||
} | ||
dataImportCallback = (event) => __awaiter(this, void 0, void 0, function* () { | ||
const message = event.data || {}; | ||
if (message.source == 'integration.app' && | ||
message.type == 'data-imported') { | ||
callback(message.data); | ||
} | ||
iframe_1.openIframe(uri, { | ||
onData: options.onData, | ||
}); | ||
window.addEventListener('message', dataImportCallback); | ||
} | ||
exports.setImportDataCallback = setImportDataCallback; | ||
exports.openNewFlow = openNewFlow; | ||
function getEmbedUri(page, options, params) { | ||
const baseUri = options.uiUri || uiUri; | ||
const token = options.userAccessToken || userAccessToken; | ||
if (!baseUri) { | ||
throw new Error('uiUri should be provided either in options or via sdk.init()'); | ||
const key = appKey || options.appKey; | ||
const baseUri = uiUri || options.uiUri || DEFAULT_UI_URI; | ||
const token = userAccessToken || options.userAccessToken; | ||
if (!key && !token) { | ||
throw Error('Either appKey or userAccessToken must be provided to use Integration.app UI'); | ||
} | ||
if (!token) { | ||
throw new Error('userAccessToken should be provided either in options or via sdk.init()'); | ||
const embedUrl = new URL(`${baseUri}/embed/${page}`); | ||
if (token) { | ||
embedUrl.searchParams.set('userAccessToken', token); | ||
} | ||
const embedUrl = new URL(`${baseUri}/embed/${page}`); | ||
embedUrl.searchParams.set('token', token); | ||
if (key) { | ||
embedUrl.searchParams.set('appKey', key); | ||
} | ||
for (const [key, value] of Object.entries(params)) { | ||
@@ -65,8 +47,1 @@ embedUrl.searchParams.set(key, value); | ||
} | ||
// Global values set in .init | ||
let apiUri; | ||
let uiUri; | ||
let userAccessToken; | ||
// We can have only one data listener per process / window | ||
// for simplicity | ||
let dataImportCallback; |
{ | ||
"name": "@integration-app/sdk", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "JavaScript SDK for Integration.app", | ||
@@ -8,9 +8,18 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc" | ||
"build": "npm run build:compile && npm run build:bundle", | ||
"build:compile": "tsc", | ||
"build:bundle": "rollup -c rollup.config.js" | ||
}, | ||
"devDependencies": { | ||
"@types/insert-css": "^2.0.0", | ||
"rollup": "^2.52.8", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"typescript": "^4.3.4" | ||
}, | ||
"author": "integration.app", | ||
"dependencies": {} | ||
"dependencies": { | ||
"insert-css": "^2.0.0", | ||
"penpal": "^5.3.0" | ||
} | ||
} |
@@ -0,16 +1,17 @@ | ||
import { openIframe } from './iframe' | ||
const DEFAULT_UI_URI = 'https://ui.integration.app' | ||
// Global values set in .init | ||
let appKey: string | undefined | ||
let uiUri: string | undefined | ||
let userAccessToken: string | undefined | ||
export function init(options: InitOptions) { | ||
apiUri = options.apiUri | ||
uiUri = options.uiUri | ||
userAccessToken = options.userAccessToken | ||
;({ uiUri, userAccessToken, appKey } = options) | ||
} | ||
export function getFlowsUri(options: FlowsUriOptions) { | ||
return getEmbedUri('flows', options, { | ||
export function openNewFlow(options: NewFlowUriOptions) { | ||
const uri = getEmbedUri('flows/new', options, { | ||
blueprintKey: options.blueprintKey, | ||
}) | ||
} | ||
export function getNewFlowUri(options: NewFlowUriOptions) { | ||
return getEmbedUri('flows/new', options, { | ||
blueprintKey: options.blueprintKey, | ||
flowConfig: options.flowConfig | ||
@@ -20,38 +21,30 @@ ? JSON.stringify(options.flowConfig) | ||
}) | ||
openIframe(uri, { | ||
onData: options.onData, | ||
}) | ||
} | ||
export function setImportDataCallback(callback: DataImportCallbackFunction) { | ||
if (dataImportCallback) { | ||
window.removeEventListener('message', dataImportCallback) | ||
} | ||
dataImportCallback = async (event: any) => { | ||
const message = event.data || {} | ||
if ( | ||
message.source == 'integration.app' && | ||
message.type == 'data-imported' | ||
) { | ||
callback(message.data) | ||
} | ||
} | ||
window.addEventListener('message', dataImportCallback) | ||
} | ||
function getEmbedUri(page: string, options: InitOptions, params?: any) { | ||
const key = appKey || options.appKey | ||
const baseUri = uiUri || options.uiUri || DEFAULT_UI_URI | ||
const token = userAccessToken || options.userAccessToken | ||
function getEmbedUri(page: string, options: OptionalInitOptions, params?: any) { | ||
const baseUri = options.uiUri || uiUri | ||
const token = options.userAccessToken || userAccessToken | ||
if (!baseUri) { | ||
throw new Error( | ||
'uiUri should be provided either in options or via sdk.init()', | ||
if (!key && !token) { | ||
throw Error( | ||
'Either appKey or userAccessToken must be provided to use Integration.app UI', | ||
) | ||
} | ||
if (!token) { | ||
throw new Error( | ||
'userAccessToken should be provided either in options or via sdk.init()', | ||
) | ||
const embedUrl = new URL(`${baseUri}/embed/${page}`) | ||
if (token) { | ||
embedUrl.searchParams.set('userAccessToken', token) | ||
} | ||
const embedUrl = new URL(`${baseUri}/embed/${page}`) | ||
embedUrl.searchParams.set('token', token) | ||
if (key) { | ||
embedUrl.searchParams.set('appKey', key) | ||
} | ||
for (const [key, value] of Object.entries(params)) { | ||
embedUrl.searchParams.set(key, value as string) | ||
} | ||
return embedUrl.href | ||
@@ -61,31 +54,11 @@ } | ||
interface InitOptions { | ||
apiUri: string | ||
uiUri: string | ||
userAccessToken: string | ||
} | ||
interface OptionalInitOptions { | ||
apiUri?: string | ||
uiUri?: string | ||
appKey?: string | ||
userAccessToken?: string | ||
} | ||
interface FlowsUriOptions extends OptionalInitOptions { | ||
interface NewFlowUriOptions extends InitOptions { | ||
blueprintKey: string | ||
} | ||
interface NewFlowUriOptions extends OptionalInitOptions { | ||
blueprintKey: string | ||
flowConfig?: any | ||
onData: (...args: any) => void | ||
} | ||
type DataImportCallbackFunction = (data: any[]) => void | ||
// Global values set in .init | ||
let apiUri: string | ||
let uiUri: string | ||
let userAccessToken: string | ||
// We can have only one data listener per process / window | ||
// for simplicity | ||
let dataImportCallback: (event: any) => void |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
160677
15
1250
2
5
1
+ Addedinsert-css@^2.0.0
+ Addedpenpal@^5.3.0
+ Addedinsert-css@2.0.0(transitive)
+ Addedpenpal@5.3.0(transitive)