@develemit/billing 0.3.0 → 0.4.0
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.
- package/README.md +26 -0
- package/dist/{chunk-YQNTE5Q6.js → chunk-JKIQULCW.js} +76 -4
- package/dist/chunk-JKIQULCW.js.map +1 -0
- package/dist/fastify.cjs +74 -3
- package/dist/fastify.cjs.map +1 -1
- package/dist/fastify.d.cts +1 -1
- package/dist/fastify.d.ts +1 -1
- package/dist/fastify.js +1 -1
- package/dist/index.cjs +90 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +19 -3
- package/dist/index.js.map +1 -1
- package/dist/{types-C1m-_c0H.d.cts → types-B2BMXZYQ.d.cts} +22 -1
- package/dist/{types-C1m-_c0H.d.ts → types-B2BMXZYQ.d.ts} +22 -1
- package/package.json +7 -7
- package/dist/chunk-YQNTE5Q6.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@develemit/billing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsup"
|
|
32
|
+
},
|
|
30
33
|
"dependencies": {
|
|
31
34
|
"zod": "^4.4.3"
|
|
32
35
|
},
|
|
@@ -34,11 +37,8 @@
|
|
|
34
37
|
"fastify": "^5.10.0"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
40
|
+
"@org/shared-types": "workspace:*",
|
|
37
41
|
"fastify": "^5.10.0",
|
|
38
|
-
"tsup": "^8.5.1"
|
|
39
|
-
"@org/shared-types": "0.0.1"
|
|
40
|
-
},
|
|
41
|
-
"scripts": {
|
|
42
|
-
"build": "tsup"
|
|
42
|
+
"tsup": "^8.5.1"
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../shared-types/src/admin.ts","../../shared-types/src/event-log.ts","../../shared-types/src/entitlements.ts","../../shared-types/src/subscriptions.ts","../../shared-types/src/overrides.ts","../../shared-types/src/checkout.ts","../../shared-types/src/projects.ts","../../shared-types/src/trials.ts","../../shared-types/src/errors.ts","../../shared-types/src/webhook-secret.ts","../../shared-types/src/portal-return-url.ts","../src/errors.ts","../src/guard.ts"],"sourcesContent":["import { z } from 'zod';\nimport {\n adminEventDetailSchema,\n adminEventSummarySchema,\n signatureCountSchema,\n wouldApplySchema,\n} from './event-log.js';\nimport { entitlementsResponseSchema } from './entitlements.js';\nimport { overrideRecordSchema } from './overrides.js';\nimport { subscriptionStatusSchema } from './subscriptions.js';\n\n// Per-project and ecosystem-wide subscription state counts. `grace` is\n// computed (never stored) — see @org/entitlements' resolveAccessStatus.\nexport const stateCountsSchema = z.object({\n trialing: z.number(),\n active: z.number(),\n past_due: z.number(),\n grace: z.number(),\n canceled: z.number(),\n unpaid: z.number(),\n});\nexport type StateCounts = z.infer<typeof stateCountsSchema>;\n\nconst dashboardMetricsSchema = z.object({\n mrrCents: z.number(),\n mrrPrevCents: z.number(),\n subjectsCount: z.number(),\n states: stateCountsSchema,\n deadLetterDepth: z.number(),\n oldestUnprocessedSec: z.number().nullable(),\n driftCount: z.number(),\n});\n\nexport const projectMetricsSchema = dashboardMetricsSchema.extend({\n projectId: z.string(),\n projectKey: z.string(),\n projectName: z.string(),\n subjectType: z.string(),\n environment: z.enum(['test', 'live']),\n envLocked: z.boolean(),\n mrrSeries: z.array(z.number()),\n});\nexport type ProjectMetrics = z.infer<typeof projectMetricsSchema>;\n\nexport const adminMetricsResponseSchema = z.object({\n ecosystem: dashboardMetricsSchema,\n // Shared x-axis labels for every project's mrrSeries (same calendar\n // months across the ecosystem) — empty when no project has snapshots yet.\n monthLabels: z.array(z.string()),\n projects: z.array(projectMetricsSchema),\n});\nexport type AdminMetricsResponse = z.infer<typeof adminMetricsResponseSchema>;\n\n// Cursor-based (data-display.md's \"Newer / Older\" contract): the page query\n// and the approximate total are the only two things a caller needs — no\n// offset, no page number.\nexport const adminEventsListResponseSchema = z.object({\n events: z.array(adminEventSummarySchema),\n nextCursor: z.string().nullable(),\n approxTotal: z.number(),\n signatureCounts: z.array(signatureCountSchema).optional(),\n});\nexport type AdminEventsListResponse = z.infer<\n typeof adminEventsListResponseSchema\n>;\n\nexport const adminEventDetailResponseSchema = z.object({\n event: adminEventDetailSchema,\n transition: z.object({\n current: z\n .object({\n state: subscriptionStatusSchema.exclude(['grace', 'none']),\n lastEventAt: z.iso.datetime().nullable(),\n })\n .nullable(),\n wouldApply: wouldApplySchema,\n }),\n});\nexport type AdminEventDetailResponse = z.infer<\n typeof adminEventDetailResponseSchema\n>;\n\nexport const adminSubjectSchema = z.object({\n id: z.string(),\n subjectType: z.string(),\n externalId: z.string(),\n providerCustomerId: z.string().nullable(),\n});\nexport type AdminSubject = z.infer<typeof adminSubjectSchema>;\n\n// Grants are the raw material entitlements are computed from (sprints\n// 12-14): a boolean flag or a numeric limit, keyed by feature name.\nexport const featureGrantsSchema = z.record(\n z.string(),\n z.union([z.boolean(), z.number()]),\n);\nexport type AdminFeatureGrants = z.infer<typeof featureGrantsSchema>;\n\n// The subject's most recent subscription's plan, independent of whether\n// that subscription currently grants access (unlike entitlements.plan,\n// which is null exactly when it doesn't) — sprint 40's plan-aware comp\n// reads this to restore the plan's real grants rather than a synthetic\n// flag. priceInterval is null when the plan has no price to derive one\n// from; comp falls back to a fixed cycle length in that case.\nexport const adminSubjectSubscriptionPlanSchema = z.object({\n key: z.string(),\n featureGrants: featureGrantsSchema,\n priceInterval: z.enum(['month', 'year']).nullable(),\n});\nexport type AdminSubjectSubscriptionPlan = z.infer<\n typeof adminSubjectSubscriptionPlanSchema\n>;\n\nexport const adminSubjectLookupResponseSchema = z.object({\n subject: adminSubjectSchema,\n entitlements: entitlementsResponseSchema,\n recentEvents: z.array(adminEventSummarySchema),\n activeOverrides: z.array(overrideRecordSchema),\n subscriptionPlan: adminSubjectSubscriptionPlanSchema.nullable(),\n});\nexport type AdminSubjectLookupResponse = z.infer<\n typeof adminSubjectLookupResponseSchema\n>;\n\nexport const adminPriceSchema = z.object({\n id: z.string(),\n interval: z.enum(['month', 'year']),\n currency: z.string(),\n unitAmountCents: z.number(),\n syncStatus: z.enum(['synced', 'pending', 'drifted']),\n syncedUnitAmountCents: z.number().nullable(),\n});\nexport type AdminPrice = z.infer<typeof adminPriceSchema>;\n\nexport const adminPlanSchema = z.object({\n id: z.string(),\n key: z.string(),\n name: z.string(),\n featureGrants: featureGrantsSchema,\n activeSubscriptions: z.number(),\n prices: z.array(adminPriceSchema),\n});\nexport type AdminPlan = z.infer<typeof adminPlanSchema>;\n\n// Statement descriptors are project-level, not per-plan (packages/db's\n// projects table), but the plan editor screen renders and edits the field\n// alongside the plans it applies to — so the response carries the project's\n// resolved descriptor config as a sibling of the plan list, not duplicated\n// per plan.\nexport const adminPlansResponseSchema = z.object({\n project: z.object({\n statementDescriptor: z.string().nullable(),\n statementDescriptorPrefix: z.string().nullable(),\n }),\n plans: z.array(adminPlanSchema),\n});\nexport type AdminPlansResponse = z.infer<typeof adminPlansResponseSchema>;\n\n// Never the raw secret — masked to last-4 (or null if never configured).\nexport const adminProviderResponseSchema = z.object({\n projectId: z.string(),\n providerKind: z.string(),\n environment: z.enum(['test', 'live']),\n envLocked: z.boolean(),\n secretKeyMasked: z.string().nullable(),\n publishableKeyMasked: z.string().nullable(),\n webhookEndpoint: z.string(),\n webhookSigningConfigured: z.boolean(),\n defaultPortalReturnUrl: z.string().nullable(),\n});\nexport type AdminProviderResponse = z.infer<typeof adminProviderResponseSchema>;\n\n// The overrides domain has no project_id column of its own (project scope\n// comes from a join through subjects), so the admin service tags each entry\n// with its project as it assembles the cross-project audit response.\nexport const adminAuditEntrySchema = overrideRecordSchema.extend({\n projectId: z.string(),\n});\nexport type AdminAuditEntry = z.infer<typeof adminAuditEntrySchema>;\n\nexport const adminAuditResponseSchema = z.object({\n entries: z.array(adminAuditEntrySchema),\n nextCursor: z.string().nullable(),\n approxTotal: z.number(),\n});\nexport type AdminAuditResponse = z.infer<typeof adminAuditResponseSchema>;\n\n// Parallel arrays, not one row per day, to match EventThroughput's own prop\n// shape (data-display.md chart 3) — the web layer passes these straight\n// through without reshaping.\nexport const adminThroughputResponseSchema = z.object({\n days: z.array(z.string()),\n processed: z.array(z.number()),\n failed: z.array(z.number()),\n});\nexport type AdminThroughputResponse = z.infer<\n typeof adminThroughputResponseSchema\n>;\n\n// No historical snapshot table exists for plan mix (unlike MRR's\n// mrr_snapshots — see packages/db/src/schema/mrr-snapshots.ts's own note\n// that nothing populates it beyond the dev seed). Sprint 38 scopes this to\n// the current month only rather than inventing a snapshot table: `months`\n// and `stacks` always carry exactly one entry.\nexport const adminPlanMixResponseSchema = z.object({\n months: z.array(z.string()),\n plans: z.array(z.object({ key: z.string(), name: z.string() })),\n stacks: z.array(z.array(z.number())),\n});\nexport type AdminPlanMixResponse = z.infer<typeof adminPlanMixResponseSchema>;\n\n// (project_id, error_signature) GROUP BY over the full dead-letter queue —\n// distinct from signatureCountSchema (event-log.ts), which groups by\n// signature alone within one already-project-scoped page and can't tell two\n// projects' identical error text apart.\nexport const adminDeadLetterGroupSchema = z.object({\n projectId: z.string(),\n signature: z.string(),\n count: z.number(),\n sampleEventId: z.string(),\n firstReceivedAt: z.iso.datetime(),\n lastReceivedAt: z.iso.datetime(),\n});\nexport type AdminDeadLetterGroup = z.infer<typeof adminDeadLetterGroupSchema>;\n\nexport const adminDeadLetterGroupsResponseSchema = z.object({\n groups: z.array(adminDeadLetterGroupSchema),\n});\nexport type AdminDeadLetterGroupsResponse = z.infer<\n typeof adminDeadLetterGroupsResponseSchema\n>;\n\n// One project's full overview-card payload in a single round trip — the\n// scoped counterpart to adminMetricsResponseSchema's all-projects bundle,\n// for screens that only ever render one project (project-overview.tsx).\nexport const adminProjectDashboardResponseSchema = z.object({\n metrics: projectMetricsSchema,\n monthLabels: z.array(z.string()),\n providerKind: z.string(),\n plans: z.array(adminPlanSchema),\n // True when the caller gave no `environment` and the key named more than\n // one row (sprint 66) — `metrics.environment` was picked by a\n // deterministic fallback rather than requested explicitly, and the\n // frontend labels it as such (sprint 68.5).\n environmentDefaulted: z.boolean(),\n});\nexport type AdminProjectDashboardResponse = z.infer<\n typeof adminProjectDashboardResponseSchema\n>;\n","import { z } from 'zod';\n\nexport const eventStatusSchema = z.enum([\n 'received',\n 'processed',\n 'failed',\n 'dead_letter',\n 'discarded',\n]);\nexport type EventStatus = z.infer<typeof eventStatusSchema>;\n\n// Matches @org/db's subscription_state enum — the five states the state\n// machine actually stores, not the computed 'grace'/'none' views.\nexport const subscriptionStateSchema = z.enum([\n 'trialing',\n 'active',\n 'past_due',\n 'canceled',\n 'unpaid',\n]);\nexport type SubscriptionStateContract = z.infer<typeof subscriptionStateSchema>;\n\nexport const adminEventSummarySchema = z.object({\n id: z.string(),\n projectId: z.string(),\n providerEventId: z.string(),\n type: z.string(),\n status: eventStatusSchema,\n attempts: z.number(),\n lastError: z.string().nullable(),\n errorSignature: z.string().nullable(),\n receivedAt: z.iso.datetime(),\n processedAt: z.iso.datetime().nullable(),\n // event_log has no subject/customer reference column (sprint 24's\n // repo-drizzle-subjects.ts documents the same gap the other direction) —\n // derived from the raw Stripe payload's well-known `data.object.customer`\n // path, so this is null for any non-Stripe-shaped payload.\n subjectRef: z.string().nullable(),\n});\nexport type AdminEventSummary = z.infer<typeof adminEventSummarySchema>;\n\nexport const adminEventDetailSchema = adminEventSummarySchema.extend({\n payload: z.record(z.string(), z.unknown()),\n discardReason: z.string().nullable(),\n discardedBy: z.string().nullable(),\n discardedAt: z.iso.datetime().nullable(),\n});\nexport type AdminEventDetail = z.infer<typeof adminEventDetailSchema>;\n\nexport const signatureCountSchema = z.object({\n signature: z.string(),\n count: z.number(),\n});\nexport type SignatureCount = z.infer<typeof signatureCountSchema>;\n\nexport const listEventsResponseSchema = z.object({\n events: z.array(adminEventSummarySchema),\n total: z.number(),\n limit: z.number(),\n offset: z.number(),\n signatureCounts: z.array(signatureCountSchema),\n});\nexport type ListEventsResponse = z.infer<typeof listEventsResponseSchema>;\n\n// Mirrors ApplyResult from apps/api's pure state machine, plus 'error' for\n// when the stored payload itself can't be replayed (e.g. missing provider\n// credentials) — dry-run degrades to this rather than throwing across the\n// HTTP boundary.\nexport const wouldApplySchema = z.discriminatedUnion('kind', [\n z.object({ kind: z.literal('create'), to: subscriptionStateSchema }),\n z.object({\n kind: z.literal('transition'),\n from: subscriptionStateSchema,\n to: subscriptionStateSchema,\n }),\n z.object({ kind: z.literal('stale') }),\n z.object({\n kind: z.literal('invalid'),\n from: subscriptionStateSchema,\n to: subscriptionStateSchema,\n }),\n z.object({ kind: z.literal('unknown_subscription') }),\n z.object({ kind: z.literal('noop'), reason: z.string() }),\n z.object({ kind: z.literal('error'), reason: z.string() }),\n]);\nexport type WouldApply = z.infer<typeof wouldApplySchema>;\n\nexport const dryRunReplayResponseSchema = z.object({\n event: adminEventDetailSchema,\n current: z\n .object({\n state: subscriptionStateSchema,\n lastEventAt: z.iso.datetime().nullable(),\n })\n .nullable(),\n wouldApply: wouldApplySchema,\n});\nexport type DryRunReplayResponse = z.infer<typeof dryRunReplayResponseSchema>;\n\nexport const replayOutcomeSchema = z.enum([\n 'created',\n 'transitioned',\n 'stale',\n 'noop',\n 'invalid',\n 'unknown_subscription',\n 'already_processed',\n 'error',\n 'foreign_project',\n]);\n\nexport const replayResponseSchema = z.object({\n outcome: replayOutcomeSchema,\n});\nexport type ReplayResponse = z.infer<typeof replayResponseSchema>;\n\nexport const discardEventRequestSchema = z.object({\n actor: z.string().min(1),\n reason: z.string(),\n});\nexport type DiscardEventRequest = z.infer<typeof discardEventRequestSchema>;\n\n// Operator-triggered, small-N batches (sprint 39): a hard ceiling so a bulk\n// replay can never process an unbounded number of events, whether in one\n// request or paged across several (sprint 48's progress UI). Shared so the\n// api's per-request clamp and the web client's paging loop can't drift.\nexport const BULK_REPLAY_CAP = 200;\n\n// Opaque-enough keyset cursor over (receivedAt, id), mirroring\n// processing-repo.ts's EventCursor — event_log's id is a random uuid, so\n// receivedAt provides the real chronological order and id only breaks ties.\nexport const replayGroupCursorSchema = z.object({\n receivedAt: z.iso.datetime(),\n id: z.string(),\n});\nexport type ReplayGroupCursor = z.infer<typeof replayGroupCursorSchema>;\n\n// A group is targeted either by its (project, signature) pair or by \"every\n// dead-lettered event in this project\" — never both, and never neither.\n// cursor/limit are optional so a bare {projectId, errorSignature|all} still\n// replays a single up-to-BULK_REPLAY_CAP batch exactly as before; the web\n// client's progress UI (sprint 48) pages through with them instead.\nexport const replayGroupRequestSchema = z\n .object({\n projectId: z.string().min(1),\n cursor: replayGroupCursorSchema.optional(),\n limit: z.number().int().positive().optional(),\n })\n .and(\n z.union([\n z.object({ errorSignature: z.string().min(1) }),\n z.object({ all: z.literal(true) }),\n ]),\n );\nexport type ReplayGroupRequest = z.infer<typeof replayGroupRequestSchema>;\n\nexport const replayGroupOutcomeEntrySchema = z.object({\n eventId: z.string(),\n outcome: replayOutcomeSchema,\n});\n\nexport const replayGroupResponseSchema = z.object({\n outcomes: z.array(replayGroupOutcomeEntrySchema),\n // Keyed by ProcessOutcome, but zod v4's record needs .partial() semantics\n // for an exhaustive enum key type, so this stays a plain string map — the\n // set of possible keys is still exactly replayOutcomeSchema's members.\n counts: z.record(z.string(), z.number()),\n // This call's batch (its own limit, or BULK_REPLAY_CAP by default) hit its\n // ceiling: more matching events remain beyond what was just replayed.\n // Paging with nextCursor continues; a non-paging caller reads this the\n // same way it always has, as \"replay again to finish draining it.\"\n truncated: z.boolean(),\n nextCursor: replayGroupCursorSchema.nullable(),\n});\nexport type ReplayGroupResponse = z.infer<typeof replayGroupResponseSchema>;\n","import { z } from 'zod';\n\nimport { subscriptionStatusSchema } from './subscriptions.js';\n\n// Additive alongside the aggregate `source` field below (kept for SDK\n// back-compat): every key in `features`/`limits` gets its own entry here,\n// so a caller no longer has to infer per-key provenance by cross-referencing\n// overrides itself.\nexport const entitlementSourcesSchema = z.object({\n features: z.record(z.string(), z.enum(['subscription', 'override'])),\n limits: z.record(z.string(), z.enum(['subscription', 'override'])),\n});\nexport type EntitlementSources = z.infer<typeof entitlementSourcesSchema>;\n\nexport const entitlementsResponseSchema = z.object({\n plan: z.string().nullable(),\n features: z.record(z.string(), z.boolean()),\n limits: z.record(z.string(), z.number()),\n status: subscriptionStatusSchema,\n source: z.enum(['subscription', 'override', 'none']),\n sources: entitlementSourcesSchema,\n});\nexport type EntitlementsResponse = z.infer<typeof entitlementsResponseSchema>;\n","import { z } from 'zod';\n\n// `grace` and `none` are computed from @org/db's stored enum + graceDays, never stored themselves.\nexport const subscriptionStatusSchema = z.enum([\n 'trialing',\n 'active',\n 'past_due',\n 'grace',\n 'canceled',\n 'unpaid',\n 'none',\n]);\nexport type SubscriptionStatus = z.infer<typeof subscriptionStatusSchema>;\n\nconst activeSubscriptionViewSchema = z.object({\n state: subscriptionStatusSchema.exclude(['none']),\n planKey: z.string(),\n currentPeriodEnd: z.iso.datetime(),\n cancelAtPeriodEnd: z.boolean(),\n});\n\nconst noSubscriptionViewSchema = z.object({\n state: z.literal('none'),\n});\n\nexport const subscriptionViewSchema = z.discriminatedUnion('state', [\n activeSubscriptionViewSchema,\n noSubscriptionViewSchema,\n]);\nexport type SubscriptionView = z.infer<typeof subscriptionViewSchema>;\n","import { z } from 'zod';\n\n// Operator vocabulary (matches the dashboard's comp/extend/revoke buttons),\n// distinct from @org/entitlements' internal grant|revoke computation\n// vocabulary — apps/api's overrides domain translates between the two.\nexport const overrideKindSchema = z.enum(['comp', 'extend', 'revoke']);\nexport type OverrideKind = z.infer<typeof overrideKindSchema>;\n\nexport const overrideTargetSchema = z.discriminatedUnion('type', [\n z.object({ type: z.literal('feature'), feature: z.string().min(1) }),\n z.object({\n type: z.literal('limit'),\n limit: z.string().min(1),\n value: z.number(),\n }),\n]);\nexport type OverrideTarget = z.infer<typeof overrideTargetSchema>;\n\nexport const createOverrideRequestSchema = z.object({\n subjectId: z.string().min(1),\n kind: overrideKindSchema,\n target: overrideTargetSchema,\n actor: z.string().min(1),\n reason: z.string().min(4),\n expiresAt: z.iso.datetime().optional(),\n});\nexport type CreateOverrideRequest = z.infer<typeof createOverrideRequestSchema>;\n\n// Multi-target variant: one subject, one kind/actor/reason/expiresAt, several\n// targets applied atomically (e.g. comping every grant key a plan defines) —\n// see apps/api's overrides service for the all-or-nothing guarantee.\nexport const createBulkOverrideRequestSchema = z.object({\n subjectId: z.string().min(1),\n kind: overrideKindSchema,\n targets: z.array(overrideTargetSchema).min(1),\n actor: z.string().min(1),\n reason: z.string().min(4),\n expiresAt: z.iso.datetime().optional(),\n});\nexport type CreateBulkOverrideRequest = z.infer<\n typeof createBulkOverrideRequestSchema\n>;\n\nexport const overrideRecordSchema = z.object({\n id: z.string(),\n subjectId: z.string(),\n kind: overrideKindSchema,\n target: overrideTargetSchema,\n actor: z.string(),\n reason: z.string(),\n expiresAt: z.iso.datetime().nullable(),\n createdAt: z.iso.datetime(),\n});\nexport type OverrideRecord = z.infer<typeof overrideRecordSchema>;\n\nexport const bulkOverrideResponseSchema = z.object({\n overrides: z.array(overrideRecordSchema),\n});\nexport type BulkOverrideResponse = z.infer<typeof bulkOverrideResponseSchema>;\n\nexport const listOverridesResponseSchema = z.object({\n overrides: z.array(overrideRecordSchema),\n total: z.number(),\n limit: z.number(),\n offset: z.number(),\n});\nexport type ListOverridesResponse = z.infer<typeof listOverridesResponseSchema>;\n","import { z } from 'zod';\n\nexport const checkoutRequestSchema = z.object({\n planKey: z.string(),\n subjectId: z.string(),\n successUrl: z.url(),\n cancelUrl: z.url(),\n email: z.email().optional(),\n});\nexport type CheckoutRequest = z.infer<typeof checkoutRequestSchema>;\n\nexport const checkoutResponseSchema = z.object({\n url: z.url(),\n});\nexport type CheckoutResponse = z.infer<typeof checkoutResponseSchema>;\n\nexport const portalRequestSchema = z.object({\n subjectId: z.string(),\n returnUrl: z.url(),\n});\nexport type PortalRequest = z.infer<typeof portalRequestSchema>;\n\nexport const portalResponseSchema = z.object({\n url: z.url(),\n});\nexport type PortalResponse = z.infer<typeof portalResponseSchema>;\n","import { z } from 'zod';\n\n// The source of truth for a registration payload's shape — apps/api's\n// projects service validates against this directly (no parallel\n// hand-written type), and the admin UI can reuse it for form validation.\nexport const registerProjectRequestSchema = z\n .object({\n key: z.string().trim().min(1, 'is required'),\n name: z.string().trim().min(1, 'is required'),\n subjectType: z.string().trim().min(1, 'is required'),\n environment: z.enum(['test', 'live'], 'must be \"test\" or \"live\"'),\n envLocked: z.boolean().optional(),\n providerKind: z.string().trim().min(1, 'is required'),\n providerSecretKeyRef: z.string().optional(),\n providerPublishableKeyRef: z.string().optional(),\n providerPortalConfigRef: z.string().optional(),\n statementDescriptor: z.string().optional(),\n statementDescriptorPrefix: z.string().optional(),\n graceDays: z.number().min(0, 'must be >= 0').optional(),\n defaultPortalReturnUrl: z.url().optional(),\n })\n .superRefine((input, ctx) => {\n if (!input.statementDescriptor && !input.statementDescriptorPrefix) {\n ctx.addIssue({\n code: 'custom',\n path: ['statementDescriptor'],\n message: 'statementDescriptor or statementDescriptorPrefix is required',\n });\n }\n });\nexport type RegisterProjectRequest = z.infer<\n typeof registerProjectRequestSchema\n>;\n","import { z } from 'zod';\n\n// Cap on self-serve trials: a leaked or buggy project key can cost at most\n// one month of entitlement per subject, never a decade.\nexport const MAX_TRIAL_DURATION_DAYS = 31;\nexport const DEFAULT_TRIAL_DURATION_DAYS = 7;\n\nexport const startTrialRequestSchema = z.object({\n subjectId: z.string().min(1),\n feature: z.string().min(1),\n durationDays: z\n .number()\n .int()\n .min(1)\n .max(MAX_TRIAL_DURATION_DAYS)\n .default(DEFAULT_TRIAL_DURATION_DAYS),\n});\n// Input (what a consumer sends — durationDays optional) and output (what the\n// route hands the service — durationDays defaulted) diverge here, unlike the\n// other contracts in this package.\nexport type StartTrialRequest = z.input<typeof startTrialRequestSchema>;\nexport type ParsedStartTrialRequest = z.output<typeof startTrialRequestSchema>;\n\nexport const trialGrantSchema = z.object({\n id: z.string(),\n subjectId: z.string(),\n feature: z.string(),\n expiresAt: z.iso.datetime(),\n createdAt: z.iso.datetime(),\n});\nexport type TrialGrant = z.infer<typeof trialGrantSchema>;\n\n// `created: false` means a trial already existed for this subject+feature —\n// possibly one that has since expired (expiresAt in the past). A subject gets\n// one trial ever; retries return the original instead of stacking a new one.\nexport const startTrialResponseSchema = z.object({\n trial: trialGrantSchema,\n created: z.boolean(),\n});\nexport type StartTrialResponse = z.infer<typeof startTrialResponseSchema>;\n","import { z } from 'zod';\n\nexport const errorEnvelopeSchema = z.object({\n error: z.object({\n code: z.string(),\n message: z.string(),\n }),\n});\nexport type ErrorEnvelope = z.infer<typeof errorEnvelopeSchema>;\n","import { z } from 'zod';\n\nexport class InvalidWebhookSecretError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'InvalidWebhookSecretError';\n }\n}\n\n// Stripe generates its own signing secret when a webhook endpoint is\n// created through its dashboard/API — this only validates the shape of a\n// value an operator copies in from there, it never generates one itself.\nconst webhookSigningSecretSchema = z\n .string()\n .regex(/^whsec_.+/, 'must be a non-empty whsec_-prefixed string');\n\nexport function resolveWebhookSigningSecret(value: string): string {\n const result = webhookSigningSecretSchema.safeParse(value);\n if (!result.success) {\n throw new InvalidWebhookSecretError(result.error.issues[0].message);\n }\n return result.data;\n}\n","import { z } from 'zod';\n\nexport class InvalidPortalReturnUrlError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'InvalidPortalReturnUrlError';\n }\n}\n\nconst portalReturnUrlSchema = z.url();\n\nexport function resolveDefaultPortalReturnUrl(value: string): string {\n const result = portalReturnUrlSchema.safeParse(value);\n if (!result.success) {\n throw new InvalidPortalReturnUrlError(result.error.issues[0].message);\n }\n return result.data;\n}\n","import { errorEnvelopeSchema } from '@org/shared-types';\n\n// Thrown for every failure path — API denials, transport failures, and\n// malformed responses alike — so consumers can branch on `status`/`code`\n// instead of catching different error shapes.\nexport class BillingApiError extends Error {\n readonly status: number;\n readonly code: string;\n\n constructor(status: number, code: string, message: string) {\n super(message);\n this.name = 'BillingApiError';\n this.status = status;\n this.code = code;\n }\n}\n\nexport async function errorFromResponse(\n response: Response,\n): Promise<BillingApiError> {\n let code = 'unknown_error';\n let message = `Request failed with status ${response.status}`;\n\n try {\n const body: unknown = await response.json();\n const parsed = errorEnvelopeSchema.safeParse(body);\n if (parsed.success) {\n code = parsed.data.error.code;\n message = parsed.data.error.message;\n }\n } catch {\n // Body wasn't JSON or didn't match the envelope — keep the defaults.\n }\n\n return new BillingApiError(response.status, code, message);\n}\n\n// Status 0 distinguishes \"couldn't reach the API\" from a real HTTP response,\n// so middleware (sprint 16) can fail open on outages without also failing\n// open on 4xx denials.\nexport function networkError(cause: unknown): BillingApiError {\n const message =\n cause instanceof Error ? cause.message : 'Network request failed';\n return new BillingApiError(0, 'network_error', message);\n}\n\nexport function invalidResponseError(message: string): BillingApiError {\n return new BillingApiError(502, 'invalid_response', message);\n}\n","import { BillingApiError } from './errors.js';\nimport type {\n CheckEntitlementInput,\n EntitlementsResult,\n GuardDecision,\n LimitCheck,\n} from './types.js';\n\nfunction isMisconfiguration(err: unknown): boolean {\n return (\n err instanceof BillingApiError && err.status >= 400 && err.status < 500\n );\n}\n\nfunction decideOnContent(\n entitlements: EntitlementsResult,\n feature: string | undefined,\n limit: LimitCheck | undefined,\n): GuardDecision {\n if (feature !== undefined) {\n return entitlements.features[feature]\n ? { decision: 'allow', entitlements }\n : { decision: 'deny', reason: `Feature \"${feature}\" is not entitled` };\n }\n\n if (limit !== undefined) {\n const max = entitlements.limits[limit.key];\n return max !== undefined && limit.usage < max\n ? { decision: 'allow', entitlements }\n : { decision: 'deny', reason: `Limit \"${limit.key}\" has been reached` };\n }\n\n return { decision: 'allow', entitlements };\n}\n\n// Framework-agnostic orchestration over BillingClient — Fastify (or any\n// other framework) middleware only needs to map GuardDecision to a\n// response. Keep this file free of any framework import.\nexport async function checkEntitlement(\n input: CheckEntitlementInput,\n): Promise<GuardDecision> {\n const { client, subjectId, feature, limit, onUnavailable } = input;\n\n let entitlements: EntitlementsResult;\n try {\n entitlements = await client.getEntitlements(subjectId);\n } catch (err) {\n if (isMisconfiguration(err)) {\n const message =\n err instanceof Error ? err.message : 'Billing request was rejected';\n return { decision: 'deny', reason: message, misconfigured: true };\n }\n return onUnavailable === 'open'\n ? { decision: 'unavailable-allow' }\n : { decision: 'unavailable-deny', reason: 'Billing is unavailable' };\n }\n\n // Fresh or stale, this is content-based — a stale entitlements payload is\n // the graceful-degradation path working, not an unavailability case.\n return decideOnContent(entitlements, feature, limit);\n}\n"],"mappings":";AAAA,SAAS,KAAAA,UAAS;;;ACAlB,SAAS,SAAS;AAEX,IAAM,oBAAoB,EAAE,KAAK;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAKM,IAAM,0BAA0B,EAAE,KAAK;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,IAAM,0BAA0B,EAAE,OAAO;AAAA,EAC9C,IAAI,EAAE,OAAO;AAAA,EACb,WAAW,EAAE,OAAO;AAAA,EACpB,iBAAiB,EAAE,OAAO;AAAA,EAC1B,MAAM,EAAE,OAAO;AAAA,EACf,QAAQ;AAAA,EACR,UAAU,EAAE,OAAO;AAAA,EACnB,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,gBAAgB,EAAE,OAAO,EAAE,SAAS;AAAA,EACpC,YAAY,EAAE,IAAI,SAAS;AAAA,EAC3B,aAAa,EAAE,IAAI,SAAS,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvC,YAAY,EAAE,OAAO,EAAE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