@prismatic-io/spectral 8.0.0-preview8 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/http/index.d.ts +1 -1
- package/dist/index.d.ts +15 -16
- package/dist/index.js +11 -10
- package/dist/serverTypes/convert.d.ts +3 -3
- package/dist/serverTypes/convert.js +6 -270
- package/dist/serverTypes/convertIntegration.d.ts +3 -0
- package/dist/serverTypes/convertIntegration.js +242 -0
- package/dist/serverTypes/index.d.ts +10 -9
- package/dist/serverTypes/integration.d.ts +60 -0
- package/dist/serverTypes/integration.js +4 -0
- package/dist/testing.d.ts +20 -20
- package/dist/testing.js +67 -76
- package/dist/types/ActionDefinition.d.ts +3 -3
- package/dist/types/ActionInputParameters.d.ts +1 -14
- package/dist/types/ActionPerformFunction.d.ts +6 -6
- package/dist/types/ComponentDefinition.d.ts +3 -3
- package/dist/types/DataSourceDefinition.d.ts +3 -3
- package/dist/types/DataSourcePerformFunction.d.ts +3 -8
- package/dist/types/DataSourceResult.d.ts +1 -3
- package/dist/types/Inputs.d.ts +52 -42
- package/dist/types/IntegrationDefinition.d.ts +44 -118
- package/dist/types/IntegrationDefinition.js +5 -19
- package/dist/types/TriggerDefinition.d.ts +5 -5
- package/dist/types/TriggerEventFunction.d.ts +2 -2
- package/dist/types/TriggerPerformFunction.d.ts +2 -2
- package/dist/types/TriggerResult.d.ts +4 -4
- package/dist/types/utils.d.ts +5 -0
- package/dist/types/utils.js +2 -0
- package/package.json +5 -4
- package/dist/clients/soap/index.d.ts +0 -2
- package/dist/clients/soap/index.js +0 -18
- package/dist/clients/soap/types.d.ts +0 -71
- package/dist/clients/soap/types.js +0 -24
- package/dist/clients/soap/utils.d.ts +0 -12
- package/dist/clients/soap/utils.js +0 -191
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.convertIntegration = void 0;
|
|
7
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const types_1 = require("../types");
|
|
11
|
+
const convert_1 = require("./convert");
|
|
12
|
+
const integration_1 = require("./integration");
|
|
13
|
+
const convertIntegration = (definition) => {
|
|
14
|
+
var _a;
|
|
15
|
+
// Generate a unique reference key that will be used to reference the
|
|
16
|
+
// actions, triggers, data sources, and connections that are created
|
|
17
|
+
// inline as part of the integration definition.
|
|
18
|
+
const referenceKey = (0, uuid_1.v4)();
|
|
19
|
+
const configVars = Object.assign({}, ...Object.values((_a = definition.configPages) !== null && _a !== void 0 ? _a : {}).map(({ elements }) => elements));
|
|
20
|
+
return Object.assign(Object.assign({}, codeNativeIntegrationComponent(definition, referenceKey, configVars)), { codeNativeIntegrationYAML: codeNativeIntegrationYaml(definition, referenceKey, configVars) });
|
|
21
|
+
};
|
|
22
|
+
exports.convertIntegration = convertIntegration;
|
|
23
|
+
const convertConfigPages = (pages) => {
|
|
24
|
+
return Object.entries(pages).map(([name, { tagline, elements }]) => ({
|
|
25
|
+
name,
|
|
26
|
+
tagline,
|
|
27
|
+
elements: Object.keys(elements).map((key) => ({
|
|
28
|
+
type: "configVar",
|
|
29
|
+
value: key,
|
|
30
|
+
})),
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, endpointType, triggerPreprocessFlowConfig, flows, configPages, }, referenceKey, configVars) => {
|
|
34
|
+
// Find the preprocess flow config on the flow, if one exists.
|
|
35
|
+
const preprocessFlows = flows.filter((flow) => flow.preprocessFlowConfig);
|
|
36
|
+
// Do some validation of preprocess flow configs.
|
|
37
|
+
if (preprocessFlows.length > 1) {
|
|
38
|
+
throw new Error("Only one flow may define a Preprocess Flow Config.");
|
|
39
|
+
}
|
|
40
|
+
if (preprocessFlows.length && triggerPreprocessFlowConfig) {
|
|
41
|
+
throw new Error("Integration must not define both a Trigger Preprocess Flow Config and a Preprocess Flow.");
|
|
42
|
+
}
|
|
43
|
+
const hasPreprocessFlow = preprocessFlows.length > 0;
|
|
44
|
+
const preprocessFlowConfig = hasPreprocessFlow
|
|
45
|
+
? preprocessFlows[0].preprocessFlowConfig
|
|
46
|
+
: triggerPreprocessFlowConfig;
|
|
47
|
+
if ([types_1.EndpointType.InstanceSpecific, types_1.EndpointType.SharedInstance].includes(endpointType || types_1.EndpointType.FlowSpecific) &&
|
|
48
|
+
!preprocessFlowConfig) {
|
|
49
|
+
throw new Error("Integration with specified EndpointType must define either a Trigger Preprocess Flow Config or a Preprocess Flow.");
|
|
50
|
+
}
|
|
51
|
+
// Transform the IntegrationDefinition into the structure that is appropriate
|
|
52
|
+
// for generating YAML, which will then be used by the Prismatic API to import
|
|
53
|
+
// the integration as a Code Native Integration.
|
|
54
|
+
const result = {
|
|
55
|
+
definitionVersion: integration_1.DefinitionVersion,
|
|
56
|
+
isCodeNative: true,
|
|
57
|
+
name,
|
|
58
|
+
description,
|
|
59
|
+
category,
|
|
60
|
+
documentation,
|
|
61
|
+
version,
|
|
62
|
+
labels,
|
|
63
|
+
requiredConfigVars: Object.entries(configVars || {}).map(([key, configVar]) => convertConfigVar(key, configVar, referenceKey)),
|
|
64
|
+
endpointType,
|
|
65
|
+
preprocessFlowName: hasPreprocessFlow ? preprocessFlows[0].name : undefined,
|
|
66
|
+
externalCustomerIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerIdField),
|
|
67
|
+
externalCustomerUserIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerUserIdField),
|
|
68
|
+
flowNameField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.flowNameField),
|
|
69
|
+
flows: flows.map((flow) => convertFlow(flow, referenceKey)),
|
|
70
|
+
configPages: convertConfigPages(configPages !== null && configPages !== void 0 ? configPages : {}),
|
|
71
|
+
};
|
|
72
|
+
return yaml_1.default.stringify(result);
|
|
73
|
+
};
|
|
74
|
+
/** Converts a Flow into the structure necessary for YAML generation. */
|
|
75
|
+
const convertFlow = (flow, referenceKey) => {
|
|
76
|
+
const result = Object.assign({}, flow);
|
|
77
|
+
delete result.onTrigger;
|
|
78
|
+
delete result.trigger;
|
|
79
|
+
delete result.onInstanceDeploy;
|
|
80
|
+
delete result.onInstanceDelete;
|
|
81
|
+
delete result.onExecution;
|
|
82
|
+
delete result.preprocessFlowConfig;
|
|
83
|
+
delete result.errorConfig;
|
|
84
|
+
const triggerStep = {
|
|
85
|
+
name: "On Trigger",
|
|
86
|
+
stableKey: `${flow.stableKey}-onTrigger`,
|
|
87
|
+
description: "The function that will be executed by the flow to return an HTTP response.",
|
|
88
|
+
isTrigger: true,
|
|
89
|
+
errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
|
|
90
|
+
action: {
|
|
91
|
+
key: flowFunctionKey(flow.name, "onTrigger"),
|
|
92
|
+
component: { key: referenceKey, version: "LATEST", isPublic: false },
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
if ("schedule" in flow && typeof flow.schedule === "object") {
|
|
96
|
+
triggerStep.schedule = {
|
|
97
|
+
type: "cronExpression" in flow.schedule ? "value" : "configVar",
|
|
98
|
+
value: "cronExpression" in flow.schedule
|
|
99
|
+
? flow.schedule.cronExpression
|
|
100
|
+
: flow.schedule.configVarKey,
|
|
101
|
+
meta: {
|
|
102
|
+
scheduleType: types_1.ScheduleType.Custom,
|
|
103
|
+
timeZone: flow.schedule.timeZone,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
delete result.schedule;
|
|
107
|
+
}
|
|
108
|
+
const actionStep = {
|
|
109
|
+
action: {
|
|
110
|
+
key: flowFunctionKey(flow.name, "onExecution"),
|
|
111
|
+
component: { key: referenceKey, version: "LATEST", isPublic: false },
|
|
112
|
+
},
|
|
113
|
+
name: "On Execution",
|
|
114
|
+
stableKey: `${flow.stableKey}-onExecution`,
|
|
115
|
+
description: "The function that will be executed by the flow.",
|
|
116
|
+
errorConfig: "errorConfig" in flow ? Object.assign({}, flow.errorConfig) : undefined,
|
|
117
|
+
};
|
|
118
|
+
result.steps = [triggerStep, actionStep];
|
|
119
|
+
return result;
|
|
120
|
+
};
|
|
121
|
+
/** Converts a Config Var into the structure necessary for YAML generation. */
|
|
122
|
+
const convertConfigVar = (key, configVar, referenceKey) => {
|
|
123
|
+
const meta = (0, lodash_1.pick)(configVar, [
|
|
124
|
+
"visibleToCustomerDeployer",
|
|
125
|
+
"visibleToOrgDeployer",
|
|
126
|
+
]);
|
|
127
|
+
if ((0, types_1.isConnectionConfigVar)(configVar)) {
|
|
128
|
+
return Object.assign(Object.assign({}, (0, lodash_1.pick)(configVar, ["stableKey", "description", "orgOnly"])), { key, dataType: "connection", connection: {
|
|
129
|
+
component: { key: referenceKey, version: "LATEST", isPublic: false },
|
|
130
|
+
key: (0, lodash_1.camelCase)(key),
|
|
131
|
+
}, inputs: Object.entries(configVar.inputs).reduce((result, [key, input]) => {
|
|
132
|
+
if (!input.shown || !input.default) {
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
return Object.assign(Object.assign({}, result), { [key]: { type: "value", value: input.default } });
|
|
136
|
+
}, {}), meta });
|
|
137
|
+
}
|
|
138
|
+
const result = (0, lodash_1.assign)({ meta, key }, (0, lodash_1.pick)(configVar, [
|
|
139
|
+
"stableKey",
|
|
140
|
+
"description",
|
|
141
|
+
"orgOnly",
|
|
142
|
+
"defaultValue",
|
|
143
|
+
"dataType",
|
|
144
|
+
"pickList",
|
|
145
|
+
"scheduleType",
|
|
146
|
+
"timeZone",
|
|
147
|
+
"codeLanguage",
|
|
148
|
+
"collectionType",
|
|
149
|
+
]));
|
|
150
|
+
// Handle data sources.
|
|
151
|
+
if ((0, types_1.isDataSourceConfigVar)(configVar)) {
|
|
152
|
+
result.dataType = configVar.dataSourceType;
|
|
153
|
+
result.dataSource = {
|
|
154
|
+
key: (0, lodash_1.camelCase)(key),
|
|
155
|
+
component: { key: referenceKey, version: "LATEST", isPublic: false },
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
};
|
|
160
|
+
/** Maps the step name field to a fully qualified input. */
|
|
161
|
+
const fieldNameToReferenceInput = (stepName, fieldName) => fieldName
|
|
162
|
+
? { type: "reference", value: `${stepName}.results.${fieldName}` }
|
|
163
|
+
: undefined;
|
|
164
|
+
/** Actions and Triggers will be scoped to their flow by combining the flow
|
|
165
|
+
* name and the function name. This is to ensure that the keys are unique
|
|
166
|
+
* on the resulting object, which will be turned into a Component. */
|
|
167
|
+
const flowFunctionKey = (flowName, functionName) => {
|
|
168
|
+
const flowKey = flowName
|
|
169
|
+
.replace(/[^0-9a-zA-Z]+/g, " ")
|
|
170
|
+
.trim()
|
|
171
|
+
.split(" ")
|
|
172
|
+
.map((w, i) => i === 0
|
|
173
|
+
? w.toLowerCase()
|
|
174
|
+
: w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
|
|
175
|
+
.join("");
|
|
176
|
+
return `${flowKey}_${functionName}`;
|
|
177
|
+
};
|
|
178
|
+
/** Creates the structure necessary to import a Component as part of a
|
|
179
|
+
* Code Native integration. */
|
|
180
|
+
const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [], }, referenceKey, configVars) => {
|
|
181
|
+
const convertedActions = flows.reduce((result, { name, onExecution }) => {
|
|
182
|
+
const key = flowFunctionKey(name, "onExecution");
|
|
183
|
+
return Object.assign(Object.assign({}, result), { [key]: {
|
|
184
|
+
key,
|
|
185
|
+
display: {
|
|
186
|
+
label: `${name} - onExecution`,
|
|
187
|
+
description: "The function that will be executed by the flow.",
|
|
188
|
+
},
|
|
189
|
+
perform: onExecution,
|
|
190
|
+
inputs: [],
|
|
191
|
+
} });
|
|
192
|
+
}, {});
|
|
193
|
+
const convertedTriggers = flows.reduce((result, { name, onTrigger, onInstanceDeploy, onInstanceDelete }) => {
|
|
194
|
+
const key = flowFunctionKey(name, "onTrigger");
|
|
195
|
+
return Object.assign(Object.assign({}, result), { [key]: {
|
|
196
|
+
key,
|
|
197
|
+
display: {
|
|
198
|
+
label: `${name} - onTrigger`,
|
|
199
|
+
description: "The function that will be executed by the flow to return an HTTP response.",
|
|
200
|
+
},
|
|
201
|
+
perform: onTrigger,
|
|
202
|
+
onInstanceDeploy: onInstanceDeploy,
|
|
203
|
+
onInstanceDelete: onInstanceDelete,
|
|
204
|
+
inputs: [],
|
|
205
|
+
scheduleSupport: "valid",
|
|
206
|
+
synchronousResponseSupport: "valid",
|
|
207
|
+
} });
|
|
208
|
+
}, {});
|
|
209
|
+
const convertedDataSources = Object.entries(configVars).reduce((result, [key, configVar]) => {
|
|
210
|
+
if (!(0, types_1.isDataSourceConfigVar)(configVar)) {
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
const dataSource = (0, lodash_1.pick)(configVar, ["perform", "dataSourceType"]);
|
|
214
|
+
return Object.assign(Object.assign({}, result), { [key]: Object.assign(Object.assign({}, dataSource), { key: (0, lodash_1.camelCase)(key), display: {
|
|
215
|
+
label: key,
|
|
216
|
+
description: key,
|
|
217
|
+
}, inputs: [] }) });
|
|
218
|
+
}, {});
|
|
219
|
+
const convertedConnections = Object.entries(configVars).reduce((result, [key, configVar]) => {
|
|
220
|
+
if (!(0, types_1.isConnectionConfigVar)(configVar)) {
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
const convertedInputs = Object.entries(configVar.inputs).map(([key, value]) => (0, convert_1.convertInput)(key, value));
|
|
224
|
+
const connection = (0, lodash_1.pick)(configVar, ["oauth2Type", "iconPath"]);
|
|
225
|
+
return [
|
|
226
|
+
...result,
|
|
227
|
+
Object.assign(Object.assign({}, connection), { inputs: convertedInputs, key: (0, lodash_1.camelCase)(key), label: key }),
|
|
228
|
+
];
|
|
229
|
+
}, []);
|
|
230
|
+
return {
|
|
231
|
+
key: referenceKey,
|
|
232
|
+
display: {
|
|
233
|
+
label: referenceKey,
|
|
234
|
+
iconPath,
|
|
235
|
+
description: description || name,
|
|
236
|
+
},
|
|
237
|
+
connections: convertedConnections,
|
|
238
|
+
actions: convertedActions,
|
|
239
|
+
triggers: convertedTriggers,
|
|
240
|
+
dataSources: convertedDataSources,
|
|
241
|
+
};
|
|
242
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { InstanceAttributes, CustomerAttributes, DataSourceType, DataSourceResultType, UserAttributes, TriggerEventFunctionReturn, IntegrationAttributes, FlowAttributes } from "../types";
|
|
2
|
+
import { InstanceAttributes, CustomerAttributes, DataSourceType, DataSourceResultType, UserAttributes, TriggerEventFunctionReturn, IntegrationAttributes, FlowAttributes, ConfigVarResultCollection } from "../types";
|
|
3
3
|
interface DisplayDefinition {
|
|
4
4
|
label: string;
|
|
5
5
|
description: string;
|
|
@@ -48,13 +48,13 @@ export interface ActionLogger {
|
|
|
48
48
|
warn: ActionLoggerFunction;
|
|
49
49
|
error: ActionLoggerFunction;
|
|
50
50
|
}
|
|
51
|
-
export
|
|
51
|
+
export declare type ActionContext<TConfigVars extends ConfigVarResultCollection> = {
|
|
52
52
|
logger: ActionLogger;
|
|
53
|
-
configVars?: Record<string, unknown>;
|
|
54
53
|
instanceState: Record<string, unknown>;
|
|
55
54
|
crossFlowState: Record<string, unknown>;
|
|
56
55
|
executionState: Record<string, unknown>;
|
|
57
56
|
integrationState: Record<string, unknown>;
|
|
57
|
+
configVars: TConfigVars;
|
|
58
58
|
stepId: string;
|
|
59
59
|
executionId: string;
|
|
60
60
|
webhookUrls: Record<string, string>;
|
|
@@ -66,7 +66,7 @@ export interface ActionContext {
|
|
|
66
66
|
integration: IntegrationAttributes;
|
|
67
67
|
flow: FlowAttributes;
|
|
68
68
|
startedAt: string;
|
|
69
|
-
}
|
|
69
|
+
};
|
|
70
70
|
declare type TriggerOptionChoice = "invalid" | "valid" | "required";
|
|
71
71
|
export interface TriggerPayload {
|
|
72
72
|
headers: Record<string, string>;
|
|
@@ -111,9 +111,9 @@ interface TriggerBranchingResult extends TriggerBaseResult {
|
|
|
111
111
|
branch: string;
|
|
112
112
|
}
|
|
113
113
|
export declare type TriggerResult = TriggerBranchingResult | TriggerBaseResult | undefined;
|
|
114
|
-
export declare type TriggerPerformFunction = (context: ActionContext
|
|
114
|
+
export declare type TriggerPerformFunction = (context: ActionContext<any>, payload: TriggerPayload, params: Record<string, unknown>) => Promise<TriggerResult>;
|
|
115
115
|
export declare type TriggerEventFunctionResult = TriggerEventFunctionReturn | void;
|
|
116
|
-
export declare type TriggerEventFunction = (context: ActionContext
|
|
116
|
+
export declare type TriggerEventFunction = (context: ActionContext<any>, params: Record<string, unknown>) => Promise<TriggerEventFunctionResult>;
|
|
117
117
|
export interface Trigger {
|
|
118
118
|
key: string;
|
|
119
119
|
display: DisplayDefinition & {
|
|
@@ -136,8 +136,9 @@ export interface Trigger {
|
|
|
136
136
|
examplePayload?: unknown;
|
|
137
137
|
isCommonTrigger?: boolean;
|
|
138
138
|
}
|
|
139
|
-
export interface DataSourceContext {
|
|
139
|
+
export interface DataSourceContext<TConfigVars extends ConfigVarResultCollection> {
|
|
140
140
|
logger: ActionLogger;
|
|
141
|
+
configVars: TConfigVars;
|
|
141
142
|
customer: CustomerAttributes;
|
|
142
143
|
instance: InstanceAttributes;
|
|
143
144
|
user: UserAttributes;
|
|
@@ -149,7 +150,7 @@ export declare type DataSourceResult = {
|
|
|
149
150
|
contentType: string;
|
|
150
151
|
};
|
|
151
152
|
};
|
|
152
|
-
export declare type DataSourcePerformFunction = (context: DataSourceContext
|
|
153
|
+
export declare type DataSourcePerformFunction = (context: DataSourceContext<any>, params: Record<string, unknown>) => Promise<DataSourceResult>;
|
|
153
154
|
export interface DataSource {
|
|
154
155
|
key: string;
|
|
155
156
|
display: DisplayDefinition & {
|
|
@@ -213,7 +214,7 @@ interface ServerPerformBranchingDataReturn extends ServerPerformDataReturn {
|
|
|
213
214
|
branch: string;
|
|
214
215
|
}
|
|
215
216
|
export declare type ActionPerformReturn = ServerPerformDataStructureReturn | ServerPerformBranchingDataStructureReturn | ServerPerformDataReturn | ServerPerformBranchingDataReturn | undefined;
|
|
216
|
-
export declare type ActionPerformFunction = (context: ActionContext
|
|
217
|
+
export declare type ActionPerformFunction = (context: ActionContext<any>, params: Record<string, unknown>) => Promise<ActionPerformReturn>;
|
|
217
218
|
interface InputFieldChoice {
|
|
218
219
|
label: string;
|
|
219
220
|
value: string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare const DefinitionVersion = 7;
|
|
2
|
+
export interface ComponentReference {
|
|
3
|
+
key: string;
|
|
4
|
+
version: number | "LATEST";
|
|
5
|
+
isPublic: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare type Input = {
|
|
8
|
+
name?: string;
|
|
9
|
+
type: "value" | "reference" | "configVar" | "template";
|
|
10
|
+
value: string;
|
|
11
|
+
meta?: Record<string, unknown>;
|
|
12
|
+
} | {
|
|
13
|
+
name?: string;
|
|
14
|
+
type: "complex";
|
|
15
|
+
value: string | Input;
|
|
16
|
+
meta?: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
export interface ConnectionRequiredConfigVariable {
|
|
19
|
+
key: string;
|
|
20
|
+
stableKey: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
orgOnly?: boolean;
|
|
23
|
+
dataType: "connection";
|
|
24
|
+
connection: {
|
|
25
|
+
component: ComponentReference;
|
|
26
|
+
key: string;
|
|
27
|
+
};
|
|
28
|
+
inputs?: Record<string, Input>;
|
|
29
|
+
meta?: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
export interface DefaultRequiredConfigVariable {
|
|
32
|
+
key: string;
|
|
33
|
+
stableKey: string;
|
|
34
|
+
defaultValue?: string;
|
|
35
|
+
dataType: "string" | "date" | "timestamp" | "picklist" | "schedule" | "code" | "boolean" | "number" | "objectSelection" | "objectFieldMap" | "jsonForm";
|
|
36
|
+
pickList?: string[];
|
|
37
|
+
scheduleType?: "none" | "custom" | "minute" | "hour" | "day" | "week";
|
|
38
|
+
timeZone?: string;
|
|
39
|
+
codeLanguage?: "json" | "xml" | "html";
|
|
40
|
+
description?: string;
|
|
41
|
+
orgOnly?: boolean;
|
|
42
|
+
collectionType?: "valuelist" | "keyvaluelist";
|
|
43
|
+
dataSource?: {
|
|
44
|
+
component: ComponentReference;
|
|
45
|
+
key: string;
|
|
46
|
+
};
|
|
47
|
+
inputs?: Record<string, Input>;
|
|
48
|
+
meta?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
export declare type RequiredConfigVariable = DefaultRequiredConfigVariable | ConnectionRequiredConfigVariable;
|
|
51
|
+
export interface ConfigPage {
|
|
52
|
+
name: string;
|
|
53
|
+
tagline?: string;
|
|
54
|
+
userLevelConfigured?: boolean;
|
|
55
|
+
elements: ConfigPageElement[];
|
|
56
|
+
}
|
|
57
|
+
export interface ConfigPageElement {
|
|
58
|
+
type: "configVar" | "htmlElement" | "jsonForm";
|
|
59
|
+
value: string;
|
|
60
|
+
}
|
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 } from "./types";
|
|
8
|
+
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow, ConfigVarResultCollection, ConfigPages } 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.
|
|
@@ -25,7 +25,7 @@ interface InvokeReturn<ReturnData> {
|
|
|
25
25
|
* to avoid extra casting within test methods. Returns an InvokeResult containing both the
|
|
26
26
|
* action result and a mock logger for asserting logging.
|
|
27
27
|
*/
|
|
28
|
-
export declare const invoke: <TInputs extends Inputs, TAllowsBranching extends boolean, TReturn extends InvokeActionPerformReturn<TAllowsBranching, unknown>>({ perform }: ActionDefinition<TInputs, TAllowsBranching, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext
|
|
28
|
+
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>>;
|
|
29
29
|
export declare const defaultTriggerPayload: () => TriggerPayload;
|
|
30
30
|
/**
|
|
31
31
|
* Invokes specified TriggerDefinition perform function using supplied params
|
|
@@ -33,13 +33,13 @@ export declare const defaultTriggerPayload: () => TriggerPayload;
|
|
|
33
33
|
* to avoid extra casting within test methods. Returns an InvokeResult containing both the
|
|
34
34
|
* trigger result and a mock logger for asserting logging.
|
|
35
35
|
*/
|
|
36
|
-
export declare const invokeTrigger: <TInputs extends Inputs, TAllowsBranching extends boolean, TResult extends InvokeTriggerResult<TAllowsBranching>>({ perform }: TriggerDefinition<TInputs, TAllowsBranching, TResult>, context?: Partial<ActionContext
|
|
36
|
+
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>>;
|
|
37
37
|
/**
|
|
38
38
|
* Invokes specified DataSourceDefinition perform function using supplied params.
|
|
39
39
|
* Accepts a generic type matching DataSourceResult as a convenience to avoid extra
|
|
40
40
|
* casting within test methods. Returns a DataSourceResult.
|
|
41
41
|
*/
|
|
42
|
-
export declare const invokeDataSource: <TInputs extends Inputs, TDataSourceType extends keyof {
|
|
42
|
+
export declare const invokeDataSource: <TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TDataSourceType extends keyof {
|
|
43
43
|
string: string;
|
|
44
44
|
date: string;
|
|
45
45
|
timestamp: string;
|
|
@@ -48,38 +48,40 @@ export declare const invokeDataSource: <TInputs extends Inputs, TDataSourceType
|
|
|
48
48
|
value: string;
|
|
49
49
|
};
|
|
50
50
|
code: string;
|
|
51
|
-
credential: unknown;
|
|
52
51
|
boolean: boolean;
|
|
53
52
|
number: number;
|
|
54
|
-
connection: import("./types").Connection;
|
|
55
53
|
objectSelection: import("./types").ObjectSelection;
|
|
56
54
|
objectFieldMap: import("./types").ObjectFieldMap;
|
|
57
55
|
jsonForm: import("./types").JSONForm;
|
|
58
|
-
}>({ perform }: DataSourceDefinition<TInputs, TDataSourceType>, params: ActionInputParameters<TInputs>, context?: Partial<DataSourceContext
|
|
56
|
+
}>({ perform }: DataSourceDefinition<TInputs, TConfigVars, TDataSourceType>, params: ActionInputParameters<TInputs>, context?: Partial<DataSourceContext<TConfigVars>> | undefined) => Promise<InvokeDataSourceResult<TDataSourceType>>;
|
|
57
|
+
declare type TestConnectionValue = Pick<ConnectionValue, "fields" | "context" | "token">;
|
|
58
|
+
declare type TestConfigVarValues = Record<string, string | TestConnectionValue>;
|
|
59
|
+
declare type ToTestValues<TConfigVars extends ConfigVarResultCollection> = {
|
|
60
|
+
[K in keyof TConfigVars]: TConfigVars[K] extends ConnectionDefinition ? TestConnectionValue : string;
|
|
61
|
+
};
|
|
59
62
|
/**
|
|
60
63
|
* Invokes specified Flow of a Code Native Integration using supplied params.
|
|
61
64
|
* Runs the Trigger and then the Action function and returns the result of the Action.
|
|
62
65
|
*/
|
|
63
|
-
export declare const invokeFlow: (flow: Flow, context?: Partial<ActionContext
|
|
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>>>;
|
|
64
67
|
export declare class ComponentTestHarness<TComponent extends Component> {
|
|
65
68
|
component: TComponent;
|
|
66
69
|
constructor(component: TComponent);
|
|
67
|
-
private buildContext;
|
|
68
70
|
private buildParams;
|
|
69
71
|
connectionValue({ key }: ConnectionDefinition): ConnectionValue;
|
|
70
|
-
trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext
|
|
71
|
-
triggerOnInstanceDeploy(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext
|
|
72
|
-
triggerOnInstanceDelete(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext
|
|
73
|
-
action(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext
|
|
74
|
-
dataSource(key: string, params?: Record<string, unknown>, context?: Partial<DataSourceContext
|
|
72
|
+
trigger<TConfigVars extends ConfigVarResultCollection>(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<TriggerResult>;
|
|
73
|
+
triggerOnInstanceDeploy<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<void | TriggerEventFunctionReturn>;
|
|
74
|
+
triggerOnInstanceDelete<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<void | TriggerEventFunctionReturn>;
|
|
75
|
+
action<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<ActionPerformReturn>;
|
|
76
|
+
dataSource<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<DataSourceContext<TConfigVars>>): Promise<DataSourceResult>;
|
|
75
77
|
}
|
|
76
78
|
export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
|
|
77
79
|
declare const _default: {
|
|
78
80
|
loggerMock: () => ActionLogger;
|
|
79
|
-
invoke: <TInputs extends Inputs, TAllowsBranching extends boolean, TReturn extends InvokeActionPerformReturn<TAllowsBranching, unknown>>({ perform }: ActionDefinition<TInputs, TAllowsBranching, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext
|
|
80
|
-
invokeTrigger: <TInputs_1 extends Inputs, TAllowsBranching_1 extends boolean, TResult extends InvokeTriggerResult<TAllowsBranching_1>>({ perform }: TriggerDefinition<TInputs_1, TAllowsBranching_1, TResult>, context?: Partial<ActionContext
|
|
81
|
+
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>>;
|
|
82
|
+
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>>;
|
|
81
83
|
createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
|
|
82
|
-
invokeDataSource: <TInputs_2 extends Inputs, TDataSourceType extends keyof {
|
|
84
|
+
invokeDataSource: <TInputs_2 extends Inputs, TConfigVars_2 extends ConfigVarResultCollection, TDataSourceType extends keyof {
|
|
83
85
|
string: string;
|
|
84
86
|
date: string;
|
|
85
87
|
timestamp: string;
|
|
@@ -88,13 +90,11 @@ declare const _default: {
|
|
|
88
90
|
value: string;
|
|
89
91
|
};
|
|
90
92
|
code: string;
|
|
91
|
-
credential: unknown;
|
|
92
93
|
boolean: boolean;
|
|
93
94
|
number: number;
|
|
94
|
-
connection: import("./types").Connection;
|
|
95
95
|
objectSelection: import("./types").ObjectSelection;
|
|
96
96
|
objectFieldMap: import("./types").ObjectFieldMap;
|
|
97
97
|
jsonForm: import("./types").JSONForm;
|
|
98
|
-
}>({ perform }: DataSourceDefinition<TInputs_2, TDataSourceType>, params: ActionInputParameters<TInputs_2>, context?: Partial<DataSourceContext
|
|
98
|
+
}>({ perform }: DataSourceDefinition<TInputs_2, TConfigVars_2, TDataSourceType>, params: ActionInputParameters<TInputs_2>, context?: Partial<DataSourceContext<TConfigVars_2>> | undefined) => Promise<InvokeDataSourceResult<TDataSourceType>>;
|
|
99
99
|
};
|
|
100
100
|
export default _default;
|