validator(data) → Promise
Root Promise namespace
All 18 enumerable validators preserve upstream property order, falsy-input normalization, resolution identity, rejection timing, and complete Ajv error records.
HAR 1.2 schema validation · MIT
Validate complete HTTP Archive documents or any of their 18 schema components while keeping the established har-validator@5.1.5 Promise, boolean, callback, and error contracts.
npm install @stackline/har-validator
Keep existing imports unchanged with har-validator: npm:@stackline/har-validator in your dependencies.
01 / Validation model
The package loads the HAR 1.2 draft-06 definitions from har-schema, registers them with Ajv 6, and compiles lazily with allErrors: true. Validate an entire archive with har(), an HTTP side with request() or response(), or an individual header, cookie, timing, content, cache, page, creator, or browser record.
02 / Quick start
Promise validators resolve to the exact object passed by the caller. A rejection includes the complete Ajv 6 error array, including dataPath, schema path, keyword, parameters, and message.
const validate = require(
'@stackline/har-validator'
)
const response = {
status: 204,
statusText: 'No Content',
httpVersion: 'HTTP/1.1',
headers: [], cookies: [],
content: { size: 0, mimeType: 'text/plain' },
redirectURL: '', headersSize: -1, bodySize: 0
}
await validate.response(response)
03 / Public API
validator(data) → Promise
All 18 enumerable validators preserve upstream property order, falsy-input normalization, resolution identity, rejection timing, and complete Ajv error records.
lib/async.validator(data[, callback])
Without a callback, returns a synchronous boolean. With one, invokes (error, valid) synchronously and returns the callback's own value.
new HARError(errors)
Exposes name, message, errors, and the upstream stack shape. The corrected isolated prototype remains an Error.
04 / Exact semantics
The implementation is compared against the immutable upstream artifact and an isolated Ajv 6.12.3 golden result set. The maintained dependency stays on Ajv 6 to retain dataPath-based errors and HAR draft-06 behavior. The Node.js 6.17.1 floor applies to CommonJS; ESM is additive on runtimes and build tools that support it.
The only intentional CommonJS correction is the HARError prototype: unrelated ordinary errors no longer satisfy instanceof HARError. Constructor, stack, enumerable shape, and direct-call behavior remain upstream-compatible.
05 / Browser use
import validate from
'@stackline/har-validator'
import HARError from
'@stackline/har-validator/lib/error'
Browser-aware bundlers receive browser-compatible sources in one graph, so rejected errors retain identity with the deep constructor.
import validate from
'@stackline/har-validator/browser'
The additive CJS/ESM bundle exposes only the Promise namespace. Ajv performs runtime code generation; review strict Content Security Policy requirements before adoption.
06 / Migration
"har-validator":
"npm:@stackline/har-validator@1.0.0"
Existing root, lib/promise, lib/async, and lib/error imports stay unchanged. Commit the manifest and lockfile together.
import validate, { response }
from '@stackline/har-validator'
Real ESM, named exports, TypeScript declarations, conditional exports, and browser bundles are additive to the preserved CommonJS contract.
07 / Trust boundary
The validators check HAR 1.2 structure. They do not parse JSON, sanitize header or body content, approve URLs, verify that an exchange occurred, reconcile sizes and timings, or bound attacker-controlled work. Apply byte, depth, entry-count, and time limits before validating untrusted archives.
Treat URLs, cookies, headers, query strings, post data, and response text as untrusted even after validation. In browsers, Ajv's runtime compilation may be rejected by a Content Security Policy that disallows dynamic code generation.
Read the complete security and reporting boundary →08 / Reference files