OpenViSTAI · Agents · Blockchain · Crypto
Menu
OPENVIST RECIPES

Audit required configuration keys without exposing values with JavaScript

JavaScript

Report missing and empty required names, duplicate assignment positions and unknown keys under one literal assignment contract.

JavaScript code excerpt: Audit required configuration keys without exposing values with JavaScript. Version 0.1.0. Read the full recipe for code, sources and recorded test scope.

Report missing and empty required names, duplicate assignment positions and unknown keys under one literal assignment contract. Uses saved stdin text; never reads the real process environment.

Before you start

  • Save as audit.js and run with Node.js 22: node audit.js < input.txt. Supply no command-line arguments. The CLI reads only descriptor 0 and requires only node:fs.
  • Input consists of selector names, exactly one literal --- separator line, then literal KEY=value assignments. Exactly empty lines and lines starting with # are ignored. Whitespace is never trimmed.
  • Keys must match ASCII [A-Za-z_][A-Za-z0-9_]{0,63}. Selectors must be unique. Assignments split at the first equals sign; all remaining characters are literal value content.
  • Successful output is exactly one JSON object followed by LF, with missing, empty, duplicates and unknown fields. Key-name arrays and duplicate entries use ASCII key ordering. Duplicate positions are one-based assignment-record ordinals.
  • A required key is empty if any of its assignments has an exactly empty value. Unknown names are distinct assigned keys absent from the selectors. Values are never emitted.
  • Invalid input, arguments, UTF-8 or stdin reads produce empty stdout, exactly error: invalid input followed by LF on stderr, and exit status 2. Successful execution exits 0 with empty stderr.
  • Example stdin: A\nB\n---\nA=\nA=literal\nC=x\n
  • Expected example stdout: {"missing":["B"],"empty":["A"],"duplicates":[{"key":"A","positions":[1,2]}],"unknown":["C"]} followed by LF.

Build and check

  1. Save the example as recipe.cjs.
  2. Prepare input.txt with selectors, a --- separator and literal assignments; use synthetic values while learning.
  3. Run the documented command and inspect the JSON output.
  4. Exit 2 indicates rejected input; no successful JSON result is emitted.

Limits to understand

  • Reads at most 65537 bytes total and rejects input longer than 65536 bytes.
  • Requires strict UTF-8 without a leading BOM. Rejects ASCII controls other than LF, including CR, NUL and DEL.
  • Allows at most 100 selector records and 100 assignment records, counting duplicate assignments separately.
  • The combined UTF-8 byte length of every assignment value, including duplicates, must not exceed 1024 bytes.
  • This is a literal LF-only protocol, not general dotenv syntax. It performs no interpolation, escaping, quote removal or inline-comment processing.
  • No files, environment variables, network resources or subprocesses are accessed by the CLI. Output-write and allocation failures are outside the input-error guarantee.
  • Literal assignment subset only; no quoting rules, export syntax, interpolation, multiline values or general dotenv compatibility.
  • Key names can themselves be sensitive.
  • stdin may block until EOF; input is bounded to 65536 bytes and 100 selector / 100 assignment records. Total assignment-value bytes are limited to 1024.

Run it

node recipe.cjs < input.txt

Example input

API_KEY
HOST
PORT
---
HOST=
API_KEY=first
API_KEY=second
EXTRA=x

Expected output

{"missing":["PORT"],"empty":["HOST"],"duplicates":[{"key":"API_KEY","positions":[2,3]}],"unknown":["EXTRA"]}
INSPECT THE SCRIPT

Inspect, copy and run the documented checks.

This browser preview builds code locally. It does not contact an API or run the code.

Default example ready.

JavaScript example
'use strict';

const fs = require('node:fs');

function audit() {
  if (process.argv.length !== 2) throw new Error();

  const buffer = Buffer.alloc(65537);
  let used = 0;
  while (used < buffer.length) {
    const count = fs.readSync(0, buffer, used, buffer.length - used, null);
    if (count === 0) break;
    used += count;
  }
  if (used > 65536) throw new Error();

  const text = new TextDecoder('utf-8', {
    fatal: true,
    ignoreBOM: true
  }).decode(buffer.subarray(0, used));

  if (text.startsWith('\uFEFF')) throw new Error();
  if (/[\u0000-\u0009\u000B-\u001F\u007F]/.test(text)) {
    throw new Error();
  }

  const keyPattern = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
  const required = new Set();
  const assigned = new Map();
  const emptyRequired = new Set();
  let separatorSeen = false;
  let selectorCount = 0;
  let assignmentCount = 0;
  let valueBytes = 0;

  for (const line of text.split('\n')) {
    if (line === '---') {
      if (separatorSeen) throw new Error();
      separatorSeen = true;
      continue;
    }
    if (line === '' || line.startsWith('#')) continue;

    if (!separatorSeen) {
      selectorCount += 1;
      if (selectorCount > 100 || !keyPattern.test(line) || required.has(line)) {
        throw new Error();
      }
      required.add(line);
      continue;
    }

    assignmentCount += 1;
    if (assignmentCount > 100) throw new Error();
    const equals = line.indexOf('=');
    if (equals < 0) throw new Error();
    const key = line.slice(0, equals);
    if (!keyPattern.test(key)) throw new Error();
    const value = line.slice(equals + 1);
    valueBytes += Buffer.byteLength(value, 'utf8');
    if (valueBytes > 1024) throw new Error();

    let positions = assigned.get(key);
    if (positions === undefined) {
      positions = [];
      assigned.set(key, positions);
    }
    positions.push(assignmentCount);
    if (value === '' && required.has(key)) emptyRequired.add(key);
  }

  if (!separatorSeen) throw new Error();

  const missing = [];
  for (const key of required) {
    if (!assigned.has(key)) missing.push(key);
  }
  missing.sort();

  const empty = Array.from(emptyRequired).sort();
  const duplicates = [];
  const unknown = [];
  const assignedKeys = Array.from(assigned.keys()).sort();
  for (const key of assignedKeys) {
    const positions = assigned.get(key);
    if (positions.length >= 2) duplicates.push({ key, positions });
    if (!required.has(key)) unknown.push(key);
  }

  return JSON.stringify({ missing, empty, duplicates, unknown }) + '\n';
}

let output;
try {
  output = audit();
} catch {
  process.stderr.write('error: invalid input\n');
  process.exit(2);
}
process.stdout.write(output);
What to verify after running
  • Check the supplied example against its expected output.
  • Inspect missing, empty, duplicate and unknown key findings.
  • Confirm invalid syntax and extra arguments fail without input values in diagnostics.

Request or format preview

Illustrative preview. No provider response, price or balance is fetched.

Change a setting to inspect the preview.

Official sources and related profiles

    Code license: MIT. Keep the license notice with your copy.

    Example version 0.1.0 · Documentation reviewed 2026-10-16.

    The release gate requires six primary fixtures and 29 supplementary checks in the pinned offline runtime. Review the bound test evidence for the actual release; these checks do not prove exhaustive correctness or compatibility with other versions.