@api3/commons 0.4.1 → 0.6.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.
Files changed (33) hide show
  1. package/README.md +6 -4
  2. package/dist/blockchain-utilities/derivation.d.ts +78 -0
  3. package/dist/blockchain-utilities/derivation.d.ts.map +1 -0
  4. package/dist/blockchain-utilities/derivation.js +97 -0
  5. package/dist/blockchain-utilities/derivation.js.map +1 -0
  6. package/dist/blockchain-utilities/schema.d.ts +12 -0
  7. package/dist/blockchain-utilities/schema.d.ts.map +1 -0
  8. package/dist/blockchain-utilities/schema.js +13 -0
  9. package/dist/blockchain-utilities/schema.js.map +1 -0
  10. package/dist/processing/processing.d.ts +70 -18
  11. package/dist/processing/processing.d.ts.map +1 -1
  12. package/dist/processing/processing.js +145 -37
  13. package/dist/processing/processing.js.map +1 -1
  14. package/dist/processing/schema.d.ts +25 -2
  15. package/dist/processing/schema.d.ts.map +1 -1
  16. package/dist/processing/schema.js +10 -9
  17. package/dist/processing/schema.js.map +1 -1
  18. package/dist/processing/unsafe-evaluate.d.ts +1 -0
  19. package/dist/processing/unsafe-evaluate.d.ts.map +1 -1
  20. package/dist/processing/unsafe-evaluate.js +31 -1
  21. package/dist/processing/unsafe-evaluate.js.map +1 -1
  22. package/package.json +6 -4
  23. package/src/blockchain-utilities/README.md +5 -0
  24. package/src/blockchain-utilities/derivation.test.ts +147 -0
  25. package/src/blockchain-utilities/derivation.ts +116 -0
  26. package/src/blockchain-utilities/schema.test.ts +23 -0
  27. package/src/blockchain-utilities/schema.ts +14 -0
  28. package/src/processing/README.md +89 -14
  29. package/src/processing/processing.test.ts +431 -113
  30. package/src/processing/processing.ts +196 -47
  31. package/src/processing/schema.ts +21 -8
  32. package/src/processing/unsafe-evaluate.test.ts +220 -1
  33. package/src/processing/unsafe-evaluate.ts +39 -0
package/README.md CHANGED
@@ -43,12 +43,14 @@ import { createLogger } from '@api3/commons/logger';
43
43
 
44
44
  To release a new version follow these steps:
45
45
 
46
- 1. `git checkout main` - Always publish from `main` branch. Also, ensure that the working directory is clean (has no
47
- uncommitted changes).
46
+ 1. `git checkout main && git pull` - Always publish from up to date `main` branch. Also, ensure that the working
47
+ directory is clean (has no uncommitted changes).
48
48
  2. `pnpm version [major|minor|patch]` - Choose the right version bump. This will bump the version, create a git tag and
49
49
  commit it.
50
- 3. `pnpm publish --access public` - Publish the new version to NPM.
51
- 4. `git push --follow-tags` - Push the tagged commit upstream.
50
+ 3. `pnpm publish --access public` - Build the package and publish the new version to NPM.
51
+ 4. `git push --follow-tags` - Push the tagged commit upstream. If you don't have access to push directly to main branch,
52
+ create a separate branch and open a PR. This PR must be merged using the "Rebase and merge" strategy to preserve the
53
+ git tag.
52
54
  5. Create a new [release on GitHub](https://github.com/api3dao/commons/releases). Use the "Generate release notes"
53
55
  feature to generate the release notes from the PR titles.
54
56
 
@@ -0,0 +1,78 @@
1
+ import { ethers } from 'ethers';
2
+ export declare const PROTOCOL_IDS: {
3
+ RRP: string;
4
+ PSP: string;
5
+ RELAYED_RRP: string;
6
+ RELAYED_PSP: string;
7
+ AIRSEEKER: string;
8
+ };
9
+ /**
10
+ * An interface that reflects the structure of a Template
11
+ */
12
+ export interface Template {
13
+ airnode: string;
14
+ encodedParameters: string;
15
+ endpointId: string;
16
+ }
17
+ /**
18
+ * Derives a template ID from the input parameters
19
+ *
20
+ * @param airnode an Airnode address
21
+ * @param encodedParameters encoded parameters, see the airnode/abi package's encode function
22
+ * @param endpointId An endpointID (see deriveEndpointId)
23
+ */
24
+ export declare const deriveTemplateId: ({ airnode, encodedParameters, endpointId }: Template) => string;
25
+ /**
26
+ * Derives an endpoint ID
27
+ *
28
+ * @param oisTitle the OIS title
29
+ * @param endpointName the endpoint name
30
+ */
31
+ export declare const deriveEndpointId: (oisTitle: string, endpointName: string) => string;
32
+ /**
33
+ * Derives an airnode address's xpub, required for allowing signed data consumers to verify authenticity
34
+ *
35
+ * @param airnodeMnemonic the airnode's mnemonic
36
+ */
37
+ export declare const deriveAirnodeXpub: (airnodeMnemonic: string) => string;
38
+ /**
39
+ * Derives a wallet path from a sponsor address, used for calculating a sponsor wallet.
40
+ *
41
+ * @param sponsorAddress an EVM-compatible address
42
+ * @param protocolId an API application protocol ID
43
+ */
44
+ export declare function deriveWalletPathFromSponsorAddress(sponsorAddress: string, protocolId: string): string;
45
+ /**
46
+ * Encodes/formats a string as a hex-encoded bytes32 string.
47
+ *
48
+ * @param input the input string
49
+ */
50
+ export declare const toBytes32String: (input: string) => string;
51
+ /**
52
+ * Decodes a hex-encoded bytes32 string to a normal string.
53
+ *
54
+ * @param input the input hex string
55
+ */
56
+ export declare const fromBytes32String: (input: string) => string;
57
+ /**
58
+ * Derives a sponsor wallet, given a mnemonic and dapiName.
59
+ *
60
+ * @param sponsorWalletMnemonic the sponsor wallet mnemonic
61
+ * @param dapiName the dapi name
62
+ */
63
+ export declare const deriveSponsorWallet: (sponsorWalletMnemonic: string, dapiName: string) => ethers.Wallet;
64
+ /**
65
+ * Derives the ID of a single beacon
66
+ *
67
+ * @param airnodeAddress the airnode address of the provider that supplies the data used to update this beacon
68
+ * @param templateId the templateId of the template used to generate the data used to update this beacon
69
+ */
70
+ export declare const deriveBeaconId: (airnodeAddress: string, templateId: string) => string;
71
+ /**
72
+ * Derives the ID of a set of beacons.
73
+ * By convention beacon IDs are sorted alphabetically - the ordering impacts the resulting hash.
74
+ *
75
+ * @param beaconIds an ordered array of beacon ids
76
+ */
77
+ export declare const deriveBeaconSetId: (beaconIds: string[]) => string;
78
+ //# sourceMappingURL=derivation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derivation.d.ts","sourceRoot":"","sources":["../../src/blockchain-utilities/derivation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,eAAO,MAAM,YAAY;;;;;;CAMxB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,+CAAgD,QAAQ,WACsB,CAAC;AAE5G;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,aAAc,MAAM,gBAAgB,MAAM,WACsC,CAAC;AAE9G;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,oBAAqB,MAAM,WAC0C,CAAC;AAEpG;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAAC,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAU5F;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,UAAW,MAAM,WAA4C,CAAC;AAE1F;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,UAAW,MAAM,WAA2C,CAAC;AAE3F;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,0BAA2B,MAAM,YAAY,MAAM,kBAWlF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,mBAAoB,MAAM,cAAc,MAAM,WACa,CAAC;AAEvF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,cAAe,MAAM,EAAE,WACoC,CAAC"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deriveBeaconSetId = exports.deriveBeaconId = exports.deriveSponsorWallet = exports.fromBytes32String = exports.toBytes32String = exports.deriveWalletPathFromSponsorAddress = exports.deriveAirnodeXpub = exports.deriveEndpointId = exports.deriveTemplateId = exports.PROTOCOL_IDS = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const schema_1 = require("./schema");
6
+ exports.PROTOCOL_IDS = {
7
+ RRP: '1',
8
+ PSP: '2',
9
+ RELAYED_RRP: '3',
10
+ RELAYED_PSP: '4',
11
+ AIRSEEKER: '5',
12
+ };
13
+ /**
14
+ * Derives a template ID from the input parameters
15
+ *
16
+ * @param airnode an Airnode address
17
+ * @param encodedParameters encoded parameters, see the airnode/abi package's encode function
18
+ * @param endpointId An endpointID (see deriveEndpointId)
19
+ */
20
+ const deriveTemplateId = ({ airnode, encodedParameters, endpointId }) => ethers_1.ethers.utils.solidityKeccak256(['address', 'bytes32', 'bytes'], [airnode, endpointId, encodedParameters]);
21
+ exports.deriveTemplateId = deriveTemplateId;
22
+ /**
23
+ * Derives an endpoint ID
24
+ *
25
+ * @param oisTitle the OIS title
26
+ * @param endpointName the endpoint name
27
+ */
28
+ const deriveEndpointId = (oisTitle, endpointName) => ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.defaultAbiCoder.encode(['string', 'string'], [oisTitle, endpointName]));
29
+ exports.deriveEndpointId = deriveEndpointId;
30
+ /**
31
+ * Derives an airnode address's xpub, required for allowing signed data consumers to verify authenticity
32
+ *
33
+ * @param airnodeMnemonic the airnode's mnemonic
34
+ */
35
+ const deriveAirnodeXpub = (airnodeMnemonic) => ethers_1.ethers.utils.HDNode.fromMnemonic(airnodeMnemonic).derivePath("m/44'/60'/0'").neuter().extendedKey;
36
+ exports.deriveAirnodeXpub = deriveAirnodeXpub;
37
+ /**
38
+ * Derives a wallet path from a sponsor address, used for calculating a sponsor wallet.
39
+ *
40
+ * @param sponsorAddress an EVM-compatible address
41
+ * @param protocolId an API application protocol ID
42
+ */
43
+ function deriveWalletPathFromSponsorAddress(sponsorAddress, protocolId) {
44
+ schema_1.addressSchema.parse(sponsorAddress);
45
+ const sponsorAddressBN = ethers_1.ethers.BigNumber.from(sponsorAddress);
46
+ const paths = [];
47
+ for (let i = 0; i < 6; i++) {
48
+ const shiftedSponsorAddressBN = sponsorAddressBN.shr(31 * i);
49
+ paths.push(shiftedSponsorAddressBN.mask(31).toString());
50
+ }
51
+ return `${protocolId}/${paths.join('/')}`;
52
+ }
53
+ exports.deriveWalletPathFromSponsorAddress = deriveWalletPathFromSponsorAddress;
54
+ /**
55
+ * Encodes/formats a string as a hex-encoded bytes32 string.
56
+ *
57
+ * @param input the input string
58
+ */
59
+ const toBytes32String = (input) => ethers_1.ethers.utils.formatBytes32String(input);
60
+ exports.toBytes32String = toBytes32String;
61
+ /**
62
+ * Decodes a hex-encoded bytes32 string to a normal string.
63
+ *
64
+ * @param input the input hex string
65
+ */
66
+ const fromBytes32String = (input) => ethers_1.ethers.utils.parseBytes32String(input);
67
+ exports.fromBytes32String = fromBytes32String;
68
+ /**
69
+ * Derives a sponsor wallet, given a mnemonic and dapiName.
70
+ *
71
+ * @param sponsorWalletMnemonic the sponsor wallet mnemonic
72
+ * @param dapiName the dapi name
73
+ */
74
+ const deriveSponsorWallet = (sponsorWalletMnemonic, dapiName) => {
75
+ // Take first 20 bytes of dapiName as sponsor address together with the "0x" prefix.
76
+ const sponsorAddress = ethers_1.ethers.utils.getAddress(dapiName.slice(0, 42));
77
+ const sponsorWallet = ethers_1.ethers.Wallet.fromMnemonic(sponsorWalletMnemonic, `m/44'/60'/0'/${(deriveWalletPathFromSponsorAddress(sponsorAddress, exports.PROTOCOL_IDS.AIRSEEKER), exports.PROTOCOL_IDS.AIRSEEKER)}`);
78
+ return sponsorWallet;
79
+ };
80
+ exports.deriveSponsorWallet = deriveSponsorWallet;
81
+ /**
82
+ * Derives the ID of a single beacon
83
+ *
84
+ * @param airnodeAddress the airnode address of the provider that supplies the data used to update this beacon
85
+ * @param templateId the templateId of the template used to generate the data used to update this beacon
86
+ */
87
+ const deriveBeaconId = (airnodeAddress, templateId) => ethers_1.ethers.utils.solidityKeccak256(['address', 'bytes32'], [airnodeAddress, templateId]);
88
+ exports.deriveBeaconId = deriveBeaconId;
89
+ /**
90
+ * Derives the ID of a set of beacons.
91
+ * By convention beacon IDs are sorted alphabetically - the ordering impacts the resulting hash.
92
+ *
93
+ * @param beaconIds an ordered array of beacon ids
94
+ */
95
+ const deriveBeaconSetId = (beaconIds) => ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.defaultAbiCoder.encode(['bytes32[]'], [beaconIds]));
96
+ exports.deriveBeaconSetId = deriveBeaconSetId;
97
+ //# sourceMappingURL=derivation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derivation.js","sourceRoot":"","sources":["../../src/blockchain-utilities/derivation.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * A Zod validation schema that represents an EVM-compatible address.
4
+ */
5
+ export declare const addressSchema: z.ZodString;
6
+ /**
7
+ * A Zod validation schema that represents an EVM-compatible hash, which includes beacon IDs and template IDs.
8
+ */
9
+ export declare const idSchema: z.ZodString;
10
+ export type Address = z.infer<typeof addressSchema>;
11
+ export type Id = z.infer<typeof idSchema>;
12
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/blockchain-utilities/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,aAAa,aAAwE,CAAC;AAEnG;;GAEG;AACH,eAAO,MAAM,QAAQ,aAAqE,CAAC;AAE3F,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,MAAM,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.idSchema = exports.addressSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * A Zod validation schema that represents an EVM-compatible address.
7
+ */
8
+ exports.addressSchema = zod_1.z.string().regex(/^0x[\dA-Fa-f]{40}$/, 'Must be a valid EVM address');
9
+ /**
10
+ * A Zod validation schema that represents an EVM-compatible hash, which includes beacon IDs and template IDs.
11
+ */
12
+ exports.idSchema = zod_1.z.string().regex(/^0x[\dA-Fa-f]{64}$/, 'Must be a valid EVM hash');
13
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/blockchain-utilities/schema.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB;;GAEG;AACU,QAAA,aAAa,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,oBAAoB,EAAE,6BAA6B,CAAC,CAAC;AAEnG;;GAEG;AACU,QAAA,QAAQ,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,oBAAoB,EAAE,0BAA0B,CAAC,CAAC"}
@@ -1,39 +1,91 @@
1
1
  import { type Endpoint } from '@api3/ois';
2
2
  import { type GoAsyncOptions } from '@api3/promise-utils';
3
- import { type ApiCallParameters } from './schema';
3
+ import { type EndpointParameters, type PreProcessingV2Response, type PostProcessingV2Response, type ProcessingSpecificationV2, type ProcessingSpecifications } from './schema';
4
4
  export declare const DEFAULT_PROCESSING_TIMEOUT_MS = 10000;
5
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.
6
+ * Removes reserved parameters from the endpoint parameters.
7
+ * @param parameters The endpoint parameters from which reserved parameters will be removed.
8
+ * @returns The endpoint parameters without reserved parameters.
9
9
  */
10
- export declare const removeReservedParameters: (parameters: ApiCallParameters) => ApiCallParameters;
10
+ export declare const removeReservedParameters: (parameters: EndpointParameters) => EndpointParameters;
11
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.
12
+ * Re-inserts reserved parameters from the initial endpoint parameters into the modified endpoint parameters.
13
+ * @param initialParameters The initial endpoint parameters that might contain reserved parameters.
14
+ * @param modifiedParameters The modified endpoint parameters to which reserved parameters will be added.
15
+ * @returns The modified endpoint parameters with re-inserted reserved parameters.
16
16
  */
17
- export declare const addReservedParameters: (initialParameters: ApiCallParameters, modifiedParameters: ApiCallParameters) => ApiCallParameters;
17
+ export declare const addReservedParameters: (initialParameters: EndpointParameters, modifiedParameters: EndpointParameters) => EndpointParameters;
18
18
  /**
19
- * Pre-processes API call parameters based on the provided endpoint's processing specifications.
19
+ * Pre-processes endpoint parameters based on the provided endpoint's processing specifications.
20
+ *
21
+ * @param preProcessingSpecifications The v1 pre-processing specifications.
22
+ * @param endpointParameters 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 preProcessEndpointParametersV1: (preProcessingSpecifications: ProcessingSpecifications | undefined, endpointParameters: EndpointParameters, processingOptions?: GoAsyncOptions) => Promise<EndpointParameters>;
28
+ /**
29
+ * Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
30
+ * API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
31
+ * allows skipping API calls in which case the response is the result of pre-processing.
32
+ *
33
+ * @param response The response to be post-processed.
34
+ * @param postProcessingSpecifications The v1 post-processing specifications.
35
+ * @param endpointParameters The endpoint parameters.
36
+ * @param processingOptions Options to control the async processing behavior like retries and timeouts.
37
+ *
38
+ * @returns A promise that resolves to the post-processed response.
39
+ */
40
+ export declare const postProcessResponseV1: (response: unknown, postProcessingSpecifications: ProcessingSpecifications | undefined, endpointParameters: EndpointParameters, processingOptions?: GoAsyncOptions) => Promise<unknown>;
41
+ /**
42
+ * Pre-processes endpoint parameters based on the provided endpoint's processing specifications.
43
+ *
44
+ * @param preProcessingSpecificationV2 The v2 pre-processing specification.
45
+ * @param endpointParameters The parameters to be pre-processed.
46
+ * @param processingOptions Options to control the async processing behavior like retries and timeouts.
47
+ *
48
+ * @returns A promise that resolves to the pre-processed parameters.
49
+ */
50
+ export declare const preProcessEndpointParametersV2: (preProcessingSpecificationV2: ProcessingSpecificationV2 | undefined, endpointParameters: EndpointParameters, processingOptions?: GoAsyncOptions) => Promise<PreProcessingV2Response>;
51
+ /**
52
+ * Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
53
+ * API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
54
+ * allows skipping API calls in which case the response is the result of pre-processing.
55
+ *
56
+ * @param response The response to be post-processed.
57
+ * @param postProcessingSpecificationV2 The v2 post-processing specification.
58
+ * @param endpointParameters The endpoint parameters.
59
+ * @param processingOptions Options to control the async processing behavior like retries and timeouts.
60
+ *
61
+ * @returns A promise that resolves to the post-processed response.
62
+ */
63
+ export declare const postProcessResponseV2: (response: unknown, postProcessingSpecificationV2: ProcessingSpecificationV2 | undefined, endpointParameters: EndpointParameters, processingOptions?: GoAsyncOptions) => Promise<PostProcessingV2Response>;
64
+ /**
65
+ * Pre-processes endpoint parameters based on the provided endpoint's processing specifications. Internally it
66
+ * determines what processing implementation should be used.
20
67
  *
21
68
  * @param endpoint The endpoint containing processing specifications.
22
- * @param apiCallParameters The parameters to be pre-processed.
69
+ * @param endpointParameters The parameters to be pre-processed.
23
70
  * @param processingOptions Options to control the async processing behavior like retries and timeouts.
24
71
  *
25
72
  * @returns A promise that resolves to the pre-processed parameters.
26
73
  */
27
- export declare const preProcessApiCallParameters: (endpoint: Endpoint, apiCallParameters: ApiCallParameters, processingOptions?: GoAsyncOptions) => Promise<ApiCallParameters>;
74
+ export declare const preProcessEndpointParameters: (endpoint: Endpoint, endpointParameters: EndpointParameters, processingOptions?: GoAsyncOptions) => Promise<PreProcessingV2Response>;
28
75
  /**
29
- * Post-processes the API call response based on the provided endpoint's processing specifications.
76
+ * Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
77
+ * API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
78
+ * allows skipping API calls in which case the response is the result of pre-processing.
79
+ *
80
+ * This function determines what processing version should be used and provides a common interface. This is useful for
81
+ * services that want to use processing and don't care which processing version is used.
30
82
  *
31
- * @param apiCallResponse The raw response obtained from the API call.
83
+ * @param response The response to be post-processed.
32
84
  * @param endpoint The endpoint containing processing specifications.
33
- * @param apiCallParameters The parameters used in the API call.
85
+ * @param endpointParameters The endpoint parameters.
34
86
  * @param processingOptions Options to control the async processing behavior like retries and timeouts.
35
87
  *
36
- * @returns A promise that resolves to the post-processed API call response.
88
+ * @returns A promise that resolves to the post-processed response.
37
89
  */
38
- export declare const postProcessApiCallResponse: (apiCallResponse: unknown, endpoint: Endpoint, apiCallParameters: ApiCallParameters, processingOptions?: GoAsyncOptions) => Promise<unknown>;
90
+ export declare const postProcessResponse: (response: unknown, endpoint: Endpoint, endpointParameters: EndpointParameters, processingOptions?: GoAsyncOptions) => Promise<PostProcessingV2Response>;
39
91
  //# sourceMappingURL=processing.d.ts.map
@@ -1 +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,EAA6B,MAAM,UAAU,CAAC;AAG7E,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"}
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,EACL,KAAK,kBAAkB,EAIvB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC9B,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAIpD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,eAAgB,kBAAkB,KAAG,kBAUzE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,sBACb,kBAAkB,sBACjB,kBAAkB,KACrC,kBAQF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,gCACZ,wBAAwB,GAAG,SAAS,sBAC7C,kBAAkB,sBACnB,cAAc,KAChC,QAAQ,kBAAkB,CA4C5B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,aACtB,OAAO,gCACa,wBAAwB,GAAG,SAAS,sBAC9C,kBAAkB,sBACnB,cAAc,qBAwClC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,iCACX,yBAAyB,GAAG,SAAS,sBAC/C,kBAAkB,sBACnB,cAAc,KAChC,QAAQ,uBAAuB,CAqBjC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,aACtB,OAAO,iCACc,yBAAyB,GAAG,SAAS,sBAChD,kBAAkB,sBACnB,cAAc,KAChC,QAAQ,wBAAwB,CAoBlC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,aAC7B,QAAQ,sBACE,kBAAkB,sBACnB,cAAc,KAChC,QAAQ,uBAAuB,CAYjC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,aACpB,OAAO,YACP,QAAQ,sBACE,kBAAkB,sBACnB,cAAc,KAChC,QAAQ,wBAAwB,CAalC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.postProcessApiCallResponse = exports.preProcessApiCallParameters = exports.addReservedParameters = exports.removeReservedParameters = exports.DEFAULT_PROCESSING_TIMEOUT_MS = void 0;
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 object.
12
- * @param parameters The API call parameters from which reserved parameters will be removed.
13
- * @returns The parameters object without reserved 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 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.
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 API call parameters based on the provided endpoint's processing specifications.
41
+ * Pre-processes endpoint parameters based on the provided endpoint's processing specifications.
42
42
  *
43
- * @param endpoint The endpoint containing processing specifications.
44
- * @param apiCallParameters The parameters to be pre-processed.
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 preProcessApiCallParameters = async (endpoint, apiCallParameters, processingOptions = { retries: 0, totalTimeoutMs: exports.DEFAULT_PROCESSING_TIMEOUT_MS }) => {
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 apiCallParameters;
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)(apiCallParameters);
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 endpointParameters = (0, exports.removeReservedParameters)(apiCallParameters);
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 = (0, schema_1.validateApiCallParameters)(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);
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.preProcessApiCallParameters = preProcessApiCallParameters;
81
+ exports.preProcessEndpointParametersV1 = preProcessEndpointParametersV1;
82
82
  /**
83
- * Post-processes the API call response based on the provided endpoint's processing specifications.
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 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.
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 API call response.
92
+ * @returns A promise that resolves to the post-processed response.
91
93
  */
92
- const postProcessApiCallResponse = async (apiCallResponse, endpoint, apiCallParameters, processingOptions = { retries: 0, totalTimeoutMs: exports.DEFAULT_PROCESSING_TIMEOUT_MS }) => {
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 apiCallResponse;
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 = apiCallResponse;
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 endpointParameters = (0, exports.removeReservedParameters)(apiCallParameters);
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.postProcessApiCallResponse = postProcessApiCallResponse;
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