@prismatic-io/spectral 8.0.0-preview6 → 8.0.0-preview7
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/index.d.ts +15 -1
- package/dist/index.js +17 -1
- package/dist/serverTypes/convert.js +23 -5
- package/dist/serverTypes/index.d.ts +1 -0
- package/dist/testing.d.ts +6 -1
- package/dist/testing.js +20 -1
- package/dist/types/ActionPerformFunction.d.ts +2 -0
- package/dist/types/IntegrationDefinition.d.ts +20 -20
- package/package.json +1 -1
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, DataSourceDefinition, IntegrationDefinition } from "./types";
|
|
6
|
+
import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, IntegrationDefinition, Flow, ConfigPage } from "./types";
|
|
7
7
|
import { convertComponent, convertIntegration } from "./serverTypes/convert";
|
|
8
8
|
/**
|
|
9
9
|
* This function creates a Integration object that can be
|
|
@@ -14,6 +14,20 @@ import { convertComponent, convertIntegration } from "./serverTypes/convert";
|
|
|
14
14
|
* @returns This function returns an integration object that has the shape the Prismatic API expects.
|
|
15
15
|
*/
|
|
16
16
|
export declare const integration: (definition: IntegrationDefinition) => ReturnType<typeof convertIntegration>;
|
|
17
|
+
/**
|
|
18
|
+
* For information on writing Code Native Integrations, see
|
|
19
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-flows.
|
|
20
|
+
* @param definition A Flow type object.
|
|
21
|
+
* @returns This function returns a flow object that has the shape the Prismatic API expects.
|
|
22
|
+
*/
|
|
23
|
+
export declare const flow: <T extends Flow>(definition: T) => T;
|
|
24
|
+
/**
|
|
25
|
+
* For information on writing Code Native Integrations, see
|
|
26
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-config-pages.
|
|
27
|
+
* @param definition A Config Page type object.
|
|
28
|
+
* @returns This function returns a config page object that has the shape the Prismatic API expects.
|
|
29
|
+
*/
|
|
30
|
+
export declare const configPage: <T extends ConfigPage>(definition: T) => T;
|
|
17
31
|
/**
|
|
18
32
|
* This function creates a component object that can be
|
|
19
33
|
* imported into the Prismatic API. For information on using
|
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.dataSource = exports.trigger = exports.action = exports.component = exports.integration = void 0;
|
|
25
|
+
exports.testing = exports.util = exports.oauth2Connection = exports.connection = exports.input = exports.dataSource = exports.trigger = exports.action = exports.component = exports.configPage = exports.flow = exports.integration = void 0;
|
|
26
26
|
const convert_1 = require("./serverTypes/convert");
|
|
27
27
|
/**
|
|
28
28
|
* This function creates a Integration object that can be
|
|
@@ -34,6 +34,22 @@ const convert_1 = require("./serverTypes/convert");
|
|
|
34
34
|
*/
|
|
35
35
|
const integration = (definition) => (0, convert_1.convertIntegration)(definition);
|
|
36
36
|
exports.integration = integration;
|
|
37
|
+
/**
|
|
38
|
+
* For information on writing Code Native Integrations, see
|
|
39
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-flows.
|
|
40
|
+
* @param definition A Flow type object.
|
|
41
|
+
* @returns This function returns a flow object that has the shape the Prismatic API expects.
|
|
42
|
+
*/
|
|
43
|
+
const flow = (definition) => definition;
|
|
44
|
+
exports.flow = flow;
|
|
45
|
+
/**
|
|
46
|
+
* For information on writing Code Native Integrations, see
|
|
47
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-config-pages.
|
|
48
|
+
* @param definition A Config Page type object.
|
|
49
|
+
* @returns This function returns a config page object that has the shape the Prismatic API expects.
|
|
50
|
+
*/
|
|
51
|
+
const configPage = (definition) => definition;
|
|
52
|
+
exports.configPage = configPage;
|
|
37
53
|
/**
|
|
38
54
|
* This function creates a component object that can be
|
|
39
55
|
* imported into the Prismatic API. For information on using
|
|
@@ -90,8 +90,25 @@ const convertIntegration = (definition) => {
|
|
|
90
90
|
return Object.assign(Object.assign({}, codeNativeIntegrationComponent(definition, referenceKey)), { codeNativeIntegrationYAML: codeNativeIntegrationYaml(definition, referenceKey) });
|
|
91
91
|
};
|
|
92
92
|
exports.convertIntegration = convertIntegration;
|
|
93
|
-
const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, configVars, endpointType,
|
|
93
|
+
const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, configVars, endpointType, triggerPreprocessFlowConfig, flows, configPages, }, referenceKey) => {
|
|
94
94
|
const DEFINITION_VERSION = 7;
|
|
95
|
+
// Find the preprocess flow config on the flow, if one exists.
|
|
96
|
+
const preprocessFlows = flows.filter((flow) => flow.preprocessFlowConfig);
|
|
97
|
+
// Do some validation of preprocess flow configs.
|
|
98
|
+
if (preprocessFlows.length > 1) {
|
|
99
|
+
throw new Error("Only one flow may define a Preprocess Flow Config.");
|
|
100
|
+
}
|
|
101
|
+
if (preprocessFlows.length && triggerPreprocessFlowConfig) {
|
|
102
|
+
throw new Error("Integration must not define both a Trigger Preprocess Flow Config and a Preprocess Flow.");
|
|
103
|
+
}
|
|
104
|
+
const hasPreprocessFlow = preprocessFlows.length > 0;
|
|
105
|
+
const preprocessFlowConfig = hasPreprocessFlow
|
|
106
|
+
? preprocessFlows[0].preprocessFlowConfig
|
|
107
|
+
: triggerPreprocessFlowConfig;
|
|
108
|
+
if ([types_1.EndpointType.InstanceSpecific, types_1.EndpointType.SharedInstance].includes(endpointType || types_1.EndpointType.FlowSpecific) &&
|
|
109
|
+
!preprocessFlowConfig) {
|
|
110
|
+
throw new Error("Integration with specified EndpointType must define either a Trigger Preprocess Flow Config or a Preprocess Flow.");
|
|
111
|
+
}
|
|
95
112
|
// Transform the IntegrationDefinition into the structure that is appropriate
|
|
96
113
|
// for generating YAML, which will then be used by the Prismatic API to import
|
|
97
114
|
// the integration as a Code Native Integration.
|
|
@@ -106,10 +123,10 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
|
|
|
106
123
|
labels,
|
|
107
124
|
requiredConfigVars: configVars === null || configVars === void 0 ? void 0 : configVars.map((configVar) => convertConfigVar(configVar, referenceKey)),
|
|
108
125
|
endpointType,
|
|
109
|
-
preprocessFlowName,
|
|
110
|
-
externalCustomerIdField: fieldNameToReferenceInput("action", externalCustomerIdField),
|
|
111
|
-
externalCustomerUserIdField: fieldNameToReferenceInput("action", externalCustomerUserIdField),
|
|
112
|
-
flowNameField: fieldNameToReferenceInput("payload", flowNameField),
|
|
126
|
+
preprocessFlowName: hasPreprocessFlow ? preprocessFlows[0].name : undefined,
|
|
127
|
+
externalCustomerIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "action" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerIdField),
|
|
128
|
+
externalCustomerUserIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "action" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerUserIdField),
|
|
129
|
+
flowNameField: fieldNameToReferenceInput(hasPreprocessFlow ? "action" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.flowNameField),
|
|
113
130
|
flows: flows.map((flow) => convertFlow(flow, referenceKey)),
|
|
114
131
|
configPages,
|
|
115
132
|
};
|
|
@@ -120,6 +137,7 @@ const convertFlow = (flow, referenceKey) => {
|
|
|
120
137
|
const result = Object.assign({}, flow);
|
|
121
138
|
delete result.trigger;
|
|
122
139
|
delete result.action;
|
|
140
|
+
delete result.preprocessFlowConfig;
|
|
123
141
|
const triggerStep = {
|
|
124
142
|
name: "trigger",
|
|
125
143
|
isTrigger: true,
|
|
@@ -50,6 +50,7 @@ export interface ActionLogger {
|
|
|
50
50
|
}
|
|
51
51
|
export interface ActionContext {
|
|
52
52
|
logger: ActionLogger;
|
|
53
|
+
configVars?: Record<string, unknown>;
|
|
53
54
|
instanceState: Record<string, unknown>;
|
|
54
55
|
crossFlowState: Record<string, unknown>;
|
|
55
56
|
executionState: Record<string, unknown>;
|
package/dist/testing.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* https://prismatic.io/docs/custom-components/writing-custom-components/#testing-a-component
|
|
6
6
|
*/
|
|
7
7
|
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult, DataSourceContext } from "./serverTypes";
|
|
8
|
-
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn } from "./types";
|
|
8
|
+
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow } from "./types";
|
|
9
9
|
export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>, tokenValues?: Record<string, unknown> | undefined) => ConnectionValue;
|
|
10
10
|
/**
|
|
11
11
|
* Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
|
|
@@ -56,6 +56,11 @@ export declare const invokeDataSource: <TInputs extends Inputs, TDataSourceType
|
|
|
56
56
|
objectFieldMap: import("./types").ObjectFieldMap;
|
|
57
57
|
jsonForm: import("./types").JSONForm;
|
|
58
58
|
}>({ perform }: DataSourceDefinition<TInputs, TDataSourceType>, params: ActionInputParameters<TInputs>, context?: Partial<DataSourceContext> | undefined) => Promise<InvokeDataSourceResult<TDataSourceType>>;
|
|
59
|
+
/**
|
|
60
|
+
* Invokes specified Flow of a Code Native Integration using supplied params.
|
|
61
|
+
* Runs the Trigger and then the Action function and returns the result of the Action.
|
|
62
|
+
*/
|
|
63
|
+
export declare const invokeFlow: ({ trigger, action }: Flow, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined) => Promise<InvokeReturn<InvokeActionPerformReturn<false, unknown>>>;
|
|
59
64
|
export declare class ComponentTestHarness<TComponent extends Component> {
|
|
60
65
|
component: TComponent;
|
|
61
66
|
constructor(component: TComponent);
|
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.invokeDataSource = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.createConnection = void 0;
|
|
18
|
+
exports.createHarness = exports.ComponentTestHarness = exports.invokeFlow = 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, tokenValues) => ({
|
|
21
21
|
configVarKey: "",
|
|
@@ -195,6 +195,25 @@ const invokeDataSource = ({ perform }, params, context) => __awaiter(void 0, voi
|
|
|
195
195
|
return result;
|
|
196
196
|
});
|
|
197
197
|
exports.invokeDataSource = invokeDataSource;
|
|
198
|
+
/**
|
|
199
|
+
* Invokes specified Flow of a Code Native Integration using supplied params.
|
|
200
|
+
* Runs the Trigger and then the Action function and returns the result of the Action.
|
|
201
|
+
*/
|
|
202
|
+
const invokeFlow = ({ trigger, action }, context, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
203
|
+
const realizedContext = Object.assign(Object.assign({}, baseActionContext), context);
|
|
204
|
+
const realizedPayload = Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload);
|
|
205
|
+
const params = {};
|
|
206
|
+
if (typeof trigger === "object" && "perform" in trigger) {
|
|
207
|
+
const triggerResult = yield trigger.perform(realizedContext, realizedPayload, params);
|
|
208
|
+
params.trigger = triggerResult;
|
|
209
|
+
}
|
|
210
|
+
const result = yield action.perform(realizedContext, params);
|
|
211
|
+
return {
|
|
212
|
+
result,
|
|
213
|
+
loggerMock: realizedContext.logger,
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
exports.invokeFlow = invokeFlow;
|
|
198
217
|
class ComponentTestHarness {
|
|
199
218
|
constructor(component) {
|
|
200
219
|
this.component = component;
|
|
@@ -5,6 +5,8 @@ export declare type ActionPerformFunction<TInputs extends Inputs, TAllowsBranchi
|
|
|
5
5
|
export interface ActionContext {
|
|
6
6
|
/** Logger for permanent logging; console calls are also captured */
|
|
7
7
|
logger: ActionLogger;
|
|
8
|
+
/** Code Components and Code Native Integration Actions will have access to all Config Vars, otherwise this will be undefined. */
|
|
9
|
+
configVars?: Record<string, unknown>;
|
|
8
10
|
/** A a flow-specific key/value store that may be used to store small amounts of data that is persisted between Instance executions */
|
|
9
11
|
instanceState: Record<string, unknown>;
|
|
10
12
|
/** A key/value store that is shared between flows on an Instance that may be used to store small amounts of data that is persisted between Instance executions */
|
|
@@ -15,19 +15,13 @@ export declare type IntegrationDefinition = {
|
|
|
15
15
|
version?: string;
|
|
16
16
|
/** Optional labels for this Integration. */
|
|
17
17
|
labels?: string[];
|
|
18
|
-
/** Optional endpoint type used by Instances of this Integration.
|
|
18
|
+
/** Optional endpoint type used by Instances of this Integration.
|
|
19
|
+
* A Preprocess Flow Config must be specified when using anything other than 'Flow Specific'.
|
|
20
|
+
* @default EndpointType.FlowSpecific. */
|
|
19
21
|
endpointType?: EndpointType;
|
|
20
|
-
/** Optional
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* or by the data payload returned by the Trigger if there is no Preprocess Flow specified. */
|
|
24
|
-
externalCustomerIdField?: string;
|
|
25
|
-
/** Optional name of the field in the data payload returned by the Preprocess Flow to use for an External Customer User Id,
|
|
26
|
-
* or by the data payload returned by the Trigger if there is no Preprocess Flow specified. */
|
|
27
|
-
externalCustomerUserIdField?: string;
|
|
28
|
-
/** Optional name of the field in the data payload returned by the Preprocess Flow to use for a Flow Name,
|
|
29
|
-
* or by the data payload returned by the Trigger if there is no Preprocess Flow specified. */
|
|
30
|
-
flowNameField?: string;
|
|
22
|
+
/** Optional Preprocess Flow configuration for when the Trigger payload contains the flow routing attributes.
|
|
23
|
+
* Cannot specify this if a Preprocess Flow is also configured. */
|
|
24
|
+
triggerPreprocessFlowConfig?: PreprocessFlowConfig;
|
|
31
25
|
/** Flows for this Integration. */
|
|
32
26
|
flows: Flow[];
|
|
33
27
|
/** Config Vars used on this Integration. */
|
|
@@ -45,6 +39,8 @@ export declare type Flow = {
|
|
|
45
39
|
name: string;
|
|
46
40
|
/** Optional description for this Flow. */
|
|
47
41
|
description?: string;
|
|
42
|
+
/** Optional Preprocess Flow configuration for when the result of this Flow contains the flow routing attributes. Only one Flow per Integration may define this. */
|
|
43
|
+
preprocessFlowConfig?: PreprocessFlowConfig;
|
|
48
44
|
/** Optional value that specifies whether this Flow is synchronous. @default false */
|
|
49
45
|
isSynchronous?: boolean;
|
|
50
46
|
/** Optional Retry Configuration for this Flow. */
|
|
@@ -64,16 +60,11 @@ export declare type Flow = {
|
|
|
64
60
|
action: CodeNativeAction;
|
|
65
61
|
};
|
|
66
62
|
/** Defines attributes of a Data Source that is defined as part of a Code Native Integration. */
|
|
67
|
-
export declare type CodeNativeDataSource = Pick<DataSourceDefinition<Inputs, DataSourceType>,
|
|
68
|
-
// TODO: Are these values correct?
|
|
69
|
-
"display" | "perform" | "dataSourceType" | "detailDataSource">;
|
|
63
|
+
export declare type CodeNativeDataSource = Pick<DataSourceDefinition<Inputs, DataSourceType>, "display" | "perform" | "dataSourceType" | "detailDataSource">;
|
|
70
64
|
/** Defines attributes of a Trigger that is defined as part of a Code Native Integration. */
|
|
71
|
-
export declare type CodeNativeTrigger = Pick<TriggerDefinition<Inputs, false, TriggerResult<false>>,
|
|
72
|
-
// TODO: Are these values correct?
|
|
73
|
-
"perform" | "onInstanceDeploy" | "onInstanceDelete">;
|
|
65
|
+
export declare type CodeNativeTrigger = Pick<TriggerDefinition<Inputs, false, TriggerResult<false>>, "display" | "perform" | "onInstanceDeploy" | "onInstanceDelete">;
|
|
74
66
|
/** Defines attributes of an CodeNativeAction, which is the main function that will be executed for a Flow of a Code Native Integration. */
|
|
75
|
-
export declare type CodeNativeAction = Pick<ActionDefinition<Inputs, false, ActionPerformReturn<false, unknown>>,
|
|
76
|
-
"perform"> & {
|
|
67
|
+
export declare type CodeNativeAction = Pick<ActionDefinition<Inputs, false, ActionPerformReturn<false, unknown>>, "display" | "perform"> & {
|
|
77
68
|
/** Optional error handling configuration. */
|
|
78
69
|
errorConfig?: StepErrorConfig;
|
|
79
70
|
};
|
|
@@ -193,6 +184,15 @@ export declare type ConfigPageElement = {
|
|
|
193
184
|
/** Specifies the value of this Element. */
|
|
194
185
|
value: string;
|
|
195
186
|
};
|
|
187
|
+
/** Defines attributes of a Preprocess Flow Configuration used by a Flow of an Integration. */
|
|
188
|
+
export declare type PreprocessFlowConfig = {
|
|
189
|
+
/** Name of the field in the data payload returned by the Preprocess Flow to use for a Flow Name. */
|
|
190
|
+
flowNameField: string;
|
|
191
|
+
/** Optional name of the field in the data payload returned by the Preprocess Flow to use for an External Customer Id. */
|
|
192
|
+
externalCustomerIdField?: string;
|
|
193
|
+
/** Optional name of the field in the data payload returned by the Preprocess Flow to use for an External Customer User Id. */
|
|
194
|
+
externalCustomerUserIdField?: string;
|
|
195
|
+
};
|
|
196
196
|
/** Defines attributes of a Retry Configuration used by a Flow of an Integration. */
|
|
197
197
|
export declare type RetryConfig = {
|
|
198
198
|
/** The maximum number of retry attempts. Must be between 0 and 10. */
|