@prismatic-io/spectral 8.0.0-preview8 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/clients/http/index.d.ts +1 -1
  2. package/dist/index.d.ts +15 -16
  3. package/dist/index.js +11 -10
  4. package/dist/serverTypes/convert.d.ts +3 -3
  5. package/dist/serverTypes/convert.js +6 -270
  6. package/dist/serverTypes/convertIntegration.d.ts +3 -0
  7. package/dist/serverTypes/convertIntegration.js +242 -0
  8. package/dist/serverTypes/index.d.ts +10 -9
  9. package/dist/serverTypes/integration.d.ts +60 -0
  10. package/dist/serverTypes/integration.js +4 -0
  11. package/dist/testing.d.ts +20 -20
  12. package/dist/testing.js +67 -76
  13. package/dist/types/ActionDefinition.d.ts +3 -3
  14. package/dist/types/ActionInputParameters.d.ts +1 -14
  15. package/dist/types/ActionPerformFunction.d.ts +6 -6
  16. package/dist/types/ComponentDefinition.d.ts +3 -3
  17. package/dist/types/DataSourceDefinition.d.ts +3 -3
  18. package/dist/types/DataSourcePerformFunction.d.ts +3 -8
  19. package/dist/types/DataSourceResult.d.ts +1 -3
  20. package/dist/types/Inputs.d.ts +52 -42
  21. package/dist/types/IntegrationDefinition.d.ts +44 -118
  22. package/dist/types/IntegrationDefinition.js +5 -19
  23. package/dist/types/TriggerDefinition.d.ts +5 -5
  24. package/dist/types/TriggerEventFunction.d.ts +2 -2
  25. package/dist/types/TriggerPerformFunction.d.ts +2 -2
  26. package/dist/types/TriggerResult.d.ts +4 -4
  27. package/dist/types/utils.d.ts +5 -0
  28. package/dist/types/utils.js +2 -0
  29. package/package.json +5 -4
  30. package/dist/clients/soap/index.d.ts +0 -2
  31. package/dist/clients/soap/index.js +0 -18
  32. package/dist/clients/soap/types.d.ts +0 -71
  33. package/dist/clients/soap/types.js +0 -24
  34. package/dist/clients/soap/utils.d.ts +0 -12
  35. package/dist/clients/soap/utils.js +0 -191
@@ -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,9 @@
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";
7
- import { convertComponent, convertIntegration } from "./serverTypes/convert";
6
+ import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, IntegrationDefinition, Flow, ConfigPage, StandardConfigVar, ConnectionConfigVar, ConfigVarResultCollection, TriggerPayload, DataSourceConfigVar, ConfigPages } from "./types";
7
+ import { convertComponent } from "./serverTypes/convert";
8
+ import { convertIntegration } from "./serverTypes/convertIntegration";
8
9
  /**
9
10
  * This function creates a Integration object that can be
10
11
  * imported into the Prismatic API. For information on using
@@ -13,14 +14,14 @@ import { convertComponent, convertIntegration } from "./serverTypes/convert";
13
14
  * @param definition An IntegrationDefinition type object.
14
15
  * @returns This function returns an integration object that has the shape the Prismatic API expects.
15
16
  */
16
- export declare const integration: (definition: IntegrationDefinition) => ReturnType<typeof convertIntegration>;
17
+ export declare const integration: <TConfigPages extends ConfigPages = ConfigPages>(definition: IntegrationDefinition<TConfigPages>) => ReturnType<typeof convertIntegration>;
17
18
  /**
18
19
  * For information on writing Code Native Integrations, see
19
20
  * https://prismatic.io/docs/code-native-integrations/#adding-flows.
20
21
  * @param definition A Flow type object.
21
22
  * @returns This function returns a flow object that has the shape the Prismatic API expects.
22
23
  */
23
- export declare const flow: <T extends Flow>(definition: T) => T;
24
+ export declare const flow: <TConfigPages extends ConfigPages = ConfigPages, TTriggerPayload extends TriggerPayload = TriggerPayload, T extends Flow<TConfigPages, TTriggerPayload> = Flow<TConfigPages, TTriggerPayload>>(definition: T) => T;
24
25
  /**
25
26
  * For information on writing Code Native Integrations, see
26
27
  * https://prismatic.io/docs/code-native-integrations/#adding-config-pages.
@@ -38,17 +39,17 @@ export declare const configVar: <T extends StandardConfigVar>(definition: T) =>
38
39
  /**
39
40
  * For information on writing Code Native Integrations, see
40
41
  * 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.
42
+ * @param definition A Data Source Config Var type object.
43
+ * @returns This function returns a data source config var object that has the shape the Prismatic API expects.
43
44
  */
44
- export declare const connectionConfigVar: <T extends ConnectionConfigVar>(definition: T) => T;
45
+ export declare const dataSourceConfigVar: <T extends DataSourceConfigVar>(definition: T) => T;
45
46
  /**
46
47
  * For information on writing Code Native Integrations, see
47
48
  * 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.
49
+ * @param definition A Connection Config Var type object.
50
+ * @returns This function returns a connection config var object that has the shape the Prismatic API expects.
50
51
  */
51
- export declare const connectionRefConfigVar: <T extends ConnectionRefConfigVar>(definition: T) => T;
52
+ export declare const connectionConfigVar: <T extends ConnectionConfigVar>(definition: T) => T;
52
53
  /**
53
54
  * This function creates a component object that can be
54
55
  * imported into the Prismatic API. For information on using
@@ -67,7 +68,7 @@ export declare const component: <TPublic extends boolean, TKey extends string>(d
67
68
  * @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
69
  * @returns This function validates the shape of the `definition` object provided, and returns the same action object.
69
70
  */
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>;
71
+ 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
72
  /**
72
73
  * This function creates a trigger object that can be referenced
73
74
  * by a custom component. It helps ensure that the shape of the
@@ -77,7 +78,7 @@ export declare const action: <TInputs extends Inputs, TAllowsBranching extends b
77
78
  * @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
79
  * @returns This function validates the shape of the `definition` object provided, and returns the same trigger object.
79
80
  */
80
- export declare const trigger: <TInputs extends Inputs, TAllowsBranching extends boolean, TResult extends TriggerResult<TAllowsBranching>>(definition: TriggerDefinition<TInputs, TAllowsBranching, TResult>) => TriggerDefinition<TInputs, TAllowsBranching, TResult>;
81
+ 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
82
  /**
82
83
  * This function creates a data source object that can be referenced
83
84
  * by a custom component. It helps ensure that the shape of the
@@ -87,7 +88,7 @@ export declare const trigger: <TInputs extends Inputs, TAllowsBranching extends
87
88
  * @param definition A DataSourceDefinition type object that includes UI display information, a function to perform when the data source is invoked, and a an object containing inputs for the perform function.
88
89
  * @returns This function validates the shape of the `definition` object provided, and returns the same data source object.
89
90
  */
90
- export declare const dataSource: <TInputs extends Inputs, TDataSourceType extends keyof {
91
+ export declare const dataSource: <TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TDataSourceType extends keyof {
91
92
  string: string;
92
93
  date: string;
93
94
  timestamp: string;
@@ -96,14 +97,12 @@ export declare const dataSource: <TInputs extends Inputs, TDataSourceType extend
96
97
  value: string;
97
98
  };
98
99
  code: string;
99
- credential: unknown;
100
100
  boolean: boolean;
101
101
  number: number;
102
- connection: import("./types").Connection;
103
102
  objectSelection: import("./types").ObjectSelection;
104
103
  objectFieldMap: import("./types").ObjectFieldMap;
105
104
  jsonForm: import("./types").JSONForm;
106
- }>(definition: DataSourceDefinition<TInputs, TDataSourceType>) => DataSourceDefinition<TInputs, TDataSourceType>;
105
+ }>(definition: DataSourceDefinition<TInputs, TConfigVars, TDataSourceType>) => DataSourceDefinition<TInputs, TConfigVars, TDataSourceType>;
107
106
  /**
108
107
  * For information and examples on how to write inputs
109
108
  * for custom component actions and triggers, see
package/dist/index.js CHANGED
@@ -22,8 +22,9 @@ 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.dataSourceConfigVar = exports.configVar = exports.configPage = exports.flow = exports.integration = void 0;
26
26
  const convert_1 = require("./serverTypes/convert");
27
+ const convertIntegration_1 = require("./serverTypes/convertIntegration");
27
28
  /**
28
29
  * This function creates a Integration object that can be
29
30
  * imported into the Prismatic API. For information on using
@@ -32,7 +33,7 @@ const convert_1 = require("./serverTypes/convert");
32
33
  * @param definition An IntegrationDefinition type object.
33
34
  * @returns This function returns an integration object that has the shape the Prismatic API expects.
34
35
  */
35
- const integration = (definition) => (0, convert_1.convertIntegration)(definition);
36
+ const integration = (definition) => (0, convertIntegration_1.convertIntegration)(definition);
36
37
  exports.integration = integration;
37
38
  /**
38
39
  * For information on writing Code Native Integrations, see
@@ -61,19 +62,19 @@ exports.configVar = configVar;
61
62
  /**
62
63
  * For information on writing Code Native Integrations, see
63
64
  * 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.
65
+ * @param definition A Data Source Config Var type object.
66
+ * @returns This function returns a data source config var object that has the shape the Prismatic API expects.
66
67
  */
67
- const connectionConfigVar = (definition) => definition;
68
- exports.connectionConfigVar = connectionConfigVar;
68
+ const dataSourceConfigVar = (definition) => definition;
69
+ exports.dataSourceConfigVar = dataSourceConfigVar;
69
70
  /**
70
71
  * For information on writing Code Native Integrations, see
71
72
  * 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.
73
+ * @param definition A Connection Config Var type object.
74
+ * @returns This function returns a connection config var object that has the shape the Prismatic API expects.
74
75
  */
75
- const connectionRefConfigVar = (definition) => definition;
76
- exports.connectionRefConfigVar = connectionRefConfigVar;
76
+ const connectionConfigVar = (definition) => definition;
77
+ exports.connectionConfigVar = connectionConfigVar;
77
78
  /**
78
79
  * This function creates a component object that can be
79
80
  * imported into the Prismatic API. For information on using
@@ -1,4 +1,4 @@
1
- import { ComponentDefinition, IntegrationDefinition } from "../types";
2
- import { Component as ServerComponent } from ".";
1
+ import { InputFieldDefinition, ComponentDefinition } from "../types";
2
+ import { Component as ServerComponent, Input as ServerInput } from ".";
3
+ export declare const convertInput: (key: string, { default: defaultValue, type, label, collection, ...rest }: InputFieldDefinition) => ServerInput;
3
4
  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,13 +10,8 @@ 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
- };
16
13
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.convertIntegration = exports.convertComponent = void 0;
18
- const yaml_1 = __importDefault(require("yaml"));
19
- const uuid_1 = require("uuid");
14
+ exports.convertComponent = exports.convertInput = void 0;
20
15
  const types_1 = require("../types");
21
16
  const perform_1 = require("./perform");
22
17
  const convertInput = (key, _a) => {
@@ -27,9 +22,10 @@ const convertInput = (key, _a) => {
27
22
  return Object.assign(Object.assign({}, rest), { key,
28
23
  type, default: defaultValue !== null && defaultValue !== void 0 ? defaultValue : types_1.InputFieldDefaultMap[type], collection, label: typeof label === "string" ? label : label.value, keyLabel });
29
24
  };
25
+ exports.convertInput = convertInput;
30
26
  const convertAction = (actionKey, _a, hooks) => {
31
27
  var { inputs = {}, perform } = _a, action = __rest(_a, ["inputs", "perform"]);
32
- const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
28
+ const convertedInputs = Object.entries(inputs).map(([key, value]) => (0, exports.convertInput)(key, value));
33
29
  const inputCleaners = Object.entries(inputs).reduce((result, [key, { clean }]) => (Object.assign(Object.assign({}, result), { [key]: clean })), {});
34
30
  return Object.assign(Object.assign({}, action), { key: actionKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
35
31
  inputCleaners,
@@ -38,7 +34,7 @@ const convertAction = (actionKey, _a, hooks) => {
38
34
  };
39
35
  const convertTrigger = (triggerKey, _a, hooks) => {
40
36
  var { inputs = {}, perform, onInstanceDeploy, onInstanceDelete } = _a, trigger = __rest(_a, ["inputs", "perform", "onInstanceDeploy", "onInstanceDelete"]);
41
- const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
37
+ const convertedInputs = Object.entries(inputs).map(([key, value]) => (0, exports.convertInput)(key, value));
42
38
  const inputCleaners = Object.entries(inputs).reduce((result, [key, { clean }]) => (Object.assign(Object.assign({}, result), { [key]: clean })), {});
43
39
  const result = Object.assign(Object.assign({}, trigger), { key: triggerKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
44
40
  inputCleaners,
@@ -62,7 +58,7 @@ const convertTrigger = (triggerKey, _a, hooks) => {
62
58
  };
63
59
  const convertDataSource = (dataSourceKey, _a, hooks) => {
64
60
  var { inputs = {}, perform } = _a, dataSource = __rest(_a, ["inputs", "perform"]);
65
- const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
61
+ const convertedInputs = Object.entries(inputs).map(([key, value]) => (0, exports.convertInput)(key, value));
66
62
  const inputCleaners = Object.entries(inputs).reduce((result, [key, { clean }]) => (Object.assign(Object.assign({}, result), { [key]: clean })), {});
67
63
  return Object.assign(Object.assign({}, dataSource), { key: dataSourceKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
68
64
  inputCleaners,
@@ -71,7 +67,7 @@ const convertDataSource = (dataSourceKey, _a, hooks) => {
71
67
  };
72
68
  const convertConnection = (_a) => {
73
69
  var { inputs = {} } = _a, connection = __rest(_a, ["inputs"]);
74
- const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
70
+ const convertedInputs = Object.entries(inputs).map(([key, value]) => (0, exports.convertInput)(key, value));
75
71
  return Object.assign(Object.assign({}, connection), { inputs: convertedInputs });
76
72
  };
77
73
  const convertComponent = (_a) => {
@@ -82,263 +78,3 @@ const convertComponent = (_a) => {
82
78
  return Object.assign(Object.assign({}, definition), { connections: connections.map(convertConnection), actions: convertedActions, triggers: convertedTriggers, dataSources: convertedDataSources });
83
79
  };
84
80
  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: configVars === null || configVars === void 0 ? void 0 : configVars.map((configVar) => convertConfigVar(configVar, referenceKey)),
125
- endpointType,
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),
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: `${flow.name} - onTrigger`,
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
- };
151
- if ("onTrigger" in flow) {
152
- triggerStep.action = {
153
- key: flowFunctionKey(flow.name, "onTrigger"),
154
- 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
- }
166
- if ("schedule" in flow && typeof flow.schedule === "object") {
167
- triggerStep.schedule = {
168
- type: "cronExpression" in flow.schedule
169
- ? types_1.SimpleInputValueType.Value
170
- : types_1.SimpleInputValueType.ConfigVar,
171
- value: "cronExpression" in flow.schedule
172
- ? flow.schedule.cronExpression
173
- : flow.schedule.configVarKey,
174
- meta: {
175
- scheduleType: types_1.ScheduleType.Custom,
176
- timeZone: flow.schedule.timeZone,
177
- },
178
- };
179
- delete result.schedule;
180
- }
181
- const actionStep = {
182
- action: {
183
- key: flowFunctionKey(flow.name, "onExecution"),
184
- component: { key: referenceKey, version: "LATEST", isPublic: false },
185
- },
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,
189
- };
190
- result.steps = [triggerStep, actionStep];
191
- return result;
192
- };
193
- /** Converts a Config Var into the structure necessary for YAML generation. */
194
- const convertConfigVar = (configVar, referenceKey) => {
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: {} });
217
- // Handle some non-standard fields.
218
- if ("visibleToOrgDeployer" in configVar) {
219
- result.meta.visibleToOrgDeployer = configVar.visibleToOrgDeployer;
220
- }
221
- if ("visibleToCustomerDeployer" in configVar) {
222
- result.meta.visibleToCustomerDeployer = configVar.visibleToCustomerDeployer;
223
- }
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
- }
250
- }
251
- // Handle data source references.
252
- if ("dataSource" in result && typeof result.dataSource === "string") {
253
- // This is a reference to a data source we are creating.
254
- result.dataSource = {
255
- key: result.dataSource,
256
- component: { key: referenceKey, version: "LATEST", isPublic: false },
257
- };
258
- }
259
- return result;
260
- };
261
- /** Maps the step name field to a fully qualified input. */
262
- const fieldNameToReferenceInput = (stepName, fieldName) => {
263
- if (!fieldName) {
264
- return undefined;
265
- }
266
- return {
267
- type: types_1.SimpleInputValueType.Reference,
268
- value: `${stepName}.results.${fieldName}`,
269
- };
270
- };
271
- /** Actions and Triggers will be scoped to their flow by combining the flow
272
- * name and the function name. This is to ensure that the keys are unique
273
- * on the resulting object, which will be turned into a Component. */
274
- const flowFunctionKey = (flowName, functionName) => {
275
- const flowKey = flowName
276
- .replace(/[^0-9a-zA-Z]+/g, " ")
277
- .trim()
278
- .split(" ")
279
- .map((w, i) => i === 0
280
- ? w.toLowerCase()
281
- : w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
282
- .join("");
283
- // functionName is only going to be either 'action' or 'trigger'.
284
- return `${flowKey}_${functionName}`;
285
- };
286
- /** Creates the structure necessary to import a Component as part of a
287
- * Code Native integration. */
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
- }) });
299
- }, {});
300
- const convertedTriggers = flows.reduce((result, flow) => {
301
- // Filter out TriggerReferences.
302
- if ("trigger" in flow)
303
- return result;
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
- }) });
318
- }, {});
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
- }, []);
332
- return {
333
- key: referenceKey,
334
- display: {
335
- label: referenceKey,
336
- iconPath,
337
- description: description || name,
338
- },
339
- connections: convertedConnections,
340
- actions: convertedActions,
341
- triggers: convertedTriggers,
342
- dataSources: convertedDataSources,
343
- };
344
- };
@@ -0,0 +1,3 @@
1
+ import { IntegrationDefinition, ConfigPages } from "../types";
2
+ import { Component as ServerComponent } from ".";
3
+ export declare const convertIntegration: (definition: IntegrationDefinition<ConfigPages>) => ServerComponent;