@prismatic-io/spectral 8.0.7 → 8.1.0-preview2

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/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, OnPremiseConnectionDefinition } from "./types";
6
+ import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, IntegrationDefinition, Flow, ConfigPage, StandardConfigVar, ConnectionConfigVar, ConfigVarResultCollection, TriggerPayload, DataSourceConfigVar, ConfigPages, OnPremiseConnectionDefinition, ScheduleConfigVar, ComponentSelector } from "./types";
7
7
  import { convertComponent } from "./serverTypes/convert";
8
8
  import { convertIntegration } from "./serverTypes/convertIntegration";
9
9
  /**
@@ -14,42 +14,49 @@ 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: <TConfigPages extends ConfigPages = ConfigPages>(definition: IntegrationDefinition<TConfigPages>) => ReturnType<typeof convertIntegration>;
17
+ export declare const integration: <TComponents extends ComponentSelector<any> = ComponentSelector<any>, TConfigPages extends ConfigPages<TComponents> = ConfigPages<TComponents>>(definition: IntegrationDefinition<TConfigPages, TComponents>) => 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 = ConfigPages, TTriggerPayload extends TriggerPayload = TriggerPayload, T extends Flow<TConfigPages, TTriggerPayload> = Flow<TConfigPages, TTriggerPayload>>(definition: T) => T;
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;
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>(definition: T) => T;
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
+ };
32
39
  /**
33
40
  * For information on writing Code Native Integrations, see
34
41
  * https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
35
42
  * @param definition A Config Var type object.
36
43
  * @returns This function returns a standard config var object that has the shape the Prismatic API expects.
37
44
  */
38
- export declare const configVar: <T extends StandardConfigVar>(definition: T) => T;
45
+ export declare const configVar: <T extends StandardConfigVar | ScheduleConfigVar>(definition: T) => T;
39
46
  /**
40
47
  * For information on writing Code Native Integrations, see
41
48
  * https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
42
49
  * @param definition A Data Source Config Var type object.
43
50
  * @returns This function returns a data source config var object that has the shape the Prismatic API expects.
44
51
  */
45
- export declare const dataSourceConfigVar: <T extends DataSourceConfigVar>(definition: T) => T;
52
+ export declare const dataSourceConfigVar: <T extends DataSourceConfigVar<any> = DataSourceConfigVar<any>>(definition: T) => T;
46
53
  /**
47
54
  * For information on writing Code Native Integrations, see
48
55
  * https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
49
56
  * @param definition A Connection Config Var type object.
50
57
  * @returns This function returns a connection config var object that has the shape the Prismatic API expects.
51
58
  */
52
- export declare const connectionConfigVar: <T extends ConnectionConfigVar>(definition: T) => T;
59
+ export declare const connectionConfigVar: <T extends ConnectionConfigVar<any> = ConnectionConfigVar<any>>(definition: T) => T;
53
60
  /**
54
61
  * This function creates a component object that can be
55
62
  * imported into the Prismatic API. For information on using
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.onPremiseConnection = 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;
25
+ exports.testing = exports.util = exports.oauth2Connection = exports.onPremiseConnection = 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;
26
26
  const convert_1 = require("./serverTypes/convert");
27
27
  const convertIntegration_1 = require("./serverTypes/convertIntegration");
28
28
  /**
@@ -58,6 +58,14 @@ 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;
61
69
  /**
62
70
  * For information on writing Code Native Integrations, see
63
71
  * https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
@@ -1,3 +1,3 @@
1
- import { IntegrationDefinition, ConfigPages } from "../types";
1
+ import { IntegrationDefinition, ConfigPages, ComponentSelector } from "../types";
2
2
  import { Component as ServerComponent } from ".";
3
- export declare const convertIntegration: (definition: IntegrationDefinition<ConfigPages>) => ServerComponent;
3
+ export declare const convertIntegration: (definition: IntegrationDefinition<ConfigPages<any>, ComponentSelector<any>>) => ServerComponent;
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.convertIntegration = void 0;
7
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
7
8
  const yaml_1 = __importDefault(require("yaml"));
8
9
  const uuid_1 = require("uuid");
9
10
  const lodash_1 = require("lodash");
@@ -47,7 +48,11 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
47
48
  const preprocessFlowConfig = hasPreprocessFlow
48
49
  ? preprocessFlows[0].preprocessFlowConfig
49
50
  : triggerPreprocessFlowConfig;
50
- if ([types_1.EndpointType.InstanceSpecific, types_1.EndpointType.SharedInstance].includes(endpointType || types_1.EndpointType.FlowSpecific) &&
51
+ const nonPreprocessFlowTypes = [
52
+ "instance_specific",
53
+ "shared_instance",
54
+ ];
55
+ if (nonPreprocessFlowTypes.includes(endpointType || "flow_specific") &&
51
56
  !preprocessFlowConfig) {
52
57
  throw new Error("Integration with specified EndpointType must define either a Trigger Preprocess Flow Config or a Preprocess Flow.");
53
58
  }
@@ -74,8 +79,35 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
74
79
  };
75
80
  return yaml_1.default.stringify(result);
76
81
  };
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]) => {
95
+ if ("value" in value) {
96
+ return Object.assign(Object.assign({}, result), { [key]: { type: "value", value: value.value } });
97
+ }
98
+ if ("configVar" in value) {
99
+ return Object.assign(Object.assign({}, result), { [key]: { type: "configVar", value: value.configVar } });
100
+ }
101
+ return result;
102
+ }, {});
103
+ return {
104
+ ref: { key, component },
105
+ inputs,
106
+ };
107
+ };
77
108
  /** Converts a Flow into the structure necessary for YAML generation. */
78
109
  const convertFlow = (flow, referenceKey) => {
110
+ var _a;
79
111
  const result = Object.assign({}, flow);
80
112
  delete result.onTrigger;
81
113
  delete result.trigger;
@@ -90,20 +122,38 @@ const convertFlow = (flow, referenceKey) => {
90
122
  description: "The function that will be executed by the flow to return an HTTP response.",
91
123
  isTrigger: true,
92
124
  errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
93
- action: {
94
- key: flowFunctionKey(flow.name, "onTrigger"),
95
- component: { key: referenceKey, version: "LATEST", isPublic: false },
96
- },
97
125
  };
126
+ if (typeof flow.onTrigger === "function") {
127
+ triggerStep.action = {
128
+ key: flowFunctionKey(flow.name, "onTrigger"),
129
+ component: {
130
+ key: referenceKey,
131
+ version: "LATEST",
132
+ isPublic: false,
133
+ },
134
+ };
135
+ }
136
+ else if ((0, types_1.isComponentReference)(flow.onTrigger)) {
137
+ const { ref, inputs } = convertComponentReference(flow.onTrigger);
138
+ triggerStep.action = ref;
139
+ triggerStep.inputs = inputs;
140
+ }
141
+ else {
142
+ const hasSchedule = "schedule" in flow && typeof flow.schedule === "object";
143
+ const key = hasSchedule ? "schedule" : "webhook";
144
+ triggerStep.action = {
145
+ key,
146
+ component: { key: `${key}-triggers`, version: "LATEST", isPublic: true },
147
+ };
148
+ }
98
149
  if ("schedule" in flow && typeof flow.schedule === "object") {
150
+ const { schedule } = flow;
99
151
  triggerStep.schedule = {
100
- type: "cronExpression" in flow.schedule ? "value" : "configVar",
101
- value: "cronExpression" in flow.schedule
102
- ? flow.schedule.cronExpression
103
- : flow.schedule.configVarKey,
152
+ type: "configVar" in schedule ? "configVar" : "value",
153
+ value: "configVar" in schedule ? schedule.configVar : schedule.value,
104
154
  meta: {
105
- scheduleType: types_1.ScheduleType.Custom,
106
- timeZone: flow.schedule.timeZone,
155
+ scheduleType: "custom",
156
+ timeZone: (_a = schedule.timezone) !== null && _a !== void 0 ? _a : "",
107
157
  },
108
158
  };
109
159
  delete result.schedule;
@@ -127,7 +177,7 @@ const convertConfigVar = (key, configVar, referenceKey) => {
127
177
  "visibleToCustomerDeployer",
128
178
  "visibleToOrgDeployer",
129
179
  ]);
130
- if ((0, types_1.isConnectionConfigVar)(configVar)) {
180
+ if ((0, types_1.isConnectionDefinitionConfigVar)(configVar)) {
131
181
  return Object.assign(Object.assign({}, (0, lodash_1.pick)(configVar, ["stableKey", "description", "orgOnly"])), { key, dataType: "connection", connection: {
132
182
  component: { key: referenceKey, version: "LATEST", isPublic: false },
133
183
  key: (0, lodash_1.camelCase)(key),
@@ -143,6 +193,10 @@ const convertConfigVar = (key, configVar, referenceKey) => {
143
193
  return Object.assign(Object.assign({}, result), { [key]: { type: "value", value } });
144
194
  }, {}), meta });
145
195
  }
196
+ if ((0, types_1.isConnectionReferenceConfigVar)(configVar)) {
197
+ const { ref, inputs } = convertComponentReference(configVar.connection);
198
+ return Object.assign(Object.assign({}, (0, lodash_1.pick)(configVar, ["stableKey", "description", "orgOnly"])), { key, dataType: "connection", connection: ref, inputs });
199
+ }
146
200
  const result = (0, lodash_1.assign)({ meta, key }, (0, lodash_1.pick)(configVar, [
147
201
  "stableKey",
148
202
  "description",
@@ -150,19 +204,26 @@ const convertConfigVar = (key, configVar, referenceKey) => {
150
204
  "defaultValue",
151
205
  "dataType",
152
206
  "pickList",
153
- "scheduleType",
154
207
  "timeZone",
155
208
  "codeLanguage",
156
209
  "collectionType",
157
210
  ]));
158
- // Handle data sources.
159
- if ((0, types_1.isDataSourceConfigVar)(configVar)) {
211
+ if ((0, types_1.isScheduleConfigVar)(configVar)) {
212
+ result.scheduleType = "custom";
213
+ }
214
+ if ((0, types_1.isDataSourceDefinitionConfigVar)(configVar)) {
160
215
  result.dataType = configVar.dataSourceType;
161
216
  result.dataSource = {
162
217
  key: (0, lodash_1.camelCase)(key),
163
218
  component: { key: referenceKey, version: "LATEST", isPublic: false },
164
219
  };
165
220
  }
221
+ if ((0, types_1.isDataSourceReferenceConfigVar)(configVar)) {
222
+ const { ref, inputs } = convertComponentReference(configVar.dataSource);
223
+ result.dataType = configVar.dataSourceType;
224
+ result.dataSource = ref;
225
+ result.inputs = inputs;
226
+ }
166
227
  return result;
167
228
  };
168
229
  /** Maps the step name field to a fully qualified input. */
@@ -199,6 +260,9 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
199
260
  } });
200
261
  }, {});
201
262
  const convertedTriggers = flows.reduce((result, { name, onTrigger, onInstanceDeploy, onInstanceDelete }) => {
263
+ if (typeof onTrigger !== "function") {
264
+ return result;
265
+ }
202
266
  const key = flowFunctionKey(name, "onTrigger");
203
267
  return Object.assign(Object.assign({}, result), { [key]: {
204
268
  key,
@@ -217,7 +281,7 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
217
281
  } });
218
282
  }, {});
219
283
  const convertedDataSources = Object.entries(configVars).reduce((result, [key, configVar]) => {
220
- if (!(0, types_1.isDataSourceConfigVar)(configVar)) {
284
+ if (!(0, types_1.isDataSourceDefinitionConfigVar)(configVar)) {
221
285
  return result;
222
286
  }
223
287
  const camelKey = (0, lodash_1.camelCase)(key);
@@ -228,7 +292,7 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
228
292
  }, inputs: [] }) });
229
293
  }, {});
230
294
  const convertedConnections = Object.entries(configVars).reduce((result, [key, configVar]) => {
231
- if (!(0, types_1.isConnectionConfigVar)(configVar)) {
295
+ if (!(0, types_1.isConnectionDefinitionConfigVar)(configVar)) {
232
296
  return result;
233
297
  }
234
298
  const convertedInputs = Object.entries(configVar.inputs).map(([key, value]) => (0, convert_1.convertInput)(key, value));
@@ -1,8 +1,11 @@
1
1
  export declare const DefinitionVersion = 7;
2
2
  export interface ComponentReference {
3
+ component: {
4
+ key: string;
5
+ version: number | "LATEST";
6
+ isPublic: boolean;
7
+ };
3
8
  key: string;
4
- version: number | "LATEST";
5
- isPublic: boolean;
6
9
  }
7
10
  export declare type Input = {
8
11
  name?: string;
@@ -21,10 +24,7 @@ export interface ConnectionRequiredConfigVariable {
21
24
  description?: string;
22
25
  orgOnly?: boolean;
23
26
  dataType: "connection";
24
- connection: {
25
- component: ComponentReference;
26
- key: string;
27
- };
27
+ connection: ComponentReference;
28
28
  inputs?: Record<string, Input>;
29
29
  meta?: Record<string, unknown>;
30
30
  }
@@ -40,10 +40,7 @@ export interface DefaultRequiredConfigVariable {
40
40
  description?: string;
41
41
  orgOnly?: boolean;
42
42
  collectionType?: "valuelist" | "keyvaluelist";
43
- dataSource?: {
44
- component: ComponentReference;
45
- key: string;
46
- };
43
+ dataSource?: ComponentReference;
47
44
  inputs?: Record<string, Input>;
48
45
  meta?: Record<string, unknown>;
49
46
  }
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 } from "./types";
8
+ import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow, ConfigVarResultCollection, ConfigPages, ComponentSelector } from "./types";
9
9
  export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>, tokenValues?: Record<string, unknown> | undefined) => ConnectionValue;
10
10
  /**
11
11
  * Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
@@ -63,7 +63,7 @@ declare type ToTestValues<TConfigVars extends ConfigVarResultCollection> = {
63
63
  * Invokes specified Flow of a Code Native Integration using supplied params.
64
64
  * Runs the Trigger and then the Action function and returns the result of the Action.
65
65
  */
66
- export declare const invokeFlow: <TConfigPages extends ConfigPages, TConfigVars extends ConfigVarResultCollection = import("./types/utils").Prettify<{ [Key in keyof (TConfigPages extends ConfigPages ? import("./types/utils").UnionToIntersection<import("./types/utils").ValueOf<TConfigPages>["elements"]> : never)]: import("./types").ElementToRuntimeType<(TConfigPages extends ConfigPages ? import("./types/utils").UnionToIntersection<import("./types/utils").ValueOf<TConfigPages>["elements"]> : never)[Key]>; }>, TConfigVarValues extends TestConfigVarValues = ToTestValues<TConfigVars>>(flow: Flow<TConfigPages, import("./types").TriggerPayload>, configVars: TConfigVarValues, context?: Partial<ActionContext<TConfigVars>> | undefined, payload?: TriggerPayload | undefined) => Promise<InvokeReturn<InvokeActionPerformReturn<false, unknown>>>;
66
+ 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: TConfigVarValues, context?: Partial<ActionContext<TConfigVars>> | undefined, payload?: TriggerPayload | undefined) => Promise<InvokeReturn<InvokeActionPerformReturn<false, unknown>>>;
67
67
  export declare class ComponentTestHarness<TComponent extends Component> {
68
68
  component: TComponent;
69
69
  constructor(component: TComponent);
package/dist/testing.js CHANGED
@@ -197,7 +197,7 @@ const invokeFlow = (flow, configVars, context, payload) => __awaiter(void 0, voi
197
197
  const params = {
198
198
  onTrigger: { results: null },
199
199
  };
200
- if ("onTrigger" in flow) {
200
+ if ("onTrigger" in flow && typeof flow.onTrigger === "function") {
201
201
  const triggerResult = yield flow.onTrigger(realizedContext, realizedPayload, params);
202
202
  params.onTrigger = { results: triggerResult === null || triggerResult === void 0 ? void 0 : triggerResult.payload };
203
203
  }
@@ -1,14 +1,13 @@
1
1
  import { DataSourceDefinition, ConnectionDefinition, ActionPerformFunction, ActionPerformReturn, TriggerEventFunction, TriggerPerformFunction, Inputs, TriggerResult, DataSourceType, TriggerPayload, Connection, JSONForm, ObjectFieldMap, ObjectSelection, ConfigVarResultCollection, Schedule } from ".";
2
2
  import { Prettify, UnionToIntersection, ValueOf } from "./utils";
3
- declare type ToDataSourceRuntimeType<TType extends DataSourceType> = TType extends "jsonForm" ? JSONForm : TType extends "objectSelection" ? ObjectSelection : TType extends "objectFieldMap" ? ObjectFieldMap : string;
4
- declare type ToRuntimeType<TType extends ConfigVarDataType> = TType extends ConfigVarDataType.Schedule ? Schedule : string;
5
- export declare type ElementToRuntimeType<TElement extends ConfigPageElement> = TElement extends ConnectionConfigVar ? Connection : TElement extends DataSourceConfigVar ? ToDataSourceRuntimeType<TElement["dataSourceType"]> : TElement extends StandardConfigVar ? ToRuntimeType<TElement["dataType"]> : never;
6
- declare type GetElements<TConfigPages extends ConfigPages> = TConfigPages extends ConfigPages ? UnionToIntersection<ValueOf<TConfigPages>["elements"]> : never;
7
- export declare type ExtractConfigVars<TConfigPages extends ConfigPages, TElements extends ConfigPage["elements"] = GetElements<TConfigPages>> = Prettify<{
8
- [Key in keyof TElements]: ElementToRuntimeType<TElements[Key]>;
3
+ export declare type ToDataSourceRuntimeType<TType extends DataSourceType> = TType extends "jsonForm" ? JSONForm : TType extends "objectSelection" ? ObjectSelection : TType extends "objectFieldMap" ? ObjectFieldMap : string;
4
+ export declare type ElementToRuntimeType<TElement extends ConfigPageElement<any>> = TElement extends ConnectionConfigVar<any> ? Connection : TElement extends DataSourceConfigVar<any> ? ToDataSourceRuntimeType<TElement["dataSourceType"]> : TElement extends ScheduleConfigVar ? Schedule : TElement extends StandardConfigVar ? string : never;
5
+ export declare type GetElements<TConfigPages extends ConfigPages<any>> = TConfigPages extends ConfigPages<any> ? UnionToIntersection<ValueOf<TConfigPages>["elements"]> : never;
6
+ export declare type ExtractConfigVars<TConfigPages extends ConfigPages<any>, TElements extends ConfigPage<any>["elements"] = GetElements<TConfigPages>> = Prettify<{
7
+ [Key in keyof TElements as Key extends string ? Key : never]: ElementToRuntimeType<TElements[Key]>;
9
8
  }>;
10
9
  /** Defines attributes of a Code-Native Integration. */
11
- export declare type IntegrationDefinition<TConfigPages extends ConfigPages> = {
10
+ export declare type IntegrationDefinition<TConfigPages extends ConfigPages<TComponents>, TComponents extends ComponentSelector<any>> = {
12
11
  /** The unique name for this Integration. */
13
12
  name: string;
14
13
  /** Optional description for this Integration. */
@@ -31,12 +30,12 @@ export declare type IntegrationDefinition<TConfigPages extends ConfigPages> = {
31
30
  * Cannot specify this if a Preprocess Flow is also configured. */
32
31
  triggerPreprocessFlowConfig?: PreprocessFlowConfig;
33
32
  /** Flows for this Integration. */
34
- flows: Flow<TConfigPages>[];
33
+ flows: Flow<TConfigPages, TComponents>[];
35
34
  /** Config Wizard Pages for this Integration. */
36
35
  configPages?: TConfigPages;
37
36
  };
38
37
  /** Defines attributes of a Flow of a Code-Native Integration. */
39
- export interface Flow<TConfigPages extends ConfigPages, TTriggerPayload extends TriggerPayload = TriggerPayload> {
38
+ export interface Flow<TConfigPages extends ConfigPages<TComponents>, TComponents extends ComponentSelector<any>, TTriggerPayload extends TriggerPayload = TriggerPayload> {
40
39
  /** The unique name for this Flow. */
41
40
  name: string;
42
41
  /** A unique, unchanging value that is used to maintain identity for the Flow even if the name changes. */
@@ -54,11 +53,13 @@ export interface Flow<TConfigPages extends ConfigPages, TTriggerPayload extends
54
53
  /** Optional list of API key(s) to use for the endpoint of this Flow when the endpoint security type is EndpointSecurityType.Organization. */
55
54
  organizationApiKeys?: string[];
56
55
  /** Optional schedule configuration that defines the frequency with which this Flow will be automatically executed. */
57
- schedule?: FlowSchedule;
56
+ schedule?: ValueReference<string, TConfigPages> & {
57
+ timezone?: string;
58
+ };
58
59
  /** Optional error handling configuration. */
59
60
  errorConfig?: StepErrorConfig;
60
61
  /** Specifies the trigger function for this Flow, which returns a payload and optional HTTP response. */
61
- onTrigger: TriggerPerformFunction<Inputs, ExtractConfigVars<TConfigPages>, false, TriggerResult<false, TTriggerPayload>>;
62
+ onTrigger?: ToComponentReferences<"trigger", TComponents, TConfigPages> | TriggerPerformFunction<Inputs, ExtractConfigVars<TConfigPages>, false, TriggerResult<false, TTriggerPayload>>;
62
63
  /** Specifies the function to execute when an Instance of this Integration is deployed. */
63
64
  onInstanceDeploy?: TriggerEventFunction<Inputs, ExtractConfigVars<TConfigPages>>;
64
65
  /** Specifies the function to execute when an Instance of an Integration is deleted. */
@@ -90,33 +91,49 @@ declare type BaseConfigVar = {
90
91
  /** Defines attributes of a standard Config Var. */
91
92
  export declare type StandardConfigVar = BaseConfigVar & {
92
93
  /** The data type of the Config Var. */
93
- dataType: ConfigVarDataType;
94
+ dataType: Exclude<ConfigVarDataType, "schedule">;
94
95
  /** Optional default value for the Config Var. */
95
96
  defaultValue?: string;
96
97
  /** Optional list of picklist values if the Config Var is a multi-choice selection value. */
97
98
  pickList?: string[];
98
- /** Optional schedule type that defines the cadence of the schedule. */
99
- scheduleType?: ScheduleType;
100
- /** Optional value to use as a timezone if the Config Var is a schedule value. */
101
- timeZone?: string;
102
99
  /** Optional value to specify the type of language if the Config Var is a code value. */
103
100
  codeLanguage?: CodeLanguageType;
104
101
  /** Optional value to specify the type of collection if the Config Var is multi-value. */
105
102
  collectionType?: CollectionType;
106
103
  };
104
+ export declare type ScheduleConfigVar = BaseConfigVar & {
105
+ /** The data type of the Config Var. */
106
+ dataType: "schedule";
107
+ /** Optional default value for the Config Var. */
108
+ defaultValue?: string;
109
+ /** Optional timezone for the schedule. */
110
+ timeZone?: string;
111
+ };
112
+ declare type DataSourceDefinitionConfigVar = BaseConfigVar & Omit<DataSourceDefinition<Inputs, ConfigVarResultCollection, DataSourceType>, "display" | "inputs" | "examplePayload">;
113
+ declare type DataSourceReferenceConfigVar<TComponents extends ComponentSelector<any>> = BaseConfigVar & {
114
+ dataSourceType: DataSourceType;
115
+ dataSource: ToComponentReferences<"dataSource", TComponents, ConfigPages<TComponents>>;
116
+ };
107
117
  /** Defines attributes of a data source Config Var. */
108
- export declare type DataSourceConfigVar = BaseConfigVar & Omit<DataSourceDefinition<Inputs, ConfigVarResultCollection, DataSourceType>, "display" | "inputs" | "examplePayload">;
118
+ export declare type DataSourceConfigVar<TComponents extends ComponentSelector<any>> = DataSourceDefinitionConfigVar | DataSourceReferenceConfigVar<TComponents>;
119
+ declare type ConnectionDefinitionConfigVar = BaseConfigVar & Omit<ConnectionDefinition, "label" | "comments" | "key">;
120
+ declare type ConnectionReferenceConfigVar<TComponents extends ComponentSelector<any>> = BaseConfigVar & {
121
+ connection: ToComponentReferences<"connection", TComponents>;
122
+ };
109
123
  /** Defines attributes of a Config Var that represents a Connection. */
110
- export declare type ConnectionConfigVar = BaseConfigVar & Omit<ConnectionDefinition, "label" | "comments" | "key">;
111
- export declare type ConfigVar = StandardConfigVar | DataSourceConfigVar | ConnectionConfigVar;
112
- export declare const isDataSourceConfigVar: (cv: ConfigVar) => cv is DataSourceConfigVar;
113
- export declare const isConnectionConfigVar: (cv: ConfigVar) => cv is ConnectionConfigVar;
114
- export declare type ConfigPageElement = string | ConfigVar;
115
- export declare type ConfigPages = Record<string, ConfigPage>;
124
+ export declare type ConnectionConfigVar<TComponents extends ComponentSelector<any>> = ConnectionDefinitionConfigVar | ConnectionReferenceConfigVar<TComponents>;
125
+ export declare type ConfigVar<TComponents extends ComponentSelector<any>> = StandardConfigVar | ScheduleConfigVar | DataSourceConfigVar<TComponents> | ConnectionConfigVar<TComponents>;
126
+ export declare const isScheduleConfigVar: (cv: ConfigVar<any>) => cv is ScheduleConfigVar;
127
+ export declare const isDataSourceDefinitionConfigVar: (cv: ConfigVar<any>) => cv is DataSourceDefinitionConfigVar;
128
+ export declare const isDataSourceReferenceConfigVar: <TComponents extends ComponentSelector<any>>(cv: ConfigVar<TComponents>) => cv is DataSourceReferenceConfigVar<TComponents>;
129
+ export declare const isConnectionDefinitionConfigVar: (cv: ConfigVar<any>) => cv is ConnectionDefinitionConfigVar;
130
+ export declare const isConnectionReferenceConfigVar: <TComponents extends ComponentSelector<any>>(cv: ConfigVar<TComponents>) => cv is ConnectionReferenceConfigVar<TComponents>;
131
+ export declare type ConfigPageElement<TComponents extends ComponentSelector<any>> = string | ConfigVar<TComponents>;
132
+ export declare type ConfigPages<TComponents extends ComponentSelector<any>> = Record<string, ConfigPage<TComponents>>;
116
133
  /** Defines attributes of a Config Wizard Page used when deploying an Instance of an Integration. */
117
- export declare type ConfigPage = {
134
+ export declare type ConfigPage<TComponents extends ComponentSelector<any>> = {
118
135
  /** Elements included on this Config Page. */
119
- elements: Record<string, ConfigPageElement>;
136
+ elements: Record<string, ConfigPageElement<TComponents>>;
120
137
  /** Specifies an optional tagline for this Config Page. */
121
138
  tagline?: string;
122
139
  };
@@ -153,66 +170,52 @@ export declare type StepErrorConfig = {
153
170
  /** Specifies whether to ignore the final error after the final retry attempt. @default false */
154
171
  ignoreFinalError?: boolean;
155
172
  };
156
- /** Defines attributes of a Schedule that controls how often a Flow is automatically executed. */
157
- export declare type FlowSchedule = {
158
- /** The cron expression to use for defining an execution schedule. */
159
- cronExpression: string;
160
- /** Specifies an optional value to use as the timezone. */
161
- timeZone?: string;
162
- } | {
163
- /** The key of the Config Var whose value will define the execution schedule. */
164
- configVarKey: string;
165
- /** Specifies an optional value to use as the timezone. */
166
- timeZone?: string;
167
- };
168
173
  /** Choices of Endpoint Types that may be used by Instances of an Integration. */
169
- export declare enum EndpointType {
170
- FlowSpecific = "flow_specific",
171
- InstanceSpecific = "instance_specific",
172
- SharedInstance = "shared_instance"
173
- }
174
+ export declare type EndpointType = "flow_specific" | "instance_specific" | "shared_instance";
174
175
  /** Choices of Endpoint Security Types that may be used by endpoints of a Flow. */
175
- export declare enum EndpointSecurityType {
176
- Unsecured = "unsecured",
177
- CustomerOptional = "customer_optional",
178
- CustomerRequired = "customer_required",
179
- Organization = "organization"
180
- }
176
+ export declare type EndpointSecurityType = "unsecured" | "customer_optional" | "customer_required" | "organization";
181
177
  /** Choices of Step Error Handlers that define the behavior when a step error occurs. */
182
- export declare enum StepErrorHandlerType {
183
- Fail = "fail",
184
- Ignore = "ignore",
185
- Retry = "retry"
186
- }
187
- /** Choices for Schedules that add context for the cadence of a given schedule. */
188
- export declare enum ScheduleType {
189
- None = "none",
190
- Custom = "custom",
191
- Minute = "minute",
192
- Hour = "hour",
193
- Day = "day",
194
- Week = "week"
195
- }
178
+ export declare type StepErrorHandlerType = "fail" | "ignore" | "retry";
196
179
  /** Supported data types for Config Vars. */
197
- export declare enum ConfigVarDataType {
198
- String = "string",
199
- Date = "date",
200
- Timestamp = "timestamp",
201
- Picklist = "picklist",
202
- Schedule = "schedule",
203
- Code = "code",
204
- Boolean = "boolean",
205
- Number = "number"
206
- }
180
+ export declare type ConfigVarDataType = "string" | "date" | "timestamp" | "picklist" | "schedule" | "code" | "boolean" | "number";
207
181
  /** Choices of programming languages that may be used for Config Var code values. */
208
- export declare enum CodeLanguageType {
209
- JSON = "json",
210
- XML = "xml",
211
- HTML = "html"
212
- }
182
+ export declare type CodeLanguageType = "json" | "xml" | "html";
213
183
  /** Choices of collection types for multi-value Config Vars. */
214
- export declare enum CollectionType {
215
- ValueList = "valuelist",
216
- KeyValueList = "keyvaluelist"
184
+ export declare type CollectionType = "valuelist" | "keyvaluelist";
185
+ /** Choices of component reference types. */
186
+ export declare type ComponentSelectorType = "trigger" | "connection" | "dataSource";
187
+ export declare type ValueReference<TValueType, TConfigPages extends ConfigPages<any>, TConfigVarKeys = keyof ExtractConfigVars<TConfigPages>> = {
188
+ value: TValueType;
189
+ } | (TConfigPages extends ConfigPages<any> ? {
190
+ configVar: TConfigVarKeys;
191
+ } : never);
192
+ export interface ComponentSelector<TValueType> {
193
+ type: ComponentSelectorType;
194
+ component: string | {
195
+ key: string;
196
+ isPublic: boolean;
197
+ };
198
+ key: string;
199
+ values?: {
200
+ [key: string]: TValueType;
201
+ };
202
+ }
203
+ export declare type ToComponentReferences<TReferenceType extends ComponentSelectorType, TComponents extends ComponentSelector<any>, TConfigPages extends ConfigPages<TComponents> = never> = TComponents extends ComponentSelector<infer TValueType> ? TComponents["type"] extends TReferenceType ? {
204
+ component: TComponents["component"];
205
+ key: TComponents["key"];
206
+ values: {
207
+ [K in keyof TComponents["values"]]: ValueReference<TValueType, TConfigPages>;
208
+ };
209
+ } : never : never;
210
+ export interface ComponentReference<TValueType, TConfigPages extends ConfigPages<any>> {
211
+ component: string | {
212
+ key: string;
213
+ isPublic: boolean;
214
+ };
215
+ key: string;
216
+ values?: {
217
+ [key: string]: ValueReference<TValueType, TConfigPages>;
218
+ };
217
219
  }
220
+ export declare const isComponentReference: (ref: unknown) => ref is ComponentReference<any, ConfigPages<any>>;
218
221
  export {};
@@ -1,64 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CollectionType = exports.CodeLanguageType = exports.ConfigVarDataType = exports.ScheduleType = exports.StepErrorHandlerType = exports.EndpointSecurityType = exports.EndpointType = exports.isConnectionConfigVar = exports.isDataSourceConfigVar = void 0;
4
- const isDataSourceConfigVar = (cv) => "dataSourceType" in cv;
5
- exports.isDataSourceConfigVar = isDataSourceConfigVar;
6
- const isConnectionConfigVar = (cv) => "inputs" in cv;
7
- exports.isConnectionConfigVar = isConnectionConfigVar;
8
- /** Choices of Endpoint Types that may be used by Instances of an Integration. */
9
- var EndpointType;
10
- (function (EndpointType) {
11
- EndpointType["FlowSpecific"] = "flow_specific";
12
- EndpointType["InstanceSpecific"] = "instance_specific";
13
- EndpointType["SharedInstance"] = "shared_instance";
14
- })(EndpointType = exports.EndpointType || (exports.EndpointType = {}));
15
- /** Choices of Endpoint Security Types that may be used by endpoints of a Flow. */
16
- var EndpointSecurityType;
17
- (function (EndpointSecurityType) {
18
- EndpointSecurityType["Unsecured"] = "unsecured";
19
- EndpointSecurityType["CustomerOptional"] = "customer_optional";
20
- EndpointSecurityType["CustomerRequired"] = "customer_required";
21
- EndpointSecurityType["Organization"] = "organization";
22
- })(EndpointSecurityType = exports.EndpointSecurityType || (exports.EndpointSecurityType = {}));
23
- /** Choices of Step Error Handlers that define the behavior when a step error occurs. */
24
- var StepErrorHandlerType;
25
- (function (StepErrorHandlerType) {
26
- StepErrorHandlerType["Fail"] = "fail";
27
- StepErrorHandlerType["Ignore"] = "ignore";
28
- StepErrorHandlerType["Retry"] = "retry";
29
- })(StepErrorHandlerType = exports.StepErrorHandlerType || (exports.StepErrorHandlerType = {}));
30
- /** Choices for Schedules that add context for the cadence of a given schedule. */
31
- var ScheduleType;
32
- (function (ScheduleType) {
33
- ScheduleType["None"] = "none";
34
- ScheduleType["Custom"] = "custom";
35
- ScheduleType["Minute"] = "minute";
36
- ScheduleType["Hour"] = "hour";
37
- ScheduleType["Day"] = "day";
38
- ScheduleType["Week"] = "week";
39
- })(ScheduleType = exports.ScheduleType || (exports.ScheduleType = {}));
40
- /** Supported data types for Config Vars. */
41
- var ConfigVarDataType;
42
- (function (ConfigVarDataType) {
43
- ConfigVarDataType["String"] = "string";
44
- ConfigVarDataType["Date"] = "date";
45
- ConfigVarDataType["Timestamp"] = "timestamp";
46
- ConfigVarDataType["Picklist"] = "picklist";
47
- ConfigVarDataType["Schedule"] = "schedule";
48
- ConfigVarDataType["Code"] = "code";
49
- ConfigVarDataType["Boolean"] = "boolean";
50
- ConfigVarDataType["Number"] = "number";
51
- })(ConfigVarDataType = exports.ConfigVarDataType || (exports.ConfigVarDataType = {}));
52
- /** Choices of programming languages that may be used for Config Var code values. */
53
- var CodeLanguageType;
54
- (function (CodeLanguageType) {
55
- CodeLanguageType["JSON"] = "json";
56
- CodeLanguageType["XML"] = "xml";
57
- CodeLanguageType["HTML"] = "html";
58
- })(CodeLanguageType = exports.CodeLanguageType || (exports.CodeLanguageType = {}));
59
- /** Choices of collection types for multi-value Config Vars. */
60
- var CollectionType;
61
- (function (CollectionType) {
62
- CollectionType["ValueList"] = "valuelist";
63
- CollectionType["KeyValueList"] = "keyvaluelist";
64
- })(CollectionType = exports.CollectionType || (exports.CollectionType = {}));
3
+ exports.isComponentReference = exports.isConnectionReferenceConfigVar = exports.isConnectionDefinitionConfigVar = exports.isDataSourceReferenceConfigVar = exports.isDataSourceDefinitionConfigVar = exports.isScheduleConfigVar = void 0;
4
+ const isScheduleConfigVar = (cv) => "dataType" in cv && cv.dataType === "schedule";
5
+ exports.isScheduleConfigVar = isScheduleConfigVar;
6
+ const isDataSourceDefinitionConfigVar = (cv) => "dataSourceType" in cv && "perform" in cv && typeof cv.perform === "function";
7
+ exports.isDataSourceDefinitionConfigVar = isDataSourceDefinitionConfigVar;
8
+ const isDataSourceReferenceConfigVar = (cv) => "dataSource" in cv && (0, exports.isComponentReference)(cv.dataSource);
9
+ exports.isDataSourceReferenceConfigVar = isDataSourceReferenceConfigVar;
10
+ const isConnectionDefinitionConfigVar = (cv) => "inputs" in cv;
11
+ exports.isConnectionDefinitionConfigVar = isConnectionDefinitionConfigVar;
12
+ const isConnectionReferenceConfigVar = (cv) => "connection" in cv && (0, exports.isComponentReference)(cv.connection);
13
+ exports.isConnectionReferenceConfigVar = isConnectionReferenceConfigVar;
14
+ const isComponentReference = (ref) => typeof ref === "object" && ref !== null && "key" in ref && "component" in ref;
15
+ exports.isComponentReference = isComponentReference;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "8.0.7",
3
+ "version": "8.1.0-preview2",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"
@@ -42,7 +42,7 @@
42
42
  "axios-retry": "3.9.1",
43
43
  "date-fns": "2.30.0",
44
44
  "form-data": "4.0.0",
45
- "jest-mock": "27.0.3",
45
+ "jest-mock": "29.7.0",
46
46
  "lodash": "4.17.21",
47
47
  "object-sizeof": "^2.6.4",
48
48
  "safe-stable-stringify": "2.3.1",
@@ -53,7 +53,7 @@
53
53
  "yaml": "2.3.4"
54
54
  },
55
55
  "devDependencies": {
56
- "@types/jest": "27.4.1",
56
+ "@types/jest": "29.5.12",
57
57
  "@types/lodash": "4.14.202",
58
58
  "@types/node": "14.14.35",
59
59
  "@types/sax": "1.2.4",
@@ -64,13 +64,13 @@
64
64
  "@typescript-eslint/parser": "5.18.0",
65
65
  "eslint": "8.12.0",
66
66
  "eslint-config-prettier": "8.5.0",
67
- "eslint-plugin-jest": "26.1.3",
67
+ "eslint-plugin-jest": "27.9.0",
68
68
  "eslint-plugin-prettier": "4.0.0",
69
69
  "fast-check": "2.16.0",
70
- "jest": "27.5.1",
70
+ "jest": "29.7.0",
71
71
  "prettier": "2.6.2",
72
- "ts-jest": "27.0.3",
73
- "tsd": "0.20.0",
72
+ "ts-jest": "29.1.2",
73
+ "tsd": "0.31.0",
74
74
  "typedoc": "0.17.7",
75
75
  "typedoc-plugin-markdown": "2.4.2",
76
76
  "typedoc-plugin-remove-references": "0.0.5",