@prismatic-io/spectral 8.0.0-preview6 → 8.0.0-preview8
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 +36 -1
- package/dist/index.js +41 -1
- package/dist/serverTypes/convert.js +134 -38
- 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 +46 -53
- 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, StandardConfigVar, ConnectionConfigVar, ConnectionRefConfigVar } 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,41 @@ 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;
|
|
31
|
+
/**
|
|
32
|
+
* For information on writing Code Native Integrations, see
|
|
33
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
|
|
34
|
+
* @param definition A Config Var type object.
|
|
35
|
+
* @returns This function returns a standard config var object that has the shape the Prismatic API expects.
|
|
36
|
+
*/
|
|
37
|
+
export declare const configVar: <T extends StandardConfigVar>(definition: T) => T;
|
|
38
|
+
/**
|
|
39
|
+
* For information on writing Code Native Integrations, see
|
|
40
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
|
|
41
|
+
* @param definition A Connection Config Var type object.
|
|
42
|
+
* @returns This function returns a connection config var object that has the shape the Prismatic API expects.
|
|
43
|
+
*/
|
|
44
|
+
export declare const connectionConfigVar: <T extends ConnectionConfigVar>(definition: T) => T;
|
|
45
|
+
/**
|
|
46
|
+
* For information on writing Code Native Integrations, see
|
|
47
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
|
|
48
|
+
* @param definition A Connection Reference Config Var type object.
|
|
49
|
+
* @returns This function returns a connection reference config var object that has the shape the Prismatic API expects.
|
|
50
|
+
*/
|
|
51
|
+
export declare const connectionRefConfigVar: <T extends ConnectionRefConfigVar>(definition: T) => T;
|
|
17
52
|
/**
|
|
18
53
|
* This function creates a component object that can be
|
|
19
54
|
* 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.connectionRefConfigVar = exports.connectionConfigVar = exports.configVar = 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,46 @@ 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;
|
|
53
|
+
/**
|
|
54
|
+
* For information on writing Code Native Integrations, see
|
|
55
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
|
|
56
|
+
* @param definition A Config Var type object.
|
|
57
|
+
* @returns This function returns a standard config var object that has the shape the Prismatic API expects.
|
|
58
|
+
*/
|
|
59
|
+
const configVar = (definition) => definition;
|
|
60
|
+
exports.configVar = configVar;
|
|
61
|
+
/**
|
|
62
|
+
* For information on writing Code Native Integrations, see
|
|
63
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
|
|
64
|
+
* @param definition A Connection Config Var type object.
|
|
65
|
+
* @returns This function returns a connection config var object that has the shape the Prismatic API expects.
|
|
66
|
+
*/
|
|
67
|
+
const connectionConfigVar = (definition) => definition;
|
|
68
|
+
exports.connectionConfigVar = connectionConfigVar;
|
|
69
|
+
/**
|
|
70
|
+
* For information on writing Code Native Integrations, see
|
|
71
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
|
|
72
|
+
* @param definition A Connection Reference Config Var type object.
|
|
73
|
+
* @returns This function returns a connection reference config var object that has the shape the Prismatic API expects.
|
|
74
|
+
*/
|
|
75
|
+
const connectionRefConfigVar = (definition) => definition;
|
|
76
|
+
exports.connectionRefConfigVar = connectionRefConfigVar;
|
|
37
77
|
/**
|
|
38
78
|
* This function creates a component object that can be
|
|
39
79
|
* 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
|
};
|
|
@@ -118,16 +135,22 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
|
|
|
118
135
|
/** Converts a Flow into the structure necessary for YAML generation. */
|
|
119
136
|
const convertFlow = (flow, referenceKey) => {
|
|
120
137
|
const result = Object.assign({}, flow);
|
|
138
|
+
delete result.onTrigger;
|
|
121
139
|
delete result.trigger;
|
|
122
|
-
delete result.
|
|
140
|
+
delete result.onInstanceDeploy;
|
|
141
|
+
delete result.onInstanceDelete;
|
|
142
|
+
delete result.onExecution;
|
|
143
|
+
delete result.preprocessFlowConfig;
|
|
144
|
+
delete result.errorConfig;
|
|
123
145
|
const triggerStep = {
|
|
124
|
-
name:
|
|
146
|
+
name: `${flow.name} - onTrigger`,
|
|
147
|
+
description: "The function that will be executed by the flow to return an HTTP response.",
|
|
125
148
|
isTrigger: true,
|
|
126
|
-
errorConfig: "errorConfig" in flow
|
|
149
|
+
errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
|
|
127
150
|
};
|
|
128
|
-
if ("
|
|
151
|
+
if ("onTrigger" in flow) {
|
|
129
152
|
triggerStep.action = {
|
|
130
|
-
key: flowFunctionKey(flow.name, "
|
|
153
|
+
key: flowFunctionKey(flow.name, "onTrigger"),
|
|
131
154
|
component: { key: referenceKey, version: "LATEST", isPublic: false },
|
|
132
155
|
};
|
|
133
156
|
}
|
|
@@ -136,10 +159,9 @@ const convertFlow = (flow, referenceKey) => {
|
|
|
136
159
|
key: flow.trigger.key,
|
|
137
160
|
component: flow.trigger.component,
|
|
138
161
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
delete result.inputs;
|
|
162
|
+
if ("inputs" in flow.trigger) {
|
|
163
|
+
triggerStep.inputs = flow.trigger.inputs;
|
|
164
|
+
}
|
|
143
165
|
}
|
|
144
166
|
if ("schedule" in flow && typeof flow.schedule === "object") {
|
|
145
167
|
triggerStep.schedule = {
|
|
@@ -158,34 +180,77 @@ const convertFlow = (flow, referenceKey) => {
|
|
|
158
180
|
}
|
|
159
181
|
const actionStep = {
|
|
160
182
|
action: {
|
|
161
|
-
key: flowFunctionKey(flow.name, "
|
|
183
|
+
key: flowFunctionKey(flow.name, "onExecution"),
|
|
162
184
|
component: { key: referenceKey, version: "LATEST", isPublic: false },
|
|
163
185
|
},
|
|
164
|
-
name:
|
|
165
|
-
|
|
186
|
+
name: `${flow.name} - onExecution`,
|
|
187
|
+
description: "The function that will be executed by the flow.",
|
|
188
|
+
errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
|
|
166
189
|
};
|
|
167
190
|
result.steps = [triggerStep, actionStep];
|
|
168
191
|
return result;
|
|
169
192
|
};
|
|
170
193
|
/** Converts a Config Var into the structure necessary for YAML generation. */
|
|
171
194
|
const convertConfigVar = (configVar, referenceKey) => {
|
|
172
|
-
|
|
195
|
+
// This is unfortunate but we need to strip out some fields that are not
|
|
196
|
+
// relevant to config vars.
|
|
197
|
+
const fields = [
|
|
198
|
+
"key",
|
|
199
|
+
"description",
|
|
200
|
+
"orgOnly",
|
|
201
|
+
"inputs",
|
|
202
|
+
"defaultValue",
|
|
203
|
+
"dataType",
|
|
204
|
+
"pickList",
|
|
205
|
+
"scheduleType",
|
|
206
|
+
"timeZone",
|
|
207
|
+
"codeLanguage",
|
|
208
|
+
"collectionType",
|
|
209
|
+
"dataSource",
|
|
210
|
+
];
|
|
211
|
+
const result = Object.entries(configVar).reduce((result, [key, value]) => {
|
|
212
|
+
if (!fields.includes(key)) {
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
return Object.assign(Object.assign({}, result), { [key]: value });
|
|
216
|
+
}, { meta: {} });
|
|
173
217
|
// Handle some non-standard fields.
|
|
174
|
-
if ("visibleToOrgDeployer" in
|
|
175
|
-
result.meta.visibleToOrgDeployer =
|
|
176
|
-
delete result.visibleToOrgDeployer;
|
|
218
|
+
if ("visibleToOrgDeployer" in configVar) {
|
|
219
|
+
result.meta.visibleToOrgDeployer = configVar.visibleToOrgDeployer;
|
|
177
220
|
}
|
|
178
|
-
if ("visibleToCustomerDeployer" in
|
|
179
|
-
result.meta.visibleToCustomerDeployer =
|
|
180
|
-
delete result.visibleToCustomerDeployer;
|
|
221
|
+
if ("visibleToCustomerDeployer" in configVar) {
|
|
222
|
+
result.meta.visibleToCustomerDeployer = configVar.visibleToCustomerDeployer;
|
|
181
223
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
224
|
+
// Handle connections.
|
|
225
|
+
if ("label" in configVar || "component" in configVar) {
|
|
226
|
+
result.dataType = "connection";
|
|
227
|
+
if ("component" in configVar) {
|
|
228
|
+
// This is a reference to another Component's connection.
|
|
229
|
+
result.connection = {
|
|
230
|
+
key: configVar.key,
|
|
231
|
+
component: configVar.component,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// This refers to a connection we are creating.
|
|
236
|
+
result.connection = {
|
|
237
|
+
key: configVar.key,
|
|
238
|
+
component: { key: referenceKey, version: "LATEST", isPublic: false },
|
|
239
|
+
};
|
|
240
|
+
result.description = configVar.label;
|
|
241
|
+
// Convert connection inputs to the inputs expected in the YAML.
|
|
242
|
+
// FIXME: This is just a placeholder for now.
|
|
243
|
+
result.inputs = Object.keys(configVar.inputs).reduce((result, key) => {
|
|
244
|
+
return Object.assign(Object.assign({}, result), { [key]: {
|
|
245
|
+
type: types_1.SimpleInputValueType.Value,
|
|
246
|
+
value: "",
|
|
247
|
+
} });
|
|
248
|
+
}, {});
|
|
249
|
+
}
|
|
187
250
|
}
|
|
251
|
+
// Handle data source references.
|
|
188
252
|
if ("dataSource" in result && typeof result.dataSource === "string") {
|
|
253
|
+
// This is a reference to a data source we are creating.
|
|
189
254
|
result.dataSource = {
|
|
190
255
|
key: result.dataSource,
|
|
191
256
|
component: { key: referenceKey, version: "LATEST", isPublic: false },
|
|
@@ -220,19 +285,50 @@ const flowFunctionKey = (flowName, functionName) => {
|
|
|
220
285
|
};
|
|
221
286
|
/** Creates the structure necessary to import a Component as part of a
|
|
222
287
|
* Code Native integration. */
|
|
223
|
-
const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [], dataSources = {},
|
|
224
|
-
const convertedActions = flows.reduce((result, { name,
|
|
225
|
-
const actionKey = flowFunctionKey(name, "
|
|
226
|
-
return Object.assign(Object.assign({}, result), { [actionKey]: convertAction(actionKey,
|
|
288
|
+
const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [], dataSources = {}, configVars = [], }, referenceKey) => {
|
|
289
|
+
const convertedActions = flows.reduce((result, { name, onExecution }) => {
|
|
290
|
+
const actionKey = flowFunctionKey(name, "onExecution");
|
|
291
|
+
return Object.assign(Object.assign({}, result), { [actionKey]: convertAction(actionKey, {
|
|
292
|
+
display: {
|
|
293
|
+
label: `${name} - onExecution`,
|
|
294
|
+
description: "The function that will be executed by the flow.",
|
|
295
|
+
},
|
|
296
|
+
perform: onExecution,
|
|
297
|
+
inputs: {},
|
|
298
|
+
}) });
|
|
227
299
|
}, {});
|
|
228
|
-
const convertedTriggers = flows.reduce((result,
|
|
300
|
+
const convertedTriggers = flows.reduce((result, flow) => {
|
|
229
301
|
// Filter out TriggerReferences.
|
|
230
|
-
if (
|
|
302
|
+
if ("trigger" in flow)
|
|
231
303
|
return result;
|
|
232
|
-
const
|
|
233
|
-
|
|
304
|
+
const { name, onTrigger, onInstanceDeploy, onInstanceDelete } = flow;
|
|
305
|
+
const triggerKey = flowFunctionKey(name, "onTrigger");
|
|
306
|
+
return Object.assign(Object.assign({}, result), { [triggerKey]: convertTrigger(triggerKey, {
|
|
307
|
+
display: {
|
|
308
|
+
label: `${name} - onTrigger`,
|
|
309
|
+
description: "The function that will be executed by the flow to return an HTTP response.",
|
|
310
|
+
},
|
|
311
|
+
perform: onTrigger,
|
|
312
|
+
onInstanceDeploy: onInstanceDeploy,
|
|
313
|
+
onInstanceDelete: onInstanceDelete,
|
|
314
|
+
inputs: {},
|
|
315
|
+
scheduleSupport: "valid",
|
|
316
|
+
synchronousResponseSupport: "valid",
|
|
317
|
+
}) });
|
|
234
318
|
}, {});
|
|
235
319
|
const convertedDataSources = Object.entries(dataSources).reduce((result, [dataSourceKey, dataSource]) => (Object.assign(Object.assign({}, result), { [dataSourceKey]: convertDataSource(dataSourceKey, Object.assign(Object.assign({}, dataSource), { inputs: {} })) })), {});
|
|
320
|
+
const convertedConnections = configVars.reduce((result, configVar) => {
|
|
321
|
+
if (!("label" in configVar)) {
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
// Remove a few fields that are not relevant to connections.
|
|
325
|
+
const {
|
|
326
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
327
|
+
orgOnly, visibleToOrgDeployer, visibleToCustomerDeployer } = configVar,
|
|
328
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
329
|
+
connection = __rest(configVar, ["orgOnly", "visibleToOrgDeployer", "visibleToCustomerDeployer"]);
|
|
330
|
+
return [...result, convertConnection(connection)];
|
|
331
|
+
}, []);
|
|
236
332
|
return {
|
|
237
333
|
key: referenceKey,
|
|
238
334
|
display: {
|
|
@@ -240,7 +336,7 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
|
|
|
240
336
|
iconPath,
|
|
241
337
|
description: description || name,
|
|
242
338
|
},
|
|
243
|
-
connections:
|
|
339
|
+
connections: convertedConnections,
|
|
244
340
|
actions: convertedActions,
|
|
245
341
|
triggers: convertedTriggers,
|
|
246
342
|
dataSources: convertedDataSources,
|
|
@@ -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: (flow: 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 = (flow, 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 ("onTrigger" in flow) {
|
|
207
|
+
const triggerResult = yield flow.onTrigger(realizedContext, realizedPayload, params);
|
|
208
|
+
params.trigger = triggerResult;
|
|
209
|
+
}
|
|
210
|
+
const result = yield flow.onExecution(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 */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataSourceDefinition, ConnectionDefinition,
|
|
1
|
+
import { DataSourceDefinition, ConnectionDefinition, ActionPerformFunction, ActionPerformReturn, TriggerEventFunction, TriggerPerformFunction, Inputs, TriggerResult, DataSourceType } from ".";
|
|
2
2
|
/** Defines attributes of a Code-Native Integration. */
|
|
3
3
|
export declare type IntegrationDefinition = {
|
|
4
4
|
/** The unique name for this Integration. */
|
|
@@ -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. */
|
|
@@ -36,15 +30,15 @@ export declare type IntegrationDefinition = {
|
|
|
36
30
|
configPages?: ConfigPage[];
|
|
37
31
|
/** Specifies any Data Sources that are defined as part of this Integration. */
|
|
38
32
|
dataSources?: Record<string, CodeNativeDataSource>;
|
|
39
|
-
/** Specifies any Connections that are defined as part of this Integration. */
|
|
40
|
-
connections?: ConnectionDefinition[];
|
|
41
33
|
};
|
|
42
|
-
/** Defines attributes of a Flow of a Code-Native Integration. */
|
|
43
|
-
|
|
34
|
+
/** Defines common attributes of a Flow of a Code-Native Integration. */
|
|
35
|
+
declare type BaseFlow = {
|
|
44
36
|
/** The unique name for this Flow. */
|
|
45
37
|
name: string;
|
|
46
38
|
/** Optional description for this Flow. */
|
|
47
39
|
description?: string;
|
|
40
|
+
/** Optional Preprocess Flow configuration for when the result of this Flow contains the flow routing attributes. Only one Flow per Integration may define this. */
|
|
41
|
+
preprocessFlowConfig?: PreprocessFlowConfig;
|
|
48
42
|
/** Optional value that specifies whether this Flow is synchronous. @default false */
|
|
49
43
|
isSynchronous?: boolean;
|
|
50
44
|
/** Optional Retry Configuration for this Flow. */
|
|
@@ -55,28 +49,29 @@ export declare type Flow = {
|
|
|
55
49
|
organizationApiKeys?: string[];
|
|
56
50
|
/** Optional schedule configuration that defines the frequency with which this Flow will be automatically executed. */
|
|
57
51
|
schedule?: FlowSchedule;
|
|
58
|
-
/** Specifies the trigger for this Flow. */
|
|
59
|
-
trigger: (CodeNativeTrigger | TriggerReference) & {
|
|
60
|
-
/** Optional error handling configuration. */
|
|
61
|
-
errorConfig?: StepErrorConfig;
|
|
62
|
-
};
|
|
63
|
-
/** Specifies the main function for this Flow. */
|
|
64
|
-
action: CodeNativeAction;
|
|
65
|
-
};
|
|
66
|
-
/** 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>, // TODO: Are these values correct?
|
|
68
|
-
// TODO: Are these values correct?
|
|
69
|
-
"display" | "perform" | "dataSourceType" | "detailDataSource">;
|
|
70
|
-
/** 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>>, // TODO: Are these values correct?
|
|
72
|
-
// TODO: Are these values correct?
|
|
73
|
-
"perform" | "onInstanceDeploy" | "onInstanceDelete">;
|
|
74
|
-
/** 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>>, // TODO: Are these values correct?
|
|
76
|
-
"perform"> & {
|
|
77
52
|
/** Optional error handling configuration. */
|
|
78
53
|
errorConfig?: StepErrorConfig;
|
|
54
|
+
/** Specifies the main function for this Flow */
|
|
55
|
+
onExecution: ActionPerformFunction<Inputs, false, ActionPerformReturn<false, unknown>>;
|
|
79
56
|
};
|
|
57
|
+
/** Defines attributes of a Flow that will have custom Trigger logic. */
|
|
58
|
+
declare type CustomTriggerFlow = BaseFlow & {
|
|
59
|
+
/** Specifies the trigger function for this Flow, which returns a payload and optional HTTP response. */
|
|
60
|
+
onTrigger: TriggerPerformFunction<Inputs, false, TriggerResult<false>>;
|
|
61
|
+
/** Specifies the function to execute when an Instance of this Integration is deployed. */
|
|
62
|
+
onInstanceDeploy?: TriggerEventFunction<Inputs>;
|
|
63
|
+
/** Specifies the function to execute when an Instance of an Integration is deleted. */
|
|
64
|
+
onInstanceDelete?: TriggerEventFunction<Inputs>;
|
|
65
|
+
};
|
|
66
|
+
/** Defines attributes of a Flow that will use a Trigger from an existing Component. */
|
|
67
|
+
declare type PrebuiltTriggerFlow = BaseFlow & {
|
|
68
|
+
/** Specifies the prebuilt Trigger that will run when this Flow executes. */
|
|
69
|
+
trigger: TriggerReference;
|
|
70
|
+
};
|
|
71
|
+
/** Defines attributes of a Flow of a Code-Native Integration. */
|
|
72
|
+
export declare type Flow = CustomTriggerFlow | PrebuiltTriggerFlow;
|
|
73
|
+
/** Defines attributes of a Data Source that is defined as part of a Code Native Integration. */
|
|
74
|
+
export declare type CodeNativeDataSource = Pick<DataSourceDefinition<Inputs, DataSourceType>, "display" | "perform" | "dataSourceType" | "detailDataSource">;
|
|
80
75
|
/** Defines attributes of a reference to an existing Trigger. */
|
|
81
76
|
export declare type TriggerReference = {
|
|
82
77
|
/** Attributes of the referenced Component. */
|
|
@@ -93,13 +88,6 @@ export declare type DataSourceReference = {
|
|
|
93
88
|
/** The unique key that identifies the Data Source within the Component. */
|
|
94
89
|
key: string;
|
|
95
90
|
};
|
|
96
|
-
/** Defines attributes of a reference to an existing Connection. */
|
|
97
|
-
export declare type ConnectionReference = {
|
|
98
|
-
/** Attributes of the referenced Component. */
|
|
99
|
-
component: ComponentReference;
|
|
100
|
-
/** The unique key that identifies the Connection within the Component. */
|
|
101
|
-
key: string;
|
|
102
|
-
};
|
|
103
91
|
/** Defines attributes of a reference to a member of an existing Component. */
|
|
104
92
|
export declare type ComponentReference = {
|
|
105
93
|
/** The unique key that identifies the Component. */
|
|
@@ -125,7 +113,7 @@ declare type BaseConfigVar = {
|
|
|
125
113
|
visibleToCustomerDeployer?: boolean;
|
|
126
114
|
};
|
|
127
115
|
/** Defines attributes of a standard Config Var. */
|
|
128
|
-
declare type StandardConfigVar = BaseConfigVar & {
|
|
116
|
+
export declare type StandardConfigVar = BaseConfigVar & {
|
|
129
117
|
/** Optional default value for the Config Var. */
|
|
130
118
|
defaultValue?: string;
|
|
131
119
|
/** The data type of the Config Var. */
|
|
@@ -147,16 +135,12 @@ declare type StandardConfigVar = BaseConfigVar & {
|
|
|
147
135
|
dataSource?: string | DataSourceReference;
|
|
148
136
|
};
|
|
149
137
|
/** Defines attributes of a Config Var that represents a Connection. */
|
|
150
|
-
declare type ConnectionConfigVar = BaseConfigVar &
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
* Connection defined in the Code Native Integration. Otherwise it is
|
|
155
|
-
* expected to be a reference to an existing Connection. */
|
|
156
|
-
connection: string | ConnectionReference;
|
|
138
|
+
export declare type ConnectionConfigVar = Omit<BaseConfigVar, "description" | "inputs"> & ConnectionDefinition;
|
|
139
|
+
export declare type ConnectionRefConfigVar = BaseConfigVar & {
|
|
140
|
+
/** Attributes of the referenced Component. */
|
|
141
|
+
component: ComponentReference;
|
|
157
142
|
};
|
|
158
|
-
|
|
159
|
-
export declare type ConfigVar = StandardConfigVar | ConnectionConfigVar;
|
|
143
|
+
export declare type ConfigVar = StandardConfigVar | ConnectionConfigVar | ConnectionRefConfigVar;
|
|
160
144
|
/** Defines attributes of a Config Wizard Page used when deploying an Instance of an Integration. */
|
|
161
145
|
export declare type ConfigPage = {
|
|
162
146
|
/** The unique name for this Config Page. */
|
|
@@ -193,6 +177,15 @@ export declare type ConfigPageElement = {
|
|
|
193
177
|
/** Specifies the value of this Element. */
|
|
194
178
|
value: string;
|
|
195
179
|
};
|
|
180
|
+
/** Defines attributes of a Preprocess Flow Configuration used by a Flow of an Integration. */
|
|
181
|
+
export declare type PreprocessFlowConfig = {
|
|
182
|
+
/** Name of the field in the data payload returned by the Preprocess Flow to use for a Flow Name. */
|
|
183
|
+
flowNameField: string;
|
|
184
|
+
/** Optional name of the field in the data payload returned by the Preprocess Flow to use for an External Customer Id. */
|
|
185
|
+
externalCustomerIdField?: string;
|
|
186
|
+
/** Optional name of the field in the data payload returned by the Preprocess Flow to use for an External Customer User Id. */
|
|
187
|
+
externalCustomerUserIdField?: string;
|
|
188
|
+
};
|
|
196
189
|
/** Defines attributes of a Retry Configuration used by a Flow of an Integration. */
|
|
197
190
|
export declare type RetryConfig = {
|
|
198
191
|
/** The maximum number of retry attempts. Must be between 0 and 10. */
|