@api3/commons 0.4.0 → 0.5.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 +2 -0
- package/dist/blockchain-utilities/derivation.d.ts +78 -0
- package/dist/blockchain-utilities/derivation.d.ts.map +1 -0
- package/dist/blockchain-utilities/derivation.js +97 -0
- package/dist/blockchain-utilities/derivation.js.map +1 -0
- package/dist/blockchain-utilities/schema.d.ts +12 -0
- package/dist/blockchain-utilities/schema.d.ts.map +1 -0
- package/dist/blockchain-utilities/schema.js +13 -0
- package/dist/blockchain-utilities/schema.js.map +1 -0
- package/dist/logger/index.d.ts +1 -1
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js.map +1 -1
- package/dist/processing/processing.d.ts +70 -18
- package/dist/processing/processing.d.ts.map +1 -1
- package/dist/processing/processing.js +145 -37
- package/dist/processing/processing.js.map +1 -1
- package/dist/processing/schema.d.ts +25 -2
- package/dist/processing/schema.d.ts.map +1 -1
- package/dist/processing/schema.js +10 -9
- package/dist/processing/schema.js.map +1 -1
- package/dist/processing/unsafe-evaluate.d.ts +1 -0
- package/dist/processing/unsafe-evaluate.d.ts.map +1 -1
- package/dist/processing/unsafe-evaluate.js +31 -1
- package/dist/processing/unsafe-evaluate.js.map +1 -1
- package/package.json +5 -3
- package/src/blockchain-utilities/README.md +5 -0
- package/src/blockchain-utilities/derivation.test.ts +147 -0
- package/src/blockchain-utilities/derivation.ts +116 -0
- package/src/blockchain-utilities/schema.test.ts +23 -0
- package/src/blockchain-utilities/schema.ts +14 -0
- package/src/logger/index.test.ts +16 -0
- package/src/logger/index.ts +8 -5
- package/src/processing/README.md +89 -14
- package/src/processing/processing.test.ts +429 -111
- package/src/processing/processing.ts +196 -47
- package/src/processing/schema.ts +21 -8
- package/src/processing/unsafe-evaluate.test.ts +220 -1
- package/src/processing/unsafe-evaluate.ts +39 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.postProcessResponse = exports.preProcessEndpointParameters = exports.postProcessResponseV2 = exports.preProcessEndpointParametersV2 = exports.postProcessResponseV1 = exports.preProcessEndpointParametersV1 = exports.addReservedParameters = exports.removeReservedParameters = exports.DEFAULT_PROCESSING_TIMEOUT_MS = void 0;
|
|
4
4
|
const ois_1 = require("@api3/ois");
|
|
5
5
|
const promise_utils_1 = require("@api3/promise-utils");
|
|
6
6
|
const schema_1 = require("./schema");
|
|
@@ -8,9 +8,9 @@ const unsafe_evaluate_1 = require("./unsafe-evaluate");
|
|
|
8
8
|
exports.DEFAULT_PROCESSING_TIMEOUT_MS = 10_000;
|
|
9
9
|
const reservedParameters = ois_1.RESERVED_PARAMETERS; // To avoid strict TS checks.
|
|
10
10
|
/**
|
|
11
|
-
* Removes reserved parameters from the parameters
|
|
12
|
-
* @param parameters The
|
|
13
|
-
* @returns The parameters
|
|
11
|
+
* Removes reserved parameters from the endpoint parameters.
|
|
12
|
+
* @param parameters The endpoint parameters from which reserved parameters will be removed.
|
|
13
|
+
* @returns The endpoint parameters without reserved parameters.
|
|
14
14
|
*/
|
|
15
15
|
const removeReservedParameters = (parameters) => {
|
|
16
16
|
const result = {};
|
|
@@ -23,10 +23,10 @@ const removeReservedParameters = (parameters) => {
|
|
|
23
23
|
};
|
|
24
24
|
exports.removeReservedParameters = removeReservedParameters;
|
|
25
25
|
/**
|
|
26
|
-
* Re-inserts reserved parameters from the initial parameters
|
|
27
|
-
* @param initialParameters The initial
|
|
28
|
-
* @param modifiedParameters The modified
|
|
29
|
-
* @returns The modified parameters
|
|
26
|
+
* Re-inserts reserved parameters from the initial endpoint parameters into the modified endpoint parameters.
|
|
27
|
+
* @param initialParameters The initial endpoint parameters that might contain reserved parameters.
|
|
28
|
+
* @param modifiedParameters The modified endpoint parameters to which reserved parameters will be added.
|
|
29
|
+
* @returns The modified endpoint parameters with re-inserted reserved parameters.
|
|
30
30
|
*/
|
|
31
31
|
const addReservedParameters = (initialParameters, modifiedParameters) => {
|
|
32
32
|
for (const key in initialParameters) {
|
|
@@ -38,33 +38,33 @@ const addReservedParameters = (initialParameters, modifiedParameters) => {
|
|
|
38
38
|
};
|
|
39
39
|
exports.addReservedParameters = addReservedParameters;
|
|
40
40
|
/**
|
|
41
|
-
* Pre-processes
|
|
41
|
+
* Pre-processes endpoint parameters based on the provided endpoint's processing specifications.
|
|
42
42
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
43
|
+
* @param preProcessingSpecifications The v1 pre-processing specifications.
|
|
44
|
+
* @param endpointParameters The parameters to be pre-processed.
|
|
45
45
|
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
|
|
46
46
|
*
|
|
47
47
|
* @returns A promise that resolves to the pre-processed parameters.
|
|
48
48
|
*/
|
|
49
|
-
const
|
|
50
|
-
const { preProcessingSpecifications } = endpoint;
|
|
49
|
+
const preProcessEndpointParametersV1 = async (preProcessingSpecifications, endpointParameters, processingOptions = { retries: 0, totalTimeoutMs: exports.DEFAULT_PROCESSING_TIMEOUT_MS }) => {
|
|
51
50
|
if (!preProcessingSpecifications || preProcessingSpecifications.length === 0) {
|
|
52
|
-
return
|
|
51
|
+
return endpointParameters;
|
|
53
52
|
}
|
|
54
|
-
// We only wrap the code through "go" utils because of the timeout and retry logic.
|
|
53
|
+
// We only wrap the code through "go" utils because of the timeout and retry logic. In case of error, the function
|
|
54
|
+
// just re-throws.
|
|
55
55
|
const goProcessedParameters = await (0, promise_utils_1.go)(async () => {
|
|
56
|
-
let currentValue = (0, exports.removeReservedParameters)(
|
|
56
|
+
let currentValue = (0, exports.removeReservedParameters)(endpointParameters);
|
|
57
57
|
for (const processing of preProcessingSpecifications) {
|
|
58
58
|
// Provide endpoint parameters without reserved parameters immutably between steps. Recompute them for each
|
|
59
59
|
// snippet independently because processing snippets can modify the parameters.
|
|
60
|
-
const
|
|
60
|
+
const nonReservedEndpointParameters = (0, exports.removeReservedParameters)(endpointParameters);
|
|
61
61
|
switch (processing.environment) {
|
|
62
62
|
case 'Node': {
|
|
63
|
-
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluate)(processing.value, { input: currentValue, endpointParameters }, processing.timeoutMs);
|
|
63
|
+
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluate)(processing.value, { input: currentValue, endpointParameters: nonReservedEndpointParameters }, processing.timeoutMs);
|
|
64
64
|
break;
|
|
65
65
|
}
|
|
66
66
|
case 'Node async': {
|
|
67
|
-
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluateAsync)(processing.value, { input: currentValue, endpointParameters }, processing.timeoutMs);
|
|
67
|
+
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluateAsync)(processing.value, { input: currentValue, endpointParameters: nonReservedEndpointParameters }, processing.timeoutMs);
|
|
68
68
|
break;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -74,40 +74,42 @@ const preProcessApiCallParameters = async (endpoint, apiCallParameters, processi
|
|
|
74
74
|
if (!goProcessedParameters.success)
|
|
75
75
|
throw goProcessedParameters.error;
|
|
76
76
|
// Let this throw if the processed parameters are invalid.
|
|
77
|
-
const parsedParameters =
|
|
78
|
-
// Having removed reserved parameters for pre-processing, we need to re-insert them
|
|
79
|
-
return (0, exports.addReservedParameters)(
|
|
77
|
+
const parsedParameters = schema_1.endpointParametersSchema.parse(goProcessedParameters.data);
|
|
78
|
+
// Having removed reserved parameters for pre-processing, we need to re-insert them after pre-processing.
|
|
79
|
+
return (0, exports.addReservedParameters)(endpointParameters, parsedParameters);
|
|
80
80
|
};
|
|
81
|
-
exports.
|
|
81
|
+
exports.preProcessEndpointParametersV1 = preProcessEndpointParametersV1;
|
|
82
82
|
/**
|
|
83
|
-
* Post-processes the
|
|
83
|
+
* Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
|
|
84
|
+
* API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
|
|
85
|
+
* allows skipping API calls in which case the response is the result of pre-processing.
|
|
84
86
|
*
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
87
|
-
* @param
|
|
87
|
+
* @param response The response to be post-processed.
|
|
88
|
+
* @param postProcessingSpecifications The v1 post-processing specifications.
|
|
89
|
+
* @param endpointParameters The endpoint parameters.
|
|
88
90
|
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
|
|
89
91
|
*
|
|
90
|
-
* @returns A promise that resolves to the post-processed
|
|
92
|
+
* @returns A promise that resolves to the post-processed response.
|
|
91
93
|
*/
|
|
92
|
-
const
|
|
93
|
-
const { postProcessingSpecifications } = endpoint;
|
|
94
|
+
const postProcessResponseV1 = async (response, postProcessingSpecifications, endpointParameters, processingOptions = { retries: 0, totalTimeoutMs: exports.DEFAULT_PROCESSING_TIMEOUT_MS }) => {
|
|
94
95
|
if (!postProcessingSpecifications || postProcessingSpecifications?.length === 0) {
|
|
95
|
-
return
|
|
96
|
+
return response;
|
|
96
97
|
}
|
|
97
|
-
// We only wrap the code through "go" utils because of the timeout and retry logic.
|
|
98
|
+
// We only wrap the code through "go" utils because of the timeout and retry logic. In case of error, the function
|
|
99
|
+
// just re-throws.
|
|
98
100
|
const goResult = await (0, promise_utils_1.go)(async () => {
|
|
99
|
-
let currentValue =
|
|
101
|
+
let currentValue = response;
|
|
100
102
|
for (const processing of postProcessingSpecifications) {
|
|
101
103
|
// Provide endpoint parameters without reserved parameters immutably between steps. Recompute them for each
|
|
102
104
|
// snippet independently because processing snippets can modify the parameters.
|
|
103
|
-
const
|
|
105
|
+
const nonReservedEndpointParameters = (0, exports.removeReservedParameters)(endpointParameters);
|
|
104
106
|
switch (processing.environment) {
|
|
105
107
|
case 'Node': {
|
|
106
|
-
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluate)(processing.value, { input: currentValue, endpointParameters }, processing.timeoutMs);
|
|
108
|
+
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluate)(processing.value, { input: currentValue, endpointParameters: nonReservedEndpointParameters }, processing.timeoutMs);
|
|
107
109
|
break;
|
|
108
110
|
}
|
|
109
111
|
case 'Node async': {
|
|
110
|
-
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluateAsync)(processing.value, { input: currentValue, endpointParameters }, processing.timeoutMs);
|
|
112
|
+
currentValue = await (0, unsafe_evaluate_1.unsafeEvaluateAsync)(processing.value, { input: currentValue, endpointParameters: nonReservedEndpointParameters }, processing.timeoutMs);
|
|
111
113
|
break;
|
|
112
114
|
}
|
|
113
115
|
}
|
|
@@ -118,5 +120,111 @@ const postProcessApiCallResponse = async (apiCallResponse, endpoint, apiCallPara
|
|
|
118
120
|
throw goResult.error;
|
|
119
121
|
return goResult.data;
|
|
120
122
|
};
|
|
121
|
-
exports.
|
|
123
|
+
exports.postProcessResponseV1 = postProcessResponseV1;
|
|
124
|
+
/**
|
|
125
|
+
* Pre-processes endpoint parameters based on the provided endpoint's processing specifications.
|
|
126
|
+
*
|
|
127
|
+
* @param preProcessingSpecificationV2 The v2 pre-processing specification.
|
|
128
|
+
* @param endpointParameters The parameters to be pre-processed.
|
|
129
|
+
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
|
|
130
|
+
*
|
|
131
|
+
* @returns A promise that resolves to the pre-processed parameters.
|
|
132
|
+
*/
|
|
133
|
+
const preProcessEndpointParametersV2 = async (preProcessingSpecificationV2, endpointParameters, processingOptions = { retries: 0, totalTimeoutMs: exports.DEFAULT_PROCESSING_TIMEOUT_MS }) => {
|
|
134
|
+
if (!preProcessingSpecificationV2)
|
|
135
|
+
return { endpointParameters };
|
|
136
|
+
// We only wrap the code through "go" utils because of the timeout and retry logic. In case of error, the function
|
|
137
|
+
// just re-throws.
|
|
138
|
+
const goProcessedParameters = await (0, promise_utils_1.go)(async () => {
|
|
139
|
+
const { environment, timeoutMs, value } = preProcessingSpecificationV2;
|
|
140
|
+
switch (environment) {
|
|
141
|
+
case 'Node': {
|
|
142
|
+
return (0, unsafe_evaluate_1.unsafeEvaluateV2)(value, { endpointParameters: (0, exports.removeReservedParameters)(endpointParameters) }, timeoutMs);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}, processingOptions);
|
|
146
|
+
if (!goProcessedParameters.success)
|
|
147
|
+
throw goProcessedParameters.error;
|
|
148
|
+
// Let this throw if the processed parameters are invalid.
|
|
149
|
+
const preProcessingResponse = schema_1.preProcessingV2ResponseSchema.parse(goProcessedParameters.data);
|
|
150
|
+
// Having removed reserved parameters for pre-processing, we need to re-insert them after pre-processing.
|
|
151
|
+
return { endpointParameters: (0, exports.addReservedParameters)(endpointParameters, preProcessingResponse.endpointParameters) };
|
|
152
|
+
};
|
|
153
|
+
exports.preProcessEndpointParametersV2 = preProcessEndpointParametersV2;
|
|
154
|
+
/**
|
|
155
|
+
* Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
|
|
156
|
+
* API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
|
|
157
|
+
* allows skipping API calls in which case the response is the result of pre-processing.
|
|
158
|
+
*
|
|
159
|
+
* @param response The response to be post-processed.
|
|
160
|
+
* @param postProcessingSpecificationV2 The v2 post-processing specification.
|
|
161
|
+
* @param endpointParameters The endpoint parameters.
|
|
162
|
+
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
|
|
163
|
+
*
|
|
164
|
+
* @returns A promise that resolves to the post-processed response.
|
|
165
|
+
*/
|
|
166
|
+
const postProcessResponseV2 = async (response, postProcessingSpecificationV2, endpointParameters, processingOptions = { retries: 0, totalTimeoutMs: exports.DEFAULT_PROCESSING_TIMEOUT_MS }) => {
|
|
167
|
+
if (!postProcessingSpecificationV2)
|
|
168
|
+
return { response };
|
|
169
|
+
// We only wrap the code through "go" utils because of the timeout and retry logic. In case of error, the function
|
|
170
|
+
// just re-throws.
|
|
171
|
+
const goResult = await (0, promise_utils_1.go)(async () => {
|
|
172
|
+
const { environment, timeoutMs, value } = postProcessingSpecificationV2;
|
|
173
|
+
// Provide endpoint parameters without reserved parameters immutably between steps. Recompute them for each
|
|
174
|
+
// snippet independently because processing snippets can modify the parameters.
|
|
175
|
+
const nonReservedEndpointParameters = (0, exports.removeReservedParameters)(endpointParameters);
|
|
176
|
+
switch (environment) {
|
|
177
|
+
case 'Node': {
|
|
178
|
+
return (0, unsafe_evaluate_1.unsafeEvaluateV2)(value, { response, endpointParameters: nonReservedEndpointParameters }, timeoutMs);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}, processingOptions);
|
|
182
|
+
if (!goResult.success)
|
|
183
|
+
throw goResult.error;
|
|
184
|
+
return schema_1.postProcessingV2ResponseSchema.parse(goResult.data);
|
|
185
|
+
};
|
|
186
|
+
exports.postProcessResponseV2 = postProcessResponseV2;
|
|
187
|
+
/**
|
|
188
|
+
* Pre-processes endpoint parameters based on the provided endpoint's processing specifications. Internally it
|
|
189
|
+
* determines what processing implementation should be used.
|
|
190
|
+
*
|
|
191
|
+
* @param endpoint The endpoint containing processing specifications.
|
|
192
|
+
* @param endpointParameters The parameters to be pre-processed.
|
|
193
|
+
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
|
|
194
|
+
*
|
|
195
|
+
* @returns A promise that resolves to the pre-processed parameters.
|
|
196
|
+
*/
|
|
197
|
+
const preProcessEndpointParameters = async (endpoint, endpointParameters, processingOptions = { retries: 0, totalTimeoutMs: exports.DEFAULT_PROCESSING_TIMEOUT_MS }) => {
|
|
198
|
+
const { preProcessingSpecificationV2, preProcessingSpecifications } = endpoint;
|
|
199
|
+
if (preProcessingSpecificationV2) {
|
|
200
|
+
return (0, exports.preProcessEndpointParametersV2)(preProcessingSpecificationV2, endpointParameters);
|
|
201
|
+
}
|
|
202
|
+
const preProcessV1Response = await (0, exports.preProcessEndpointParametersV1)(preProcessingSpecifications, endpointParameters, processingOptions);
|
|
203
|
+
return { endpointParameters: preProcessV1Response };
|
|
204
|
+
};
|
|
205
|
+
exports.preProcessEndpointParameters = preProcessEndpointParameters;
|
|
206
|
+
/**
|
|
207
|
+
* Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
|
|
208
|
+
* API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
|
|
209
|
+
* allows skipping API calls in which case the response is the result of pre-processing.
|
|
210
|
+
*
|
|
211
|
+
* This function determines what processing version should be used and provides a common interface. This is useful for
|
|
212
|
+
* services that want to use processing and don't care which processing version is used.
|
|
213
|
+
*
|
|
214
|
+
* @param response The response to be post-processed.
|
|
215
|
+
* @param endpoint The endpoint containing processing specifications.
|
|
216
|
+
* @param endpointParameters The endpoint parameters.
|
|
217
|
+
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
|
|
218
|
+
*
|
|
219
|
+
* @returns A promise that resolves to the post-processed response.
|
|
220
|
+
*/
|
|
221
|
+
const postProcessResponse = async (response, endpoint, endpointParameters, processingOptions = { retries: 0, totalTimeoutMs: exports.DEFAULT_PROCESSING_TIMEOUT_MS }) => {
|
|
222
|
+
const { postProcessingSpecificationV2, postProcessingSpecifications } = endpoint;
|
|
223
|
+
if (postProcessingSpecificationV2) {
|
|
224
|
+
return (0, exports.postProcessResponseV2)(response, postProcessingSpecificationV2, endpointParameters);
|
|
225
|
+
}
|
|
226
|
+
const postProcessV1Response = await (0, exports.postProcessResponseV1)(response, postProcessingSpecifications, endpointParameters, processingOptions);
|
|
227
|
+
return { response: postProcessV1Response };
|
|
228
|
+
};
|
|
229
|
+
exports.postProcessResponse = postProcessResponse;
|
|
122
230
|
//# sourceMappingURL=processing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processing.js","sourceRoot":"","sources":["../../src/processing/processing.ts"],"names":[],"mappings":";;;AAAA,mCAA+D;AAC/D,uDAA8D;AAE9D,
|
|
1
|
+
{"version":3,"file":"processing.js","sourceRoot":"","sources":["../../src/processing/processing.ts"],"names":[],"mappings":";;;AAAA,mCAA+D;AAC/D,uDAA8D;AAE9D,qCASkB;AAClB,uDAA0F;AAE7E,QAAA,6BAA6B,GAAG,MAAM,CAAC;AAEpD,MAAM,kBAAkB,GAAG,yBAA+B,CAAC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A,6BAAqB,EAAC,QAAQ,EAAE,6BAA6B,EAAE,kBAAkB,CAAC,CAAC;KAC3F;IAED,MAAM,qBAAqB,GAAG,MAAM,IAAA,6BAAqB,EACvD,QAAQ,EACR,4BAA4B,EAC5B,kBAAkB,EAClB,iBAAiB,CAClB,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,CAAC;AAC7C,CAAC,CAAC;AAlBW,QAAA,mBAAmB,uBAkB9B"}
|
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { processingSpecificationSchemaV2, ProcessingSpecification } from '@api3/ois';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export type ProcessingSpecificationV2 = z.infer<typeof processingSpecificationSchemaV2>;
|
|
4
|
+
export type ProcessingSpecifications = ProcessingSpecification[];
|
|
5
|
+
export declare const endpointParametersSchema: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
6
|
+
export type EndpointParameters = z.infer<typeof endpointParametersSchema>;
|
|
7
|
+
export declare const preProcessingV2ResponseSchema: z.ZodObject<{
|
|
8
|
+
endpointParameters: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
endpointParameters: Record<string, any>;
|
|
11
|
+
}, {
|
|
12
|
+
endpointParameters: Record<string, any>;
|
|
13
|
+
}>;
|
|
14
|
+
export type PreProcessingV2Response = z.infer<typeof preProcessingV2ResponseSchema>;
|
|
15
|
+
export declare const postProcessingV2ResponseSchema: z.ZodObject<{
|
|
16
|
+
response: z.ZodAny;
|
|
17
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
response?: any;
|
|
20
|
+
timestamp?: number | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
response?: any;
|
|
23
|
+
timestamp?: number | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
export type PostProcessingV2Response = z.infer<typeof postProcessingV2ResponseSchema>;
|
|
3
26
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/processing/schema.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/processing/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAC1F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AAExF,MAAM,MAAM,wBAAwB,GAAG,uBAAuB,EAAE,CAAC;AAEjE,eAAO,MAAM,wBAAwB,oCAAoB,CAAC;AAE1D,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,eAAO,MAAM,6BAA6B;;;;;;EAExC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEpF,eAAO,MAAM,8BAA8B;;;;;;;;;EAGzC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
exports.postProcessingV2ResponseSchema = exports.preProcessingV2ResponseSchema = exports.endpointParametersSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.endpointParametersSchema = zod_1.z.record(zod_1.z.any());
|
|
6
|
+
exports.preProcessingV2ResponseSchema = zod_1.z.object({
|
|
7
|
+
endpointParameters: exports.endpointParametersSchema,
|
|
8
|
+
});
|
|
9
|
+
exports.postProcessingV2ResponseSchema = zod_1.z.object({
|
|
10
|
+
response: zod_1.z.any(),
|
|
11
|
+
timestamp: zod_1.z.number().nonnegative().int().optional(),
|
|
12
|
+
});
|
|
12
13
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/processing/schema.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/processing/schema.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AAMX,QAAA,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC,CAAC;AAI7C,QAAA,6BAA6B,GAAG,OAAC,CAAC,MAAM,CAAC;IACpD,kBAAkB,EAAE,gCAAwB;CAC7C,CAAC,CAAC;AAIU,QAAA,8BAA8B,GAAG,OAAC,CAAC,MAAM,CAAC;IACrD,QAAQ,EAAE,OAAC,CAAC,GAAG,EAAE;IACjB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACrD,CAAC,CAAC"}
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*console.log(result); // Outputs: 2
|
|
21
21
|
*/
|
|
22
22
|
export declare const unsafeEvaluate: (code: string, globalVariables: Record<string, unknown>, timeout: number) => unknown;
|
|
23
|
+
export declare const unsafeEvaluateV2: (code: string, payload: unknown, timeout: number) => Promise<any>;
|
|
23
24
|
/**
|
|
24
25
|
* Asynchronously evaluates the provided code in a new VM context with the specified global variables.
|
|
25
26
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsafe-evaluate.d.ts","sourceRoot":"","sources":["../../src/processing/unsafe-evaluate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unsafe-evaluate.d.ts","sourceRoot":"","sources":["../../src/processing/unsafe-evaluate.ts"],"names":[],"mappings":"AAiFA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,SAAU,MAAM,mBAAmB,OAAO,MAAM,EAAE,OAAO,CAAC,WAAW,MAAM,YAarG,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAgB,MAAM,WAAW,OAAO,WAAW,MAAM,iBAmCrF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,mBAAmB,SAAgB,MAAM,mBAAmB,OAAO,MAAM,EAAE,OAAO,CAAC,WAAW,MAAM,qBAoChH,CAAC"}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.unsafeEvaluateAsync = exports.unsafeEvaluate = void 0;
|
|
6
|
+
exports.unsafeEvaluateAsync = exports.unsafeEvaluateV2 = exports.unsafeEvaluate = void 0;
|
|
7
7
|
/* eslint-disable camelcase */
|
|
8
8
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
9
9
|
const node_async_hooks_1 = __importDefault(require("node:async_hooks"));
|
|
@@ -41,6 +41,7 @@ const node_v8_1 = __importDefault(require("node:v8"));
|
|
|
41
41
|
const node_vm_1 = __importDefault(require("node:vm"));
|
|
42
42
|
const node_worker_threads_1 = __importDefault(require("node:worker_threads"));
|
|
43
43
|
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
44
|
+
const promise_utils_1 = require("@api3/promise-utils");
|
|
44
45
|
const vm_timers_1 = require("./vm-timers");
|
|
45
46
|
const builtInNodeModules = {
|
|
46
47
|
assert: node_assert_1.default,
|
|
@@ -114,6 +115,35 @@ const unsafeEvaluate = (code, globalVariables, timeout) => {
|
|
|
114
115
|
return vmContext.deferredOutput;
|
|
115
116
|
};
|
|
116
117
|
exports.unsafeEvaluate = unsafeEvaluate;
|
|
118
|
+
const unsafeEvaluateV2 = async (code, payload, timeout) => {
|
|
119
|
+
const timers = (0, vm_timers_1.createTimers)();
|
|
120
|
+
const goEvaluate = await (0, promise_utils_1.go)(
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
122
|
+
async () => node_vm_1.default.runInNewContext(`
|
|
123
|
+
(async () => {
|
|
124
|
+
return await (${code})(payload)
|
|
125
|
+
})();
|
|
126
|
+
`, {
|
|
127
|
+
...builtInNodeModules,
|
|
128
|
+
setTimeout: timers.customSetTimeout,
|
|
129
|
+
setInterval: timers.customSetInterval,
|
|
130
|
+
clearTimeout: timers.customClearTimeout,
|
|
131
|
+
clearInterval: timers.customClearInterval,
|
|
132
|
+
payload,
|
|
133
|
+
}, { displayErrors: true, timeout }),
|
|
134
|
+
// Make sure the timeout is applied. When the processing snippet uses setTimeout or setInterval, the timeout option
|
|
135
|
+
// from VM is broken. See: https://github.com/nodejs/node/issues/3020.
|
|
136
|
+
{ totalTimeoutMs: timeout });
|
|
137
|
+
// We need to manually clear all timers and reject the processing manually.
|
|
138
|
+
timers.clearAll();
|
|
139
|
+
if (goEvaluate.success) {
|
|
140
|
+
return goEvaluate.data;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
throw goEvaluate.error.reason ?? goEvaluate.error;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
exports.unsafeEvaluateV2 = unsafeEvaluateV2;
|
|
117
147
|
/**
|
|
118
148
|
* Asynchronously evaluates the provided code in a new VM context with the specified global variables.
|
|
119
149
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsafe-evaluate.js","sourceRoot":"","sources":["../../src/processing/unsafe-evaluate.ts"],"names":[],"mappings":";;;;;;AAAA,8BAA8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name": "@api3/commons",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"exports": "./dist/index.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@api3/ois": "^2.
|
|
17
|
+
"@api3/ois": "^2.3.0",
|
|
18
18
|
"@api3/promise-utils": "^0.4.0",
|
|
19
19
|
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
20
20
|
"@typescript-eslint/parser": "^6.2.1",
|
|
@@ -32,9 +32,11 @@
|
|
|
32
32
|
"eslint-plugin-react": "^7.32.1",
|
|
33
33
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
34
34
|
"eslint-plugin-unicorn": "^48.0.1",
|
|
35
|
+
"ethers": "^5.7.2",
|
|
35
36
|
"lodash": "^4.17.21",
|
|
36
37
|
"winston": "^3.10.0",
|
|
37
|
-
"winston-console-format": "^1.0.8"
|
|
38
|
+
"winston-console-format": "^1.0.8",
|
|
39
|
+
"zod": "^3.22.4"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@types/jest": "^29.5.5",
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
deriveAirnodeXpub,
|
|
5
|
+
deriveBeaconId,
|
|
6
|
+
deriveBeaconSetId,
|
|
7
|
+
deriveEndpointId,
|
|
8
|
+
deriveSponsorWallet,
|
|
9
|
+
deriveTemplateId,
|
|
10
|
+
deriveWalletPathFromSponsorAddress,
|
|
11
|
+
fromBytes32String,
|
|
12
|
+
PROTOCOL_IDS,
|
|
13
|
+
toBytes32String,
|
|
14
|
+
} from './derivation';
|
|
15
|
+
|
|
16
|
+
describe('deriveWalletPathFromSponsorAddress', () => {
|
|
17
|
+
it('converts address to derivation path', () => {
|
|
18
|
+
const sponsorAddress = '0x8A45eac0267dD0803Fd957723EdE10693A076698';
|
|
19
|
+
const res = deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER);
|
|
20
|
+
expect(res).toBe('5/973563544/2109481170/2137349576/871269377/610184194/17');
|
|
21
|
+
|
|
22
|
+
const randomAddress = ethers.utils.getAddress(ethers.utils.hexlify(ethers.utils.randomBytes(20)));
|
|
23
|
+
const randomPath = deriveWalletPathFromSponsorAddress(randomAddress, PROTOCOL_IDS.AIRSEEKER);
|
|
24
|
+
expect(res).not.toStrictEqual(randomPath);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('converts zero address to derivation path', () => {
|
|
28
|
+
const sponsorAddress = ethers.constants.AddressZero;
|
|
29
|
+
const res = deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER);
|
|
30
|
+
expect(res).toBe('5/0/0/0/0/0/0');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('throws if address is null', () => {
|
|
34
|
+
const sponsorAddress = null;
|
|
35
|
+
expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress!, PROTOCOL_IDS.AIRSEEKER)).toThrow(
|
|
36
|
+
expect.objectContaining({ name: expect.stringContaining('Error') })
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('throws if address is undefined', () => {
|
|
41
|
+
const sponsorAddress = undefined;
|
|
42
|
+
expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress!, PROTOCOL_IDS.AIRSEEKER)).toThrow(
|
|
43
|
+
expect.objectContaining({ name: expect.stringContaining('Error') })
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('throws if address is an empty string', () => {
|
|
48
|
+
const sponsorAddress = '';
|
|
49
|
+
expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER)).toThrow(
|
|
50
|
+
expect.objectContaining({ name: expect.stringContaining('Error') })
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('throws if address is invalid', () => {
|
|
55
|
+
let sponsorAddress = '7dD0803Fd957723EdE10693A076698';
|
|
56
|
+
expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER)).toThrow(
|
|
57
|
+
expect.objectContaining({ name: expect.stringContaining('Error') })
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
sponsorAddress = ethers.utils.hexlify(ethers.utils.randomBytes(4));
|
|
61
|
+
expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER)).toThrow(
|
|
62
|
+
expect.objectContaining({ name: expect.stringContaining('Error') })
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
sponsorAddress = ethers.utils.hexlify(ethers.utils.randomBytes(32));
|
|
66
|
+
expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER)).toThrow(
|
|
67
|
+
expect.objectContaining({ name: expect.stringContaining('Error') })
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('blockchain utilities', () => {
|
|
72
|
+
it('derives a sponsor wallet', () => {
|
|
73
|
+
const dapiName = ethers.utils.formatBytes32String('BTC/ETH');
|
|
74
|
+
const sponsorWallet = deriveSponsorWallet(
|
|
75
|
+
'test test test test test test test test test test test junk',
|
|
76
|
+
dapiName
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(sponsorWallet.address).toBe('0x1e6f0dfb1775f5032f12f56a01526351eD3F07aF');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('throws deriving a sponsor wallet due to an invalid DApi name', () => {
|
|
83
|
+
const dapiName = 'invalid dapi name';
|
|
84
|
+
const throwingFn = () =>
|
|
85
|
+
deriveSponsorWallet('test test test test test test test test test test test junk', dapiName);
|
|
86
|
+
|
|
87
|
+
expect(throwingFn).toThrow(expect.objectContaining({ name: expect.stringContaining('Error') }));
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it(`derives an airnode's xpub from a mnemonic`, () => {
|
|
91
|
+
const xpub = deriveAirnodeXpub('test test test test test test test test test test test junk');
|
|
92
|
+
|
|
93
|
+
expect(xpub).toBe(
|
|
94
|
+
'xpub6Ce9NcJvTk36xtLSrJLZqE7wtgA5deCeYs7rSQtreh4cj6ByPtrg9sD7V2FNFLPnf8heNP3FGkeV9qwfzvZNSd54JoNXVsXFYSYwHsnJxqP'
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it(`derives an endpoint ID`, () => {
|
|
99
|
+
const endpointId = deriveEndpointId('weather', 'temperature');
|
|
100
|
+
|
|
101
|
+
expect(endpointId).toBe('0x5a82d40e44ecd3ef0906e9e82c1a20f2f4ffe4f613ac70f999047496a9cd4635');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it(`it derives a template ID`, () => {
|
|
105
|
+
const templateId = deriveTemplateId({
|
|
106
|
+
airnode: '0x4E95C31894a89CdC4288669A6F294836948c862b',
|
|
107
|
+
endpointId: '0x5a82d40e44ecd3ef0906e9e82c1a20f2f4ffe4f613ac70f999047496a9cd4635',
|
|
108
|
+
encodedParameters: '0x1234',
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(templateId).toBe('0x7655363f294273f84bcc7c47d79858cf46f21951deee92746d9f17a69ac0b0c0');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('derives a beacon ID', () => {
|
|
115
|
+
const beaconId = deriveBeaconId(
|
|
116
|
+
'0xc52EeA00154B4fF1EbbF8Ba39FDe37F1AC3B9Fd4',
|
|
117
|
+
'0x457a3b3da67e394a895ea49e534a4d91b2d009477bef15eab8cbed313925b010'
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
expect(beaconId).toBe('0xf5c140bcb4814dfec311d38f6293e86c02d32ba1b7da027fe5b5202cae35dbc6');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it(`derives a beacon set ID`, () => {
|
|
124
|
+
const beaconSetId = deriveBeaconSetId([
|
|
125
|
+
'0x0e30ed302a3c8eeaa0053caf5fbd0825c86ce1767584d12c69c310f0068b1176',
|
|
126
|
+
'0x496092597aef79595df1567412c6ddefd037f63a5a1572702dd469f62f31f469',
|
|
127
|
+
'0x84c1da28b2f29f0a2b0ff360d537d405d1cd69249fcf5f32ae9c2298cee6da12',
|
|
128
|
+
'0xe8655dc68f2b765c5e6d4a042ba7ba8606cf37e1c8c96676f85364ec5bfe9163',
|
|
129
|
+
'0xf5c140bcb4814dfec311d38f6293e86c02d32ba1b7da027fe5b5202cae35dbc6',
|
|
130
|
+
]);
|
|
131
|
+
|
|
132
|
+
expect(beaconSetId).toBe('0x33bf380fd5b06a317a905b23eaf5c61ef0a9b4a20589a1bf1d13133daca34b0e');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('encodes a string as a bytes32 string', () => {
|
|
136
|
+
const formattedString = toBytes32String('test string');
|
|
137
|
+
|
|
138
|
+
expect(formattedString).toBe('0x7465737420737472696e67000000000000000000000000000000000000000000');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('decodes a bytes32 string to a normal string', () => {
|
|
142
|
+
const formattedString = fromBytes32String('0x7465737420737472696e67000000000000000000000000000000000000000000');
|
|
143
|
+
|
|
144
|
+
expect(formattedString).toBe('test string');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|