@prismatic-io/spectral 8.1.7 → 9.0.0-rc.2

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 (75) hide show
  1. package/bin/component-manifest.js +2 -0
  2. package/dist/generators/componentManifest/cli.d.ts +2 -0
  3. package/dist/generators/componentManifest/cli.js +134 -0
  4. package/dist/generators/componentManifest/createActions.d.ts +13 -0
  5. package/dist/generators/componentManifest/createActions.js +95 -0
  6. package/dist/generators/componentManifest/createConnections.d.ts +13 -0
  7. package/dist/generators/componentManifest/createConnections.js +95 -0
  8. package/dist/generators/componentManifest/createDataSources.d.ts +13 -0
  9. package/dist/generators/componentManifest/createDataSources.js +95 -0
  10. package/dist/generators/componentManifest/createStaticFiles.d.ts +80 -0
  11. package/dist/generators/componentManifest/createStaticFiles.js +145 -0
  12. package/dist/generators/componentManifest/createTriggers.d.ts +13 -0
  13. package/dist/generators/componentManifest/createTriggers.js +95 -0
  14. package/dist/generators/componentManifest/getImports.d.ts +7 -0
  15. package/dist/generators/componentManifest/getImports.js +16 -0
  16. package/dist/generators/componentManifest/getInputs.d.ts +23 -0
  17. package/dist/generators/componentManifest/getInputs.js +66 -0
  18. package/dist/generators/componentManifest/helpers.d.ts +5 -0
  19. package/dist/generators/componentManifest/helpers.js +11 -0
  20. package/dist/generators/componentManifest/index.d.ts +15 -0
  21. package/dist/generators/componentManifest/index.js +78 -0
  22. package/dist/generators/componentManifest/removeComponentManifest.d.ts +6 -0
  23. package/dist/generators/componentManifest/removeComponentManifest.js +19 -0
  24. package/dist/generators/componentManifest/templates/README.md.ejs +186 -0
  25. package/dist/generators/componentManifest/templates/actions/action.ts.ejs +14 -0
  26. package/dist/generators/componentManifest/templates/actions/index.ts.ejs +1 -0
  27. package/dist/generators/componentManifest/templates/connections/connection.ts.ejs +14 -0
  28. package/dist/generators/componentManifest/templates/connections/index.ts.ejs +1 -0
  29. package/dist/generators/componentManifest/templates/dataSources/dataSource.ts.ejs +14 -0
  30. package/dist/generators/componentManifest/templates/dataSources/index.ts.ejs +1 -0
  31. package/dist/generators/componentManifest/templates/index.ts.ejs +20 -0
  32. package/dist/generators/componentManifest/templates/package.json.ejs +23 -0
  33. package/dist/generators/componentManifest/templates/partials/importBarrel.ejs +9 -0
  34. package/dist/generators/componentManifest/templates/partials/imports.ejs +1 -0
  35. package/dist/generators/componentManifest/templates/partials/inputTypes.ejs +10 -0
  36. package/dist/generators/componentManifest/templates/triggers/index.ts.ejs +1 -0
  37. package/dist/generators/componentManifest/templates/triggers/trigger.ts.ejs +14 -0
  38. package/dist/generators/componentManifest/templates/tsconfig.json.ejs +15 -0
  39. package/dist/generators/utils/capitalizeFirstLetter.d.ts +1 -0
  40. package/dist/generators/utils/capitalizeFirstLetter.js +5 -0
  41. package/dist/generators/utils/createDependencyImports.d.ts +5 -0
  42. package/dist/generators/utils/createDependencyImports.js +9 -0
  43. package/dist/generators/utils/createFlagHelpText.d.ts +12 -0
  44. package/dist/generators/utils/createFlagHelpText.js +19 -0
  45. package/dist/generators/utils/createTemplate.d.ts +9 -0
  46. package/dist/generators/utils/createTemplate.js +59 -0
  47. package/dist/generators/utils/generatePackageJsonVersion.d.ts +1 -0
  48. package/dist/generators/utils/generatePackageJsonVersion.js +14 -0
  49. package/dist/generators/utils/getComponentSignatureWithPrism.d.ts +1 -0
  50. package/dist/generators/utils/getComponentSignatureWithPrism.js +41 -0
  51. package/dist/generators/utils/getFlagBooleanValue.d.ts +11 -0
  52. package/dist/generators/utils/getFlagBooleanValue.js +17 -0
  53. package/dist/generators/utils/getFlagStringValue.d.ts +11 -0
  54. package/dist/generators/utils/getFlagStringValue.js +25 -0
  55. package/dist/generators/utils/truncatePathByFolder.d.ts +1 -0
  56. package/dist/generators/utils/truncatePathByFolder.js +5 -0
  57. package/dist/index.d.ts +14 -15
  58. package/dist/index.js +9 -9
  59. package/dist/serverTypes/convertIntegration.d.ts +2 -2
  60. package/dist/serverTypes/convertIntegration.js +83 -36
  61. package/dist/serverTypes/index.d.ts +3 -2
  62. package/dist/serverTypes/integration.d.ts +10 -2
  63. package/dist/testing.d.ts +7 -7
  64. package/dist/testing.js +1 -1
  65. package/dist/types/ActionDefinition.d.ts +2 -1
  66. package/dist/types/ActionPerformFunction.d.ts +5 -3
  67. package/dist/types/ComponentManifest.d.ts +13 -0
  68. package/dist/types/ComponentManifest.js +2 -0
  69. package/dist/types/IntegrationDefinition.d.ts +129 -70
  70. package/dist/types/IntegrationDefinition.js +4 -4
  71. package/dist/types/index.d.ts +1 -0
  72. package/dist/types/index.js +1 -0
  73. package/dist/util.d.ts +2 -0
  74. package/dist/util.js +17 -10
  75. package/package.json +12 -6
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, ConfigVarResultCollection, TriggerPayload, DataSourceConfigVar, ConfigPages, OnPremConnectionDefinition, ScheduleConfigVar, ComponentSelector } from "./types";
6
+ import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, IntegrationDefinition, Flow, ConfigPage, StandardConfigVar, ConnectionConfigVar, ConfigVarResultCollection, TriggerPayload, DataSourceConfigVar, OnPremConnectionDefinition, ScheduleConfigVar, ComponentManifest } from "./types";
7
7
  import { convertComponent } from "./serverTypes/convert";
8
8
  import { convertIntegration } from "./serverTypes/convertIntegration";
9
9
  /**
@@ -14,28 +14,21 @@ import { convertIntegration } from "./serverTypes/convertIntegration";
14
14
  * @param definition An IntegrationDefinition type object.
15
15
  * @returns This function returns an integration object that has the shape the Prismatic API expects.
16
16
  */
17
- export declare const integration: <T extends IntegrationDefinition<any, any> = IntegrationDefinition<any, any>>(definition: T) => ReturnType<typeof convertIntegration>;
17
+ export declare const integration: <T extends IntegrationDefinition = IntegrationDefinition>(definition: T) => ReturnType<typeof convertIntegration>;
18
18
  /**
19
19
  * For information on writing Code Native Integrations, see
20
20
  * https://prismatic.io/docs/code-native-integrations/#adding-flows.
21
21
  * @param definition A Flow type object.
22
22
  * @returns This function returns a flow object that has the shape the Prismatic API expects.
23
23
  */
24
- export declare const flow: <TConfigPages extends ConfigPages<any> = ConfigPages<any>, TComponents extends ComponentSelector<any> = ComponentSelector<any>, TTriggerPayload extends TriggerPayload = TriggerPayload, T extends Flow<TConfigPages, TComponents, TTriggerPayload> = Flow<TConfigPages, TComponents, TTriggerPayload>>(definition: T) => T;
24
+ export declare const flow: <TTriggerPayload extends TriggerPayload = TriggerPayload, T extends Flow<TTriggerPayload> = Flow<TTriggerPayload>>(definition: T) => T;
25
25
  /**
26
26
  * For information on writing Code Native Integrations, see
27
27
  * https://prismatic.io/docs/code-native-integrations/#adding-config-pages.
28
28
  * @param definition A Config Page type object.
29
29
  * @returns This function returns a config page object that has the shape the Prismatic API expects.
30
30
  */
31
- export declare const configPage: <T extends ConfigPage<any> = ConfigPage<any>>(definition: T) => T;
32
- /**
33
- * @returns Helper utility to create component references.
34
- */
35
- export declare const reference: <TComponents extends ComponentSelector<any>>() => {
36
- connection: <T extends ConnectionConfigVar<TComponents>>(definition: T) => T;
37
- dataSource: <T_1 extends DataSourceConfigVar<TComponents>>(definition: T_1) => T_1;
38
- };
31
+ export declare const configPage: <T extends ConfigPage = ConfigPage>(definition: T) => T;
39
32
  /**
40
33
  * For information on writing Code Native Integrations, see
41
34
  * https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
@@ -49,14 +42,19 @@ export declare const configVar: <T extends StandardConfigVar | ScheduleConfigVar
49
42
  * @param definition A Data Source Config Var type object.
50
43
  * @returns This function returns a data source config var object that has the shape the Prismatic API expects.
51
44
  */
52
- export declare const dataSourceConfigVar: <T extends DataSourceConfigVar<any> = DataSourceConfigVar<any>>(definition: T) => T;
45
+ export declare const dataSourceConfigVar: <TDataSourceConfigVar extends DataSourceConfigVar>(definition: TDataSourceConfigVar) => TDataSourceConfigVar;
53
46
  /**
54
47
  * For information on writing Code Native Integrations, see
55
48
  * https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
56
49
  * @param definition A Connection Config Var type object.
57
50
  * @returns This function returns a connection config var object that has the shape the Prismatic API expects.
58
51
  */
59
- export declare const connectionConfigVar: <T extends ConnectionConfigVar<any> = ConnectionConfigVar<any>>(definition: T) => T;
52
+ export declare const connectionConfigVar: <T extends ConnectionConfigVar = ConnectionConfigVar>(definition: T) => T;
53
+ /**
54
+ * @param definition A Component Manifest type object.
55
+ * @returns This function returns a component manifest object that has the shape the Prismatic API expects.
56
+ */
57
+ export declare const componentManifest: <T extends ComponentManifest>(definition: T) => T;
60
58
  /**
61
59
  * This function creates a component object that can be
62
60
  * imported into the Prismatic API. For information on using
@@ -75,7 +73,7 @@ export declare const component: <TPublic extends boolean, TKey extends string>(d
75
73
  * @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.
76
74
  * @returns This function validates the shape of the `definition` object provided, and returns the same action object.
77
75
  */
78
- 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>;
76
+ export declare const action: <TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>>(definition: ActionDefinition<TInputs, TConfigVars, TAllowsBranching, TReturn>) => ActionDefinition<TInputs, TConfigVars, TAllowsBranching, TReturn>;
79
77
  /**
80
78
  * This function creates a trigger object that can be referenced
81
79
  * by a custom component. It helps ensure that the shape of the
@@ -85,7 +83,7 @@ export declare const action: <TInputs extends Inputs, TConfigVar extends ConfigV
85
83
  * @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.
86
84
  * @returns This function validates the shape of the `definition` object provided, and returns the same trigger object.
87
85
  */
88
- 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>;
86
+ export declare const trigger: <TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean, TResult extends TriggerResult<TAllowsBranching, TriggerPayload>>(definition: TriggerDefinition<TInputs, TConfigVars, TAllowsBranching, TResult>) => TriggerDefinition<TInputs, TConfigVars, TAllowsBranching, TResult>;
89
87
  /**
90
88
  * This function creates a data source object that can be referenced
91
89
  * by a custom component. It helps ensure that the shape of the
@@ -139,6 +137,7 @@ export declare const onPremConnection: <T extends OnPremConnectionDefinition>(de
139
137
  * @returns This functions validates the shape of the `definition` object provided and returns the same connection object.
140
138
  */
141
139
  export declare const oauth2Connection: <T extends OAuth2ConnectionDefinition>(definition: T) => T;
140
+ export declare const componentManifests: <T extends Record<string, ComponentManifest>>(definition: T) => T;
142
141
  export { default as util } from "./util";
143
142
  export * from "./types";
144
143
  export { default as testing } from "./testing";
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.onPremConnection = exports.connection = exports.input = exports.dataSource = exports.trigger = exports.action = exports.component = exports.connectionConfigVar = exports.dataSourceConfigVar = exports.configVar = exports.reference = exports.configPage = exports.flow = exports.integration = void 0;
25
+ exports.testing = exports.util = exports.componentManifests = exports.oauth2Connection = exports.onPremConnection = exports.connection = exports.input = exports.dataSource = exports.trigger = exports.action = exports.component = exports.componentManifest = exports.connectionConfigVar = exports.dataSourceConfigVar = exports.configVar = exports.configPage = exports.flow = exports.integration = void 0;
26
26
  const convert_1 = require("./serverTypes/convert");
27
27
  const convertIntegration_1 = require("./serverTypes/convertIntegration");
28
28
  /**
@@ -58,14 +58,6 @@ exports.flow = flow;
58
58
  */
59
59
  const configPage = (definition) => definition;
60
60
  exports.configPage = configPage;
61
- /**
62
- * @returns Helper utility to create component references.
63
- */
64
- const reference = () => ({
65
- connection: (definition) => definition,
66
- dataSource: (definition) => definition,
67
- });
68
- exports.reference = reference;
69
61
  /**
70
62
  * For information on writing Code Native Integrations, see
71
63
  * https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
@@ -90,6 +82,12 @@ exports.dataSourceConfigVar = dataSourceConfigVar;
90
82
  */
91
83
  const connectionConfigVar = (definition) => definition;
92
84
  exports.connectionConfigVar = connectionConfigVar;
85
+ /**
86
+ * @param definition A Component Manifest type object.
87
+ * @returns This function returns a component manifest object that has the shape the Prismatic API expects.
88
+ */
89
+ const componentManifest = (definition) => definition;
90
+ exports.componentManifest = componentManifest;
93
91
  /**
94
92
  * This function creates a component object that can be
95
93
  * imported into the Prismatic API. For information on using
@@ -166,6 +164,8 @@ exports.onPremConnection = onPremConnection;
166
164
  */
167
165
  const oauth2Connection = (definition) => definition;
168
166
  exports.oauth2Connection = oauth2Connection;
167
+ const componentManifests = (definition) => definition;
168
+ exports.componentManifests = componentManifests;
169
169
  var util_1 = require("./util");
170
170
  Object.defineProperty(exports, "util", { enumerable: true, get: function () { return __importDefault(util_1).default; } });
171
171
  __exportStar(require("./types"), exports);
@@ -1,3 +1,3 @@
1
- import { IntegrationDefinition, ConfigPages, ComponentSelector } from "../types";
1
+ import { IntegrationDefinition } from "../types";
2
2
  import { Component as ServerComponent } from ".";
3
- export declare const convertIntegration: (definition: IntegrationDefinition<ConfigPages<any>, ComponentSelector<any>>) => ServerComponent;
3
+ export declare const convertIntegration: (definition: IntegrationDefinition) => ServerComponent;
@@ -1,10 +1,20 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
17
  exports.convertIntegration = void 0;
7
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
8
18
  const yaml_1 = __importDefault(require("yaml"));
9
19
  const uuid_1 = require("uuid");
10
20
  const lodash_1 = require("lodash");
@@ -34,7 +44,7 @@ const convertConfigPages = (pages) => {
34
44
  })),
35
45
  }));
36
46
  };
37
- const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, endpointType, triggerPreprocessFlowConfig, flows, configPages, }, referenceKey, configVars) => {
47
+ const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, endpointType, triggerPreprocessFlowConfig, flows, configPages, componentRegistry = {}, }, referenceKey, configVars) => {
38
48
  // Find the preprocess flow config on the flow, if one exists.
39
49
  const preprocessFlows = flows.filter((flow) => flow.preprocessFlowConfig);
40
50
  // Do some validation of preprocess flow configs.
@@ -68,30 +78,28 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
68
78
  documentation,
69
79
  version,
70
80
  labels,
71
- requiredConfigVars: Object.entries(configVars || {}).map(([key, configVar]) => convertConfigVar(key, configVar, referenceKey)),
81
+ requiredConfigVars: Object.entries(configVars || {}).map(([key, configVar]) => convertConfigVar(key, configVar, referenceKey, componentRegistry)),
72
82
  endpointType,
73
83
  preprocessFlowName: hasPreprocessFlow ? preprocessFlows[0].name : undefined,
74
84
  externalCustomerIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerIdField),
75
85
  externalCustomerUserIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerUserIdField),
76
86
  flowNameField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.flowNameField),
77
- flows: flows.map((flow) => convertFlow(flow, referenceKey)),
87
+ flows: flows.map((flow) => convertFlow(flow, componentRegistry, referenceKey)),
78
88
  configPages: convertConfigPages(configPages !== null && configPages !== void 0 ? configPages : {}),
79
89
  };
80
90
  return yaml_1.default.stringify(result);
81
91
  };
82
- const convertComponentReference = ({ key, component: componentRef, values, }) => {
83
- const component = typeof componentRef === "string"
84
- ? {
85
- key: componentRef,
86
- version: "LATEST",
87
- isPublic: true,
88
- }
89
- : {
90
- key: componentRef.key,
91
- version: "LATEST",
92
- isPublic: componentRef.isPublic,
93
- };
94
- const inputs = Object.entries(values !== null && values !== void 0 ? values : {}).reduce((result, [key, value]) => {
92
+ const convertComponentReference = (componentReference, componentRegistry) => {
93
+ var _a, _b, _c;
94
+ const ref = {
95
+ component: {
96
+ key: componentReference.component,
97
+ signature: (_b = (_a = componentRegistry[componentReference.component]) === null || _a === void 0 ? void 0 : _a.signature) !== null && _b !== void 0 ? _b : "",
98
+ isPublic: componentReference.isPublic,
99
+ },
100
+ key: componentReference.key,
101
+ };
102
+ const inputs = Object.entries((_c = componentReference.values) !== null && _c !== void 0 ? _c : {}).reduce((result, [key, value]) => {
95
103
  if ("value" in value) {
96
104
  const type = value.value instanceof Object ? "complex" : "value";
97
105
  const valueExpr = value.value instanceof Object && !Array.isArray(value.value)
@@ -109,12 +117,28 @@ const convertComponentReference = ({ key, component: componentRef, values, }) =>
109
117
  return result;
110
118
  }, {});
111
119
  return {
112
- ref: { key, component },
120
+ ref,
113
121
  inputs,
114
122
  };
115
123
  };
124
+ const convertComponentRegistry = (componentRegistry) => Object.values(componentRegistry).map(({ key, public: isPublic, signature }) => ({
125
+ key,
126
+ signature: signature !== null && signature !== void 0 ? signature : "",
127
+ isPublic,
128
+ }));
129
+ /**
130
+ * Create a reference to the private component built as part of this CNI.
131
+ *
132
+ * References to this component always use `version: "LATEST", isPublic: false`
133
+ * because they automatically publish alongside the corresponding CNI yml.
134
+ * */
135
+ const codeNativeIntegrationComponentReference = (referenceKey) => ({
136
+ key: referenceKey,
137
+ version: "LATEST",
138
+ isPublic: false,
139
+ });
116
140
  /** Converts a Flow into the structure necessary for YAML generation. */
117
- const convertFlow = (flow, referenceKey) => {
141
+ const convertFlow = (flow, componentRegistry, referenceKey) => {
118
142
  var _a;
119
143
  const result = Object.assign({}, flow);
120
144
  delete result.onTrigger;
@@ -134,15 +158,11 @@ const convertFlow = (flow, referenceKey) => {
134
158
  if (typeof flow.onTrigger === "function") {
135
159
  triggerStep.action = {
136
160
  key: flowFunctionKey(flow.name, "onTrigger"),
137
- component: {
138
- key: referenceKey,
139
- version: "LATEST",
140
- isPublic: false,
141
- },
161
+ component: codeNativeIntegrationComponentReference(referenceKey),
142
162
  };
143
163
  }
144
164
  else if ((0, types_1.isComponentReference)(flow.onTrigger)) {
145
- const { ref, inputs } = convertComponentReference(flow.onTrigger);
165
+ const { ref, inputs } = convertComponentReference(flow.onTrigger, componentRegistry);
146
166
  triggerStep.action = ref;
147
167
  triggerStep.inputs = inputs;
148
168
  }
@@ -151,7 +171,14 @@ const convertFlow = (flow, referenceKey) => {
151
171
  const key = hasSchedule ? "schedule" : "webhook";
152
172
  triggerStep.action = {
153
173
  key,
154
- component: { key: `${key}-triggers`, version: "LATEST", isPublic: true },
174
+ component: {
175
+ key: `${key}-triggers`,
176
+ /**
177
+ * TODO: Add support for specific versions of platform triggers
178
+ */
179
+ version: "LATEST",
180
+ isPublic: true,
181
+ },
155
182
  };
156
183
  }
157
184
  if ("schedule" in flow && typeof flow.schedule === "object") {
@@ -169,7 +196,7 @@ const convertFlow = (flow, referenceKey) => {
169
196
  const actionStep = {
170
197
  action: {
171
198
  key: flowFunctionKey(flow.name, "onExecution"),
172
- component: { key: referenceKey, version: "LATEST", isPublic: false },
199
+ component: codeNativeIntegrationComponentReference(referenceKey),
173
200
  },
174
201
  name: "On Execution",
175
202
  stableKey: `${flow.stableKey}-onExecution`,
@@ -177,18 +204,19 @@ const convertFlow = (flow, referenceKey) => {
177
204
  errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
178
205
  };
179
206
  result.steps = [triggerStep, actionStep];
207
+ result.supplementalComponents = convertComponentRegistry(componentRegistry);
180
208
  return result;
181
209
  };
182
210
  /** Converts a Config Var into the structure necessary for YAML generation. */
183
- const convertConfigVar = (key, configVar, referenceKey) => {
211
+ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
184
212
  const meta = (0, lodash_1.pick)(configVar, [
185
213
  "visibleToCustomerDeployer",
186
214
  "visibleToOrgDeployer",
187
215
  ]);
188
216
  if ((0, types_1.isConnectionDefinitionConfigVar)(configVar)) {
189
217
  return Object.assign(Object.assign({}, (0, lodash_1.pick)(configVar, ["stableKey", "description", "orgOnly"])), { key, dataType: "connection", connection: {
190
- component: { key: referenceKey, version: "LATEST", isPublic: false },
191
218
  key: (0, lodash_1.camelCase)(key),
219
+ component: codeNativeIntegrationComponentReference(referenceKey),
192
220
  }, inputs: Object.entries(configVar.inputs).reduce((result, [key, input]) => {
193
221
  if (input.shown === false) {
194
222
  return result;
@@ -201,7 +229,7 @@ const convertConfigVar = (key, configVar, referenceKey) => {
201
229
  }, {}), meta });
202
230
  }
203
231
  if ((0, types_1.isConnectionReferenceConfigVar)(configVar)) {
204
- const { ref, inputs } = convertComponentReference(configVar.connection);
232
+ const { ref, inputs } = convertComponentReference(configVar.connection, componentRegistry);
205
233
  return Object.assign(Object.assign({}, (0, lodash_1.pick)(configVar, ["stableKey", "description", "orgOnly"])), { key, dataType: "connection", connection: Object.assign(Object.assign({}, ref), { template: configVar.connection.template }), inputs });
206
234
  }
207
235
  const result = (0, lodash_1.assign)({ meta, key }, (0, lodash_1.pick)(configVar, [
@@ -222,11 +250,11 @@ const convertConfigVar = (key, configVar, referenceKey) => {
222
250
  result.dataType = configVar.dataSourceType;
223
251
  result.dataSource = {
224
252
  key: (0, lodash_1.camelCase)(key),
225
- component: { key: referenceKey, version: "LATEST", isPublic: false },
253
+ component: codeNativeIntegrationComponentReference(referenceKey),
226
254
  };
227
255
  }
228
256
  if ((0, types_1.isDataSourceReferenceConfigVar)(configVar)) {
229
- const { ref, inputs } = convertComponentReference(configVar.dataSource);
257
+ const { ref, inputs } = convertComponentReference(configVar.dataSource, componentRegistry);
230
258
  result.dataType = configVar.dataSourceType;
231
259
  result.dataSource = ref;
232
260
  result.inputs = inputs;
@@ -251,9 +279,28 @@ const flowFunctionKey = (flowName, functionName) => {
251
279
  .join("");
252
280
  return `${flowKey}_${functionName}`;
253
281
  };
282
+ const convertOnExecution = (onExecution, componentRegistry) => (context, params) => {
283
+ // @ts-expect-error _components isn't part of the public API
284
+ const { _components } = context, remainingContext = __rest(context, ["_components"]);
285
+ const invoke = _components
286
+ .invoke;
287
+ const componentMethods = Object.entries(componentRegistry).reduce((acc, [componentKey, { actions, public: isPublic, signature }]) => {
288
+ return Object.assign(Object.assign({}, acc), { [componentKey]: Object.keys(actions).reduce((acc, actionKey) => (Object.assign(Object.assign({}, acc), { [actionKey]: (values) => {
289
+ return invoke({
290
+ component: {
291
+ key: componentKey,
292
+ signature: signature !== null && signature !== void 0 ? signature : "",
293
+ isPublic,
294
+ },
295
+ key: actionKey,
296
+ }, context, values);
297
+ } })), {}) });
298
+ }, {});
299
+ return onExecution(Object.assign(Object.assign({}, remainingContext), { components: componentMethods }), params);
300
+ };
254
301
  /** Creates the structure necessary to import a Component as part of a
255
302
  * Code Native integration. */
256
- const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [], }, referenceKey, configVars) => {
303
+ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [], componentRegistry = {}, }, referenceKey, configVars) => {
257
304
  const convertedActions = flows.reduce((result, { name, onExecution }) => {
258
305
  const key = flowFunctionKey(name, "onExecution");
259
306
  return Object.assign(Object.assign({}, result), { [key]: {
@@ -262,7 +309,7 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
262
309
  label: `${name} - onExecution`,
263
310
  description: "The function that will be executed by the flow.",
264
311
  },
265
- perform: onExecution,
312
+ perform: convertOnExecution(onExecution, componentRegistry),
266
313
  inputs: [],
267
314
  } });
268
315
  }, {});
@@ -278,9 +325,9 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
278
325
  description: "The function that will be executed by the flow to return an HTTP response.",
279
326
  },
280
327
  perform: onTrigger,
281
- onInstanceDeploy,
328
+ onInstanceDeploy: onInstanceDeploy,
282
329
  hasOnInstanceDeploy: !!onInstanceDeploy,
283
- onInstanceDelete,
330
+ onInstanceDelete: onInstanceDeploy,
284
331
  hasOnInstanceDelete: !!onInstanceDelete,
285
332
  inputs: [],
286
333
  scheduleSupport: "valid",
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { InstanceAttributes, CustomerAttributes, DataSourceType, DataSourceResultType, UserAttributes, TriggerEventFunctionReturn, IntegrationAttributes, FlowAttributes, ConfigVarResultCollection } from "../types";
2
+ import { InstanceAttributes, CustomerAttributes, DataSourceType, DataSourceResultType, UserAttributes, TriggerEventFunctionReturn, IntegrationAttributes, FlowAttributes, ConfigVarResultCollection, ComponentManifest } from "../types";
3
3
  interface DisplayDefinition {
4
4
  label: string;
5
5
  description: string;
@@ -48,13 +48,14 @@ export interface ActionLogger {
48
48
  warn: ActionLoggerFunction;
49
49
  error: ActionLoggerFunction;
50
50
  }
51
- export declare type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection> = {
51
+ export declare type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]>> = {
52
52
  logger: ActionLogger;
53
53
  instanceState: Record<string, unknown>;
54
54
  crossFlowState: Record<string, unknown>;
55
55
  executionState: Record<string, unknown>;
56
56
  integrationState: Record<string, unknown>;
57
57
  configVars: TConfigVars;
58
+ components: TComponentActions;
58
59
  stepId: string;
59
60
  executionId: string;
60
61
  webhookUrls: Record<string, string>;
@@ -1,5 +1,5 @@
1
1
  export declare const DefinitionVersion = 7;
2
- export interface ComponentReference {
2
+ export declare type ComponentReference = {
3
3
  component: {
4
4
  key: string;
5
5
  version: number | "LATEST";
@@ -7,7 +7,15 @@ export interface ComponentReference {
7
7
  };
8
8
  key: string;
9
9
  template?: string;
10
- }
10
+ } | {
11
+ component: {
12
+ key: string;
13
+ signature: string;
14
+ isPublic: boolean;
15
+ };
16
+ key: string;
17
+ template?: string;
18
+ };
11
19
  export declare type Input = {
12
20
  name?: string | Input;
13
21
  type: "value" | "reference" | "configVar" | "template";
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, ConfigVarResultCollection, ConfigPages, ComponentSelector } from "./types";
8
+ import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow, ConfigVarResultCollection } 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
  export declare const defaultConnectionValueEnvironmentVariable = "PRISMATIC_CONNECTION_VALUE";
11
11
  export declare const connectionValue: (envVarKey?: string) => ConnectionValue;
@@ -27,7 +27,7 @@ interface InvokeReturn<ReturnData> {
27
27
  * to avoid extra casting within test methods. Returns an InvokeResult containing both the
28
28
  * action result and a mock logger for asserting logging.
29
29
  */
30
- 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>> | undefined) => Promise<InvokeReturn<TReturn>>;
30
+ 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, Record<string, Record<string, import("./types").ComponentManifestAction>>>> | undefined) => Promise<InvokeReturn<TReturn>>;
31
31
  export declare const defaultTriggerPayload: () => TriggerPayload;
32
32
  /**
33
33
  * Invokes specified TriggerDefinition perform function using supplied params
@@ -35,7 +35,7 @@ export declare const defaultTriggerPayload: () => TriggerPayload;
35
35
  * to avoid extra casting within test methods. Returns an InvokeResult containing both the
36
36
  * trigger result and a mock logger for asserting logging.
37
37
  */
38
- 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>> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs> | undefined) => Promise<InvokeReturn<TResult>>;
38
+ 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, Record<string, Record<string, import("./types").ComponentManifestAction>>>> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs> | undefined) => Promise<InvokeReturn<TResult>>;
39
39
  /**
40
40
  * Invokes specified DataSourceDefinition perform function using supplied params.
41
41
  * Accepts a generic type matching DataSourceResult as a convenience to avoid extra
@@ -65,9 +65,9 @@ declare type ToTestValues<TConfigVars extends ConfigVarResultCollection> = {
65
65
  * Invokes specified Flow of a Code Native Integration using supplied params.
66
66
  * Runs the Trigger and then the Action function and returns the result of the Action.
67
67
  */
68
- export declare const invokeFlow: <TConfigPages extends ConfigPages<any>, TConfigVars extends ConfigVarResultCollection = import("./types/utils").Prettify<{ [Key in keyof import("./types").GetElements<TConfigPages> as Key extends string ? Key : never]: import("./types").ElementToRuntimeType<import("./types").GetElements<TConfigPages>[Key]>; }>, TConfigVarValues extends TestConfigVarValues = ToTestValues<TConfigVars>>(flow: Flow<TConfigPages, ComponentSelector<any>, import("./types").TriggerPayload>, { configVars, context, payload, }?: {
68
+ export declare const invokeFlow: <TConfigVars extends import("./types/utils").Prettify<{} & {}> = import("./types/utils").Prettify<{} & {}>, TConfigVarValues extends TestConfigVarValues = ToTestValues<TConfigVars>>(flow: Flow, { configVars, context, payload, }?: {
69
69
  configVars?: TConfigVarValues | undefined;
70
- context?: Partial<ActionContext<TConfigVars>> | undefined;
70
+ context?: Partial<ActionContext<TConfigVars, Record<string, Record<string, import("./types").ComponentManifestAction>>>> | undefined;
71
71
  payload?: Partial<TriggerPayload> | undefined;
72
72
  }) => Promise<InvokeReturn<InvokeActionPerformReturn<false, unknown>>>;
73
73
  export declare class ComponentTestHarness<TComponent extends Component> {
@@ -84,8 +84,8 @@ export declare class ComponentTestHarness<TComponent extends Component> {
84
84
  export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
85
85
  declare const _default: {
86
86
  loggerMock: () => ActionLogger;
87
- 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>> | undefined) => Promise<InvokeReturn<TReturn>>;
88
- 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>> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs_1> | undefined) => Promise<InvokeReturn<TResult>>;
87
+ 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, Record<string, Record<string, import("./types").ComponentManifestAction>>>> | undefined) => Promise<InvokeReturn<TReturn>>;
88
+ 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, Record<string, Record<string, import("./types").ComponentManifestAction>>>> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs_1> | undefined) => Promise<InvokeReturn<TResult>>;
89
89
  createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
90
90
  invokeDataSource: <TInputs_2 extends Inputs, TConfigVars_2 extends ConfigVarResultCollection, TDataSourceType extends keyof {
91
91
  string: string;
package/dist/testing.js CHANGED
@@ -49,7 +49,7 @@ const loggerMock = () => ({
49
49
  });
50
50
  exports.loggerMock = loggerMock;
51
51
  const createActionContext = (context) => {
52
- return Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, integrationState: {}, configVars: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
52
+ return Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, integrationState: {}, configVars: {}, components: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
53
53
  "Flow 1": "https://example.com",
54
54
  }, webhookApiKeys: {
55
55
  "Flow 1": ["example-123", "example-456"],
@@ -1,4 +1,5 @@
1
1
  import { ActionDisplayDefinition, ActionPerformFunction, ActionPerformReturn, ConfigVarResultCollection, Inputs } from ".";
2
+ import { ComponentManifestAction } from "./ComponentManifest";
2
3
  /**
3
4
  * ActionDefinition is the type of the object that is passed in to `action` function to
4
5
  * define a component action.
@@ -7,7 +8,7 @@ export interface ActionDefinition<TInputs extends Inputs = Inputs, TConfigVars e
7
8
  /** Defines how the Action is displayed in the Prismatic interface. */
8
9
  display: ActionDisplayDefinition;
9
10
  /** Function to perform when this Action is invoked. */
10
- perform: ActionPerformFunction<TInputs, TConfigVars, TAllowsBranching, TReturn>;
11
+ perform: ActionPerformFunction<TInputs, TConfigVars, Record<string, Record<string, ComponentManifestAction>>, TAllowsBranching, TReturn>;
11
12
  /** InputFields to present in the Prismatic interface for configuration of this Action. */
12
13
  inputs: TInputs;
13
14
  /** Optional attribute that specifies whether an Action will terminate execution.*/
@@ -1,8 +1,8 @@
1
- import { Inputs, ConfigVarResultCollection, ActionPerformReturn, ActionInputParameters, ActionLogger, InstanceAttributes, CustomerAttributes, UserAttributes, IntegrationAttributes, FlowAttributes } from ".";
1
+ import { Inputs, ConfigVarResultCollection, ActionPerformReturn, ActionInputParameters, ActionLogger, InstanceAttributes, CustomerAttributes, UserAttributes, IntegrationAttributes, FlowAttributes, ComponentManifest } from ".";
2
2
  /** Definition of the function to perform when an Action is invoked. */
3
- export declare type ActionPerformFunction<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean | undefined, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>> = (context: ActionContext<TConfigVars>, params: ActionInputParameters<TInputs>) => Promise<TReturn>;
3
+ export declare type ActionPerformFunction<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]>, TAllowsBranching extends boolean | undefined, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>> = (context: ActionContext<TConfigVars, TComponentActions>, params: ActionInputParameters<TInputs>) => Promise<TReturn>;
4
4
  /** Context provided to perform method containing helpers and contextual data */
5
- export declare type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection> = {
5
+ export declare type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]>> = {
6
6
  /** Logger for permanent logging; console calls are also captured */
7
7
  logger: ActionLogger;
8
8
  /** A a flow-specific key/value store that may be used to store small amounts of data that is persisted between Instance executions */
@@ -15,6 +15,8 @@ export declare type ActionContext<TConfigVars extends ConfigVarResultCollection
15
15
  integrationState: Record<string, unknown>;
16
16
  /** Key/value collection of config variables of the integration. */
17
17
  configVars: TConfigVars;
18
+ /** Available component actions registered in the `componentRegistry`. */
19
+ components: TComponentActions;
18
20
  /** A unique id that corresponds to the step on the Integration */
19
21
  stepId: string;
20
22
  /** A unique id that corresponds to the specific execution of the Integration */
@@ -0,0 +1,13 @@
1
+ export interface ComponentManifest {
2
+ key: string;
3
+ public: boolean;
4
+ signature: string | null;
5
+ actions: Record<string, ComponentManifestAction>;
6
+ triggers: Record<string, ComponentManifestTrigger>;
7
+ dataSources: Record<string, ComponentManifestDataSource>;
8
+ connections: Record<string, ComponentManifestConnection>;
9
+ }
10
+ export declare type ComponentManifestAction = (values: any) => Promise<unknown>;
11
+ export declare type ComponentManifestTrigger = (values: any) => Promise<unknown>;
12
+ export declare type ComponentManifestDataSource = (values: any) => Promise<unknown>;
13
+ export declare type ComponentManifestConnection = (values: any) => Promise<unknown>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });