@prismatic-io/spectral 9.0.0-rc.6 → 9.0.0-rc.7
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.
|
@@ -31,34 +31,35 @@ const types_1 = require("../types");
|
|
|
31
31
|
const convert_1 = require("./convert");
|
|
32
32
|
const integration_1 = require("./integration");
|
|
33
33
|
const convertIntegration = (definition) => {
|
|
34
|
-
var _a;
|
|
34
|
+
var _a, _b;
|
|
35
35
|
// Generate a unique reference key that will be used to reference the
|
|
36
36
|
// actions, triggers, data sources, and connections that are created
|
|
37
37
|
// inline as part of the integration definition.
|
|
38
38
|
const referenceKey = (0, uuid_1.v4)();
|
|
39
|
-
const configVars = Object.values(
|
|
39
|
+
const configVars = Object.values({
|
|
40
|
+
configPages: (_a = definition.configPages) !== null && _a !== void 0 ? _a : {},
|
|
41
|
+
userLevelConfigPages: (_b = definition.userLevelConfigPages) !== null && _b !== void 0 ? _b : {},
|
|
42
|
+
}).reduce((acc, configPages) => (Object.assign(Object.assign({}, acc), Object.values(configPages).reduce((acc, configPage) => Object.entries(configPage.elements).reduce((acc, [key, element]) => {
|
|
40
43
|
// "string" elements are HTML elements and should be ignored.
|
|
41
44
|
if (typeof element === "string") {
|
|
42
45
|
return acc;
|
|
43
46
|
}
|
|
44
47
|
if (key in acc) {
|
|
45
|
-
throw new Error(
|
|
48
|
+
throw new Error(`Duplicate config var key: "${key}"`);
|
|
46
49
|
}
|
|
47
50
|
return Object.assign(Object.assign({}, acc), { [key]: element });
|
|
48
|
-
}, acc), {});
|
|
51
|
+
}, acc), {}))), {});
|
|
49
52
|
const cniComponent = codeNativeIntegrationComponent(definition, referenceKey, configVars);
|
|
50
53
|
const cniYaml = codeNativeIntegrationYaml(definition, referenceKey, configVars);
|
|
51
54
|
return Object.assign(Object.assign({}, cniComponent), { codeNativeIntegrationYAML: cniYaml });
|
|
52
55
|
};
|
|
53
56
|
exports.convertIntegration = convertIntegration;
|
|
54
|
-
const convertConfigPages = (pages) => {
|
|
57
|
+
const convertConfigPages = (pages, userLevelConfigured) => {
|
|
55
58
|
if (!pages || !Object.keys(pages).length) {
|
|
56
|
-
return;
|
|
59
|
+
return [];
|
|
57
60
|
}
|
|
58
|
-
return Object.entries(pages).map(([name, { tagline, elements }]) => ({
|
|
59
|
-
|
|
60
|
-
tagline,
|
|
61
|
-
elements: Object.entries(elements).map(([key, value]) => typeof value === "string"
|
|
61
|
+
return Object.entries(pages).map(([name, { tagline, elements }]) => (Object.assign(Object.assign({ name,
|
|
62
|
+
tagline }, (userLevelConfigured ? { userLevelConfigured } : {})), { elements: Object.entries(elements).map(([key, value]) => typeof value === "string"
|
|
62
63
|
? {
|
|
63
64
|
type: "htmlElement",
|
|
64
65
|
value,
|
|
@@ -66,10 +67,9 @@ const convertConfigPages = (pages) => {
|
|
|
66
67
|
: {
|
|
67
68
|
type: "configVar",
|
|
68
69
|
value: key,
|
|
69
|
-
})
|
|
70
|
-
}));
|
|
70
|
+
}) })));
|
|
71
71
|
};
|
|
72
|
-
const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, endpointType, triggerPreprocessFlowConfig, flows, configPages, componentRegistry = {}, }, referenceKey, configVars) => {
|
|
72
|
+
const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, endpointType, triggerPreprocessFlowConfig, flows, configPages, userLevelConfigPages, componentRegistry = {}, }, referenceKey, configVars) => {
|
|
73
73
|
// Find the preprocess flow config on the flow, if one exists.
|
|
74
74
|
const preprocessFlows = flows.filter((flow) => flow.preprocessFlowConfig);
|
|
75
75
|
// Do some validation of preprocess flow configs.
|
|
@@ -110,7 +110,10 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
|
|
|
110
110
|
externalCustomerUserIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerUserIdField),
|
|
111
111
|
flowNameField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.flowNameField),
|
|
112
112
|
flows: flows.map((flow) => convertFlow(flow, componentRegistry, referenceKey)),
|
|
113
|
-
configPages:
|
|
113
|
+
configPages: [
|
|
114
|
+
...convertConfigPages(configPages, false),
|
|
115
|
+
...convertConfigPages(userLevelConfigPages, true),
|
|
116
|
+
],
|
|
114
117
|
};
|
|
115
118
|
return yaml_1.default.stringify(result);
|
|
116
119
|
};
|
|
@@ -28,6 +28,20 @@ export interface IntegrationDefinitionComponentRegistry {
|
|
|
28
28
|
*/
|
|
29
29
|
export interface IntegrationDefinitionConfigPages {
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Root UserLevelConfigPages type exposed for augmentation.
|
|
33
|
+
*
|
|
34
|
+
* The expected interface when augmenting is:
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* interface IntegrationDefinitionUserLevelConfigPages {
|
|
38
|
+
* [key: string]: ConfigPage
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
export interface IntegrationDefinitionUserLevelConfigPages {
|
|
44
|
+
}
|
|
31
45
|
/** Defines attributes of a Code-Native Integration. */
|
|
32
46
|
export declare type IntegrationDefinition = {
|
|
33
47
|
/** The unique name for this Integration. */
|
|
@@ -55,6 +69,8 @@ export declare type IntegrationDefinition = {
|
|
|
55
69
|
flows: Flow[];
|
|
56
70
|
/** Config Wizard Pages for this Integration. */
|
|
57
71
|
configPages?: ConfigPages;
|
|
72
|
+
/** User Level Config Wizard Pages for this Integration. */
|
|
73
|
+
userLevelConfigPages?: UserLevelConfigPages;
|
|
58
74
|
componentRegistry?: ComponentRegistry;
|
|
59
75
|
};
|
|
60
76
|
/** Defines attributes of a Flow of a Code-Native Integration. */
|
|
@@ -239,14 +255,19 @@ export declare const isDataSourceReferenceConfigVar: (cv: ConfigVar) => cv is Da
|
|
|
239
255
|
export declare const isConnectionDefinitionConfigVar: (cv: ConfigVar) => cv is ConnectionDefinitionConfigVar;
|
|
240
256
|
export declare const isConnectionReferenceConfigVar: (cv: ConfigVar) => cv is ConnectionReferenceConfigVar;
|
|
241
257
|
export declare type ConfigPageElement = string | ConfigVar;
|
|
242
|
-
|
|
258
|
+
declare type CreateConfigPages<TIntegrationDefinitionConfigPages> = keyof TIntegrationDefinitionConfigPages extends never ? {
|
|
243
259
|
[key: string]: ConfigPage;
|
|
244
|
-
} : UnionToIntersection<keyof
|
|
245
|
-
[Key in TPageName]:
|
|
260
|
+
} : UnionToIntersection<keyof TIntegrationDefinitionConfigPages extends infer TPageName ? TPageName extends keyof TIntegrationDefinitionConfigPages ? TIntegrationDefinitionConfigPages[TPageName] extends ConfigPage ? {
|
|
261
|
+
[Key in TPageName]: TIntegrationDefinitionConfigPages[TPageName];
|
|
246
262
|
} : never : never : never>;
|
|
247
|
-
export declare type
|
|
263
|
+
export declare type ConfigPages = CreateConfigPages<IntegrationDefinitionConfigPages>;
|
|
264
|
+
export declare type UserLevelConfigPages = CreateConfigPages<IntegrationDefinitionUserLevelConfigPages>;
|
|
265
|
+
declare type ExtractConfigVars<TConfigPages extends {
|
|
266
|
+
[key: string]: ConfigPage;
|
|
267
|
+
}> = keyof TConfigPages extends infer TPageName ? TPageName extends keyof TConfigPages ? TConfigPages[TPageName] extends infer TConfigPage ? TConfigPage extends ConfigPage ? {
|
|
248
268
|
[Key in keyof TConfigPage["elements"] as Key extends string ? TConfigPage["elements"][Key] extends ConfigVar ? Key : never : never]: ElementToRuntimeType<TConfigPage["elements"][Key]>;
|
|
249
|
-
} : never : never : never : never
|
|
269
|
+
} : never : never : never : never;
|
|
270
|
+
export declare type ConfigVars = Prettify<UnionToIntersection<ExtractConfigVars<ConfigPages> | ExtractConfigVars<UserLevelConfigPages>>>;
|
|
250
271
|
export declare type ToDataSourceRuntimeType<TType extends DataSourceType> = TType extends "jsonForm" ? JSONForm : TType extends "objectSelection" ? ObjectSelection : TType extends "objectFieldMap" ? ObjectFieldMap : string;
|
|
251
272
|
export declare type ElementToRuntimeType<TElement extends ConfigPageElement> = TElement extends ConnectionConfigVar ? Connection : TElement extends DataSourceConfigVar ? ToDataSourceRuntimeType<TElement["dataSourceType"]> : TElement extends ScheduleConfigVar ? Schedule : TElement extends StandardConfigVar ? string : never;
|
|
252
273
|
/** Defines attributes of a Config Wizard Page used when deploying an Instance of an Integration. */
|