Skip to content

Commit

Permalink
Widen allowed HTTP parameters (#1797)
Browse files Browse the repository at this point in the history
* Widen parameter type

* Fix validation tests

* Update @api3/ois fixtures

* Bump zod to match zod version in @api3/ois v2.1.0

---------

Co-authored-by: Derek Croote <[email protected]>
  • Loading branch information
aquarat and dcroote authored Jun 7, 2023
1 parent 031919e commit 0b7d89e
Show file tree
Hide file tree
Showing 42 changed files with 52 additions and 88 deletions.
6 changes: 6 additions & 0 deletions .changeset/flat-emus-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@api3/airnode-validator': minor
'@api3/airnode-node': minor
---

Widen accepted types for parameters to allow for native types to be sent as JSON
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.0.0",
"@api3/ois": "2.1.0",
"@api3/promise-utils": "^0.4.0",
"axios": "^1.4.0",
"bignumber.js": "^9.1.1",
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.0.0',
oisFormat: '2.1.0',
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.0.0",
"oisFormat": "2.1.0",
"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.20.6"
"zod": "^3.21.4"
},
"devDependencies": {
"@aws-sdk/util-stream-node": "^3.344.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.0.0",
"oisFormat": "2.1.0",
"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.0.0",
"oisFormat": "2.1.0",
"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.0.0",
"oisFormat": "2.1.0",
"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.0.0',
oisFormat: '2.1.0',
title: 'CoinMarketCap Basic Authenticated Request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.0.0",
"oisFormat": "2.1.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.0.0',
oisFormat: '2.1.0',
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.0.0",
"oisFormat": "2.1.0",
"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.0.0',
oisFormat: '2.1.0',
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.0.0",
"oisFormat": "2.1.0",
"title": "CoinGecko coins markets 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.0.0',
oisFormat: '2.1.0',
title: 'CoinGecko coins markets 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.0.0",
"oisFormat": "2.1.0",
"title": "CoinGecko history data 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.0.0',
oisFormat: '2.1.0',
title: 'CoinGecko history data request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
],
"ois": [
{
"oisFormat": "2.0.0",
"oisFormat": "2.1.0",
"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.0.0',
oisFormat: '2.1.0',
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.0.0",
"oisFormat": "2.1.0",
"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.0.0',
oisFormat: '2.1.0',
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.0.0",
"oisFormat": "2.1.0",
"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.0.0',
oisFormat: '2.1.0',
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.0.0",
"oisFormat": "2.1.0",
"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.0.0',
oisFormat: '2.1.0',
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.0.0",
"oisFormat": "2.1.0",
"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.0.0',
oisFormat: '2.1.0',
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 @@ -84,7 +84,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.0.0",
"oisFormat": "2.1.0",
"version": "1.2.3",
"title": "Currency Converter API",
"apiSpecifications": {
Expand Down
4 changes: 2 additions & 2 deletions packages/airnode-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@api3/airnode-protocol": "^0.11.0",
"@api3/airnode-utilities": "^0.11.0",
"@api3/airnode-validator": "^0.11.0",
"@api3/ois": "2.0.0",
"@api3/ois": "2.1.0",
"@api3/promise-utils": "^0.4.0",
"@aws-sdk/client-lambda": "^3.346.0",
"date-fns": "^2.30.0",
Expand All @@ -39,7 +39,7 @@
"google-auth-library": "^8.8.0",
"lodash": "^4.17.21",
"yargs": "^17.7.2",
"zod": "^3.20.6"
"zod": "^3.21.4"
},
"devDependencies": {
"@api3/airnode-operation": "^0.11.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-node/src/adapters/http/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function getReservedParameterValue(
name: ReservedParameterName,
endpoint: Endpoint,
requestParameters: ApiCallParameters
): string | undefined {
): any {
const reservedParameter = endpoint.reservedParameters.find((rp) => rp.name === name);
// Reserved parameters must be whitelisted in order to be used, even if they have no fixed or default value
if (!reservedParameter) {
Expand Down
30 changes: 0 additions & 30 deletions packages/airnode-node/src/api/processing.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ZodError } from 'zod';
import { postProcessApiSpecifications, preProcessApiSpecifications } from './processing';
import * as fixtures from '../../test/fixtures';

Expand Down Expand Up @@ -56,35 +55,6 @@ describe('processing', () => {

await expect(throwingFunc).rejects.toEqual(new Error('SyntaxError: Unexpected identifier'));
});

it('throws validation error if result does not have parameters shape', async () => {
const config = fixtures.buildConfig();
const preProcessingSpecifications = [
{
environment: 'Node' as const,
value: 'const output = {...input, object: {a: 123, b: false}};',
timeoutMs: 5_000,
},
];
config.ois[0].endpoints[0] = { ...config.ois[0].endpoints[0], preProcessingSpecifications };

const parameters = { _type: 'int256', _path: 'price', from: '*ETH' };
const aggregatedApiCall = fixtures.buildAggregatedRegularApiCall({ parameters });

const throwingFunc = () => preProcessApiSpecifications({ type: 'regular', config, aggregatedApiCall });

await expect(throwingFunc).rejects.toEqual(
new ZodError([
{
code: 'invalid_type',
expected: 'string',
received: 'object',
path: ['object'],
message: 'Expected string, received object',
},
])
);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-node/src/handlers/process-http-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Config } from '../config';
export async function processHttpRequest(
config: Config,
endpointId: string,
parameters: Record<string, string>
parameters: Record<string, any>
): Promise<[Error, null] | [null, HttpGatewayApiCallSuccessResponse]> {
// Guaranteed to exist because validation is already performed in the deployer handler
const trigger = find(config.triggers.http, ['endpointId', endpointId])!;
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-node/src/validation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { z } from 'zod';

export const apiCallParametersSchema = z.record(z.string(), z.string());
export const apiCallParametersSchema = z.record(z.string(), z.any());
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,6 @@ describe('verifyHttpRequest', () => {
});
});

it('returns error when the parameters are invalid', () => {
const config = loadConfigFixture();

const result = verifyHttpRequest(config, { nonStringValue: 123 }, validEndpointId);

expect(result).toEqual({
error: { message: 'Invalid request body' },
statusCode: 400,
success: false,
});
});

it('returns success when the data is valid', () => {
const config = loadConfigFixture();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.0.0",
"oisFormat": "2.1.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-node/test/fixtures/config/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(ois?: Partial<OIS>): OIS {
return {
oisFormat: '2.0.0',
oisFormat: '2.1.0',
version: '1.2.3',
title: 'Currency Converter API',
apiSpecifications: {
Expand Down
4 changes: 2 additions & 2 deletions packages/airnode-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
},
"dependencies": {
"@api3/airnode-protocol": "^0.11.0",
"@api3/ois": "2.0.0",
"@api3/ois": "2.1.0",
"@api3/promise-utils": "^0.4.0",
"dotenv": "^16.1.4",
"ethers": "^5.7.2",
"lodash": "^4.17.21",
"ora": "^5.4.1",
"yargs": "^17.7.2",
"zod": "^3.20.6"
"zod": "^3.21.4"
},
"devDependencies": {
"@types/yargs": "^17.0.24",
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-validator/test/fixtures/config.valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.0.0",
"oisFormat": "2.1.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Loading

0 comments on commit 0b7d89e

Please sign in to comment.