@prismatic-io/spectral 6.5.2 → 7.0.0-pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/http/index.d.ts +2 -1
- package/dist/clients/http/index.js +2 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +12 -1
- package/dist/serverTypes/convert.d.ts +1 -1
- package/dist/serverTypes/convert.js +11 -2
- package/dist/serverTypes/index.d.ts +32 -0
- package/dist/testing.d.ts +11 -2
- package/dist/testing.js +52 -5
- package/dist/types/ActionPerformFunction.d.ts +17 -0
- package/dist/types/ActionPerformReturn.d.ts +1 -1
- package/dist/types/ComponentDefinition.d.ts +3 -1
- package/dist/types/DataSourceDefinition.d.ts +15 -0
- package/dist/types/DataSourceDefinition.js +2 -0
- package/dist/types/DataSourcePerformFunction.d.ts +3 -0
- package/dist/types/DataSourcePerformFunction.js +2 -0
- package/dist/types/DataSourceResult.d.ts +10 -0
- package/dist/types/DataSourceResult.js +2 -0
- package/dist/types/DataSourceType.d.ts +20 -0
- package/dist/types/DataSourceType.js +2 -0
- package/dist/types/Inputs.d.ts +24 -1
- package/dist/types/Inputs.js +2 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +4 -0
- package/dist/util.d.ts +5 -1
- package/dist/util.js +83 -4
- package/package.json +2 -2
|
@@ -13,11 +13,12 @@ export interface ClientProps {
|
|
|
13
13
|
baseUrl?: string;
|
|
14
14
|
responseType?: AxiosRequestConfig["responseType"];
|
|
15
15
|
headers?: AxiosRequestConfig["headers"];
|
|
16
|
+
params?: Record<string, any>;
|
|
16
17
|
timeout?: number;
|
|
17
18
|
debug?: boolean;
|
|
18
19
|
retryConfig?: RetryConfig;
|
|
19
20
|
}
|
|
20
|
-
export declare const createClient: ({ baseUrl, responseType, headers, timeout, debug, retryConfig, }: ClientProps) => HttpClient;
|
|
21
|
+
export declare const createClient: ({ baseUrl, responseType, headers, timeout, params, debug, retryConfig, }: ClientProps) => HttpClient;
|
|
21
22
|
export declare const handleErrors: (error: unknown) => unknown;
|
|
22
23
|
declare type SendRawRequestValues = ActionInputParameters<typeof inputs>;
|
|
23
24
|
export declare const sendRawRequest: (baseUrl: string, values: SendRawRequestValues, authorizationHeaders?: Record<string, string>) => Promise<AxiosResponse>;
|
|
@@ -89,12 +89,13 @@ const toAxiosRetryConfig = (_a) => {
|
|
|
89
89
|
var { retryDelay, retryAllErrors, retryCondition, useExponentialBackoff } = _a, rest = __rest(_a, ["retryDelay", "retryAllErrors", "retryCondition", "useExponentialBackoff"]);
|
|
90
90
|
return (Object.assign(Object.assign({}, rest), { retryDelay: computeRetryDelay(retryDelay, useExponentialBackoff), retryCondition: retryAllErrors ? () => true : retryCondition }));
|
|
91
91
|
};
|
|
92
|
-
const createClient = ({ baseUrl, responseType, headers, timeout, debug = false, retryConfig, }) => {
|
|
92
|
+
const createClient = ({ baseUrl, responseType, headers, timeout, params, debug = false, retryConfig, }) => {
|
|
93
93
|
const client = axios_1.default.create({
|
|
94
94
|
baseURL: baseUrl,
|
|
95
95
|
responseType,
|
|
96
96
|
headers,
|
|
97
97
|
timeout,
|
|
98
|
+
params,
|
|
98
99
|
maxContentLength: Infinity,
|
|
99
100
|
maxBodyLength: Infinity,
|
|
100
101
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* authors create inputs, actions, and components that can
|
|
4
4
|
* be processed by the Prismatic API.
|
|
5
5
|
*/
|
|
6
|
-
import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult } from "./types";
|
|
6
|
+
import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, DataSourceResult } from "./types";
|
|
7
7
|
import { convertComponent } from "./serverTypes/convert";
|
|
8
8
|
/**
|
|
9
9
|
* This function creates a component object that can be
|
|
@@ -34,6 +34,16 @@ export declare const action: <TInputs extends Inputs, TAllowsBranching extends b
|
|
|
34
34
|
* @returns This function validates the shape of the `definition` object provided, and returns the same trigger object.
|
|
35
35
|
*/
|
|
36
36
|
export declare const trigger: <TInputs extends Inputs, TAllowsBranching extends boolean, TResult extends TriggerResult<TAllowsBranching>>(definition: TriggerDefinition<TInputs, TAllowsBranching, TResult>) => TriggerDefinition<TInputs, TAllowsBranching, TResult>;
|
|
37
|
+
/**
|
|
38
|
+
* This function creates a data source object that can be referenced
|
|
39
|
+
* by a custom component. It helps ensure that the shape of the
|
|
40
|
+
* data source object conforms to what the Prismatic API expects.
|
|
41
|
+
* For information on writing custom component data sources, see
|
|
42
|
+
* https://prismatic.io/docs/custom-components/writing-custom-components/#writing-data-sources.
|
|
43
|
+
* @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.
|
|
44
|
+
* @returns This function validates the shape of the `definition` object provided, and returns the same data source object.
|
|
45
|
+
*/
|
|
46
|
+
export declare const dataSource: <TInputs extends Inputs, TResult extends DataSourceResult<unknown>>(definition: DataSourceDefinition<TInputs, TResult>) => DataSourceDefinition<TInputs, TResult>;
|
|
37
47
|
/**
|
|
38
48
|
* For information and examples on how to write inputs
|
|
39
49
|
* for custom component actions and triggers, see
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.testing = exports.util = exports.oauth2Connection = exports.connection = exports.input = exports.trigger = exports.action = exports.component = void 0;
|
|
25
|
+
exports.testing = exports.util = exports.oauth2Connection = exports.connection = exports.input = exports.dataSource = exports.trigger = exports.action = exports.component = void 0;
|
|
26
26
|
const convert_1 = require("./serverTypes/convert");
|
|
27
27
|
/**
|
|
28
28
|
* This function creates a component object that can be
|
|
@@ -56,6 +56,17 @@ exports.action = action;
|
|
|
56
56
|
*/
|
|
57
57
|
const trigger = (definition) => definition;
|
|
58
58
|
exports.trigger = trigger;
|
|
59
|
+
/**
|
|
60
|
+
* This function creates a data source object that can be referenced
|
|
61
|
+
* by a custom component. It helps ensure that the shape of the
|
|
62
|
+
* data source object conforms to what the Prismatic API expects.
|
|
63
|
+
* For information on writing custom component data sources, see
|
|
64
|
+
* https://prismatic.io/docs/custom-components/writing-custom-components/#writing-data-sources.
|
|
65
|
+
* @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.
|
|
66
|
+
* @returns This function validates the shape of the `definition` object provided, and returns the same data source object.
|
|
67
|
+
*/
|
|
68
|
+
const dataSource = (definition) => definition;
|
|
69
|
+
exports.dataSource = dataSource;
|
|
59
70
|
/**
|
|
60
71
|
* For information and examples on how to write inputs
|
|
61
72
|
* for custom component actions and triggers, see
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ComponentDefinition } from "../types";
|
|
2
2
|
import { Component as ServerComponent } from ".";
|
|
3
|
-
export declare const convertComponent: <TPublic extends boolean>({ connections, actions, triggers, hooks, ...definition }: ComponentDefinition<TPublic>) => ServerComponent;
|
|
3
|
+
export declare const convertComponent: <TPublic extends boolean>({ connections, actions, triggers, dataSources, hooks, ...definition }: ComponentDefinition<TPublic>) => ServerComponent;
|
|
@@ -39,15 +39,24 @@ const convertTrigger = (triggerKey, _a, hooks) => {
|
|
|
39
39
|
errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
|
|
40
40
|
}) });
|
|
41
41
|
};
|
|
42
|
+
const convertDataSource = (dataSourceKey, _a, hooks) => {
|
|
43
|
+
var { inputs = {}, perform } = _a, dataSource = __rest(_a, ["inputs", "perform"]);
|
|
44
|
+
const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
|
|
45
|
+
return Object.assign(Object.assign({}, dataSource), { key: dataSourceKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
|
|
46
|
+
inputCleaners: {},
|
|
47
|
+
errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
|
|
48
|
+
}) });
|
|
49
|
+
};
|
|
42
50
|
const convertConnection = (_a) => {
|
|
43
51
|
var { inputs = {} } = _a, connection = __rest(_a, ["inputs"]);
|
|
44
52
|
const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
|
|
45
53
|
return Object.assign(Object.assign({}, connection), { inputs: convertedInputs });
|
|
46
54
|
};
|
|
47
55
|
const convertComponent = (_a) => {
|
|
48
|
-
var { connections = [], actions = {}, triggers = {}, hooks } = _a, definition = __rest(_a, ["connections", "actions", "triggers", "hooks"]);
|
|
56
|
+
var { connections = [], actions = {}, triggers = {}, dataSources = {}, hooks } = _a, definition = __rest(_a, ["connections", "actions", "triggers", "dataSources", "hooks"]);
|
|
49
57
|
const convertedActions = Object.entries(actions).reduce((result, [actionKey, action]) => (Object.assign(Object.assign({}, result), { [actionKey]: convertAction(actionKey, action, hooks) })), {});
|
|
50
58
|
const convertedTriggers = Object.entries(triggers).reduce((result, [triggerKey, trigger]) => (Object.assign(Object.assign({}, result), { [triggerKey]: convertTrigger(triggerKey, trigger, hooks) })), {});
|
|
51
|
-
|
|
59
|
+
const convertedDataSources = Object.entries(dataSources).reduce((result, [dataSourceKey, dataSource]) => (Object.assign(Object.assign({}, result), { [dataSourceKey]: convertDataSource(dataSourceKey, dataSource, hooks) })), {});
|
|
60
|
+
return Object.assign(Object.assign({}, definition), { connections: connections.map(convertConnection), actions: convertedActions, triggers: convertedTriggers, dataSources: convertedDataSources });
|
|
52
61
|
};
|
|
53
62
|
exports.convertComponent = convertComponent;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { DataSourceType } from "../types";
|
|
2
3
|
interface DisplayDefinition {
|
|
3
4
|
label: string;
|
|
4
5
|
description: string;
|
|
@@ -13,6 +14,7 @@ export interface Component {
|
|
|
13
14
|
};
|
|
14
15
|
actions: Record<string, Action>;
|
|
15
16
|
triggers: Record<string, Trigger>;
|
|
17
|
+
dataSources: Record<string, DataSource>;
|
|
16
18
|
connections: Connection[];
|
|
17
19
|
}
|
|
18
20
|
export interface Action {
|
|
@@ -47,6 +49,18 @@ export interface ActionContext {
|
|
|
47
49
|
executionState: Record<string, unknown>;
|
|
48
50
|
stepId: string;
|
|
49
51
|
executionId: string;
|
|
52
|
+
webhookUrls: Record<string, string>;
|
|
53
|
+
webhookApiKeys: Record<string, string[]>;
|
|
54
|
+
invokeUrl: string;
|
|
55
|
+
customer: {
|
|
56
|
+
id: string | null;
|
|
57
|
+
externalId: string | null;
|
|
58
|
+
name: string | null;
|
|
59
|
+
};
|
|
60
|
+
instance: {
|
|
61
|
+
id: string | null;
|
|
62
|
+
name: string | null;
|
|
63
|
+
};
|
|
50
64
|
}
|
|
51
65
|
declare type TriggerOptionChoice = "invalid" | "valid" | "required";
|
|
52
66
|
export interface TriggerPayload {
|
|
@@ -113,6 +127,24 @@ export interface Trigger {
|
|
|
113
127
|
examplePayload?: unknown;
|
|
114
128
|
isCommonTrigger?: boolean;
|
|
115
129
|
}
|
|
130
|
+
export declare type DataSourceResult = {
|
|
131
|
+
content: DataSourceType;
|
|
132
|
+
supplementalData: {
|
|
133
|
+
data: unknown;
|
|
134
|
+
contentType: string;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
export declare type DataSourcePerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<DataSourceResult>;
|
|
138
|
+
export interface DataSource {
|
|
139
|
+
key: string;
|
|
140
|
+
display: DisplayDefinition & {
|
|
141
|
+
directions?: string;
|
|
142
|
+
important?: boolean;
|
|
143
|
+
};
|
|
144
|
+
inputs: Input[];
|
|
145
|
+
perform: DataSourcePerformFunction;
|
|
146
|
+
examplePayload?: unknown;
|
|
147
|
+
}
|
|
116
148
|
export declare enum OAuth2Type {
|
|
117
149
|
ClientCredentials = "client_credentials",
|
|
118
150
|
AuthorizationCode = "authorization_code"
|
package/dist/testing.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* information on unit testing, check out our docs:
|
|
5
5
|
* https://prismatic.io/docs/custom-components/writing-custom-components/#testing-a-component
|
|
6
6
|
*/
|
|
7
|
-
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn } from "./serverTypes";
|
|
8
|
-
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult } from "./types";
|
|
7
|
+
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult } from "./serverTypes";
|
|
8
|
+
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult } from "./types";
|
|
9
9
|
export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>) => ConnectionValue;
|
|
10
10
|
/**
|
|
11
11
|
* Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
|
|
@@ -34,12 +34,20 @@ export declare const defaultTriggerPayload: () => TriggerPayload;
|
|
|
34
34
|
* trigger result and a mock logger for asserting logging.
|
|
35
35
|
*/
|
|
36
36
|
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>>;
|
|
37
|
+
/**
|
|
38
|
+
* Invokes specified DataSourceDefinition perform function using supplied params
|
|
39
|
+
* and optional context. Accepts a generic type matching DataSourceResult as a convenience
|
|
40
|
+
* to avoid extra casting within test methods. Returns an InvokeResult containing both the
|
|
41
|
+
* action result and a mock logger for asserting logging.
|
|
42
|
+
*/
|
|
43
|
+
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>>;
|
|
37
44
|
export declare class ComponentTestHarness<TComponent extends Component> {
|
|
38
45
|
component: TComponent;
|
|
39
46
|
constructor(component: TComponent);
|
|
40
47
|
connectionValue({ key }: ConnectionDefinition): ConnectionValue;
|
|
41
48
|
trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>;
|
|
42
49
|
action(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<ActionPerformReturn>;
|
|
50
|
+
dataSource(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<DataSourceResult>;
|
|
43
51
|
}
|
|
44
52
|
export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
|
|
45
53
|
declare const _default: {
|
|
@@ -47,5 +55,6 @@ declare const _default: {
|
|
|
47
55
|
invoke: <TInputs extends Inputs, TAllowsBranching extends boolean, TReturn extends InvokeActionPerformReturn<TAllowsBranching, unknown>>({ perform }: ActionDefinition<TInputs, TAllowsBranching, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn>>;
|
|
48
56
|
invokeTrigger: <TInputs_1 extends Inputs, TAllowsBranching_1 extends boolean, TResult extends InvokeTriggerResult<TAllowsBranching_1>>({ perform }: TriggerDefinition<TInputs_1, TAllowsBranching_1, TResult>, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs_1> | undefined) => Promise<InvokeReturn<TResult>>;
|
|
49
57
|
createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
|
|
58
|
+
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>>;
|
|
50
59
|
};
|
|
51
60
|
export default _default;
|
package/dist/testing.js
CHANGED
|
@@ -15,7 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.createHarness = exports.ComponentTestHarness = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.createConnection = void 0;
|
|
18
|
+
exports.createHarness = exports.ComponentTestHarness = exports.invokeDataSource = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.createConnection = void 0;
|
|
19
19
|
const jest_mock_1 = require("jest-mock");
|
|
20
20
|
const createConnection = ({ key }, values) => ({
|
|
21
21
|
configVarKey: "",
|
|
@@ -37,6 +37,30 @@ const loggerMock = () => ({
|
|
|
37
37
|
error: (0, jest_mock_1.spyOn)(console, "error"),
|
|
38
38
|
});
|
|
39
39
|
exports.loggerMock = loggerMock;
|
|
40
|
+
const baseContext = {
|
|
41
|
+
logger: (0, exports.loggerMock)(),
|
|
42
|
+
instanceState: {},
|
|
43
|
+
crossFlowState: {},
|
|
44
|
+
executionState: {},
|
|
45
|
+
stepId: "mockStepId",
|
|
46
|
+
executionId: "mockExecutionId",
|
|
47
|
+
webhookUrls: {
|
|
48
|
+
"Flow 1": "https://example.com",
|
|
49
|
+
},
|
|
50
|
+
webhookApiKeys: {
|
|
51
|
+
"Flow 1": ["example-123", "example-456"],
|
|
52
|
+
},
|
|
53
|
+
invokeUrl: "https://example.com",
|
|
54
|
+
customer: {
|
|
55
|
+
id: "customerId",
|
|
56
|
+
name: "Customer 1",
|
|
57
|
+
externalId: "1234",
|
|
58
|
+
},
|
|
59
|
+
instance: {
|
|
60
|
+
id: "instanceId",
|
|
61
|
+
name: "Instance 1",
|
|
62
|
+
},
|
|
63
|
+
};
|
|
40
64
|
/**
|
|
41
65
|
* Invokes specified ActionDefinition perform function using supplied params
|
|
42
66
|
* and optional context. Accepts a generic type matching ActionPerformReturn as a convenience
|
|
@@ -44,7 +68,7 @@ exports.loggerMock = loggerMock;
|
|
|
44
68
|
* action result and a mock logger for asserting logging.
|
|
45
69
|
*/
|
|
46
70
|
const invoke = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
const realizedContext = Object.assign(
|
|
71
|
+
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
|
|
48
72
|
const result = yield perform(realizedContext, params);
|
|
49
73
|
return {
|
|
50
74
|
result,
|
|
@@ -96,7 +120,7 @@ exports.defaultTriggerPayload = defaultTriggerPayload;
|
|
|
96
120
|
* trigger result and a mock logger for asserting logging.
|
|
97
121
|
*/
|
|
98
122
|
const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
-
const realizedContext = Object.assign(
|
|
123
|
+
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
|
|
100
124
|
const realizedPayload = Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload);
|
|
101
125
|
const realizedParams = params || {};
|
|
102
126
|
const result = yield perform(realizedContext, realizedPayload, realizedParams);
|
|
@@ -106,6 +130,21 @@ const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void
|
|
|
106
130
|
};
|
|
107
131
|
});
|
|
108
132
|
exports.invokeTrigger = invokeTrigger;
|
|
133
|
+
/**
|
|
134
|
+
* Invokes specified DataSourceDefinition perform function using supplied params
|
|
135
|
+
* and optional context. Accepts a generic type matching DataSourceResult as a convenience
|
|
136
|
+
* to avoid extra casting within test methods. Returns an InvokeResult containing both the
|
|
137
|
+
* action result and a mock logger for asserting logging.
|
|
138
|
+
*/
|
|
139
|
+
const invokeDataSource = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
|
|
141
|
+
const result = yield perform(realizedContext, params);
|
|
142
|
+
return {
|
|
143
|
+
result,
|
|
144
|
+
loggerMock: realizedContext.logger,
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
exports.invokeDataSource = invokeDataSource;
|
|
109
148
|
class ComponentTestHarness {
|
|
110
149
|
constructor(component) {
|
|
111
150
|
this.component = component;
|
|
@@ -120,18 +159,25 @@ class ComponentTestHarness {
|
|
|
120
159
|
}
|
|
121
160
|
trigger(key, payload, params, context) {
|
|
122
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
const realizedContext = Object.assign(
|
|
162
|
+
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
|
|
124
163
|
const trigger = this.component.triggers[key];
|
|
125
164
|
return trigger.perform(realizedContext, Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), Object.assign({}, params));
|
|
126
165
|
});
|
|
127
166
|
}
|
|
128
167
|
action(key, params, context) {
|
|
129
168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
const realizedContext = Object.assign(
|
|
169
|
+
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
|
|
131
170
|
const action = this.component.actions[key];
|
|
132
171
|
return action.perform(realizedContext, Object.assign({}, params));
|
|
133
172
|
});
|
|
134
173
|
}
|
|
174
|
+
dataSource(key, params, context) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
|
|
177
|
+
const dataSource = this.component.dataSources[key];
|
|
178
|
+
return dataSource.perform(realizedContext, Object.assign({}, params));
|
|
179
|
+
});
|
|
180
|
+
}
|
|
135
181
|
}
|
|
136
182
|
exports.ComponentTestHarness = ComponentTestHarness;
|
|
137
183
|
const createHarness = (component) => {
|
|
@@ -143,4 +189,5 @@ exports.default = {
|
|
|
143
189
|
invoke: exports.invoke,
|
|
144
190
|
invokeTrigger: exports.invokeTrigger,
|
|
145
191
|
createHarness: exports.createHarness,
|
|
192
|
+
invokeDataSource: exports.invokeDataSource,
|
|
146
193
|
};
|
|
@@ -15,4 +15,21 @@ export interface ActionContext {
|
|
|
15
15
|
stepId: string;
|
|
16
16
|
/** A unique id that corresponds to the specific execution of the Integration */
|
|
17
17
|
executionId: string;
|
|
18
|
+
/** An object containing webhook URLs for all flows of the currently running instance */
|
|
19
|
+
webhookUrls: Record<string, string>;
|
|
20
|
+
/** An object containing webhook API keys for all flows of the currently running instance */
|
|
21
|
+
webhookApiKeys: Record<string, string[]>;
|
|
22
|
+
/** The URL used to invoke the current execution */
|
|
23
|
+
invokeUrl: string;
|
|
24
|
+
/** An object containing the ID, External ID and name of the customer the instance is deployed to */
|
|
25
|
+
customer: {
|
|
26
|
+
id: string | null;
|
|
27
|
+
externalId: string | null;
|
|
28
|
+
name: string | null;
|
|
29
|
+
};
|
|
30
|
+
/** An object containing the ID ad name of the currently running instance */
|
|
31
|
+
instance: {
|
|
32
|
+
id: string | null;
|
|
33
|
+
name: string | null;
|
|
34
|
+
};
|
|
18
35
|
}
|
|
@@ -12,7 +12,7 @@ export interface ActionPerformDataReturn<ReturnData> {
|
|
|
12
12
|
crossFlowState?: Record<string, unknown>;
|
|
13
13
|
/** An optional object, the keys and values of which will be persisted in the executionState and available for the duration of the execution */
|
|
14
14
|
executionState?: Record<string, unknown>;
|
|
15
|
-
/** A field populated by the Prismatic platform which indicates whether the
|
|
15
|
+
/** A field populated by the Prismatic platform which indicates whether the action failed with an error during execution. */
|
|
16
16
|
failed?: boolean;
|
|
17
17
|
/** A field populated by the Prismatic platform which may refer to an object that contains data about any error that resulted in failure. */
|
|
18
18
|
error?: Record<string, unknown>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionDefinition, ConnectionDefinition, ComponentDisplayDefinition, TriggerDefinition } from ".";
|
|
1
|
+
import { ActionDefinition, ConnectionDefinition, ComponentDisplayDefinition, TriggerDefinition, DataSourceDefinition } from ".";
|
|
2
2
|
export declare type ErrorHandler = (error: unknown) => unknown;
|
|
3
3
|
export interface ComponentHooks {
|
|
4
4
|
/** Defines a global error handler that automatically wraps the component's action/trigger perform functions. */
|
|
@@ -16,6 +16,8 @@ export declare type ComponentDefinition<TPublic extends boolean> = {
|
|
|
16
16
|
actions?: Record<string, ActionDefinition<any, boolean, any>>;
|
|
17
17
|
/** Specifies the supported Triggers of this Component. */
|
|
18
18
|
triggers?: Record<string, TriggerDefinition<any, boolean, any>>;
|
|
19
|
+
/** Specifies the supported Data Sources of this Component. */
|
|
20
|
+
dataSources?: Record<string, DataSourceDefinition<any, any>>;
|
|
19
21
|
/** Specifies the supported Connections of this Component. */
|
|
20
22
|
connections?: ConnectionDefinition[];
|
|
21
23
|
/** Hooks */
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ActionDisplayDefinition, DataSourcePerformFunction, Inputs, DataSourceResult, DataSourceType } from ".";
|
|
2
|
+
/**
|
|
3
|
+
* DataSourceDefinition is the type of the object that is passed in to `dataSource` function to
|
|
4
|
+
* define a component Data Source.
|
|
5
|
+
*/
|
|
6
|
+
export interface DataSourceDefinition<TInputs extends Inputs, TDataSourceResult extends DataSourceResult<DataSourceType>> {
|
|
7
|
+
/** Defines how the Data Source is displayed in the Prismatic interface. */
|
|
8
|
+
display: ActionDisplayDefinition;
|
|
9
|
+
/** Function to perform when this Data Source is invoked. */
|
|
10
|
+
perform: DataSourcePerformFunction<TInputs, TDataSourceResult>;
|
|
11
|
+
/** InputFields to present in the Prismatic interface for configuration of this Data Source. */
|
|
12
|
+
inputs: TInputs;
|
|
13
|
+
/** An example of the payload outputted by this Data Source. */
|
|
14
|
+
examplePayload?: Awaited<ReturnType<this["perform"]>>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Inputs, DataSourceResult, DataSourceType, ActionInputParameters, ActionContext } from ".";
|
|
2
|
+
/** Definition of the function to perform when a Data Source is invoked. */
|
|
3
|
+
export declare type DataSourcePerformFunction<T extends Inputs, TResult extends DataSourceResult<DataSourceType>> = (context: ActionContext, params: ActionInputParameters<T>) => Promise<TResult>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Represents the result of a Data Source action. */
|
|
2
|
+
export declare type DataSourceResult<ContentData> = {
|
|
3
|
+
/** The data that will be used as content. */
|
|
4
|
+
content: ContentData;
|
|
5
|
+
/** Additional data that may be useful for out-of-band processing at a later time. */
|
|
6
|
+
supplementalData?: {
|
|
7
|
+
data: unknown;
|
|
8
|
+
contentType: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare type ObjectSelection = {
|
|
3
|
+
key: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
fields: {
|
|
6
|
+
key: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
}[];
|
|
9
|
+
}[];
|
|
10
|
+
export declare type ObjectFieldMap = {
|
|
11
|
+
key: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
value: {
|
|
14
|
+
objectKey: string;
|
|
15
|
+
objectLabel?: string;
|
|
16
|
+
fieldKey: string;
|
|
17
|
+
fieldLabel?: string;
|
|
18
|
+
};
|
|
19
|
+
}[];
|
|
20
|
+
export declare type DataSourceType = ObjectSelection | ObjectFieldMap | Buffer | boolean | number | string | Record<string, unknown> | unknown[] | unknown;
|
package/dist/types/Inputs.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConditionalExpression } from "./conditional-logic";
|
|
2
|
+
import { ObjectSelection, ObjectFieldMap } from "./DataSourceType";
|
|
2
3
|
/** InputField type enumeration. */
|
|
3
4
|
export declare type InputFieldType = InputFieldDefinition["type"];
|
|
4
5
|
export declare const InputFieldDefaultMap: Record<InputFieldType, string | undefined>;
|
|
@@ -6,7 +7,7 @@ export declare type Inputs = Record<string, InputFieldDefinition>;
|
|
|
6
7
|
export declare type ConnectionInput = (StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField) & {
|
|
7
8
|
shown?: boolean;
|
|
8
9
|
};
|
|
9
|
-
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField;
|
|
10
|
+
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField;
|
|
10
11
|
export declare type InputCleanFunction<TValue, TResult = TValue> = (value: TValue) => TResult;
|
|
11
12
|
interface BaseInputField {
|
|
12
13
|
/** Interface label of the InputField. */
|
|
@@ -132,6 +133,28 @@ export interface Connection {
|
|
|
132
133
|
token?: Record<string, unknown>;
|
|
133
134
|
context?: Record<string, unknown>;
|
|
134
135
|
}
|
|
136
|
+
/** Defines attributes of an ObjectSelectionInputField. */
|
|
137
|
+
export interface ObjectSelectionInputField extends BaseInputField {
|
|
138
|
+
/** Data type the InputField will collect. */
|
|
139
|
+
type: "objectselection";
|
|
140
|
+
/** Collection type of the InputField */
|
|
141
|
+
collection?: InputFieldCollection;
|
|
142
|
+
/** Default value for this field. */
|
|
143
|
+
default?: ObjectSelection;
|
|
144
|
+
/** Clean function */
|
|
145
|
+
clean?: InputCleanFunction<NonNullable<this["default"]>>;
|
|
146
|
+
}
|
|
147
|
+
/** Defines attributes of an ObjectFieldMapInputField. */
|
|
148
|
+
export interface ObjectFieldMapInputField extends BaseInputField {
|
|
149
|
+
/** Data type the InputField will collect. */
|
|
150
|
+
type: "objectfieldmap";
|
|
151
|
+
/** Collection type of the InputField */
|
|
152
|
+
collection?: InputFieldCollection;
|
|
153
|
+
/** Default value for this field. */
|
|
154
|
+
default?: ObjectFieldMap;
|
|
155
|
+
/** Clean function */
|
|
156
|
+
clean?: InputCleanFunction<NonNullable<this["default"]>>;
|
|
157
|
+
}
|
|
135
158
|
/** Defines a single Choice option for a InputField. */
|
|
136
159
|
export interface InputFieldChoice {
|
|
137
160
|
/** Label to display for this Choice. */
|
package/dist/types/Inputs.js
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -18,3 +18,7 @@ export * from "./TriggerPerformFunction";
|
|
|
18
18
|
export * from "./TriggerDefinition";
|
|
19
19
|
export * from "./HttpResponse";
|
|
20
20
|
export * from "./TriggerPayload";
|
|
21
|
+
export * from "./DataSourceDefinition";
|
|
22
|
+
export * from "./DataSourcePerformFunction";
|
|
23
|
+
export * from "./DataSourceResult";
|
|
24
|
+
export * from "./DataSourceType";
|
package/dist/types/index.js
CHANGED
|
@@ -34,3 +34,7 @@ __exportStar(require("./TriggerPerformFunction"), exports);
|
|
|
34
34
|
__exportStar(require("./TriggerDefinition"), exports);
|
|
35
35
|
__exportStar(require("./HttpResponse"), exports);
|
|
36
36
|
__exportStar(require("./TriggerPayload"), exports);
|
|
37
|
+
__exportStar(require("./DataSourceDefinition"), exports);
|
|
38
|
+
__exportStar(require("./DataSourcePerformFunction"), exports);
|
|
39
|
+
__exportStar(require("./DataSourceResult"), exports);
|
|
40
|
+
__exportStar(require("./DataSourceType"), exports);
|
package/dist/util.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Many functions in the `util` module are used to coerce data into a particular type, and can be accessed through `util.types`.
|
|
4
4
|
* For example, `util.types.toInt("5.5")` will return an integer, `5`.
|
|
5
5
|
*/
|
|
6
|
-
import { KeyValuePair, DataPayload } from "./types";
|
|
6
|
+
import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap } from "./types";
|
|
7
7
|
/**
|
|
8
8
|
* This function returns a lower cased version of the headers passed to it.
|
|
9
9
|
*
|
|
@@ -36,6 +36,10 @@ declare const _default: {
|
|
|
36
36
|
isJSON: (value: string) => boolean;
|
|
37
37
|
toJSON: (value: unknown) => string;
|
|
38
38
|
lowerCaseHeaders: (headers: Record<string, string>) => Record<string, string>;
|
|
39
|
+
isObjectSelection: (value: unknown) => value is ObjectSelection;
|
|
40
|
+
toObjectSelection: (value: unknown) => ObjectSelection;
|
|
41
|
+
isObjectFieldMap: (value: unknown) => value is ObjectFieldMap;
|
|
42
|
+
toObjectFieldMap: (value: unknown) => ObjectFieldMap;
|
|
39
43
|
};
|
|
40
44
|
docs: {
|
|
41
45
|
formatJsonExample: (input: unknown) => string;
|
package/dist/util.js
CHANGED
|
@@ -15,6 +15,81 @@ const isValid_1 = __importDefault(require("date-fns/isValid"));
|
|
|
15
15
|
const isDate_1 = __importDefault(require("date-fns/isDate"));
|
|
16
16
|
const safe_stable_stringify_1 = require("safe-stable-stringify");
|
|
17
17
|
const valid_url_1 = require("valid-url");
|
|
18
|
+
const isObjectWithTruthyKeys = (value, keys) => {
|
|
19
|
+
return (value !== null &&
|
|
20
|
+
typeof value === "object" &&
|
|
21
|
+
keys.every((key) => key in value && Boolean(value === null || value === void 0 ? void 0 : value[key])));
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* @param value The value to test
|
|
25
|
+
* @returns This function returns true if the type of `value` is an ObjectSelection, or false otherwise.
|
|
26
|
+
*/
|
|
27
|
+
const isObjectSelection = (value) => {
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
for (const selection of value) {
|
|
30
|
+
if (isObjectWithTruthyKeys(selection, ["key", "fields"])) {
|
|
31
|
+
const { fields } = selection;
|
|
32
|
+
if (!Array.isArray(fields) ||
|
|
33
|
+
fields.length === 0 ||
|
|
34
|
+
!fields.every((field) => isObjectWithTruthyKeys(field, ["key"]))) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* This function coerces a provided value into an ObjectSelection if possible.
|
|
50
|
+
* @param value The value to coerce to ObjectSelection.
|
|
51
|
+
* @returns This function returns the the value as an ObjectSelection if possible.
|
|
52
|
+
*/
|
|
53
|
+
const toObjectSelection = (value) => {
|
|
54
|
+
if (isObjectSelection(value)) {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
throw new Error(`Value '${value}' cannot be coerced to ObjectSelection.`);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* @param value The value to test
|
|
61
|
+
* @returns This function returns true if the type of `value` is an ObjectFieldMap, or false otherwise.
|
|
62
|
+
*/
|
|
63
|
+
const isObjectFieldMap = (value) => {
|
|
64
|
+
if (Array.isArray(value)) {
|
|
65
|
+
for (const fieldMap of value) {
|
|
66
|
+
if (isObjectWithTruthyKeys(fieldMap, ["key", "value"])) {
|
|
67
|
+
const { value: val } = fieldMap;
|
|
68
|
+
if (!isObjectWithTruthyKeys(val, ["objectKey", "fieldKey"])) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* This function coerces a provided value into an ObjectFieldMap if possible.
|
|
84
|
+
* @param value The value to coerce to ObjectFieldMap.
|
|
85
|
+
* @returns This function returns the the value as an ObjectFieldMap if possible.
|
|
86
|
+
*/
|
|
87
|
+
const toObjectFieldMap = (value) => {
|
|
88
|
+
if (isObjectFieldMap(value)) {
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`Value '${value}' cannot be coerced to ObjectFieldMap.`);
|
|
92
|
+
};
|
|
18
93
|
/**
|
|
19
94
|
* Determine if a variable is a boolean (true or false).
|
|
20
95
|
*
|
|
@@ -26,16 +101,16 @@ const valid_url_1 = require("valid-url");
|
|
|
26
101
|
*/
|
|
27
102
|
const isBool = (value) => value === true || value === false;
|
|
28
103
|
/**
|
|
29
|
-
* Convert
|
|
30
|
-
* and
|
|
31
|
-
* Truthy/
|
|
104
|
+
* Convert truthy (true, "t", "true", "y", "yes") values to boolean `true`,
|
|
105
|
+
* and falsy (false, "f", "false", "n", "no") values to boolean `false`.
|
|
106
|
+
* Truthy/falsy checks are case-insensitive.
|
|
32
107
|
*
|
|
33
108
|
* In the event that `value` is undefined or an empty string, a default value can be provided.
|
|
34
109
|
* For example, `util.types.toBool('', true)` will return `true`.
|
|
35
110
|
*
|
|
36
111
|
* @param value The value to convert to a boolean.
|
|
37
112
|
* @param defaultValue The value to return if `value` is undefined or an empty string.
|
|
38
|
-
* @returns The boolean equivalent of the
|
|
113
|
+
* @returns The boolean equivalent of the truthy or falsy `value`.
|
|
39
114
|
*/
|
|
40
115
|
const toBool = (value, defaultValue) => {
|
|
41
116
|
if (isBool(value)) {
|
|
@@ -357,6 +432,10 @@ exports.default = {
|
|
|
357
432
|
isJSON,
|
|
358
433
|
toJSON,
|
|
359
434
|
lowerCaseHeaders: exports.lowerCaseHeaders,
|
|
435
|
+
isObjectSelection,
|
|
436
|
+
toObjectSelection,
|
|
437
|
+
isObjectFieldMap,
|
|
438
|
+
toObjectFieldMap,
|
|
360
439
|
},
|
|
361
440
|
docs: {
|
|
362
441
|
formatJsonExample,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismatic-io/spectral",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-pre",
|
|
4
4
|
"description": "Utility library for building Prismatic components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"prismatic"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"check": "yarn run check-format && yarn run lint",
|
|
30
30
|
"lint": "eslint --ext .ts .",
|
|
31
31
|
"lint-fix": "eslint --fix --ext .ts .",
|
|
32
|
-
"test": "jest
|
|
32
|
+
"test": "jest",
|
|
33
33
|
"tsd": "tsd",
|
|
34
34
|
"docs": "rm -f sidebars.{js,jse} && typedoc"
|
|
35
35
|
},
|