@prismatic-io/spectral 10.4.1 → 10.4.3-alpha.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.
|
@@ -6,5 +6,15 @@ export declare const validate: (expression: ConditionalExpression) => Validation
|
|
|
6
6
|
export declare const parseValue: (value: unknown) => any;
|
|
7
7
|
export declare const contains: (container: unknown, containee: unknown) => boolean;
|
|
8
8
|
export declare const parseDate: (value: unknown) => Date;
|
|
9
|
+
export declare const isEqual: (left: unknown, right: unknown) => boolean;
|
|
10
|
+
export declare const isDeepEqual: (left: unknown, right: unknown) => boolean;
|
|
11
|
+
export declare const evaluatesTrue: (value: string | boolean) => boolean;
|
|
12
|
+
export declare const evaluatesFalse: (value: string | boolean) => boolean;
|
|
13
|
+
export declare const evaluatesNull: (value: unknown) => boolean;
|
|
14
|
+
export declare const evaluatesEmpty: (value: string | Array<unknown>) => boolean;
|
|
15
|
+
export declare const evaluatesNotEmpty: (value: string | Array<unknown>) => boolean;
|
|
16
|
+
export declare const dateIsAfter: (left: unknown, right: unknown) => boolean;
|
|
17
|
+
export declare const dateIsBefore: (left: unknown, right: unknown) => boolean;
|
|
18
|
+
export declare const dateIsEqual: (left: unknown, right: unknown) => boolean;
|
|
9
19
|
export declare const evaluate: (expression: ConditionalExpression) => boolean;
|
|
10
20
|
export * from "./types";
|
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.evaluate = exports.parseDate = exports.contains = exports.parseValue = exports.validate = void 0;
|
|
20
|
+
exports.evaluate = exports.dateIsEqual = exports.dateIsBefore = exports.dateIsAfter = exports.evaluatesNotEmpty = exports.evaluatesEmpty = exports.evaluatesNull = exports.evaluatesFalse = exports.evaluatesTrue = exports.isDeepEqual = exports.isEqual = exports.parseDate = exports.contains = exports.parseValue = exports.validate = void 0;
|
|
21
21
|
const types_1 = require("./types");
|
|
22
22
|
const date_fns_1 = require("date-fns");
|
|
23
23
|
const isEqualWith_1 = __importDefault(require("lodash/isEqualWith"));
|
|
@@ -110,6 +110,56 @@ const isEqual = (left, right) => left == right ||
|
|
|
110
110
|
}
|
|
111
111
|
return objectA == objectB;
|
|
112
112
|
});
|
|
113
|
+
exports.isEqual = isEqual;
|
|
114
|
+
const isDeepEqual = (left, right) => {
|
|
115
|
+
return (0, isEqual_1.default)(left, right);
|
|
116
|
+
};
|
|
117
|
+
exports.isDeepEqual = isDeepEqual;
|
|
118
|
+
const evaluatesTrue = (value) => {
|
|
119
|
+
return typeof value === "string" ? ["t", "true", "y", "yes"].includes(value) : value;
|
|
120
|
+
};
|
|
121
|
+
exports.evaluatesTrue = evaluatesTrue;
|
|
122
|
+
const evaluatesFalse = (value) => {
|
|
123
|
+
return typeof value === "string" ? ["f", "false", "n", "no"].includes(value) : value;
|
|
124
|
+
};
|
|
125
|
+
exports.evaluatesFalse = evaluatesFalse;
|
|
126
|
+
const evaluatesNull = (value) => {
|
|
127
|
+
const nullValues = [undefined, null, 0, Number.NaN, false, ""];
|
|
128
|
+
return nullValues.includes(value);
|
|
129
|
+
};
|
|
130
|
+
exports.evaluatesNull = evaluatesNull;
|
|
131
|
+
const evaluatesEmpty = (value) => {
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
return value.length === 0;
|
|
134
|
+
}
|
|
135
|
+
if (typeof value === "string") {
|
|
136
|
+
return value.length === 0;
|
|
137
|
+
}
|
|
138
|
+
throw new Error("Please provide an array or string");
|
|
139
|
+
};
|
|
140
|
+
exports.evaluatesEmpty = evaluatesEmpty;
|
|
141
|
+
const evaluatesNotEmpty = (value) => {
|
|
142
|
+
if (Array.isArray(value)) {
|
|
143
|
+
return value.length > 0;
|
|
144
|
+
}
|
|
145
|
+
if (typeof value === "string") {
|
|
146
|
+
return value.length > 0;
|
|
147
|
+
}
|
|
148
|
+
throw new Error("Please provide an array or string");
|
|
149
|
+
};
|
|
150
|
+
exports.evaluatesNotEmpty = evaluatesNotEmpty;
|
|
151
|
+
const dateIsAfter = (left, right) => {
|
|
152
|
+
return (0, date_fns_1.isAfter)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
153
|
+
};
|
|
154
|
+
exports.dateIsAfter = dateIsAfter;
|
|
155
|
+
const dateIsBefore = (left, right) => {
|
|
156
|
+
return (0, date_fns_1.isBefore)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
157
|
+
};
|
|
158
|
+
exports.dateIsBefore = dateIsBefore;
|
|
159
|
+
const dateIsEqual = (left, right) => {
|
|
160
|
+
return (0, date_fns_1.isEqual)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
161
|
+
};
|
|
162
|
+
exports.dateIsEqual = dateIsEqual;
|
|
113
163
|
const evaluate = (expression) => {
|
|
114
164
|
const [valid, message] = (0, exports.validate)(expression);
|
|
115
165
|
if (!valid) {
|
|
@@ -144,10 +194,10 @@ const evaluate = (expression) => {
|
|
|
144
194
|
case types_1.UnaryOperator.isTrue:
|
|
145
195
|
if (typeof left === "string") {
|
|
146
196
|
const lowerValue = left.toLowerCase();
|
|
147
|
-
if (
|
|
197
|
+
if ((0, exports.evaluatesTrue)(lowerValue)) {
|
|
148
198
|
return true;
|
|
149
199
|
}
|
|
150
|
-
else if (
|
|
200
|
+
else if ((0, exports.evaluatesFalse)(lowerValue)) {
|
|
151
201
|
return false;
|
|
152
202
|
}
|
|
153
203
|
}
|
|
@@ -155,25 +205,25 @@ const evaluate = (expression) => {
|
|
|
155
205
|
case types_1.UnaryOperator.isFalse:
|
|
156
206
|
if (typeof left === "string") {
|
|
157
207
|
const lowerValue = left.toLowerCase();
|
|
158
|
-
if (
|
|
208
|
+
if ((0, exports.evaluatesTrue)(lowerValue)) {
|
|
159
209
|
return false;
|
|
160
210
|
}
|
|
161
|
-
else if (
|
|
211
|
+
else if ((0, exports.evaluatesFalse)(lowerValue)) {
|
|
162
212
|
return true;
|
|
163
213
|
}
|
|
164
214
|
}
|
|
165
215
|
return !left;
|
|
166
216
|
case types_1.UnaryOperator.doesNotExist:
|
|
167
|
-
return
|
|
217
|
+
return (0, exports.evaluatesNull)(left);
|
|
168
218
|
case types_1.UnaryOperator.exists:
|
|
169
|
-
return !
|
|
219
|
+
return !(0, exports.evaluatesNull)(left);
|
|
170
220
|
case types_1.UnaryOperator.isEmpty:
|
|
171
221
|
if (Array.isArray(left)) {
|
|
172
|
-
return left
|
|
222
|
+
return (0, exports.evaluatesEmpty)(left);
|
|
173
223
|
}
|
|
174
224
|
// leftTerm is used here, since "123" would be cast to 123 and would not be a string
|
|
175
225
|
if (typeof leftTerm === "string") {
|
|
176
|
-
return leftTerm
|
|
226
|
+
return (0, exports.evaluatesEmpty)(leftTerm);
|
|
177
227
|
}
|
|
178
228
|
throw new Error("Please provide an array or string");
|
|
179
229
|
case types_1.UnaryOperator.isNotEmpty:
|
|
@@ -211,9 +261,9 @@ const evaluate = (expression) => {
|
|
|
211
261
|
try {
|
|
212
262
|
switch (operator) {
|
|
213
263
|
case types_1.BinaryOperator.equal:
|
|
214
|
-
return isEqual(left, right);
|
|
264
|
+
return (0, exports.isEqual)(left, right);
|
|
215
265
|
case types_1.BinaryOperator.notEqual:
|
|
216
|
-
return !isEqual(left, right);
|
|
266
|
+
return !(0, exports.isEqual)(left, right);
|
|
217
267
|
case types_1.BinaryOperator.greaterThan:
|
|
218
268
|
return left > right;
|
|
219
269
|
case types_1.BinaryOperator.greaterThanOrEqual:
|
|
@@ -227,9 +277,9 @@ const evaluate = (expression) => {
|
|
|
227
277
|
case types_1.BinaryOperator.notIn:
|
|
228
278
|
return !(0, exports.contains)(right, leftTerm);
|
|
229
279
|
case types_1.BinaryOperator.exactlyMatches:
|
|
230
|
-
return left === right || (0,
|
|
280
|
+
return left === right || (0, exports.isDeepEqual)(left, right);
|
|
231
281
|
case types_1.BinaryOperator.doesNotExactlyMatch:
|
|
232
|
-
return !(left === right || (0,
|
|
282
|
+
return !(left === right || (0, exports.isDeepEqual)(left, right));
|
|
233
283
|
case types_1.BinaryOperator.startsWith:
|
|
234
284
|
return `${right}`.startsWith(`${left}`);
|
|
235
285
|
case types_1.BinaryOperator.doesNotStartWith:
|
|
@@ -239,11 +289,11 @@ const evaluate = (expression) => {
|
|
|
239
289
|
case types_1.BinaryOperator.doesNotEndWith:
|
|
240
290
|
return !`${right}`.endsWith(`${left}`);
|
|
241
291
|
case types_1.BinaryOperator.dateTimeAfter:
|
|
242
|
-
return (0,
|
|
292
|
+
return (0, exports.dateIsAfter)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
243
293
|
case types_1.BinaryOperator.dateTimeBefore:
|
|
244
|
-
return (0,
|
|
294
|
+
return (0, exports.dateIsBefore)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
245
295
|
case types_1.BinaryOperator.dateTimeSame:
|
|
246
|
-
return (0,
|
|
296
|
+
return (0, exports.dateIsEqual)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
247
297
|
default:
|
|
248
298
|
throw new Error(`Invalid operator: '${operator}'`);
|
|
249
299
|
}
|
|
@@ -64,7 +64,7 @@ const convertConfigPages = (pages, userLevelConfigured) => {
|
|
|
64
64
|
value: key,
|
|
65
65
|
}) })));
|
|
66
66
|
};
|
|
67
|
-
const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, endpointType, triggerPreprocessFlowConfig, flows, configPages, userLevelConfigPages, scopedConfigVars, componentRegistry = {}, }, referenceKey, configVars) => {
|
|
67
|
+
const codeNativeIntegrationYaml = ({ name, description, category, documentation, version, labels, endpointType, triggerPreprocessFlowConfig, flows, configPages, userLevelConfigPages, scopedConfigVars, instanceProfile = "Default Instance Profile", componentRegistry = {}, }, referenceKey, configVars) => {
|
|
68
68
|
// Find the preprocess flow config on the flow, if one exists.
|
|
69
69
|
const preprocessFlows = flows.filter((flow) => flow.preprocessFlowConfig);
|
|
70
70
|
// Do some validation of preprocess flow configs.
|
|
@@ -108,6 +108,7 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
|
|
|
108
108
|
externalCustomerUserIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerUserIdField),
|
|
109
109
|
flowNameField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.flowNameField),
|
|
110
110
|
flows: flows.map((flow) => (0, exports.convertFlow)(flow, componentRegistry, referenceKey)),
|
|
111
|
+
defaultInstanceProfile: instanceProfile,
|
|
111
112
|
configPages: [
|
|
112
113
|
...convertConfigPages(configPages, false),
|
|
113
114
|
...convertConfigPages(userLevelConfigPages, true),
|
|
@@ -30,6 +30,10 @@ export type IntegrationDefinition = {
|
|
|
30
30
|
userLevelConfigPages?: UserLevelConfigPages;
|
|
31
31
|
/** Scoped ConfigVars for this Integration. */
|
|
32
32
|
scopedConfigVars?: ScopedConfigVarMap;
|
|
33
|
+
/** Instance Profile used for this integration.
|
|
34
|
+
* @default "Default Instance Profile"
|
|
35
|
+
*/
|
|
36
|
+
instanceProfile?: string;
|
|
33
37
|
componentRegistry?: ComponentRegistry;
|
|
34
38
|
};
|
|
35
39
|
export type FlowOnExecution<TTriggerPayload extends TriggerPayload> = ActionPerformFunction<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismatic-io/spectral",
|
|
3
|
-
"version": "10.4.
|
|
3
|
+
"version": "10.4.3-alpha.0",
|
|
4
4
|
"description": "Utility library for building Prismatic connectors and code-native integrations",
|
|
5
5
|
"keywords": ["prismatic"],
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"@types/jest": "29.5.12",
|
|
64
64
|
"@types/lodash": "4.17.0",
|
|
65
65
|
"@types/node": "14.14.35",
|
|
66
|
+
"@types/prettier": "2.6.2",
|
|
66
67
|
"@types/sax": "1.2.4",
|
|
67
68
|
"@types/url-join": "4.0.1",
|
|
68
69
|
"@types/uuid": "8.3.4",
|