@revstackhq/node 0.0.0-dev-20260226054346

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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +136 -0
  3. package/dist/errors.d.ts +106 -0
  4. package/dist/errors.d.ts.map +1 -0
  5. package/dist/errors.js +102 -0
  6. package/dist/index.d.ts +75 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +94 -0
  9. package/dist/modules/admin/entitlements.d.ts +68 -0
  10. package/dist/modules/admin/entitlements.d.ts.map +1 -0
  11. package/dist/modules/admin/entitlements.js +87 -0
  12. package/dist/modules/admin/environments.d.ts +71 -0
  13. package/dist/modules/admin/environments.d.ts.map +1 -0
  14. package/dist/modules/admin/environments.js +84 -0
  15. package/dist/modules/admin/index.d.ts +30 -0
  16. package/dist/modules/admin/index.d.ts.map +1 -0
  17. package/dist/modules/admin/index.js +31 -0
  18. package/dist/modules/admin/integrations.d.ts +79 -0
  19. package/dist/modules/admin/integrations.d.ts.map +1 -0
  20. package/dist/modules/admin/integrations.js +97 -0
  21. package/dist/modules/admin/plans.d.ts +72 -0
  22. package/dist/modules/admin/plans.d.ts.map +1 -0
  23. package/dist/modules/admin/plans.js +93 -0
  24. package/dist/modules/admin/system.d.ts +53 -0
  25. package/dist/modules/admin/system.d.ts.map +1 -0
  26. package/dist/modules/admin/system.js +61 -0
  27. package/dist/modules/base.d.ts +43 -0
  28. package/dist/modules/base.d.ts.map +1 -0
  29. package/dist/modules/base.js +84 -0
  30. package/dist/modules/customers.d.ts +56 -0
  31. package/dist/modules/customers.d.ts.map +1 -0
  32. package/dist/modules/customers.js +72 -0
  33. package/dist/modules/entitlements.d.ts +49 -0
  34. package/dist/modules/entitlements.d.ts.map +1 -0
  35. package/dist/modules/entitlements.js +64 -0
  36. package/dist/modules/invoices.d.ts +33 -0
  37. package/dist/modules/invoices.d.ts.map +1 -0
  38. package/dist/modules/invoices.js +37 -0
  39. package/dist/modules/plans.d.ts +35 -0
  40. package/dist/modules/plans.d.ts.map +1 -0
  41. package/dist/modules/plans.js +39 -0
  42. package/dist/modules/subscriptions.d.ts +55 -0
  43. package/dist/modules/subscriptions.d.ts.map +1 -0
  44. package/dist/modules/subscriptions.js +71 -0
  45. package/dist/modules/usage.d.ts +59 -0
  46. package/dist/modules/usage.d.ts.map +1 -0
  47. package/dist/modules/usage.js +80 -0
  48. package/dist/modules/wallets.d.ts +53 -0
  49. package/dist/modules/wallets.d.ts.map +1 -0
  50. package/dist/modules/wallets.js +69 -0
  51. package/dist/modules/webhooks.d.ts +51 -0
  52. package/dist/modules/webhooks.d.ts.map +1 -0
  53. package/dist/modules/webhooks.js +90 -0
  54. package/dist/src/errors.d.ts +91 -0
  55. package/dist/src/errors.d.ts.map +1 -0
  56. package/dist/src/errors.js +101 -0
  57. package/dist/src/index.d.ts +71 -0
  58. package/dist/src/index.d.ts.map +1 -0
  59. package/dist/src/index.js +91 -0
  60. package/dist/src/modules/admin/entitlements.d.ts +73 -0
  61. package/dist/src/modules/admin/entitlements.d.ts.map +1 -0
  62. package/dist/src/modules/admin/entitlements.js +90 -0
  63. package/dist/src/modules/admin/environments.d.ts +76 -0
  64. package/dist/src/modules/admin/environments.d.ts.map +1 -0
  65. package/dist/src/modules/admin/environments.js +87 -0
  66. package/dist/src/modules/admin/index.d.ts +16 -0
  67. package/dist/src/modules/admin/index.d.ts.map +1 -0
  68. package/dist/src/modules/admin/index.js +16 -0
  69. package/dist/src/modules/admin/integrations.d.ts +84 -0
  70. package/dist/src/modules/admin/integrations.d.ts.map +1 -0
  71. package/dist/src/modules/admin/integrations.js +100 -0
  72. package/dist/src/modules/admin/plans.d.ts +77 -0
  73. package/dist/src/modules/admin/plans.d.ts.map +1 -0
  74. package/dist/src/modules/admin/plans.js +96 -0
  75. package/dist/src/modules/admin/system.d.ts +53 -0
  76. package/dist/src/modules/admin/system.d.ts.map +1 -0
  77. package/dist/src/modules/admin/system.js +61 -0
  78. package/dist/src/modules/base.d.ts +43 -0
  79. package/dist/src/modules/base.d.ts.map +1 -0
  80. package/dist/src/modules/base.js +84 -0
  81. package/dist/src/modules/customers.d.ts +61 -0
  82. package/dist/src/modules/customers.d.ts.map +1 -0
  83. package/dist/src/modules/customers.js +75 -0
  84. package/dist/src/modules/entitlements.d.ts +54 -0
  85. package/dist/src/modules/entitlements.d.ts.map +1 -0
  86. package/dist/src/modules/entitlements.js +67 -0
  87. package/dist/src/modules/invoices.d.ts +38 -0
  88. package/dist/src/modules/invoices.d.ts.map +1 -0
  89. package/dist/src/modules/invoices.js +40 -0
  90. package/dist/src/modules/plans.d.ts +40 -0
  91. package/dist/src/modules/plans.d.ts.map +1 -0
  92. package/dist/src/modules/plans.js +42 -0
  93. package/dist/src/modules/subscriptions.d.ts +60 -0
  94. package/dist/src/modules/subscriptions.d.ts.map +1 -0
  95. package/dist/src/modules/subscriptions.js +74 -0
  96. package/dist/src/modules/usage.d.ts +64 -0
  97. package/dist/src/modules/usage.d.ts.map +1 -0
  98. package/dist/src/modules/usage.js +83 -0
  99. package/dist/src/modules/wallets.d.ts +58 -0
  100. package/dist/src/modules/wallets.d.ts.map +1 -0
  101. package/dist/src/modules/wallets.js +72 -0
  102. package/dist/src/modules/webhooks.d.ts +51 -0
  103. package/dist/src/modules/webhooks.d.ts.map +1 -0
  104. package/dist/src/modules/webhooks.js +90 -0
  105. package/dist/src/types.d.ts +676 -0
  106. package/dist/src/types.d.ts.map +1 -0
  107. package/dist/src/types.js +7 -0
  108. package/dist/types.d.ts +720 -0
  109. package/dist/types.d.ts.map +1 -0
  110. package/dist/types.js +7 -0
  111. package/package.json +40 -0
@@ -0,0 +1,720 @@
1
+ /**
2
+ * @module @revstackhq/node/types
3
+ * @description Core type definitions for the Revstack SDK. Split into Data Plane
4
+ * types (used by merchant backend code) and Admin types (used by the CLI and
5
+ * advanced integrations).
6
+ */
7
+ /**
8
+ * Configuration options for initializing the Revstack SDK client.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const revstack = new Revstack({
13
+ * secretKey: "sk_live_...",
14
+ * baseUrl: "https://app.revstack.dev/api/v1",
15
+ * timeout: 10000,
16
+ * });
17
+ * ```
18
+ */
19
+ export interface RevstackOptions {
20
+ /** Secret API key. Obtain yours at {@link https://app.revstack.dev}. */
21
+ secretKey: string;
22
+ /** Base URL for the Revstack API. Defaults to `https://app.revstack.dev/api/v1`. */
23
+ baseUrl?: string;
24
+ /** Request timeout in milliseconds. Defaults to `10000` (10s). */
25
+ timeout?: number;
26
+ }
27
+ /** Common pagination parameters for list endpoints. */
28
+ export interface ListParams {
29
+ /** Maximum number of records to return. */
30
+ limit?: number;
31
+ /** Number of records to skip (for offset-based pagination). */
32
+ offset?: number;
33
+ }
34
+ /**
35
+ * Paginated response wrapper returned by all list endpoints.
36
+ * @typeParam T - The type of each item in the `data` array.
37
+ */
38
+ export interface PaginatedResponse<T> {
39
+ /** Array of results for the current page. */
40
+ data: T[];
41
+ /** Total number of records matching the query (if available). */
42
+ total?: number;
43
+ /** Whether more records exist beyond this page. */
44
+ hasMore?: boolean;
45
+ }
46
+ /** Represents an end-user (app user) within a merchant's environment. */
47
+ export interface Customer {
48
+ /** Unique identifier with `usr_` prefix. */
49
+ id: string;
50
+ /** Environment this customer belongs to. */
51
+ environmentId: string;
52
+ /** UID from an external auth provider (e.g. Firebase, Auth0). */
53
+ providerUid?: string;
54
+ /** Customer's email address. */
55
+ email?: string;
56
+ /** Hashed device fingerprint for anonymous identification. */
57
+ deviceHash?: string;
58
+ /** Whether this customer was created anonymously. */
59
+ isAnonymous?: boolean;
60
+ /** External payment gateway customer ID (e.g. Stripe `cus_...`). */
61
+ gatewayCustomerId?: string;
62
+ /** Arbitrary key-value metadata attached to this customer. */
63
+ metadata?: Record<string, unknown>;
64
+ /** ISO 8601 timestamp of when this customer was created. */
65
+ createdAt?: string;
66
+ }
67
+ /**
68
+ * Parameters for identifying (upserting) a customer.
69
+ * If the `customerId` already exists, it updates the record.
70
+ */
71
+ export interface IdentifyCustomerParams {
72
+ /** Unique customer identifier within the merchant's system. */
73
+ customerId: string;
74
+ /** Customer email. */
75
+ email?: string;
76
+ /** Customer display name. */
77
+ name?: string;
78
+ /** Arbitrary metadata to attach to the customer. */
79
+ metadata?: Record<string, unknown>;
80
+ }
81
+ /** Parameters for updating an existing customer record. */
82
+ export interface UpdateCustomerParams {
83
+ /** New email address. */
84
+ email?: string;
85
+ /** Metadata fields to merge with existing metadata. */
86
+ metadata?: Record<string, unknown>;
87
+ }
88
+ /** Represents an active or historical subscription linking a customer to a plan. */
89
+ export interface Subscription {
90
+ /** Unique identifier with `sub_` prefix. */
91
+ id: string;
92
+ /** Environment this subscription belongs to. */
93
+ environmentId: string;
94
+ /** The customer who owns this subscription. */
95
+ appUserId?: string;
96
+ /** The plan this subscription is for. */
97
+ planId: string;
98
+ /** The specific price (billing interval) selected. */
99
+ priceId?: string;
100
+ /** Current status: `active`, `canceled`, `past_due`, `trialing`, etc. */
101
+ status: string;
102
+ /** Start of the current billing period (ISO 8601). */
103
+ currentPeriodStart: string;
104
+ /** End of the current billing period (ISO 8601). */
105
+ currentPeriodEnd: string;
106
+ /** Subscription ID in the external payment gateway (e.g. Stripe `sub_...`). */
107
+ externalSubscriptionId?: string;
108
+ /** Organization this subscription is billed to (for B2B). */
109
+ organizationId?: string;
110
+ /** Per-subscription entitlement overrides. */
111
+ customEntitlements?: Record<string, unknown>;
112
+ /** ISO 8601 timestamp of when this subscription was created. */
113
+ createdAt?: string;
114
+ }
115
+ /** Parameters for creating a new subscription. */
116
+ export interface CreateSubscriptionParams {
117
+ /** The customer to subscribe. */
118
+ customerId: string;
119
+ /** The plan to subscribe the customer to. */
120
+ planId: string;
121
+ /** Optional specific price ID (if the plan has multiple billing intervals). */
122
+ priceId?: string;
123
+ }
124
+ /** Parameters for changing a subscription's plan (upgrade/downgrade). */
125
+ export interface ChangePlanParams {
126
+ /** The new plan to switch to. */
127
+ newPlanId: string;
128
+ /** Optional specific price ID for the new plan. */
129
+ newPriceId?: string;
130
+ }
131
+ /** Filter parameters for listing subscriptions. */
132
+ export interface ListSubscriptionsParams extends ListParams {
133
+ /** Filter by customer ID. */
134
+ customerId?: string;
135
+ /** Filter by subscription status. */
136
+ status?: string;
137
+ }
138
+ /**
139
+ * Represents a feature or capability that can be gated behind a plan.
140
+ *
141
+ * @example
142
+ * An entitlement named "API Calls" with type "metered" and unitType "count"
143
+ * tracks how many API calls a customer has consumed.
144
+ */
145
+ export interface Entitlement {
146
+ /** Unique identifier with `ent_` prefix. */
147
+ id: string;
148
+ /** Human-readable entitlement name. */
149
+ name: string;
150
+ /** URL-safe unique slug (e.g. `api-calls`). */
151
+ slug: string;
152
+ /** Entitlement type: `boolean`, `metered`, `tiered`, etc. */
153
+ type: string;
154
+ /** Project this entitlement belongs to. */
155
+ projectId: string;
156
+ /** Unit of measurement: `count`, `bytes`, `seconds`, etc. */
157
+ unitType: string;
158
+ /** ISO 8601 timestamp of creation. */
159
+ createdAt?: string;
160
+ }
161
+ /** Options for checking an entitlement against a customer's allocation. */
162
+ export interface EntitlementCheckOptions {
163
+ /** The amount of the entitlement to consume. Defaults to `1`. */
164
+ amount?: number;
165
+ }
166
+ /** Result of an entitlement check. */
167
+ export interface EntitlementCheckResult {
168
+ /** Whether the customer is allowed to perform the action. */
169
+ allowed: boolean;
170
+ /** Human-readable reason if `allowed` is `false`. */
171
+ reason?: string;
172
+ /** Remaining balance after this check (for metered entitlements). */
173
+ remainingBalance?: number;
174
+ /** Currency of the remaining balance (for monetary entitlements). */
175
+ currency?: string;
176
+ }
177
+ /** Tracks cumulative usage of a metered entitlement for a customer. */
178
+ export interface UsageMeter {
179
+ /** Unique identifier with `meter_` prefix. */
180
+ id: string;
181
+ /** The customer this meter belongs to. */
182
+ appUserId: string;
183
+ /** The entitlement being metered. */
184
+ entitlementId: string;
185
+ /** Current usage count within the billing period. */
186
+ currentUsage: number;
187
+ /** ISO 8601 timestamp of the last recorded usage event. */
188
+ lastEventAt?: string;
189
+ /** ISO 8601 timestamp of when the meter will reset. */
190
+ resetAt?: string;
191
+ }
192
+ /** Parameters for reporting usage of a metered feature. */
193
+ export interface ReportUsageParams {
194
+ /** The customer who consumed the feature. */
195
+ customerId: string;
196
+ /** The entitlement slug or ID being consumed. */
197
+ featureId: string;
198
+ /** Amount of usage to report. */
199
+ amount: number;
200
+ /** Idempotency key to prevent duplicate reports. */
201
+ idempotencyKey?: string;
202
+ }
203
+ /**
204
+ * Parameters for reverting previously reported usage.
205
+ * Useful when a downstream API call fails after usage was already recorded.
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * // Revert usage after an OpenAI call fails
210
+ * await revstack.usage.revert({
211
+ * customerId: "usr_abc",
212
+ * featureId: "ai-tokens",
213
+ * amount: 500,
214
+ * reason: "downstream_failure",
215
+ * });
216
+ * ```
217
+ */
218
+ export interface RevertUsageParams {
219
+ /** The customer whose usage to revert. */
220
+ customerId: string;
221
+ /** The entitlement slug or ID to revert usage for. */
222
+ featureId: string;
223
+ /** Amount of usage to revert (positive number). */
224
+ amount: number;
225
+ /** Idempotency key to prevent double-reverts. */
226
+ idempotencyKey?: string;
227
+ /** Audit reason for the revert (e.g. `downstream_failure`, `user_error`). */
228
+ reason?: string;
229
+ }
230
+ /** Represents a customer's balance in a specific currency. */
231
+ export interface BalanceResponse {
232
+ /** ISO 4217 currency code (e.g. `USD`, `EUR`). */
233
+ currency: string;
234
+ /** Current balance amount. */
235
+ amount: number;
236
+ }
237
+ /** Parameters for granting credit to a customer's wallet. */
238
+ export interface GrantBalanceParams {
239
+ /** The customer to grant balance to. */
240
+ customerId: string;
241
+ /** ISO 4217 currency code. */
242
+ currency: string;
243
+ /** Amount to grant (positive number). */
244
+ amount: number;
245
+ /** Optional description for the transaction (e.g. `"Welcome bonus"`). */
246
+ description?: string;
247
+ }
248
+ /**
249
+ * Parameters for revoking (deducting) balance from a customer's wallet.
250
+ * Used for manual deductions, penalties, or credit refunds.
251
+ */
252
+ export interface RevokeBalanceParams {
253
+ /** The customer to deduct balance from. */
254
+ customerId: string;
255
+ /** ISO 4217 currency code. */
256
+ currency: string;
257
+ /** Amount to deduct (positive number). */
258
+ amount: number;
259
+ /** Audit reason for the deduction (e.g. `refund`, `penalty`, `adjustment`). */
260
+ reason?: string;
261
+ }
262
+ /**
263
+ * Represents a billing plan with its associated prices and entitlements.
264
+ * Read-only from the Data Plane — mutations happen via `revstack.admin.plans`.
265
+ */
266
+ export interface Plan {
267
+ /** Unique identifier with `plan_` prefix. */
268
+ id: string;
269
+ /** Human-readable plan name (e.g. `"Pro"`, `"Enterprise"`). */
270
+ name: string;
271
+ /** URL-safe unique slug (e.g. `pro`, `enterprise`). */
272
+ slug: string;
273
+ /** Optional plan description for display in pricing pages. */
274
+ description?: string;
275
+ /** Project this plan belongs to. */
276
+ projectId: string;
277
+ /** Plan status: `draft`, `active`, `archived`. */
278
+ status: string;
279
+ /** Plan type: `free`, `paid`, `custom`. */
280
+ type: string;
281
+ /** Arbitrary key-value metadata. */
282
+ metadata?: Record<string, unknown>;
283
+ /** Whether this is the default plan assigned to new customers. */
284
+ isDefault: boolean;
285
+ /** Whether this plan is publicly visible in pricing pages. */
286
+ isPublic: boolean;
287
+ /** Associated prices (billing intervals). Populated on `get()` calls. */
288
+ prices?: Price[];
289
+ /** Associated entitlement allocations. Populated on `get()` calls. */
290
+ entitlements?: PlanEntitlement[];
291
+ /** ISO 8601 timestamp of creation. */
292
+ createdAt?: string;
293
+ }
294
+ /** A specific price point for a plan (e.g. monthly, yearly). */
295
+ export interface Price {
296
+ /** Unique identifier with `price_` prefix. */
297
+ id: string;
298
+ /** The plan this price belongs to. */
299
+ planId: string;
300
+ /** Price amount in the smallest currency unit (e.g. cents). */
301
+ amount: number;
302
+ /** ISO 4217 currency code. Defaults to `USD`. */
303
+ currency: string;
304
+ /** Billing interval: `month`, `year`, `week`, `day`. */
305
+ billingInterval: string;
306
+ /** Overage pricing configuration for metered features. */
307
+ overageConfig?: Record<string, unknown>;
308
+ /** Whether this price is currently available for new subscriptions. */
309
+ isActive: boolean;
310
+ /** Number of trial days before billing begins. */
311
+ trialPeriodDays: number;
312
+ /** ISO 8601 timestamp of creation. */
313
+ createdAt?: string;
314
+ }
315
+ /** Maps an entitlement to a plan with specific limits and configuration. */
316
+ export interface PlanEntitlement {
317
+ /** Unique identifier with `plan_ent_` prefix. */
318
+ id: string;
319
+ /** The plan this allocation belongs to. */
320
+ planId: string;
321
+ /** The entitlement being allocated. */
322
+ entitlementId: string;
323
+ /** Numeric usage limit (for metered entitlements). `null` = unlimited. */
324
+ valueLimit?: number;
325
+ /** Boolean value (for boolean entitlements). */
326
+ valueBool?: boolean;
327
+ /** Text value (for text entitlements). */
328
+ valueText?: string;
329
+ /** JSON configuration value (for complex entitlements). */
330
+ valueConfig?: Record<string, unknown>;
331
+ /** Whether exceeding the limit blocks access (`true`) or only triggers alerts. */
332
+ isHardLimit: boolean;
333
+ /** Reset interval: `monthly`, `daily`, `yearly`, `never`. */
334
+ resetPeriod: string;
335
+ /** ISO 8601 timestamp of creation. */
336
+ createdAt?: string;
337
+ }
338
+ /** Filter parameters for listing plans. */
339
+ export interface ListPlansParams extends ListParams {
340
+ /** Filter by plan status. */
341
+ status?: string;
342
+ /** Filter by plan type. */
343
+ type?: string;
344
+ }
345
+ /**
346
+ * Represents a billing invoice generated for a subscription.
347
+ * Read-only from the Data Plane — invoices are created by the payment pipeline.
348
+ */
349
+ export interface Invoice {
350
+ /** Unique identifier with `inv_` prefix. */
351
+ id: string;
352
+ /** The subscription this invoice belongs to. */
353
+ subscriptionId: string;
354
+ /** Invoice amount in the smallest currency unit. */
355
+ amount: number;
356
+ /** ISO 4217 currency code (max 3 characters). */
357
+ currency: string;
358
+ /** Invoice status: `draft`, `open`, `paid`, `void`, `uncollectible`. */
359
+ status: string;
360
+ /** Reason the invoice was created (e.g. `subscription_create`, `subscription_cycle`). */
361
+ billingReason?: string;
362
+ /** ISO 8601 timestamp of when the invoice was paid. */
363
+ paidAt?: string;
364
+ /** ISO 8601 timestamp of creation. */
365
+ createdAt?: string;
366
+ }
367
+ /** Filter parameters for listing invoices. */
368
+ export interface ListInvoicesParams extends ListParams {
369
+ /** Filter by customer ID. */
370
+ customerId?: string;
371
+ /** Filter by subscription ID. */
372
+ subscriptionId?: string;
373
+ /** Filter by invoice status. */
374
+ status?: string;
375
+ }
376
+ /**
377
+ * A verified webhook event received from Revstack Cloud.
378
+ * Returned by {@link WebhooksClient.constructEvent} after signature verification.
379
+ */
380
+ export interface WebhookEvent {
381
+ /** Unique event identifier. */
382
+ id: string;
383
+ /** Event type (e.g. `subscription.created`, `invoice.paid`). */
384
+ type: string;
385
+ /** Event payload containing the relevant resource data. */
386
+ data: Record<string, unknown>;
387
+ /** ISO 8601 timestamp of when the event occurred. */
388
+ createdAt: string;
389
+ }
390
+ /** Parameters for creating a new plan via the Admin API. */
391
+ export interface CreatePlanParams {
392
+ /** Human-readable plan name. */
393
+ name: string;
394
+ /** URL-safe unique slug. Used as the idempotency key for upserts. */
395
+ slug: string;
396
+ /** Optional description for display in pricing pages. */
397
+ description?: string;
398
+ /** Plan status. Defaults to `draft`. */
399
+ status?: string;
400
+ /** Plan type. Defaults to `paid`. */
401
+ type?: string;
402
+ /** Arbitrary metadata. */
403
+ metadata?: Record<string, unknown>;
404
+ /** Whether this is the default plan. */
405
+ isDefault?: boolean;
406
+ /** Whether this plan is publicly visible. */
407
+ isPublic?: boolean;
408
+ /** Prices to create alongside the plan. */
409
+ prices?: UpsertPriceInput[];
410
+ /** Entitlement allocations to create alongside the plan. */
411
+ entitlements?: UpsertPlanEntitlementInput[];
412
+ }
413
+ /** Parameters for partially updating an existing plan. */
414
+ export interface UpdatePlanParams {
415
+ /** New plan name. */
416
+ name?: string;
417
+ /** New description. */
418
+ description?: string;
419
+ /** New status. */
420
+ status?: string;
421
+ /** New type. */
422
+ type?: string;
423
+ /** Metadata to merge. */
424
+ metadata?: Record<string, unknown>;
425
+ /** Whether this is the default plan. */
426
+ isDefault?: boolean;
427
+ /** Whether this plan is publicly visible. */
428
+ isPublic?: boolean;
429
+ }
430
+ /**
431
+ * Parameters for upserting a plan (create or update by `slug`).
432
+ * Idempotent — the `slug` is used as the natural key.
433
+ * This is the primary method used by the CLI for Billing as Code.
434
+ */
435
+ export interface UpsertPlanParams {
436
+ /** URL-safe unique slug. Acts as the natural/idempotency key. */
437
+ slug: string;
438
+ /** Human-readable plan name. */
439
+ name: string;
440
+ /** Optional plan description. */
441
+ description?: string;
442
+ /** Plan status. */
443
+ status?: string;
444
+ /** Plan type. */
445
+ type?: string;
446
+ /** Arbitrary metadata. */
447
+ metadata?: Record<string, unknown>;
448
+ /** Whether this is the default plan. */
449
+ isDefault?: boolean;
450
+ /** Whether this plan is publicly visible. */
451
+ isPublic?: boolean;
452
+ /** Prices to sync. Replaces existing prices. */
453
+ prices?: UpsertPriceInput[];
454
+ /** Entitlement allocations to sync. Replaces existing allocations. */
455
+ entitlements?: UpsertPlanEntitlementInput[];
456
+ }
457
+ /** Input for declaring a price within a plan upsert. */
458
+ export interface UpsertPriceInput {
459
+ /** Price amount. */
460
+ amount: number;
461
+ /** ISO 4217 currency code. Defaults to `USD`. */
462
+ currency?: string;
463
+ /** Billing interval: `month`, `year`, `week`, `day`. */
464
+ billingInterval: string;
465
+ /** Number of trial days. Defaults to `0`. */
466
+ trialPeriodDays?: number;
467
+ /** Overage pricing configuration. */
468
+ overageConfig?: Record<string, unknown>;
469
+ }
470
+ /** Input for declaring an entitlement allocation within a plan upsert. */
471
+ export interface UpsertPlanEntitlementInput {
472
+ /** Slug of the entitlement to allocate. */
473
+ entitlementSlug: string;
474
+ /** Numeric usage limit. */
475
+ valueLimit?: number;
476
+ /** Boolean value (for boolean entitlements). */
477
+ valueBool?: boolean;
478
+ /** Text value (for text entitlements). */
479
+ valueText?: string;
480
+ /** JSON configuration value. */
481
+ valueConfig?: Record<string, unknown>;
482
+ /** Whether this is a hard limit. Defaults to `true`. */
483
+ isHardLimit?: boolean;
484
+ /** Reset period. Defaults to `monthly`. */
485
+ resetPeriod?: string;
486
+ }
487
+ /** Parameters for creating a new entitlement definition. */
488
+ export interface CreateEntitlementParams {
489
+ /** Human-readable name. */
490
+ name: string;
491
+ /** URL-safe unique slug (e.g. `api-calls`). */
492
+ slug: string;
493
+ /** Entitlement type: `boolean`, `metered`, `tiered`. */
494
+ type: string;
495
+ /** Unit of measurement. Defaults to `count`. */
496
+ unitType?: string;
497
+ }
498
+ /** Parameters for partially updating an entitlement definition. */
499
+ export interface UpdateEntitlementParams {
500
+ /** New name. */
501
+ name?: string;
502
+ /** New type. */
503
+ type?: string;
504
+ /** New unit type. */
505
+ unitType?: string;
506
+ }
507
+ /**
508
+ * Parameters for upserting an entitlement (create or update by `slug`).
509
+ * Idempotent — used by the CLI for Billing as Code.
510
+ */
511
+ export interface UpsertEntitlementParams {
512
+ /** URL-safe unique slug. Acts as the natural/idempotency key. */
513
+ slug: string;
514
+ /** Human-readable name. */
515
+ name: string;
516
+ /** Entitlement type. */
517
+ type: string;
518
+ /** Unit of measurement. */
519
+ unitType?: string;
520
+ }
521
+ /** Represents a payment provider integration (e.g. Stripe, Paddle). */
522
+ export interface Integration {
523
+ /** Unique identifier with `int_` prefix. */
524
+ id: string;
525
+ /** Environment this integration belongs to. */
526
+ environmentId: string;
527
+ /** Payment provider name (e.g. `stripe`, `paddle`). */
528
+ provider: string;
529
+ /** Encrypted provider credentials (API keys, tokens). */
530
+ credentials: Record<string, unknown>;
531
+ /** Secret used to verify incoming webhooks from the provider. */
532
+ webhookSecret?: string;
533
+ /** Whether this integration is currently active. */
534
+ isActive: boolean;
535
+ /** ISO 8601 timestamp of the last received webhook event. */
536
+ lastEventAt?: string;
537
+ /** Status of the last processed event (`ok`, `error`). */
538
+ lastEventStatus?: string;
539
+ /** Total monetary volume processed through this integration. */
540
+ totalVolume?: number;
541
+ /** Total number of events processed. */
542
+ totalEvents?: number;
543
+ /** ISO 8601 timestamp of creation. */
544
+ createdAt?: string;
545
+ }
546
+ /** Parameters for creating a new payment integration. */
547
+ export interface CreateIntegrationParams {
548
+ /** Payment provider name. */
549
+ provider: string;
550
+ /** Provider credentials (API keys, tokens). */
551
+ credentials: Record<string, unknown>;
552
+ /** Webhook signing secret. */
553
+ webhookSecret?: string;
554
+ }
555
+ /** Parameters for updating an existing integration. */
556
+ export interface UpdateIntegrationParams {
557
+ /** Updated credentials. */
558
+ credentials?: Record<string, unknown>;
559
+ /** Updated webhook secret. */
560
+ webhookSecret?: string;
561
+ /** Enable or disable the integration. */
562
+ isActive?: boolean;
563
+ }
564
+ /** A webhook event received from an external payment provider. */
565
+ export interface ProviderEvent {
566
+ /** Unique identifier with `evt_` prefix. */
567
+ id: string;
568
+ /** The integration that received this event. */
569
+ integrationId: string;
570
+ /** External event ID from the provider. */
571
+ externalId?: string;
572
+ /** Event type (e.g. `invoice.paid`, `customer.subscription.updated`). */
573
+ type: string;
574
+ /** Processing status: `ok`, `error`, `skipped`. */
575
+ status: string;
576
+ /** Raw event payload from the provider. */
577
+ payload?: Record<string, unknown>;
578
+ /** ISO 8601 timestamp of when the event was received. */
579
+ createdAt?: string;
580
+ }
581
+ /** Aggregated hourly metrics for an integration. */
582
+ export interface IntegrationMetric {
583
+ /** Auto-incrementing row ID. */
584
+ id: number;
585
+ /** The integration this metric belongs to. */
586
+ integrationId: string;
587
+ /** Start of the hour bucket (ISO 8601). */
588
+ hourBucket: string;
589
+ /** Total monetary volume processed in this hour. */
590
+ volume: number;
591
+ /** Total number of events processed in this hour. */
592
+ eventCount: number;
593
+ }
594
+ /** Filter parameters for listing integrations. */
595
+ export interface ListIntegrationsParams extends ListParams {
596
+ /** Filter by provider name. */
597
+ provider?: string;
598
+ /** Filter by active status. */
599
+ isActive?: boolean;
600
+ }
601
+ /** Filter parameters for listing provider events. */
602
+ export interface ListProviderEventsParams extends ListParams {
603
+ /** Filter by event type. */
604
+ type?: string;
605
+ /** Filter by processing status. */
606
+ status?: string;
607
+ }
608
+ /** Filter parameters for listing hourly metrics. */
609
+ export interface ListMetricsParams extends ListParams {
610
+ /** ISO 8601 start date for the time range. */
611
+ from?: string;
612
+ /** ISO 8601 end date for the time range. */
613
+ to?: string;
614
+ }
615
+ /** Represents a deployment environment (e.g. production, staging) with API keys and auth config. */
616
+ export interface Environment {
617
+ /** Unique identifier with `env_` prefix. */
618
+ id: string;
619
+ /** Project this environment belongs to. */
620
+ projectId: string;
621
+ /** Environment name (e.g. `production`, `staging`). */
622
+ name: string;
623
+ /** Public API key (safe to expose in client-side code). */
624
+ apiKeyPublic: string;
625
+ /** Secret API key (server-side only — never expose to clients). */
626
+ apiKeySecret: string;
627
+ /** Auth provider: `supabase`, `firebase`, `auth0`, `custom`. */
628
+ authProvider?: string;
629
+ /** JWT signing algorithm (e.g. `RS256`, `HS256`). */
630
+ authAlgorithm?: string;
631
+ /** JWT issuer (`iss` claim). */
632
+ authIssuer?: string;
633
+ /** JWT audience (`aud` claim). */
634
+ authAudience?: string;
635
+ /** JWT signing secret (for HMAC algorithms). */
636
+ authSecret?: string;
637
+ /** JWKS endpoint URI (for RSA/ECDSA algorithms). */
638
+ authJwksUri?: string;
639
+ /** ISO 8601 timestamp of creation. */
640
+ createdAt?: string;
641
+ }
642
+ /** Parameters for creating a new environment. */
643
+ export interface CreateEnvironmentParams {
644
+ /** Environment name. */
645
+ name: string;
646
+ /** Auth provider identifier. */
647
+ authProvider?: string;
648
+ /** JWT signing algorithm. */
649
+ authAlgorithm?: string;
650
+ /** JWT issuer. */
651
+ authIssuer?: string;
652
+ /** JWT audience. */
653
+ authAudience?: string;
654
+ /** JWT secret (HMAC). */
655
+ authSecret?: string;
656
+ /** JWKS endpoint URI (RSA/ECDSA). */
657
+ authJwksUri?: string;
658
+ }
659
+ /** Parameters for updating an existing environment. */
660
+ export interface UpdateEnvironmentParams {
661
+ /** New environment name. */
662
+ name?: string;
663
+ /** Updated auth provider. */
664
+ authProvider?: string;
665
+ /** Updated JWT algorithm. */
666
+ authAlgorithm?: string;
667
+ /** Updated JWT issuer. */
668
+ authIssuer?: string;
669
+ /** Updated JWT audience. */
670
+ authAudience?: string;
671
+ /** Updated JWT secret. */
672
+ authSecret?: string;
673
+ /** Updated JWKS URI. */
674
+ authJwksUri?: string;
675
+ }
676
+ /**
677
+ * The desired state object sent by the CLI's `npx revstack push` command.
678
+ * Contains the full billing configuration defined in `revstack.config.ts`.
679
+ */
680
+ export interface SyncConfig {
681
+ /** Plans to synchronize (upserted by slug). */
682
+ plans: UpsertPlanParams[];
683
+ /** Entitlements to synchronize (upserted by slug). */
684
+ entitlements: UpsertEntitlementParams[];
685
+ }
686
+ /**
687
+ * Preview of what changes would be applied by a `sync()` call.
688
+ * Returned by `admin.system.preview()` without applying any mutations.
689
+ */
690
+ export interface SyncPreview {
691
+ /** List of changes that would be applied. */
692
+ changes: SyncChange[];
693
+ /** Whether any of the changes are breaking (e.g. removing active entitlements). */
694
+ hasBreakingChanges: boolean;
695
+ }
696
+ /** Describes a single change within a sync operation. */
697
+ export interface SyncChange {
698
+ /** The type of resource being changed. */
699
+ resource: "plan" | "entitlement" | "price" | "plan_entitlement" | "integration";
700
+ /** The action to be performed. */
701
+ action: "create" | "update" | "delete" | "noop";
702
+ /** The slug (natural key) of the resource. */
703
+ slug: string;
704
+ /** Field-level diff showing what changed (`from` → `to`). */
705
+ diff?: Record<string, {
706
+ from: unknown;
707
+ to: unknown;
708
+ }>;
709
+ }
710
+ /**
711
+ * Result of a successful `sync()` call.
712
+ * Contains the list of changes that were applied in a single ACID transaction.
713
+ */
714
+ export interface SyncResult {
715
+ /** Changes that were applied. */
716
+ applied: SyncChange[];
717
+ /** ISO 8601 timestamp of when the sync was executed. */
718
+ timestamp: string;
719
+ }
720
+ //# sourceMappingURL=types.d.ts.map