@prismatic-io/spectral 8.0.0-preview8 → 8.0.0

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.
@@ -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,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, Flow, ConfigPage, StandardConfigVar, ConnectionConfigVar, ConnectionRefConfigVar } from "./types";
6
+ import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, IntegrationDefinition, Flow, ConfigPage, StandardConfigVar, ConnectionConfigVar, ConfigVar, ConfigVarResultCollection, ConfigVarCollection, TriggerPayload } from "./types";
7
7
  import { convertComponent, convertIntegration } from "./serverTypes/convert";
8
8
  /**
9
9
  * This function creates a Integration object that can be
@@ -13,21 +13,21 @@ import { convertComponent, convertIntegration } from "./serverTypes/convert";
13
13
  * @param definition An IntegrationDefinition type object.
14
14
  * @returns This function returns an integration object that has the shape the Prismatic API expects.
15
15
  */
16
- export declare const integration: (definition: IntegrationDefinition) => ReturnType<typeof convertIntegration>;
16
+ export declare const integration: <TConfigVar extends Record<string, ConfigVar> = Record<string, ConfigVar>>(definition: IntegrationDefinition<TConfigVar>) => ReturnType<typeof convertIntegration>;
17
17
  /**
18
18
  * For information on writing Code Native Integrations, see
19
19
  * https://prismatic.io/docs/code-native-integrations/#adding-flows.
20
20
  * @param definition A Flow type object.
21
21
  * @returns This function returns a flow object that has the shape the Prismatic API expects.
22
22
  */
23
- export declare const flow: <T extends Flow>(definition: T) => T;
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
24
  /**
25
25
  * For information on writing Code Native Integrations, see
26
26
  * https://prismatic.io/docs/code-native-integrations/#adding-config-pages.
27
27
  * @param definition A Config Page type object.
28
28
  * @returns This function returns a config page object that has the shape the Prismatic API expects.
29
29
  */
30
- export declare const configPage: <T extends ConfigPage>(definition: T) => T;
30
+ export declare const configPage: <T extends ConfigPage<ConfigVarCollection>>(definition: T) => T;
31
31
  /**
32
32
  * For information on writing Code Native Integrations, see
33
33
  * https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
@@ -42,13 +42,6 @@ export declare const configVar: <T extends StandardConfigVar>(definition: T) =>
42
42
  * @returns This function returns a connection config var object that has the shape the Prismatic API expects.
43
43
  */
44
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;
52
45
  /**
53
46
  * This function creates a component object that can be
54
47
  * imported into the Prismatic API. For information on using
@@ -67,7 +60,7 @@ export declare const component: <TPublic extends boolean, TKey extends string>(d
67
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.
68
61
  * @returns This function validates the shape of the `definition` object provided, and returns the same action object.
69
62
  */
70
- 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>;
71
64
  /**
72
65
  * This function creates a trigger object that can be referenced
73
66
  * by a custom component. It helps ensure that the shape of the
@@ -77,7 +70,7 @@ export declare const action: <TInputs extends Inputs, TAllowsBranching extends b
77
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.
78
71
  * @returns This function validates the shape of the `definition` object provided, and returns the same trigger object.
79
72
  */
80
- 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>;
81
74
  /**
82
75
  * This function creates a data source object that can be referenced
83
76
  * by a custom component. It helps ensure that the shape of the
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.connectionRefConfigVar = exports.connectionConfigVar = exports.configVar = exports.configPage = exports.flow = exports.integration = 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
27
  /**
28
28
  * This function creates a Integration object that can be
@@ -66,14 +66,6 @@ exports.configVar = configVar;
66
66
  */
67
67
  const connectionConfigVar = (definition) => definition;
68
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;
77
69
  /**
78
70
  * This function creates a component object that can be
79
71
  * imported into the Prismatic API. For information on using
@@ -121,12 +121,12 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
121
121
  documentation,
122
122
  version,
123
123
  labels,
124
- requiredConfigVars: configVars === null || configVars === void 0 ? void 0 : configVars.map((configVar) => convertConfigVar(configVar, referenceKey)),
124
+ requiredConfigVars: Object.entries(configVars || {}).map(([key, configVar]) => convertConfigVar(Object.assign(Object.assign({}, configVar), { key }), referenceKey)),
125
125
  endpointType,
126
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),
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
130
  flows: flows.map((flow) => convertFlow(flow, referenceKey)),
131
131
  configPages,
132
132
  };
@@ -143,26 +143,16 @@ const convertFlow = (flow, referenceKey) => {
143
143
  delete result.preprocessFlowConfig;
144
144
  delete result.errorConfig;
145
145
  const triggerStep = {
146
- name: `${flow.name} - onTrigger`,
146
+ name: "On Trigger",
147
+ stableKey: `${flow.stableKey}-onTrigger`,
147
148
  description: "The function that will be executed by the flow to return an HTTP response.",
148
149
  isTrigger: true,
149
150
  errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
150
- };
151
- if ("onTrigger" in flow) {
152
- triggerStep.action = {
151
+ action: {
153
152
  key: flowFunctionKey(flow.name, "onTrigger"),
154
153
  component: { key: referenceKey, version: "LATEST", isPublic: false },
155
- };
156
- }
157
- else {
158
- triggerStep.action = {
159
- key: flow.trigger.key,
160
- component: flow.trigger.component,
161
- };
162
- if ("inputs" in flow.trigger) {
163
- triggerStep.inputs = flow.trigger.inputs;
164
- }
165
- }
154
+ },
155
+ };
166
156
  if ("schedule" in flow && typeof flow.schedule === "object") {
167
157
  triggerStep.schedule = {
168
158
  type: "cronExpression" in flow.schedule
@@ -183,7 +173,8 @@ const convertFlow = (flow, referenceKey) => {
183
173
  key: flowFunctionKey(flow.name, "onExecution"),
184
174
  component: { key: referenceKey, version: "LATEST", isPublic: false },
185
175
  },
186
- name: `${flow.name} - onExecution`,
176
+ name: "On Execution",
177
+ stableKey: `${flow.stableKey}-onExecution`,
187
178
  description: "The function that will be executed by the flow.",
188
179
  errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
189
180
  };
@@ -196,6 +187,7 @@ const convertConfigVar = (configVar, referenceKey) => {
196
187
  // relevant to config vars.
197
188
  const fields = [
198
189
  "key",
190
+ "stableKey",
199
191
  "description",
200
192
  "orgOnly",
201
193
  "inputs",
@@ -222,34 +214,27 @@ const convertConfigVar = (configVar, referenceKey) => {
222
214
  result.meta.visibleToCustomerDeployer = configVar.visibleToCustomerDeployer;
223
215
  }
224
216
  // Handle connections.
225
- if ("label" in configVar || "component" in configVar) {
217
+ if ("label" in configVar) {
226
218
  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
- }
219
+ // This refers to a connection we are creating.
220
+ result.connection = {
221
+ key: configVar.key,
222
+ component: { key: referenceKey, version: "LATEST", isPublic: false },
223
+ };
224
+ result.description = configVar.label;
225
+ // Convert connection inputs to the inputs expected in the YAML.
226
+ // FIXME: This is just a placeholder for now.
227
+ // TODO: It seems like using the default value as the value is probably correct?
228
+ result.inputs = Object.entries(configVar.inputs).reduce((result, [key, input]) => {
229
+ var _a;
230
+ return Object.assign(Object.assign({}, result), { [key]: {
231
+ type: types_1.SimpleInputValueType.Value,
232
+ value: (_a = input.default) !== null && _a !== void 0 ? _a : "",
233
+ } });
234
+ }, {});
250
235
  }
251
236
  // Handle data source references.
252
- if ("dataSource" in result && typeof result.dataSource === "string") {
237
+ if ("dataSource" in result) {
253
238
  // This is a reference to a data source we are creating.
254
239
  result.dataSource = {
255
240
  key: result.dataSource,
@@ -280,12 +265,11 @@ const flowFunctionKey = (flowName, functionName) => {
280
265
  ? w.toLowerCase()
281
266
  : w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
282
267
  .join("");
283
- // functionName is only going to be either 'action' or 'trigger'.
284
268
  return `${flowKey}_${functionName}`;
285
269
  };
286
270
  /** Creates the structure necessary to import a Component as part of a
287
271
  * Code Native integration. */
288
- const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [], dataSources = {}, configVars = [], }, referenceKey) => {
272
+ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [], dataSources = {}, configVars = {}, }, referenceKey) => {
289
273
  const convertedActions = flows.reduce((result, { name, onExecution }) => {
290
274
  const actionKey = flowFunctionKey(name, "onExecution");
291
275
  return Object.assign(Object.assign({}, result), { [actionKey]: convertAction(actionKey, {
@@ -317,17 +301,17 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
317
301
  }) });
318
302
  }, {});
319
303
  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) => {
304
+ const convertedConnections = Object.entries(configVars).reduce((result, [key, configVar]) => {
321
305
  if (!("label" in configVar)) {
322
306
  return result;
323
307
  }
324
308
  // Remove a few fields that are not relevant to connections.
325
309
  const {
326
310
  /* eslint-disable @typescript-eslint/no-unused-vars */
327
- orgOnly, visibleToOrgDeployer, visibleToCustomerDeployer } = configVar,
311
+ orgOnly, visibleToOrgDeployer, visibleToCustomerDeployer, stableKey } = configVar,
328
312
  /* eslint-enable @typescript-eslint/no-unused-vars */
329
- connection = __rest(configVar, ["orgOnly", "visibleToOrgDeployer", "visibleToCustomerDeployer"]);
330
- return [...result, convertConnection(connection)];
313
+ connection = __rest(configVar, ["orgOnly", "visibleToOrgDeployer", "visibleToCustomerDeployer", "stableKey"]);
314
+ return [...result, convertConnection(Object.assign(Object.assign({}, connection), { key }))];
331
315
  }, []);
332
316
  return {
333
317
  key: referenceKey,
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { InstanceAttributes, CustomerAttributes, DataSourceType, DataSourceResultType, UserAttributes, TriggerEventFunctionReturn, IntegrationAttributes, FlowAttributes } 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;
@@ -48,9 +48,8 @@ export interface ActionLogger {
48
48
  warn: ActionLoggerFunction;
49
49
  error: ActionLoggerFunction;
50
50
  }
51
- export interface ActionContext {
51
+ export declare type ActionContext<TConfigVars extends ConfigVarResultCollection, THasConfigVars extends boolean = false> = {
52
52
  logger: ActionLogger;
53
- configVars?: Record<string, unknown>;
54
53
  instanceState: Record<string, unknown>;
55
54
  crossFlowState: Record<string, unknown>;
56
55
  executionState: Record<string, unknown>;
@@ -66,7 +65,9 @@ export interface ActionContext {
66
65
  integration: IntegrationAttributes;
67
66
  flow: FlowAttributes;
68
67
  startedAt: string;
69
- }
68
+ } & (THasConfigVars extends true ? {
69
+ configVars: TConfigVars;
70
+ } : Record<string, never>);
70
71
  declare type TriggerOptionChoice = "invalid" | "valid" | "required";
71
72
  export interface TriggerPayload {
72
73
  headers: Record<string, string>;
@@ -111,9 +112,9 @@ interface TriggerBranchingResult extends TriggerBaseResult {
111
112
  branch: string;
112
113
  }
113
114
  export declare type TriggerResult = TriggerBranchingResult | TriggerBaseResult | undefined;
114
- 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>;
115
116
  export declare type TriggerEventFunctionResult = TriggerEventFunctionReturn | void;
116
- 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>;
117
118
  export interface Trigger {
118
119
  key: string;
119
120
  display: DisplayDefinition & {
@@ -213,7 +214,7 @@ interface ServerPerformBranchingDataReturn extends ServerPerformDataReturn {
213
214
  branch: string;
214
215
  }
215
216
  export declare type ActionPerformReturn = ServerPerformDataStructureReturn | ServerPerformBranchingDataStructureReturn | ServerPerformDataReturn | ServerPerformBranchingDataReturn | undefined;
216
- 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>;
217
218
  interface InputFieldChoice {
218
219
  label: string;
219
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, Flow } 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
@@ -60,24 +60,24 @@ export declare const invokeDataSource: <TInputs extends Inputs, TDataSourceType
60
60
  * Invokes specified Flow of a Code Native Integration using supplied params.
61
61
  * Runs the Trigger and then the Action function and returns the result of the Action.
62
62
  */
63
- export declare const invokeFlow: (flow: Flow, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined) => Promise<InvokeReturn<InvokeActionPerformReturn<false, unknown>>>;
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>>>;
64
64
  export declare class ComponentTestHarness<TComponent extends Component> {
65
65
  component: TComponent;
66
66
  constructor(component: TComponent);
67
67
  private buildContext;
68
68
  private buildParams;
69
69
  connectionValue({ key }: ConnectionDefinition): ConnectionValue;
70
- trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>;
71
- triggerOnInstanceDeploy(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<void | TriggerEventFunctionReturn>;
72
- triggerOnInstanceDelete(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<void | TriggerEventFunctionReturn>;
73
- 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>;
74
74
  dataSource(key: string, params?: Record<string, unknown>, context?: Partial<DataSourceContext>): Promise<DataSourceResult>;
75
75
  }
76
76
  export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
77
77
  declare const _default: {
78
78
  loggerMock: () => ActionLogger;
79
- 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>>;
80
- 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>>;
81
81
  createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
82
82
  invokeDataSource: <TInputs_2 extends Inputs, TDataSourceType extends keyof {
83
83
  string: string;
package/dist/testing.js CHANGED
@@ -38,47 +38,32 @@ const loggerMock = () => ({
38
38
  error: (0, jest_mock_1.spyOn)(console, "error"),
39
39
  });
40
40
  exports.loggerMock = loggerMock;
41
- const baseActionContext = {
42
- logger: (0, exports.loggerMock)(),
43
- instanceState: {},
44
- crossFlowState: {},
45
- executionState: {},
46
- integrationState: {},
47
- stepId: "mockStepId",
48
- executionId: "mockExecutionId",
49
- webhookUrls: {
50
- "Flow 1": "https://example.com",
51
- },
52
- webhookApiKeys: {
53
- "Flow 1": ["example-123", "example-456"],
54
- },
55
- invokeUrl: "https://example.com",
56
- customer: {
57
- id: "customerId",
58
- name: "Customer 1",
59
- externalId: "1234",
60
- },
61
- instance: {
62
- id: "instanceId",
63
- name: "Instance 1",
64
- },
65
- user: {
66
- id: "userId",
67
- email: "user@example.com",
68
- name: "User 1",
69
- externalId: "1234",
70
- },
71
- integration: {
72
- id: "integrationId",
73
- name: "Integration 1",
74
- versionSequenceId: "1234",
75
- externalVersion: "1.0.0",
76
- },
77
- flow: {
78
- id: "flowId",
79
- name: "Flow 1",
80
- },
81
- startedAt: new Date().toISOString(),
41
+ const createActionContext = (context) => {
42
+ return Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, integrationState: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
43
+ "Flow 1": "https://example.com",
44
+ }, webhookApiKeys: {
45
+ "Flow 1": ["example-123", "example-456"],
46
+ }, invokeUrl: "https://example.com", customer: {
47
+ id: "customerId",
48
+ name: "Customer 1",
49
+ externalId: "1234",
50
+ }, instance: {
51
+ id: "instanceId",
52
+ name: "Instance 1",
53
+ }, user: {
54
+ id: "userId",
55
+ email: "user@example.com",
56
+ name: "User 1",
57
+ externalId: "1234",
58
+ }, integration: {
59
+ id: "integrationId",
60
+ name: "Integration 1",
61
+ versionSequenceId: "1234",
62
+ externalVersion: "1.0.0",
63
+ }, flow: {
64
+ id: "flowId",
65
+ name: "Flow 1",
66
+ }, startedAt: new Date().toISOString() }, context);
82
67
  };
83
68
  /**
84
69
  * Invokes specified ActionDefinition perform function using supplied params
@@ -86,8 +71,8 @@ const baseActionContext = {
86
71
  * to avoid extra casting within test methods. Returns an InvokeResult containing both the
87
72
  * action result and a mock logger for asserting logging.
88
73
  */
89
- const invoke = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
90
- const realizedContext = Object.assign(Object.assign({}, baseActionContext), context);
74
+ const invoke = ({ perform, }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
75
+ const realizedContext = createActionContext(context);
91
76
  const result = yield perform(realizedContext, params);
92
77
  return {
93
78
  result,
@@ -155,8 +140,8 @@ exports.defaultTriggerPayload = defaultTriggerPayload;
155
140
  * to avoid extra casting within test methods. Returns an InvokeResult containing both the
156
141
  * trigger result and a mock logger for asserting logging.
157
142
  */
158
- const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void 0, void 0, void 0, function* () {
159
- const realizedContext = Object.assign(Object.assign({}, baseActionContext), context);
143
+ const invokeTrigger = ({ perform, }, context, payload, params) => __awaiter(void 0, void 0, void 0, function* () {
144
+ const realizedContext = createActionContext(context);
160
145
  const realizedPayload = Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload);
161
146
  const realizedParams = params || {};
162
147
  const result = yield perform(realizedContext, realizedPayload, realizedParams);
@@ -200,12 +185,14 @@ exports.invokeDataSource = invokeDataSource;
200
185
  * Runs the Trigger and then the Action function and returns the result of the Action.
201
186
  */
202
187
  const invokeFlow = (flow, context, payload) => __awaiter(void 0, void 0, void 0, function* () {
203
- const realizedContext = Object.assign(Object.assign({}, baseActionContext), context);
188
+ const realizedContext = createActionContext(context);
204
189
  const realizedPayload = Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload);
205
- const params = {};
190
+ const params = {
191
+ onTrigger: { results: null },
192
+ };
206
193
  if ("onTrigger" in flow) {
207
194
  const triggerResult = yield flow.onTrigger(realizedContext, realizedPayload, params);
208
- params.trigger = triggerResult;
195
+ params.onTrigger = { results: triggerResult === null || triggerResult === void 0 ? void 0 : triggerResult.payload };
209
196
  }
210
197
  const result = yield flow.onExecution(realizedContext, params);
211
198
  return {
@@ -236,7 +223,7 @@ class ComponentTestHarness {
236
223
  trigger(key, payload, params, context) {
237
224
  return __awaiter(this, void 0, void 0, function* () {
238
225
  const trigger = this.component.triggers[key];
239
- return trigger.perform(this.buildContext(baseActionContext, context), Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), this.buildParams(trigger.inputs, params));
226
+ return trigger.perform(createActionContext(context), Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), this.buildParams(trigger.inputs, params));
240
227
  });
241
228
  }
242
229
  triggerOnInstanceDeploy(key, params, context) {
@@ -245,7 +232,7 @@ class ComponentTestHarness {
245
232
  if (!trigger.onInstanceDeploy) {
246
233
  throw new Error("Trigger does not support onInstanceDeploy");
247
234
  }
248
- return trigger.onInstanceDeploy(this.buildContext(baseActionContext, context), this.buildParams(trigger.inputs, params));
235
+ return trigger.onInstanceDeploy(createActionContext(context), this.buildParams(trigger.inputs, params));
249
236
  });
250
237
  }
251
238
  triggerOnInstanceDelete(key, params, context) {
@@ -254,13 +241,13 @@ class ComponentTestHarness {
254
241
  if (!trigger.onInstanceDelete) {
255
242
  throw new Error("Trigger does not support onInstanceDelete");
256
243
  }
257
- return trigger.onInstanceDelete(this.buildContext(baseActionContext, context), this.buildParams(trigger.inputs, params));
244
+ return trigger.onInstanceDelete(createActionContext(context), this.buildParams(trigger.inputs, params));
258
245
  });
259
246
  }
260
247
  action(key, params, context) {
261
248
  return __awaiter(this, void 0, void 0, function* () {
262
249
  const action = this.component.actions[key];
263
- return action.perform(this.buildContext(baseActionContext, context), this.buildParams(action.inputs, params));
250
+ return action.perform(createActionContext(context), this.buildParams(action.inputs, params));
264
251
  });
265
252
  }
266
253
  dataSource(key, params, context) {
@@ -1,13 +1,13 @@
1
- import { ActionDisplayDefinition, ActionPerformFunction, ActionPerformReturn, Inputs } from ".";
1
+ import { ActionDisplayDefinition, ActionPerformFunction, ActionPerformReturn, ConfigVarResultCollection, Inputs } from ".";
2
2
  /**
3
3
  * ActionDefinition is the type of the object that is passed in to `action` function to
4
4
  * define a component action.
5
5
  */
6
- export interface ActionDefinition<TInputs extends Inputs, TAllowsBranching extends boolean, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>> {
6
+ export interface ActionDefinition<TInputs extends Inputs = Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TAllowsBranching extends boolean = boolean, TReturn extends ActionPerformReturn<TAllowsBranching, unknown> = ActionPerformReturn<TAllowsBranching, unknown>> {
7
7
  /** Defines how the Action is displayed in the Prismatic interface. */
8
8
  display: ActionDisplayDefinition;
9
9
  /** Function to perform when this Action is invoked. */
10
- perform: ActionPerformFunction<TInputs, TAllowsBranching, TReturn>;
10
+ perform: ActionPerformFunction<TInputs, TConfigVars, false, TAllowsBranching, TReturn>;
11
11
  /** InputFields to present in the Prismatic interface for configuration of this Action. */
12
12
  inputs: TInputs;
13
13
  /** Optional attribute that specifies whether an Action will terminate execution.*/
@@ -1,6 +1,6 @@
1
1
  import { Inputs } from ".";
2
2
  import { ConditionalExpression } from "./conditional-logic";
3
- import { InputFieldCollection, InputCleanFunction, Connection } from "./Inputs";
3
+ import { InputFieldCollection, InputCleanFunction, Connection, KeyValuePair } from "./Inputs";
4
4
  /**
5
5
  * Collection of input parameters.
6
6
  * Inputs can be static values, references to config variables, or
@@ -10,16 +10,3 @@ export declare type ActionInputParameters<TInputs extends Inputs> = {
10
10
  [Property in keyof TInputs]: TInputs[Property]["clean"] extends InputCleanFunction<any> ? ReturnType<TInputs[Property]["clean"]> : TInputs[Property]["type"] extends "connection" ? ExtractValue<Connection, TInputs[Property]["collection"]> : TInputs[Property]["type"] extends "conditional" ? ExtractValue<ConditionalExpression, TInputs[Property]["collection"]> : ExtractValue<TInputs[Property]["default"], TInputs[Property]["collection"]>;
11
11
  };
12
12
  export declare type ExtractValue<TType, TCollection extends InputFieldCollection | undefined> = TCollection extends "keyvaluelist" ? KeyValuePair<TType>[] : TCollection extends "valuelist" ? TType[] : TType;
13
- /**
14
- * KeyValuePair input parameter type.
15
- * This allows users to input multiple keys / values as an input.
16
- * To see an example of how this can be used, see the `tagging` input
17
- * of the `putObject` action of the AWS S3 component:
18
- * https://github.com/prismatic-io/examples/blob/main/components/aws-s3/src/actions.ts
19
- */
20
- export interface KeyValuePair<V = unknown> {
21
- /** Key of the KeyValuePair */
22
- key: string;
23
- /** Value of the KeyValuePair */
24
- value: V;
25
- }
@@ -1,12 +1,10 @@
1
- import { Inputs, ActionPerformReturn, ActionInputParameters, ActionLogger, InstanceAttributes, CustomerAttributes, UserAttributes, IntegrationAttributes, FlowAttributes } from ".";
1
+ import { Inputs, ConfigVarResultCollection, ActionPerformReturn, ActionInputParameters, ActionLogger, InstanceAttributes, CustomerAttributes, UserAttributes, IntegrationAttributes, FlowAttributes } from ".";
2
2
  /** Definition of the function to perform when an Action is invoked. */
3
- export declare type ActionPerformFunction<TInputs extends Inputs, TAllowsBranching extends boolean | undefined, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>> = (context: ActionContext, params: ActionInputParameters<TInputs>) => Promise<TReturn>;
3
+ export declare type ActionPerformFunction<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, THasConfigVars extends boolean, TAllowsBranching extends boolean | undefined, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>> = (context: ActionContext<TConfigVars, THasConfigVars>, params: ActionInputParameters<TInputs>) => Promise<TReturn>;
4
4
  /** Context provided to perform method containing helpers and contextual data */
5
- export interface ActionContext {
5
+ export declare type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, THasConfigVars extends boolean = false> = {
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>;
10
8
  /** A a flow-specific key/value store that may be used to store small amounts of data that is persisted between Instance executions */
11
9
  instanceState: Record<string, unknown>;
12
10
  /** 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 */
@@ -37,4 +35,7 @@ export interface ActionContext {
37
35
  flow: FlowAttributes;
38
36
  /** The time in UTC that execution started. */
39
37
  startedAt: string;
40
- }
38
+ } & (THasConfigVars extends true ? {
39
+ /** Key/value collection of config variables of the integration. */
40
+ configVars: TConfigVars;
41
+ } : Record<string, never>);
@@ -13,9 +13,9 @@ export declare type ComponentDefinition<TPublic extends boolean, TKey extends st
13
13
  /** Defines how the Component is displayed in the Prismatic interface. */
14
14
  display: ComponentDisplayDefinition<TPublic>;
15
15
  /** Specifies the supported Actions of this Component. */
16
- actions?: Record<string, ActionDefinition<any, boolean, any>>;
16
+ actions?: Record<string, ActionDefinition<any, any, boolean, any>>;
17
17
  /** Specifies the supported Triggers of this Component. */
18
- triggers?: Record<string, TriggerDefinition<any, boolean, any>>;
18
+ triggers?: Record<string, TriggerDefinition<any, any, boolean, any>>;
19
19
  /** Specifies the supported Data Sources of this Component. */
20
20
  dataSources?: Record<string, DataSourceDefinition<any, any>>;
21
21
  /** Specifies the supported Connections of this Component. */