M-MIG-7 — the always-on customer ⇄ CRM ⇄ ERP link (ERP/02; decisions 3, 12, 13, 18). Stacked on #23 (base branch = feat/m-mig-5-products-entitlements); retarget to main once #23 is merged.
Clientinternal/erp: Frappe REST (Authorization: token key:secret) — Customer upsert keyed by the custom field tenant_id, Subscription list, Usage Record, Lead. Webhook HMAC signing/verification (X-Frappe-Webhook-Signature base64 or X-Hub-Signature-256).
Outbox worker: tenant create → customer.upsert (writes back erp_customer_id), usage event → usage.record, catalog request → lead.create; backoff 1 m / 5 m / 15 m / 1 h; idle when ERP_BASE_URL is unset (rows accumulate).
Webhook receiverPOST /v1/internal/erp/webhook (PUBLIC_EXPLICIT, HMAC, idempotent by event id): sales_order.submit → subscriptions + tenant_products (SKU → product, -STD/-BUS/-ENT → plan, add-on SKUs → limits such as runners) + active; sales_invoice.overdue → warning / restricted (≥ ERP_RESTRICT_AFTER_DAYS) / halted (≥ ERP_HALT_AFTER_DAYS), never moving a tenant back up; payment_entry.submit → active (only with an active subscription); subscription.cancel → halted, ERP-sourced entitlements disabled (trials untouched).
Reconcile (every ERP_RECONCILE_INTERVAL, also POST /v1/internal/erp/reconcile): mirrors ERP Subscriptions per customer (safety net for lost webhooks) and applies the time-based steps — trial expiry → restricted, warning → restricted after 14 d, restricted → halted at 30 d, halted → archived after the export window. Every change syncs tenant_status to Keycloak.
UsagePOST /v1/usage/events (one / array / {events}; ≤ 500; user tokens scoped to their tenant), GET /v1/usage/events, GET /v1/subscriptions, GET /v1/internal/erp/status.
ERPNext mock (staging, decision 18)
cmd/erpmock (also shipped in the image as /erpmock): /api/resource/{doctype} list/create/get/update/delete with filters, seeded Items + Subscription Plans for the Phase-1 SKUs, GET /_mock/requests + /_mock/deliveries for test assertions, POST /_mock/fire/{sales-order-submit|invoice-overdue|payment-entry|subscription-cancel} which mutate the docs and deliver the signed webhook to ERP_WEBHOOK_URL. Deployed as erpnext-mock-stage (orca-platform#10).
CLI licences (decision 13)
Ed25519 signer (LICENCE_SIGNING_KEY base64 seed; ephemeral + warning when unset). POST /v1/licences (entitlement-gated; user tokens from the device-flow clients get their own tenant; expiry = min(TTL, entitlement expiry)), GET /.well-known/licence-keys.json (JWKS, OKP), POST /v1/licences/heartbeat (PUBLIC_EXPLICIT — the JWT is the credential; ok | warning | degraded | hard_stop | revoked from the tenant ladder + the token's grace policy 7/14/30 d; renewal past half-life), GET /v1/licences, POST /v1/licences/{id}/revoke.
authn.Principal now carries the tenant-context claims (tenant_id, tenant_slug, tenant_status, email).
Tests
Both stores: webhook ladder end-to-end, usage idempotency + outbox, outbox drained against the real erpmock (customer link, usage synced, lead; fired webhooks round-trip; reconcile picks up an order created only in ERP), ladder escalation with an injected clock, licence issue/heartbeat/renew/revoke. Unit tests for erpmock, erp, licence. CI package set coverage: 73.2 %.
orca's `cmd` sets the container CMD, so with an ENTRYPOINT the stage
service ran `/tenant-registry /bin/sh -c …` (no migrations) and the
erpmock service ran the registry. The image now has CMD only and the
server applies embedded migrations itself when MIGRATE_ON_START=true.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang
merged commit 209524e5ac into main2026-09-12 08:35:14 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
M-MIG-7 — the always-on customer ⇄ CRM ⇄ ERP link (ERP/02; decisions 3, 12, 13, 18). Stacked on #23 (base branch =
feat/m-mig-5-products-entitlements); retarget tomainonce #23 is merged.Schema (migration 0004)
subscriptions(tenant × SKU × Sales Order),usage_events(uniqueidempotency_key,erp_synced_at),erp_outbox(retry/backoff),erp_webhook_receipts(idempotent inbound),licences(revocation + heartbeat),tenants.status_changed_at(trigger) for the time-based ladder.ERP link
internal/erp: Frappe REST (Authorization: token key:secret) — Customer upsert keyed by the custom fieldtenant_id, Subscription list, Usage Record, Lead. Webhook HMAC signing/verification (X-Frappe-Webhook-Signaturebase64 orX-Hub-Signature-256).customer.upsert(writes backerp_customer_id), usage event →usage.record, catalog request →lead.create; backoff 1 m / 5 m / 15 m / 1 h; idle whenERP_BASE_URLis unset (rows accumulate).POST /v1/internal/erp/webhook(PUBLIC_EXPLICIT, HMAC, idempotent by event id):sales_order.submit→ subscriptions +tenant_products(SKU → product,-STD/-BUS/-ENT→ plan, add-on SKUs → limits such asrunners) +active;sales_invoice.overdue→warning/restricted(≥ERP_RESTRICT_AFTER_DAYS) /halted(≥ERP_HALT_AFTER_DAYS), never moving a tenant back up;payment_entry.submit→active(only with an active subscription);subscription.cancel→halted, ERP-sourced entitlements disabled (trials untouched).ERP_RECONCILE_INTERVAL, alsoPOST /v1/internal/erp/reconcile): mirrors ERP Subscriptions per customer (safety net for lost webhooks) and applies the time-based steps — trial expiry →restricted,warning→restrictedafter 14 d,restricted→haltedat 30 d,halted→archivedafter the export window. Every change syncstenant_statusto Keycloak.POST /v1/usage/events(one / array /{events}; ≤ 500; user tokens scoped to their tenant),GET /v1/usage/events,GET /v1/subscriptions,GET /v1/internal/erp/status.ERPNext mock (staging, decision 18)
cmd/erpmock(also shipped in the image as/erpmock):/api/resource/{doctype}list/create/get/update/delete with filters, seeded Items + Subscription Plans for the Phase-1 SKUs,GET /_mock/requests+/_mock/deliveriesfor test assertions,POST /_mock/fire/{sales-order-submit|invoice-overdue|payment-entry|subscription-cancel}which mutate the docs and deliver the signed webhook toERP_WEBHOOK_URL. Deployed aserpnext-mock-stage(orca-platform#10).CLI licences (decision 13)
Ed25519 signer (
LICENCE_SIGNING_KEYbase64 seed; ephemeral + warning when unset).POST /v1/licences(entitlement-gated; user tokens from the device-flow clients get their own tenant; expiry = min(TTL, entitlement expiry)),GET /.well-known/licence-keys.json(JWKS, OKP),POST /v1/licences/heartbeat(PUBLIC_EXPLICIT — the JWT is the credential;ok | warning | degraded | hard_stop | revokedfrom the tenant ladder + the token's grace policy 7/14/30 d; renewal past half-life),GET /v1/licences,POST /v1/licences/{id}/revoke.authn.Principalnow carries the tenant-context claims (tenant_id,tenant_slug,tenant_status,email).Tests
Both stores: webhook ladder end-to-end, usage idempotency + outbox, outbox drained against the real erpmock (customer link, usage synced, lead; fired webhooks round-trip; reconcile picks up an order created only in ERP), ladder escalation with an injected clock, licence issue/heartbeat/renew/revoke. Unit tests for
erpmock,erp,licence. CI package set coverage: 73.2 %.Follow-ups (separate PRs)
Portal billing page + status banner; Firmwerk cloud-server / CLI licence client; Werkpilot licence client; Prüfwerk usage emission; ERP/03 live-ERP configuration (prod).
🤖 Generated with Claude Code
https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
M-MIG-7 (ERP/02, decisions 3, 12, 13, 18): - migration 0004: subscriptions, usage_events, erp_outbox, erp_webhook_receipts, licences; tenants.status_changed_at (trigger) - internal/erp: Frappe REST client (Customer upsert by tenant_id, Subscription list, Usage Record, Lead) + webhook signing/verification - internal/erpmock + cmd/erpmock: ERPNext stand-in for staging — /api/resource/{doctype} with token auth, request log, /_mock/fire/* triggers that mutate docs and deliver signed webhooks - POST /v1/internal/erp/webhook (HMAC, idempotent by event id): sales_order.submit → subscriptions + entitlements (SKU → product/plan, add-on SKUs → limits) + active; sales_invoice.overdue → warning / restricted / halted by days overdue; payment_entry.submit → active; subscription.cancel → halted - outbox worker (customer.upsert on tenant create, usage.record, lead.create on catalog request) with backoff; reconcile job mirrors ERP subscriptions and applies the time-based ladder (trial expiry, warning→restricted 14 d, restricted→halted 30 d, halted→archived 30 d) - POST/GET /v1/usage/events (idempotency_key, batch), GET /v1/subscriptions, GET /v1/internal/erp/status, POST /v1/internal/erp/reconcile - CLI licences: Ed25519 signer (LICENCE_SIGNING_KEY), POST /v1/licences (entitlement-gated, expiry capped by the entitlement), GET /.well-known/licence-keys.json, POST /v1/licences/heartbeat (grace ladder, renewal past half-life, revoked), revoke/list - authn Principal carries tenant-context claims (user tokens scope usage and licence calls to their own tenant); authz groups usage(.read) - tests for every path (both stores), erpmock, erp client, licence pkg; openapi.yaml + README updated; Dockerfile ships /erpmock Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsBa7d7e22994to7b02cd1c21