@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,53 @@
1
+ import { BaseClient } from "@/modules/base";
2
+ import { SyncConfig, SyncResult, SyncPreview } from "@/types";
3
+ /**
4
+ * Admin client for the Billing as Code orchestrator.
5
+ * Provides atomic sync operations used by the CLI (`npx revstack push`) to
6
+ * apply the full desired state from `revstack.config.ts` in a single ACID
7
+ * Postgres transaction.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const config: SyncConfig = {
12
+ * plans: [
13
+ * { slug: "free", name: "Free", type: "free", status: "active" },
14
+ * { slug: "pro", name: "Pro", prices: [{ amount: 4900, billingInterval: "month" }] },
15
+ * ],
16
+ * entitlements: [
17
+ * { slug: "api-calls", name: "API Calls", type: "metered", unitType: "count" },
18
+ * ],
19
+ * };
20
+ *
21
+ * // Preview changes before applying
22
+ * const preview = await revstack.admin.system.preview(config);
23
+ * console.log(`${preview.changes.length} changes, breaking: ${preview.hasBreakingChanges}`);
24
+ *
25
+ * // Apply atomically
26
+ * const result = await revstack.admin.system.sync(config);
27
+ * console.log(`Applied ${result.applied.length} changes at ${result.timestamp}`);
28
+ * ```
29
+ */
30
+ export declare class AdminSystemClient extends BaseClient {
31
+ /**
32
+ * Apply the full desired billing state in a single ACID transaction.
33
+ * The Revstack Cloud backend computes the diff between the current state
34
+ * and the desired config, then applies all changes atomically.
35
+ *
36
+ * @param config - The complete desired state (plans + entitlements).
37
+ * @returns The list of changes that were applied and the execution timestamp.
38
+ *
39
+ * @throws {SyncConflictError} If the remote state has drifted unexpectedly (HTTP 409).
40
+ */
41
+ sync(config: SyncConfig): Promise<SyncResult>;
42
+ /**
43
+ * Preview the changes that would be applied by a `sync()` call.
44
+ * Returns the computed diff without applying any mutations.
45
+ * The CLI should **always** call this before `sync()` to show the operator
46
+ * what will change.
47
+ *
48
+ * @param config - The complete desired state (plans + entitlements).
49
+ * @returns A preview with the list of changes and whether any are breaking.
50
+ */
51
+ preview(config: SyncConfig): Promise<SyncPreview>;
52
+ }
53
+ //# sourceMappingURL=system.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../../src/modules/admin/system.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC/C;;;;;;;;;OASG;IACG,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAOnD;;;;;;;;OAQG;IACG,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;CAMxD"}
@@ -0,0 +1,61 @@
1
+ import { BaseClient } from "@/modules/base";
2
+ /**
3
+ * Admin client for the Billing as Code orchestrator.
4
+ * Provides atomic sync operations used by the CLI (`npx revstack push`) to
5
+ * apply the full desired state from `revstack.config.ts` in a single ACID
6
+ * Postgres transaction.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const config: SyncConfig = {
11
+ * plans: [
12
+ * { slug: "free", name: "Free", type: "free", status: "active" },
13
+ * { slug: "pro", name: "Pro", prices: [{ amount: 4900, billingInterval: "month" }] },
14
+ * ],
15
+ * entitlements: [
16
+ * { slug: "api-calls", name: "API Calls", type: "metered", unitType: "count" },
17
+ * ],
18
+ * };
19
+ *
20
+ * // Preview changes before applying
21
+ * const preview = await revstack.admin.system.preview(config);
22
+ * console.log(`${preview.changes.length} changes, breaking: ${preview.hasBreakingChanges}`);
23
+ *
24
+ * // Apply atomically
25
+ * const result = await revstack.admin.system.sync(config);
26
+ * console.log(`Applied ${result.applied.length} changes at ${result.timestamp}`);
27
+ * ```
28
+ */
29
+ export class AdminSystemClient extends BaseClient {
30
+ /**
31
+ * Apply the full desired billing state in a single ACID transaction.
32
+ * The Revstack Cloud backend computes the diff between the current state
33
+ * and the desired config, then applies all changes atomically.
34
+ *
35
+ * @param config - The complete desired state (plans + entitlements).
36
+ * @returns The list of changes that were applied and the execution timestamp.
37
+ *
38
+ * @throws {SyncConflictError} If the remote state has drifted unexpectedly (HTTP 409).
39
+ */
40
+ async sync(config) {
41
+ return this.request("/admin/system/sync", {
42
+ method: "POST",
43
+ body: JSON.stringify(config),
44
+ });
45
+ }
46
+ /**
47
+ * Preview the changes that would be applied by a `sync()` call.
48
+ * Returns the computed diff without applying any mutations.
49
+ * The CLI should **always** call this before `sync()` to show the operator
50
+ * what will change.
51
+ *
52
+ * @param config - The complete desired state (plans + entitlements).
53
+ * @returns A preview with the list of changes and whether any are breaking.
54
+ */
55
+ async preview(config) {
56
+ return this.request("/admin/system/preview", {
57
+ method: "POST",
58
+ body: JSON.stringify(config),
59
+ });
60
+ }
61
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Base HTTP client shared by all SDK modules.
3
+ * Handles authentication, timeouts, idempotency headers, and typed error responses.
4
+ *
5
+ * @internal Not intended for direct use — all public modules extend this class.
6
+ */
7
+ export declare class BaseClient {
8
+ protected config: {
9
+ secretKey: string;
10
+ baseUrl: string;
11
+ timeout: number;
12
+ };
13
+ constructor(config: {
14
+ secretKey: string;
15
+ baseUrl: string;
16
+ timeout: number;
17
+ });
18
+ /**
19
+ * Builds a URL query string from an object of parameters.
20
+ * Filters out `null` and `undefined` values.
21
+ *
22
+ * @typeParam T - The parameter object type.
23
+ * @param params - Key-value pairs to encode as query parameters.
24
+ * @returns A query string prefixed with `?`, or an empty string if no params.
25
+ */
26
+ protected buildQuery<T extends object>(params?: T): string;
27
+ /**
28
+ * Sends an authenticated HTTP request to the Revstack API.
29
+ *
30
+ * @typeParam T - Expected response body type.
31
+ * @param endpoint - API endpoint path (e.g. `/customers`).
32
+ * @param options - Fetch options with optional `idempotencyKey`.
33
+ * @returns Parsed JSON response body.
34
+ *
35
+ * @throws {RateLimitError} When the API returns HTTP 429.
36
+ * @throws {SyncConflictError} When `admin.system.sync()` detects a conflict (HTTP 409).
37
+ * @throws {RevstackAPIError} For all other non-2xx responses.
38
+ */
39
+ protected request<T>(endpoint: string, options?: RequestInit & {
40
+ idempotencyKey?: string;
41
+ }): Promise<T>;
42
+ }
43
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/modules/base.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,qBAAa,UAAU;IAEnB,SAAS,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;gBAA/D,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAG3E;;;;;;;OAOG;IACH,SAAS,CAAC,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM;IAY1D;;;;;;;;;;;OAWG;cACa,OAAO,CAAC,CAAC,EACvB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,WAAW,GAAG;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAO,GACtD,OAAO,CAAC,CAAC,CAAC;CAsDd"}
@@ -0,0 +1,84 @@
1
+ import { RevstackAPIError, RateLimitError, SyncConflictError, } from "@/errors";
2
+ /**
3
+ * Base HTTP client shared by all SDK modules.
4
+ * Handles authentication, timeouts, idempotency headers, and typed error responses.
5
+ *
6
+ * @internal Not intended for direct use — all public modules extend this class.
7
+ */
8
+ export class BaseClient {
9
+ config;
10
+ constructor(config) {
11
+ this.config = config;
12
+ }
13
+ /**
14
+ * Builds a URL query string from an object of parameters.
15
+ * Filters out `null` and `undefined` values.
16
+ *
17
+ * @typeParam T - The parameter object type.
18
+ * @param params - Key-value pairs to encode as query parameters.
19
+ * @returns A query string prefixed with `?`, or an empty string if no params.
20
+ */
21
+ buildQuery(params) {
22
+ if (!params)
23
+ return "";
24
+ const searchParams = new URLSearchParams();
25
+ for (const [key, value] of Object.entries(params)) {
26
+ if (value !== undefined && value !== null) {
27
+ searchParams.append(key, String(value));
28
+ }
29
+ }
30
+ const query = searchParams.toString();
31
+ return query ? `?${query}` : "";
32
+ }
33
+ /**
34
+ * Sends an authenticated HTTP request to the Revstack API.
35
+ *
36
+ * @typeParam T - Expected response body type.
37
+ * @param endpoint - API endpoint path (e.g. `/customers`).
38
+ * @param options - Fetch options with optional `idempotencyKey`.
39
+ * @returns Parsed JSON response body.
40
+ *
41
+ * @throws {RateLimitError} When the API returns HTTP 429.
42
+ * @throws {SyncConflictError} When `admin.system.sync()` detects a conflict (HTTP 409).
43
+ * @throws {RevstackAPIError} For all other non-2xx responses.
44
+ */
45
+ async request(endpoint, options = {}) {
46
+ const controller = new AbortController();
47
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
48
+ const headers = {
49
+ Authorization: `Bearer ${this.config.secretKey}`,
50
+ "Content-Type": "application/json",
51
+ ...options.headers,
52
+ };
53
+ if (options.idempotencyKey) {
54
+ headers["Idempotency-Key"] = options.idempotencyKey;
55
+ }
56
+ try {
57
+ const response = await fetch(`${this.config.baseUrl}${endpoint}`, {
58
+ ...options,
59
+ headers,
60
+ signal: controller.signal,
61
+ });
62
+ if (!response.ok) {
63
+ const errorData = (await response
64
+ .json()
65
+ .catch(() => ({})));
66
+ const message = errorData.message || `Revstack API Error: ${response.status}`;
67
+ const requestId = errorData.requestId;
68
+ if (response.status === 429) {
69
+ const retryAfter = errorData.retryAfter ??
70
+ parseInt(response.headers.get("Retry-After") || "60", 10);
71
+ throw new RateLimitError(message, retryAfter, requestId);
72
+ }
73
+ if (response.status === 409 && errorData.conflicts) {
74
+ throw new SyncConflictError(message, errorData.conflicts, requestId);
75
+ }
76
+ throw new RevstackAPIError(message, response.status, errorData.code || "UNKNOWN_ERROR", requestId);
77
+ }
78
+ return (await response.json());
79
+ }
80
+ finally {
81
+ clearTimeout(timeoutId);
82
+ }
83
+ }
84
+ }
@@ -0,0 +1,56 @@
1
+ import { BaseClient } from "@/modules/base";
2
+ import { Customer, IdentifyCustomerParams, UpdateCustomerParams, ListParams, PaginatedResponse } from "@/types";
3
+ /**
4
+ * Client for managing end-user (customer) records.
5
+ * Provides full CRUD operations on the `app_users` table.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const customer = await revstack.customers.identify({
10
+ * customerId: "user-123",
11
+ * email: "john@acme.com",
12
+ * });
13
+ * ```
14
+ */
15
+ export declare class CustomersClient extends BaseClient {
16
+ /**
17
+ * Identify (upsert) a customer. Creates the customer if not found,
18
+ * or updates it if a record with the same `customerId` already exists.
19
+ *
20
+ * @param params - Customer identification parameters.
21
+ * @returns The created or updated customer record.
22
+ */
23
+ identify(params: IdentifyCustomerParams): Promise<Customer>;
24
+ /**
25
+ * Retrieve a customer by ID.
26
+ *
27
+ * @param customerId - The customer's unique identifier.
28
+ * @returns The customer record.
29
+ */
30
+ get(customerId: string): Promise<Customer>;
31
+ /**
32
+ * List customers with optional pagination.
33
+ *
34
+ * @param params - Pagination parameters (limit, offset).
35
+ * @returns A paginated list of customer records.
36
+ */
37
+ list(params?: ListParams): Promise<PaginatedResponse<Customer>>;
38
+ /**
39
+ * Update an existing customer's profile.
40
+ *
41
+ * @param customerId - The customer's unique identifier.
42
+ * @param params - Fields to update (email, metadata).
43
+ * @returns The updated customer record.
44
+ */
45
+ update(customerId: string, params: UpdateCustomerParams): Promise<Customer>;
46
+ /**
47
+ * Delete a customer and all associated data.
48
+ *
49
+ * @param customerId - The customer's unique identifier.
50
+ * @returns Confirmation of deletion.
51
+ */
52
+ delete(customerId: string): Promise<{
53
+ success: boolean;
54
+ }>;
55
+ }
56
+ //# sourceMappingURL=customers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customers.d.ts","sourceRoot":"","sources":["../../src/modules/customers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,QAAQ,EACR,sBAAsB,EACtB,oBAAoB,EACpB,UAAU,EACV,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;GAWG;AACH,qBAAa,eAAgB,SAAQ,UAAU;IAC7C;;;;;;OAMG;IACG,QAAQ,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAOjE;;;;;OAKG;IACG,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMhD;;;;;OAKG;IACG,IAAI,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAOrE;;;;;;OAMG;IACG,MAAM,CACV,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,QAAQ,CAAC;IAOpB;;;;;OAKG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CAKhE"}
@@ -0,0 +1,72 @@
1
+ import { BaseClient } from "@/modules/base";
2
+ /**
3
+ * Client for managing end-user (customer) records.
4
+ * Provides full CRUD operations on the `app_users` table.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const customer = await revstack.customers.identify({
9
+ * customerId: "user-123",
10
+ * email: "john@acme.com",
11
+ * });
12
+ * ```
13
+ */
14
+ export class CustomersClient extends BaseClient {
15
+ /**
16
+ * Identify (upsert) a customer. Creates the customer if not found,
17
+ * or updates it if a record with the same `customerId` already exists.
18
+ *
19
+ * @param params - Customer identification parameters.
20
+ * @returns The created or updated customer record.
21
+ */
22
+ async identify(params) {
23
+ return this.request("/customers", {
24
+ method: "POST",
25
+ body: JSON.stringify(params),
26
+ });
27
+ }
28
+ /**
29
+ * Retrieve a customer by ID.
30
+ *
31
+ * @param customerId - The customer's unique identifier.
32
+ * @returns The customer record.
33
+ */
34
+ async get(customerId) {
35
+ return this.request(`/customers/${customerId}`, {
36
+ method: "GET",
37
+ });
38
+ }
39
+ /**
40
+ * List customers with optional pagination.
41
+ *
42
+ * @param params - Pagination parameters (limit, offset).
43
+ * @returns A paginated list of customer records.
44
+ */
45
+ async list(params) {
46
+ return this.request(`/customers${this.buildQuery(params)}`, { method: "GET" });
47
+ }
48
+ /**
49
+ * Update an existing customer's profile.
50
+ *
51
+ * @param customerId - The customer's unique identifier.
52
+ * @param params - Fields to update (email, metadata).
53
+ * @returns The updated customer record.
54
+ */
55
+ async update(customerId, params) {
56
+ return this.request(`/customers/${customerId}`, {
57
+ method: "PATCH",
58
+ body: JSON.stringify(params),
59
+ });
60
+ }
61
+ /**
62
+ * Delete a customer and all associated data.
63
+ *
64
+ * @param customerId - The customer's unique identifier.
65
+ * @returns Confirmation of deletion.
66
+ */
67
+ async delete(customerId) {
68
+ return this.request(`/customers/${customerId}`, {
69
+ method: "DELETE",
70
+ });
71
+ }
72
+ }
@@ -0,0 +1,49 @@
1
+ import { BaseClient } from "@/modules/base";
2
+ import { Entitlement, EntitlementCheckOptions, EntitlementCheckResult } from "@/types";
3
+ /**
4
+ * Client for checking and querying feature entitlements.
5
+ * The `check()` method is the core primitive of the SDK — it determines whether
6
+ * a customer is allowed to use a specific feature based on their plan.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const { allowed, reason } = await revstack.entitlements.check(
11
+ * "usr_abc",
12
+ * "api-calls",
13
+ * { amount: 10 }
14
+ * );
15
+ *
16
+ * if (!allowed) {
17
+ * throw new Error(`Access denied: ${reason}`);
18
+ * }
19
+ * ```
20
+ */
21
+ export declare class EntitlementsClient extends BaseClient {
22
+ /**
23
+ * Check whether a customer has access to a specific feature.
24
+ * This is the most critical method in the SDK — it evaluates the customer's
25
+ * plan, metered usage, and custom entitlement overrides.
26
+ *
27
+ * @param customerId - The customer to check.
28
+ * @param featureId - The entitlement slug or ID.
29
+ * @param options - Optional check parameters (e.g. requested amount).
30
+ * @returns The check result with `allowed`, `reason`, and `remainingBalance`.
31
+ */
32
+ check(customerId: string, featureId: string, options?: EntitlementCheckOptions): Promise<EntitlementCheckResult>;
33
+ /**
34
+ * List all active entitlements for a customer, including limits from
35
+ * their plan and any custom overrides.
36
+ *
37
+ * @param customerId - The customer whose entitlements to list.
38
+ * @returns Array of entitlement definitions the customer has access to.
39
+ */
40
+ list(customerId: string): Promise<Entitlement[]>;
41
+ /**
42
+ * Retrieve a single entitlement definition by ID.
43
+ *
44
+ * @param entitlementId - The entitlement's unique identifier.
45
+ * @returns The entitlement definition.
46
+ */
47
+ get(entitlementId: string): Promise<Entitlement>;
48
+ }
49
+ //# sourceMappingURL=entitlements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entitlements.d.ts","sourceRoot":"","sources":["../../src/modules/entitlements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;IAChD;;;;;;;;;OASG;IACG,KAAK,CACT,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,sBAAsB,CAAC;IAWlC;;;;;;OAMG;IACG,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAMtD;;;;;OAKG;IACG,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAKvD"}
@@ -0,0 +1,64 @@
1
+ import { BaseClient } from "@/modules/base";
2
+ /**
3
+ * Client for checking and querying feature entitlements.
4
+ * The `check()` method is the core primitive of the SDK — it determines whether
5
+ * a customer is allowed to use a specific feature based on their plan.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const { allowed, reason } = await revstack.entitlements.check(
10
+ * "usr_abc",
11
+ * "api-calls",
12
+ * { amount: 10 }
13
+ * );
14
+ *
15
+ * if (!allowed) {
16
+ * throw new Error(`Access denied: ${reason}`);
17
+ * }
18
+ * ```
19
+ */
20
+ export class EntitlementsClient extends BaseClient {
21
+ /**
22
+ * Check whether a customer has access to a specific feature.
23
+ * This is the most critical method in the SDK — it evaluates the customer's
24
+ * plan, metered usage, and custom entitlement overrides.
25
+ *
26
+ * @param customerId - The customer to check.
27
+ * @param featureId - The entitlement slug or ID.
28
+ * @param options - Optional check parameters (e.g. requested amount).
29
+ * @returns The check result with `allowed`, `reason`, and `remainingBalance`.
30
+ */
31
+ async check(customerId, featureId, options) {
32
+ return this.request("/entitlements/check", {
33
+ method: "POST",
34
+ body: JSON.stringify({
35
+ customerId,
36
+ featureId,
37
+ requestedAmount: options?.amount || 1,
38
+ }),
39
+ });
40
+ }
41
+ /**
42
+ * List all active entitlements for a customer, including limits from
43
+ * their plan and any custom overrides.
44
+ *
45
+ * @param customerId - The customer whose entitlements to list.
46
+ * @returns Array of entitlement definitions the customer has access to.
47
+ */
48
+ async list(customerId) {
49
+ return this.request(`/entitlements/customer/${customerId}`, {
50
+ method: "GET",
51
+ });
52
+ }
53
+ /**
54
+ * Retrieve a single entitlement definition by ID.
55
+ *
56
+ * @param entitlementId - The entitlement's unique identifier.
57
+ * @returns The entitlement definition.
58
+ */
59
+ async get(entitlementId) {
60
+ return this.request(`/entitlements/${entitlementId}`, {
61
+ method: "GET",
62
+ });
63
+ }
64
+ }
@@ -0,0 +1,33 @@
1
+ import { BaseClient } from "@/modules/base";
2
+ import { Invoice, ListInvoicesParams, PaginatedResponse } from "@/types";
3
+ /**
4
+ * Read-only client for querying billing invoices.
5
+ * Used to display billing history to end users. Invoice creation is handled
6
+ * automatically by the payment pipeline and is not accessible from the SDK.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // List invoices for a customer's billing history page
11
+ * const { data: invoices } = await revstack.invoices.list({
12
+ * customerId: "usr_abc",
13
+ * status: "paid",
14
+ * });
15
+ * ```
16
+ */
17
+ export declare class InvoicesClient extends BaseClient {
18
+ /**
19
+ * List invoices with optional filters.
20
+ *
21
+ * @param params - Filter and pagination parameters.
22
+ * @returns A paginated list of invoices.
23
+ */
24
+ list(params?: ListInvoicesParams): Promise<PaginatedResponse<Invoice>>;
25
+ /**
26
+ * Retrieve a single invoice by ID.
27
+ *
28
+ * @param invoiceId - The invoice's unique identifier.
29
+ * @returns The invoice record.
30
+ */
31
+ get(invoiceId: string): Promise<Invoice>;
32
+ }
33
+ //# sourceMappingURL=invoices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoices.d.ts","sourceRoot":"","sources":["../../src/modules/invoices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEzE;;;;;;;;;;;;;GAaG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAC5C;;;;;OAKG;IACG,IAAI,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAO5E;;;;;OAKG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAK/C"}
@@ -0,0 +1,37 @@
1
+ import { BaseClient } from "@/modules/base";
2
+ /**
3
+ * Read-only client for querying billing invoices.
4
+ * Used to display billing history to end users. Invoice creation is handled
5
+ * automatically by the payment pipeline and is not accessible from the SDK.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // List invoices for a customer's billing history page
10
+ * const { data: invoices } = await revstack.invoices.list({
11
+ * customerId: "usr_abc",
12
+ * status: "paid",
13
+ * });
14
+ * ```
15
+ */
16
+ export class InvoicesClient extends BaseClient {
17
+ /**
18
+ * List invoices with optional filters.
19
+ *
20
+ * @param params - Filter and pagination parameters.
21
+ * @returns A paginated list of invoices.
22
+ */
23
+ async list(params) {
24
+ return this.request(`/invoices${this.buildQuery(params)}`, { method: "GET" });
25
+ }
26
+ /**
27
+ * Retrieve a single invoice by ID.
28
+ *
29
+ * @param invoiceId - The invoice's unique identifier.
30
+ * @returns The invoice record.
31
+ */
32
+ async get(invoiceId) {
33
+ return this.request(`/invoices/${invoiceId}`, {
34
+ method: "GET",
35
+ });
36
+ }
37
+ }
@@ -0,0 +1,35 @@
1
+ import { BaseClient } from "@/modules/base";
2
+ import { Plan, ListPlansParams, PaginatedResponse } from "@/types";
3
+ /**
4
+ * Read-only client for querying billing plans.
5
+ * Used by the merchant's frontend to render pricing pages and plan selectors.
6
+ * Plan mutations are handled via `revstack.admin.plans`.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Fetch all public plans for the pricing page
11
+ * const { data: plans } = await revstack.plans.list({ status: "active" });
12
+ *
13
+ * // Get a specific plan with prices and entitlements
14
+ * const proPlan = await revstack.plans.get("plan_pro");
15
+ * console.log(proPlan.prices); // billing intervals
16
+ * console.log(proPlan.entitlements); // feature allocations
17
+ * ```
18
+ */
19
+ export declare class PlansClient extends BaseClient {
20
+ /**
21
+ * List plans with optional filters.
22
+ *
23
+ * @param params - Filter and pagination parameters.
24
+ * @returns A paginated list of plans.
25
+ */
26
+ list(params?: ListPlansParams): Promise<PaginatedResponse<Plan>>;
27
+ /**
28
+ * Retrieve a single plan by ID, including its nested prices and entitlements.
29
+ *
30
+ * @param planId - The plan's unique identifier.
31
+ * @returns The plan with populated `prices[]` and `entitlements[]`.
32
+ */
33
+ get(planId: string): Promise<Plan>;
34
+ }
35
+ //# sourceMappingURL=plans.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../../src/modules/plans.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEnE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,WAAY,SAAQ,UAAU;IACzC;;;;;OAKG;IACG,IAAI,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAOtE;;;;;OAKG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAKzC"}
@@ -0,0 +1,39 @@
1
+ import { BaseClient } from "@/modules/base";
2
+ /**
3
+ * Read-only client for querying billing plans.
4
+ * Used by the merchant's frontend to render pricing pages and plan selectors.
5
+ * Plan mutations are handled via `revstack.admin.plans`.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Fetch all public plans for the pricing page
10
+ * const { data: plans } = await revstack.plans.list({ status: "active" });
11
+ *
12
+ * // Get a specific plan with prices and entitlements
13
+ * const proPlan = await revstack.plans.get("plan_pro");
14
+ * console.log(proPlan.prices); // billing intervals
15
+ * console.log(proPlan.entitlements); // feature allocations
16
+ * ```
17
+ */
18
+ export class PlansClient extends BaseClient {
19
+ /**
20
+ * List plans with optional filters.
21
+ *
22
+ * @param params - Filter and pagination parameters.
23
+ * @returns A paginated list of plans.
24
+ */
25
+ async list(params) {
26
+ return this.request(`/plans${this.buildQuery(params)}`, { method: "GET" });
27
+ }
28
+ /**
29
+ * Retrieve a single plan by ID, including its nested prices and entitlements.
30
+ *
31
+ * @param planId - The plan's unique identifier.
32
+ * @returns The plan with populated `prices[]` and `entitlements[]`.
33
+ */
34
+ async get(planId) {
35
+ return this.request(`/plans/${planId}`, {
36
+ method: "GET",
37
+ });
38
+ }
39
+ }