@integration-app/sdk
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -10,2 +10,3 @@ "use strict"; | ||
const errors_1 = require("./errors"); | ||
const jwt_1 = require("./jwt"); | ||
const DEFAULT_API_URI = 'https://engine-api.integration.app'; | ||
@@ -32,2 +33,4 @@ const DEFAULT_UI_URI = 'https://ui.integration.app'; | ||
init(options) { | ||
if (options.accessToken !== undefined && !(0, jwt_1.isJWT)(options.accessToken)) | ||
throw new Error('Access token should be a valid JWT token'); | ||
this.initialized = true; | ||
@@ -34,0 +37,0 @@ this.apiUri = options.apiUri || DEFAULT_API_URI; |
@@ -51,5 +51,7 @@ import { JSONSchema } from './json-schema'; | ||
} | ||
export declare function plainRecipeToClass(value: any): any; | ||
export declare function validateRecipe(value: any): void; | ||
export declare function isRecipe(value: any): boolean; | ||
export declare function getRecipe(value: any): DataComposerRecipe; | ||
export declare function makeRecipeValue(recipe: DataComposerRecipe): any; | ||
export declare function makeComposeRecipeValue(recipe: DataComposerRecipe): any; | ||
export declare function extractLocatorsFromTemplate(recipe: DataComposerRecipeTemplate): string[]; | ||
@@ -56,0 +58,0 @@ export declare function locatorToSteps(sourceLocator: string | DataLocator): DataLocatorStep[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.walkSchema = exports.getFullTitleForLocator = exports.getTitleForLocator = exports.makeSchemaForLocator = exports.setValueAtLocator = exports.getDataFields = exports.getSchemaByLocator = exports.stepsToLocator = exports.locatorToString = exports.locatorToSteps = exports.extractLocatorsFromTemplate = exports.makeRecipeValue = exports.getRecipe = exports.isRecipe = exports.InvalidLocatorError = exports.DataComposerRecipePlain = exports.DataComposerRecipeTemplate = exports.DataComposerRecipeRef = exports.DataComposerRecipeBase = exports.DataComposerRecipeType = exports.DataLocatorAnyOfOption = exports.DataLocatorCurrentArrayItem = exports.DataLocatorArrayItem = exports.DataLocatorObjectProperty = exports.DataLocatorStep = exports.DataLocatorStepType = void 0; | ||
exports.walkSchema = exports.getFullTitleForLocator = exports.getTitleForLocator = exports.makeSchemaForLocator = exports.setValueAtLocator = exports.getDataFields = exports.getSchemaByLocator = exports.stepsToLocator = exports.locatorToString = exports.locatorToSteps = exports.extractLocatorsFromTemplate = exports.makeComposeRecipeValue = exports.getRecipe = exports.isRecipe = exports.validateRecipe = exports.plainRecipeToClass = exports.InvalidLocatorError = exports.DataComposerRecipePlain = exports.DataComposerRecipeTemplate = 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"); | ||
@@ -86,11 +86,51 @@ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash")); | ||
exports.InvalidLocatorError = InvalidLocatorError; | ||
function plainRecipeToClass(value) { | ||
let recipe; | ||
if (value === null || value === void 0 ? void 0 : value.$compose) { | ||
return value; | ||
} | ||
else if (value === null || value === void 0 ? void 0 : value.$ref) { | ||
recipe = value.$ref; | ||
if (typeof recipe === 'string') { | ||
recipe = makeComposeRecipeValue(new DataComposerRecipeRef(locatorToSteps(recipe))); | ||
} | ||
else { | ||
recipe = makeComposeRecipeValue(new DataComposerRecipeRef(locatorToSteps(recipe.locator), recipe.items)); | ||
} | ||
} | ||
else if (value === null || value === void 0 ? void 0 : value.$tpl) { | ||
recipe = makeComposeRecipeValue(new DataComposerRecipeTemplate(value.$tpl)); | ||
} | ||
else if (value === null || value === void 0 ? void 0 : value.$plain) { | ||
recipe = makeComposeRecipeValue(new DataComposerRecipePlain(value.$plain)); | ||
} | ||
else { | ||
throw new errors_1.BadRequestError(`Not supported recipe: ${JSON.stringify(value)}`); | ||
} | ||
return recipe; | ||
} | ||
exports.plainRecipeToClass = plainRecipeToClass; | ||
function validateRecipe(value) { | ||
const hasComposeRecipe = !!(value === null || value === void 0 ? void 0 : value.$compose); | ||
const hasRefRecipe = !!(value === null || value === void 0 ? void 0 : value.$ref); | ||
const hasTplRecipe = !!(value === null || value === void 0 ? void 0 : value.$tpl); | ||
const hasPlainRecipe = !!(value === null || value === void 0 ? void 0 : value.$plain); | ||
if (+hasComposeRecipe + +hasRefRecipe + +hasTplRecipe + +hasPlainRecipe > 1) { | ||
throw new errors_1.BadRequestError(`There are multiple recipes found in value. Expected a single recipe. Value: ${JSON.stringify(value)}`); | ||
} | ||
if (!hasComposeRecipe && !hasRefRecipe && !hasTplRecipe && !hasPlainRecipe) { | ||
throw new errors_1.BadRequestError(`No recipe found in value. Value: ${JSON.stringify(value)}`); | ||
} | ||
} | ||
exports.validateRecipe = validateRecipe; | ||
function isRecipe(value) { | ||
return !!(value === null || value === void 0 ? void 0 : value.$compose); | ||
return !!(value === null || value === void 0 ? void 0 : value.$compose) || !!(value === null || value === void 0 ? void 0 : value.$ref) || !!(value === null || value === void 0 ? void 0 : value.$tpl) || !!(value === null || value === void 0 ? void 0 : value.$plain); | ||
} | ||
exports.isRecipe = isRecipe; | ||
function getRecipe(value) { | ||
return value === null || value === void 0 ? void 0 : value.$compose; | ||
validateRecipe(value); | ||
return lodash_1.default.head(lodash_1.default.filter([value === null || value === void 0 ? void 0 : value.$compose, value === null || value === void 0 ? void 0 : value.$ref, value === null || value === void 0 ? void 0 : value.$tpl, value === null || value === void 0 ? void 0 : value.$plain], (v) => !!v)); | ||
} | ||
exports.getRecipe = getRecipe; | ||
function makeRecipeValue(recipe) { | ||
function makeComposeRecipeValue(recipe) { | ||
return { | ||
@@ -100,3 +140,3 @@ $compose: recipe, | ||
} | ||
exports.makeRecipeValue = makeRecipeValue; | ||
exports.makeComposeRecipeValue = makeComposeRecipeValue; | ||
function extractLocatorsFromTemplate(recipe) { | ||
@@ -103,0 +143,0 @@ const openingBracketRegex = /(?<!\\)(?:\\\\)*{/; |
{ | ||
"name": "@integration-app/sdk", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "JavaScript SDK for Integration.app", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,2 +8,3 @@ import Pusher, { Channel } from 'pusher-js' | ||
import { getErrorFromData } from './errors' | ||
import { isJWT } from './jwt' | ||
@@ -63,2 +64,5 @@ const DEFAULT_API_URI = 'https://engine-api.integration.app' | ||
public init(options: IntegrationAppClientOptions) { | ||
if (options.accessToken !== undefined && !isJWT(options.accessToken)) | ||
throw new Error('Access token should be a valid JWT token') | ||
this.initialized = true | ||
@@ -65,0 +69,0 @@ this.apiUri = options.apiUri || DEFAULT_API_URI |
@@ -84,11 +84,66 @@ import _ from 'lodash' | ||
export function plainRecipeToClass(value) { | ||
let recipe | ||
if (value?.$compose) { | ||
return value | ||
} else if (value?.$ref) { | ||
recipe = value.$ref | ||
if (typeof recipe === 'string') { | ||
recipe = makeComposeRecipeValue( | ||
new DataComposerRecipeRef(locatorToSteps(recipe)), | ||
) | ||
} else { | ||
recipe = makeComposeRecipeValue( | ||
new DataComposerRecipeRef(locatorToSteps(recipe.locator), recipe.items), | ||
) | ||
} | ||
} else if (value?.$tpl) { | ||
recipe = makeComposeRecipeValue(new DataComposerRecipeTemplate(value.$tpl)) | ||
} else if (value?.$plain) { | ||
recipe = makeComposeRecipeValue(new DataComposerRecipePlain(value.$plain)) | ||
} else { | ||
throw new BadRequestError(`Not supported recipe: ${JSON.stringify(value)}`) | ||
} | ||
return recipe | ||
} | ||
export function validateRecipe(value) { | ||
const hasComposeRecipe = !!value?.$compose | ||
const hasRefRecipe = !!value?.$ref | ||
const hasTplRecipe = !!value?.$tpl | ||
const hasPlainRecipe = !!value?.$plain | ||
if (+hasComposeRecipe + +hasRefRecipe + +hasTplRecipe + +hasPlainRecipe > 1) { | ||
throw new BadRequestError( | ||
`There are multiple recipes found in value. Expected a single recipe. Value: ${JSON.stringify( | ||
value, | ||
)}`, | ||
) | ||
} | ||
if (!hasComposeRecipe && !hasRefRecipe && !hasTplRecipe && !hasPlainRecipe) { | ||
throw new BadRequestError( | ||
`No recipe found in value. Value: ${JSON.stringify(value)}`, | ||
) | ||
} | ||
} | ||
export function isRecipe(value) { | ||
return !!value?.$compose | ||
return !!value?.$compose || !!value?.$ref || !!value?.$tpl || !!value?.$plain | ||
} | ||
export function getRecipe(value): DataComposerRecipe { | ||
return value?.$compose | ||
validateRecipe(value) | ||
// pick first value which exists | ||
return _.head( | ||
_.filter( | ||
[value?.$compose, value?.$ref, value?.$tpl, value?.$plain], | ||
(v) => !!v, | ||
), | ||
) | ||
} | ||
export function makeRecipeValue(recipe: DataComposerRecipe): any { | ||
export function makeComposeRecipeValue(recipe: DataComposerRecipe): any { | ||
return { | ||
@@ -95,0 +150,0 @@ $compose: recipe, |
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
2481128
104
28903