@prismatic-io/spectral 9.1.3 → 9.2.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.
- package/dist/clients/http/index.js +2 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +11 -1
- package/dist/serverTypes/convertIntegration.d.ts +3 -1
- package/dist/serverTypes/convertIntegration.js +140 -41
- package/dist/serverTypes/integration.d.ts +8 -1
- package/dist/types/ConfigVars.d.ts +8 -3
- package/dist/types/IntegrationDefinition.d.ts +3 -1
- package/dist/types/ScopedConfigVars.d.ts +29 -0
- package/dist/types/ScopedConfigVars.js +9 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/package.json +2 -2
|
@@ -104,11 +104,12 @@ const createClient = ({ baseUrl, responseType, headers, timeout, params, debug =
|
|
|
104
104
|
});
|
|
105
105
|
if (debug) {
|
|
106
106
|
client.interceptors.request.use((request) => {
|
|
107
|
-
const { baseURL, headers, method, timeout, url, data } = request;
|
|
107
|
+
const { baseURL, headers, method, timeout, url, data, params } = request;
|
|
108
108
|
const dataSize = (0, object_sizeof_1.default)(data);
|
|
109
109
|
console.log(util_1.default.types.toJSON({
|
|
110
110
|
type: "request",
|
|
111
111
|
baseURL,
|
|
112
|
+
params,
|
|
112
113
|
url,
|
|
113
114
|
headers,
|
|
114
115
|
method,
|
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, DataSourceType, IntegrationDefinition, Flow, ConfigPage, StandardConfigVar, ConnectionConfigVar, ConfigVarResultCollection, TriggerPayload, DataSourceConfigVar, OnPremConnectionDefinition, ComponentManifest } from "./types";
|
|
6
|
+
import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, DataSourceType, IntegrationDefinition, Flow, ConfigPage, StandardConfigVar, ConnectionConfigVar, ConfigVarResultCollection, TriggerPayload, DataSourceConfigVar, OnPremConnectionDefinition, ComponentManifest, OrganizationActivatedConnectionConfigVar } from "./types";
|
|
7
7
|
import { convertComponent } from "./serverTypes/convertComponent";
|
|
8
8
|
import { convertIntegration } from "./serverTypes/convertIntegration";
|
|
9
9
|
/**
|
|
@@ -50,6 +50,15 @@ export declare const dataSourceConfigVar: <TDataSourceConfigVar extends DataSour
|
|
|
50
50
|
* @returns This function returns a connection config var object that has the shape the Prismatic API expects.
|
|
51
51
|
*/
|
|
52
52
|
export declare const connectionConfigVar: <T extends ConnectionConfigVar = ConnectionConfigVar>(definition: T) => T;
|
|
53
|
+
/**
|
|
54
|
+
* For information on writing Code Native Integrations, see
|
|
55
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
|
|
56
|
+
* @param definition A Customer Connection Config Var type object.
|
|
57
|
+
* @returns This function returns a connection config var object that has the shape the Prismatic API expects.
|
|
58
|
+
*/
|
|
59
|
+
export declare const organizationActivatedConnection: <T extends {
|
|
60
|
+
stableKey: string;
|
|
61
|
+
}>(definition: T) => OrganizationActivatedConnectionConfigVar;
|
|
53
62
|
/**
|
|
54
63
|
* @param definition A Component Manifest type object.
|
|
55
64
|
* @returns This function returns a component manifest object that has the shape the Prismatic API expects.
|
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.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;
|
|
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.organizationActivatedConnection = exports.connectionConfigVar = exports.dataSourceConfigVar = exports.configVar = exports.configPage = exports.flow = exports.integration = void 0;
|
|
26
26
|
const convertComponent_1 = require("./serverTypes/convertComponent");
|
|
27
27
|
const convertIntegration_1 = require("./serverTypes/convertIntegration");
|
|
28
28
|
/**
|
|
@@ -82,6 +82,16 @@ exports.dataSourceConfigVar = dataSourceConfigVar;
|
|
|
82
82
|
*/
|
|
83
83
|
const connectionConfigVar = (definition) => definition;
|
|
84
84
|
exports.connectionConfigVar = connectionConfigVar;
|
|
85
|
+
/**
|
|
86
|
+
* For information on writing Code Native Integrations, see
|
|
87
|
+
* https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
|
|
88
|
+
* @param definition A Customer Connection Config Var type object.
|
|
89
|
+
* @returns This function returns a connection config var object that has the shape the Prismatic API expects.
|
|
90
|
+
*/
|
|
91
|
+
const organizationActivatedConnection = (definition) => {
|
|
92
|
+
return Object.assign(Object.assign({}, definition), { dataType: "connection" });
|
|
93
|
+
};
|
|
94
|
+
exports.organizationActivatedConnection = organizationActivatedConnection;
|
|
85
95
|
/**
|
|
86
96
|
* @param definition A Component Manifest type object.
|
|
87
97
|
* @returns This function returns a component manifest object that has the shape the Prismatic API expects.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { IntegrationDefinition, ConfigVar, ComponentRegistry } from "../types";
|
|
1
|
+
import { IntegrationDefinition, ConfigVar, Flow, ComponentRegistry } from "../types";
|
|
2
2
|
import { Component as ServerComponent } from ".";
|
|
3
3
|
import { RequiredConfigVariable as ServerRequiredConfigVariable } from "./integration";
|
|
4
4
|
export declare const convertIntegration: (definition: IntegrationDefinition) => ServerComponent;
|
|
5
|
+
/** Converts a Flow into the structure necessary for YAML generation. */
|
|
6
|
+
export declare const convertFlow: (flow: Flow, componentRegistry: ComponentRegistry, referenceKey: string) => Record<string, unknown>;
|
|
5
7
|
/** Converts a Config Var into the structure necessary for YAML generation. */
|
|
6
8
|
export declare const convertConfigVar: (key: string, configVar: ConfigVar, referenceKey: string, componentRegistry: ComponentRegistry) => ServerRequiredConfigVariable;
|
|
@@ -8,43 +8,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
13
|
};
|
|
25
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.convertConfigVar = exports.convertIntegration = void 0;
|
|
15
|
+
exports.convertConfigVar = exports.convertFlow = exports.convertIntegration = void 0;
|
|
27
16
|
const yaml_1 = __importDefault(require("yaml"));
|
|
28
17
|
const uuid_1 = require("uuid");
|
|
29
18
|
const lodash_1 = require("lodash");
|
|
30
19
|
const types_1 = require("../types");
|
|
31
20
|
const convertComponent_1 = require("./convertComponent");
|
|
32
21
|
const integration_1 = require("./integration");
|
|
22
|
+
const lodash_2 = require("lodash");
|
|
33
23
|
const convertIntegration = (definition) => {
|
|
34
|
-
var _a, _b;
|
|
24
|
+
var _a, _b, _c;
|
|
35
25
|
// Generate a unique reference key that will be used to reference the
|
|
36
26
|
// actions, triggers, data sources, and connections that are created
|
|
37
27
|
// inline as part of the integration definition.
|
|
38
28
|
const referenceKey = (0, uuid_1.v4)();
|
|
29
|
+
const scopedConfigVars = (_a = definition.scopedConfigVars) !== null && _a !== void 0 ? _a : {};
|
|
39
30
|
const configVars = Object.values({
|
|
40
|
-
configPages: (
|
|
41
|
-
userLevelConfigPages: (
|
|
31
|
+
configPages: (_b = definition.configPages) !== null && _b !== void 0 ? _b : {},
|
|
32
|
+
userLevelConfigPages: (_c = definition.userLevelConfigPages) !== null && _c !== void 0 ? _c : {},
|
|
42
33
|
}).reduce((acc, configPages) => (Object.assign(Object.assign({}, acc), Object.values(configPages).reduce((acc, configPage) => Object.entries(configPage.elements).reduce((acc, [key, element]) => {
|
|
43
34
|
// "string" elements are HTML elements and should be ignored.
|
|
44
35
|
if (typeof element === "string") {
|
|
45
36
|
return acc;
|
|
46
37
|
}
|
|
47
|
-
if (key in acc) {
|
|
38
|
+
if (key in acc || key in scopedConfigVars) {
|
|
48
39
|
throw new Error(`Duplicate config var key: "${key}"`);
|
|
49
40
|
}
|
|
50
41
|
return Object.assign(Object.assign({}, acc), { [key]: element });
|
|
@@ -69,7 +60,7 @@ const convertConfigPages = (pages, userLevelConfigured) => {
|
|
|
69
60
|
value: key,
|
|
70
61
|
}) })));
|
|
71
62
|
};
|
|
72
|
-
const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, endpointType, triggerPreprocessFlowConfig, flows, configPages, userLevelConfigPages, componentRegistry = {}, }, referenceKey, configVars) => {
|
|
63
|
+
const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, endpointType, triggerPreprocessFlowConfig, flows, configPages, userLevelConfigPages, scopedConfigVars, componentRegistry = {}, }, referenceKey, configVars) => {
|
|
73
64
|
// Find the preprocess flow config on the flow, if one exists.
|
|
74
65
|
const preprocessFlows = flows.filter((flow) => flow.preprocessFlowConfig);
|
|
75
66
|
// Do some validation of preprocess flow configs.
|
|
@@ -87,6 +78,13 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
|
|
|
87
78
|
if (nonPreprocessFlowTypes.includes(endpointType || "flow_specific") && !preprocessFlowConfig) {
|
|
88
79
|
throw new Error("Integration with specified EndpointType must define either a Trigger Preprocess Flow Config or a Preprocess Flow.");
|
|
89
80
|
}
|
|
81
|
+
const configVarMap = Object.entries(scopedConfigVars !== null && scopedConfigVars !== void 0 ? scopedConfigVars : {}).reduce((acc, [key, value]) => {
|
|
82
|
+
if (typeof value === "string") {
|
|
83
|
+
return acc;
|
|
84
|
+
}
|
|
85
|
+
return Object.assign(Object.assign({}, acc), { [key]: value });
|
|
86
|
+
}, Object.assign({}, (configVars !== null && configVars !== void 0 ? configVars : {})));
|
|
87
|
+
const requiredConfigVars = Object.entries(configVarMap).map(([key, configVar]) => (0, exports.convertConfigVar)(key, configVar, referenceKey, componentRegistry));
|
|
90
88
|
// Transform the IntegrationDefinition into the structure that is appropriate
|
|
91
89
|
// for generating YAML, which will then be used by the Prismatic API to import
|
|
92
90
|
// the integration as a Code Native Integration.
|
|
@@ -99,13 +97,13 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
|
|
|
99
97
|
documentation,
|
|
100
98
|
version,
|
|
101
99
|
labels,
|
|
102
|
-
requiredConfigVars
|
|
100
|
+
requiredConfigVars,
|
|
103
101
|
endpointType,
|
|
104
102
|
preprocessFlowName: hasPreprocessFlow ? preprocessFlows[0].name : undefined,
|
|
105
103
|
externalCustomerIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerIdField),
|
|
106
104
|
externalCustomerUserIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerUserIdField),
|
|
107
105
|
flowNameField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.flowNameField),
|
|
108
|
-
flows: flows.map((flow) => convertFlow(flow, componentRegistry, referenceKey)),
|
|
106
|
+
flows: flows.map((flow) => (0, exports.convertFlow)(flow, componentRegistry, referenceKey)),
|
|
109
107
|
configPages: [
|
|
110
108
|
...convertConfigPages(configPages, false),
|
|
111
109
|
...convertConfigPages(userLevelConfigPages, true),
|
|
@@ -209,11 +207,21 @@ const convertComponentReference = (componentReference, componentRegistry, refere
|
|
|
209
207
|
inputs,
|
|
210
208
|
};
|
|
211
209
|
};
|
|
212
|
-
const convertComponentRegistry = (componentRegistry
|
|
213
|
-
key,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
210
|
+
const convertComponentRegistry = (componentRegistry, publicSupplementalComponent) => {
|
|
211
|
+
const convertedRegistry = Object.values(componentRegistry).map(({ key, public: isPublic, signature }) => ({
|
|
212
|
+
key,
|
|
213
|
+
signature: signature !== null && signature !== void 0 ? signature : "",
|
|
214
|
+
isPublic,
|
|
215
|
+
}));
|
|
216
|
+
if (publicSupplementalComponent) {
|
|
217
|
+
convertedRegistry.push({
|
|
218
|
+
key: `${publicSupplementalComponent}-triggers`,
|
|
219
|
+
isPublic: true,
|
|
220
|
+
version: "LATEST",
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return convertedRegistry;
|
|
224
|
+
};
|
|
217
225
|
/**
|
|
218
226
|
* Create a reference to the private component built as part of this CNI.
|
|
219
227
|
*
|
|
@@ -225,6 +233,12 @@ const codeNativeIntegrationComponentReference = (referenceKey) => ({
|
|
|
225
233
|
version: "LATEST",
|
|
226
234
|
isPublic: false,
|
|
227
235
|
});
|
|
236
|
+
/* A flow's trigger gets wrapped in a custom component if there's a defined
|
|
237
|
+
* onTrigger function, or if any custom onInstance behavior is defined.
|
|
238
|
+
* */
|
|
239
|
+
const flowUsesWrapperTrigger = (flow) => {
|
|
240
|
+
return typeof flow.onTrigger === "function" || flow.onInstanceDelete || flow.onInstanceDeploy;
|
|
241
|
+
};
|
|
228
242
|
/** Converts a Flow into the structure necessary for YAML generation. */
|
|
229
243
|
const convertFlow = (flow, componentRegistry, referenceKey) => {
|
|
230
244
|
var _a;
|
|
@@ -236,6 +250,7 @@ const convertFlow = (flow, componentRegistry, referenceKey) => {
|
|
|
236
250
|
result.onExecution = undefined;
|
|
237
251
|
result.preprocessFlowConfig = undefined;
|
|
238
252
|
result.errorConfig = undefined;
|
|
253
|
+
let publicSupplementalComponent;
|
|
239
254
|
const triggerStep = {
|
|
240
255
|
name: "On Trigger",
|
|
241
256
|
stableKey: `${flow.stableKey}-onTrigger`,
|
|
@@ -243,17 +258,21 @@ const convertFlow = (flow, componentRegistry, referenceKey) => {
|
|
|
243
258
|
isTrigger: true,
|
|
244
259
|
errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
|
|
245
260
|
};
|
|
246
|
-
|
|
261
|
+
const useWrapperTrigger = flowUsesWrapperTrigger(flow);
|
|
262
|
+
if ((0, types_1.isComponentReference)(flow.onTrigger) && !useWrapperTrigger) {
|
|
263
|
+
const { ref, inputs } = convertComponentReference(flow.onTrigger, componentRegistry, "triggers");
|
|
264
|
+
triggerStep.action = ref;
|
|
265
|
+
triggerStep.inputs = inputs;
|
|
266
|
+
}
|
|
267
|
+
else if (useWrapperTrigger) {
|
|
268
|
+
if (!flow.onTrigger) {
|
|
269
|
+
publicSupplementalComponent = flow.schedule ? "schedule" : "webhook";
|
|
270
|
+
}
|
|
247
271
|
triggerStep.action = {
|
|
248
272
|
key: flowFunctionKey(flow.name, "onTrigger"),
|
|
249
273
|
component: codeNativeIntegrationComponentReference(referenceKey),
|
|
250
274
|
};
|
|
251
275
|
}
|
|
252
|
-
else if ((0, types_1.isComponentReference)(flow.onTrigger)) {
|
|
253
|
-
const { ref, inputs } = convertComponentReference(flow.onTrigger, componentRegistry, "triggers");
|
|
254
|
-
triggerStep.action = ref;
|
|
255
|
-
triggerStep.inputs = inputs;
|
|
256
|
-
}
|
|
257
276
|
else {
|
|
258
277
|
const hasSchedule = "schedule" in flow && typeof flow.schedule === "object";
|
|
259
278
|
const key = hasSchedule ? "schedule" : "webhook";
|
|
@@ -292,9 +311,10 @@ const convertFlow = (flow, componentRegistry, referenceKey) => {
|
|
|
292
311
|
errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
|
|
293
312
|
};
|
|
294
313
|
result.steps = [triggerStep, actionStep];
|
|
295
|
-
result.supplementalComponents = convertComponentRegistry(componentRegistry);
|
|
314
|
+
result.supplementalComponents = convertComponentRegistry(componentRegistry, publicSupplementalComponent);
|
|
296
315
|
return result;
|
|
297
316
|
};
|
|
317
|
+
exports.convertFlow = convertFlow;
|
|
298
318
|
/** Converts an input value to the expected server type by its collection type */
|
|
299
319
|
const convertInputValue = (value, collectionType) => {
|
|
300
320
|
if (collectionType !== "keyvaluelist") {
|
|
@@ -311,6 +331,16 @@ const convertInputValue = (value, collectionType) => {
|
|
|
311
331
|
/** Converts a Config Var into the structure necessary for YAML generation. */
|
|
312
332
|
const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
|
|
313
333
|
var _a;
|
|
334
|
+
if ((0, types_1.isOrganizationActivatedConnectionConfigVar)(configVar)) {
|
|
335
|
+
const { stableKey } = (0, lodash_1.pick)(configVar, ["stableKey"]);
|
|
336
|
+
return {
|
|
337
|
+
key,
|
|
338
|
+
stableKey,
|
|
339
|
+
dataType: "connection",
|
|
340
|
+
orgOnly: false,
|
|
341
|
+
useScopedConfigVar: stableKey,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
314
344
|
const { orgOnly, meta } = convertConfigVarPermissionAndVisibility((0, lodash_1.pick)(configVar, ["permissionAndVisibilityType", "visibleToOrgDeployer"]));
|
|
315
345
|
if ((0, types_1.isConnectionDefinitionConfigVar)(configVar)) {
|
|
316
346
|
const { stableKey, description } = (0, lodash_1.pick)(configVar, ["stableKey", "description"]);
|
|
@@ -424,10 +454,61 @@ const flowFunctionKey = (flowName, functionName) => {
|
|
|
424
454
|
.join("");
|
|
425
455
|
return `${flowKey}_${functionName}`;
|
|
426
456
|
};
|
|
457
|
+
/* Generates component argument for invokeTrigger calls */
|
|
458
|
+
const invokeTriggerComponentInput = (componentRef, onTrigger, eventName) => {
|
|
459
|
+
const { component } = componentRef;
|
|
460
|
+
const inputComponent = "signature" in componentRef.component
|
|
461
|
+
? {
|
|
462
|
+
key: component.key,
|
|
463
|
+
signature: "signature" in component &&
|
|
464
|
+
component.signature !== null &&
|
|
465
|
+
component.signature !== void 0
|
|
466
|
+
? component.signature
|
|
467
|
+
: "",
|
|
468
|
+
isPublic: component.isPublic,
|
|
469
|
+
}
|
|
470
|
+
: component;
|
|
471
|
+
return {
|
|
472
|
+
component: inputComponent,
|
|
473
|
+
key: onTrigger ? onTrigger.key : componentRef.key,
|
|
474
|
+
triggerEventFunctionName: eventName,
|
|
475
|
+
};
|
|
476
|
+
};
|
|
477
|
+
/* Generates a wrapper function that calls an existing component trigger's perform */
|
|
478
|
+
const generateTriggerPerformFn = (componentRef, onTrigger) => {
|
|
479
|
+
const performFn = componentRef && typeof onTrigger !== "function"
|
|
480
|
+
? (context, payload, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
481
|
+
// @ts-expect-error: _components isn't part of the public API
|
|
482
|
+
const { _components } = context;
|
|
483
|
+
const invokeTrigger = _components.invokeTrigger;
|
|
484
|
+
return yield invokeTrigger(invokeTriggerComponentInput(componentRef, onTrigger, "perform"), context, payload, params);
|
|
485
|
+
})
|
|
486
|
+
: onTrigger;
|
|
487
|
+
return performFn;
|
|
488
|
+
};
|
|
489
|
+
/** Generates a wrapper function that calls an existing component's onInstanceDeploy
|
|
490
|
+
* or onInstanceDelete, then calls the flow-defined version if it exists.
|
|
491
|
+
* Returns the deep-merged results of the two, prioritizing the custom response
|
|
492
|
+
* if there's a conflict. */
|
|
493
|
+
const generateOnInstanceWrapperFn = (componentRef, onTrigger, eventName, customFn) => {
|
|
494
|
+
const onInstanceFn = componentRef && typeof onTrigger !== "function"
|
|
495
|
+
? (context, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
496
|
+
// @ts-expect-error: _components isn't part of the public API
|
|
497
|
+
const { _components } = context;
|
|
498
|
+
const invokeTrigger = _components.invokeTrigger;
|
|
499
|
+
const invokeResponse = (yield invokeTrigger(invokeTriggerComponentInput(componentRef, onTrigger, eventName), context, null, params)) || {};
|
|
500
|
+
let customResponse = {};
|
|
501
|
+
if (customFn) {
|
|
502
|
+
customResponse = (yield customFn(context, params)) || {};
|
|
503
|
+
}
|
|
504
|
+
return (0, lodash_2.merge)(invokeResponse, customResponse);
|
|
505
|
+
})
|
|
506
|
+
: customFn;
|
|
507
|
+
return onInstanceFn;
|
|
508
|
+
};
|
|
427
509
|
const convertOnExecution = (onExecution, componentRegistry) => (context, params) => {
|
|
428
|
-
const {
|
|
429
510
|
// @ts-expect-error _components isn't part of the public API
|
|
430
|
-
_components } = context
|
|
511
|
+
const { _components } = context;
|
|
431
512
|
const invoke = _components.invoke;
|
|
432
513
|
// Construct the component methods from the component registry
|
|
433
514
|
const componentMethods = Object.entries(componentRegistry).reduce((accumulator, [registryComponentKey, { key: componentKey, actions, public: isPublic, signature }]) => {
|
|
@@ -458,7 +539,7 @@ const convertOnExecution = (onExecution, componentRegistry) => (context, params)
|
|
|
458
539
|
}, {});
|
|
459
540
|
return Object.assign(Object.assign({}, accumulator), { [registryComponentKey]: componentActions });
|
|
460
541
|
}, {});
|
|
461
|
-
return onExecution(Object.assign(Object.assign({},
|
|
542
|
+
return onExecution(Object.assign(Object.assign({}, context), { components: componentMethods }), params);
|
|
462
543
|
};
|
|
463
544
|
/** Creates the structure necessary to import a Component as part of a
|
|
464
545
|
* Code Native integration. */
|
|
@@ -475,22 +556,40 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
|
|
|
475
556
|
inputs: [],
|
|
476
557
|
} });
|
|
477
558
|
}, {});
|
|
478
|
-
const convertedTriggers = flows.reduce((result, { name, onTrigger, onInstanceDeploy, onInstanceDelete }) => {
|
|
479
|
-
if (
|
|
559
|
+
const convertedTriggers = flows.reduce((result, { name, onTrigger, onInstanceDeploy, onInstanceDelete, schedule }) => {
|
|
560
|
+
if (!flowUsesWrapperTrigger({ onTrigger, onInstanceDelete, onInstanceDeploy })) {
|
|
561
|
+
// In this scenario, the user has defined an existing component trigger
|
|
562
|
+
// without any custom behavior, so we don't need to wrap anything.
|
|
480
563
|
return result;
|
|
481
564
|
}
|
|
482
565
|
const key = flowFunctionKey(name, "onTrigger");
|
|
566
|
+
const defaultComponentKey = schedule && typeof schedule === "object" ? "schedule" : "webhook";
|
|
567
|
+
const defaultComponentRef = {
|
|
568
|
+
component: {
|
|
569
|
+
key: `${defaultComponentKey}-triggers`,
|
|
570
|
+
version: "LATEST",
|
|
571
|
+
isPublic: true,
|
|
572
|
+
},
|
|
573
|
+
key: defaultComponentKey,
|
|
574
|
+
};
|
|
575
|
+
// The component ref here is undefined if onTrigger is a function.
|
|
576
|
+
const { ref } = (0, types_1.isComponentReference)(onTrigger)
|
|
577
|
+
? convertComponentReference(onTrigger, componentRegistry, "triggers")
|
|
578
|
+
: { ref: onTrigger ? undefined : defaultComponentRef };
|
|
579
|
+
const performFn = generateTriggerPerformFn(ref, onTrigger);
|
|
580
|
+
const deleteFn = generateOnInstanceWrapperFn(ref, onTrigger, "onInstanceDelete", onInstanceDelete);
|
|
581
|
+
const deployFn = generateOnInstanceWrapperFn(ref, onTrigger, "onInstanceDeploy", onInstanceDeploy);
|
|
483
582
|
return Object.assign(Object.assign({}, result), { [key]: {
|
|
484
583
|
key,
|
|
485
584
|
display: {
|
|
486
585
|
label: `${name} - onTrigger`,
|
|
487
586
|
description: "The function that will be executed by the flow to return an HTTP response.",
|
|
488
587
|
},
|
|
489
|
-
perform:
|
|
490
|
-
onInstanceDeploy:
|
|
491
|
-
hasOnInstanceDeploy: !!
|
|
492
|
-
onInstanceDelete:
|
|
493
|
-
hasOnInstanceDelete: !!
|
|
588
|
+
perform: performFn,
|
|
589
|
+
onInstanceDeploy: deployFn,
|
|
590
|
+
hasOnInstanceDeploy: !!deployFn,
|
|
591
|
+
onInstanceDelete: deleteFn,
|
|
592
|
+
hasOnInstanceDelete: !!deleteFn,
|
|
494
593
|
inputs: [],
|
|
495
594
|
scheduleSupport: "valid",
|
|
496
595
|
synchronousResponseSupport: "valid",
|
|
@@ -54,7 +54,14 @@ export interface DefaultRequiredConfigVariable {
|
|
|
54
54
|
inputs?: Record<string, Input>;
|
|
55
55
|
meta?: Record<string, unknown>;
|
|
56
56
|
}
|
|
57
|
-
export
|
|
57
|
+
export interface OrganizationActivatedConnectionRequiredConfigVariable {
|
|
58
|
+
key: string;
|
|
59
|
+
dataType: "connection";
|
|
60
|
+
orgOnly: false;
|
|
61
|
+
inputs?: never;
|
|
62
|
+
useScopedConfigVar: string;
|
|
63
|
+
}
|
|
64
|
+
export type RequiredConfigVariable = DefaultRequiredConfigVariable | ConnectionRequiredConfigVariable | OrganizationActivatedConnectionRequiredConfigVariable;
|
|
58
65
|
export interface ConfigPage {
|
|
59
66
|
name: string;
|
|
60
67
|
tagline?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValidationMode } from "@jsonforms/core";
|
|
2
|
-
import { type DataSourceDefinition, type ConnectionDefinition, type Inputs, type DataSourceType, type Connection, type JSONForm, type ObjectFieldMap, type ObjectSelection, type ConfigVarResultCollection, type Schedule, type CollectionDataSourceType, type DataSourceReference, type ConfigPage, type ConfigPages, type ConfigPageElement, type ComponentRegistryDataSource, type ComponentRegistryConnection, type UserLevelConfigPages } from ".";
|
|
2
|
+
import { type DataSourceDefinition, type ConnectionDefinition, type Inputs, type DataSourceType, type Connection, type JSONForm, type ObjectFieldMap, type ObjectSelection, type ConfigVarResultCollection, type Schedule, type CollectionDataSourceType, type DataSourceReference, type ConfigPage, type ConfigPages, type ConfigPageElement, type ComponentRegistryDataSource, type ComponentRegistryConnection, type UserLevelConfigPages, type OrganizationActivatedConnectionConfigVar, type ScopedConfigVarMap } from ".";
|
|
3
3
|
import type { Prettify, UnionToIntersection } from "./utils";
|
|
4
4
|
/** Supported data types for Config Vars. */
|
|
5
5
|
export type ConfigVarDataType = "string" | "date" | "timestamp" | "picklist" | "code" | "boolean" | "number" | "schedule" | "objectSelection" | "objectFieldMap" | "jsonForm";
|
|
@@ -161,7 +161,7 @@ type ConnectionReferenceConfigVar = ComponentRegistryConnection extends infer TC
|
|
|
161
161
|
} : never : never;
|
|
162
162
|
/** Defines attributes of a Config Var that represents a Connection. */
|
|
163
163
|
export type ConnectionConfigVar = ConnectionDefinitionConfigVar | ConnectionReferenceConfigVar;
|
|
164
|
-
export type ConfigVar = StandardConfigVar | DataSourceConfigVar | ConnectionConfigVar;
|
|
164
|
+
export type ConfigVar = StandardConfigVar | DataSourceConfigVar | ConnectionConfigVar | OrganizationActivatedConnectionConfigVar;
|
|
165
165
|
type WithCollectionType<TValue, TCollectionType extends CollectionType | undefined> = undefined | unknown extends TCollectionType ? TValue : TCollectionType extends "valuelist" ? TValue[] : Array<{
|
|
166
166
|
key: string;
|
|
167
167
|
value: TValue;
|
|
@@ -174,7 +174,12 @@ type ExtractConfigVars<TConfigPages extends {
|
|
|
174
174
|
}> = keyof TConfigPages extends infer TPageName ? TPageName extends keyof TConfigPages ? TConfigPages[TPageName] extends infer TConfigPage ? TConfigPage extends ConfigPage ? {
|
|
175
175
|
[Key in keyof TConfigPage["elements"] as Key extends string ? TConfigPage["elements"][Key] extends ConfigVar ? Key : never : never]: ElementToRuntimeType<TConfigPage["elements"][Key]>;
|
|
176
176
|
} : never : never : never : never;
|
|
177
|
-
|
|
177
|
+
type ExtractScopedConfigVars<TScopedConfigVarMap extends {
|
|
178
|
+
[key: string]: string | OrganizationActivatedConnectionConfigVar;
|
|
179
|
+
}> = keyof TScopedConfigVarMap extends infer TScopedConfigVarName ? TScopedConfigVarName extends keyof TScopedConfigVarMap ? TScopedConfigVarMap[TScopedConfigVarName] extends infer TScopedConfigVar ? TScopedConfigVar extends OrganizationActivatedConnectionConfigVar ? {
|
|
180
|
+
[Key in keyof TScopedConfigVarMap as Key extends string ? TScopedConfigVarMap[Key] extends OrganizationActivatedConnectionConfigVar ? Key : never : never]: Connection;
|
|
181
|
+
} : never : never : never : never;
|
|
182
|
+
export type ConfigVars = Prettify<UnionToIntersection<ExtractConfigVars<ConfigPages>>> & Prettify<UnionToIntersection<ExtractConfigVars<UserLevelConfigPages>>> & Prettify<UnionToIntersection<ExtractScopedConfigVars<ScopedConfigVarMap>>>;
|
|
178
183
|
export declare const isCodeConfigVar: (cv: ConfigVar) => cv is CodeConfigVar;
|
|
179
184
|
export declare const isScheduleConfigVar: (cv: ConfigVar) => cv is ScheduleConfigVar;
|
|
180
185
|
export declare const isJsonFormConfigVar: (cv: ConfigVar) => cv is JsonFormConfigVar;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionPerformFunction, ActionPerformReturn, TriggerEventFunction, TriggerPerformFunction, Inputs, TriggerResult, TriggerPayload, ComponentRegistry, TriggerReference, ConfigVars, ConfigPages, UserLevelConfigPages, ValueExpression, ConfigVarExpression, ActionContext } from ".";
|
|
1
|
+
import { ActionPerformFunction, ActionPerformReturn, TriggerEventFunction, TriggerPerformFunction, Inputs, TriggerResult, TriggerPayload, ComponentRegistry, TriggerReference, ConfigVars, ConfigPages, UserLevelConfigPages, ValueExpression, ConfigVarExpression, ActionContext, ScopedConfigVarMap } from ".";
|
|
2
2
|
/** Defines attributes of a Code-Native Integration. */
|
|
3
3
|
export type IntegrationDefinition = {
|
|
4
4
|
/** The unique name for this Integration. */
|
|
@@ -28,6 +28,8 @@ export type IntegrationDefinition = {
|
|
|
28
28
|
configPages?: ConfigPages;
|
|
29
29
|
/** User Level Config Wizard Pages for this Integration. */
|
|
30
30
|
userLevelConfigPages?: UserLevelConfigPages;
|
|
31
|
+
/** Scoped ConfigVars for this Integration. */
|
|
32
|
+
scopedConfigVars?: ScopedConfigVarMap;
|
|
31
33
|
componentRegistry?: ComponentRegistry;
|
|
32
34
|
};
|
|
33
35
|
export type FlowOnExecution<TTriggerPayload extends TriggerPayload> = ActionPerformFunction<{
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ConfigVar } from ".";
|
|
2
|
+
import type { UnionToIntersection } from "./utils";
|
|
3
|
+
export type OrganizationActivatedConnectionConfigVar = {
|
|
4
|
+
dataType: "connection";
|
|
5
|
+
stableKey: string;
|
|
6
|
+
};
|
|
7
|
+
export type ScopedConfigVar = OrganizationActivatedConnectionConfigVar;
|
|
8
|
+
/**
|
|
9
|
+
* Root ScopedConfigVars type exposed for augmentation.
|
|
10
|
+
*
|
|
11
|
+
* The expected interface when augmenting is:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* interface IntegrationDefinitionScopedConfigVars {
|
|
15
|
+
* [key: string]: OrganizationActivatedConnectionConfigVar
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export interface IntegrationDefinitionScopedConfigVars {
|
|
21
|
+
}
|
|
22
|
+
type CreateScopedConfigVars<TScopedConfigVarMap> = keyof TScopedConfigVarMap extends never ? {
|
|
23
|
+
[key: string]: OrganizationActivatedConnectionConfigVar | string;
|
|
24
|
+
} : UnionToIntersection<keyof TScopedConfigVarMap extends infer TScopedConfigVarName ? TScopedConfigVarName extends keyof TScopedConfigVarMap ? TScopedConfigVarMap[TScopedConfigVarName] extends OrganizationActivatedConnectionConfigVar ? {
|
|
25
|
+
[Key in TScopedConfigVarName]: TScopedConfigVarMap[TScopedConfigVarName];
|
|
26
|
+
} : never : never : never>;
|
|
27
|
+
export type ScopedConfigVarMap = CreateScopedConfigVars<IntegrationDefinitionScopedConfigVars>;
|
|
28
|
+
export declare const isOrganizationActivatedConnectionConfigVar: (cv: ConfigVar) => cv is OrganizationActivatedConnectionConfigVar;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOrganizationActivatedConnectionConfigVar = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const isOrganizationActivatedConnectionConfigVar = (cv) => "dataType" in cv &&
|
|
6
|
+
cv.dataType === "connection" &&
|
|
7
|
+
!(0, _1.isConnectionDefinitionConfigVar)(cv) &&
|
|
8
|
+
!(0, _1.isConnectionReferenceConfigVar)(cv);
|
|
9
|
+
exports.isOrganizationActivatedConnectionConfigVar = isOrganizationActivatedConnectionConfigVar;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./ComponentDefinition";
|
|
|
7
7
|
export * from "./ComponentRegistry";
|
|
8
8
|
export * from "./ConfigPages";
|
|
9
9
|
export * from "./ConfigVars";
|
|
10
|
+
export * from "./ScopedConfigVars";
|
|
10
11
|
export * from "./ConnectionDefinition";
|
|
11
12
|
export * from "./Inputs";
|
|
12
13
|
export * from "./ActionPerformReturn";
|
|
@@ -32,4 +33,5 @@ export * from "./IntegrationAttributes";
|
|
|
32
33
|
export * from "./FlowAttributes";
|
|
33
34
|
export * from "./IntegrationDefinition";
|
|
34
35
|
export * from "./ComponentManifest";
|
|
36
|
+
export * from "./ScopedConfigVars";
|
|
35
37
|
export * as serverTypes from "../serverTypes";
|
package/dist/types/index.js
CHANGED
|
@@ -36,6 +36,7 @@ __exportStar(require("./ComponentDefinition"), exports);
|
|
|
36
36
|
__exportStar(require("./ComponentRegistry"), exports);
|
|
37
37
|
__exportStar(require("./ConfigPages"), exports);
|
|
38
38
|
__exportStar(require("./ConfigVars"), exports);
|
|
39
|
+
__exportStar(require("./ScopedConfigVars"), exports);
|
|
39
40
|
__exportStar(require("./ConnectionDefinition"), exports);
|
|
40
41
|
__exportStar(require("./Inputs"), exports);
|
|
41
42
|
__exportStar(require("./ActionPerformReturn"), exports);
|
|
@@ -61,4 +62,5 @@ __exportStar(require("./IntegrationAttributes"), exports);
|
|
|
61
62
|
__exportStar(require("./FlowAttributes"), exports);
|
|
62
63
|
__exportStar(require("./IntegrationDefinition"), exports);
|
|
63
64
|
__exportStar(require("./ComponentManifest"), exports);
|
|
65
|
+
__exportStar(require("./ScopedConfigVars"), exports);
|
|
64
66
|
exports.serverTypes = __importStar(require("../serverTypes"));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismatic-io/spectral",
|
|
3
|
-
"version": "9.
|
|
4
|
-
"description": "Utility library for building Prismatic components",
|
|
3
|
+
"version": "9.2.0",
|
|
4
|
+
"description": "Utility library for building Prismatic components and code-native integrations",
|
|
5
5
|
"keywords": ["prismatic"],
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|