@orangecheck/me-client 0.31.0 → 0.32.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/subtypes.ts","../src/templates.ts"],"names":[],"mappings":";AAkBO,IAAM,mBAAA,GAAsB;AAAA;AAAA,EAE/B,GAAA,EAAK,GAAA;AAAA;AAAA,EAEL,cAAA,EAAgB,CAAA;AAAA;AAAA;AAAA,EAGhB,QAAA,EAAU;AACd;AASO,IAAM,yBAAA,GAA4B;AAelC,IAAM,yBAAA,GAA4B,GAAA;AAoIlC,SAAS,WAAA,CACZ,GAAA,EACA,mBAAA,EACA,IAAA,EACY;AACZ,EAAA,MAAM,QAAA,GAAW,MAAM,QAAA,KAAa,IAAA;AACpC,EAAA,IAAI,QAAA,IAAY,GAAA,CAAI,KAAA,EAAO,MAAA,EAAQ;AAC/B,IAAA,MAAM,IAAI,MAAM,eAAe,CAAA;AAAA,EACnC;AACA,EAAA,MAAM,mBAAA,GACF,YAAY,GAAA,CAAI,KAAA,EAAO,YAAY,GAAA,CAAI,KAAA,CAAM,YAAY,GAAA,CAAI,SAAA;AACjE,EAAA,MAAM,wBAAA,GACF,QAAA,IAAY,OAAO,GAAA,CAAI,KAAA,EAAO,mBAAmB,QAAA,GAC3C,GAAA,CAAI,KAAA,CAAM,cAAA,GACV,GAAA,CAAI,cAAA;AAEd,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,IAAI,mBAAA,CAAoB,SAAS,YAAA,EAAc;AAC3C,IAAA,KAAA,GAAQ,KAAK,GAAA,CAAI,yBAAA,EAA2B,KAAK,KAAA,CAAM,mBAAA,CAAoB,IAAI,CAAC,CAAA;AAAA,EACpF,CAAA,MAAO;AACH,IAAA,IAAI,uBAAuB,IAAA,EAAM;AAC7B,MAAA,MAAM,IAAI,MAAM,uDAAuD,CAAA;AAAA,IAC3E;AACA,IAAA,KAAA,GAAQ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A,EACqB;AACrB,EAAA,MAAM,QAAA,GAAW,iBAAiB,OAAO,CAAA;AACzC,EAAA,IAAI,CAAC,QAAA,EAAU;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,CAAA,2CAAA,EAA8C,OAAO,CAAA,UAAA,EAAa,MAAA,CAAO,IAAA;AAAA,QACrE;AAAA,OACJ,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,KAChB;AAAA,EACJ;AACA,EAAA,MAAM,SAA0C,EAAC;AACjD,EAAA,KAAA,MAAW,OAAO,YAAA,EAAc;AAC5B,IAAA,MAAA,CAAO,GAAG,CAAA,GAAI,QAAA,CAAS,MAAA,CAAO,GAAG,CAAA,IAAK,gBAAA;AAAA,EAC1C;AACA,EAAA,OAAO;AAAA,IACH,aAAa,QAAA,CAAS,WAAA;AAAA,IACtB,QAAQ,QAAA,CAAS,MAAA;AAAA,IACjB,cAAc,QAAA,CAAS,YAAA;AAAA,IACvB,UAAA,EAAA,iBAAY,IAAI,IAAA,EAAK,EAAE,WAAA,EAAY;AAAA,IACnC;AAAA,GACJ;AACJ;AAIO,SAAS,qBAAqB,EAAA,EAA4C;AAC7E,EAAA,OAAO,iBAAiB,EAAE,CAAA;AAC9B","file":"integrator.mjs","sourcesContent":["/**\n * Canonical types for me.ochk.io integrators.\n *\n * Mirrors the source of truth at oc-me-web/src/lib/events/types.ts. Two\n * layers:\n * - Platform-level (PLATFORM_FEE_POLICY, MIN_INTEGRATOR_PRICE_SATS) —\n * fixed by OC, surfaced as constants here so integrators can validate\n * their config client-side before posting it.\n * - Integrator-level (IntegratorPriceConfig) — every integrator declares\n * their own per-event prices and user-share splits.\n *\n * Per Addendum 01: every chargeable event is in exactly one of three\n * classes. Sites pay for sessions and actions, not for clicks. Free\n * events never instantiate a BillableEvent.\n */\n\n// ── platform constants (fixed by OC) ──────────────────────────────────────\n\nexport const PLATFORM_FEE_POLICY = {\n /** Fraction of every gross_fee that OC retains. */\n pct: 0.2,\n /** Absolute minimum platform fee, in sats. */\n min_floor_sats: 1,\n /** Date this policy was last ratified. Changes require a versioned\n * @orangecheck/me-client release. */\n ratified: '2026-04-30',\n} as const;\n\n/** Per-event price floor. 1 sat — the natural atomic Bitcoin unit.\n * Integrators choose their own per-event prices above this; OC does\n * not impose sybil-resistance opinions on integrators (that's their\n * call, from their own threat model). The 1-sat floor is purely\n * mechanical — fees can't be fractional sats. Mirrors the canonical\n * value at oc-me-web/src/lib/events/types.ts (a previous SDK release\n * drifted to 5 while the platform ratified 1). */\nexport const MIN_INTEGRATOR_PRICE_SATS = 1;\n\n/**\n * Hard per-event ceiling, mirroring the server's own bound.\n *\n * The server clamps gross to this before splitting it; this package did not,\n * so `verify()` re-derived 99,000,000 for an envelope the server had recorded\n * at 10,000,000 and rejected a correct receipt. It also over-reported what a\n * misconfigured site would be charged, by the ratio of the two numbers.\n *\n * 10,000,000 sats = 0.1 BTC: orders of magnitude above any real per-event\n * price, low enough that a misconfiguration cannot mint an unbounded number\n * of sats in one event. Found by the cross-package vector test in oc-me-web\n * on its first run.\n */\nexport const MAX_INTEGRATOR_PRICE_SATS = 10_000_000;\n\n/** Platform ceiling on drop-period windows: no integrator schedule may\n * hold a user's earned share open longer than this, regardless of\n * cadence. Published in ABUSE_LIMITS on me.ochk.io /trust + /security. */\nexport const MAX_DROP_WINDOW_DAYS = 92;\n\n// ── event taxonomy ────────────────────────────────────────────────────────\n\nexport type EventClass = 'A' | 'B' | 'C';\n\nexport type ClassASubtype =\n | 'account_creation'\n | 'account_recovery'\n | 'attest_bond_increased'\n | 'payment_method_connected'\n | 'agent_delegation_issued'\n | 'recovery_method_updated';\n\nexport type ClassBSubtype =\n | 'payment_authorization'\n | 'scoped_action_authorization'\n | 'attest_verification_at_gate'\n | 'stamp_signing'\n | 'pledge_resolution';\n\nexport type ClassCSubtype = 'session_creation';\n\nexport type EventSubtype = ClassASubtype | ClassBSubtype | ClassCSubtype;\n\n/**\n * Any billable event key. A project's catalog is OPEN: alongside the built-in\n * subtypes above, an integrator can define their own event keys (with their own\n * label + class + price) on the project config. `EventKey` keeps autocomplete\n * for the built-ins while accepting any custom string — the `(string & {})`\n * arm preserves the literal union in editors instead of collapsing it to\n * `string`. The server resolves class/label off the project's catalog for\n * custom keys.\n */\nexport type EventKey = EventSubtype | (string & {});\n\n/** AttestTier · what an integrator's gate can read about an oc identity.\n *\n * me.ochk does NOT do KYC. Sybil resistance is bounded by three\n * composable mechanisms, none of which involve OC handling PII:\n * 1. paid-action history · billable events cost real sats\n * 2. BIP-322 sat-bonding · bond size + age via signed attestation\n * 3. integrator-defined gates · per-site threat-model overlays\n *\n * Tier itself is intentionally simple — anonymous | bonded.\n * Granularity (bond_sats, bond_locked_at, etc) carried separately. */\nexport type AttestTier = 'anonymous' | 'bonded';\n\n/** The shape of a per-event fee — either a fixed sats amount or a percent\n * of the underlying transaction amount (used for payments + pledges). */\nexport type SiteFeeShape =\n | { kind: 'fixed_sats'; sats: number }\n | { kind: 'percent_of_amount'; pct: number };\n\n/** Optional per-class pricing overrides · per OCHK-V3-PLAN §7 phase-1.\n * Agents acting under a scoped oc-agent delegation may bill\n * differently than humans firing the same subtype. When `agent` is\n * unset on a subtype, agent traffic bills at the human rate. `refuse:\n * true` makes the subtype human-only — the endpoint returns 422\n * agent_refused for is_agent=true requests. */\nexport interface AgentClassOverride {\n /** Override site_pays for agent-fired events. */\n site_pays?: SiteFeeShape;\n /** Override user_share_pct. Same default-fallback as site_pays. */\n user_share_pct?: number;\n /** When true, agent traffic is refused for this subtype. */\n refuse?: boolean;\n}\n\n/** What an integrator declares for a single event subtype. */\nexport interface IntegratorEventConfig {\n /** Whether this site bills this event subtype at all. */\n enabled: boolean;\n /** The per-event fee the site pays. */\n site_pays: SiteFeeShape;\n /** Fraction of GROSS that flows to the user (0–0.8 since the\n * platform fee is 20%). The remainder is a rebate to the site's\n * OC project balance. */\n user_share_pct: number;\n /** Optional per-agent-class pricing override applied when an event\n * fires with is_agent=true. */\n agent?: AgentClassOverride;\n}\n\n/** A complete integrator pricing config. Posted to me.ochk.io once at\n * integration time, mutable via the configurator UI or this SDK any time\n * after. */\nexport interface IntegratorPriceConfig {\n project_key: string;\n display_name: string;\n domain: string;\n /** ISO-8601 timestamp the config was last updated. */\n updated_at: string;\n /** Per-event configs, keyed by event key. Open catalog: built-in subtypes\n * AND your own custom keys. Keys not listed are disabled by default. */\n events: Partial<Record<EventKey, IntegratorEventConfig>>;\n}\n\n/** A computed fee breakdown for a single event. site_rebate_sats is what\n * flows back to the developer's balance after the platform fee and what\n * the user earns: zero at the full user share, 0.8. */\nexport interface ComputedFees {\n gross_fee_sats: number;\n platform_fee_sats: number;\n user_earned_sats: number;\n site_rebate_sats: number;\n}\n\n/** Compute the four-way fee split for an event given an integrator's\n * config and (for percent_of_amount events) the underlying payment\n * amount. MIRRORS oc-me-web/src/lib/events/types.ts computeFees()\n * EXACTLY — the SDK-side replay (oc.event.verify) re-runs this against\n * envelopes the server billed, so any drift is a false \"divergence\".\n *\n * Invariants:\n * 1. gross_fee_sats >= MIN_INTEGRATOR_PRICE_SATS (1-sat atomic floor)\n * 2. platform_fee_sats = min(gross, max(min_floor, round(gross × pct)))\n * — bounded above by gross so a 1-sat event can't owe more\n * platform fee than it grossed\n * 3. user_earned_sats = min(gross − platform, round(gross × share)),\n * share clamped to [0, 0.8]\n * 4. site_rebate_sats = gross − platform − user (exact remainder)\n * 5. gross == platform + user + rebate exactly\n *\n * When `opts.is_agent` is true AND the config has an `agent` override,\n * the agent's site_pays / user_share_pct apply. `agent.refuse: true`\n * throws 'agent_refused' (the server maps it to 422). */\nexport function computeFees(\n cfg: IntegratorEventConfig,\n payment_amount_sats?: number,\n opts?: { is_agent?: boolean }\n): ComputedFees {\n const is_agent = opts?.is_agent === true;\n if (is_agent && cfg.agent?.refuse) {\n throw new Error('agent_refused');\n }\n const effective_site_pays =\n is_agent && cfg.agent?.site_pays ? cfg.agent.site_pays : cfg.site_pays;\n const effective_user_share_pct =\n is_agent && typeof cfg.agent?.user_share_pct === 'number'\n ? cfg.agent.user_share_pct\n : cfg.user_share_pct;\n\n let gross = 0;\n if (effective_site_pays.kind === 'fixed_sats') {\n gross = Math.max(MIN_INTEGRATOR_PRICE_SATS, Math.round(effective_site_pays.sats));\n } else {\n if (payment_amount_sats == null) {\n throw new Error('percent_of_amount config requires payment_amount_sats');\n }\n gross = Math.max(\n MIN_INTEGRATOR_PRICE_SATS,\n Math.round(payment_amount_sats * effective_site_pays.pct)\n );\n }\n // Hard ceiling · no single event mints more than MAX_INTEGRATOR_PRICE_SATS.\n // The server applies this before splitting; omitting it here made verify()\n // reject correct envelopes priced above the bound.\n gross = Math.min(gross, MAX_INTEGRATOR_PRICE_SATS);\n const platform_fee_sats = Math.min(\n gross,\n Math.max(PLATFORM_FEE_POLICY.min_floor_sats, Math.round(gross * PLATFORM_FEE_POLICY.pct))\n );\n const user_share = Math.min(0.8, Math.max(0, effective_user_share_pct));\n const user_earned_sats = Math.min(gross - platform_fee_sats, Math.round(gross * user_share));\n const site_rebate_sats = gross - platform_fee_sats - user_earned_sats;\n return { gross_fee_sats: gross, platform_fee_sats, user_earned_sats, site_rebate_sats };\n}\n\n/** Result of validating an IntegratorPriceConfig. */\nexport interface ValidationResult {\n ok: boolean;\n errors: { subtype?: EventKey; message: string }[];\n}\n\n/**\n * Validate an integrator's pricing config against the platform's\n * non-negotiable rules. Run client-side before posting; the server runs\n * the same checks and rejects anything that fails.\n */\nexport function validateIntegratorConfig(cfg: IntegratorPriceConfig): ValidationResult {\n const errors: ValidationResult['errors'] = [];\n\n if (!cfg.project_key) errors.push({ message: 'project_key is required' });\n if (!cfg.display_name) errors.push({ message: 'display_name is required' });\n if (!cfg.domain) errors.push({ message: 'domain is required' });\n\n for (const [key, eventCfg] of Object.entries(cfg.events)) {\n if (!eventCfg) continue;\n const subtype = key as EventKey;\n if (!eventCfg.enabled) continue;\n\n if (eventCfg.site_pays.kind === 'fixed_sats') {\n if (eventCfg.site_pays.sats < MIN_INTEGRATOR_PRICE_SATS) {\n errors.push({\n subtype,\n message: `site_pays.sats (${eventCfg.site_pays.sats}) is below MIN_INTEGRATOR_PRICE_SATS (${MIN_INTEGRATOR_PRICE_SATS})`,\n });\n }\n } else {\n const pct = eventCfg.site_pays.pct;\n if (!(pct > 0 && pct <= 1)) {\n errors.push({\n subtype,\n message: `site_pays.pct (${pct}) must be in (0, 1]`,\n });\n }\n }\n\n const u = eventCfg.user_share_pct;\n if (u < 0 || u > 0.8) {\n errors.push({\n subtype,\n message: `user_share_pct (${u}) must be in [0, 0.8]; max is 0.8 because platform_fee is ${PLATFORM_FEE_POLICY.pct}`,\n });\n }\n }\n\n return { ok: errors.length === 0, errors };\n}\n\n// ── canonical envelope ────────────────────────────────────────────────────\n\nexport interface BillableEvent {\n id: string;\n occurred_at: string;\n class: EventClass;\n subtype: EventKey;\n site: { domain: string; display_name: string };\n gross_fee_sats: number;\n platform_fee_sats: number;\n user_earned_sats: number;\n site_rebate_sats: number;\n verify_url: string;\n /** Per OCHK-V3-PLAN §7 phase-1 · true when the event was fired by\n * an oc-agent delegation rather than a human session. The\n * integrator's IntegratorEventConfig.agent block may price\n * these differently or refuse them. Optional · canonical encoder\n * branches to v=3 only when present, so legacy human-fired\n * events keep their v=2 hash + signature. */\n is_agent?: boolean;\n /** Drop-period stamp · present when the project covers this\n * subtype with a drop schedule. The user-share of a stamped event\n * MATURES until the window's boundary, then vests as one batch\n * (the drop). Billing is untouched. Part of the SIGNED canonical\n * bytes (encoder branches to v=4 when present). No clawback\n * exists — vesting is unconditional, and an open window's\n * boundary can only ever move earlier. */\n drop?: {\n /** Deterministic window id · the window's signed manifest is\n * verifiable at me.ochk.io/verify/<manifest_id> after close. */\n window_id: string;\n /** Block-denominated vesting boundary; null when no chain tip\n * was observable at window open (wallclock + the published\n * 24h safety valve then govern). */\n close_height_target: number | null;\n } | null;\n}\n\n// ── drop periods · integrator-scheduled payout windows ───────────────────\n\n/** A drop schedule's cadence. Weekly/monthly close at a fixed UTC\n * boundary; manual closes when the integrator says (Drop now), with a\n * hard auto-close at max_open_days (≤ MAX_DROP_WINDOW_DAYS). */\nexport type DropCadence =\n | { kind: 'weekly'; day: number; hour: number }\n | { kind: 'monthly'; day: number; hour: number }\n | { kind: 'manual'; max_open_days: number };\n\n/** Public shape of an enabled drop schedule, as returned in the\n * `drops` array of GET /api/integrator/config — part of the project's\n * public payout contract (earners can see when covered subtypes pay\n * out before earning under them). */\nexport interface DropScheduleSummary {\n schedule_id: string;\n label: string;\n subtypes: EventSubtype[];\n cadence: DropCadence;\n}\n\n/** Drop-period context on event-ingest responses (single route:\n * top-level `drop`; batch route: per-result `drop`). `state` flips\n * from 'open' to 'closing' once the scheduled boundary passes and the\n * window awaits its sweep (~15 min) — render \"processing\", never a\n * negative countdown. */\nexport interface DropResponseBlock {\n window_id: string;\n label: string;\n state: 'open' | 'closing';\n closes_at_target: string;\n close_height_target: number | null;\n}\n\n// ── webhook payload ───────────────────────────────────────────────────────\n\n/**\n * The exact JSON body delivered to a registered webhook endpoint when\n * a billable event fires. Imported by integrator backends so the\n * receive handler is type-checked end-to-end without re-declaring the\n * shape.\n *\n * import type { WebhookPayload } from '@orangecheck/me-client';\n *\n * export async function POST(req: Request) {\n * const payload = (await req.json()) as WebhookPayload;\n * if (payload.subtype === 'payment_authorization') {\n * creditUser(payload.sub, payload.user_earned_sats);\n * }\n * }\n *\n * Headers carry the signature and metadata (see WebhookHeaders below).\n * Verify the signature with `oc.webhook.verify({ body, headers, jwks })`.\n *\n * Privacy contract · the master oc identity is NEVER in the payload.\n * Integrators see `sub` (per-integrator anonymous id) plus any\n * `scopes` the user explicitly granted. See PRIVACY-ARCHITECTURE.md.\n */\nexport interface WebhookPayload extends BillableEvent {\n /** Discriminator · identifies the payload kind for routing on\n * the integrator's side. Always 'oc-billable-event' today; future\n * webhook payload kinds (refunds, charters, etc) will use\n * distinct discriminator values. */\n kind: 'oc-billable-event';\n /** Per-integrator anonymous subject id · stable across events for\n * the same (oc_identity, project_key) pair. Key your user records\n * on this; OC will never give you the master address unless the\n * user explicitly grants `bitcoin_address` or `email` scope. */\n sub: string;\n /** Resolved scoped fields · only present for scopes the user has\n * granted to this project. Wire format is string-keyed (every\n * value is stringified · ints stringified, addresses as-is). */\n scopes?: Partial<\n Record<\n | 'bitcoin_address'\n | 'email'\n | 'attest_tier'\n | 'display_name'\n | 'cross_integrator_event_count'\n | 'cross_integrator_human_event_count'\n | 'trust_attestation_count'\n | 'trust_attestations_bundle',\n string\n >\n >;\n}\n\n/**\n * Non-billable SYSTEM webhook deliveries — project-level operational\n * signals (escrow.low, escrow.depleted, escrow.recovered, drop.closed).\n * Same signing + headers as billable deliveries; receivers subscribe\n * via the same `subscribed` list ('*' or the explicit subtype string).\n * Carries no user identity. Discriminate on `kind` first, then\n * `subtype`:\n *\n * const payload = JSON.parse(body) as WebhookPayload | SystemWebhookPayload;\n * if (payload.kind === 'oc-system-event' && payload.subtype === 'drop.closed') { … }\n */\nexport interface SystemWebhookPayload {\n kind: 'oc-system-event';\n subtype: string;\n project_key: string;\n [extra: string]: unknown;\n}\n\n/** The `drop.closed` system event — one per closed drop window. The\n * manifest is the signed, content-addressed record (Merkle commitments\n * over member events + recipients); verify_url renders + live-verifies\n * it, and /api/envelope/<manifest_id> serves the raw canonical bytes. */\nexport interface DropClosedWebhookPayload extends SystemWebhookPayload {\n subtype: 'drop.closed';\n window_id: string;\n schedule_id: string;\n label: string;\n manifest_id: string;\n verify_url: string;\n sealed_at: string;\n sealed_height: number | null;\n event_count: number;\n recipient_count: number;\n gross_fee_sats: number;\n user_share_sats: number;\n}\n\n/**\n * HTTP headers OC sends with every webhook delivery. Capture these in\n * the receive handler · `OC-Signature` is what verifies the body.\n */\nexport interface WebhookHeaders {\n /** Ed25519 signature over the raw response body, hex-encoded. */\n 'OC-Signature': string;\n /** Stable kid of the signing key · resolves against\n * ochk.io/.well-known/jwks.json. */\n 'OC-Key-Id': string;\n /** Envelope id · matches payload.id; useful for idempotent\n * receive handlers that dedupe on this header without parsing\n * the body. */\n 'OC-Envelope-Id': string;\n /** Subtype · matches payload.subtype (built-in or a custom event key);\n * lets routers branch on the header before parsing. */\n 'OC-Subtype': EventKey;\n /** Class · matches payload.class. */\n 'OC-Class': EventClass;\n /** 1-indexed delivery attempt count. >1 means the prior attempt\n * did not return a 2xx within the timeout · idempotency key on\n * payload.id is critical. */\n 'OC-Delivery-Attempt': string;\n}\n\n// ── session lifecycle ────────────────────────────────────────────────────\n\nexport interface SessionPolicy {\n duration_seconds: number;\n refresh: 'sliding' | 'rolling' | 'none';\n sensitive_actions?: 're-auth' | 'none';\n}\n\nexport interface Session {\n id: string;\n identity: string;\n opens_at: string;\n expires_at: string;\n policy: SessionPolicy;\n scope: string[];\n}\n\nexport interface SignInOptions {\n scope: string[];\n sessionPolicy?: Partial<SessionPolicy>;\n returnTo?: string;\n}\n\nexport interface PaymentAuthorizeOptions {\n identity: string;\n amount_sats?: number;\n usd_cents?: number;\n description: string;\n external_ref?: string;\n}\n\nexport interface PaymentResult {\n id: string;\n status: 'authorized' | 'failed' | 'cancelled';\n sats_charged?: number;\n user_envelope_id?: string;\n verify_url?: string;\n}\n\nexport interface TelemetryEvent {\n code:\n | 'session.intra_signin'\n | 'session.token_refresh'\n | 'session.navigation'\n /** Emitted by `session.invalidate()`. Was `session.intra_signin`, which\n * means the opposite thing — \"user pressed sign-in while a valid\n * session was already open\" — so a subscriber saw a sign-in event\n * every time the integrator tore a session down. Non-billable. */\n | 'session.teardown'\n | 'auth.signin_failed'\n | 'auth.signin_cancelled'\n | 'auth.signin_rejected'\n | 'verify.passive_check';\n timestamp: string;\n session_id?: string;\n}\n\n// ── federation directory ───────────────────────────────────────────────\n//\n// The SDK consumes the federation directory at runtime so multi-federation\n// routing is a directory write, not a code change. v1 has one live\n// federation; the directory is plural-shaped so federation #2 lights up\n// without an SDK release.\n\nexport type FederationStatus = 'recruiting' | 'forming' | 'binding' | 'live';\n\n/** Federation directory entry. Mirrors `oc-me-web/src/lib/federations/registry.ts`\n * field-for-field; this package is the public consumption shape. */\nexport interface Federation {\n slug: string;\n name: string;\n status: FederationStatus;\n threshold: string;\n target_guardian_count: number;\n /** Fedimint invite code; null until status === 'live'. */\n invite: string | null;\n /** SHA-256 of the canonical federation charter, hex-encoded. */\n charter_hash: string | null;\n /** ISO-8601 of the most recent ongoing-attestation envelope. */\n last_attestation_at: string | null;\n geography_hint: string;\n // Operator-recruiting fields (present on slots in 'recruiting' /\n // 'forming' / 'binding' state). Nullable so one shape spans the\n // lifecycle.\n geography_requirements?: string;\n charter_status?: string;\n ceremony_window?: string;\n why_this_one?: string;\n apply_cta?: string;\n apply_href?: string;\n}\n\n/** SigningMethod discriminator on the user identity. Federation-agnostic\n * by construction — the OC identity (did:email or BIP-322 address)\n * remains stable across all three states. Transitions are recorded as\n * anchored \"rebind\" envelopes on the canonical event log. Graduation\n * is the product thesis; this discriminator is the structural primitive\n * that records where a user is on the custody-state graph. */\nexport type SigningMethod = 'fedimint_threshold' | 'fedimint_client' | 'bip322';\n","/**\n * Rich metadata for every billable event subtype.\n *\n * The SDK already exports the `EventSubtype` union (closed enum, type-\n * checked), but a new integrator picking between\n * `'scoped_action_authorization'` and `'stamp_signing'` and\n * `'attest_verification_at_gate'` has no inline guidance on which fits\n * their flow. This file is the canonical \"when do I use this subtype\"\n * reference, programmatically accessible:\n *\n * import { oc, EVENT_SUBTYPES } from '@orangecheck/me-client';\n *\n * for (const meta of Object.values(EVENT_SUBTYPES)) {\n * console.log(`${meta.id} (class ${meta.class}) — ${meta.fires_when}`);\n * }\n *\n * Or per-subtype:\n *\n * const meta = EVENT_SUBTYPES.account_creation;\n * console.log(meta.example); // → \"user signed up via email-OTP and the account row was inserted\"\n *\n * Used by `oc.config.fromTemplate()` to assemble archetype configs and\n * by /me/projects/* dashboards to drive consent prompts and config\n * editor labels from a single source.\n */\n\nimport type { EventClass, EventSubtype } from './types';\n\nexport interface EventSubtypeMetadata {\n id: EventSubtype;\n class: EventClass;\n /** Short label · matches SUBTYPE_LABELS on the server. */\n label: string;\n /** When this fires · imperative-mood plain English. The integrator\n * reads this to know which event in their codebase should call\n * `oc.event.fire()` with this subtype. */\n fires_when: string;\n /** A concrete example from a typical SaaS · helps integrators map\n * an unfamiliar subtype name to a real flow they recognize. */\n example: string;\n /** Common use cases · lets integrators search their own product\n * for matching flows. Two-three terms each, lowercase. */\n common_use_cases: readonly string[];\n /** What an integrator typically pays for this subtype, anchored at\n * $1 ≈ 1052 sats. Returns null for percent-of-amount subtypes\n * where the price scales with the underlying transaction. */\n typical_price_hint: string;\n}\n\nexport const EVENT_SUBTYPES: Record<EventSubtype, EventSubtypeMetadata> = {\n // ── Class A · durable state transitions ──\n account_creation: {\n id: 'account_creation',\n class: 'A',\n label: 'account creation',\n fires_when:\n 'a new oc identity creates a durable account record on your surface (first sign-in, profile row inserted)',\n example: 'user signed up via email-OTP and your account row was inserted in your DB',\n common_use_cases: ['onboarding', 'signup', 'registration', 'first-login'],\n typical_price_hint: '~1300 sats (~$1.24)',\n },\n account_recovery: {\n id: 'account_recovery',\n class: 'A',\n label: 'account recovery',\n fires_when:\n 'a user re-binds an existing account to a new device or recovery method',\n example: 'user lost their device and recovered the account via email OTP + recovery code',\n common_use_cases: ['recovery', 'device-rebind', 'restore-access'],\n typical_price_hint: '~650 sats (~$0.62)',\n },\n attest_bond_increased: {\n id: 'attest_bond_increased',\n class: 'A',\n label: 'attest bond increased',\n fires_when:\n 'a user upgrades their bond size (locks more sats to attest_tier=bonded with higher cap)',\n example: 'user moved from 10k-sat bond to 100k-sat bond to clear your higher-trust gate',\n common_use_cases: ['bond-upgrade', 'tier-promotion', 'sybil-resistance'],\n typical_price_hint: '~1600 sats (~$1.52) · OFF by default',\n },\n payment_method_connected: {\n id: 'payment_method_connected',\n class: 'A',\n label: 'payment method connected',\n fires_when:\n 'a user connects a Lightning address, BIP-322 wallet, or payment-routing channel to their account',\n example: 'user pasted a lightning@address.com receive address into their profile',\n common_use_cases: ['payment-setup', 'wallet-connect', 'payout-config'],\n typical_price_hint: '~320 sats (~$0.30)',\n },\n agent_delegation_issued: {\n id: 'agent_delegation_issued',\n class: 'A',\n label: 'agent delegation issued',\n fires_when:\n 'a user signs an oc-agent delegation envelope authorizing an AI agent to act on their behalf',\n example: 'user delegated a \"summarize my emails\" agent for 24 hours with scope email:read',\n common_use_cases: ['agent-grant', 'ai-delegation', 'scoped-authorization'],\n typical_price_hint: '~320 sats · OFF by default (power-user)',\n },\n recovery_method_updated: {\n id: 'recovery_method_updated',\n class: 'A',\n label: 'recovery method updated',\n fires_when:\n 'a user changes their recovery email, recovery key, or social-recovery contacts',\n example: 'user rotated their recovery email after a phone change',\n common_use_cases: ['recovery-rotation', 'security-update'],\n typical_price_hint: '~160 sats (~$0.15)',\n },\n\n // ── Class B · action-bound ──\n payment_authorization: {\n id: 'payment_authorization',\n class: 'B',\n label: 'payment authorized',\n fires_when:\n 'a user authorizes a payment of underlying value (Lightning, on-chain BTC, or fiat-quoted)',\n example: 'user paid $5.00 (≈5260 sats) for a premium feature on your site',\n common_use_cases: ['payment', 'checkout', 'paywall', 'subscription'],\n typical_price_hint: '0.75% of payment amount (percent_of_amount)',\n },\n scoped_action_authorization: {\n id: 'scoped_action_authorization',\n class: 'B',\n label: 'scoped action authorized',\n fires_when:\n 'a user takes a specific action your site bills on (post, vote, comment, claim) where each instance is meaningful',\n example: 'user posted a long-form review that earns them sats from your editorial budget',\n common_use_cases: ['post', 'vote', 'comment', 'claim', 'submit'],\n typical_price_hint: '~100 sats (~$0.10)',\n },\n attest_verification_at_gate: {\n id: 'attest_verification_at_gate',\n class: 'B',\n label: 'attest verification',\n fires_when:\n \"your site's gate consulted the user's attest_tier and admitted them (counted only when admitted)\",\n example: 'admin gate checked attest_tier=bonded with bond≥10k sats and granted access',\n common_use_cases: ['gate-check', 'tier-gate', 'sybil-filter'],\n typical_price_hint: '~280 sats (~$0.27) · OFF by default',\n },\n stamp_signing: {\n id: 'stamp_signing',\n class: 'B',\n label: 'stamp signed',\n fires_when:\n 'a user signs an oc-stamp envelope (provenance attestation, review credential, content stamp)',\n example: 'user stamped their published recipe with their oc identity for downstream verification',\n common_use_cases: ['provenance', 'review', 'credential', 'attestation'],\n typical_price_hint: '~55 sats (~$0.05) · OFF by default',\n },\n pledge_resolution: {\n id: 'pledge_resolution',\n class: 'B',\n label: 'pledge resolved',\n fires_when:\n 'an oc-pledge bonded commitment resolves on your surface (kept / broken / disputed / expired_unresolved). pledge bonds never move — any sat payout is an integrator-composed flow on top of pledge (e.g., HTLC), not a pledge primitive (oc-pledge-protocol WHY.md H7)',\n example:\n 'user staked sats × days-unspent on a prediction; the pledge resolved kept and the integrator paid out per its own composed terms',\n common_use_cases: ['pledge', 'staking', 'resolution', 'commit-reveal'],\n typical_price_hint: '1% of pledge bond amount (percent_of_amount) · OFF by default',\n },\n\n // ── Class C · session ──\n session_creation: {\n id: 'session_creation',\n class: 'C',\n label: 'session opened',\n fires_when:\n 'a fresh authenticated session is opened for a returning user (sign-in within an existing session is FREE)',\n example: 'user signed in after their last session expired; new session token issued',\n common_use_cases: ['sign-in', 'session', 'authenticate'],\n typical_price_hint: '~55 sats (~$0.05)',\n },\n};\n\n/** All subtypes for a given class · convenience accessor. */\nexport function subtypesForClass(cls: EventClass): EventSubtypeMetadata[] {\n return Object.values(EVENT_SUBTYPES).filter((m) => m.class === cls);\n}\n\n/** All subtypes as a flat list, ordered class A → B → C. */\nexport const ALL_EVENT_SUBTYPES: readonly EventSubtypeMetadata[] = [\n ...subtypesForClass('A'),\n ...subtypesForClass('B'),\n ...subtypesForClass('C'),\n];\n","/**\n * Archetype templates for `oc.config.fromTemplate(useCase, ...)`.\n *\n * A new integrator with a 30-second decision shouldn't have to fill\n * 12 IntegratorEventConfig entries by hand. Pick the archetype that\n * matches your site, get a sensible starting config, tweak whatever\n * you want, submit:\n *\n * import { oc } from '@orangecheck/me-client';\n *\n * const config = oc.config.fromTemplate('saas-paywall', {\n * project_key: 'pk_live_yourcompany',\n * domain: 'yoursite.com',\n * display_name: 'Your Site',\n * });\n * await oc.config.save(config);\n *\n * Templates differ on which subtypes are enabled (a content platform\n * doesn't need payment_authorization; a marketplace does) and on the\n * price per subtype. Every price is at the full user share, 0.8: the\n * user gets everything the 20% platform fee leaves. A smaller share only\n * returned part of the fee to the developer's own balance after it was\n * charged, so it cost more for nothing.\n *\n * To customize after picking a template:\n *\n * const config = oc.config.fromTemplate('marketplace', { ... });\n * config.events.payment_authorization!.site_pays = {\n * kind: 'percent_of_amount',\n * pct: 0.005, // 0.5% instead of the template's 0.75%\n * };\n */\n\nimport type {\n EventSubtype,\n IntegratorEventConfig,\n IntegratorPriceConfig,\n} from './types';\n\nexport type IntegratorArchetype =\n | 'saas-paywall'\n | 'marketplace'\n | 'content-platform'\n | 'gaming'\n | 'agent-only';\n\ninterface ProjectIdentity {\n project_key: string;\n domain: string;\n display_name: string;\n}\n\n/** Template descriptor · what each archetype enables and prices.\n * Exposed so dashboards can render \"you're using the X template\"\n * state and offer one-click swaps. */\nexport interface ArchetypeTemplate {\n id: IntegratorArchetype;\n label: string;\n /** One-sentence summary shown next to the picker. */\n summary: string;\n /** Concrete examples of sites this archetype fits. */\n examples: readonly string[];\n /** Per-subtype config the template emits. Subtypes not listed are\n * emitted as `enabled: false` (the SDK fills them with a\n * conservative default to keep the type happy without firing). */\n events: Partial<Record<EventSubtype, IntegratorEventConfig>>;\n}\n\nconst FIXED = (sats: number): IntegratorEventConfig['site_pays'] => ({\n kind: 'fixed_sats',\n sats,\n});\nconst PCT = (pct: number): IntegratorEventConfig['site_pays'] => ({\n kind: 'percent_of_amount',\n pct,\n});\n\n/**\n * The full archetype catalog. Add new templates here · one record per\n * common integrator pattern. Keep the list curated (≤8 archetypes) —\n * if there are too many, none feel like the obvious default and\n * integrators stall on the picker.\n */\nexport const ARCHETYPE_TEMPLATES: readonly ArchetypeTemplate[] = [\n {\n id: 'saas-paywall',\n label: 'SaaS · paywall',\n summary:\n 'A subscription product: people sign up, sign in and sometimes pay for more. Pays them for signing up and coming back.',\n examples: ['notes app', 'project tracker', 'design editor'],\n events: {\n account_creation: {\n enabled: true,\n site_pays: FIXED(1056),\n user_share_pct: 0.8,\n },\n session_creation: {\n enabled: true,\n site_pays: FIXED(45),\n user_share_pct: 0.8,\n },\n payment_authorization: {\n enabled: true,\n site_pays: PCT(0.00609375),\n user_share_pct: 0.8,\n },\n payment_method_connected: {\n enabled: true,\n site_pays: FIXED(260),\n user_share_pct: 0.8,\n },\n },\n },\n {\n id: 'marketplace',\n label: 'marketplace',\n summary:\n 'Buyers and sellers trade. Pays on payments, listings and new payment methods.',\n examples: ['checkout', 'handmade-goods market', 'ride-hailing'],\n events: {\n account_creation: {\n enabled: true,\n site_pays: FIXED(1056),\n user_share_pct: 0.8,\n },\n session_creation: {\n enabled: true,\n site_pays: FIXED(45),\n user_share_pct: 0.8,\n },\n payment_authorization: {\n enabled: true,\n site_pays: PCT(0.00609375),\n user_share_pct: 0.8,\n },\n scoped_action_authorization: {\n enabled: true,\n site_pays: FIXED(81),\n user_share_pct: 0.8,\n },\n payment_method_connected: {\n enabled: true,\n site_pays: FIXED(260),\n user_share_pct: 0.8,\n },\n attest_verification_at_gate: {\n enabled: true,\n site_pays: FIXED(227),\n user_share_pct: 0.8,\n },\n },\n },\n {\n id: 'content-platform',\n label: 'content platform',\n summary:\n 'Posts, reviews, votes and comments. Pays for each meaningful action, and for signed reviews.',\n examples: ['forum', 'video host', 'newsletter'],\n events: {\n account_creation: {\n enabled: true,\n site_pays: FIXED(1137),\n user_share_pct: 0.8,\n },\n session_creation: {\n enabled: true,\n site_pays: FIXED(49),\n user_share_pct: 0.8,\n },\n scoped_action_authorization: {\n enabled: true,\n site_pays: FIXED(87),\n user_share_pct: 0.8,\n },\n stamp_signing: {\n enabled: true,\n site_pays: FIXED(49),\n user_share_pct: 0.8,\n },\n },\n },\n {\n id: 'gaming',\n label: 'gaming',\n summary:\n 'A game where actions carry value. Pays for playing, paying and settled pledges.',\n examples: [\n 'on-chain prediction markets',\n 'skill-staking tournaments',\n 'multiplayer games',\n ],\n events: {\n account_creation: {\n enabled: true,\n site_pays: FIXED(1137),\n user_share_pct: 0.8,\n },\n session_creation: {\n enabled: true,\n site_pays: FIXED(49),\n user_share_pct: 0.8,\n },\n scoped_action_authorization: {\n enabled: true,\n site_pays: FIXED(87),\n user_share_pct: 0.8,\n },\n payment_authorization: {\n enabled: true,\n site_pays: PCT(0.004375),\n user_share_pct: 0.8,\n },\n pledge_resolution: {\n enabled: true,\n site_pays: PCT(0.00875),\n user_share_pct: 0.8,\n },\n attest_verification_at_gate: {\n enabled: true,\n site_pays: FIXED(245),\n user_share_pct: 0.8,\n },\n },\n },\n {\n id: 'agent-only',\n label: 'agent-only',\n summary:\n 'AI agents act for people under a delegation. Sessions are off; delegations and the actions they allow carry the activity.',\n examples: [\n 'AI assistant calling APIs on user behalf',\n 'autonomous trading bot',\n 'agent-driven customer support',\n ],\n events: {\n account_creation: {\n enabled: true,\n site_pays: FIXED(1056),\n user_share_pct: 0.8,\n },\n agent_delegation_issued: {\n enabled: true,\n site_pays: FIXED(260),\n user_share_pct: 0.8,\n },\n scoped_action_authorization: {\n enabled: true,\n site_pays: FIXED(81),\n user_share_pct: 0.8,\n },\n },\n },\n];\n\nconst ARCHETYPES_BY_ID: Record<IntegratorArchetype, ArchetypeTemplate> = Object.fromEntries(\n ARCHETYPE_TEMPLATES.map((t) => [t.id, t])\n) as Record<IntegratorArchetype, ArchetypeTemplate>;\n\n/** All 12 subtypes — used to fill `enabled: false` defaults for any\n * subtype the chosen archetype doesn't list. */\nconst ALL_SUBTYPES: readonly EventSubtype[] = [\n 'account_creation',\n 'account_recovery',\n 'attest_bond_increased',\n 'payment_method_connected',\n 'agent_delegation_issued',\n 'recovery_method_updated',\n 'payment_authorization',\n 'scoped_action_authorization',\n 'attest_verification_at_gate',\n 'stamp_signing',\n 'pledge_resolution',\n 'session_creation',\n];\n\nconst DEFAULT_DISABLED: IntegratorEventConfig = {\n enabled: false,\n site_pays: { kind: 'fixed_sats', sats: 100 },\n user_share_pct: 0.8,\n};\n\n/**\n * Build a complete IntegratorPriceConfig from an archetype id + the\n * project's identity fields. Every subtype gets an entry — the\n * archetype's listed subtypes get the template's pricing; everything\n * else gets `enabled: false` with conservative defaults so the config\n * is type-complete and the integrator can flip-on later subtypes\n * without re-deriving prices.\n *\n * Throws synchronously if `useCase` isn't a known archetype id.\n */\nexport function fromTemplate(\n useCase: IntegratorArchetype,\n identity: ProjectIdentity\n): IntegratorPriceConfig {\n const template = ARCHETYPES_BY_ID[useCase];\n if (!template) {\n throw new Error(\n `oc.config.fromTemplate: unknown archetype \"${useCase}\". Valid: ${Object.keys(\n ARCHETYPES_BY_ID\n ).join(', ')}`\n );\n }\n const events: IntegratorPriceConfig['events'] = {};\n for (const sub of ALL_SUBTYPES) {\n events[sub] = template.events[sub] ?? DEFAULT_DISABLED;\n }\n return {\n project_key: identity.project_key,\n domain: identity.domain,\n display_name: identity.display_name,\n updated_at: new Date().toISOString(),\n events,\n };\n}\n\n/** Look up a template's metadata · used by config-editor UIs to render\n * \"you're on the X template · here's what it enables\" copy. */\nexport function getArchetypeTemplate(id: IntegratorArchetype): ArchetypeTemplate {\n return ARCHETYPES_BY_ID[id];\n}\n"]}
1
+ {"version":3,"sources":["../src/types.ts","../src/subtypes.ts","../src/templates.ts"],"names":[],"mappings":";AAkBO,IAAM,mBAAA,GAAsB;AAAA;AAAA,EAE/B,GAAA,EAAK,GAAA;AAAA;AAAA,EAEL,cAAA,EAAgB,CAAA;AAAA;AAAA;AAAA,EAGhB,QAAA,EAAU;AACd;AASO,IAAM,yBAAA,GAA4B;AAelC,IAAM,yBAAA,GAA4B,GAAA;AAoIlC,SAAS,WAAA,CACZ,GAAA,EACA,mBAAA,EACA,IAAA,EACY;AACZ,EAAA,MAAM,QAAA,GAAW,MAAM,QAAA,KAAa,IAAA;AACpC,EAAA,IAAI,QAAA,IAAY,GAAA,CAAI,KAAA,EAAO,MAAA,EAAQ;AAC/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AA;AAAA,IACvB,UAAA,EAAA,iBAAY,IAAI,IAAA,EAAK,EAAE,WAAA,EAAY;AAAA,IACnC;AAAA,GACJ;AACJ;AAIO,SAAS,qBAAqB,EAAA,EAA4C;AAC7E,EAAA,OAAO,iBAAiB,EAAE,CAAA;AAC9B","file":"integrator.mjs","sourcesContent":["/**\n * Canonical types for me.ochk.io integrators.\n *\n * Mirrors the source of truth at oc-me-web/src/lib/events/types.ts. Two\n * layers:\n * - Platform-level (PLATFORM_FEE_POLICY, MIN_INTEGRATOR_PRICE_SATS) —\n * fixed by OC, surfaced as constants here so integrators can validate\n * their config client-side before posting it.\n * - Integrator-level (IntegratorPriceConfig) — every integrator declares\n * their own per-event prices and user-share splits.\n *\n * Per Addendum 01: every chargeable event is in exactly one of three\n * classes. Sites pay for sessions and actions, not for clicks. Free\n * events never instantiate a BillableEvent.\n */\n\n// ── platform constants (fixed by OC) ──────────────────────────────────────\n\nexport const PLATFORM_FEE_POLICY = {\n /** Fraction of every gross_fee that OC retains. */\n pct: 0.2,\n /** Absolute minimum platform fee, in sats. */\n min_floor_sats: 1,\n /** Date this policy was last ratified. Changes require a versioned\n * @orangecheck/me-client release. */\n ratified: '2026-04-30',\n} as const;\n\n/** Per-event price floor. 1 sat — the natural atomic Bitcoin unit.\n * Integrators choose their own per-event prices above this; OC does\n * not impose sybil-resistance opinions on integrators (that's their\n * call, from their own threat model). The 1-sat floor is purely\n * mechanical — fees can't be fractional sats. Mirrors the canonical\n * value at oc-me-web/src/lib/events/types.ts (a previous SDK release\n * drifted to 5 while the platform ratified 1). */\nexport const MIN_INTEGRATOR_PRICE_SATS = 1;\n\n/**\n * Hard per-event ceiling, mirroring the server's own bound.\n *\n * The server clamps gross to this before splitting it; this package did not,\n * so `verify()` re-derived 99,000,000 for an envelope the server had recorded\n * at 10,000,000 and rejected a correct receipt. It also over-reported what a\n * misconfigured site would be charged, by the ratio of the two numbers.\n *\n * 10,000,000 sats = 0.1 BTC: orders of magnitude above any real per-event\n * price, low enough that a misconfiguration cannot mint an unbounded number\n * of sats in one event. Found by the cross-package vector test in oc-me-web\n * on its first run.\n */\nexport const MAX_INTEGRATOR_PRICE_SATS = 10_000_000;\n\n/** Platform ceiling on drop-period windows: no integrator schedule may\n * hold a user's earned share open longer than this, regardless of\n * cadence. Published in ABUSE_LIMITS on me.ochk.io /trust + /security. */\nexport const MAX_DROP_WINDOW_DAYS = 92;\n\n// ── event taxonomy ────────────────────────────────────────────────────────\n\nexport type EventClass = 'A' | 'B' | 'C';\n\nexport type ClassASubtype =\n | 'account_creation'\n | 'account_recovery'\n | 'attest_bond_increased'\n | 'payment_method_connected'\n | 'agent_delegation_issued'\n | 'recovery_method_updated';\n\nexport type ClassBSubtype =\n | 'payment_authorization'\n | 'scoped_action_authorization'\n | 'attest_verification_at_gate'\n | 'stamp_signing'\n | 'pledge_resolution';\n\nexport type ClassCSubtype = 'session_creation';\n\nexport type EventSubtype = ClassASubtype | ClassBSubtype | ClassCSubtype;\n\n/**\n * Any billable event key. A project's catalog is OPEN: alongside the built-in\n * subtypes above, an integrator can define their own event keys (with their own\n * label + class + price) on the project config. `EventKey` keeps autocomplete\n * for the built-ins while accepting any custom string — the `(string & {})`\n * arm preserves the literal union in editors instead of collapsing it to\n * `string`. The server resolves class/label off the project's catalog for\n * custom keys.\n */\nexport type EventKey = EventSubtype | (string & {});\n\n/** AttestTier · what an integrator's gate can read about an oc identity.\n *\n * me.ochk does NOT do KYC. Sybil resistance is bounded by three\n * composable mechanisms, none of which involve OC handling PII:\n * 1. paid-action history · billable events cost real sats\n * 2. BIP-322 sat-bonding · bond size + age via signed attestation\n * 3. integrator-defined gates · per-site threat-model overlays\n *\n * Tier itself is intentionally simple — anonymous | bonded.\n * Granularity (bond_sats, bond_locked_at, etc) carried separately. */\nexport type AttestTier = 'anonymous' | 'bonded';\n\n/** The shape of a per-event fee — either a fixed sats amount or a percent\n * of the underlying transaction amount (used for payments + pledges). */\nexport type SiteFeeShape =\n | { kind: 'fixed_sats'; sats: number }\n | { kind: 'percent_of_amount'; pct: number };\n\n/** Optional per-class pricing overrides · per OCHK-V3-PLAN §7 phase-1.\n * Agents acting under a scoped oc-agent delegation may bill\n * differently than humans firing the same subtype. When `agent` is\n * unset on a subtype, agent traffic bills at the human rate. `refuse:\n * true` makes the subtype human-only — the endpoint returns 422\n * agent_refused for is_agent=true requests. */\nexport interface AgentClassOverride {\n /** Override site_pays for agent-fired events. */\n site_pays?: SiteFeeShape;\n /** Override user_share_pct. Same default-fallback as site_pays. */\n user_share_pct?: number;\n /** When true, agent traffic is refused for this subtype. */\n refuse?: boolean;\n}\n\n/** What an integrator declares for a single event subtype. */\nexport interface IntegratorEventConfig {\n /** Whether this site bills this event subtype at all. */\n enabled: boolean;\n /** The per-event fee the site pays. */\n site_pays: SiteFeeShape;\n /** Fraction of GROSS that flows to the user (0–0.8 since the\n * platform fee is 20%). The remainder is a rebate to the site's\n * OC project balance. */\n user_share_pct: number;\n /** Optional per-agent-class pricing override applied when an event\n * fires with is_agent=true. */\n agent?: AgentClassOverride;\n}\n\n/** A complete integrator pricing config. Posted to me.ochk.io once at\n * integration time, mutable via the configurator UI or this SDK any time\n * after. */\nexport interface IntegratorPriceConfig {\n project_key: string;\n display_name: string;\n domain: string;\n /** ISO-8601 timestamp the config was last updated. */\n updated_at: string;\n /** Per-event configs, keyed by event key. Open catalog: built-in subtypes\n * AND your own custom keys. Keys not listed are disabled by default. */\n events: Partial<Record<EventKey, IntegratorEventConfig>>;\n}\n\n/** A computed fee breakdown for a single event. site_rebate_sats is what\n * flows back to the developer's balance after the platform fee and what\n * the user earns: zero at the full user share, 0.8. */\nexport interface ComputedFees {\n gross_fee_sats: number;\n platform_fee_sats: number;\n user_earned_sats: number;\n site_rebate_sats: number;\n}\n\n/** Compute the four-way fee split for an event given an integrator's\n * config and (for percent_of_amount events) the underlying payment\n * amount. MIRRORS oc-me-web/src/lib/events/types.ts computeFees()\n * EXACTLY — the SDK-side replay (oc.event.verify) re-runs this against\n * envelopes the server billed, so any drift is a false \"divergence\".\n *\n * Invariants:\n * 1. gross_fee_sats >= MIN_INTEGRATOR_PRICE_SATS (1-sat atomic floor)\n * 2. platform_fee_sats = min(gross, max(min_floor, round(gross × pct)))\n * — bounded above by gross so a 1-sat event can't owe more\n * platform fee than it grossed\n * 3. user_earned_sats = min(gross − platform, round(gross × share)),\n * share clamped to [0, 0.8]\n * 4. site_rebate_sats = gross − platform − user (exact remainder)\n * 5. gross == platform + user + rebate exactly\n *\n * When `opts.is_agent` is true AND the config has an `agent` override,\n * the agent's site_pays / user_share_pct apply. `agent.refuse: true`\n * throws 'agent_refused' (the server maps it to 422). */\nexport function computeFees(\n cfg: IntegratorEventConfig,\n payment_amount_sats?: number,\n opts?: { is_agent?: boolean }\n): ComputedFees {\n const is_agent = opts?.is_agent === true;\n if (is_agent && cfg.agent?.refuse) {\n throw new Error('agent_refused');\n }\n const effective_site_pays =\n is_agent && cfg.agent?.site_pays ? cfg.agent.site_pays : cfg.site_pays;\n const effective_user_share_pct =\n is_agent && typeof cfg.agent?.user_share_pct === 'number'\n ? cfg.agent.user_share_pct\n : cfg.user_share_pct;\n\n let gross = 0;\n if (effective_site_pays.kind === 'fixed_sats') {\n gross = Math.max(MIN_INTEGRATOR_PRICE_SATS, Math.round(effective_site_pays.sats));\n } else {\n if (payment_amount_sats == null) {\n throw new Error('percent_of_amount config requires payment_amount_sats');\n }\n gross = Math.max(\n MIN_INTEGRATOR_PRICE_SATS,\n Math.round(payment_amount_sats * effective_site_pays.pct)\n );\n }\n // Hard ceiling · no single event mints more than MAX_INTEGRATOR_PRICE_SATS.\n // The server applies this before splitting; omitting it here made verify()\n // reject correct envelopes priced above the bound.\n gross = Math.min(gross, MAX_INTEGRATOR_PRICE_SATS);\n const platform_fee_sats = Math.min(\n gross,\n Math.max(PLATFORM_FEE_POLICY.min_floor_sats, Math.round(gross * PLATFORM_FEE_POLICY.pct))\n );\n const user_share = Math.min(0.8, Math.max(0, effective_user_share_pct));\n const user_earned_sats = Math.min(gross - platform_fee_sats, Math.round(gross * user_share));\n const site_rebate_sats = gross - platform_fee_sats - user_earned_sats;\n return { gross_fee_sats: gross, platform_fee_sats, user_earned_sats, site_rebate_sats };\n}\n\n/** Result of validating an IntegratorPriceConfig. */\nexport interface ValidationResult {\n ok: boolean;\n errors: { subtype?: EventKey; message: string }[];\n}\n\n/**\n * Validate an integrator's pricing config against the platform's\n * non-negotiable rules. Run client-side before posting; the server runs\n * the same checks and rejects anything that fails.\n */\nexport function validateIntegratorConfig(cfg: IntegratorPriceConfig): ValidationResult {\n const errors: ValidationResult['errors'] = [];\n\n if (!cfg.project_key) errors.push({ message: 'project_key is required' });\n if (!cfg.display_name) errors.push({ message: 'display_name is required' });\n if (!cfg.domain) errors.push({ message: 'domain is required' });\n\n for (const [key, eventCfg] of Object.entries(cfg.events)) {\n if (!eventCfg) continue;\n const subtype = key as EventKey;\n if (!eventCfg.enabled) continue;\n\n if (eventCfg.site_pays.kind === 'fixed_sats') {\n if (eventCfg.site_pays.sats < MIN_INTEGRATOR_PRICE_SATS) {\n errors.push({\n subtype,\n message: `site_pays.sats (${eventCfg.site_pays.sats}) is below MIN_INTEGRATOR_PRICE_SATS (${MIN_INTEGRATOR_PRICE_SATS})`,\n });\n }\n } else {\n const pct = eventCfg.site_pays.pct;\n if (!(pct > 0 && pct <= 1)) {\n errors.push({\n subtype,\n message: `site_pays.pct (${pct}) must be in (0, 1]`,\n });\n }\n }\n\n const u = eventCfg.user_share_pct;\n if (u < 0 || u > 0.8) {\n errors.push({\n subtype,\n message: `user_share_pct (${u}) must be in [0, 0.8]; max is 0.8 because platform_fee is ${PLATFORM_FEE_POLICY.pct}`,\n });\n }\n }\n\n return { ok: errors.length === 0, errors };\n}\n\n// ── canonical envelope ────────────────────────────────────────────────────\n\nexport interface BillableEvent {\n id: string;\n occurred_at: string;\n class: EventClass;\n subtype: EventKey;\n site: { domain: string; display_name: string };\n gross_fee_sats: number;\n platform_fee_sats: number;\n user_earned_sats: number;\n site_rebate_sats: number;\n verify_url: string;\n /** Per OCHK-V3-PLAN §7 phase-1 · true when the event was fired by\n * an oc-agent delegation rather than a human session. The\n * integrator's IntegratorEventConfig.agent block may price\n * these differently or refuse them. Optional · canonical encoder\n * branches to v=3 only when present, so legacy human-fired\n * events keep their v=2 hash + signature. */\n is_agent?: boolean;\n /** Drop-period stamp · present when the project covers this\n * subtype with a drop schedule. The user-share of a stamped event\n * MATURES until the window's boundary, then vests as one batch\n * (the drop). Billing is untouched. Part of the SIGNED canonical\n * bytes (encoder branches to v=4 when present). No clawback\n * exists — vesting is unconditional, and an open window's\n * boundary can only ever move earlier. */\n drop?: {\n /** Deterministic window id · the window's signed manifest is\n * verifiable at me.ochk.io/verify/<manifest_id> after close. */\n window_id: string;\n /** Block-denominated vesting boundary; null when no chain tip\n * was observable at window open (wallclock + the published\n * 24h safety valve then govern). */\n close_height_target: number | null;\n } | null;\n}\n\n// ── drop periods · integrator-scheduled payout windows ───────────────────\n\n/** A drop schedule's cadence. Weekly/monthly close at a fixed UTC\n * boundary; manual closes when the integrator says (Drop now), with a\n * hard auto-close at max_open_days (≤ MAX_DROP_WINDOW_DAYS). */\nexport type DropCadence =\n | { kind: 'weekly'; day: number; hour: number }\n | { kind: 'monthly'; day: number; hour: number }\n | { kind: 'manual'; max_open_days: number };\n\n/** Public shape of an enabled drop schedule, as returned in the\n * `drops` array of GET /api/integrator/config — part of the project's\n * public payout contract (earners can see when covered subtypes pay\n * out before earning under them). */\nexport interface DropScheduleSummary {\n schedule_id: string;\n label: string;\n subtypes: EventSubtype[];\n cadence: DropCadence;\n}\n\n/** Drop-period context on event-ingest responses (single route:\n * top-level `drop`; batch route: per-result `drop`). `state` flips\n * from 'open' to 'closing' once the scheduled boundary passes and the\n * window awaits its sweep (~15 min) — render \"processing\", never a\n * negative countdown. */\nexport interface DropResponseBlock {\n window_id: string;\n label: string;\n state: 'open' | 'closing';\n closes_at_target: string;\n close_height_target: number | null;\n}\n\n// ── webhook payload ───────────────────────────────────────────────────────\n\n/**\n * The exact JSON body delivered to a registered webhook endpoint when\n * a billable event fires. Imported by integrator backends so the\n * receive handler is type-checked end-to-end without re-declaring the\n * shape.\n *\n * import type { WebhookPayload } from '@orangecheck/me-client';\n *\n * export async function POST(req: Request) {\n * const payload = (await req.json()) as WebhookPayload;\n * if (payload.subtype === 'payment_authorization') {\n * creditUser(payload.sub, payload.user_earned_sats);\n * }\n * }\n *\n * Headers carry the signature and metadata (see WebhookHeaders below).\n * Verify the signature with `oc.webhook.verify({ body, headers, jwks })`.\n *\n * Privacy contract · the master oc identity is NEVER in the payload.\n * Integrators see `sub` (per-integrator anonymous id) plus any\n * `scopes` the user explicitly granted. See PRIVACY-ARCHITECTURE.md.\n */\nexport interface WebhookPayload extends BillableEvent {\n /** Discriminator · identifies the payload kind for routing on\n * the integrator's side. Always 'oc-billable-event' today; future\n * webhook payload kinds (refunds, charters, etc) will use\n * distinct discriminator values. */\n kind: 'oc-billable-event';\n /** Per-integrator anonymous subject id · stable across events for\n * the same (oc_identity, project_key) pair. Key your user records\n * on this; OC will never give you the master address unless the\n * user explicitly grants `bitcoin_address` or `email` scope. */\n sub: string;\n /** Resolved scoped fields · only present for scopes the user has\n * granted to this project. Wire format is string-keyed (every\n * value is stringified · ints stringified, addresses as-is). */\n scopes?: Partial<\n Record<\n | 'bitcoin_address'\n | 'email'\n | 'attest_tier'\n | 'display_name'\n | 'cross_integrator_event_count'\n | 'cross_integrator_human_event_count'\n | 'trust_attestation_count'\n | 'trust_attestations_bundle',\n string\n >\n >;\n}\n\n/**\n * Non-billable SYSTEM webhook deliveries — project-level operational\n * signals (escrow.low, escrow.depleted, escrow.recovered, drop.closed).\n * Same signing + headers as billable deliveries; receivers subscribe\n * via the same `subscribed` list ('*' or the explicit subtype string).\n * Carries no user identity. Discriminate on `kind` first, then\n * `subtype`:\n *\n * const payload = JSON.parse(body) as WebhookPayload | SystemWebhookPayload;\n * if (payload.kind === 'oc-system-event' && payload.subtype === 'drop.closed') { … }\n */\nexport interface SystemWebhookPayload {\n kind: 'oc-system-event';\n subtype: string;\n project_key: string;\n [extra: string]: unknown;\n}\n\n/** The `drop.closed` system event — one per closed drop window. The\n * manifest is the signed, content-addressed record (Merkle commitments\n * over member events + recipients); verify_url renders + live-verifies\n * it, and /api/envelope/<manifest_id> serves the raw canonical bytes. */\nexport interface DropClosedWebhookPayload extends SystemWebhookPayload {\n subtype: 'drop.closed';\n window_id: string;\n schedule_id: string;\n label: string;\n manifest_id: string;\n verify_url: string;\n sealed_at: string;\n sealed_height: number | null;\n event_count: number;\n recipient_count: number;\n gross_fee_sats: number;\n user_share_sats: number;\n}\n\n/**\n * HTTP headers OC sends with every webhook delivery. Capture these in\n * the receive handler · `OC-Signature` is what verifies the body.\n */\nexport interface WebhookHeaders {\n /** Ed25519 signature over the raw response body, hex-encoded. */\n 'OC-Signature': string;\n /** Stable kid of the signing key · resolves against\n * ochk.io/.well-known/jwks.json. */\n 'OC-Key-Id': string;\n /** Envelope id · matches payload.id; useful for idempotent\n * receive handlers that dedupe on this header without parsing\n * the body. */\n 'OC-Envelope-Id': string;\n /** Subtype · matches payload.subtype (built-in or a custom event key);\n * lets routers branch on the header before parsing. */\n 'OC-Subtype': EventKey;\n /** Class · matches payload.class. */\n 'OC-Class': EventClass;\n /** 1-indexed delivery attempt count. >1 means the prior attempt\n * did not return a 2xx within the timeout · idempotency key on\n * payload.id is critical. */\n 'OC-Delivery-Attempt': string;\n}\n\n// ── session lifecycle ────────────────────────────────────────────────────\n\nexport interface SessionPolicy {\n duration_seconds: number;\n refresh: 'sliding' | 'rolling' | 'none';\n sensitive_actions?: 're-auth' | 'none';\n}\n\nexport interface Session {\n id: string;\n identity: string;\n opens_at: string;\n expires_at: string;\n policy: SessionPolicy;\n scope: string[];\n}\n\nexport interface SignInOptions {\n scope: string[];\n sessionPolicy?: Partial<SessionPolicy>;\n returnTo?: string;\n}\n\nexport interface PaymentAuthorizeOptions {\n /** @deprecated Ignored: the server takes the account from the session. */\n identity?: string;\n amount_sats?: number;\n usd_cents?: number;\n description: string;\n external_ref?: string;\n}\n\nexport interface PaymentResult {\n id: string;\n status: 'authorized' | 'failed' | 'cancelled';\n sats_charged?: number;\n user_envelope_id?: string;\n verify_url?: string;\n}\n\nexport interface TelemetryEvent {\n code:\n | 'session.intra_signin'\n | 'session.token_refresh'\n | 'session.navigation'\n /** Emitted by `session.invalidate()`. Was `session.intra_signin`, which\n * means the opposite thing — \"user pressed sign-in while a valid\n * session was already open\" — so a subscriber saw a sign-in event\n * every time the integrator tore a session down. Non-billable. */\n | 'session.teardown'\n | 'auth.signin_failed'\n | 'auth.signin_cancelled'\n | 'auth.signin_rejected'\n | 'verify.passive_check';\n timestamp: string;\n session_id?: string;\n}\n\n// ── federation directory ───────────────────────────────────────────────\n//\n// The SDK consumes the federation directory at runtime so multi-federation\n// routing is a directory write, not a code change. v1 has one live\n// federation; the directory is plural-shaped so federation #2 lights up\n// without an SDK release.\n\nexport type FederationStatus = 'recruiting' | 'forming' | 'binding' | 'live';\n\n/** Federation directory entry. Mirrors `oc-me-web/src/lib/federations/registry.ts`\n * field-for-field; this package is the public consumption shape. */\nexport interface Federation {\n slug: string;\n name: string;\n status: FederationStatus;\n threshold: string;\n target_guardian_count: number;\n /** Fedimint invite code; null until status === 'live'. */\n invite: string | null;\n /** SHA-256 of the canonical federation charter, hex-encoded. */\n charter_hash: string | null;\n /** ISO-8601 of the most recent ongoing-attestation envelope. */\n last_attestation_at: string | null;\n geography_hint: string;\n // Operator-recruiting fields (present on slots in 'recruiting' /\n // 'forming' / 'binding' state). Nullable so one shape spans the\n // lifecycle.\n geography_requirements?: string;\n charter_status?: string;\n ceremony_window?: string;\n why_this_one?: string;\n apply_cta?: string;\n apply_href?: string;\n}\n\n/** SigningMethod discriminator on the user identity. Federation-agnostic\n * by construction — the OC identity (did:email or BIP-322 address)\n * remains stable across all three states. Transitions are recorded as\n * anchored \"rebind\" envelopes on the canonical event log. Graduation\n * is the product thesis; this discriminator is the structural primitive\n * that records where a user is on the custody-state graph. */\nexport type SigningMethod = 'fedimint_threshold' | 'fedimint_client' | 'bip322';\n","/**\n * Rich metadata for every billable event subtype.\n *\n * The SDK already exports the `EventSubtype` union (closed enum, type-\n * checked), but a new integrator picking between\n * `'scoped_action_authorization'` and `'stamp_signing'` and\n * `'attest_verification_at_gate'` has no inline guidance on which fits\n * their flow. This file is the canonical \"when do I use this subtype\"\n * reference, programmatically accessible:\n *\n * import { oc, EVENT_SUBTYPES } from '@orangecheck/me-client';\n *\n * for (const meta of Object.values(EVENT_SUBTYPES)) {\n * console.log(`${meta.id} (class ${meta.class}) — ${meta.fires_when}`);\n * }\n *\n * Or per-subtype:\n *\n * const meta = EVENT_SUBTYPES.account_creation;\n * console.log(meta.example); // → \"user signed up via email-OTP and the account row was inserted\"\n *\n * Used by `oc.config.fromTemplate()` to assemble archetype configs and\n * by /me/projects/* dashboards to drive consent prompts and config\n * editor labels from a single source.\n */\n\nimport type { EventClass, EventSubtype } from './types';\n\nexport interface EventSubtypeMetadata {\n id: EventSubtype;\n class: EventClass;\n /** Short label · matches SUBTYPE_LABELS on the server. */\n label: string;\n /** When this fires · imperative-mood plain English. The integrator\n * reads this to know which event in their codebase should call\n * `oc.event.fire()` with this subtype. */\n fires_when: string;\n /** A concrete example from a typical SaaS · helps integrators map\n * an unfamiliar subtype name to a real flow they recognize. */\n example: string;\n /** Common use cases · lets integrators search their own product\n * for matching flows. Two-three terms each, lowercase. */\n common_use_cases: readonly string[];\n /** What an integrator typically pays for this subtype, anchored at\n * $1 ≈ 1052 sats. Returns null for percent-of-amount subtypes\n * where the price scales with the underlying transaction. */\n typical_price_hint: string;\n}\n\nexport const EVENT_SUBTYPES: Record<EventSubtype, EventSubtypeMetadata> = {\n // ── Class A · durable state transitions ──\n account_creation: {\n id: 'account_creation',\n class: 'A',\n label: 'account creation',\n fires_when:\n 'a new oc identity creates a durable account record on your surface (first sign-in, profile row inserted)',\n example: 'user signed up via email-OTP and your account row was inserted in your DB',\n common_use_cases: ['onboarding', 'signup', 'registration', 'first-login'],\n typical_price_hint: '~1300 sats (~$1.24)',\n },\n account_recovery: {\n id: 'account_recovery',\n class: 'A',\n label: 'account recovery',\n fires_when:\n 'a user re-binds an existing account to a new device or recovery method',\n example: 'user lost their device and recovered the account via email OTP + recovery code',\n common_use_cases: ['recovery', 'device-rebind', 'restore-access'],\n typical_price_hint: '~650 sats (~$0.62)',\n },\n attest_bond_increased: {\n id: 'attest_bond_increased',\n class: 'A',\n label: 'attest bond increased',\n fires_when:\n 'a user upgrades their bond size (locks more sats to attest_tier=bonded with higher cap)',\n example: 'user moved from 10k-sat bond to 100k-sat bond to clear your higher-trust gate',\n common_use_cases: ['bond-upgrade', 'tier-promotion', 'sybil-resistance'],\n typical_price_hint: '~1600 sats (~$1.52) · OFF by default',\n },\n payment_method_connected: {\n id: 'payment_method_connected',\n class: 'A',\n label: 'payment method connected',\n fires_when:\n 'a user connects a Lightning address, BIP-322 wallet, or payment-routing channel to their account',\n example: 'user pasted a lightning@address.com receive address into their profile',\n common_use_cases: ['payment-setup', 'wallet-connect', 'payout-config'],\n typical_price_hint: '~320 sats (~$0.30)',\n },\n agent_delegation_issued: {\n id: 'agent_delegation_issued',\n class: 'A',\n label: 'agent delegation issued',\n fires_when:\n 'a user signs an oc-agent delegation envelope authorizing an AI agent to act on their behalf',\n example: 'user delegated a \"summarize my emails\" agent for 24 hours with scope email:read',\n common_use_cases: ['agent-grant', 'ai-delegation', 'scoped-authorization'],\n typical_price_hint: '~320 sats · OFF by default (power-user)',\n },\n recovery_method_updated: {\n id: 'recovery_method_updated',\n class: 'A',\n label: 'recovery method updated',\n fires_when:\n 'a user changes their recovery email, recovery key, or social-recovery contacts',\n example: 'user rotated their recovery email after a phone change',\n common_use_cases: ['recovery-rotation', 'security-update'],\n typical_price_hint: '~160 sats (~$0.15)',\n },\n\n // ── Class B · action-bound ──\n payment_authorization: {\n id: 'payment_authorization',\n class: 'B',\n label: 'payment authorized',\n fires_when:\n 'a user authorizes a payment of underlying value (Lightning, on-chain BTC, or fiat-quoted)',\n example: 'user paid $5.00 (≈5260 sats) for a premium feature on your site',\n common_use_cases: ['payment', 'checkout', 'paywall', 'subscription'],\n typical_price_hint: '0.75% of payment amount (percent_of_amount)',\n },\n scoped_action_authorization: {\n id: 'scoped_action_authorization',\n class: 'B',\n label: 'scoped action authorized',\n fires_when:\n 'a user takes a specific action your site bills on (post, vote, comment, claim) where each instance is meaningful',\n example: 'user posted a long-form review that earns them sats from your editorial budget',\n common_use_cases: ['post', 'vote', 'comment', 'claim', 'submit'],\n typical_price_hint: '~100 sats (~$0.10)',\n },\n attest_verification_at_gate: {\n id: 'attest_verification_at_gate',\n class: 'B',\n label: 'attest verification',\n fires_when:\n \"your site's gate consulted the user's attest_tier and admitted them (counted only when admitted)\",\n example: 'admin gate checked attest_tier=bonded with bond≥10k sats and granted access',\n common_use_cases: ['gate-check', 'tier-gate', 'sybil-filter'],\n typical_price_hint: '~280 sats (~$0.27) · OFF by default',\n },\n stamp_signing: {\n id: 'stamp_signing',\n class: 'B',\n label: 'stamp signed',\n fires_when:\n 'a user signs an oc-stamp envelope (provenance attestation, review credential, content stamp)',\n example: 'user stamped their published recipe with their oc identity for downstream verification',\n common_use_cases: ['provenance', 'review', 'credential', 'attestation'],\n typical_price_hint: '~55 sats (~$0.05) · OFF by default',\n },\n pledge_resolution: {\n id: 'pledge_resolution',\n class: 'B',\n label: 'pledge resolved',\n fires_when:\n 'an oc-pledge bonded commitment resolves on your surface (kept / broken / disputed / expired_unresolved). pledge bonds never move — any sat payout is an integrator-composed flow on top of pledge (e.g., HTLC), not a pledge primitive (oc-pledge-protocol WHY.md H7)',\n example:\n 'user staked sats × days-unspent on a prediction; the pledge resolved kept and the integrator paid out per its own composed terms',\n common_use_cases: ['pledge', 'staking', 'resolution', 'commit-reveal'],\n typical_price_hint: '1% of pledge bond amount (percent_of_amount) · OFF by default',\n },\n\n // ── Class C · session ──\n session_creation: {\n id: 'session_creation',\n class: 'C',\n label: 'session opened',\n fires_when:\n 'a fresh authenticated session is opened for a returning user (sign-in within an existing session is FREE)',\n example: 'user signed in after their last session expired; new session token issued',\n common_use_cases: ['sign-in', 'session', 'authenticate'],\n typical_price_hint: '~55 sats (~$0.05)',\n },\n};\n\n/** All subtypes for a given class · convenience accessor. */\nexport function subtypesForClass(cls: EventClass): EventSubtypeMetadata[] {\n return Object.values(EVENT_SUBTYPES).filter((m) => m.class === cls);\n}\n\n/** All subtypes as a flat list, ordered class A → B → C. */\nexport const ALL_EVENT_SUBTYPES: readonly EventSubtypeMetadata[] = [\n ...subtypesForClass('A'),\n ...subtypesForClass('B'),\n ...subtypesForClass('C'),\n];\n","/**\n * Archetype templates for `oc.config.fromTemplate(useCase, ...)`.\n *\n * A new integrator with a 30-second decision shouldn't have to fill\n * 12 IntegratorEventConfig entries by hand. Pick the archetype that\n * matches your site, get a sensible starting config, tweak whatever\n * you want, submit:\n *\n * import { oc } from '@orangecheck/me-client';\n *\n * const config = oc.config.fromTemplate('saas-paywall', {\n * project_key: 'pk_live_yourcompany',\n * domain: 'yoursite.com',\n * display_name: 'Your Site',\n * });\n * await oc.config.save(config);\n *\n * Templates differ on which subtypes are enabled (a content platform\n * doesn't need payment_authorization; a marketplace does) and on the\n * price per subtype. Every price is at the full user share, 0.8: the\n * user gets everything the 20% platform fee leaves. A smaller share only\n * returned part of the fee to the developer's own balance after it was\n * charged, so it cost more for nothing.\n *\n * To customize after picking a template:\n *\n * const config = oc.config.fromTemplate('marketplace', { ... });\n * config.events.payment_authorization!.site_pays = {\n * kind: 'percent_of_amount',\n * pct: 0.005, // 0.5% instead of the template's 0.75%\n * };\n */\n\nimport type {\n EventSubtype,\n IntegratorEventConfig,\n IntegratorPriceConfig,\n} from './types';\n\nexport type IntegratorArchetype =\n | 'saas-paywall'\n | 'marketplace'\n | 'content-platform'\n | 'gaming'\n | 'agent-only';\n\ninterface ProjectIdentity {\n project_key: string;\n domain: string;\n display_name: string;\n}\n\n/** Template descriptor · what each archetype enables and prices.\n * Exposed so dashboards can render \"you're using the X template\"\n * state and offer one-click swaps. */\nexport interface ArchetypeTemplate {\n id: IntegratorArchetype;\n label: string;\n /** One-sentence summary shown next to the picker. */\n summary: string;\n /** Concrete examples of sites this archetype fits. */\n examples: readonly string[];\n /** Per-subtype config the template emits. Subtypes not listed are\n * emitted as `enabled: false` (the SDK fills them with a\n * conservative default to keep the type happy without firing). */\n events: Partial<Record<EventSubtype, IntegratorEventConfig>>;\n}\n\nconst FIXED = (sats: number): IntegratorEventConfig['site_pays'] => ({\n kind: 'fixed_sats',\n sats,\n});\nconst PCT = (pct: number): IntegratorEventConfig['site_pays'] => ({\n kind: 'percent_of_amount',\n pct,\n});\n\n/**\n * The full archetype catalog. Add new templates here · one record per\n * common integrator pattern. Keep the list curated (≤8 archetypes) —\n * if there are too many, none feel like the obvious default and\n * integrators stall on the picker.\n */\nexport const ARCHETYPE_TEMPLATES: readonly ArchetypeTemplate[] = [\n {\n id: 'saas-paywall',\n label: 'SaaS · paywall',\n summary:\n 'A subscription product: people sign up, sign in and sometimes pay for more. Pays them for signing up and coming back.',\n examples: ['notes app', 'project tracker', 'design editor'],\n events: {\n account_creation: {\n enabled: true,\n site_pays: FIXED(1056),\n user_share_pct: 0.8,\n },\n session_creation: {\n enabled: true,\n site_pays: FIXED(45),\n user_share_pct: 0.8,\n },\n payment_authorization: {\n enabled: true,\n site_pays: PCT(0.00609375),\n user_share_pct: 0.8,\n },\n payment_method_connected: {\n enabled: true,\n site_pays: FIXED(260),\n user_share_pct: 0.8,\n },\n },\n },\n {\n id: 'marketplace',\n label: 'marketplace',\n summary:\n 'Buyers and sellers trade. Pays on payments, listings and new payment methods.',\n examples: ['checkout', 'handmade-goods market', 'ride-hailing'],\n events: {\n account_creation: {\n enabled: true,\n site_pays: FIXED(1056),\n user_share_pct: 0.8,\n },\n session_creation: {\n enabled: true,\n site_pays: FIXED(45),\n user_share_pct: 0.8,\n },\n payment_authorization: {\n enabled: true,\n site_pays: PCT(0.00609375),\n user_share_pct: 0.8,\n },\n scoped_action_authorization: {\n enabled: true,\n site_pays: FIXED(81),\n user_share_pct: 0.8,\n },\n payment_method_connected: {\n enabled: true,\n site_pays: FIXED(260),\n user_share_pct: 0.8,\n },\n attest_verification_at_gate: {\n enabled: true,\n site_pays: FIXED(227),\n user_share_pct: 0.8,\n },\n },\n },\n {\n id: 'content-platform',\n label: 'content platform',\n summary:\n 'Posts, reviews, votes and comments. Pays for each meaningful action, and for signed reviews.',\n examples: ['forum', 'video host', 'newsletter'],\n events: {\n account_creation: {\n enabled: true,\n site_pays: FIXED(1137),\n user_share_pct: 0.8,\n },\n session_creation: {\n enabled: true,\n site_pays: FIXED(49),\n user_share_pct: 0.8,\n },\n scoped_action_authorization: {\n enabled: true,\n site_pays: FIXED(87),\n user_share_pct: 0.8,\n },\n stamp_signing: {\n enabled: true,\n site_pays: FIXED(49),\n user_share_pct: 0.8,\n },\n },\n },\n {\n id: 'gaming',\n label: 'gaming',\n summary:\n 'A game where actions carry value. Pays for playing, paying and settled pledges.',\n examples: [\n 'on-chain prediction markets',\n 'skill-staking tournaments',\n 'multiplayer games',\n ],\n events: {\n account_creation: {\n enabled: true,\n site_pays: FIXED(1137),\n user_share_pct: 0.8,\n },\n session_creation: {\n enabled: true,\n site_pays: FIXED(49),\n user_share_pct: 0.8,\n },\n scoped_action_authorization: {\n enabled: true,\n site_pays: FIXED(87),\n user_share_pct: 0.8,\n },\n payment_authorization: {\n enabled: true,\n site_pays: PCT(0.004375),\n user_share_pct: 0.8,\n },\n pledge_resolution: {\n enabled: true,\n site_pays: PCT(0.00875),\n user_share_pct: 0.8,\n },\n attest_verification_at_gate: {\n enabled: true,\n site_pays: FIXED(245),\n user_share_pct: 0.8,\n },\n },\n },\n {\n id: 'agent-only',\n label: 'agent-only',\n summary:\n 'AI agents act for people under a delegation. Sessions are off; delegations and the actions they allow carry the activity.',\n examples: [\n 'AI assistant calling APIs on user behalf',\n 'autonomous trading bot',\n 'agent-driven customer support',\n ],\n events: {\n account_creation: {\n enabled: true,\n site_pays: FIXED(1056),\n user_share_pct: 0.8,\n },\n agent_delegation_issued: {\n enabled: true,\n site_pays: FIXED(260),\n user_share_pct: 0.8,\n },\n scoped_action_authorization: {\n enabled: true,\n site_pays: FIXED(81),\n user_share_pct: 0.8,\n },\n },\n },\n];\n\nconst ARCHETYPES_BY_ID: Record<IntegratorArchetype, ArchetypeTemplate> = Object.fromEntries(\n ARCHETYPE_TEMPLATES.map((t) => [t.id, t])\n) as Record<IntegratorArchetype, ArchetypeTemplate>;\n\n/** All 12 subtypes — used to fill `enabled: false` defaults for any\n * subtype the chosen archetype doesn't list. */\nconst ALL_SUBTYPES: readonly EventSubtype[] = [\n 'account_creation',\n 'account_recovery',\n 'attest_bond_increased',\n 'payment_method_connected',\n 'agent_delegation_issued',\n 'recovery_method_updated',\n 'payment_authorization',\n 'scoped_action_authorization',\n 'attest_verification_at_gate',\n 'stamp_signing',\n 'pledge_resolution',\n 'session_creation',\n];\n\nconst DEFAULT_DISABLED: IntegratorEventConfig = {\n enabled: false,\n site_pays: { kind: 'fixed_sats', sats: 100 },\n user_share_pct: 0.8,\n};\n\n/**\n * Build a complete IntegratorPriceConfig from an archetype id + the\n * project's identity fields. Every subtype gets an entry — the\n * archetype's listed subtypes get the template's pricing; everything\n * else gets `enabled: false` with conservative defaults so the config\n * is type-complete and the integrator can flip-on later subtypes\n * without re-deriving prices.\n *\n * Throws synchronously if `useCase` isn't a known archetype id.\n */\nexport function fromTemplate(\n useCase: IntegratorArchetype,\n identity: ProjectIdentity\n): IntegratorPriceConfig {\n const template = ARCHETYPES_BY_ID[useCase];\n if (!template) {\n throw new Error(\n `oc.config.fromTemplate: unknown archetype \"${useCase}\". Valid: ${Object.keys(\n ARCHETYPES_BY_ID\n ).join(', ')}`\n );\n }\n const events: IntegratorPriceConfig['events'] = {};\n for (const sub of ALL_SUBTYPES) {\n events[sub] = template.events[sub] ?? DEFAULT_DISABLED;\n }\n return {\n project_key: identity.project_key,\n domain: identity.domain,\n display_name: identity.display_name,\n updated_at: new Date().toISOString(),\n events,\n };\n}\n\n/** Look up a template's metadata · used by config-editor UIs to render\n * \"you're on the X template · here's what it enables\" copy. */\nexport function getArchetypeTemplate(id: IntegratorArchetype): ArchetypeTemplate {\n return ARCHETYPES_BY_ID[id];\n}\n"]}
package/dist/server.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { VerifyOcOptions, SessionRequestHeaders, SessionPayload } from '@orangecheck/auth-core';
1
+ import { SessionPayload, VerifyOcOptions, SessionRequestHeaders } from '@orangecheck/auth-core';
2
2
  export { BondClaim, SessionPayload, VerifyOcOptions, bondMeets, readBondClaim, verifyOcToken } from '@orangecheck/auth-core';
3
3
  export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity, r as refreshEnvelopeJwks, v as verifyActivityAttestation } from './identity-1VYMOhzV.mjs';
4
4
 
@@ -16,7 +16,9 @@ interface NextApiResponseLike {
16
16
  json(body: unknown): unknown;
17
17
  setHeader(name: string, value: string | number | readonly string[]): unknown;
18
18
  }
19
- type NextApiHandlerLike = (req: NextApiRequestLike, res: NextApiResponseLike) => unknown | Promise<unknown>;
19
+ type WithOcSession<Req> = Req & {
20
+ ocSession?: SessionPayload | null;
21
+ };
20
22
  interface WithOcAuthOptions extends VerifyOcOptions {
21
23
  required?: boolean;
22
24
  requireBond?: {
@@ -28,7 +30,19 @@ interface WithOcAuthOptions extends VerifyOcOptions {
28
30
  meOrigin?: string;
29
31
  }
30
32
  declare const BACK_ACCOUNT_URL = "https://ochk.app/me/account#backing";
31
- declare function withOcAuth<T extends NextApiHandlerLike>(handler: T, options?: WithOcAuthOptions): T;
33
+ declare function withOcAuth<Req extends NextApiRequestLike = NextApiRequestLike, Res extends NextApiResponseLike = NextApiResponseLike>(handler: (req: WithOcSession<Req>, res: Res) => unknown, options?: WithOcAuthOptions): (req: Req, res: Res) => Promise<unknown>;
34
+ declare global {
35
+ namespace Express {
36
+ interface Request {
37
+ ocSession?: SessionPayload | null;
38
+ }
39
+ }
40
+ }
41
+ type OcHonoEnv = {
42
+ Variables: {
43
+ ocSession: SessionPayload | null;
44
+ };
45
+ };
32
46
  interface ExpressRequestLike {
33
47
  headers: {
34
48
  cookie?: string;
@@ -57,4 +71,4 @@ interface HonoContextLike {
57
71
  type HonoNextLike = () => Promise<void>;
58
72
  declare function ocAuthHono(options?: WithOcAuthOptions): (c: HonoContextLike, next: HonoNextLike) => Promise<unknown>;
59
73
 
60
- export { BACK_ACCOUNT_URL, type WithOcAuthOptions, getOcSession, ocAuthExpress, ocAuthHono, withOcAuth };
74
+ export { BACK_ACCOUNT_URL, type OcHonoEnv, type WithOcAuthOptions, type WithOcSession, getOcSession, ocAuthExpress, ocAuthHono, withOcAuth };
package/dist/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { VerifyOcOptions, SessionRequestHeaders, SessionPayload } from '@orangecheck/auth-core';
1
+ import { SessionPayload, VerifyOcOptions, SessionRequestHeaders } from '@orangecheck/auth-core';
2
2
  export { BondClaim, SessionPayload, VerifyOcOptions, bondMeets, readBondClaim, verifyOcToken } from '@orangecheck/auth-core';
3
3
  export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity, r as refreshEnvelopeJwks, v as verifyActivityAttestation } from './identity-1VYMOhzV.js';
4
4
 
@@ -16,7 +16,9 @@ interface NextApiResponseLike {
16
16
  json(body: unknown): unknown;
17
17
  setHeader(name: string, value: string | number | readonly string[]): unknown;
18
18
  }
19
- type NextApiHandlerLike = (req: NextApiRequestLike, res: NextApiResponseLike) => unknown | Promise<unknown>;
19
+ type WithOcSession<Req> = Req & {
20
+ ocSession?: SessionPayload | null;
21
+ };
20
22
  interface WithOcAuthOptions extends VerifyOcOptions {
21
23
  required?: boolean;
22
24
  requireBond?: {
@@ -28,7 +30,19 @@ interface WithOcAuthOptions extends VerifyOcOptions {
28
30
  meOrigin?: string;
29
31
  }
30
32
  declare const BACK_ACCOUNT_URL = "https://ochk.app/me/account#backing";
31
- declare function withOcAuth<T extends NextApiHandlerLike>(handler: T, options?: WithOcAuthOptions): T;
33
+ declare function withOcAuth<Req extends NextApiRequestLike = NextApiRequestLike, Res extends NextApiResponseLike = NextApiResponseLike>(handler: (req: WithOcSession<Req>, res: Res) => unknown, options?: WithOcAuthOptions): (req: Req, res: Res) => Promise<unknown>;
34
+ declare global {
35
+ namespace Express {
36
+ interface Request {
37
+ ocSession?: SessionPayload | null;
38
+ }
39
+ }
40
+ }
41
+ type OcHonoEnv = {
42
+ Variables: {
43
+ ocSession: SessionPayload | null;
44
+ };
45
+ };
32
46
  interface ExpressRequestLike {
33
47
  headers: {
34
48
  cookie?: string;
@@ -57,4 +71,4 @@ interface HonoContextLike {
57
71
  type HonoNextLike = () => Promise<void>;
58
72
  declare function ocAuthHono(options?: WithOcAuthOptions): (c: HonoContextLike, next: HonoNextLike) => Promise<unknown>;
59
73
 
60
- export { BACK_ACCOUNT_URL, type WithOcAuthOptions, getOcSession, ocAuthExpress, ocAuthHono, withOcAuth };
74
+ export { BACK_ACCOUNT_URL, type OcHonoEnv, type WithOcAuthOptions, type WithOcSession, getOcSession, ocAuthExpress, ocAuthHono, withOcAuth };
package/dist/server.js CHANGED
@@ -450,8 +450,12 @@ async function getOcSession(headers, options = {}) {
450
450
  var warnedAudience = false;
451
451
  function warnIfAudienceMissing(headers) {
452
452
  if (warnedAudience) return;
453
- const auth = typeof Headers !== "undefined" && headers instanceof Headers ? headers.get("authorization") : headers.authorization;
454
- const m = typeof auth === "string" ? /^Bearer\s+([^.]+)\.([^.]+)\./i.exec(auth) : null;
453
+ const web = typeof Headers !== "undefined" && headers instanceof Headers;
454
+ const auth = web ? headers.get("authorization") : headers.authorization;
455
+ const cookie = web ? headers.get("cookie") : headers.cookie;
456
+ const bearer = typeof auth === "string" ? /^Bearer\s+(\S+)$/i.exec(auth.trim())?.[1] : void 0;
457
+ const fromCookie = typeof cookie === "string" ? /(?:^|;\s*)oc_session=([^;]+)/.exec(cookie)?.[1] : void 0;
458
+ const m = /^([^.]+)\.([^.]+)\./.exec(bearer ?? fromCookie ?? "");
455
459
  if (!m) return;
456
460
  try {
457
461
  const payload = JSON.parse(base64UrlToString(m[2]));
@@ -469,6 +473,8 @@ function base64UrlToString(s) {
469
473
  return Buffer.from(s, "base64url").toString("utf8");
470
474
  }
471
475
  var BACK_ACCOUNT_URL = "https://ochk.app/me/account#backing";
476
+ var unknownKeys = /* @__PURE__ */ new Map();
477
+ var UNKNOWN_PROJECT = /* @__PURE__ */ Symbol("unknown_project");
472
478
  var POLICY_TTL_MS = 6e4;
473
479
  var POLICY_RETRY_MS = 1e4;
474
480
  var policies = /* @__PURE__ */ new Map();
@@ -476,6 +482,7 @@ async function projectRequirement(options) {
476
482
  const key = options.projectKey;
477
483
  const hit = policies.get(key);
478
484
  const now = Date.now();
485
+ if (unknownKeys.has(key) && now - unknownKeys.get(key) < POLICY_TTL_MS) return UNKNOWN_PROJECT;
479
486
  if (hit && now - hit.at < POLICY_TTL_MS) return hit.need;
480
487
  if (hit?.failedAt && now - hit.failedAt < POLICY_RETRY_MS) return hit.at ? hit.need : void 0;
481
488
  try {
@@ -483,6 +490,16 @@ async function projectRequirement(options) {
483
490
  const r = await fetch(`${base}/api/integrator/${encodeURIComponent(key)}/sign-in`, {
484
491
  signal: AbortSignal.timeout(4e3)
485
492
  });
493
+ if (r.status === 404) {
494
+ if (!unknownKeys.has(key)) {
495
+ console.error(
496
+ `[@orangecheck/me-client] projectKey "${key}" is not a project. Copy yours from https://ochk.app/me/projects.`
497
+ );
498
+ }
499
+ unknownKeys.set(key, Date.now());
500
+ return UNKNOWN_PROJECT;
501
+ }
502
+ unknownKeys.delete(key);
486
503
  if (!r.ok) throw new Error(`HTTP ${r.status}`);
487
504
  const j = await r.json();
488
505
  const req = j.require_bond ?? null;
@@ -504,6 +521,9 @@ async function refusal(session, options) {
504
521
  if (!session && options.required) {
505
522
  return { status: 401, body: { ok: false, reason: "unauthenticated" } };
506
523
  }
524
+ if (need === UNKNOWN_PROJECT) {
525
+ return { status: 500, body: { ok: false, reason: "unknown_project_key" } };
526
+ }
507
527
  if (need === void 0) {
508
528
  return { status: 503, body: { ok: false, reason: "bond_policy_unavailable" } };
509
529
  }
@@ -530,7 +550,7 @@ async function refusal(session, options) {
530
550
  return null;
531
551
  }
532
552
  function withOcAuth(handler, options = {}) {
533
- const wrapped = async (req, res) => {
553
+ return async (req, res) => {
534
554
  res.setHeader("Cache-Control", "no-store, private");
535
555
  res.setHeader("Vary", "Cookie, Authorization");
536
556
  const session = await getOcSession(
@@ -540,12 +560,12 @@ function withOcAuth(handler, options = {}) {
540
560
  },
541
561
  options
542
562
  );
543
- req.ocSession = session;
563
+ const withSession = req;
564
+ withSession.ocSession = session;
544
565
  const refused = await refusal(session, options);
545
566
  if (refused) return res.status(refused.status).json(refused.body);
546
- return handler(req, res);
567
+ return handler(withSession, res);
547
568
  };
548
- return wrapped;
549
569
  }
550
570
  function ocAuthExpress(options = {}) {
551
571
  return async (req, res, next) => {