Skip to content

Commit

Permalink
Support processing v2 (#1914)
Browse files Browse the repository at this point in the history
* Support processing v2

* Migrate to processing after naming changes

* Remove redundant check

* Update ois and commons

* Add changeset

* Fix tests

* Update OIS version properly

* Use [email protected] and remove typing hacks

* Fix processing snippets, apply PR suggestions

* Properly apply PR suggestions
  • Loading branch information
Siegrift authored Dec 1, 2023
1 parent 3a05d77 commit 37d5a12
Show file tree
Hide file tree
Showing 41 changed files with 280 additions and 334 deletions.
6 changes: 6 additions & 0 deletions .changeset/mighty-parents-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@api3/airnode-examples': minor
'@api3/airnode-node': minor
---

Support OIS processing v2
2 changes: 1 addition & 1 deletion packages/airnode-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test:watch": "yarn test:ts --watch"
},
"dependencies": {
"@api3/ois": "2.2.1",
"@api3/ois": "2.3.1",
"@api3/promise-utils": "^0.4.0",
"axios": "^1.5.0",
"bignumber.js": "^9.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-adapter/test/fixtures/ois.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OIS } from '@api3/ois';

export function buildOIS(overrides?: Partial<OIS>): OIS {
return {
oisFormat: '2.2.1',
oisFormat: '2.3.1',
version: '1.2.3',
title: 'Currency Converter API',
apiSpecifications: {
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-deployer/config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-deployer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"lodash": "^4.17.21",
"ora": "^5.4.1",
"yargs": "^17.7.2",
"zod": "^3.22.3"
"zod": "^3.22.4"
},
"devDependencies": {
"@aws-sdk/util-stream-node": "^3.370.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "CoinMarketCap Basic Authenticated Request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.2.1',
oisFormat: '2.3.1',
title: 'CoinMarketCap Basic Authenticated Request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.2.1',
oisFormat: '2.3.1',
title: 'CoinGecko basic request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.2.1',
oisFormat: '2.3.1',
title: 'CoinGecko basic request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "CoinGecko coins markets request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down Expand Up @@ -196,13 +196,11 @@
}
}
],
"postProcessingSpecifications": [
{
"environment": "Node",
"timeoutMs": 5000,
"value": "\n // Log out every coin data\n input.forEach((coinData) => {\n console.log(`[Post-processing snippet]: Received the following coin data: \\${JSON.stringify(coinData, null, 2)}`)\n })\n\n const sum = (nums) => nums.reduce((acc, num) => acc + num, 0);\n const average = sum(input.map((coinData) => coinData.current_price)) / input.length;\n const percentageChange = sum(input.map((coinData) => coinData.price_change_percentage_30d_in_currency)) / input.length;\n\n // Create the data to be sent on chain and multiply it by 10^8 to preserve precision\n const output = [average, percentageChange].map((x) => x * 10 ** 8);\n "
}
]
"postProcessingSpecificationV2": {
"environment": "Node",
"timeoutMs": 5000,
"value": "async function({ response }) {\n // Log out every coin data\n response.forEach((coinData) => {\n console.log(`[Post-processing snippet]: Received the following coin data: \\${JSON.stringify(coinData, null, 2)}`);\n });\n\n const sum = (nums) => nums.reduce((acc, num) => acc + num, 0);\n const average = sum(response.map((coinData) => coinData.current_price)) / response.length;\n const percentageChange =\n sum(response.map((coinData) => coinData.price_change_percentage_30d_in_currency)) / response.length;\n\n // Create the data to be sent on chain and multiply it by 10^8 to preserve precision\n return { response: [average, percentageChange].map((x) => x * 10 ** 8) };\n}"
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.2.1',
oisFormat: '2.3.1',
title: 'CoinGecko coins markets request',
version: '1.0.0',
apiSpecifications: {
Expand Down Expand Up @@ -203,25 +203,26 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
},
},
],
postProcessingSpecifications: [
{
environment: 'Node',
timeoutMs: 5000,
value: `
// Log out every coin data
input.forEach((coinData) => {
console.log(\`[Post-processing snippet]: Received the following coin data: \\\${JSON.stringify(coinData, null, 2)}\`)
})
postProcessingSpecificationV2: {
environment: 'Node',
timeoutMs: 5000,
value: `
async function({ response }) {
// Log out every coin data
response.forEach((coinData) => {
console.log(\`[Post-processing snippet]: Received the following coin data: \\\${JSON.stringify(coinData, null, 2)}\`);
});
const sum = (nums) => nums.reduce((acc, num) => acc + num, 0);
const average = sum(input.map((coinData) => coinData.current_price)) / input.length;
const percentageChange = sum(input.map((coinData) => coinData.price_change_percentage_30d_in_currency)) / input.length;
const sum = (nums) => nums.reduce((acc, num) => acc + num, 0);
const average = sum(response.map((coinData) => coinData.current_price)) / response.length;
const percentageChange =
sum(response.map((coinData) => coinData.price_change_percentage_30d_in_currency)) / response.length;
// Create the data to be sent on chain and multiply it by 10^8 to preserve precision
const output = [average, percentageChange].map((x) => x * 10 ** 8);
`,
},
],
// Create the data to be sent on chain and multiply it by 10^8 to preserve precision
return { response: [average, percentageChange].map((x) => x * 10 ** 8) };
}
`.trim(),
},
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "CoinGecko history data request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down Expand Up @@ -163,13 +163,11 @@
}
}
],
"preProcessingSpecifications": [
{
"environment": "Node",
"timeoutMs": 5000,
"value": "\n const rawDate = new Date(input.unixTimestamp * 1000);\n const day = rawDate.getDate().toString().padStart(2, '0');\n const month = (rawDate.getMonth() + 1).toString().padStart(2, '0'); // Months start at 0\n const year = rawDate.getFullYear();\n\n const formattedDate = day + '-' + month + '-' + year;\n const output = {...input, unixTimestamp: formattedDate};\n\n console.log(`[Pre-processing snippet]: Formatted \\${input.unixTimestamp} to \\${formattedDate}.`)\n "
}
]
"preProcessingSpecificationV2": {
"environment": "Node",
"timeoutMs": 5000,
"value": "async ({endpointParameters}) => {\n const rawDate = new Date(endpointParameters.unixTimestamp * 1000);\n const day = rawDate.getDate().toString().padStart(2, '0');\n const month = (rawDate.getMonth() + 1).toString().padStart(2, '0'); // Months start at 0\n const year = rawDate.getFullYear();\n\n const formattedDate = day + '-' + month + '-' + year;\n const newEndpointParameters = {...endpointParameters, unixTimestamp: formattedDate};\n\n console.log(`[Pre-processing snippet]: Formatted \\${endpointParameters.unixTimestamp} to \\${formattedDate}.`)\n return {endpointParameters: newEndpointParameters};\n}"
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.2.1',
oisFormat: '2.3.1',
title: 'CoinGecko history data request',
version: '1.0.0',
apiSpecifications: {
Expand Down Expand Up @@ -170,23 +170,24 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
},
},
],
preProcessingSpecifications: [
{
environment: 'Node',
timeoutMs: 5000,
value: `
const rawDate = new Date(input.unixTimestamp * 1000);
const day = rawDate.getDate().toString().padStart(2, '0');
const month = (rawDate.getMonth() + 1).toString().padStart(2, '0'); // Months start at 0
const year = rawDate.getFullYear();
preProcessingSpecificationV2: {
environment: 'Node',
timeoutMs: 5000,
value: `
async ({endpointParameters}) => {
const rawDate = new Date(endpointParameters.unixTimestamp * 1000);
const day = rawDate.getDate().toString().padStart(2, '0');
const month = (rawDate.getMonth() + 1).toString().padStart(2, '0'); // Months start at 0
const year = rawDate.getFullYear();
const formattedDate = day + '-' + month + '-' + year;
const output = {...input, unixTimestamp: formattedDate};
const formattedDate = day + '-' + month + '-' + year;
const newEndpointParameters = {...endpointParameters, unixTimestamp: formattedDate};
console.log(\`[Pre-processing snippet]: Formatted \\\${input.unixTimestamp} to \\\${formattedDate}.\`)
`,
},
],
console.log(\`[Pre-processing snippet]: Formatted \\\${endpointParameters.unixTimestamp} to \\\${formattedDate}.\`)
return {endpointParameters: newEndpointParameters};
}
`.trim(),
},
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
],
ois: [
{
oisFormat: '2.2.1',
oisFormat: '2.3.1',
title: 'CoinGecko basic request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.2.1',
oisFormat: '2.3.1',
title: 'CoinGecko basic request',
version: '1.0.0',
apiSpecifications: {
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-examples/integrations/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const addAirnodeRrpV0DryRunAddress = async (config: Config) => {

export const generateConfigFile = async (dirname: string, config: Config, generateExampleFile: boolean) => {
const filename = generateExampleFile ? 'config.example.json' : 'config.json';
const updatedConfig = await addAirnodeRrpV0DryRunAddress(config);
const updatedConfig = generateExampleFile ? config : await addAirnodeRrpV0DryRunAddress(config);
const formattedConfig = await format(JSON.stringify(updatedConfig, null, 2), { parser: 'json', printWidth: 120 });
writeFileSync(join(dirname, filename), formattedConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "Failure Example",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.2.1',
oisFormat: '2.3.1',
title: 'Failure Example',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "Relay Security Schemes via httpbin",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.2.1',
oisFormat: '2.3.1',
title: 'Relay Security Schemes via httpbin',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"title": "OpenWeather Multiple Encoded Values",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.2.1',
oisFormat: '2.3.1',
title: 'OpenWeather Multiple Encoded Values',
version: '1.0.0',
apiSpecifications: {
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-node/config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.2.1",
"oisFormat": "2.3.1",
"version": "1.2.3",
"title": "Currency Converter API",
"apiSpecifications": {
Expand Down
Loading

0 comments on commit 37d5a12

Please sign in to comment.