📂 Reference > Packages

# Validator

Table of Contents

The airnode-validator (opens new window) is used internally by the Docker Images to validate the configuration files you provide when deploying an Airnode.

However, validator can also be used as a standalone package to verify the correctness of the configuration files without deploying the Airnode. The recommended way is to use the validator CLI, but for advanced use cases you can use the validator SDK.

# CLI Usage

The simplest way to run the CLI is using npx (opens new window). Alternatively, you can install the validator package as a dependency in your project.

npx @api3/airnode-validator --config "pathTo/config.json" --secrets "pathTo/secrets.env"
1

alternatively

# First install the package
npm install @api3/airnode-validator
# Or
yarn add @api3/airnode-validator
# Run the validator CLI
npx airnode-validator --config "pathTo/config.json" --secrets "pathTo/secrets.env"
1
2
3
4
5
6
7

# Examples

Assuming the configurations files inside the config directory are valid, executing:

npx @api3/airnode-validator --config "config/valid-config.json" --secrets "config/valid-secrets.env"
1

yields:

✔ The configuration is valid
1

When there is an error during validation, the command prints out the error and fails with a non zero status code.

npx @api3/airnode-validator --config "config/valid-config.json" --secrets "config/non-existent-secrets.env"
1

yields:

✖ Unable to read secrets file at "config/non-existent-secrets.env". Reason: Error: ENOENT: no such file or directory, open (...omitted for brevity)
1

# SDK Usage

The validator package contains an API that can be used to validate Airnode configuration files programatically.

The following functions can be used:

  • parseConfigWithSecrets(config, secrets) - Interpolates secrets into config and validates the interpolated configuration. Expects both config and secrets to be JSON objects.
  • parseConfig(config) - Validates the config. Expects the config to be a JSON object.
  • parseSecrets(secrets) - Validates the secrets. Expects the secrets to be a JSON object.
  • parseReceipt(receipt) - Validates the receipt. Expects the receipt to be a JSON object.
  • unsafeParseConfigWithSecrets(config, secrets) - Interpolates secrets into config but does not perform any validation afterwards. Use this function only when you can guarantee that the configuration is valid.

Validator has also full TypeScript support. All of these functions return a typed object.

# Examples

const validator = require('@api3/airnode-validator');
const dotenv = require('dotenv');
const fs = require('fs');
const config = JSON.parse(fs.readFileSync('pathTo/config.json', 'utf-8'));
const secrets = dotenv.parse(fs.readFileSync('pathTo/secrets.env', 'utf-8'));
const parseResult = validator.parseConfigWithSecrets(config, secrets);
if (parseResult.success) {
  const config = parseResult.data;
  // ... (do something with valid "config")
} else {
  console.error(parseResult.error);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

or:

import * as validator from '@api3/airnode-validator';
import { join } from 'path';
import dotenv from 'dotenv';
import { readFileSync } from 'fs';
const config = JSON.parse(readFileSync('pathTo/config.json', 'utf-8'));
const secrets = dotenv.parse(readFileSync('pathTo/secrets.env', 'utf-8'));
const parseResult = validator.parseConfigWithSecrets(config, secrets);
if (parseResult.success) {
  const config = parseResult.data;
  // ... (do something with valid "config")
} else {
  console.error(parseResult.error);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# Build Manually

See the build instruction in the package developer documentation: https://github.com/api3dao/airnode/tree/v0.7/packages/airnode-validator

Last Updated: 8/9/2022, 3:28:25 PM