@prismatic-io/spectral 10.2.3 → 10.3.1
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/generators/componentManifest/getInputs.js +2 -0
- package/dist/serverTypes/convertIntegration.js +2 -1
- package/dist/serverTypes/index.d.ts +4 -2
- package/dist/serverTypes/index.js +2 -0
- package/dist/serverTypes/perform.d.ts +4 -1
- package/dist/serverTypes/perform.js +23 -3
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +14 -1
- package/dist/types/ActionPerformFunction.d.ts +25 -1
- package/dist/types/Inputs.d.ts +23 -1
- package/dist/types/Inputs.js +2 -0
- package/dist/types/PollingTriggerDefinition.d.ts +1 -1
- package/package.json +1 -1
|
@@ -20,6 +20,7 @@ const types_1 = require("../types");
|
|
|
20
20
|
const convertComponent_1 = require("./convertComponent");
|
|
21
21
|
const integration_1 = require("./integration");
|
|
22
22
|
const lodash_2 = require("lodash");
|
|
23
|
+
const perform_1 = require("./perform");
|
|
23
24
|
const convertIntegration = (definition) => {
|
|
24
25
|
var _a, _b, _c;
|
|
25
26
|
// Generate a unique reference key that will be used to reference the
|
|
@@ -546,7 +547,7 @@ const convertOnExecution = (onExecution, componentRegistry) => (context, params)
|
|
|
546
547
|
}, {});
|
|
547
548
|
return Object.assign(Object.assign({}, accumulator), { [registryComponentKey]: componentActions });
|
|
548
549
|
}, {});
|
|
549
|
-
return onExecution(Object.assign(Object.assign({}, context), { components: componentMethods }), params);
|
|
550
|
+
return onExecution(Object.assign(Object.assign({}, context), { components: componentMethods, invokeFlow: (0, perform_1.createInvokeFlow)(context, { isCNI: true }) }), params);
|
|
550
551
|
};
|
|
551
552
|
/** Creates the structure necessary to import a Component as part of a
|
|
552
553
|
* Code Native integration. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InstanceAttributes, CustomerAttributes, DataSourceType, DataSourceResultType, UserAttributes, TriggerEventFunctionReturn, IntegrationAttributes, FlowAttributes, ConfigVarResultCollection, ComponentManifest } from "../types";
|
|
1
|
+
import { InstanceAttributes, CustomerAttributes, DataSourceType, DataSourceResultType, UserAttributes, TriggerEventFunctionReturn, IntegrationAttributes, FlowAttributes, ConfigVarResultCollection, ComponentManifest, FlowInvoker, ExecutionFrame } from "../types";
|
|
2
2
|
interface DisplayDefinition {
|
|
3
3
|
label: string;
|
|
4
4
|
description: string;
|
|
@@ -47,7 +47,7 @@ export interface ActionLogger {
|
|
|
47
47
|
warn: ActionLoggerFunction;
|
|
48
48
|
error: ActionLoggerFunction;
|
|
49
49
|
}
|
|
50
|
-
export type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]
|
|
50
|
+
export type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]>, TFlows extends string[] = string[]> = {
|
|
51
51
|
logger: ActionLogger;
|
|
52
52
|
instanceState: Record<string, unknown>;
|
|
53
53
|
crossFlowState: Record<string, unknown>;
|
|
@@ -70,6 +70,8 @@ export type ActionContext<TConfigVars extends ConfigVarResultCollection = Config
|
|
|
70
70
|
integration: IntegrationAttributes;
|
|
71
71
|
flow: FlowAttributes;
|
|
72
72
|
startedAt: string;
|
|
73
|
+
invokeFlow: FlowInvoker<TFlows>;
|
|
74
|
+
executionFrame: ExecutionFrame;
|
|
73
75
|
};
|
|
74
76
|
type TriggerOptionChoice = "invalid" | "valid" | "required";
|
|
75
77
|
export interface TriggerPayload {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ErrorHandler, Inputs, PollingTriggerPerformFunction } from "../types";
|
|
1
|
+
import type { ActionContext, ErrorHandler, FlowInvoker, Inputs, PollingTriggerPerformFunction } from "../types";
|
|
2
2
|
import { type PollingTriggerDefinition } from "../types/PollingTriggerDefinition";
|
|
3
3
|
export type PerformFn = (...args: any[]) => Promise<any>;
|
|
4
4
|
export type CleanFn = (...args: any[]) => any;
|
|
@@ -8,6 +8,9 @@ interface CreatePerformProps {
|
|
|
8
8
|
errorHandler?: ErrorHandler;
|
|
9
9
|
}
|
|
10
10
|
export declare const cleanParams: (params: Record<string, unknown>, cleaners: InputCleaners) => Record<string, any>;
|
|
11
|
+
export declare const createInvokeFlow: <const TFlows extends Readonly<string[]>>(context: ActionContext, options?: {
|
|
12
|
+
isCNI?: boolean;
|
|
13
|
+
}) => FlowInvoker<TFlows>;
|
|
11
14
|
export declare const createPerform: (performFn: PerformFn, { inputCleaners, errorHandler }: CreatePerformProps) => PerformFn;
|
|
12
15
|
export declare const createPollingPerform: (trigger: PollingTriggerDefinition, { inputCleaners, errorHandler }: CreatePerformProps) => PollingTriggerPerformFunction<Inputs, Inputs>;
|
|
13
16
|
export {};
|
|
@@ -19,8 +19,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
}
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
22
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.createPollingPerform = exports.createPerform = exports.cleanParams = void 0;
|
|
26
|
+
exports.createPollingPerform = exports.createPerform = exports.createInvokeFlow = exports.cleanParams = void 0;
|
|
27
|
+
const axios_1 = __importDefault(require("axios"));
|
|
24
28
|
const lodash_1 = require("lodash");
|
|
25
29
|
const cleanParams = (params, cleaners) => {
|
|
26
30
|
const keys = (0, lodash_1.uniq)([...Object.keys(params), ...Object.keys(cleaners)]);
|
|
@@ -31,6 +35,21 @@ const cleanParams = (params, cleaners) => {
|
|
|
31
35
|
}, {});
|
|
32
36
|
};
|
|
33
37
|
exports.cleanParams = cleanParams;
|
|
38
|
+
function formatExecutionFrameHeaders(frame, source) {
|
|
39
|
+
let frameToUse = frame;
|
|
40
|
+
if (source) {
|
|
41
|
+
frameToUse = Object.assign(Object.assign({}, frame), { customSource: source });
|
|
42
|
+
}
|
|
43
|
+
return JSON.stringify(frameToUse);
|
|
44
|
+
}
|
|
45
|
+
const createInvokeFlow = (context, options = {}) => {
|
|
46
|
+
return (flowName, data, config, source) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
var _a;
|
|
48
|
+
const sourceToUse = options.isCNI ? source : undefined;
|
|
49
|
+
return yield axios_1.default.post(context.webhookUrls[flowName], data, Object.assign(Object.assign({}, config), { headers: Object.assign(Object.assign({}, ((_a = config === null || config === void 0 ? void 0 : config.headers) !== null && _a !== void 0 ? _a : {})), { "prismatic-invoked-by": formatExecutionFrameHeaders(context.executionFrame, sourceToUse) }) }));
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
exports.createInvokeFlow = createInvokeFlow;
|
|
34
53
|
const createPerform = (performFn, { inputCleaners, errorHandler }) => {
|
|
35
54
|
return (...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
55
|
try {
|
|
@@ -40,10 +59,10 @@ const createPerform = (performFn, { inputCleaners, errorHandler }) => {
|
|
|
40
59
|
}
|
|
41
60
|
if (args.length === 2) {
|
|
42
61
|
const [context, params] = args;
|
|
43
|
-
return yield performFn(context, (0, exports.cleanParams)(params, inputCleaners));
|
|
62
|
+
return yield performFn(Object.assign(Object.assign({}, context), { invokeFlow: (0, exports.createInvokeFlow)(context) }), (0, exports.cleanParams)(params, inputCleaners));
|
|
44
63
|
}
|
|
45
64
|
const [context, payload, params] = args;
|
|
46
|
-
return yield performFn(context, payload, (0, exports.cleanParams)(params, inputCleaners));
|
|
65
|
+
return yield performFn(Object.assign(Object.assign({}, context), { invokeFlow: (0, exports.createInvokeFlow)(context) }), payload, (0, exports.cleanParams)(params, inputCleaners));
|
|
47
66
|
}
|
|
48
67
|
catch (error) {
|
|
49
68
|
throw errorHandler ? errorHandler(error) : error;
|
|
@@ -69,6 +88,7 @@ const createPollingPerform = (trigger, { inputCleaners, errorHandler }) => {
|
|
|
69
88
|
try {
|
|
70
89
|
const { pollAction } = trigger;
|
|
71
90
|
const pollingContext = {
|
|
91
|
+
invokeFlow: (0, exports.createInvokeFlow)(context),
|
|
72
92
|
polling: {
|
|
73
93
|
invokeAction: createInvokePollAction(context, pollAction, {
|
|
74
94
|
inputCleaners,
|
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,
|
|
8
|
-
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceType, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow, ConfigVarResultCollection } from "./types";
|
|
7
|
+
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionPerformReturn, DataSourceResult, DataSourceContext } from "./serverTypes";
|
|
8
|
+
import { ActionContext, ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceType, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow, ConfigVarResultCollection } from "./types";
|
|
9
9
|
export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>, tokenValues?: Record<string, unknown>) => ConnectionValue;
|
|
10
10
|
export declare const defaultConnectionValueEnvironmentVariable = "PRISMATIC_CONNECTION_VALUE";
|
|
11
11
|
export declare const connectionValue: (envVarKey?: string) => ConnectionValue;
|
package/dist/testing.js
CHANGED
|
@@ -48,6 +48,11 @@ const loggerMock = () => ({
|
|
|
48
48
|
error: (0, jest_mock_1.spyOn)(console, "error"),
|
|
49
49
|
});
|
|
50
50
|
exports.loggerMock = loggerMock;
|
|
51
|
+
function invokeFlowTest(flowName, data, config) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return Promise.resolve({});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
51
56
|
const createActionContext = (context) => {
|
|
52
57
|
return Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, integrationState: {}, configVars: {}, components: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
|
|
53
58
|
"Flow 1": "https://example.com",
|
|
@@ -73,7 +78,15 @@ const createActionContext = (context) => {
|
|
|
73
78
|
}, flow: {
|
|
74
79
|
id: "flowId",
|
|
75
80
|
name: "Flow 1",
|
|
76
|
-
}, startedAt: new Date().toISOString()
|
|
81
|
+
}, startedAt: new Date().toISOString(), invokeFlow: invokeFlowTest, executionFrame: {
|
|
82
|
+
invokedByExecutionJWT: "some-jwt",
|
|
83
|
+
invokedByExecutionStartedAt: "00-00-0000",
|
|
84
|
+
componentActionKey: "my-component-action-key",
|
|
85
|
+
executionId: "abc-123",
|
|
86
|
+
executionStartedAt: "",
|
|
87
|
+
stepName: "some-step",
|
|
88
|
+
loopPath: "",
|
|
89
|
+
} }, context);
|
|
77
90
|
};
|
|
78
91
|
const createDataSourceContext = (context) => {
|
|
79
92
|
return Object.assign({ logger: (0, exports.loggerMock)(), configVars: {}, customer: {
|
|
@@ -1,8 +1,27 @@
|
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from "axios";
|
|
1
2
|
import { Inputs, ConfigVarResultCollection, ActionPerformReturn, ActionInputParameters, ActionLogger, InstanceAttributes, CustomerAttributes, UserAttributes, IntegrationAttributes, FlowAttributes, ComponentManifest } from ".";
|
|
3
|
+
interface StandardLineage {
|
|
4
|
+
componentActionKey: string;
|
|
5
|
+
executionId: string;
|
|
6
|
+
executionStartedAt: string;
|
|
7
|
+
stepName: string;
|
|
8
|
+
loopPath: string;
|
|
9
|
+
}
|
|
10
|
+
interface CustomLineage {
|
|
11
|
+
customSource: string;
|
|
12
|
+
}
|
|
13
|
+
export type ExecutionFrame = ({
|
|
14
|
+
invokedByExecutionJWT: string;
|
|
15
|
+
invokedByExecutionStartedAt: string;
|
|
16
|
+
} & StandardLineage) | ({
|
|
17
|
+
invokedByExecutionJWT: string;
|
|
18
|
+
invokedByExecutionStartedAt: string;
|
|
19
|
+
} & CustomLineage);
|
|
20
|
+
export type FlowInvoker<TFlows extends Readonly<string[]> | undefined> = (flowName: TFlows extends Readonly<string[]> ? TFlows[number] : string, data?: Record<string, unknown>, config?: AxiosRequestConfig<any>, source?: string) => Promise<AxiosResponse<any, any>>;
|
|
2
21
|
/** Definition of the function to perform when an Action is invoked. */
|
|
3
22
|
export type ActionPerformFunction<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]>, TAllowsBranching extends boolean | undefined, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>> = (context: ActionContext<TConfigVars, TComponentActions>, params: ActionInputParameters<TInputs>) => Promise<TReturn>;
|
|
4
23
|
/** Context provided to perform method containing helpers and contextual data */
|
|
5
|
-
export type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]
|
|
24
|
+
export type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]>, TFlows extends string[] = string[]> = {
|
|
6
25
|
/** Logger for permanent logging; console calls are also captured */
|
|
7
26
|
logger: ActionLogger;
|
|
8
27
|
/** A a flow-specific key/value store that may be used to store small amounts of data that is persisted between Instance executions */
|
|
@@ -43,4 +62,9 @@ export type ActionContext<TConfigVars extends ConfigVarResultCollection = Config
|
|
|
43
62
|
flow: FlowAttributes;
|
|
44
63
|
/** The time in UTC that execution started. */
|
|
45
64
|
startedAt: string;
|
|
65
|
+
/** Function to invoke an execution of another flow.. */
|
|
66
|
+
invokeFlow: FlowInvoker<TFlows>;
|
|
67
|
+
/** Reference to the current execution and, when applicable, the current step. */
|
|
68
|
+
executionFrame: ExecutionFrame;
|
|
46
69
|
};
|
|
70
|
+
export {};
|
package/dist/types/Inputs.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export type ConnectionInput = (StringInputField | DataInputField | TextInputFiel
|
|
|
71
71
|
export type OnPremConnectionInput = {
|
|
72
72
|
onPremControlled: true;
|
|
73
73
|
} & ConnectionInput;
|
|
74
|
-
export type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField | JSONFormInputField | DynamicObjectSelectionInputField | DynamicFieldSelectionInputField;
|
|
74
|
+
export type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField | JSONFormInputField | DynamicObjectSelectionInputField | DynamicFieldSelectionInputField | DateInputField | DateTimeInputField;
|
|
75
75
|
export type InputCleanFunction<TValue, TResult = TValue> = (value: TValue) => TResult;
|
|
76
76
|
interface BaseInputField {
|
|
77
77
|
/** Interface label of the InputField. */
|
|
@@ -247,6 +247,22 @@ export interface DynamicFieldSelectionInputField extends BaseInputField {
|
|
|
247
247
|
/** Clean function */
|
|
248
248
|
clean?: InputCleanFunction<this["default"]>;
|
|
249
249
|
}
|
|
250
|
+
export type DateInputField = BaseInputField & {
|
|
251
|
+
/** Data type the InputField will collect. */
|
|
252
|
+
type: "date";
|
|
253
|
+
/** Dictates possible choices for the input. */
|
|
254
|
+
model?: InputFieldChoice[];
|
|
255
|
+
/** Clean function */
|
|
256
|
+
clean?: InputCleanFunction<unknown>;
|
|
257
|
+
} & CollectionOptions<string>;
|
|
258
|
+
export type DateTimeInputField = BaseInputField & {
|
|
259
|
+
/** Data type the InputField will collect. */
|
|
260
|
+
type: "timestamp";
|
|
261
|
+
/** Dictates possible choices for the input. */
|
|
262
|
+
model?: InputFieldChoice[];
|
|
263
|
+
/** Clean function */
|
|
264
|
+
clean?: InputCleanFunction<unknown>;
|
|
265
|
+
} & CollectionOptions<string>;
|
|
250
266
|
/** Defines a single Choice option for a InputField. */
|
|
251
267
|
export interface InputFieldChoice {
|
|
252
268
|
/** Label to display for this Choice. */
|
|
@@ -258,4 +274,10 @@ export interface InputFieldChoice {
|
|
|
258
274
|
export type InputFieldCollection = "valuelist" | "keyvaluelist";
|
|
259
275
|
/** Config variable result collection */
|
|
260
276
|
export type ConfigVarResultCollection = Record<string, string | Schedule | Connection | unknown | ObjectSelection | ObjectFieldMap>;
|
|
277
|
+
export type FlowInputField = BaseInputField & {
|
|
278
|
+
/** Data type the InputField will collect. */
|
|
279
|
+
type: "flow";
|
|
280
|
+
/** Clean function */
|
|
281
|
+
clean?: InputCleanFunction<unknown>;
|
|
282
|
+
} & CollectionOptions<string>;
|
|
261
283
|
export {};
|
package/dist/types/Inputs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActionDisplayDefinition, TriggerEventFunction, Inputs, ConfigVarResultCollection, TriggerPayload, ActionDefinition,
|
|
1
|
+
import type { ActionDisplayDefinition, TriggerEventFunction, Inputs, ConfigVarResultCollection, TriggerPayload, ActionDefinition, ActionInputParameters, ActionPerformReturn, TriggerResult, ActionContext } from ".";
|
|
2
2
|
export interface PollingContext<TInputs extends Inputs = Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection> extends ActionContext<TConfigVars> {
|
|
3
3
|
polling: {
|
|
4
4
|
invokeAction: (params: ActionInputParameters<TInputs>) => Promise<ActionPerformReturn<boolean, any>>;
|