Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Binding: Avalara Integration Foundation (#1061)
Kind
feature
Risk
medium — No DB schema changes beyond one seed row. Touches packages/ee, packages/env, ERP routes, and apps/erp settings wiring. No SST infra changes. Risk is correctness of the typed client (auth plumbing, retry policy, error taxonomy) and following the Xero/Plaid precedent exactly.
Issue
crbnos/carbon#1061
Spec
.ai/specs/2026-07-04-avalara-integration-foundation.md (from period-closing-spec branch / PR #1013 — read via git show origin/period-closing-spec:.ai/specs/2026-07-04-avalara-integration-foundation.md)
Plan
.ai/plans/2026-07-04-avalara-integration-foundation.md (from period-closing-spec branch — read via git show origin/period-closing-spec:.ai/plans/2026-07-04-avalara-integration-foundation.md)
IMPORTANT: The spec and plan files do not exist on
mainyet (they're in PR #1013 /period-closing-spec). Read them viagit show origin/period-closing-spec:.ai/specs/2026-07-04-avalara-integration-foundation.mdandgit show origin/period-closing-spec:.ai/plans/2026-07-04-avalara-integration-foundation.md.
Summary
Ship the shared Avalara substrate for both US sales-tax determination (#1044) and EU e-invoicing clearance (#1054). Following the Xero integration architecture exactly: registry entry (defineIntegration, id avalara), per-company config in companyIntegration.metadata, server lifecycle hooks, and a typed REST client covering AvaTax + e-invoicing surfaces. Credentials are env-level (AVALARA_ACCOUNT_ID + AVALARA_LICENSE_KEY for AvaTax; AVALARA_CLIENT_ID + AVALARA_CLIENT_SECRET for e-invoicing Avalara Identity OAuth2). Integration hidden unless env creds present. No new tables; one idempotent seed migration for the registry row.
Package layout
packages/ee/src/avalara/
├── config.tsx # defineIntegration registry entry (browser-safe — NO server imports)
├── hooks.server.ts # onInstall / onUninstall / onHealthcheck
├── service.server.ts # getAvalaraClient(companyId), getAvalaraConfig(companyId), isAvalaraFeatureEnabled(...)
├── lib/
│ ├── client.ts # AvalaraClient — shared HTTP core: auth, base URLs, retry, timeout, error taxonomy
│ ├── avatax.ts # AvaTax surface: ping, companies, createTransaction, commit, void, resolveAddress, listNexus
│ ├── einvoicing.ts # E-invoicing surface: submitDocument, getDocumentStatus, listDocuments, listMandates
│ └── types.ts # namespace Avalara — request/response models for both surfaces
└── index.ts # barrel
Critical constraints (non-negotiable)
config.tsxmust never importservice.server.ts,hooks.server.ts, or client files — it's bundled for the browser (seepackages/ee/AGENTS.md"Never").- No plaintext secrets in
companyIntegration.metadata— only non-secret config. - No whole-repo typecheck — OOMs. Run
pnpm --filter @carbon/ee typecheckandpnpm --filter @carbon/erp typecheck. - No
pnpm run generate:types— no DB schema changes. - License key never logged — error messages include taxonomy
kind+ Avalara message only. - E-invoicing auth: assume Avalara Identity OAuth2 client-credentials model —
AVALARA_CLIENT_ID/AVALARA_CLIENT_SECRETenv pair + token manager. If sandbox testing proves license-key auth suffices, remove the token manager. - Retry policy: retry ONLY on 429 (honor
Retry-After), 502/503/504, and network errors. NEVER retry on 4xx. NEVER auto-retry acommit: truecall after an ambiguous timeout without idempotentcode. - Sandbox default: new installs default to
environment: sandbox.
Acceptance criteria
- With
AVALARA_ACCOUNT_ID/AVALARA_LICENSE_KEYunset → Avalara card absent from/x/settings/integrations;getAvalaraClient()returns a typed "not configured" error. - With env set → card appears under Tax & Compliance; install with a
companyCode(chosen from livelistCompanies()options) persistscompanyIntegration.metadatamatchingAvalaraSettingsSchemawith no secret material in the row. onHealthcheckreturns healthy only whenping().authenticated === trueAND company code resolves; wrong license key or bogus code → unhealthy badge.- Test Connection flashes environment + resolved company name on success; taxonomy-mapped reason (
authvsnot_foundvstransient) on failure. - Unit tests (mocked fetch) prove:
- Basic-auth header +
X-Avalara-Clientsent on AvaTax calls - 429 honored via
Retry-Afterthen succeeds - 400 maps to
validationwith parseddetails[], NOT retried - 503 retries then maps to
transient - Timeout aborts at configured budget
- Basic-auth header +
- Sandbox smoke (mocked in CI, env-gated for live):
createTransaction({ type: "SalesOrder" })returns computedtotalTax+details[];resolveAddressreturns validated address;voidTransactionreturnsCancelled. - Feature toggles:
isAvalaraFeatureEnabled(companyId, "taxDetermination")reflects the switch; both toggles independent. pnpm --filter @carbon/ee typecheck✅,pnpm --filter @carbon/erp typecheck✅,pnpm --filter @carbon/ee test✅,pnpm run lint✅.
Reference: Xero precedent
- Registry entry:
packages/ee/src/xero/config.tsx - Hooks (no Avalara subscriptions needed — Avalara is outbound only):
packages/ee/src/xero/hooks.server.ts - Env vars pattern:
packages/env/src/index.tslines forXERO_CLIENT_ID/XERO_CLIENT_SECRET integrationsarray:packages/ee/src/index.ts
Reference: Plaid credential precedent
- Token storage (AES-GCM / Vault probe):
.ai/specs/2026-07-02-plaid-bank-feeds.md§Token storage
Seed migration
-- packages/database/supabase/migrations/YYYYMMDDHHMMSS_add-avalara-integration.sql
INSERT INTO "integration" ("id", "jsonschema")
VALUES ('avalara', '{"type": "object", "properties": {}}'::json)
ON CONFLICT ("id") DO NOTHING;
Use the current timestamp for the filename. Do NOT run generate:types.
API routes
apps/erp/app/routes/api+/integrations.avalara.test.ts— action: uncached healthcheck, flash resultapps/erp/app/routes/api+/integrations.avalara.companies.ts— loader:listCompanies()for dynamiccompanyCodeoptions- Wired in
apps/erp/app/modules/settings/settings.server.tsdynamic-options section (beside Xero accounts)