@api3/commons 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/dist/eslint/jest.d.ts +1 -0
- package/dist/eslint/jest.js +1 -0
- package/dist/eslint/jest.js.map +1 -1
- package/dist/eslint/react.d.ts +0 -1
- package/dist/eslint/react.js +0 -1
- package/dist/eslint/react.js.map +1 -1
- package/dist/eslint/universal.d.ts +1 -5
- package/dist/eslint/universal.js +2 -19
- package/dist/eslint/universal.js.map +1 -1
- package/dist/processing/index.d.ts +4 -0
- package/dist/processing/index.d.ts.map +1 -0
- package/dist/processing/index.js +20 -0
- package/dist/processing/index.js.map +1 -0
- package/dist/processing/processing.d.ts +39 -0
- package/dist/processing/processing.d.ts.map +1 -0
- package/dist/processing/processing.js +122 -0
- package/dist/processing/processing.js.map +1 -0
- package/dist/processing/schema.d.ts +4 -0
- package/dist/processing/schema.d.ts.map +1 -0
- package/dist/processing/schema.js +6 -0
- package/dist/processing/schema.js.map +1 -0
- package/dist/processing/unsafe-evaluate.d.ts +50 -0
- package/dist/processing/unsafe-evaluate.d.ts.map +1 -0
- package/dist/processing/unsafe-evaluate.js +178 -0
- package/dist/processing/unsafe-evaluate.js.map +1 -0
- package/dist/processing/vm-timers.d.ts +21 -0
- package/dist/processing/vm-timers.d.ts.map +1 -0
- package/dist/processing/vm-timers.js +54 -0
- package/dist/processing/vm-timers.js.map +1 -0
- package/package.json +6 -4
- package/src/eslint/README.md +0 -5
- package/src/eslint/jest.js +1 -0
- package/src/eslint/react.js +0 -1
- package/src/eslint/universal.js +2 -20
- package/src/processing/README.md +49 -0
- package/src/processing/index.ts +3 -0
- package/src/processing/processing.test.ts +272 -0
- package/src/processing/processing.ts +160 -0
- package/src/processing/schema.ts +5 -0
- package/src/processing/unsafe-evaluate.test.ts +103 -0
- package/src/processing/unsafe-evaluate.ts +178 -0
- package/src/processing/vm-timers.ts +58 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/src/index.ts +0 -2
package/README.md
CHANGED
|
@@ -30,19 +30,28 @@ Read the documentation of each module how to use it in the project.
|
|
|
30
30
|
|
|
31
31
|
### Import paths
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
There are two options how to import the commons modules, depending on the module resolution:
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
|
-
|
|
37
|
-
// and not like this
|
|
36
|
+
// 1) Import relative to the "node_modules" directory.
|
|
38
37
|
import { createLogger } from '@api3/commons/dist/logger';
|
|
38
|
+
// 2) Cleaner imports based on the "exports" field in "package.json".
|
|
39
|
+
import { createLogger } from '@api3/commons/logger';
|
|
39
40
|
```
|
|
40
41
|
|
|
42
|
+
#### Import relative to the "node_modules"
|
|
43
|
+
|
|
44
|
+
This is the default CommonJS style and it applies if you have `moduleResolution` set to `Node` or `Node10` inside the
|
|
45
|
+
`tsconfig.json`.
|
|
46
|
+
|
|
47
|
+
#### The "exports" based import
|
|
48
|
+
|
|
41
49
|
This is done via `package.json` field called [exports](https://nodejs.org/api/packages.html#package-entry-points). This
|
|
42
50
|
field works for both CJS and ESM starting from Node version 12. In order for TS to support this, you need to make sure
|
|
43
|
-
you use `moduleResolution` and `module` set to `Node16
|
|
51
|
+
you use `moduleResolution` and `module` set to `Node16` inside `tsconfig.json`.
|
|
44
52
|
|
|
45
|
-
```
|
|
53
|
+
```jsonc
|
|
54
|
+
// tsconfig.json
|
|
46
55
|
{
|
|
47
56
|
"compilerOptions": {
|
|
48
57
|
"module": "Node16",
|
package/dist/eslint/jest.d.ts
CHANGED
package/dist/eslint/jest.js
CHANGED
package/dist/eslint/jest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.js","sourceRoot":"","sources":["../../src/eslint/jest.js"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG;IACf,MAAM,EAAE,2BAA2B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,kBAAkB,EAAE,KAAK;gBACzB,iCAAiC,EAAE,KAAK;gBACxC,kBAAkB,EAAE,KAAK;gBACzB,kBAAkB,EAAE,KAAK;gBACzB,eAAe,EAAE;oBACf,OAAO;oBACP;wBACE,KAAK,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC;qBACjC;iBACF;gBACD,wBAAwB,EAAE,KAAK,EAAE,yGAAyG;aAC3I;SACF;KACF;CACF,CAAC"}
|
package/dist/eslint/react.d.ts
CHANGED
package/dist/eslint/react.js
CHANGED
|
@@ -41,7 +41,6 @@ module.exports = {
|
|
|
41
41
|
'react/destructuring-assignment': ['error', 'always', { destructureInSignature: 'ignore' }],
|
|
42
42
|
'react/forbid-component-props': ['error', { forbid: [] }],
|
|
43
43
|
'react/forbid-dom-props': ['error', { forbid: [] }],
|
|
44
|
-
'react/function-component-definition': 'off',
|
|
45
44
|
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never', propElementValues: 'always' }],
|
|
46
45
|
'react/jsx-curly-newline': 'off',
|
|
47
46
|
'react/jsx-filename-extension': 'off',
|
package/dist/eslint/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/eslint/react.js"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEpC,8DAA8D;AAC9D,MAAM,EAAE,gCAAgC,EAAE,0BAA0B,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAE/F,MAAM,CAAC,OAAO,GAAG;IACf,MAAM,EAAE,2BAA2B;IACnC,aAAa,EAAE;QACb,WAAW,EAAE,IAAI;QACjB,YAAY,EAAE;YACZ,GAAG,EAAE,IAAI,EAAE,sBAAsB;SAClC;QACD,UAAU,EAAE,QAAQ,EAAE,mCAAmC;KAC1D;IACD,QAAQ,EAAE;QACR,KAAK,EAAE;YACL,OAAO,EAAE,QAAQ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AAK;QAC7B,qBAAqB,EAAE,KAAK;QAC5B,6BAA6B,EAAE,KAAK;QACpC,4BAA4B,EAAE,KAAK;QACnC,8BAA8B,EAAE,KAAK;QACrC,kBAAkB,EAAE,KAAK;QACzB,0BAA0B,EAAE,KAAK;QACjC,6BAA6B,EAAE,KAAK;QACpC,yBAAyB,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACrE,qCAAqC,EAAE,OAAO;QAE9C,+CAA+C;QAC/C,0CAA0C,EAAE;YAC1C,OAAO;YACP,KAAK,CAAC,EAAE,EAAE,gCAAgC,EAAE;gBAC1C,KAAK,EAAE;oBACL;wBACE,IAAI,EAAE,OAAO;wBACb,WAAW,EAAE,CAAC,SAAS,CAAC;wBACxB,OAAO,EACL,uHAAuH;qBAC1H;iBACF;aACF,CAAC;SACH;QAED,mCAAmC;QACnC,qBAAqB,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;KAC3C;CACF,CAAC"}
|
|
@@ -54,11 +54,6 @@ export declare let rules: {
|
|
|
54
54
|
markers: string[];
|
|
55
55
|
};
|
|
56
56
|
})[];
|
|
57
|
-
'prefer-arrow/prefer-arrow-functions': (string | {
|
|
58
|
-
disallowPrototype: boolean;
|
|
59
|
-
singleReturnOnly: boolean;
|
|
60
|
-
classPropertiesAllowed: boolean;
|
|
61
|
-
})[];
|
|
62
57
|
'check-file/folder-naming-convention': (string | {
|
|
63
58
|
'**/': string;
|
|
64
59
|
})[];
|
|
@@ -72,6 +67,7 @@ export declare let rules: {
|
|
|
72
67
|
'unicorn/no-array-reduce': string;
|
|
73
68
|
'unicorn/no-nested-ternary': string;
|
|
74
69
|
'unicorn/no-null': string;
|
|
70
|
+
'unicorn/no-object-as-default-parameter': string;
|
|
75
71
|
'unicorn/no-useless-undefined': (string | {
|
|
76
72
|
checkArguments: boolean;
|
|
77
73
|
})[];
|
package/dist/eslint/universal.js
CHANGED
|
@@ -20,16 +20,7 @@ module.exports = {
|
|
|
20
20
|
'plugin:promise/recommended',
|
|
21
21
|
'plugin:lodash/recommended',
|
|
22
22
|
],
|
|
23
|
-
plugins: [
|
|
24
|
-
'@typescript-eslint',
|
|
25
|
-
'deprecation',
|
|
26
|
-
'functional',
|
|
27
|
-
'prefer-arrow',
|
|
28
|
-
'unicorn',
|
|
29
|
-
'check-file',
|
|
30
|
-
'import',
|
|
31
|
-
'lodash',
|
|
32
|
-
],
|
|
23
|
+
plugins: ['@typescript-eslint', 'deprecation', 'functional', 'unicorn', 'check-file', 'import', 'lodash'],
|
|
33
24
|
rules: {
|
|
34
25
|
/* Rule definitions and overrides for standard ESLint rules */
|
|
35
26
|
camelcase: 'error',
|
|
@@ -77,15 +68,6 @@ module.exports = {
|
|
|
77
68
|
},
|
|
78
69
|
},
|
|
79
70
|
],
|
|
80
|
-
/* Rules to setup enforcement of arrow functions over regular functions */
|
|
81
|
-
'prefer-arrow/prefer-arrow-functions': [
|
|
82
|
-
'error',
|
|
83
|
-
{
|
|
84
|
-
disallowPrototype: true,
|
|
85
|
-
singleReturnOnly: false,
|
|
86
|
-
classPropertiesAllowed: false,
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
71
|
/* Rules to enforce kebab-case folder structure */
|
|
90
72
|
'check-file/folder-naming-convention': [
|
|
91
73
|
'error',
|
|
@@ -107,6 +89,7 @@ module.exports = {
|
|
|
107
89
|
'unicorn/no-array-reduce': 'off',
|
|
108
90
|
'unicorn/no-nested-ternary': 'off',
|
|
109
91
|
'unicorn/no-null': 'off',
|
|
92
|
+
'unicorn/no-object-as-default-parameter': 'off',
|
|
110
93
|
'unicorn/no-useless-undefined': ['error', { checkArguments: false }],
|
|
111
94
|
'unicorn/prefer-module': 'off',
|
|
112
95
|
'unicorn/prevent-abbreviations': 'off',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"universal.js","sourceRoot":"","sources":["../../src/eslint/universal.js"],"names":[],"mappings":";AAAA,8DAA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AE,CAAC,MAAM,CAAC;YACjB,OAAO,EAAE,CAAC,iBAAiB,EAAE,oCAAoC,CAAC;YAClE,KAAK,EAAE;gBACL,+BAA+B,EAAE,KAAK;gBACtC,kBAAkB,EAAE,KAAK;gBACzB,iCAAiC,EAAE,KAAK;gBACxC,kBAAkB,EAAE,KAAK;gBACzB,kBAAkB,EAAE,KAAK,EAAE,uDAAuD;aACnF;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/processing/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./processing"), exports);
|
|
18
|
+
__exportStar(require("./schema"), exports);
|
|
19
|
+
__exportStar(require("./unsafe-evaluate"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/processing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,2CAAyB;AACzB,oDAAkC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Endpoint } from '@api3/ois';
|
|
2
|
+
import { type GoAsyncOptions } from '@api3/promise-utils';
|
|
3
|
+
import { type ApiCallParameters } from './schema';
|
|
4
|
+
export declare const DEFAULT_PROCESSING_TIMEOUT_MS = 10000;
|
|
5
|
+
/**
|
|
6
|
+
* Removes reserved parameters from the parameters object.
|
|
7
|
+
* @param parameters The API call parameters from which reserved parameters will be removed.
|
|
8
|
+
* @returns The parameters object without reserved parameters.
|
|
9
|
+
*/
|
|
10
|
+
export declare const removeReservedParameters: (parameters: ApiCallParameters) => ApiCallParameters;
|
|
11
|
+
/**
|
|
12
|
+
* Re-inserts reserved parameters from the initial parameters object into the modified parameters object.
|
|
13
|
+
* @param initialParameters The initial API call parameters that might contain reserved parameters.
|
|
14
|
+
* @param modifiedParameters The modified API call parameters to which reserved parameters will be added.
|
|
15
|
+
* @returns The modified parameters object with re-inserted reserved parameters.
|
|
16
|
+
*/
|
|
17
|
+
export declare const addReservedParameters: (initialParameters: ApiCallParameters, modifiedParameters: ApiCallParameters) => ApiCallParameters;
|
|
18
|
+
/**
|
|
19
|
+
* Pre-processes API call parameters based on the provided endpoint's processing specifications.
|
|
20
|
+
*
|
|
21
|
+
* @param endpoint The endpoint containing processing specifications.
|
|
22
|
+
* @param apiCallParameters The parameters to be pre-processed.
|
|
23
|
+
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
|
|
24
|
+
*
|
|
25
|
+
* @returns A promise that resolves to the pre-processed parameters.
|
|
26
|
+
*/
|
|
27
|
+
export declare const preProcessApiCallParameters: (endpoint: Endpoint, apiCallParameters: ApiCallParameters, processingOptions?: GoAsyncOptions) => Promise<ApiCallParameters>;
|
|
28
|
+
/**
|
|
29
|
+
* Post-processes the API call response based on the provided endpoint's processing specifications.
|
|
30
|
+
*
|
|
31
|
+
* @param apiCallResponse The raw response obtained from the API call.
|
|
32
|
+
* @param endpoint The endpoint containing processing specifications.
|
|
33
|
+
* @param apiCallParameters The parameters used in the API call.
|
|
34
|
+
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
|
|
35
|
+
*
|
|
36
|
+
* @returns A promise that resolves to the post-processed API call response.
|
|
37
|
+
*/
|
|
38
|
+
export declare const postProcessApiCallResponse: (apiCallResponse: unknown, endpoint: Endpoint, apiCallParameters: ApiCallParameters, processingOptions?: GoAsyncOptions) => Promise<unknown>;
|
|
39
|
+
//# sourceMappingURL=processing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processing.d.ts","sourceRoot":"","sources":["../../src/processing/processing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAuB,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,KAAK,cAAc,EAAM,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAAE,KAAK,iBAAiB,EAA2B,MAAM,UAAU,CAAC;AAG3E,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAIpD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,eAAgB,iBAAiB,KAAG,iBAUxE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,sBACb,iBAAiB,sBAChB,iBAAiB,KACpC,iBAQF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,aAC5B,QAAQ,qBACC,iBAAiB,sBACjB,cAAc,KAChC,QAAQ,iBAAiB,CA4C3B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,oBACpB,OAAO,YACd,QAAQ,qBACC,iBAAiB,sBACjB,cAAc,qBAwClC,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postProcessApiCallResponse = exports.preProcessApiCallParameters = exports.addReservedParameters = exports.removeReservedParameters = exports.DEFAULT_PROCESSING_TIMEOUT_MS = void 0;
|
|
4
|
+
const ois_1 = require("@api3/ois");
|
|
5
|
+
const promise_utils_1 = require("@api3/promise-utils");
|
|
6
|
+
const schema_1 = require("./schema");
|
|
7
|
+
const unsafe_evaluate_1 = require("./unsafe-evaluate");
|
|
8
|
+
exports.DEFAULT_PROCESSING_TIMEOUT_MS = 10_000;
|
|
9
|
+
const reservedParameters = ois_1.RESERVED_PARAMETERS; // To avoid strict TS checks.
|
|
10
|
+
/**
|
|
11
|
+
* Removes reserved parameters from the parameters object.
|
|
12
|
+
* @param parameters The API call parameters from which reserved parameters will be removed.
|
|
13
|
+
* @returns The parameters object without reserved parameters.
|
|
14
|
+
*/
|
|
15
|
+
const removeReservedParameters = (parameters) => {
|
|
16
|
+
const result = {};
|
|
17
|
+
for (const key in parameters) {
|
|
18
|
+
if (!reservedParameters.includes(key)) {
|
|
19
|
+
result[key] = parameters[key];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
exports.removeReservedParameters = removeReservedParameters;
|
|
25
|
+
/**
|
|
26
|
+
* Re-inserts reserved parameters from the initial parameters object into the modified parameters object.
|
|
27
|
+
* @param initialParameters The initial API call parameters that might contain reserved parameters.
|
|
28
|
+
* @param modifiedParameters The modified API call parameters to which reserved parameters will be added.
|
|
29
|
+
* @returns The modified parameters object with re-inserted reserved parameters.
|
|
30
|
+
*/
|
|
31
|
+
const addReservedParameters = (initialParameters, modifiedParameters) => {
|
|
32
|
+
for (const key in initialParameters) {
|
|
33
|
+
if (reservedParameters.includes(key)) {
|
|
34
|
+
modifiedParameters[key] = initialParameters[key];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return modifiedParameters;
|
|
38
|
+
};
|
|
39
|
+
exports.addReservedParameters = addReservedParameters;
|
|
40
|
+
/**
|
|
41
|
+
* Pre-processes API call parameters based on the provided endpoint's processing specifications.
|
|
42
|
+
*
|
|
43
|
+
* @param endpoint The endpoint containing processing specifications.
|
|
44
|
+
* @param apiCallParameters The parameters to be pre-processed.
|
|
45
|
+
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
|
|
46
|
+
*
|
|
47
|
+
* @returns A promise that resolves to the pre-processed parameters.
|
|
48
|
+
*/
|
|
49
|
+
const preProcessApiCallParameters = async (endpoint, apiCallParameters, processingOptions = { retries: 0, totalTimeoutMs: exports.DEFAULT_PROCESSING_TIMEOUT_MS }) => {
|
|
50
|
+
const { preProcessingSpecifications } = endpoint;
|
|
51
|
+
if (!preProcessingSpecifications || preProcessingSpecifications.length === 0) {
|
|
52
|
+
return apiCallParameters;
|
|
53
|
+
}
|
|
54
|
+
// We only wrap the code through "go" utils because of the timeout and retry logic.
|
|
55
|
+
const goProcessedParameters = await (0, promise_utils_1.go)(async () => {
|
|
56
|
+
let currentValue = (0, exports.removeReservedParameters)(apiCallParameters);
|
|
57
|
+
for (const processing of preProcessingSpecifications) {
|
|
58
|
+
// Provide endpoint parameters without reserved parameters immutably between steps. Recompute them for each
|
|
59
|
+
// snippet independently because processing snippets can modify the parameters.
|
|
60
|
+
const endpointParameters = (0, exports.removeReservedParameters)(apiCallParameters);
|
|
61
|
+
switch (processing.environment) {
|
|
62
|
+
case 'Node': {
|
|
63
|
+
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluate)(processing.value, { input: currentValue, endpointParameters }, processing.timeoutMs);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case 'Node async': {
|
|
67
|
+
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluateAsync)(processing.value, { input: currentValue, endpointParameters }, processing.timeoutMs);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return currentValue;
|
|
73
|
+
}, processingOptions);
|
|
74
|
+
if (!goProcessedParameters.success)
|
|
75
|
+
throw goProcessedParameters.error;
|
|
76
|
+
// Let this throw if the processed parameters are invalid.
|
|
77
|
+
const parsedParameters = schema_1.apiCallParametersSchema.parse(goProcessedParameters.data);
|
|
78
|
+
// Having removed reserved parameters for pre-processing, we need to re-insert them for the API call.
|
|
79
|
+
return (0, exports.addReservedParameters)(apiCallParameters, parsedParameters);
|
|
80
|
+
};
|
|
81
|
+
exports.preProcessApiCallParameters = preProcessApiCallParameters;
|
|
82
|
+
/**
|
|
83
|
+
* Post-processes the API call response based on the provided endpoint's processing specifications.
|
|
84
|
+
*
|
|
85
|
+
* @param apiCallResponse The raw response obtained from the API call.
|
|
86
|
+
* @param endpoint The endpoint containing processing specifications.
|
|
87
|
+
* @param apiCallParameters The parameters used in the API call.
|
|
88
|
+
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
|
|
89
|
+
*
|
|
90
|
+
* @returns A promise that resolves to the post-processed API call response.
|
|
91
|
+
*/
|
|
92
|
+
const postProcessApiCallResponse = async (apiCallResponse, endpoint, apiCallParameters, processingOptions = { retries: 0, totalTimeoutMs: exports.DEFAULT_PROCESSING_TIMEOUT_MS }) => {
|
|
93
|
+
const { postProcessingSpecifications } = endpoint;
|
|
94
|
+
if (!postProcessingSpecifications || postProcessingSpecifications?.length === 0) {
|
|
95
|
+
return apiCallResponse;
|
|
96
|
+
}
|
|
97
|
+
// We only wrap the code through "go" utils because of the timeout and retry logic.
|
|
98
|
+
const goResult = await (0, promise_utils_1.go)(async () => {
|
|
99
|
+
let currentValue = apiCallResponse;
|
|
100
|
+
for (const processing of postProcessingSpecifications) {
|
|
101
|
+
// Provide endpoint parameters without reserved parameters immutably between steps. Recompute them for each
|
|
102
|
+
// snippet independently because processing snippets can modify the parameters.
|
|
103
|
+
const endpointParameters = (0, exports.removeReservedParameters)(apiCallParameters);
|
|
104
|
+
switch (processing.environment) {
|
|
105
|
+
case 'Node': {
|
|
106
|
+
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluate)(processing.value, { input: currentValue, endpointParameters }, processing.timeoutMs);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'Node async': {
|
|
110
|
+
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluateAsync)(processing.value, { input: currentValue, endpointParameters }, processing.timeoutMs);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return currentValue;
|
|
116
|
+
}, processingOptions);
|
|
117
|
+
if (!goResult.success)
|
|
118
|
+
throw goResult.error;
|
|
119
|
+
return goResult.data;
|
|
120
|
+
};
|
|
121
|
+
exports.postProcessApiCallResponse = postProcessApiCallResponse;
|
|
122
|
+
//# sourceMappingURL=processing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processing.js","sourceRoot":"","sources":["../../src/processing/processing.ts"],"names":[],"mappings":";;;AAAA,mCAA+D;AAC/D,uDAA8D;AAE9D,qCAA2E;AAC3E,uDAAwE;AAE3D,QAAA,6BAA6B,GAAG,MAAM,CAAC;AAEpD,MAAM,kBAAkB,GAAG,yBAA+B,CAAC,CAAC,6BAA6B;AAEzF;;;;GAIG;AACI,MAAM,wBAAwB,GAAG,CAAC,UAA6B,EAAqB,EAAE;IAC3F,MAAM,MAAM,GAAsB,EAAE,CAAC;IAErC,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE;QAC5B,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACrC,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;SAC/B;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAVW,QAAA,wBAAwB,4BAUnC;AAEF;;;;;GAKG;AACI,MAAM,qBAAqB,GAAG,CACnC,iBAAoC,EACpC,kBAAqC,EAClB,EAAE;IACrB,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE;QACnC,IAAI,kBAAkB,CAAC,QAAQ,CAAC,GA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oBACjB,YAAY,GAAG,MAAM,IAAA,qCAAmB,EACtC,UAAU,CAAC,KAAK,EAChB,EAAE,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,EAC3C,UAAU,CAAC,SAAS,CACrB,CAAC;oBACF,MAAM;iBACP;aACF;SACF;QAED,OAAO,YAAY,CAAC;IACtB,CAAC,EAAE,iBAAiB,CAAC,CAAC;IACtB,IAAI,CAAC,QAAQ,CAAC,OAAO;QAAE,MAAM,QAAQ,CAAC,KAAK,CAAC;IAE5C,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC,CAAC;AA5CW,QAAA,0BAA0B,8BA4CrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/processing/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,uBAAuB,oCAAgC,CAAC;AAErE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.apiCallParametersSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.apiCallParametersSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.any());
|
|
6
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/processing/schema.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAEX,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluates the provided code in a new VM context with the specified global variables.
|
|
3
|
+
*
|
|
4
|
+
* **Security Warning:** This function executes the provided code and can have unintended side effects or
|
|
5
|
+
* vulnerabilities if used with untrusted or malicious input. It's imperative to use this function only with code you
|
|
6
|
+
* trust completely. Avoid using this function with user-generated code or third-party code that hasn't been thoroughly
|
|
7
|
+
* reviewed.
|
|
8
|
+
*
|
|
9
|
+
* @param code The JavaScript code to evaluate.
|
|
10
|
+
* @param globalVariables A key-value pair of variables to be made available in the context of the executed code.
|
|
11
|
+
* @param timeout Duration in milliseconds to wait before terminating the execution.
|
|
12
|
+
*
|
|
13
|
+
* @returns The result of the evaluated code.
|
|
14
|
+
*
|
|
15
|
+
* @throws Throws an error if the execution exceeds the provided timeout or if there's a problem with the code.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
*const result = unsafeEvaluate('const output = input + 1;', { input: 1 }, 1000);
|
|
20
|
+
*console.log(result); // Outputs: 2
|
|
21
|
+
*/
|
|
22
|
+
export declare const unsafeEvaluate: (code: string, globalVariables: Record<string, unknown>, timeout: number) => unknown;
|
|
23
|
+
/**
|
|
24
|
+
* Asynchronously evaluates the provided code in a new VM context with the specified global variables.
|
|
25
|
+
*
|
|
26
|
+
* **Security Warning:** This function executes the provided code and can have unintended side effects or
|
|
27
|
+
* vulnerabilities if used with untrusted or malicious input. It's imperative to use this function only with code you
|
|
28
|
+
* trust completely. Avoid using this function with user-generated code or third-party code that hasn't been thoroughly
|
|
29
|
+
* reviewed.
|
|
30
|
+
*
|
|
31
|
+
* @param code The JavaScript code to evaluate. The code should call the `resolve` method to return the result of the
|
|
32
|
+
* evaluation. You may use async/await syntax in the code.
|
|
33
|
+
* @param globalVariables A key-value pair of variables to be made available in the context of the executed code.
|
|
34
|
+
* @param timeout Duration in milliseconds to wait before terminating the execution.
|
|
35
|
+
*
|
|
36
|
+
* @returns The result of the evaluated code wrapped in a Promise.
|
|
37
|
+
*
|
|
38
|
+
* @throws Throws an error if the execution exceeds the provided timeout or if there's a problem with the code.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
*
|
|
42
|
+
*const result = await unsafeEvaluateAsync(
|
|
43
|
+
* "const output = {...input, c: 'some-value'}; resolve(output);",
|
|
44
|
+
* { input: { a: true, b: 123 } },
|
|
45
|
+
* 5000
|
|
46
|
+
*);
|
|
47
|
+
*console.log(result); // Outputs: { a: true, b: 123, c: 'some-value' }
|
|
48
|
+
*/
|
|
49
|
+
export declare const unsafeEvaluateAsync: (code: string, globalVariables: Record<string, unknown>, timeout: number) => Promise<unknown>;
|
|
50
|
+
//# sourceMappingURL=unsafe-evaluate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsafe-evaluate.d.ts","sourceRoot":"","sources":["../../src/processing/unsafe-evaluate.ts"],"names":[],"mappings":"AA+EA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,SAAU,MAAM,mBAAmB,OAAO,MAAM,EAAE,OAAO,CAAC,WAAW,MAAM,YAarG,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,mBAAmB,SAAgB,MAAM,mBAAmB,OAAO,MAAM,EAAE,OAAO,CAAC,WAAW,MAAM,qBAoChH,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
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.unsafeEvaluateAsync = exports.unsafeEvaluate = void 0;
|
|
7
|
+
/* eslint-disable camelcase */
|
|
8
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
9
|
+
const node_async_hooks_1 = __importDefault(require("node:async_hooks"));
|
|
10
|
+
const node_buffer_1 = __importDefault(require("node:buffer"));
|
|
11
|
+
const node_child_process_1 = __importDefault(require("node:child_process"));
|
|
12
|
+
const node_cluster_1 = __importDefault(require("node:cluster"));
|
|
13
|
+
const node_console_1 = __importDefault(require("node:console"));
|
|
14
|
+
const node_constants_1 = __importDefault(require("node:constants"));
|
|
15
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
16
|
+
const node_dgram_1 = __importDefault(require("node:dgram"));
|
|
17
|
+
const node_dns_1 = __importDefault(require("node:dns"));
|
|
18
|
+
const node_events_1 = __importDefault(require("node:events"));
|
|
19
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
20
|
+
const node_http_1 = __importDefault(require("node:http"));
|
|
21
|
+
const node_http2_1 = __importDefault(require("node:http2"));
|
|
22
|
+
const node_https_1 = __importDefault(require("node:https"));
|
|
23
|
+
const node_inspector_1 = __importDefault(require("node:inspector"));
|
|
24
|
+
const node_module_1 = __importDefault(require("node:module"));
|
|
25
|
+
const node_net_1 = __importDefault(require("node:net"));
|
|
26
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
27
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
28
|
+
const node_perf_hooks_1 = __importDefault(require("node:perf_hooks"));
|
|
29
|
+
const node_process_1 = __importDefault(require("node:process"));
|
|
30
|
+
const node_readline_1 = __importDefault(require("node:readline"));
|
|
31
|
+
const node_repl_1 = __importDefault(require("node:repl"));
|
|
32
|
+
const node_stream_1 = __importDefault(require("node:stream"));
|
|
33
|
+
const node_string_decoder_1 = __importDefault(require("node:string_decoder"));
|
|
34
|
+
const node_timers_1 = __importDefault(require("node:timers"));
|
|
35
|
+
const node_tls_1 = __importDefault(require("node:tls"));
|
|
36
|
+
const node_trace_events_1 = __importDefault(require("node:trace_events"));
|
|
37
|
+
const node_tty_1 = __importDefault(require("node:tty"));
|
|
38
|
+
const node_url_1 = __importDefault(require("node:url"));
|
|
39
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
40
|
+
const node_v8_1 = __importDefault(require("node:v8"));
|
|
41
|
+
const node_vm_1 = __importDefault(require("node:vm"));
|
|
42
|
+
const node_worker_threads_1 = __importDefault(require("node:worker_threads"));
|
|
43
|
+
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
44
|
+
const vm_timers_1 = require("./vm-timers");
|
|
45
|
+
const builtInNodeModules = {
|
|
46
|
+
assert: node_assert_1.default,
|
|
47
|
+
async_hooks: node_async_hooks_1.default,
|
|
48
|
+
buffer: node_buffer_1.default,
|
|
49
|
+
child_process: node_child_process_1.default,
|
|
50
|
+
cluster: node_cluster_1.default,
|
|
51
|
+
console: node_console_1.default,
|
|
52
|
+
constants: node_constants_1.default,
|
|
53
|
+
crypto: node_crypto_1.default,
|
|
54
|
+
dgram: node_dgram_1.default,
|
|
55
|
+
dns: node_dns_1.default,
|
|
56
|
+
events: node_events_1.default,
|
|
57
|
+
fs: node_fs_1.default,
|
|
58
|
+
http: node_http_1.default,
|
|
59
|
+
http2: node_http2_1.default,
|
|
60
|
+
https: node_https_1.default,
|
|
61
|
+
inspector: node_inspector_1.default,
|
|
62
|
+
module: node_module_1.default,
|
|
63
|
+
net: node_net_1.default,
|
|
64
|
+
os: node_os_1.default,
|
|
65
|
+
path: node_path_1.default,
|
|
66
|
+
perf_hooks: node_perf_hooks_1.default,
|
|
67
|
+
process: node_process_1.default,
|
|
68
|
+
readline: node_readline_1.default,
|
|
69
|
+
repl: node_repl_1.default,
|
|
70
|
+
stream: node_stream_1.default,
|
|
71
|
+
string_decoder: node_string_decoder_1.default,
|
|
72
|
+
timers: node_timers_1.default,
|
|
73
|
+
tls: node_tls_1.default,
|
|
74
|
+
trace_events: node_trace_events_1.default,
|
|
75
|
+
tty: node_tty_1.default,
|
|
76
|
+
url: node_url_1.default,
|
|
77
|
+
util: node_util_1.default,
|
|
78
|
+
v8: node_v8_1.default,
|
|
79
|
+
vm: node_vm_1.default,
|
|
80
|
+
worker_threads: node_worker_threads_1.default,
|
|
81
|
+
zlib: node_zlib_1.default,
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Evaluates the provided code in a new VM context with the specified global variables.
|
|
85
|
+
*
|
|
86
|
+
* **Security Warning:** This function executes the provided code and can have unintended side effects or
|
|
87
|
+
* vulnerabilities if used with untrusted or malicious input. It's imperative to use this function only with code you
|
|
88
|
+
* trust completely. Avoid using this function with user-generated code or third-party code that hasn't been thoroughly
|
|
89
|
+
* reviewed.
|
|
90
|
+
*
|
|
91
|
+
* @param code The JavaScript code to evaluate.
|
|
92
|
+
* @param globalVariables A key-value pair of variables to be made available in the context of the executed code.
|
|
93
|
+
* @param timeout Duration in milliseconds to wait before terminating the execution.
|
|
94
|
+
*
|
|
95
|
+
* @returns The result of the evaluated code.
|
|
96
|
+
*
|
|
97
|
+
* @throws Throws an error if the execution exceeds the provided timeout or if there's a problem with the code.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
*
|
|
101
|
+
*const result = unsafeEvaluate('const output = input + 1;', { input: 1 }, 1000);
|
|
102
|
+
*console.log(result); // Outputs: 2
|
|
103
|
+
*/
|
|
104
|
+
const unsafeEvaluate = (code, globalVariables, timeout) => {
|
|
105
|
+
const vmContext = {
|
|
106
|
+
...globalVariables,
|
|
107
|
+
...builtInNodeModules,
|
|
108
|
+
deferredOutput: undefined,
|
|
109
|
+
};
|
|
110
|
+
node_vm_1.default.runInNewContext(`${code}; deferredOutput = output;`, vmContext, {
|
|
111
|
+
displayErrors: true,
|
|
112
|
+
timeout,
|
|
113
|
+
});
|
|
114
|
+
return vmContext.deferredOutput;
|
|
115
|
+
};
|
|
116
|
+
exports.unsafeEvaluate = unsafeEvaluate;
|
|
117
|
+
/**
|
|
118
|
+
* Asynchronously evaluates the provided code in a new VM context with the specified global variables.
|
|
119
|
+
*
|
|
120
|
+
* **Security Warning:** This function executes the provided code and can have unintended side effects or
|
|
121
|
+
* vulnerabilities if used with untrusted or malicious input. It's imperative to use this function only with code you
|
|
122
|
+
* trust completely. Avoid using this function with user-generated code or third-party code that hasn't been thoroughly
|
|
123
|
+
* reviewed.
|
|
124
|
+
*
|
|
125
|
+
* @param code The JavaScript code to evaluate. The code should call the `resolve` method to return the result of the
|
|
126
|
+
* evaluation. You may use async/await syntax in the code.
|
|
127
|
+
* @param globalVariables A key-value pair of variables to be made available in the context of the executed code.
|
|
128
|
+
* @param timeout Duration in milliseconds to wait before terminating the execution.
|
|
129
|
+
*
|
|
130
|
+
* @returns The result of the evaluated code wrapped in a Promise.
|
|
131
|
+
*
|
|
132
|
+
* @throws Throws an error if the execution exceeds the provided timeout or if there's a problem with the code.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
*
|
|
136
|
+
*const result = await unsafeEvaluateAsync(
|
|
137
|
+
* "const output = {...input, c: 'some-value'}; resolve(output);",
|
|
138
|
+
* { input: { a: true, b: 123 } },
|
|
139
|
+
* 5000
|
|
140
|
+
*);
|
|
141
|
+
*console.log(result); // Outputs: { a: true, b: 123, c: 'some-value' }
|
|
142
|
+
*/
|
|
143
|
+
const unsafeEvaluateAsync = async (code, globalVariables, timeout) => {
|
|
144
|
+
let vmReject;
|
|
145
|
+
// Make sure the timeout is applied. When the processing snippet uses setTimeout or setInterval, the timeout option
|
|
146
|
+
// from VM is broken. See: https://github.com/nodejs/node/issues/3020.
|
|
147
|
+
//
|
|
148
|
+
// We need to manually clear all timers and reject the processing manually.
|
|
149
|
+
const timeoutTimer = setTimeout(() => {
|
|
150
|
+
vmReject(new Error('Timeout exceeded'));
|
|
151
|
+
}, timeout);
|
|
152
|
+
return new Promise((resolve, reject) => {
|
|
153
|
+
const timers = (0, vm_timers_1.createTimers)();
|
|
154
|
+
const vmResolve = (value) => {
|
|
155
|
+
timers.clearAll();
|
|
156
|
+
clearTimeout(timeoutTimer);
|
|
157
|
+
resolve(value);
|
|
158
|
+
};
|
|
159
|
+
vmReject = (reason) => {
|
|
160
|
+
timers.clearAll();
|
|
161
|
+
clearTimeout(timeoutTimer);
|
|
162
|
+
reject(reason);
|
|
163
|
+
};
|
|
164
|
+
const vmContext = {
|
|
165
|
+
...globalVariables,
|
|
166
|
+
...builtInNodeModules,
|
|
167
|
+
resolve: vmResolve,
|
|
168
|
+
reject: vmReject,
|
|
169
|
+
setTimeout: timers.customSetTimeout,
|
|
170
|
+
setInterval: timers.customSetInterval,
|
|
171
|
+
clearTimeout: timers.customClearTimeout,
|
|
172
|
+
clearInterval: timers.customClearInterval,
|
|
173
|
+
};
|
|
174
|
+
node_vm_1.default.runInNewContext(code, vmContext, { displayErrors: true, timeout });
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
exports.unsafeEvaluateAsync = unsafeEvaluateAsync;
|
|
178
|
+
//# sourceMappingURL=unsafe-evaluate.js.map
|