App Node SDK
The server-side TypeScript package for native ATM checkout, status reconciliation, notifications and Tickets calls.
Compatible with the closed-beta ATM app APIs and versioned ATM event headers. Check atm-api-version on every webhook or XRPC receiver event.
Package status
@atmosphere-money/app-node is ATM's SDK for app backends. It is MIT licensed, needs Node 22 or newer, has no runtime dependencies, and exports ESM with TypeScript declarations. The package license covers this SDK only.
View the package on npmx to review its README, source, changelog, provenance and package signals.
Native build and API compatibility
The native checkout helpers (createCheckout, getCheckoutStatus, createAtmCheckoutAttempts and createAtmFileStore) ship in the pinned native build supplied for your integration. Older npm betas may not include them. Webhook and receiver events carry an atm-api-version header; check it, and do not accept unknown future shapes without a compatibility review.
| Package | @atmosphere-money/app-node |
|---|---|
| Native build | Supplied for your integration. Keep its integrity hash in your lockfile; the version number alone does not identify it. |
| API compatibility | ATM API beta: 2026-06 |
| Package browser | https://npmx.dev/package/@atmosphere-money/app-node |
| Event version signal | atm-api-version header on HTTP webhooks and XRPC receiver events. |
| Breaking changes | Documented in the SDK reference, Versioning and the package changelog. |
Install
# For example, a supplied package tarball:
npm install ./atmosphere-money-app-node-<version>.tgz
# Confirm the native helpers are present. This prints "function".
node -e "import('@atmosphere-money/app-node').then((sdk) => console.log(typeof sdk.createAtmCheckoutAttempts))"Keep the package on your backend. Update it deliberately, and review the changelog before you do.
Initialize
The SDK asks your backend for a fresh service-auth JWT on every app-facing XRPC call and passes the exact lxm and aud to sign. Point the client at your assigned test broker.
import { createAtmAppClient } from "@atmosphere-money/app-node";
export const atm = createAtmAppClient({
brokerUrl: "https://your-assigned-test-checkout.example",
serviceAudience: "did:plc:bbbbbbbbbbbbbbbbbbbbbbbb#atmosphere_money_broker",
// A NEW token per call, signed by your PDS via com.atproto.server.getServiceAuth.
getServiceAuthToken: ({ lxm, aud }) => mintMyAppServiceAuthJwt({ lxm, aud }),
});For checkout itself, use createAtmCheckoutAttempts. It uses the same transport, with durable attempts.
Start checkout
Capture a durable attempt before contacting ATM, then send it. recover is safe to repeat: it always replays the original body and key.
import {
createAtmCheckoutAttempts,
createAtmFileStore,
type AtmCheckoutAttempt,
} from "@atmosphere-money/app-node";
const attempts = createAtmCheckoutAttempts({
appDid: "did:plc:aaaaaaaaaaaaaaaaaaaaaaaa",
brokerDid: "did:plc:bbbbbbbbbbbbbbbbbbbbbbbb",
brokerUrl: "https://your-assigned-test-checkout.example",
store: createAtmFileStore<AtmCheckoutAttempt>("./private-attempts"),
getServiceAuthToken: ({ lxm, aud }) => mintMyAppServiceAuthJwt({ lxm, aud }),
});
// Illustrative refs: use your seller's exact Product and fixed Price.
const cid = "bafyreigh2akiscaildcwti7d2x3xfyq5gsgq7s6ni5cndflr2nzz4j4y5m";
await attempts.capture("order_123_attempt_1", {
environment: "test",
idempotencyKey: "order_123_attempt_1",
items: [{
recipient: "did:plc:cccccccccccccccccccccccc",
listing: { uri: "at://did:plc:cccccccccccccccccccccccc/money.atmosphere.product/digital", cid },
price: { uri: "at://did:plc:cccccccccccccccccccccccc/money.atmosphere.price/fixed", cid },
quantity: 1,
paymentType: "shop",
}],
returnUrl: "https://app.example/orders/123/return",
});
const attempt = await attempts.recover("order_123_attempt_1");
export const checkoutUrl = attempt.checkout!.url; // only this goes to the buyerA backend worker then reconciles the attempt, whether or not the buyer returns:
const result = await attempts.reconcile("order_123_attempt_1");
if (result.action === "fulfil") {
// completed + fulfil. Insert result.effectKey under a unique constraint and
// grant the purchase in the SAME database transaction.
}
// "wait": poll again later. "closed": failed, canceled or expired.
// "order": an order owner must confirm first.Optional webhook receiver
If you opt into HTTP webhooks, verify the exact raw body and ATM headers. Claim a delivery before queuing work, complete it only after a 2xx result, and release failed claims so ATM can redrive them.
import { createNodeWebhookHandler } from "@atmosphere-money/app-node";
export const POST = createNodeWebhookHandler({
secret: [process.env.ATM_WEBHOOK_SECRET, process.env.ATM_WEBHOOK_PREVIOUS_SECRET]
.filter((value): value is string => Boolean(value)),
deliveryStore: {
claim: claimWebhookDelivery,
complete: completeWebhookDelivery,
release: releaseWebhookDelivery,
},
onEvent: async (event) => {
if (event.environment !== "test" || event.apiVersion !== "2026-07")
return { status: 422, body: { error: "UnexpectedEventBinding" } };
await enqueueReconciliation(event); // the worker reads canonical status
return { body: { ok: true } };
},
});When you know the expected event type, the typed constructor gives you a narrower event.data shape for parsing or tests. In routes, use a handler with a delivery store.
const paymentEvent = constructTypedAtmWebhookEvent({
rawBody,
secret: process.env.ATM_WEBHOOK_SECRET!,
expectedType: "payment.completed",
headers: {
signature: request.headers.get("atm-signature"),
deliveryId: request.headers.get("atm-delivery-id"),
apiVersion: request.headers.get("atm-api-version"),
environment: request.headers.get("atm-environment"),
},
});
console.log(paymentEvent.data.payment.id);For route-level integration, use createNodeWebhookHandler, createNextWebhookRoute, createExpressWebhookHandler, createHonoWebhookHandler, or createCloudflareWorkerWebhookHandler. All of them verify the signed raw body and give your code a typed ATM event before it wakes canonical status reconciliation.
Fetch-style helpers stream at most 1 MiB by default before rejecting the request. All webhook verification paths also cap the Atm-Signature header at 8 KiB and accept at most eight v1 rotation signatures. Express apps must apply the same or a smaller limit in their raw-body middleware because it runs before the SDK handler.
Tickets helpers
Tickets use the same package because ticket holds, free limited claims and QR or pass checks all depend on ATM app auth. Tickets follow their own admitted contract; a ticket hold is not native checkout admission.
import { createFreeTicketClaimBody, createTicketHoldBody } from "@atmosphere-money/app-node";
const eventUri = "at://did:plc:organizer/community.lexicon.calendar.event/demo";
const availability = await atm.getTicketAvailability({ environment: "test", eventUri });
const hold = await atm.createTicketHold(createTicketHoldBody({
environment: "test",
eventUri,
buyerDid: "did:plc:buyer",
buyerAssertionJwt: "short-lived-buyer-assertion",
items: [{ ticketTypeId: "tier_123", quantity: 2 }],
returnUrl: "https://app.example/tickets/return",
cancelUrl: "https://app.example/events/demo",
idempotencyKey: "hold:event:buyer:tier_123:2",
}));
// Persist hold.statusToken on your server, then redirect to hold.url.
const freeClaim = await atm.claimFreeTicket(createFreeTicketClaimBody({
environment: "test",
eventUri,
buyerDid: "did:plc:buyer",
buyerAssertionJwt: "short-lived-buyer-assertion",
customerEmail: "buyer@example.com",
items: [{ ticketTypeId: "tier_free", quantity: 1 }],
idempotencyKey: "claim:event:buyer:tier_free",
}));
const verified = await atm.verifyTicket({
environment: "test",
ticketToken: "opaque_scan_token",
});
export { availability, freeClaim, hold, verified };Ticket-specific concepts, diagrams, and scanner flows live on atmosphere.tickets. ATM docs cover the shared payment, app auth, and event surfaces.
Framework examples
Copyable examples so you can start from your own backend style without rewriting the verification logic. Every webhook example queues reconciliation; none grants a purchase from the event alone.
| Native integration | docs/developer/examples/happy-path-app.ts |
|---|---|
| Next checkout route | docs/developer/examples/next-checkout-route.ts |
| Next webhook route | docs/developer/examples/next-webhook-route.ts |
| Next XRPC receiver route | docs/developer/examples/next-xrpc-receiver-route.ts |
| Express webhook route | docs/developer/examples/express-webhook-route.ts |
| Fastify webhook route | docs/developer/examples/fastify-webhook-route.ts |
| Hono webhook route | docs/developer/examples/hono-webhook-route.ts |
| Cloudflare Worker webhook | docs/developer/examples/cloudflare-worker-webhook.ts |
| Ticket hold checkout | docs/developer/examples/ticket-hold-checkout.ts |
| Free limited ticket claim | docs/developer/examples/free-ticket-claim.ts |
Errors and retries
Failed requests throw AtmApiError with a stable code, HTTP status and parsed body. Contract checks throw AtmCheckoutContractError: before sending an input that breaks the contract, and on a reply or stored attempt that does. Retry network failures, 401, 429 and 503 with the same attempt ID. A missing reply is never proof of non-payment.
import { AtmApiError } from "@atmosphere-money/app-node";
try {
await attempts.recover("order_123_attempt_1");
} catch (error) {
if (error instanceof AtmApiError && error.code === "RecipientNotPayable") {
showSetupRequiredState();
} else if (!(error instanceof AtmApiError) || [401, 429, 503].includes(error.status)) {
// Network failure or retryable status: try again later with the same
// attempt ID. recover replays the original request and key.
} else {
throw error; // keep the attempt for support; never replace it automatically
}
}Every native error code and its expected recovery is on Checkout.
API surface
| createAtmCheckoutAttempts | Durable capture, recovery and reconciliation of native test checkouts. |
|---|---|
| createAtmFileStore | A durable compare-and-swap store for one server on a private persistent volume. |
| AtmDurableStore | The store interface to implement with compare-and-swap in your shared database. |
| createAtmAppClient | A backend client for createCheckout, getCheckoutStatus, profiles, configuration and Tickets calls. |
| ATM_XRPC_METHODS | Method constants, so app code avoids scattered NSID strings. |
| constructAtmWebhookEvent | Verify an HTTP webhook signature and parse the event envelope. |
| constructTypedAtmWebhookEvent | Verify a webhook and narrow data for a known event type. |
| createNodeWebhookHandler | A Request/Response webhook handler for Node-compatible runtimes. |
| createNextWebhookRoute | Alias for Next route handlers and other Web Request runtimes. |
| createExpressWebhookHandler | An Express-style webhook handler without an Express dependency. |
| createHonoWebhookHandler | A Hono route handler around the same signed webhook verification. |
| createCloudflareWorkerWebhookHandler | A Workers fetch handler around the same signed webhook verification. |
| constructAtmXrpcReceiverEvent | Verify canonical XRPC receiver service-auth and parse the same envelope. |
| constructTypedAtmXrpcReceiverEvent | Verify an XRPC receiver event and narrow data for a known event type. |
| verifyServiceAuthRequest | Verify a service-auth bearer request before custom XRPC receiver routing. |
| createTicketHoldBody, createFreeTicketClaimBody | Validate ticket hold and free claim request bodies before calling Tickets methods. |
| signAtmWebhookPayload | Test helper for local webhook signature fixtures. |
| AtmApiError, AtmCheckoutContractError | A structured request failure, and a contract refusal for an input, reply or stored attempt. |
Payments
createCheckout and getCheckoutStatus, plus createAtmCheckoutAttempts. The SDK still exports the legacy initiatePayment and getPaymentStatus; new integrations must not use them.
Profiles
getProfile reads ATM profile data from the AppView.
Tickets
Ticket types, capacity, availability, holds, release, claims, lists, verify and check-in.
Events
Canonical XRPC receiver and HTTP webhook constructors share one envelope shape.
Go live with the SDK
- Keep service-auth minting, attempt storage and webhook secrets on your backend.
- Capture every attempt before contacting ATM, and retry only with its original request and key.
- Reconcile from a backend worker and grant purchases only on completed plus fulfil.
- Verify notification authentication, then queue reconciliation; never grant from the event alone.
- Store delivery IDs, payment IDs and effect keys before sending downloads, emails or app changes.
- Test restart recovery, duplicate deliveries, redrive and unavailable states.
- Live access is a separate review. Never reuse test secrets or receivers in live.
Browser packages
Browser embeds belong in separate packages. ATM checkout embeds can become an @atmosphere-money/checkout-embed wrapper around an ATM-hosted iframe, with hosted checkout as the fallback.