New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@backwork/x278

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@backwork/x278

Agent-native prior authorization protocol reference implementation and TypeScript SDK.

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

x278

npm CI License: MIT Runtime: Bun Effect TS

TypeScript SDK and reference implementation for x278, Backwork's proposed agent-native protocol for prior authorization.

x278 models prior authorization as a typed exchange between provider-side and payer-side software agents. A provider agent submits a structured request. A payer agent returns an actionable determination: approved, denied, info-needed, or pended. The provider agent can then attach evidence, wait for review, correct the request, or appeal without restarting the authorization context.

This package is a protocol SDK and runnable reference environment. It is not a certified payer integration, a substitute for Da Vinci PAS conformance testing, or legal/compliance advice.

Install

npm install @backwork/x278
bun add @backwork/x278

The package ships dual ESM/CJS builds, declaration maps, and subpath exports for SDK, HTTP transport, FHIR/PAS helpers, signing, conformance, and protocol types.

Quick Start

Run the provider loop against the deterministic in-memory payer:

import {
  createMockX278Client,
  kneeReplacementMissingDocs
} from "@backwork/x278";

const client = createMockX278Client({
  collectEvidence: (_request, requirements) =>
    requirements.map((requirement) => ({
      id: requirement.id,
      value: `chart evidence for ${requirement.id}`,
      source: "chart"
    }))
});

const trace = await client.requestWithTrace(kneeReplacementMissingDocs);

console.log(trace.steps.map((step) => step.status));
// ["info-needed", "approved"]

console.log(trace.final.authNumber);

The same client loop also handles pended determinations by awaiting the returned subscription handle, and denied determinations by returning a coded reason plus appeal path.

HTTP Client

Use @backwork/x278/http when calling an x278-compatible payer endpoint:

import { createX278HttpClient } from "@backwork/x278/http";

const client = createX278HttpClient({
  baseUrl: "https://payer.example/x278",
  bearerToken: process.env.X278_BEARER_TOKEN,
  collectEvidence: async (_request, requirements) =>
    requirements.map((requirement) => ({
      id: requirement.id,
      value: "supporting chart evidence",
      source: "chart"
    }))
});

const capabilities = await client.capabilities();
const determination = await client.request({
  patient: { memberId: "A1234567", dob: "1971-03-02" },
  provider: { npi: "1972648392", tin: "84-1234567" },
  service: {
    code: "27447",
    codeSystem: "CPT",
    diagnosis: ["M17.11"],
    placeOfService: "21",
    requestedStart: "2026-06-01",
    units: 1,
    urgency: "standard"
  },
  supportingInfo: []
});

The HTTP client includes production-oriented defaults:

  • 30 second request timeout
  • retry support for transient HTTP failures
  • Retry-After handling
  • bearer token and custom header hooks
  • request, response, retry, and error lifecycle hooks
  • redacted debug logging
  • typed ProtocolError failures with request IDs where available
  • /.well-known/x278 capabilities discovery

For local parity, createX278HttpClientFromEnv() reads X278_PAYER_URL and X278_BEARER_TOKEN.

Protocol States

StateMeaningNext action
approvedAuthorization approved by rules or reviewerUse the returned authorization number and validity window
deniedRequest denied with coded reason and appeal pathCorrect, resubmit, or appeal
info-neededPayer needs specific documentationAttach evidence and resume the same authId
pendedRequest accepted but not finalAwait the returned subscription/update handle
errorMalformed or unprocessable exchangeFix the request or contact the payer

Public Exports

ImportPurpose
@backwork/x278Full public SDK surface
@backwork/x278/httpFetch-backed HTTP client and transport
@backwork/x278/sdkPromise and Effect provider clients
@backwork/x278/conformanceConformance harness for x278 transports
@backwork/x278/typesProtocol schemas, domain types, and typed errors
@backwork/x278/schemasSchema-focused alias for protocol validation
@backwork/x278/evidenceDTR-style evidence and QuestionnaireResponse helpers
@backwork/x278/fhir-pasFHIR/PAS/DTR mapping helpers
@backwork/x278/policyVersioned executable policy adapter interface
@backwork/x278/signingCanonical hashing and signed receipt utilities
@backwork/x278/smartSMART Backend Services token provider utilities
@backwork/x278/subscriptionsLocal subscription/webhook broker helpers
@backwork/x278/payer-agentReference payer agent service
@backwork/x278/provider-clientLower-level provider loop primitives

Effect and Promise APIs

x278 is implemented with Effect schemas and services internally, while exposing a Promise API for conventional TypeScript applications.

  • Use createX278EffectClient and runX278ConformanceEffect inside Effect applications.
  • Use createX278Client, createX278HttpClient, and runX278Conformance in Promise-based services.
  • API boundaries accept unknown where appropriate and validate into typed protocol objects before transport use.

Conformance

Transport implementers can run the conformance harness against any x278 transport:

import { createMockPayer, runX278Conformance } from "@backwork/x278";

const report = await runX278Conformance(createMockPayer());

if (!report.ok) {
  throw new Error("x278 conformance failed");
}

The harness exercises the core behaviors described by the protocol: approval, denial, information-needed retry, pended review, signature verification, audit records, and bounded workflow handling.

Conformance reports can also be serialized for release artifacts:

import {
  runX278Conformance,
  toConformanceBadge,
  toConformanceMarkdown
} from "@backwork/x278";

const report = await runX278Conformance(transport);

console.log(toConformanceMarkdown(report));
console.log(toConformanceBadge(report));

Examples

The repository includes runnable examples that use the same public package exports consumers install from npm:

CommandWhat it shows
bun run example:mockFull provider loop against the in-memory payer, including info-needed, pended, and denied paths
bun run example:conformanceRunning the conformance harness against a transport
bun run payer:http + bun run example:httpHTTP client usage against the local reference payer

For the HTTP example, start the payer in one terminal:

bun run payer:http

Then run the client from another terminal:

bun run example:http

Local Development

bun install
bun run typecheck
bun run test
bun run build

Useful verification commands:

CommandPurpose
bun run testUnit and protocol behavior tests
bun run test:liveLive OpenAI Agents SDK and Anthropic SDK proof tests
bun run release:smokePackaged ESM/CJS consumer smoke test
bun run release:attwPackage export/type validation
bun run docker:realisticProvider and payer containers over HTTP
bun run docker:fhirHTTP scenario with HAPI FHIR validation
bun run prove:fullFull local release proof gate

Live agent tests require provider API keys in the environment. The normal test suite does not call paid model APIs.

Specification

x278 is designed to interoperate with FHIR prior authorization infrastructure, including Da Vinci PAS, DTR, and CRD patterns, rather than replace those rails. Where X12 278/275 applies, production implementers still need the appropriate mapping, licensing, and trading-partner testing outside this SDK.

Status and Boundaries

The repository currently includes:

  • protocol schemas and typed determination states
  • Promise and Effect SDK clients
  • production HTTP client and transport
  • deterministic reference payer agent
  • signed terminal determinations and audit records
  • FHIR/PAS mapping helpers
  • conformance and release proof harnesses
  • Docker-based realistic scenarios

Before production healthcare use, organizations still need real payer endpoint registration, SMART Backend Services/OAuth configuration, PAS/FHIR conformance testing, HIPAA/security review, operational monitoring, and policy/legal review.

This project is not affiliated with CMS, HL7, X12, or the Da Vinci Project.

License

MIT. See LICENSE.

Keywords

x278

FAQs

Package last updated on 29 May 2026

Related posts