Socket
Socket
Sign inDemoInstall

@prismatic-io/spectral

Package Overview
Dependencies
Maintainers
4
Versions
171
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prismatic-io/spectral - npm Package Compare versions

Comparing version 6.6.1 to 7.0.0-pre

dist/types/DataSourceDefinition.d.ts

12

dist/index.d.ts

@@ -6,3 +6,3 @@ /**

*/
import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult } from "./types";
import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, DataSourceResult } from "./types";
import { convertComponent } from "./serverTypes/convert";

@@ -39,2 +39,12 @@ /**

/**
* This function creates a data source object that can be referenced
* by a custom component. It helps ensure that the shape of the
* data source object conforms to what the Prismatic API expects.
* For information on writing custom component data sources, see
* https://prismatic.io/docs/custom-components/writing-custom-components/#writing-data-sources.
* @param definition A DataSourceDefinition type object that includes UI display information, a function to perform when the data source is invoked, and a an object containing inputs for the perform function.
* @returns This function validates the shape of the `definition` object provided, and returns the same data source object.
*/
export declare const dataSource: <TInputs extends Inputs, TResult extends DataSourceResult<unknown>>(definition: DataSourceDefinition<TInputs, TResult>) => DataSourceDefinition<TInputs, TResult>;
/**
* For information and examples on how to write inputs

@@ -41,0 +51,0 @@ * for custom component actions and triggers, see

@@ -25,3 +25,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.testing = exports.util = exports.oauth2Connection = exports.connection = exports.input = exports.trigger = exports.action = exports.component = void 0;
exports.testing = exports.util = exports.oauth2Connection = exports.connection = exports.input = exports.dataSource = exports.trigger = exports.action = exports.component = void 0;
const convert_1 = require("./serverTypes/convert");

@@ -61,2 +61,13 @@ /**

/**
* This function creates a data source object that can be referenced
* by a custom component. It helps ensure that the shape of the
* data source object conforms to what the Prismatic API expects.
* For information on writing custom component data sources, see
* https://prismatic.io/docs/custom-components/writing-custom-components/#writing-data-sources.
* @param definition A DataSourceDefinition type object that includes UI display information, a function to perform when the data source is invoked, and a an object containing inputs for the perform function.
* @returns This function validates the shape of the `definition` object provided, and returns the same data source object.
*/
const dataSource = (definition) => definition;
exports.dataSource = dataSource;
/**
* For information and examples on how to write inputs

@@ -63,0 +74,0 @@ * for custom component actions and triggers, see

2

dist/serverTypes/convert.d.ts
import { ComponentDefinition } from "../types";
import { Component as ServerComponent } from ".";
export declare const convertComponent: <TPublic extends boolean>({ connections, actions, triggers, hooks, ...definition }: ComponentDefinition<TPublic>) => ServerComponent;
export declare const convertComponent: <TPublic extends boolean>({ connections, actions, triggers, dataSources, hooks, ...definition }: ComponentDefinition<TPublic>) => ServerComponent;

@@ -42,2 +42,10 @@ "use strict";

};
const convertDataSource = (dataSourceKey, _a, hooks) => {
var { inputs = {}, perform } = _a, dataSource = __rest(_a, ["inputs", "perform"]);
const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
return Object.assign(Object.assign({}, dataSource), { key: dataSourceKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
inputCleaners: {},
errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
}) });
};
const convertConnection = (_a) => {

@@ -49,7 +57,8 @@ var { inputs = {} } = _a, connection = __rest(_a, ["inputs"]);

const convertComponent = (_a) => {
var { connections = [], actions = {}, triggers = {}, hooks } = _a, definition = __rest(_a, ["connections", "actions", "triggers", "hooks"]);
var { connections = [], actions = {}, triggers = {}, dataSources = {}, hooks } = _a, definition = __rest(_a, ["connections", "actions", "triggers", "dataSources", "hooks"]);
const convertedActions = Object.entries(actions).reduce((result, [actionKey, action]) => (Object.assign(Object.assign({}, result), { [actionKey]: convertAction(actionKey, action, hooks) })), {});
const convertedTriggers = Object.entries(triggers).reduce((result, [triggerKey, trigger]) => (Object.assign(Object.assign({}, result), { [triggerKey]: convertTrigger(triggerKey, trigger, hooks) })), {});
return Object.assign(Object.assign({}, definition), { connections: connections.map(convertConnection), actions: convertedActions, triggers: convertedTriggers });
const convertedDataSources = Object.entries(dataSources).reduce((result, [dataSourceKey, dataSource]) => (Object.assign(Object.assign({}, result), { [dataSourceKey]: convertDataSource(dataSourceKey, dataSource, hooks) })), {});
return Object.assign(Object.assign({}, definition), { connections: connections.map(convertConnection), actions: convertedActions, triggers: convertedTriggers, dataSources: convertedDataSources });
};
exports.convertComponent = convertComponent;
/// <reference types="node" />
import { DataSourceType } from "../types";
interface DisplayDefinition {

@@ -16,2 +17,3 @@ label: string;

triggers: Record<string, Trigger>;
dataSources: Record<string, DataSource>;
connections: Connection[];

@@ -129,2 +131,20 @@ }

}
export declare type DataSourceResult = {
content: DataSourceType;
supplementalData: {
data: unknown;
contentType: string;
};
};
export declare type DataSourcePerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<DataSourceResult>;
export interface DataSource {
key: string;
display: DisplayDefinition & {
directions?: string;
important?: boolean;
};
inputs: Input[];
perform: DataSourcePerformFunction;
examplePayload?: unknown;
}
export declare enum OAuth2Type {

@@ -131,0 +151,0 @@ ClientCredentials = "client_credentials",

@@ -7,4 +7,4 @@ /**

*/
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn } from "./serverTypes";
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult } from "./types";
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult } from "./serverTypes";
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult } from "./types";
export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>) => ConnectionValue;

@@ -38,2 +38,9 @@ /**

export declare const invokeTrigger: <TInputs extends Inputs, TAllowsBranching extends boolean, TResult extends InvokeTriggerResult<TAllowsBranching>>({ perform }: TriggerDefinition<TInputs, TAllowsBranching, TResult>, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs> | undefined) => Promise<InvokeReturn<TResult>>;
/**
* Invokes specified DataSourceDefinition perform function using supplied params
* and optional context. Accepts a generic type matching DataSourceResult as a convenience
* to avoid extra casting within test methods. Returns an InvokeResult containing both the
* action result and a mock logger for asserting logging.
*/
export declare const invokeDataSource: <TInputs extends Inputs, TReturn extends InvokeDataSourceResult<unknown>>({ perform }: DataSourceDefinition<TInputs, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn>>;
export declare class ComponentTestHarness<TComponent extends Component> {

@@ -45,2 +52,3 @@ component: TComponent;

action(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<ActionPerformReturn>;
dataSource(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<DataSourceResult>;
}

@@ -53,3 +61,4 @@ export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;

createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
invokeDataSource: <TInputs_2 extends Inputs, TReturn_1 extends InvokeDataSourceResult<unknown>>({ perform }: DataSourceDefinition<TInputs_2, TReturn_1>, params: ActionInputParameters<TInputs_2>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn_1>>;
};
export default _default;

@@ -18,3 +18,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createHarness = exports.ComponentTestHarness = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.createConnection = void 0;
exports.createHarness = exports.ComponentTestHarness = exports.invokeDataSource = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.createConnection = void 0;
const jest_mock_1 = require("jest-mock");

@@ -41,2 +41,26 @@ const createConnection = ({ key }, values) => ({

exports.loggerMock = loggerMock;
const baseContext = {
logger: (0, exports.loggerMock)(),
instanceState: {},
crossFlowState: {},
executionState: {},
stepId: "mockStepId",
executionId: "mockExecutionId",
webhookUrls: {
"Flow 1": "https://example.com",
},
webhookApiKeys: {
"Flow 1": ["example-123", "example-456"],
},
invokeUrl: "https://example.com",
customer: {
id: "customerId",
name: "Customer 1",
externalId: "1234",
},
instance: {
id: "instanceId",
name: "Instance 1",
},
};
/**

@@ -49,14 +73,3 @@ * Invokes specified ActionDefinition perform function using supplied params

const invoke = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
"Flow 1": "https://example.com",
}, webhookApiKeys: {
"Flow 1": ["example-123", "example-456"],
}, invokeUrl: "https://example.com", customer: {
id: "customerId",
name: "Customer 1",
externalId: "1234",
}, instance: {
id: "instanceId",
name: "Instance 1",
} }, context);
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
const result = yield perform(realizedContext, params);

@@ -113,14 +126,3 @@ return {

const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void 0, void 0, void 0, function* () {
const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
"Flow 1": "https://example.com",
}, webhookApiKeys: {
"Flow 1": ["example-123", "example-456"],
}, invokeUrl: "https://example.com", customer: {
id: "customerId",
name: "Customer 1",
externalId: "1234",
}, instance: {
id: "instanceId",
name: "Instance 1",
} }, context);
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
const realizedPayload = Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload);

@@ -135,2 +137,17 @@ const realizedParams = params || {};

exports.invokeTrigger = invokeTrigger;
/**
* Invokes specified DataSourceDefinition perform function using supplied params
* and optional context. Accepts a generic type matching DataSourceResult as a convenience
* to avoid extra casting within test methods. Returns an InvokeResult containing both the
* action result and a mock logger for asserting logging.
*/
const invokeDataSource = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
const result = yield perform(realizedContext, params);
return {
result,
loggerMock: realizedContext.logger,
};
});
exports.invokeDataSource = invokeDataSource;
class ComponentTestHarness {

@@ -150,14 +167,3 @@ constructor(component) {

return __awaiter(this, void 0, void 0, function* () {
const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
"Flow 1": "https://example.com",
}, webhookApiKeys: {
"Flow 1": ["example-123", "example-456"],
}, invokeUrl: "https://example.com", customer: {
id: "customerId",
name: "Customer 1",
externalId: "1234",
}, instance: {
id: "instanceId",
name: "Instance 1",
} }, context);
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
const trigger = this.component.triggers[key];

@@ -169,14 +175,3 @@ return trigger.perform(realizedContext, Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), Object.assign({}, params));

return __awaiter(this, void 0, void 0, function* () {
const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
"Flow 1": "https://example.com",
}, webhookApiKeys: {
"Flow 1": ["example-123", "example-456"],
}, invokeUrl: "https://example.com", customer: {
id: "customerId",
name: "Customer 1",
externalId: "1234",
}, instance: {
id: "instanceId",
name: "Instance 1",
} }, context);
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
const action = this.component.actions[key];

@@ -186,2 +181,9 @@ return action.perform(realizedContext, Object.assign({}, params));

}
dataSource(key, params, context) {
return __awaiter(this, void 0, void 0, function* () {
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
const dataSource = this.component.dataSources[key];
return dataSource.perform(realizedContext, Object.assign({}, params));
});
}
}

@@ -198,2 +200,3 @@ exports.ComponentTestHarness = ComponentTestHarness;

createHarness: exports.createHarness,
invokeDataSource: exports.invokeDataSource,
};

@@ -15,3 +15,3 @@ /** Used to represent a binary or serialized data return as content type must be specified */

executionState?: Record<string, unknown>;
/** A field populated by the Prismatic platform which indicates whether the trigger failed with an error during execution. */
/** A field populated by the Prismatic platform which indicates whether the action failed with an error during execution. */
failed?: boolean;

@@ -18,0 +18,0 @@ /** A field populated by the Prismatic platform which may refer to an object that contains data about any error that resulted in failure. */

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

import { ActionDefinition, ConnectionDefinition, ComponentDisplayDefinition, TriggerDefinition } from ".";
import { ActionDefinition, ConnectionDefinition, ComponentDisplayDefinition, TriggerDefinition, DataSourceDefinition } from ".";
export declare type ErrorHandler = (error: unknown) => unknown;

@@ -19,2 +19,4 @@ export interface ComponentHooks {

triggers?: Record<string, TriggerDefinition<any, boolean, any>>;
/** Specifies the supported Data Sources of this Component. */
dataSources?: Record<string, DataSourceDefinition<any, any>>;
/** Specifies the supported Connections of this Component. */

@@ -21,0 +23,0 @@ connections?: ConnectionDefinition[];

@@ -21,1 +21,5 @@ /**

export * from "./TriggerPayload";
export * from "./DataSourceDefinition";
export * from "./DataSourcePerformFunction";
export * from "./DataSourceResult";
export * from "./DataSourceType";

@@ -37,1 +37,5 @@ "use strict";

__exportStar(require("./TriggerPayload"), exports);
__exportStar(require("./DataSourceDefinition"), exports);
__exportStar(require("./DataSourcePerformFunction"), exports);
__exportStar(require("./DataSourceResult"), exports);
__exportStar(require("./DataSourceType"), exports);
import { ConditionalExpression } from "./conditional-logic";
import { ObjectSelection, ObjectFieldMap } from "./DataSourceType";
/** InputField type enumeration. */

@@ -9,3 +10,3 @@ export declare type InputFieldType = InputFieldDefinition["type"];

};
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField;
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField;
export declare type InputCleanFunction<TValue, TResult = TValue> = (value: TValue) => TResult;

@@ -136,2 +137,24 @@ interface BaseInputField {

}
/** Defines attributes of an ObjectSelectionInputField. */
export interface ObjectSelectionInputField extends BaseInputField {
/** Data type the InputField will collect. */
type: "objectselection";
/** Collection type of the InputField */
collection?: InputFieldCollection;
/** Default value for this field. */
default?: ObjectSelection;
/** Clean function */
clean?: InputCleanFunction<NonNullable<this["default"]>>;
}
/** Defines attributes of an ObjectFieldMapInputField. */
export interface ObjectFieldMapInputField extends BaseInputField {
/** Data type the InputField will collect. */
type: "objectfieldmap";
/** Collection type of the InputField */
collection?: InputFieldCollection;
/** Default value for this field. */
default?: ObjectFieldMap;
/** Clean function */
clean?: InputCleanFunction<NonNullable<this["default"]>>;
}
/** Defines a single Choice option for a InputField. */

@@ -138,0 +161,0 @@ export interface InputFieldChoice {

@@ -13,2 +13,4 @@ "use strict";

connection: undefined,
objectselection: undefined,
objectfieldmap: undefined,
};

@@ -6,3 +6,3 @@ /**

*/
import { KeyValuePair, DataPayload } from "./types";
import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap } from "./types";
/**

@@ -40,2 +40,6 @@ * This function returns a lower cased version of the headers passed to it.

lowerCaseHeaders: (headers: Record<string, string>) => Record<string, string>;
isObjectSelection: (value: unknown) => value is ObjectSelection;
toObjectSelection: (value: unknown) => ObjectSelection;
isObjectFieldMap: (value: unknown) => value is ObjectFieldMap;
toObjectFieldMap: (value: unknown) => ObjectFieldMap;
};

@@ -42,0 +46,0 @@ docs: {

@@ -18,3 +18,78 @@ "use strict";

const valid_url_1 = require("valid-url");
const isObjectWithTruthyKeys = (value, keys) => {
return (value !== null &&
typeof value === "object" &&
keys.every((key) => key in value && Boolean(value === null || value === void 0 ? void 0 : value[key])));
};
/**
* @param value The value to test
* @returns This function returns true if the type of `value` is an ObjectSelection, or false otherwise.
*/
const isObjectSelection = (value) => {
if (Array.isArray(value)) {
for (const selection of value) {
if (isObjectWithTruthyKeys(selection, ["key", "fields"])) {
const { fields } = selection;
if (!Array.isArray(fields) ||
fields.length === 0 ||
!fields.every((field) => isObjectWithTruthyKeys(field, ["key"]))) {
return false;
}
}
else {
return false;
}
}
}
else {
return false;
}
return true;
};
/**
* This function coerces a provided value into an ObjectSelection if possible.
* @param value The value to coerce to ObjectSelection.
* @returns This function returns the the value as an ObjectSelection if possible.
*/
const toObjectSelection = (value) => {
if (isObjectSelection(value)) {
return value;
}
throw new Error(`Value '${value}' cannot be coerced to ObjectSelection.`);
};
/**
* @param value The value to test
* @returns This function returns true if the type of `value` is an ObjectFieldMap, or false otherwise.
*/
const isObjectFieldMap = (value) => {
if (Array.isArray(value)) {
for (const fieldMap of value) {
if (isObjectWithTruthyKeys(fieldMap, ["key", "value"])) {
const { value: val } = fieldMap;
if (!isObjectWithTruthyKeys(val, ["objectKey", "fieldKey"])) {
return false;
}
}
else {
return false;
}
}
}
else {
return false;
}
return true;
};
/**
* This function coerces a provided value into an ObjectFieldMap if possible.
* @param value The value to coerce to ObjectFieldMap.
* @returns This function returns the the value as an ObjectFieldMap if possible.
*/
const toObjectFieldMap = (value) => {
if (isObjectFieldMap(value)) {
return value;
}
throw new Error(`Value '${value}' cannot be coerced to ObjectFieldMap.`);
};
/**
* Determine if a variable is a boolean (true or false).

@@ -361,2 +436,6 @@ *

lowerCaseHeaders: exports.lowerCaseHeaders,
isObjectSelection,
toObjectSelection,
isObjectFieldMap,
toObjectFieldMap,
},

@@ -363,0 +442,0 @@ docs: {

{
"name": "@prismatic-io/spectral",
"version": "6.6.1",
"version": "7.0.0-pre",
"description": "Utility library for building Prismatic components",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc