@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 CHANGED
@@ -197,6 +197,29 @@ Latency is measured with `performance.now()`, so `shadowLatencyMs` keeps
197
197
  sub-millisecond resolution — a cache-served shadow read reports e.g. `0.1`
198
198
  rather than a flat `0` that's indistinguishable from "never measured."
199
199
 
200
+ ## Reporting usage (metered plans)
201
+
202
+ ```ts
203
+ await billing.reportUsage({
204
+ subjectId: 'user_123',
205
+ quantity: 1,
206
+ timestamp: new Date(),
207
+ idempotencyKey: `delivery:${deliveryId}`,
208
+ });
209
+
210
+ const { usage } = await billing.getEntitlements('user_123');
211
+ // usage?.used, usage?.periodEnd — undefined on licensed plans and for
212
+ // subjects with no subscription
213
+ ```
214
+
215
+ **Idempotency contract.** The API dedupes on `(subject, idempotencyKey)`. If
216
+ you omit `idempotencyKey`, the SDK generates a random one for that call —
217
+ which is only safe when you never retry. **If you retry a failed report,
218
+ pass the same key every time; a fresh key is a new event and double-bills.**
219
+ Prefer a natural id you already own (a delivery id, a job id) so a retry
220
+ after a crash reuses it. Timestamps must be within the last 35 days and no
221
+ more than 5 minutes in the future.
222
+
200
223
  ## Behavior
201
224
 
202
225
  - `getEntitlements(subjectId)` caches per-subject for `entitlementsTtlMs`
@@ -215,6 +238,9 @@ rather than a flat `0` that's indistinguishable from "never measured."
215
238
  expired, so retried signups can't stack or restart a trial. A successful
216
239
  call drops that subject's cached entitlements so the next
217
240
  `getEntitlements` reflects the grant immediately.
241
+ - `reportUsage({ subjectId, quantity, timestamp, idempotencyKey? })` posts to
242
+ `/v1/usage`, returns the stored record, and drops that subject's cached
243
+ entitlements. It throws `BillingApiError` on any failure.
218
244
  - Every failure is a `BillingApiError` with `status` and `code`. Network
219
245
  failures use `status: 0, code: 'network_error'` so callers can tell
220
246
  "billing is unreachable" apart from "request was denied".
@@ -153,19 +153,31 @@ var subscriptionViewSchema = z2.discriminatedUnion("state", [
153
153
  activeSubscriptionViewSchema,
154
154
  noSubscriptionViewSchema
155
155
  ]);
156
+ var subscriptionCancelRequestSchema = z2.object({
157
+ subjectId: z2.string()
158
+ });
159
+ var subscriptionCancelResponseSchema = z2.object({
160
+ canceled: z2.literal(true),
161
+ providerSubscriptionId: z2.string()
162
+ });
156
163
 
157
164
  // ../shared-types/src/entitlements.ts
158
165
  var entitlementSourcesSchema = z3.object({
159
166
  features: z3.record(z3.string(), z3.enum(["subscription", "override"])),
160
167
  limits: z3.record(z3.string(), z3.enum(["subscription", "override"]))
161
168
  });
169
+ var meteredUsageSchema = z3.object({
170
+ used: z3.number(),
171
+ periodEnd: z3.string()
172
+ });
162
173
  var entitlementsResponseSchema = z3.object({
163
174
  plan: z3.string().nullable(),
164
175
  features: z3.record(z3.string(), z3.boolean()),
165
176
  limits: z3.record(z3.string(), z3.number()),
166
177
  status: subscriptionStatusSchema,
167
178
  source: z3.enum(["subscription", "override", "none"]),
168
- sources: entitlementSourcesSchema
179
+ sources: entitlementSourcesSchema,
180
+ usage: meteredUsageSchema.optional()
169
181
  });
170
182
 
171
183
  // ../shared-types/src/overrides.ts
@@ -243,6 +255,8 @@ var projectMetricsSchema = dashboardMetricsSchema.extend({
243
255
  mrrSeries: z5.array(z5.number())
244
256
  });
245
257
  var adminMetricsResponseSchema = z5.object({
258
+ // Which environment every total below describes — never a mix.
259
+ environment: z5.enum(["test", "live"]),
246
260
  ecosystem: dashboardMetricsSchema,
247
261
  // Shared x-axis labels for every project's mrrSeries (same calendar
248
262
  // months across the ecosystem) — empty when no project has snapshots yet.
@@ -291,7 +305,11 @@ var adminPriceSchema = z5.object({
291
305
  id: z5.string(),
292
306
  interval: z5.enum(["month", "year"]),
293
307
  currency: z5.string(),
294
- unitAmountCents: z5.number(),
308
+ // Null for a metered price (sprint 96) — no fixed amount to display yet.
309
+ unitAmountCents: z5.number().nullable(),
310
+ // Optional on input so callers built before sprint 96 still parse; always
311
+ // present on output via the default.
312
+ usageType: z5.enum(["licensed", "metered"]).default("licensed"),
295
313
  syncStatus: z5.enum(["synced", "pending", "drifted"]),
296
314
  syncedUnitAmountCents: z5.number().nullable()
297
315
  });
@@ -345,7 +363,8 @@ var adminDeadLetterGroupSchema = z5.object({
345
363
  count: z5.number(),
346
364
  sampleEventId: z5.string(),
347
365
  firstReceivedAt: z5.iso.datetime(),
348
- lastReceivedAt: z5.iso.datetime()
366
+ lastReceivedAt: z5.iso.datetime(),
367
+ environment: z5.enum(["test", "live"])
349
368
  });
350
369
  var adminDeadLetterGroupsResponseSchema = z5.object({
351
370
  groups: z5.array(adminDeadLetterGroupSchema)
@@ -446,6 +465,58 @@ var webhookSigningSecretSchema = z10.string().regex(/^whsec_.+/, "must be a non-
446
465
  import { z as z11 } from "zod";
447
466
  var portalReturnUrlSchema = z11.url();
448
467
 
468
+ // ../shared-types/src/usage.ts
469
+ import { z as z12 } from "zod";
470
+ var recordUsageRequestSchema = z12.object({
471
+ subjectId: z12.string().min(1),
472
+ quantity: z12.number().int().positive(),
473
+ timestamp: z12.iso.datetime(),
474
+ idempotencyKey: z12.string().min(1)
475
+ });
476
+ var usageRecordSchema = z12.object({
477
+ id: z12.string(),
478
+ subjectId: z12.string(),
479
+ quantity: z12.number(),
480
+ eventTimestamp: z12.iso.datetime(),
481
+ idempotencyKey: z12.string(),
482
+ createdAt: z12.iso.datetime()
483
+ });
484
+ var listUsageResponseSchema = z12.object({
485
+ records: z12.array(usageRecordSchema),
486
+ total: z12.number().int().nonnegative(),
487
+ limit: z12.number().int().nonnegative(),
488
+ offset: z12.number().int().nonnegative()
489
+ });
490
+
491
+ // ../shared-types/src/admin-usage.ts
492
+ import { z as z13 } from "zod";
493
+ var usageIssueCauseSchema = z13.enum([
494
+ "unreportable",
495
+ "no_customer",
496
+ "no_meter",
497
+ "transport_failure",
498
+ "waiting"
499
+ ]);
500
+ var adminUsageIssueSchema = z13.object({
501
+ id: z13.string(),
502
+ projectId: z13.string(),
503
+ subjectId: z13.string(),
504
+ planKey: z13.string().nullable(),
505
+ quantity: z13.number(),
506
+ eventTimestamp: z13.iso.datetime(),
507
+ createdAt: z13.iso.datetime(),
508
+ state: z13.enum(["terminal", "retrying"]),
509
+ cause: usageIssueCauseSchema,
510
+ reason: z13.string(),
511
+ attempts: z13.number()
512
+ });
513
+ var adminUsageIssuesResponseSchema = z13.object({
514
+ environment: z13.enum(["test", "live"]),
515
+ issues: z13.array(adminUsageIssueSchema),
516
+ nextCursor: z13.string().nullable(),
517
+ approxTotal: z13.number()
518
+ });
519
+
449
520
  // src/errors.ts
450
521
  var BillingApiError = class extends Error {
451
522
  status;
@@ -514,10 +585,11 @@ export {
514
585
  checkoutResponseSchema,
515
586
  portalResponseSchema,
516
587
  startTrialResponseSchema,
588
+ usageRecordSchema,
517
589
  BillingApiError,
518
590
  errorFromResponse,
519
591
  networkError,
520
592
  invalidResponseError,
521
593
  checkEntitlement
522
594
  };
523
- //# sourceMappingURL=chunk-YQNTE5Q6.js.map
595
+ //# sourceMappingURL=chunk-JKIQULCW.js.map
@@ -0,0 +1 @@
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","../../shared-types/src/usage.ts","../../shared-types/src/admin-usage.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 // Which environment every total below describes — never a mix.\n environment: z.enum(['test', 'live']),\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 // Null for a metered price (sprint 96) — no fixed amount to display yet.\n unitAmountCents: z.number().nullable(),\n // Optional on input so callers built before sprint 96 still parse; always\n // present on output via the default.\n usageType: z.enum(['licensed', 'metered']).default('licensed'),\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 environment: z.enum(['test', 'live']),\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\n// Kept in its own well-typed field rather than folded into `limits` — sprint\n// 79.1 is the cautionary tale for a wrong-typed value in that map 500ing the\n// endpoint in production. Absent entirely (not present with a null/zero\n// value) for a licensed plan or a subject with no subscription, so older\n// callers and existing licensed-plan responses stay byte-identical.\nexport const meteredUsageSchema = z.object({\n used: z.number(),\n periodEnd: z.string(),\n});\nexport type MeteredUsage = z.infer<typeof meteredUsageSchema>;\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 usage: meteredUsageSchema.optional(),\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\nexport const subscriptionCancelRequestSchema = z.object({\n subjectId: z.string(),\n});\nexport type SubscriptionCancelRequest = z.infer<\n typeof subscriptionCancelRequestSchema\n>;\n\nexport const subscriptionCancelResponseSchema = z.object({\n canceled: z.literal(true),\n providerSubscriptionId: z.string(),\n});\nexport type SubscriptionCancelResponse = z.infer<\n typeof subscriptionCancelResponseSchema\n>;\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 { z } from 'zod';\n\nexport const recordUsageRequestSchema = z.object({\n subjectId: z.string().min(1),\n quantity: z.number().int().positive(),\n timestamp: z.iso.datetime(),\n idempotencyKey: z.string().min(1),\n});\nexport type RecordUsageRequest = z.infer<typeof recordUsageRequestSchema>;\n\nexport const usageRecordSchema = z.object({\n id: z.string(),\n subjectId: z.string(),\n quantity: z.number(),\n eventTimestamp: z.iso.datetime(),\n idempotencyKey: z.string(),\n createdAt: z.iso.datetime(),\n});\nexport type UsageRecordResponse = z.infer<typeof usageRecordSchema>;\n\nexport const listUsageResponseSchema = z.object({\n records: z.array(usageRecordSchema),\n total: z.number().int().nonnegative(),\n limit: z.number().int().nonnegative(),\n offset: z.number().int().nonnegative(),\n});\nexport type ListUsageResponse = z.infer<typeof listUsageResponseSchema>;\n","import { z } from 'zod';\n\n// 'unreportable' is terminal (the sweep gave up); the rest are still-pending\n// rows the sweep has already touched, split by *why* they haven't landed.\n// 'waiting' means nothing is wrong that the row itself can show — it was\n// claimed and simply hasn't been reported yet.\nexport const usageIssueCauseSchema = z.enum([\n 'unreportable',\n 'no_customer',\n 'no_meter',\n 'transport_failure',\n 'waiting',\n]);\nexport type UsageIssueCause = z.infer<typeof usageIssueCauseSchema>;\n\nexport const adminUsageIssueSchema = z.object({\n id: z.string(),\n projectId: z.string(),\n subjectId: z.string(),\n planKey: z.string().nullable(),\n quantity: z.number(),\n eventTimestamp: z.iso.datetime(),\n createdAt: z.iso.datetime(),\n state: z.enum(['terminal', 'retrying']),\n cause: usageIssueCauseSchema,\n reason: z.string(),\n attempts: z.number(),\n});\nexport type AdminUsageIssue = z.infer<typeof adminUsageIssueSchema>;\n\n// Echoes the resolved environment like every ecosystem-scoped admin read\n// (sprints 104–106), so an omitted param can't be mistaken for \"all\".\nexport const adminUsageIssuesResponseSchema = z.object({\n environment: z.enum(['test', 'live']),\n issues: z.array(adminUsageIssueSchema),\n nextCursor: z.string().nullable(),\n approxTotal: z.number(),\n});\nexport type AdminUsageIssuesResponse = z.infer<\n typeof adminUsageIssuesResponseSchema\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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I;AACF,mBAAe,MAAM,OAAO,gBAAgB,SAAS;AAAA,EACvD,SAAS,KAAK;AACZ,QAAI,mBAAmB,GAAG,GAAG;AAC3B,YAAM,UACJ,eAAe,QAAQ,IAAI,UAAU;AACvC,aAAO,EAAE,UAAU,QAAQ,QAAQ,SAAS,eAAe,KAAK;AAAA,IAClE;AACA,WAAO,kBAAkB,SACrB,EAAE,UAAU,oBAAoB,IAChC,EAAE,UAAU,oBAAoB,QAAQ,yBAAyB;AAAA,EACvE;AAIA,SAAO,gBAAgB,cAAc,SAAS,KAAK;AACrD;","names":["z","z","z","z","z","z","z","z","z","z","z","z","z","z","z","z"]}
package/dist/fastify.cjs CHANGED
@@ -179,19 +179,31 @@ var subscriptionViewSchema = import_zod2.z.discriminatedUnion("state", [
179
179
  activeSubscriptionViewSchema,
180
180
  noSubscriptionViewSchema
181
181
  ]);
182
+ var subscriptionCancelRequestSchema = import_zod2.z.object({
183
+ subjectId: import_zod2.z.string()
184
+ });
185
+ var subscriptionCancelResponseSchema = import_zod2.z.object({
186
+ canceled: import_zod2.z.literal(true),
187
+ providerSubscriptionId: import_zod2.z.string()
188
+ });
182
189
 
183
190
  // ../shared-types/src/entitlements.ts
184
191
  var entitlementSourcesSchema = import_zod3.z.object({
185
192
  features: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.enum(["subscription", "override"])),
186
193
  limits: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.enum(["subscription", "override"]))
187
194
  });
195
+ var meteredUsageSchema = import_zod3.z.object({
196
+ used: import_zod3.z.number(),
197
+ periodEnd: import_zod3.z.string()
198
+ });
188
199
  var entitlementsResponseSchema = import_zod3.z.object({
189
200
  plan: import_zod3.z.string().nullable(),
190
201
  features: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.boolean()),
191
202
  limits: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number()),
192
203
  status: subscriptionStatusSchema,
193
204
  source: import_zod3.z.enum(["subscription", "override", "none"]),
194
- sources: entitlementSourcesSchema
205
+ sources: entitlementSourcesSchema,
206
+ usage: meteredUsageSchema.optional()
195
207
  });
196
208
 
197
209
  // ../shared-types/src/overrides.ts
@@ -269,6 +281,8 @@ var projectMetricsSchema = dashboardMetricsSchema.extend({
269
281
  mrrSeries: import_zod5.z.array(import_zod5.z.number())
270
282
  });
271
283
  var adminMetricsResponseSchema = import_zod5.z.object({
284
+ // Which environment every total below describes — never a mix.
285
+ environment: import_zod5.z.enum(["test", "live"]),
272
286
  ecosystem: dashboardMetricsSchema,
273
287
  // Shared x-axis labels for every project's mrrSeries (same calendar
274
288
  // months across the ecosystem) — empty when no project has snapshots yet.
@@ -317,7 +331,11 @@ var adminPriceSchema = import_zod5.z.object({
317
331
  id: import_zod5.z.string(),
318
332
  interval: import_zod5.z.enum(["month", "year"]),
319
333
  currency: import_zod5.z.string(),
320
- unitAmountCents: import_zod5.z.number(),
334
+ // Null for a metered price (sprint 96) — no fixed amount to display yet.
335
+ unitAmountCents: import_zod5.z.number().nullable(),
336
+ // Optional on input so callers built before sprint 96 still parse; always
337
+ // present on output via the default.
338
+ usageType: import_zod5.z.enum(["licensed", "metered"]).default("licensed"),
321
339
  syncStatus: import_zod5.z.enum(["synced", "pending", "drifted"]),
322
340
  syncedUnitAmountCents: import_zod5.z.number().nullable()
323
341
  });
@@ -371,7 +389,8 @@ var adminDeadLetterGroupSchema = import_zod5.z.object({
371
389
  count: import_zod5.z.number(),
372
390
  sampleEventId: import_zod5.z.string(),
373
391
  firstReceivedAt: import_zod5.z.iso.datetime(),
374
- lastReceivedAt: import_zod5.z.iso.datetime()
392
+ lastReceivedAt: import_zod5.z.iso.datetime(),
393
+ environment: import_zod5.z.enum(["test", "live"])
375
394
  });
376
395
  var adminDeadLetterGroupsResponseSchema = import_zod5.z.object({
377
396
  groups: import_zod5.z.array(adminDeadLetterGroupSchema)
@@ -472,6 +491,58 @@ var webhookSigningSecretSchema = import_zod10.z.string().regex(/^whsec_.+/, "mus
472
491
  var import_zod11 = require("zod");
473
492
  var portalReturnUrlSchema = import_zod11.z.url();
474
493
 
494
+ // ../shared-types/src/usage.ts
495
+ var import_zod12 = require("zod");
496
+ var recordUsageRequestSchema = import_zod12.z.object({
497
+ subjectId: import_zod12.z.string().min(1),
498
+ quantity: import_zod12.z.number().int().positive(),
499
+ timestamp: import_zod12.z.iso.datetime(),
500
+ idempotencyKey: import_zod12.z.string().min(1)
501
+ });
502
+ var usageRecordSchema = import_zod12.z.object({
503
+ id: import_zod12.z.string(),
504
+ subjectId: import_zod12.z.string(),
505
+ quantity: import_zod12.z.number(),
506
+ eventTimestamp: import_zod12.z.iso.datetime(),
507
+ idempotencyKey: import_zod12.z.string(),
508
+ createdAt: import_zod12.z.iso.datetime()
509
+ });
510
+ var listUsageResponseSchema = import_zod12.z.object({
511
+ records: import_zod12.z.array(usageRecordSchema),
512
+ total: import_zod12.z.number().int().nonnegative(),
513
+ limit: import_zod12.z.number().int().nonnegative(),
514
+ offset: import_zod12.z.number().int().nonnegative()
515
+ });
516
+
517
+ // ../shared-types/src/admin-usage.ts
518
+ var import_zod13 = require("zod");
519
+ var usageIssueCauseSchema = import_zod13.z.enum([
520
+ "unreportable",
521
+ "no_customer",
522
+ "no_meter",
523
+ "transport_failure",
524
+ "waiting"
525
+ ]);
526
+ var adminUsageIssueSchema = import_zod13.z.object({
527
+ id: import_zod13.z.string(),
528
+ projectId: import_zod13.z.string(),
529
+ subjectId: import_zod13.z.string(),
530
+ planKey: import_zod13.z.string().nullable(),
531
+ quantity: import_zod13.z.number(),
532
+ eventTimestamp: import_zod13.z.iso.datetime(),
533
+ createdAt: import_zod13.z.iso.datetime(),
534
+ state: import_zod13.z.enum(["terminal", "retrying"]),
535
+ cause: usageIssueCauseSchema,
536
+ reason: import_zod13.z.string(),
537
+ attempts: import_zod13.z.number()
538
+ });
539
+ var adminUsageIssuesResponseSchema = import_zod13.z.object({
540
+ environment: import_zod13.z.enum(["test", "live"]),
541
+ issues: import_zod13.z.array(adminUsageIssueSchema),
542
+ nextCursor: import_zod13.z.string().nullable(),
543
+ approxTotal: import_zod13.z.number()
544
+ });
545
+
475
546
  // src/errors.ts
476
547
  var BillingApiError = class extends Error {
477
548
  status;