@buildspacestudio/sdk 0.2.2 → 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.
Files changed (106) hide show
  1. package/README.md +126 -0
  2. package/dist/auth/index.cjs +259 -0
  3. package/dist/auth/index.cjs.map +1 -0
  4. package/dist/auth/index.d.cts +3 -0
  5. package/dist/auth/index.d.ts +3 -5
  6. package/dist/auth/index.js +255 -2
  7. package/dist/auth/index.js.map +1 -1
  8. package/dist/billing/index.cjs +226 -0
  9. package/dist/billing/index.cjs.map +1 -0
  10. package/dist/billing/index.d.cts +60 -0
  11. package/dist/billing/index.d.ts +60 -0
  12. package/dist/billing/index.js +222 -0
  13. package/dist/billing/index.js.map +1 -0
  14. package/dist/client/index.cjs +558 -0
  15. package/dist/client/index.cjs.map +1 -0
  16. package/dist/client/index.d.cts +89 -0
  17. package/dist/client/index.d.ts +12 -7
  18. package/dist/client/index.js +546 -105
  19. package/dist/client/index.js.map +1 -1
  20. package/dist/client-BYUWUiGZ.d.cts +143 -0
  21. package/dist/{auth/client.d.ts → client-ByNR5EZz.d.ts} +7 -5
  22. package/dist/client-D0vypxWb.d.cts +58 -0
  23. package/dist/{auth/client.js → client-D7bqvGJv.d.cts} +27 -30
  24. package/dist/{events/client.d.ts → client-DbGRRMt7.d.ts} +5 -3
  25. package/dist/client-d7kX5WfR.d.ts +143 -0
  26. package/dist/events/index.cjs +131 -0
  27. package/dist/events/index.cjs.map +1 -0
  28. package/dist/events/{server.d.ts → index.d.cts} +7 -4
  29. package/dist/events/index.d.ts +59 -4
  30. package/dist/events/index.js +127 -2
  31. package/dist/events/index.js.map +1 -1
  32. package/dist/http-D2gXpNpr.d.cts +100 -0
  33. package/dist/http-D2gXpNpr.d.ts +100 -0
  34. package/dist/index.cjs +1029 -0
  35. package/dist/index.cjs.map +1 -0
  36. package/dist/index.d.cts +92 -0
  37. package/dist/index.d.ts +21 -15
  38. package/dist/index.js +1010 -106
  39. package/dist/index.js.map +1 -1
  40. package/dist/next/index.cjs +183 -0
  41. package/dist/next/index.cjs.map +1 -0
  42. package/dist/next/index.d.cts +164 -0
  43. package/dist/next/index.d.ts +164 -0
  44. package/dist/next/index.js +172 -0
  45. package/dist/next/index.js.map +1 -0
  46. package/dist/notifications/index.cjs +56 -0
  47. package/dist/notifications/index.cjs.map +1 -0
  48. package/dist/notifications/{server.d.ts → index.d.cts} +8 -6
  49. package/dist/notifications/index.d.ts +79 -3
  50. package/dist/notifications/index.js +53 -1
  51. package/dist/notifications/index.js.map +1 -1
  52. package/dist/react/index.cjs +120 -0
  53. package/dist/react/index.cjs.map +1 -0
  54. package/dist/react/index.d.cts +567 -0
  55. package/dist/react/index.d.ts +567 -0
  56. package/dist/react/index.js +92 -0
  57. package/dist/react/index.js.map +1 -0
  58. package/dist/server-CoPDzSUP.d.cts +117 -0
  59. package/dist/{auth/server.d.ts → server-Suq3tZZC.d.ts} +8 -6
  60. package/dist/storage/index.cjs +213 -0
  61. package/dist/storage/index.cjs.map +1 -0
  62. package/dist/storage/index.d.cts +195 -0
  63. package/dist/storage/index.d.ts +195 -5
  64. package/dist/storage/index.js +209 -2
  65. package/dist/storage/index.js.map +1 -1
  66. package/package.json +124 -16
  67. package/dist/auth/client.d.ts.map +0 -1
  68. package/dist/auth/client.js.map +0 -1
  69. package/dist/auth/index.d.ts.map +0 -1
  70. package/dist/auth/server.d.ts.map +0 -1
  71. package/dist/auth/server.js +0 -148
  72. package/dist/auth/server.js.map +0 -1
  73. package/dist/client/index.d.ts.map +0 -1
  74. package/dist/config.d.ts +0 -40
  75. package/dist/config.d.ts.map +0 -1
  76. package/dist/config.js +0 -27
  77. package/dist/config.js.map +0 -1
  78. package/dist/errors.d.ts +0 -31
  79. package/dist/errors.d.ts.map +0 -1
  80. package/dist/errors.js +0 -30
  81. package/dist/errors.js.map +0 -1
  82. package/dist/events/client.d.ts.map +0 -1
  83. package/dist/events/client.js +0 -97
  84. package/dist/events/client.js.map +0 -1
  85. package/dist/events/index.d.ts.map +0 -1
  86. package/dist/events/server.d.ts.map +0 -1
  87. package/dist/events/server.js +0 -65
  88. package/dist/events/server.js.map +0 -1
  89. package/dist/http.d.ts +0 -39
  90. package/dist/http.d.ts.map +0 -1
  91. package/dist/http.js +0 -74
  92. package/dist/http.js.map +0 -1
  93. package/dist/index.d.ts.map +0 -1
  94. package/dist/notifications/index.d.ts.map +0 -1
  95. package/dist/notifications/server.d.ts.map +0 -1
  96. package/dist/notifications/server.js +0 -73
  97. package/dist/notifications/server.js.map +0 -1
  98. package/dist/storage/client.d.ts +0 -91
  99. package/dist/storage/client.d.ts.map +0 -1
  100. package/dist/storage/client.js +0 -117
  101. package/dist/storage/client.js.map +0 -1
  102. package/dist/storage/index.d.ts.map +0 -1
  103. package/dist/storage/server.d.ts +0 -104
  104. package/dist/storage/server.d.ts.map +0 -1
  105. package/dist/storage/server.js +0 -104
  106. package/dist/storage/server.js.map +0 -1
@@ -0,0 +1,60 @@
1
+ import { f as BillingStatusResponse, e as BillingProduct, d as BillingPrice, C as CreateServerCheckoutOptions, a as BillingCheckoutResponse, h as CreateServerPortalSessionOptions, c as BillingPortalResponse, g as BillingSubscriptionResponse, b as BillingEntitlementsResponse } from '../client-d7kX5WfR.js';
2
+ export { B as BillingClientNamespace, s as shouldShowTestBanner } from '../client-d7kX5WfR.js';
3
+ import { H as HttpTransport } from '../http-D2gXpNpr.js';
4
+
5
+ declare class BillingServerNamespace {
6
+ private readonly transport;
7
+ constructor(transport: HttpTransport);
8
+ /**
9
+ * Read whether billing is enabled for the app environment tied to this API
10
+ * key, and whether the connected Stripe account is in test or live mode.
11
+ *
12
+ * Render a "Test mode" banner in your app whenever `testMode` is true.
13
+ */
14
+ getStatus(): Promise<BillingStatusResponse>;
15
+ /**
16
+ * List the active billing products configured for the app environment tied to
17
+ * this API key.
18
+ */
19
+ listProducts(): Promise<{
20
+ products: BillingProduct[];
21
+ }>;
22
+ /**
23
+ * List the active billing prices configured for the app environment tied to
24
+ * this API key.
25
+ */
26
+ listPrices(): Promise<{
27
+ prices: BillingPrice[];
28
+ }>;
29
+ /**
30
+ * Create a Stripe Checkout Session on the creator's connected Stripe account.
31
+ *
32
+ * Use `userId` for Buildspace-authenticated users, or `appUserId` when your
33
+ * app uses its own auth system and you want Buildspace to track billing state
34
+ * against an app-defined user id.
35
+ */
36
+ createCheckout(opts: CreateServerCheckoutOptions): Promise<BillingCheckoutResponse>;
37
+ /**
38
+ * Create a Stripe-hosted customer portal session for the specified billing
39
+ * identity.
40
+ */
41
+ createPortalSession(opts: CreateServerPortalSessionOptions): Promise<BillingPortalResponse>;
42
+ /**
43
+ * Read the current subscription state for a Buildspace user or app-defined
44
+ * billing identity.
45
+ */
46
+ getSubscription(opts?: {
47
+ appUserId?: string;
48
+ userId?: string;
49
+ }): Promise<BillingSubscriptionResponse>;
50
+ /**
51
+ * Read the current paid entitlement state for a Buildspace user or app-defined
52
+ * billing identity.
53
+ */
54
+ getEntitlements(opts?: {
55
+ appUserId?: string;
56
+ userId?: string;
57
+ }): Promise<BillingEntitlementsResponse>;
58
+ }
59
+
60
+ export { BillingCheckoutResponse, BillingEntitlementsResponse, BillingPortalResponse, BillingPrice, BillingProduct, BillingServerNamespace, BillingStatusResponse, BillingSubscriptionResponse, CreateServerCheckoutOptions, CreateServerPortalSessionOptions };
@@ -0,0 +1,222 @@
1
+ // src/billing/shared.ts
2
+ function shouldShowTestBanner(status) {
3
+ return status.testMode;
4
+ }
5
+ function billingIdentityQuery(opts) {
6
+ return { app_user_id: opts?.appUserId, user_id: opts?.userId };
7
+ }
8
+ function checkoutRequestBody(opts) {
9
+ return {
10
+ app_user_id: "appUserId" in opts ? opts.appUserId : void 0,
11
+ cancel_url: opts.cancelUrl,
12
+ checkout_request_id: opts.checkoutRequestId,
13
+ lookup_key: opts.lookupKey,
14
+ metadata: opts.metadata,
15
+ price_id: opts.priceId,
16
+ quantity: opts.quantity,
17
+ success_url: opts.successUrl,
18
+ user_id: "userId" in opts ? opts.userId : void 0
19
+ };
20
+ }
21
+ function portalRequestBody(opts) {
22
+ return {
23
+ app_user_id: "appUserId" in opts ? opts.appUserId : void 0,
24
+ return_url: opts.returnUrl,
25
+ user_id: "userId" in opts ? opts.userId : void 0
26
+ };
27
+ }
28
+
29
+ // src/billing/client.ts
30
+ function redirectTo(url) {
31
+ const browser = globalThis;
32
+ if (!browser.window?.location) {
33
+ throw new Error("redirectToCheckout can only be used in a browser environment");
34
+ }
35
+ browser.window.location.href = url;
36
+ }
37
+ var BillingClientNamespace = class {
38
+ transport;
39
+ constructor(transport) {
40
+ this.transport = transport;
41
+ }
42
+ /**
43
+ * Read whether billing is enabled for the app environment tied to this
44
+ * publishable key, and whether the connected Stripe account is in test or
45
+ * live mode.
46
+ *
47
+ * Render a "Test mode" banner in your app whenever `testMode` is true.
48
+ */
49
+ getStatus() {
50
+ return this.transport.request({
51
+ service: "billing",
52
+ path: "/v1/billing/status"
53
+ });
54
+ }
55
+ /**
56
+ * List the active billing products for the app environment tied to this
57
+ * publishable key.
58
+ */
59
+ listProducts() {
60
+ return this.transport.request({
61
+ service: "billing",
62
+ path: "/v1/billing/products"
63
+ });
64
+ }
65
+ /**
66
+ * List the active billing prices for the app environment tied to this
67
+ * publishable key.
68
+ */
69
+ listPrices() {
70
+ return this.transport.request({
71
+ service: "billing",
72
+ path: "/v1/billing/prices"
73
+ });
74
+ }
75
+ /**
76
+ * Create a Checkout Session for the signed-in browser user and redirect to
77
+ * the Stripe-hosted Checkout page.
78
+ *
79
+ * This method depends on a Buildspace session being available through
80
+ * `setSession()` or your app's authenticated request context.
81
+ */
82
+ async redirectToCheckout(opts) {
83
+ const checkout = await this.transport.request({
84
+ service: "billing",
85
+ path: "/v1/billing/checkout",
86
+ method: "POST",
87
+ body: checkoutRequestBody(opts)
88
+ });
89
+ redirectTo(checkout.url);
90
+ }
91
+ /**
92
+ * Open the Stripe-hosted customer portal for the signed-in browser user.
93
+ */
94
+ async redirectToPortal(opts) {
95
+ const portal = await this.transport.request({
96
+ service: "billing",
97
+ path: "/v1/billing/portal",
98
+ method: "POST",
99
+ body: portalRequestBody(opts)
100
+ });
101
+ redirectTo(portal.url);
102
+ }
103
+ /**
104
+ * Discoverable alias for redirectToPortal — opens the Stripe-hosted customer
105
+ * portal so the signed-in user can manage their subscription, payment method,
106
+ * and invoices.
107
+ */
108
+ manageSubscription(opts) {
109
+ return this.redirectToPortal(opts);
110
+ }
111
+ /**
112
+ * Read the current subscription state for the signed-in browser user.
113
+ */
114
+ getSubscription() {
115
+ return this.transport.request({
116
+ service: "billing",
117
+ path: "/v1/billing/subscription"
118
+ });
119
+ }
120
+ /**
121
+ * Read the current paid entitlement state for the signed-in browser user.
122
+ */
123
+ getEntitlements() {
124
+ return this.transport.request({
125
+ service: "billing",
126
+ path: "/v1/billing/entitlements"
127
+ });
128
+ }
129
+ };
130
+
131
+ // src/billing/server.ts
132
+ var BillingServerNamespace = class {
133
+ transport;
134
+ constructor(transport) {
135
+ this.transport = transport;
136
+ }
137
+ /**
138
+ * Read whether billing is enabled for the app environment tied to this API
139
+ * key, and whether the connected Stripe account is in test or live mode.
140
+ *
141
+ * Render a "Test mode" banner in your app whenever `testMode` is true.
142
+ */
143
+ getStatus() {
144
+ return this.transport.request({
145
+ service: "billing",
146
+ path: "/v1/billing/status"
147
+ });
148
+ }
149
+ /**
150
+ * List the active billing products configured for the app environment tied to
151
+ * this API key.
152
+ */
153
+ listProducts() {
154
+ return this.transport.request({
155
+ service: "billing",
156
+ path: "/v1/billing/products"
157
+ });
158
+ }
159
+ /**
160
+ * List the active billing prices configured for the app environment tied to
161
+ * this API key.
162
+ */
163
+ listPrices() {
164
+ return this.transport.request({
165
+ service: "billing",
166
+ path: "/v1/billing/prices"
167
+ });
168
+ }
169
+ /**
170
+ * Create a Stripe Checkout Session on the creator's connected Stripe account.
171
+ *
172
+ * Use `userId` for Buildspace-authenticated users, or `appUserId` when your
173
+ * app uses its own auth system and you want Buildspace to track billing state
174
+ * against an app-defined user id.
175
+ */
176
+ createCheckout(opts) {
177
+ return this.transport.request({
178
+ service: "billing",
179
+ path: "/v1/billing/checkout",
180
+ method: "POST",
181
+ body: checkoutRequestBody(opts)
182
+ });
183
+ }
184
+ /**
185
+ * Create a Stripe-hosted customer portal session for the specified billing
186
+ * identity.
187
+ */
188
+ createPortalSession(opts) {
189
+ return this.transport.request({
190
+ service: "billing",
191
+ path: "/v1/billing/portal",
192
+ method: "POST",
193
+ body: portalRequestBody(opts)
194
+ });
195
+ }
196
+ /**
197
+ * Read the current subscription state for a Buildspace user or app-defined
198
+ * billing identity.
199
+ */
200
+ getSubscription(opts) {
201
+ return this.transport.request({
202
+ service: "billing",
203
+ path: "/v1/billing/subscription",
204
+ query: billingIdentityQuery(opts)
205
+ });
206
+ }
207
+ /**
208
+ * Read the current paid entitlement state for a Buildspace user or app-defined
209
+ * billing identity.
210
+ */
211
+ getEntitlements(opts) {
212
+ return this.transport.request({
213
+ service: "billing",
214
+ path: "/v1/billing/entitlements",
215
+ query: billingIdentityQuery(opts)
216
+ });
217
+ }
218
+ };
219
+
220
+ export { BillingClientNamespace, BillingServerNamespace, shouldShowTestBanner };
221
+ //# sourceMappingURL=index.js.map
222
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/billing/shared.ts","../../src/billing/client.ts","../../src/billing/server.ts"],"names":[],"mappings":";AAoFO,SAAS,qBAAqB,MAAA,EAAwC;AAC3E,EAAA,OAAO,MAAA,CAAO,QAAA;AAChB;AAYO,SAAS,qBAAqB,IAAA,EAAgD;AACnF,EAAA,OAAO,EAAE,WAAA,EAAa,IAAA,EAAM,SAAA,EAAW,OAAA,EAAS,MAAM,MAAA,EAAO;AAC/D;AAEO,SAAS,oBACd,IAAA,EACA;AACA,EAAA,OAAO;AAAA,IACL,WAAA,EAAa,WAAA,IAAe,IAAA,GAAO,IAAA,CAAK,SAAA,GAAY,MAAA;AAAA,IACpD,YAAY,IAAA,CAAK,SAAA;AAAA,IAC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AAO,IAAA,CAAK,UAAU,OAAA,CAA+B;AAAA,MACnD,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM,oBAAA;AAAA,MACN,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM,kBAAkB,IAAI;AAAA,KAC7B,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAAgB,IAAA,EAGyB;AACvC,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAAqC;AAAA,MACzD,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM,0BAAA;AAAA,MACN,KAAA,EAAO,qBAAqB,IAAI;AAAA,KACjC,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAAgB,IAAA,EAGyB;AACvC,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAAqC;AAAA,MACzD,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM,0BAAA;AAAA,MACN,KAAA,EAAO,qBAAqB,IAAI;AAAA,KACjC,CAAA;AAAA,EACH;AACF","file":"index.js","sourcesContent":["export interface BillingProduct {\n active: boolean;\n createdAt: string;\n description: string | null;\n id: string;\n name: string;\n}\n\nexport interface BillingPrice {\n active: boolean;\n amountCents: number | null;\n createdAt: string;\n currency: string;\n id: string;\n interval: string | null;\n lookupKey: string | null;\n productId: string;\n productName: string;\n type: \"one_time\" | \"recurring\" | \"metered\";\n}\n\nexport interface CreateServerCheckoutOptions {\n appUserId?: string;\n cancelUrl: string;\n checkoutRequestId?: string;\n lookupKey?: string;\n metadata?: Record<string, string>;\n priceId?: string;\n quantity?: number;\n successUrl: string;\n userId?: string;\n}\n\nexport interface CreateClientCheckoutOptions {\n cancelUrl: string;\n checkoutRequestId?: string;\n lookupKey?: string;\n metadata?: Record<string, string>;\n priceId?: string;\n quantity?: number;\n successUrl: string;\n}\n\nexport interface BillingCheckoutResponse {\n id?: string;\n stripe_checkout_session_id: string;\n url: string;\n}\n\nexport interface BillingPortalResponse {\n url: string;\n}\n\nexport interface BillingSubscriptionResponse {\n subscription: {\n cancelAtPeriodEnd: boolean;\n currentPeriodEnd: string | null;\n id: string;\n status: string;\n } | null;\n}\n\nexport interface BillingEntitlementsResponse {\n active: boolean;\n subscription: { currentPeriodEnd: string | null; id: string; status: string } | null;\n}\n\nexport type BillingMode = \"test\" | \"live\";\n\nexport type BillingConfigStatus = \"disabled\" | \"setup_required\" | \"active\" | \"paused\";\n\nexport interface BillingStatusResponse {\n enabled: boolean;\n mode: BillingMode | null;\n status: BillingConfigStatus | null;\n testMode: boolean;\n}\n\n/**\n * True when the app environment is wired to a Stripe test-mode account.\n *\n * Use this to render a \"Test mode\" banner in your app — payments aren't real\n * charges, and end-buyers should not be expected to enter real card details.\n */\nexport function shouldShowTestBanner(status: BillingStatusResponse): boolean {\n return status.testMode;\n}\n\nexport interface CreateServerPortalSessionOptions {\n appUserId?: string;\n returnUrl: string;\n userId?: string;\n}\n\nexport interface CreateClientPortalSessionOptions {\n returnUrl: string;\n}\n\nexport function billingIdentityQuery(opts?: { appUserId?: string; userId?: string }) {\n return { app_user_id: opts?.appUserId, user_id: opts?.userId };\n}\n\nexport function checkoutRequestBody(\n opts: CreateServerCheckoutOptions | CreateClientCheckoutOptions\n) {\n return {\n app_user_id: \"appUserId\" in opts ? opts.appUserId : undefined,\n cancel_url: opts.cancelUrl,\n checkout_request_id: opts.checkoutRequestId,\n lookup_key: opts.lookupKey,\n metadata: opts.metadata,\n price_id: opts.priceId,\n quantity: opts.quantity,\n success_url: opts.successUrl,\n user_id: \"userId\" in opts ? opts.userId : undefined,\n };\n}\n\nexport function portalRequestBody(\n opts: CreateServerPortalSessionOptions | CreateClientPortalSessionOptions\n) {\n return {\n app_user_id: \"appUserId\" in opts ? opts.appUserId : undefined,\n return_url: opts.returnUrl,\n user_id: \"userId\" in opts ? opts.userId : undefined,\n };\n}\n","import type { HttpTransport } from \"../http\";\nimport {\n type BillingEntitlementsResponse,\n type BillingPortalResponse,\n type BillingPrice,\n type BillingProduct,\n type BillingStatusResponse,\n type BillingSubscriptionResponse,\n type CreateClientCheckoutOptions,\n type CreateClientPortalSessionOptions,\n checkoutRequestBody,\n portalRequestBody,\n} from \"./shared\";\n\nfunction redirectTo(url: string): void {\n const browser = globalThis as typeof globalThis & {\n window?: { location: { href: string } };\n };\n if (!browser.window?.location) {\n throw new Error(\"redirectToCheckout can only be used in a browser environment\");\n }\n browser.window.location.href = url;\n}\n\nexport class BillingClientNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Read whether billing is enabled for the app environment tied to this\n * publishable key, and whether the connected Stripe account is in test or\n * live mode.\n *\n * Render a \"Test mode\" banner in your app whenever `testMode` is true.\n */\n getStatus(): Promise<BillingStatusResponse> {\n return this.transport.request<BillingStatusResponse>({\n service: \"billing\",\n path: \"/v1/billing/status\",\n });\n }\n\n /**\n * List the active billing products for the app environment tied to this\n * publishable key.\n */\n listProducts(): Promise<{ products: BillingProduct[] }> {\n return this.transport.request<{ products: BillingProduct[] }>({\n service: \"billing\",\n path: \"/v1/billing/products\",\n });\n }\n\n /**\n * List the active billing prices for the app environment tied to this\n * publishable key.\n */\n listPrices(): Promise<{ prices: BillingPrice[] }> {\n return this.transport.request<{ prices: BillingPrice[] }>({\n service: \"billing\",\n path: \"/v1/billing/prices\",\n });\n }\n\n /**\n * Create a Checkout Session for the signed-in browser user and redirect to\n * the Stripe-hosted Checkout page.\n *\n * This method depends on a Buildspace session being available through\n * `setSession()` or your app's authenticated request context.\n */\n async redirectToCheckout(opts: CreateClientCheckoutOptions): Promise<void> {\n const checkout = await this.transport.request<{ url: string }>({\n service: \"billing\",\n path: \"/v1/billing/checkout\",\n method: \"POST\",\n body: checkoutRequestBody(opts),\n });\n redirectTo(checkout.url);\n }\n\n /**\n * Open the Stripe-hosted customer portal for the signed-in browser user.\n */\n async redirectToPortal(opts: CreateClientPortalSessionOptions): Promise<void> {\n const portal = await this.transport.request<BillingPortalResponse>({\n service: \"billing\",\n path: \"/v1/billing/portal\",\n method: \"POST\",\n body: portalRequestBody(opts),\n });\n redirectTo(portal.url);\n }\n\n /**\n * Discoverable alias for redirectToPortal — opens the Stripe-hosted customer\n * portal so the signed-in user can manage their subscription, payment method,\n * and invoices.\n */\n manageSubscription(opts: CreateClientPortalSessionOptions): Promise<void> {\n return this.redirectToPortal(opts);\n }\n\n /**\n * Read the current subscription state for the signed-in browser user.\n */\n getSubscription(): Promise<BillingSubscriptionResponse> {\n return this.transport.request<BillingSubscriptionResponse>({\n service: \"billing\",\n path: \"/v1/billing/subscription\",\n });\n }\n\n /**\n * Read the current paid entitlement state for the signed-in browser user.\n */\n getEntitlements(): Promise<BillingEntitlementsResponse> {\n return this.transport.request<BillingEntitlementsResponse>({\n service: \"billing\",\n path: \"/v1/billing/entitlements\",\n });\n }\n}\n","import type { HttpTransport } from \"../http\";\nimport {\n type BillingCheckoutResponse,\n type BillingEntitlementsResponse,\n type BillingPortalResponse,\n type BillingPrice,\n type BillingProduct,\n type BillingStatusResponse,\n type BillingSubscriptionResponse,\n billingIdentityQuery,\n type CreateServerCheckoutOptions,\n type CreateServerPortalSessionOptions,\n checkoutRequestBody,\n portalRequestBody,\n} from \"./shared\";\n\nexport type {\n BillingCheckoutResponse,\n BillingEntitlementsResponse,\n BillingPortalResponse,\n BillingPrice,\n BillingProduct,\n BillingStatusResponse,\n BillingSubscriptionResponse,\n CreateServerCheckoutOptions,\n CreateServerPortalSessionOptions,\n} from \"./shared\";\nexport { shouldShowTestBanner } from \"./shared\";\n\nexport class BillingServerNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Read whether billing is enabled for the app environment tied to this API\n * key, and whether the connected Stripe account is in test or live mode.\n *\n * Render a \"Test mode\" banner in your app whenever `testMode` is true.\n */\n getStatus(): Promise<BillingStatusResponse> {\n return this.transport.request<BillingStatusResponse>({\n service: \"billing\",\n path: \"/v1/billing/status\",\n });\n }\n\n /**\n * List the active billing products configured for the app environment tied to\n * this API key.\n */\n listProducts(): Promise<{ products: BillingProduct[] }> {\n return this.transport.request<{ products: BillingProduct[] }>({\n service: \"billing\",\n path: \"/v1/billing/products\",\n });\n }\n\n /**\n * List the active billing prices configured for the app environment tied to\n * this API key.\n */\n listPrices(): Promise<{ prices: BillingPrice[] }> {\n return this.transport.request<{ prices: BillingPrice[] }>({\n service: \"billing\",\n path: \"/v1/billing/prices\",\n });\n }\n\n /**\n * Create a Stripe Checkout Session on the creator's connected Stripe account.\n *\n * Use `userId` for Buildspace-authenticated users, or `appUserId` when your\n * app uses its own auth system and you want Buildspace to track billing state\n * against an app-defined user id.\n */\n createCheckout(opts: CreateServerCheckoutOptions): Promise<BillingCheckoutResponse> {\n return this.transport.request<BillingCheckoutResponse>({\n service: \"billing\",\n path: \"/v1/billing/checkout\",\n method: \"POST\",\n body: checkoutRequestBody(opts),\n });\n }\n\n /**\n * Create a Stripe-hosted customer portal session for the specified billing\n * identity.\n */\n createPortalSession(opts: CreateServerPortalSessionOptions): Promise<BillingPortalResponse> {\n return this.transport.request<BillingPortalResponse>({\n service: \"billing\",\n path: \"/v1/billing/portal\",\n method: \"POST\",\n body: portalRequestBody(opts),\n });\n }\n\n /**\n * Read the current subscription state for a Buildspace user or app-defined\n * billing identity.\n */\n getSubscription(opts?: {\n appUserId?: string;\n userId?: string;\n }): Promise<BillingSubscriptionResponse> {\n return this.transport.request<BillingSubscriptionResponse>({\n service: \"billing\",\n path: \"/v1/billing/subscription\",\n query: billingIdentityQuery(opts),\n });\n }\n\n /**\n * Read the current paid entitlement state for a Buildspace user or app-defined\n * billing identity.\n */\n getEntitlements(opts?: {\n appUserId?: string;\n userId?: string;\n }): Promise<BillingEntitlementsResponse> {\n return this.transport.request<BillingEntitlementsResponse>({\n service: \"billing\",\n path: \"/v1/billing/entitlements\",\n query: billingIdentityQuery(opts),\n });\n }\n}\n"]}