@prismatic-io/spectral 7.8.4 → 8.0.0-preview10

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.
Files changed (33) hide show
  1. package/dist/clients/http/index.d.ts +1 -1
  2. package/dist/index.d.ts +41 -12
  3. package/dist/index.js +43 -1
  4. package/dist/serverTypes/convert.d.ts +2 -1
  5. package/dist/serverTypes/convert.js +247 -1
  6. package/dist/serverTypes/index.d.ts +27 -24
  7. package/dist/testing.d.ts +14 -9
  8. package/dist/testing.js +57 -49
  9. package/dist/types/ActionDefinition.d.ts +3 -3
  10. package/dist/types/ActionPerformFunction.d.ts +12 -9
  11. package/dist/types/ComponentDefinition.d.ts +2 -2
  12. package/dist/types/{Customer.d.ts → CustomerAttributes.d.ts} +1 -1
  13. package/dist/types/DataSourcePerformFunction.d.ts +4 -4
  14. package/dist/types/{Flow.d.ts → FlowAttributes.d.ts} +1 -1
  15. package/dist/types/Inputs.d.ts +2 -0
  16. package/dist/types/{Instance.d.ts → InstanceAttributes.d.ts} +1 -1
  17. package/dist/types/{Integration.d.ts → IntegrationAttributes.d.ts} +2 -1
  18. package/dist/types/IntegrationDefinition.d.ts +269 -0
  19. package/dist/types/IntegrationDefinition.js +78 -0
  20. package/dist/types/TriggerDefinition.d.ts +5 -5
  21. package/dist/types/TriggerEventFunction.d.ts +2 -2
  22. package/dist/types/TriggerPayload.d.ts +6 -6
  23. package/dist/types/TriggerPerformFunction.d.ts +2 -2
  24. package/dist/types/TriggerResult.d.ts +4 -4
  25. package/dist/types/{User.d.ts → UserAttributes.d.ts} +1 -1
  26. package/dist/types/index.d.ts +6 -5
  27. package/dist/types/index.js +6 -5
  28. package/package.json +3 -2
  29. /package/dist/types/{Customer.js → CustomerAttributes.js} +0 -0
  30. /package/dist/types/{Flow.js → FlowAttributes.js} +0 -0
  31. /package/dist/types/{Instance.js → InstanceAttributes.js} +0 -0
  32. /package/dist/types/{Integration.js → IntegrationAttributes.js} +0 -0
  33. /package/dist/types/{User.js → UserAttributes.js} +0 -0
@@ -162,7 +162,7 @@ export declare const buildRawRequestAction: (baseUrl: string, label?: string, de
162
162
  type: "connection";
163
163
  required: true;
164
164
  };
165
- }, boolean, {
165
+ }, import("../..").ConfigVarResultCollection, boolean, {
166
166
  data: any;
167
167
  }>;
168
168
  export { inputs };
package/dist/index.d.ts CHANGED
@@ -3,8 +3,45 @@
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 } from "./types";
7
- import { convertComponent } from "./serverTypes/convert";
6
+ import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, IntegrationDefinition, Flow, ConfigPage, StandardConfigVar, ConnectionConfigVar, ConfigVar, ConfigVarResultCollection, ConfigVarCollection, TriggerPayload } from "./types";
7
+ import { convertComponent, convertIntegration } from "./serverTypes/convert";
8
+ /**
9
+ * This function creates a Integration object that can be
10
+ * imported into the Prismatic API. For information on using
11
+ * this function to write code native integrations, see
12
+ * https://prismatic.io/docs/code-native-integrations/.
13
+ * @param definition An IntegrationDefinition type object.
14
+ * @returns This function returns an integration object that has the shape the Prismatic API expects.
15
+ */
16
+ export declare const integration: <TConfigVar extends Record<string, ConfigVar> = Record<string, ConfigVar>>(definition: IntegrationDefinition<TConfigVar>) => 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: <TConfigVars extends ConfigVarCollection = ConfigVarCollection, TTriggerPayload extends TriggerPayload = TriggerPayload, T extends Flow<TConfigVars, TTriggerPayload> = Flow<TConfigVars, TTriggerPayload>>(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<ConfigVarCollection>>(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;
8
45
  /**
9
46
  * This function creates a component object that can be
10
47
  * imported into the Prismatic API. For information on using
@@ -23,7 +60,7 @@ export declare const component: <TPublic extends boolean, TKey extends string>(d
23
60
  * @param definition An ActionDefinition type object that includes UI display information, a function to perform when the action is invoked, and a an object containing inputs for the perform function.
24
61
  * @returns This function validates the shape of the `definition` object provided, and returns the same action object.
25
62
  */
26
- export declare const action: <TInputs extends Inputs, TAllowsBranching extends boolean, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>>(definition: ActionDefinition<TInputs, TAllowsBranching, TReturn>) => ActionDefinition<TInputs, TAllowsBranching, TReturn>;
63
+ export declare const action: <TInputs extends Inputs, TConfigVar extends ConfigVarResultCollection, TAllowsBranching extends boolean, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>>(definition: ActionDefinition<TInputs, TConfigVar, TAllowsBranching, TReturn>) => ActionDefinition<TInputs, TConfigVar, TAllowsBranching, TReturn>;
27
64
  /**
28
65
  * This function creates a trigger object that can be referenced
29
66
  * by a custom component. It helps ensure that the shape of the
@@ -33,7 +70,7 @@ export declare const action: <TInputs extends Inputs, TAllowsBranching extends b
33
70
  * @param definition A TriggerDefinition type object that includes UI display information, a function to perform when the trigger is invoked, and a an object containing inputs for the perform function.
34
71
  * @returns This function validates the shape of the `definition` object provided, and returns the same trigger object.
35
72
  */
36
- export declare const trigger: <TInputs extends Inputs, TAllowsBranching extends boolean, TResult extends TriggerResult<TAllowsBranching>>(definition: TriggerDefinition<TInputs, TAllowsBranching, TResult>) => TriggerDefinition<TInputs, TAllowsBranching, TResult>;
73
+ export declare const trigger: <TInputs extends Inputs, TConfigVar extends ConfigVarResultCollection, TAllowsBranching extends boolean, TResult extends TriggerResult<TAllowsBranching, TriggerPayload>>(definition: TriggerDefinition<TInputs, TConfigVar, TAllowsBranching, TResult>) => TriggerDefinition<TInputs, TConfigVar, TAllowsBranching, TResult>;
37
74
  /**
38
75
  * This function creates a data source object that can be referenced
39
76
  * by a custom component. It helps ensure that the shape of the
@@ -56,14 +93,6 @@ export declare const dataSource: <TInputs extends Inputs, TDataSourceType extend
56
93
  boolean: boolean;
57
94
  number: number;
58
95
  connection: import("./types").Connection;
59
- /**
60
- * This function creates a component object that can be
61
- * imported into the Prismatic API. For information on using
62
- * this function to write custom components, see
63
- * https://prismatic.io/docs/custom-components/writing-custom-components/#exporting-a-component.
64
- * @param definition A ComponentDefinition type object, including display information, unique key, and a set of actions the component implements.
65
- * @returns This function returns a component object that has the shape the Prismatic API expects.
66
- */
67
96
  objectSelection: import("./types").ObjectSelection;
68
97
  objectFieldMap: import("./types").ObjectFieldMap;
69
98
  jsonForm: import("./types").JSONForm;
package/dist/index.js CHANGED
@@ -22,8 +22,50 @@ 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 = void 0;
25
+ exports.testing = exports.util = exports.oauth2Connection = exports.connection = exports.input = exports.dataSource = exports.trigger = exports.action = exports.component = exports.connectionConfigVar = exports.configVar = exports.configPage = exports.flow = exports.integration = void 0;
26
26
  const convert_1 = require("./serverTypes/convert");
27
+ /**
28
+ * This function creates a Integration object that can be
29
+ * imported into the Prismatic API. For information on using
30
+ * this function to write code native integrations, see
31
+ * https://prismatic.io/docs/code-native-integrations/.
32
+ * @param definition An IntegrationDefinition type object.
33
+ * @returns This function returns an integration object that has the shape the Prismatic API expects.
34
+ */
35
+ const integration = (definition) => (0, convert_1.convertIntegration)(definition);
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;
27
69
  /**
28
70
  * This function creates a component object that can be
29
71
  * imported into the Prismatic API. For information on using
@@ -1,3 +1,4 @@
1
- import { ComponentDefinition } from "../types";
1
+ import { ComponentDefinition, IntegrationDefinition } from "../types";
2
2
  import { Component as ServerComponent } from ".";
3
3
  export declare const convertComponent: <TPublic extends boolean, TKey extends string>({ connections, actions, triggers, dataSources, hooks, ...definition }: ComponentDefinition<TPublic, TKey>) => ServerComponent;
4
+ export declare const convertIntegration: (definition: IntegrationDefinition) => ServerComponent;
@@ -10,8 +10,13 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  }
11
11
  return t;
12
12
  };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
13
16
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.convertComponent = void 0;
17
+ exports.convertIntegration = exports.convertComponent = void 0;
18
+ const yaml_1 = __importDefault(require("yaml"));
19
+ const uuid_1 = require("uuid");
15
20
  const types_1 = require("../types");
16
21
  const perform_1 = require("./perform");
17
22
  const convertInput = (key, _a) => {
@@ -77,3 +82,244 @@ const convertComponent = (_a) => {
77
82
  return Object.assign(Object.assign({}, definition), { connections: connections.map(convertConnection), actions: convertedActions, triggers: convertedTriggers, dataSources: convertedDataSources });
78
83
  };
79
84
  exports.convertComponent = convertComponent;
85
+ const convertIntegration = (definition) => {
86
+ // Generate a unique reference key that will be used to reference the
87
+ // actions, triggers, data sources, and connections that are created
88
+ // inline as part of the integration definition.
89
+ const referenceKey = (0, uuid_1.v4)();
90
+ return Object.assign(Object.assign({}, codeNativeIntegrationComponent(definition, referenceKey)), { codeNativeIntegrationYAML: codeNativeIntegrationYaml(definition, referenceKey) });
91
+ };
92
+ exports.convertIntegration = convertIntegration;
93
+ const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, configVars, endpointType, triggerPreprocessFlowConfig, flows, configPages, }, referenceKey) => {
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
+ }
112
+ // Transform the IntegrationDefinition into the structure that is appropriate
113
+ // for generating YAML, which will then be used by the Prismatic API to import
114
+ // the integration as a Code Native Integration.
115
+ const result = {
116
+ definitionVersion: DEFINITION_VERSION,
117
+ isCodeNative: true,
118
+ name,
119
+ description,
120
+ category,
121
+ documentation,
122
+ version,
123
+ labels,
124
+ requiredConfigVars: Object.entries(configVars || {}).map(([key, configVar]) => convertConfigVar(Object.assign(Object.assign({}, configVar), { key }), referenceKey)),
125
+ endpointType,
126
+ preprocessFlowName: hasPreprocessFlow ? preprocessFlows[0].name : undefined,
127
+ externalCustomerIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerIdField),
128
+ externalCustomerUserIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerUserIdField),
129
+ flowNameField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.flowNameField),
130
+ flows: flows.map((flow) => convertFlow(flow, referenceKey)),
131
+ configPages,
132
+ };
133
+ return yaml_1.default.stringify(result);
134
+ };
135
+ /** Converts a Flow into the structure necessary for YAML generation. */
136
+ const convertFlow = (flow, referenceKey) => {
137
+ const result = Object.assign({}, flow);
138
+ delete result.onTrigger;
139
+ delete result.trigger;
140
+ delete result.onInstanceDeploy;
141
+ delete result.onInstanceDelete;
142
+ delete result.onExecution;
143
+ delete result.preprocessFlowConfig;
144
+ delete result.errorConfig;
145
+ const triggerStep = {
146
+ name: "On Trigger",
147
+ description: "The function that will be executed by the flow to return an HTTP response.",
148
+ isTrigger: true,
149
+ errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
150
+ action: {
151
+ key: flowFunctionKey(flow.name, "onTrigger"),
152
+ component: { key: referenceKey, version: "LATEST", isPublic: false },
153
+ },
154
+ };
155
+ if ("schedule" in flow && typeof flow.schedule === "object") {
156
+ triggerStep.schedule = {
157
+ type: "cronExpression" in flow.schedule
158
+ ? types_1.SimpleInputValueType.Value
159
+ : types_1.SimpleInputValueType.ConfigVar,
160
+ value: "cronExpression" in flow.schedule
161
+ ? flow.schedule.cronExpression
162
+ : flow.schedule.configVarKey,
163
+ meta: {
164
+ scheduleType: types_1.ScheduleType.Custom,
165
+ timeZone: flow.schedule.timeZone,
166
+ },
167
+ };
168
+ delete result.schedule;
169
+ }
170
+ const actionStep = {
171
+ action: {
172
+ key: flowFunctionKey(flow.name, "onExecution"),
173
+ component: { key: referenceKey, version: "LATEST", isPublic: false },
174
+ },
175
+ name: "On Execution",
176
+ description: "The function that will be executed by the flow.",
177
+ errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
178
+ };
179
+ result.steps = [triggerStep, actionStep];
180
+ return result;
181
+ };
182
+ /** Converts a Config Var into the structure necessary for YAML generation. */
183
+ const convertConfigVar = (configVar, referenceKey) => {
184
+ // This is unfortunate but we need to strip out some fields that are not
185
+ // relevant to config vars.
186
+ const fields = [
187
+ "key",
188
+ "description",
189
+ "orgOnly",
190
+ "inputs",
191
+ "defaultValue",
192
+ "dataType",
193
+ "pickList",
194
+ "scheduleType",
195
+ "timeZone",
196
+ "codeLanguage",
197
+ "collectionType",
198
+ "dataSource",
199
+ ];
200
+ const result = Object.entries(configVar).reduce((result, [key, value]) => {
201
+ if (!fields.includes(key)) {
202
+ return result;
203
+ }
204
+ return Object.assign(Object.assign({}, result), { [key]: value });
205
+ }, { meta: {} });
206
+ // Handle some non-standard fields.
207
+ if ("visibleToOrgDeployer" in configVar) {
208
+ result.meta.visibleToOrgDeployer = configVar.visibleToOrgDeployer;
209
+ }
210
+ if ("visibleToCustomerDeployer" in configVar) {
211
+ result.meta.visibleToCustomerDeployer = configVar.visibleToCustomerDeployer;
212
+ }
213
+ // Handle connections.
214
+ if ("label" in configVar) {
215
+ result.dataType = "connection";
216
+ // This refers to a connection we are creating.
217
+ result.connection = {
218
+ key: configVar.key,
219
+ component: { key: referenceKey, version: "LATEST", isPublic: false },
220
+ };
221
+ result.description = configVar.label;
222
+ // Convert connection inputs to the inputs expected in the YAML.
223
+ // FIXME: This is just a placeholder for now.
224
+ // TODO: It seems like using the default value as the value is probably correct?
225
+ result.inputs = Object.entries(configVar.inputs).reduce((result, [key, input]) => {
226
+ var _a;
227
+ return Object.assign(Object.assign({}, result), { [key]: {
228
+ type: types_1.SimpleInputValueType.Value,
229
+ value: (_a = input.default) !== null && _a !== void 0 ? _a : "",
230
+ } });
231
+ }, {});
232
+ }
233
+ // Handle data source references.
234
+ if ("dataSource" in result) {
235
+ // This is a reference to a data source we are creating.
236
+ result.dataSource = {
237
+ key: result.dataSource,
238
+ component: { key: referenceKey, version: "LATEST", isPublic: false },
239
+ };
240
+ }
241
+ return result;
242
+ };
243
+ /** Maps the step name field to a fully qualified input. */
244
+ const fieldNameToReferenceInput = (stepName, fieldName) => {
245
+ if (!fieldName) {
246
+ return undefined;
247
+ }
248
+ return {
249
+ type: types_1.SimpleInputValueType.Reference,
250
+ value: `${stepName}.results.${fieldName}`,
251
+ };
252
+ };
253
+ /** Actions and Triggers will be scoped to their flow by combining the flow
254
+ * name and the function name. This is to ensure that the keys are unique
255
+ * on the resulting object, which will be turned into a Component. */
256
+ const flowFunctionKey = (flowName, functionName) => {
257
+ const flowKey = flowName
258
+ .replace(/[^0-9a-zA-Z]+/g, " ")
259
+ .trim()
260
+ .split(" ")
261
+ .map((w, i) => i === 0
262
+ ? w.toLowerCase()
263
+ : w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
264
+ .join("");
265
+ return `${flowKey}_${functionName}`;
266
+ };
267
+ /** Creates the structure necessary to import a Component as part of a
268
+ * Code Native integration. */
269
+ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [], dataSources = {}, configVars = {}, }, referenceKey) => {
270
+ const convertedActions = flows.reduce((result, { name, onExecution }) => {
271
+ const actionKey = flowFunctionKey(name, "onExecution");
272
+ return Object.assign(Object.assign({}, result), { [actionKey]: convertAction(actionKey, {
273
+ display: {
274
+ label: `${name} - onExecution`,
275
+ description: "The function that will be executed by the flow.",
276
+ },
277
+ perform: onExecution,
278
+ inputs: {},
279
+ }) });
280
+ }, {});
281
+ const convertedTriggers = flows.reduce((result, flow) => {
282
+ // Filter out TriggerReferences.
283
+ if ("trigger" in flow)
284
+ return result;
285
+ const { name, onTrigger, onInstanceDeploy, onInstanceDelete } = flow;
286
+ const triggerKey = flowFunctionKey(name, "onTrigger");
287
+ return Object.assign(Object.assign({}, result), { [triggerKey]: convertTrigger(triggerKey, {
288
+ display: {
289
+ label: `${name} - onTrigger`,
290
+ description: "The function that will be executed by the flow to return an HTTP response.",
291
+ },
292
+ perform: onTrigger,
293
+ onInstanceDeploy: onInstanceDeploy,
294
+ onInstanceDelete: onInstanceDelete,
295
+ inputs: {},
296
+ scheduleSupport: "valid",
297
+ synchronousResponseSupport: "valid",
298
+ }) });
299
+ }, {});
300
+ const convertedDataSources = Object.entries(dataSources).reduce((result, [dataSourceKey, dataSource]) => (Object.assign(Object.assign({}, result), { [dataSourceKey]: convertDataSource(dataSourceKey, Object.assign(Object.assign({}, dataSource), { inputs: {} })) })), {});
301
+ const convertedConnections = Object.entries(configVars).reduce((result, [key, configVar]) => {
302
+ if (!("label" in configVar)) {
303
+ return result;
304
+ }
305
+ // Remove a few fields that are not relevant to connections.
306
+ const {
307
+ /* eslint-disable @typescript-eslint/no-unused-vars */
308
+ orgOnly, visibleToOrgDeployer, visibleToCustomerDeployer } = configVar,
309
+ /* eslint-enable @typescript-eslint/no-unused-vars */
310
+ connection = __rest(configVar, ["orgOnly", "visibleToOrgDeployer", "visibleToCustomerDeployer"]);
311
+ return [...result, convertConnection(Object.assign(Object.assign({}, connection), { key }))];
312
+ }, []);
313
+ return {
314
+ key: referenceKey,
315
+ display: {
316
+ label: referenceKey,
317
+ iconPath,
318
+ description: description || name,
319
+ },
320
+ connections: convertedConnections,
321
+ actions: convertedActions,
322
+ triggers: convertedTriggers,
323
+ dataSources: convertedDataSources,
324
+ };
325
+ };
@@ -1,14 +1,14 @@
1
1
  /// <reference types="node" />
2
- import { Instance, Customer, DataSourceType, DataSourceResultType, User, TriggerEventFunctionReturn, Integration, Flow } from "../types";
2
+ import { InstanceAttributes, CustomerAttributes, DataSourceType, DataSourceResultType, UserAttributes, TriggerEventFunctionReturn, IntegrationAttributes, FlowAttributes, ConfigVarResultCollection } from "../types";
3
3
  interface DisplayDefinition {
4
4
  label: string;
5
5
  description: string;
6
6
  }
7
- export { Instance } from "../types";
8
- export { Customer } from "../types";
9
- export { User } from "../types";
10
- export { Integration } from "../types";
11
- export { Flow } from "../types";
7
+ export { InstanceAttributes } from "../types";
8
+ export { CustomerAttributes } from "../types";
9
+ export { UserAttributes } from "../types";
10
+ export { IntegrationAttributes } from "../types";
11
+ export { FlowAttributes } from "../types";
12
12
  export interface Component {
13
13
  key: string;
14
14
  public?: boolean;
@@ -21,6 +21,7 @@ export interface Component {
21
21
  triggers: Record<string, Trigger>;
22
22
  dataSources: Record<string, DataSource>;
23
23
  connections: Connection[];
24
+ codeNativeIntegrationYAML?: string;
24
25
  }
25
26
  export interface Action {
26
27
  key: string;
@@ -47,7 +48,7 @@ export interface ActionLogger {
47
48
  warn: ActionLoggerFunction;
48
49
  error: ActionLoggerFunction;
49
50
  }
50
- export interface ActionContext {
51
+ export declare type ActionContext<TConfigVars extends ConfigVarResultCollection, THasConfigVars extends boolean = false> = {
51
52
  logger: ActionLogger;
52
53
  instanceState: Record<string, unknown>;
53
54
  crossFlowState: Record<string, unknown>;
@@ -58,13 +59,15 @@ export interface ActionContext {
58
59
  webhookUrls: Record<string, string>;
59
60
  webhookApiKeys: Record<string, string[]>;
60
61
  invokeUrl: string;
61
- customer: Customer;
62
- instance: Instance;
63
- user: User;
64
- integration: Integration;
65
- flow: Flow;
62
+ customer: CustomerAttributes;
63
+ instance: InstanceAttributes;
64
+ user: UserAttributes;
65
+ integration: IntegrationAttributes;
66
+ flow: FlowAttributes;
66
67
  startedAt: string;
67
- }
68
+ } & (THasConfigVars extends true ? {
69
+ configVars: TConfigVars;
70
+ } : Record<string, never>);
68
71
  declare type TriggerOptionChoice = "invalid" | "valid" | "required";
69
72
  export interface TriggerPayload {
70
73
  headers: Record<string, string>;
@@ -82,11 +85,11 @@ export interface TriggerPayload {
82
85
  webhookApiKeys: Record<string, string[]>;
83
86
  invokeUrl: string;
84
87
  executionId: string;
85
- customer: Customer;
86
- instance: Instance;
87
- user: User;
88
- integration: Integration;
89
- flow: Flow;
88
+ customer: CustomerAttributes;
89
+ instance: InstanceAttributes;
90
+ user: UserAttributes;
91
+ integration: IntegrationAttributes;
92
+ flow: FlowAttributes;
90
93
  startedAt: string;
91
94
  }
92
95
  interface HttpResponse {
@@ -109,9 +112,9 @@ interface TriggerBranchingResult extends TriggerBaseResult {
109
112
  branch: string;
110
113
  }
111
114
  export declare type TriggerResult = TriggerBranchingResult | TriggerBaseResult | undefined;
112
- export declare type TriggerPerformFunction = (context: ActionContext, payload: TriggerPayload, params: Record<string, unknown>) => Promise<TriggerResult>;
115
+ export declare type TriggerPerformFunction = (context: ActionContext<any>, payload: TriggerPayload, params: Record<string, unknown>) => Promise<TriggerResult>;
113
116
  export declare type TriggerEventFunctionResult = TriggerEventFunctionReturn | void;
114
- export declare type TriggerEventFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<TriggerEventFunctionResult>;
117
+ export declare type TriggerEventFunction = (context: ActionContext<any>, params: Record<string, unknown>) => Promise<TriggerEventFunctionResult>;
115
118
  export interface Trigger {
116
119
  key: string;
117
120
  display: DisplayDefinition & {
@@ -136,9 +139,9 @@ export interface Trigger {
136
139
  }
137
140
  export interface DataSourceContext {
138
141
  logger: ActionLogger;
139
- customer: Customer;
140
- instance: Instance;
141
- user: User;
142
+ customer: CustomerAttributes;
143
+ instance: InstanceAttributes;
144
+ user: UserAttributes;
142
145
  }
143
146
  export declare type DataSourceResult = {
144
147
  result: DataSourceResultType;
@@ -211,7 +214,7 @@ interface ServerPerformBranchingDataReturn extends ServerPerformDataReturn {
211
214
  branch: string;
212
215
  }
213
216
  export declare type ActionPerformReturn = ServerPerformDataStructureReturn | ServerPerformBranchingDataStructureReturn | ServerPerformDataReturn | ServerPerformBranchingDataReturn | undefined;
214
- export declare type ActionPerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<ActionPerformReturn>;
217
+ export declare type ActionPerformFunction = (context: ActionContext<any>, params: Record<string, unknown>) => Promise<ActionPerformReturn>;
215
218
  interface InputFieldChoice {
216
219
  label: string;
217
220
  value: string;
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, ConfigVarResultCollection, ConfigVarCollection, ConfigVarDefinitionsToResults } 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.
@@ -25,7 +25,7 @@ interface InvokeReturn<ReturnData> {
25
25
  * to avoid extra casting within test methods. Returns an InvokeResult containing both the
26
26
  * action result and a mock logger for asserting logging.
27
27
  */
28
- export declare const 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>>;
28
+ export declare const invoke: <TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean, TReturn extends InvokeActionPerformReturn<TAllowsBranching, unknown>>({ perform, }: ActionDefinition<TInputs, TConfigVars, TAllowsBranching, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext<TConfigVars, false>> | undefined) => Promise<InvokeReturn<TReturn>>;
29
29
  export declare const defaultTriggerPayload: () => TriggerPayload;
30
30
  /**
31
31
  * Invokes specified TriggerDefinition perform function using supplied params
@@ -33,7 +33,7 @@ export declare const defaultTriggerPayload: () => TriggerPayload;
33
33
  * to avoid extra casting within test methods. Returns an InvokeResult containing both the
34
34
  * trigger result and a mock logger for asserting logging.
35
35
  */
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>>;
36
+ export declare const invokeTrigger: <TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean, TResult extends InvokeTriggerResult<TAllowsBranching, TriggerPayload>>({ perform, }: TriggerDefinition<TInputs, TConfigVars, TAllowsBranching, TResult>, context?: Partial<ActionContext<TConfigVars, false>> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs> | undefined) => Promise<InvokeReturn<TResult>>;
37
37
  /**
38
38
  * Invokes specified DataSourceDefinition perform function using supplied params.
39
39
  * Accepts a generic type matching DataSourceResult as a convenience to avoid extra
@@ -56,23 +56,28 @@ 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: <TConfigVars extends ConfigVarCollection>(flow: Flow<TConfigVars, import("./types").TriggerPayload>, context?: Partial<ActionContext<ConfigVarDefinitionsToResults<TConfigVars>, true>> | 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);
62
67
  private buildContext;
63
68
  private buildParams;
64
69
  connectionValue({ key }: ConnectionDefinition): ConnectionValue;
65
- trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>;
66
- triggerOnInstanceDeploy(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<void | TriggerEventFunctionReturn>;
67
- triggerOnInstanceDelete(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<void | TriggerEventFunctionReturn>;
68
- action(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<ActionPerformReturn>;
70
+ trigger<TConfigVars extends ConfigVarResultCollection>(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<TriggerResult>;
71
+ triggerOnInstanceDeploy<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<void | TriggerEventFunctionReturn>;
72
+ triggerOnInstanceDelete<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<void | TriggerEventFunctionReturn>;
73
+ action<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<ActionPerformReturn>;
69
74
  dataSource(key: string, params?: Record<string, unknown>, context?: Partial<DataSourceContext>): Promise<DataSourceResult>;
70
75
  }
71
76
  export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
72
77
  declare const _default: {
73
78
  loggerMock: () => ActionLogger;
74
- 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>>;
75
- 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>>;
79
+ invoke: <TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean, TReturn extends InvokeActionPerformReturn<TAllowsBranching, unknown>>({ perform, }: ActionDefinition<TInputs, TConfigVars, TAllowsBranching, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext<TConfigVars, false>> | undefined) => Promise<InvokeReturn<TReturn>>;
80
+ invokeTrigger: <TInputs_1 extends Inputs, TConfigVars_1 extends ConfigVarResultCollection, TAllowsBranching_1 extends boolean, TResult extends InvokeTriggerResult<TAllowsBranching_1, TriggerPayload>>({ perform, }: TriggerDefinition<TInputs_1, TConfigVars_1, TAllowsBranching_1, TResult>, context?: Partial<ActionContext<TConfigVars_1, false>> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs_1> | undefined) => Promise<InvokeReturn<TResult>>;
76
81
  createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
77
82
  invokeDataSource: <TInputs_2 extends Inputs, TDataSourceType extends keyof {
78
83
  string: string;