Node API
The exports of the npm package verdock, version 0.3.0. Node 18 or newer, zero runtime dependencies, the same receipts as the Python package.
On this page
npm install verdock
npx verdock --helpThe package is an ES module. A receipt written by Node verifies in Python and the other way round, with the same failure reasons.
Guard and decide#
import verdock, { loadPolicy, decide } from 'verdock';
const decision = decide(loadPolicy('verdock.yaml'), 'payout', 1500, 'USD');
const payout = verdock.guard('payout', async ({ amountMinor, currency, counterparty, requestId }) => {
return sendPayout(amountMinor, currency, counterparty, requestId);
}, {
policyPath: 'verdock.yaml',
stateDir: '.verdock',
reconcile: async (requestId) => readPayoutRecord(requestId),
});
await payout({ amountMinor: 1500, currency: 'USD', counterparty: 'c1', requestKey: 'order-1017' });reconcile returns { amountMinor, currency } or null. The decision has allowed, needsApproval, reason, limitMinor and approversRequired.
Exports#
| Area | Names |
|---|---|
| Policy | LEVELS, RETRY_VALUES, parseYamlSubset, validatePolicy, loadsPolicy, loadPolicy, policyHash, decide |
| Stores | ApprovalStore, Invariants, OutcomeLog, LocalState |
| Outcomes | VERIFIED, MISMATCH, UNKNOWN, PENDING, STATES, compare, mayRetry |
| Receipts | canonicalBytes, buildLine, lineHash, createSeed, loadSeed, ReceiptLog, verifyBytes, verifyLog, canonical |
| Disclosure | SENSITIVE, fieldSalt, commitment, protect, verifyDisclosure, disclose |
| Approvals | signVote, checkEvidence |
| Manifests | ManifestError, normalizeActions, widening, issueManifest, verifyChain, checkAction, checkDelegation, ManifestRegistry |
| Exchange | rfc6238Totp, timeStep, boundCode, exchangeHash, signRole, attestCode, SendPolicy, draftExchange, verifyExchangeReceipt |
| Other | guard, exceptions, runDemo, runScenes, publicKey, VERSION, Refused, PolicyError, ReceiptError |
| Adapters | StripeAdapter, RazorpayAdapter, ProviderError, Result, loadEnv, also from verdock/adapters |
Differences from Python#
- State is kept in JSON files in the state folder (
adapters.json,invariants.json,outcomes.json,receipts.ndjson) rather than SQLite, and is shared withguard. Receipt bytes are the same as the Python package. - Arguments are camelCase:
amountMinor,requestKey,fundAccountId. - Producing exchanges over a store (
request,approve,accept) andexceptionsover SQLite files are Python commands. The Node package verifies exchange receipts and exposes the producers that the built in run uses. - Node 18 prints a runtime warning to stderr the first time an adapter uses
fetch.
Commands are in the CLI reference.