@omnibase/core-js 0.4.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-767PUXYD.js +556 -0
- package/dist/chunk-DDFBRGMG.js +106 -0
- package/dist/chunk-LIS5WD3H.js +560 -0
- package/dist/index.cjs +1259 -0
- package/dist/index.d.cts +3 -10
- package/dist/index.d.ts +3 -3
- package/dist/index.js +51 -0
- package/dist/payments/index.cjs +474 -83
- package/dist/payments/index.d.cts +1862 -66
- package/dist/payments/index.d.ts +1862 -66
- package/dist/payments/index.js +12 -161
- package/dist/permissions/index.js +3 -102
- package/dist/tenants/index.cjs +535 -157
- package/dist/tenants/index.d.cts +3 -635
- package/dist/tenants/index.d.ts +3 -635
- package/dist/tenants/index.js +4 -175
- package/package.json +7 -2
|
@@ -1,191 +1,1987 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PermissionsClient } from '../permissions/index.cjs';
|
|
2
|
+
import '@ory/client';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Base API Response structure for all operations
|
|
6
|
+
*
|
|
7
|
+
* This generic type defines the standard response format returned by all
|
|
8
|
+
* API endpoints. It provides a consistent structure for
|
|
9
|
+
* handling both successful responses and error conditions across the SDK.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of the response data payload
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* Successful response:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const response: ApiResponse<{ tenant: Tenant }> = {
|
|
17
|
+
* data: { tenant: { id: '123', name: 'My Company' } },
|
|
18
|
+
* status: 200
|
|
19
|
+
* };
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* Error response:
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const response: ApiResponse<never> = {
|
|
26
|
+
* status: 400,
|
|
27
|
+
* error: 'Invalid tenant name provided'
|
|
28
|
+
* };
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
type ApiResponse<T> = {
|
|
35
|
+
/**
|
|
36
|
+
* Response data payload (present only on successful operations)
|
|
37
|
+
* Contains the actual data returned by the API endpoint
|
|
38
|
+
*/
|
|
39
|
+
data?: T;
|
|
40
|
+
/**
|
|
41
|
+
* HTTP status code indicating the result of the operation
|
|
42
|
+
* @example 200 for success, 400 for client errors, 500 for server errors
|
|
43
|
+
*/
|
|
44
|
+
status: number;
|
|
45
|
+
/**
|
|
46
|
+
* Error message (present only when operation fails)
|
|
47
|
+
* Provides human-readable description of what went wrong
|
|
48
|
+
*/
|
|
49
|
+
error?: string;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Configuration options for creating a Stripe checkout session
|
|
54
|
+
*
|
|
55
|
+
* Defines all parameters needed to create a checkout session for either
|
|
56
|
+
* one-time payments or subscription billing. The session will redirect
|
|
57
|
+
* users to Stripe's hosted checkout page.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const options: CheckoutOptions = {
|
|
62
|
+
* price_id: 'price_1234567890',
|
|
63
|
+
* mode: 'subscription',
|
|
64
|
+
* success_url: 'https://app.com/success?session_id={CHECKOUT_SESSION_ID}',
|
|
65
|
+
* cancel_url: 'https://app.com/pricing',
|
|
66
|
+
* customer_id: 'cus_1234567890'
|
|
67
|
+
* };
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @since 1.0.0
|
|
71
|
+
* @public
|
|
72
|
+
* @group Checkout
|
|
73
|
+
*/
|
|
74
|
+
type CheckoutOptions = {
|
|
75
|
+
/** Stripe price ID for the product/service being purchased */
|
|
76
|
+
price_id: string;
|
|
77
|
+
/**
|
|
78
|
+
* Checkout mode determining the type of transaction
|
|
79
|
+
* - 'payment': One-time payment
|
|
80
|
+
* - 'subscription': Recurring subscription
|
|
81
|
+
*/
|
|
82
|
+
mode: "payment" | "subscription";
|
|
83
|
+
/**
|
|
84
|
+
* URL to redirect to after successful payment
|
|
85
|
+
* Can include {CHECKOUT_SESSION_ID} placeholder for session tracking
|
|
86
|
+
*/
|
|
87
|
+
success_url: string;
|
|
88
|
+
/** URL to redirect to if the user cancels the checkout */
|
|
89
|
+
cancel_url: string;
|
|
90
|
+
/**
|
|
91
|
+
* Optional Stripe customer ID to associate with this checkout
|
|
92
|
+
* If not provided, a new customer will be created
|
|
93
|
+
*/
|
|
94
|
+
customer_id?: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Response from creating a checkout session
|
|
98
|
+
*
|
|
99
|
+
* Contains the checkout session URL and ID for redirecting users
|
|
100
|
+
* to Stripe's hosted checkout page and tracking the session.
|
|
101
|
+
*
|
|
102
|
+
* @since 1.0.0
|
|
103
|
+
* @public
|
|
104
|
+
* @group Checkout
|
|
105
|
+
*/
|
|
106
|
+
type CreateCheckoutResponse = ApiResponse<{
|
|
107
|
+
/** URL to redirect the user to for completing payment */
|
|
108
|
+
url: string;
|
|
109
|
+
/** Unique identifier for the checkout session */
|
|
110
|
+
sessionId: string;
|
|
111
|
+
}>;
|
|
112
|
+
/**
|
|
113
|
+
* Manager for Stripe checkout session operations
|
|
114
|
+
*
|
|
115
|
+
* Handles creation and management of Stripe checkout sessions for both
|
|
116
|
+
* one-time payments and subscription billing. Provides a simple interface
|
|
117
|
+
* for redirecting users to Stripe's hosted checkout experience.
|
|
118
|
+
*
|
|
119
|
+
* Checkout sessions are the recommended way to accept payments as they
|
|
120
|
+
* provide a secure, PCI-compliant payment flow without requiring
|
|
121
|
+
* sensitive payment data to touch your servers.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* Creating a subscription checkout:
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const checkoutManager = new CheckoutManager(paymentHandler);
|
|
127
|
+
*
|
|
128
|
+
* const session = await checkoutManager.createSession({
|
|
129
|
+
* price_id: 'price_monthly_pro',
|
|
130
|
+
* mode: 'subscription',
|
|
131
|
+
* success_url: 'https://app.com/welcome?session_id={CHECKOUT_SESSION_ID}',
|
|
132
|
+
* cancel_url: 'https://app.com/pricing',
|
|
133
|
+
* customer_id: 'cus_existing_customer'
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* // Redirect user to checkout
|
|
137
|
+
* window.location.href = session.data.url;
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @since 1.0.0
|
|
141
|
+
* @public
|
|
142
|
+
* @group Checkout
|
|
143
|
+
*/
|
|
144
|
+
declare class CheckoutManager {
|
|
145
|
+
private omnibaseClient;
|
|
146
|
+
/**
|
|
147
|
+
* Initialize the checkout manager
|
|
148
|
+
*
|
|
149
|
+
* @param paymentHandler - Payment handler instance for API communication
|
|
150
|
+
*
|
|
151
|
+
* @group Checkout
|
|
152
|
+
*/
|
|
153
|
+
constructor(omnibaseClient: OmnibaseClient);
|
|
154
|
+
/**
|
|
155
|
+
* Create a new Stripe checkout session
|
|
156
|
+
*
|
|
157
|
+
* Creates a checkout session with the specified options and returns
|
|
158
|
+
* the session URL for redirecting the user to complete payment.
|
|
159
|
+
* The session will be configured for either one-time payment or
|
|
160
|
+
* subscription based on the mode parameter.
|
|
161
|
+
*
|
|
162
|
+
* @param options - Configuration options for the checkout session
|
|
163
|
+
* @param options.price_id - Stripe price ID for the product/service
|
|
164
|
+
* @param options.mode - Payment mode ('payment' for one-time, 'subscription' for recurring)
|
|
165
|
+
* @param options.success_url - URL to redirect after successful payment
|
|
166
|
+
* @param options.cancel_url - URL to redirect if user cancels
|
|
167
|
+
* @param options.customer_id - Optional existing Stripe customer ID
|
|
168
|
+
*
|
|
169
|
+
* @returns Promise resolving to checkout session response with URL and session ID
|
|
170
|
+
*
|
|
171
|
+
* @throws {Error} When the API request fails due to network issues
|
|
172
|
+
* @throws {Error} When the server returns an error response (invalid price_id, etc.)
|
|
173
|
+
* @throws {ValidationError} When required parameters are missing or invalid
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* One-time payment checkout:
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const session = await checkoutManager.createSession({
|
|
179
|
+
* price_id: 'price_one_time_product',
|
|
180
|
+
* mode: 'payment',
|
|
181
|
+
* success_url: 'https://app.com/success',
|
|
182
|
+
* cancel_url: 'https://app.com/cancel'
|
|
183
|
+
* });
|
|
184
|
+
*
|
|
185
|
+
* // Redirect to Stripe checkout
|
|
186
|
+
* window.location.href = session.data.url;
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* Subscription checkout with existing customer:
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const session = await checkoutManager.createSession({
|
|
193
|
+
* price_id: 'price_monthly_plan',
|
|
194
|
+
* mode: 'subscription',
|
|
195
|
+
* success_url: 'https://app.com/dashboard?welcome=true',
|
|
196
|
+
* cancel_url: 'https://app.com/pricing',
|
|
197
|
+
* customer_id: 'cus_12345'
|
|
198
|
+
* });
|
|
199
|
+
*
|
|
200
|
+
* console.log(`Session created: ${session.data.sessionId}`);
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @since 1.0.0
|
|
204
|
+
* @group Checkout
|
|
205
|
+
*/
|
|
206
|
+
createSession(options: CheckoutOptions): Promise<CreateCheckoutResponse>;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Response from Stripe configuration API endpoints
|
|
211
|
+
*
|
|
212
|
+
* Contains the current Stripe configuration including products, prices,
|
|
213
|
+
* and UI customization settings. This represents the complete billing
|
|
214
|
+
* configuration loaded from the database.
|
|
215
|
+
*
|
|
216
|
+
* @since 1.0.0
|
|
217
|
+
* @public
|
|
218
|
+
* @group Configuration
|
|
5
219
|
*/
|
|
6
220
|
type StripeConfigResponse = ApiResponse<{
|
|
221
|
+
/** The complete Stripe configuration object */
|
|
7
222
|
config: StripeConfiguration;
|
|
223
|
+
/** Optional message from the API response */
|
|
8
224
|
message?: string;
|
|
9
225
|
}>;
|
|
226
|
+
/**
|
|
227
|
+
* Complete Stripe billing configuration
|
|
228
|
+
*
|
|
229
|
+
* Represents a versioned Stripe configuration containing all products,
|
|
230
|
+
* prices, and UI customizations. This configuration is stored in the
|
|
231
|
+
* database and enables safe deployment and rollback of pricing changes.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const config: StripeConfiguration = {
|
|
236
|
+
* version: "v1.2.0",
|
|
237
|
+
* products: [
|
|
238
|
+
* {
|
|
239
|
+
* id: "starter_plan",
|
|
240
|
+
* name: "Starter Plan",
|
|
241
|
+
* description: "Perfect for individuals and small teams",
|
|
242
|
+
* type: "service",
|
|
243
|
+
* prices: [...]
|
|
244
|
+
* }
|
|
245
|
+
* ]
|
|
246
|
+
* };
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @since 1.0.0
|
|
250
|
+
* @public
|
|
251
|
+
* @group Configuration
|
|
252
|
+
*/
|
|
10
253
|
interface StripeConfiguration {
|
|
254
|
+
/** Version identifier for this configuration */
|
|
11
255
|
version: string;
|
|
256
|
+
/** Array of all products in this configuration */
|
|
12
257
|
products: Product[];
|
|
13
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Product definition in Stripe configuration
|
|
261
|
+
*
|
|
262
|
+
* Represents a billable product or service with associated pricing options
|
|
263
|
+
* and UI customizations. Products can be services, physical goods, or
|
|
264
|
+
* metered usage products.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* const product: Product = {
|
|
269
|
+
* id: "pro_plan",
|
|
270
|
+
* name: "Professional Plan",
|
|
271
|
+
* description: "Advanced features for growing businesses",
|
|
272
|
+
* type: "service",
|
|
273
|
+
* prices: [
|
|
274
|
+
* { id: "monthly", amount: 2900, currency: "usd", interval: "month" },
|
|
275
|
+
* { id: "yearly", amount: 29000, currency: "usd", interval: "year" }
|
|
276
|
+
* ],
|
|
277
|
+
* ui: {
|
|
278
|
+
* display_name: "Pro",
|
|
279
|
+
* tagline: "Most Popular",
|
|
280
|
+
* features: ["Unlimited projects", "24/7 support"],
|
|
281
|
+
* highlighted: true
|
|
282
|
+
* }
|
|
283
|
+
* };
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @since 1.0.0
|
|
287
|
+
* @public
|
|
288
|
+
* @group Configuration
|
|
289
|
+
*/
|
|
14
290
|
interface Product {
|
|
291
|
+
/** Unique identifier for this product */
|
|
15
292
|
id: string;
|
|
293
|
+
/** Display name for the product */
|
|
16
294
|
name: string;
|
|
295
|
+
/** Optional detailed description */
|
|
17
296
|
description?: string;
|
|
297
|
+
/**
|
|
298
|
+
* Product type affecting billing behavior
|
|
299
|
+
* - 'service': Subscription services
|
|
300
|
+
* - 'good': Physical or digital goods
|
|
301
|
+
* - 'metered': Usage-based billing
|
|
302
|
+
*/
|
|
18
303
|
type?: "service" | "good" | "metered";
|
|
304
|
+
/** Array of pricing options for this product */
|
|
19
305
|
prices: Price[];
|
|
306
|
+
/** Optional UI customization settings */
|
|
20
307
|
ui?: ProductUI;
|
|
21
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Price definition for a product
|
|
311
|
+
*
|
|
312
|
+
* Defines a specific pricing option including amount, currency, billing
|
|
313
|
+
* frequency, and advanced pricing features like tiered billing. Supports
|
|
314
|
+
* both fixed and usage-based pricing models.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* Simple monthly pricing:
|
|
318
|
+
* ```typescript
|
|
319
|
+
* const monthlyPrice: Price = {
|
|
320
|
+
* id: "monthly_standard",
|
|
321
|
+
* amount: 1999, // $19.99 in cents
|
|
322
|
+
* currency: "usd",
|
|
323
|
+
* interval: "month",
|
|
324
|
+
* usage_type: "licensed"
|
|
325
|
+
* };
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* Tiered usage pricing:
|
|
330
|
+
* ```typescript
|
|
331
|
+
* const tieredPrice: Price = {
|
|
332
|
+
* id: "api_calls_tiered",
|
|
333
|
+
* currency: "usd",
|
|
334
|
+
* usage_type: "metered",
|
|
335
|
+
* billing_scheme: "tiered",
|
|
336
|
+
* tiers_mode: "graduated",
|
|
337
|
+
* tiers: [
|
|
338
|
+
* { up_to: 1000, unit_amount: 10 }, // First 1000 calls at $0.10 each
|
|
339
|
+
* { up_to: "inf", unit_amount: 5 } // Additional calls at $0.05 each
|
|
340
|
+
* ]
|
|
341
|
+
* };
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
* @since 1.0.0
|
|
345
|
+
* @public
|
|
346
|
+
* @group Configuration
|
|
347
|
+
*/
|
|
22
348
|
interface Price {
|
|
349
|
+
/** Unique identifier for this price */
|
|
23
350
|
id: string;
|
|
351
|
+
/**
|
|
352
|
+
* Price amount in smallest currency unit (e.g., cents for USD)
|
|
353
|
+
* Omitted for usage-based pricing with tiers
|
|
354
|
+
*/
|
|
24
355
|
amount?: number;
|
|
356
|
+
/** Currency code (ISO 4217) */
|
|
25
357
|
currency: string;
|
|
358
|
+
/**
|
|
359
|
+
* Billing interval for recurring prices
|
|
360
|
+
* - 'month': Monthly billing
|
|
361
|
+
* - 'year': Annual billing
|
|
362
|
+
* - 'week': Weekly billing
|
|
363
|
+
* - 'day': Daily billing
|
|
364
|
+
*/
|
|
26
365
|
interval?: "month" | "year" | "week" | "day";
|
|
366
|
+
/**
|
|
367
|
+
* Number of intervals between billings
|
|
368
|
+
* @defaultValue 1
|
|
369
|
+
*/
|
|
27
370
|
interval_count?: number;
|
|
371
|
+
/**
|
|
372
|
+
* Usage type determining billing model
|
|
373
|
+
* - 'licensed': Fixed recurring pricing
|
|
374
|
+
* - 'metered': Usage-based pricing
|
|
375
|
+
*/
|
|
28
376
|
usage_type?: "licensed" | "metered";
|
|
377
|
+
/**
|
|
378
|
+
* Billing scheme for complex pricing
|
|
379
|
+
* - 'per_unit': Simple per-unit pricing
|
|
380
|
+
* - 'tiered': Graduated or volume-based tiers
|
|
381
|
+
*/
|
|
29
382
|
billing_scheme?: "per_unit" | "tiered";
|
|
383
|
+
/**
|
|
384
|
+
* Tier calculation mode (when billing_scheme is 'tiered')
|
|
385
|
+
* - 'graduated': Each tier applies to usage within that tier
|
|
386
|
+
* - 'volume': Entire usage charged at the tier rate
|
|
387
|
+
*/
|
|
30
388
|
tiers_mode?: "graduated" | "volume";
|
|
389
|
+
/** Pricing tiers for tiered billing */
|
|
31
390
|
tiers?: Tier[];
|
|
391
|
+
/** Optional UI customization settings */
|
|
32
392
|
ui?: PriceUI;
|
|
33
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Pricing tier definition for tiered billing
|
|
396
|
+
*
|
|
397
|
+
* Defines a usage range and associated pricing for tiered billing models.
|
|
398
|
+
* Enables graduated pricing where different usage levels have different rates.
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```typescript
|
|
402
|
+
* const tiers: Tier[] = [
|
|
403
|
+
* { up_to: 100, flat_amount: 0, unit_amount: 10 }, // First 100 free, then $0.10 each
|
|
404
|
+
* { up_to: 1000, unit_amount: 5 }, // Next 900 at $0.05 each
|
|
405
|
+
* { up_to: "inf", unit_amount: 2 } // Beyond 1000 at $0.02 each
|
|
406
|
+
* ];
|
|
407
|
+
* ```
|
|
408
|
+
*
|
|
409
|
+
* @since 1.0.0
|
|
410
|
+
* @public
|
|
411
|
+
* @group Configuration
|
|
412
|
+
*/
|
|
34
413
|
interface Tier {
|
|
414
|
+
/**
|
|
415
|
+
* Upper bound for this tier
|
|
416
|
+
* Use "inf" for the highest tier with no upper limit
|
|
417
|
+
*/
|
|
35
418
|
up_to: number | "inf";
|
|
419
|
+
/**
|
|
420
|
+
* Fixed amount charged for this tier (in cents)
|
|
421
|
+
* Used for flat fees at tier boundaries
|
|
422
|
+
*/
|
|
36
423
|
flat_amount?: number;
|
|
424
|
+
/**
|
|
425
|
+
* Per-unit amount for usage within this tier (in cents)
|
|
426
|
+
* Applied to each unit of usage in this tier range
|
|
427
|
+
*/
|
|
37
428
|
unit_amount?: number;
|
|
38
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* UI customization settings for products
|
|
432
|
+
*
|
|
433
|
+
* Controls how products are displayed in pricing tables and marketing pages.
|
|
434
|
+
* Provides extensive customization options for branding and presentation.
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```typescript
|
|
438
|
+
* const productUI: ProductUI = {
|
|
439
|
+
* display_name: "Enterprise",
|
|
440
|
+
* tagline: "For large organizations",
|
|
441
|
+
* features: ["SSO integration", "Advanced analytics", "Priority support"],
|
|
442
|
+
* badge: "Most Popular",
|
|
443
|
+
* cta_text: "Contact Sales",
|
|
444
|
+
* highlighted: true,
|
|
445
|
+
* sort_order: 3
|
|
446
|
+
* };
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* @since 1.0.0
|
|
450
|
+
* @public
|
|
451
|
+
* @group UI Configuration
|
|
452
|
+
*/
|
|
39
453
|
interface ProductUI {
|
|
454
|
+
/** Custom display name (overrides product.name) */
|
|
40
455
|
display_name?: string;
|
|
456
|
+
/** Marketing tagline or subtitle */
|
|
41
457
|
tagline?: string;
|
|
458
|
+
/** List of key features to highlight */
|
|
42
459
|
features?: string[];
|
|
460
|
+
/** Optional badge text (e.g., "Popular", "Best Value") */
|
|
43
461
|
badge?: string;
|
|
462
|
+
/** Custom call-to-action button text */
|
|
44
463
|
cta_text?: string;
|
|
464
|
+
/** Whether to visually highlight this product */
|
|
45
465
|
highlighted?: boolean;
|
|
466
|
+
/** Sort order for display (lower numbers first) */
|
|
46
467
|
sort_order?: number;
|
|
47
468
|
}
|
|
469
|
+
/**
|
|
470
|
+
* UI customization settings for prices
|
|
471
|
+
*
|
|
472
|
+
* Controls how individual price options are displayed within products.
|
|
473
|
+
* Enables custom formatting, feature lists, and usage limits display.
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```typescript
|
|
477
|
+
* const priceUI: PriceUI = {
|
|
478
|
+
* display_name: "Annual Billing",
|
|
479
|
+
* price_display: {
|
|
480
|
+
* custom_text: "$99/year",
|
|
481
|
+
* suffix: "billed annually"
|
|
482
|
+
* },
|
|
483
|
+
* billing_period: "per year",
|
|
484
|
+
* features: ["2 months free", "Priority support"],
|
|
485
|
+
* limits: [
|
|
486
|
+
* { text: "Up to 10 users", value: 10, unit: "users" },
|
|
487
|
+
* { text: "100GB storage", value: 100, unit: "GB" }
|
|
488
|
+
* ]
|
|
489
|
+
* };
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* @since 1.0.0
|
|
493
|
+
* @public
|
|
494
|
+
* @group UI Configuration
|
|
495
|
+
*/
|
|
48
496
|
interface PriceUI {
|
|
497
|
+
/** Custom display name for this price option */
|
|
49
498
|
display_name?: string;
|
|
499
|
+
/** Custom price display formatting */
|
|
50
500
|
price_display?: PriceDisplay;
|
|
501
|
+
/** Custom billing period description */
|
|
51
502
|
billing_period?: string;
|
|
503
|
+
/** Price-specific features to highlight */
|
|
52
504
|
features?: string[];
|
|
505
|
+
/** Usage limits and quotas for this price */
|
|
53
506
|
limits?: PriceLimit[];
|
|
54
507
|
}
|
|
508
|
+
/**
|
|
509
|
+
* Custom price display formatting options
|
|
510
|
+
*
|
|
511
|
+
* Provides fine-grained control over how prices are formatted and displayed,
|
|
512
|
+
* including custom text, currency symbols, and suffixes.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```typescript
|
|
516
|
+
* const priceDisplay: PriceDisplay = {
|
|
517
|
+
* custom_text: "Contact us for pricing",
|
|
518
|
+
* show_currency: false,
|
|
519
|
+
* suffix: "per month"
|
|
520
|
+
* };
|
|
521
|
+
* ```
|
|
522
|
+
*
|
|
523
|
+
* @since 1.0.0
|
|
524
|
+
* @public
|
|
525
|
+
* @group UI Configuration
|
|
526
|
+
*/
|
|
55
527
|
interface PriceDisplay {
|
|
528
|
+
/**
|
|
529
|
+
* Custom text to display instead of calculated price
|
|
530
|
+
* Useful for "Contact us" or "Free" pricing
|
|
531
|
+
*/
|
|
56
532
|
custom_text?: string;
|
|
533
|
+
/**
|
|
534
|
+
* Whether to show currency symbol
|
|
535
|
+
* @defaultValue true
|
|
536
|
+
*/
|
|
57
537
|
show_currency?: boolean;
|
|
538
|
+
/** Additional text to append after the price */
|
|
58
539
|
suffix?: string;
|
|
59
540
|
}
|
|
541
|
+
/**
|
|
542
|
+
* Usage limit or quota definition
|
|
543
|
+
*
|
|
544
|
+
* Represents a specific limit or quota associated with a price tier,
|
|
545
|
+
* such as user limits, storage quotas, or API call allowances.
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* ```typescript
|
|
549
|
+
* const limits: PriceLimit[] = [
|
|
550
|
+
* { text: "Up to 5 team members", value: 5, unit: "users" },
|
|
551
|
+
* { text: "50GB storage included", value: 50, unit: "GB" },
|
|
552
|
+
* { text: "Unlimited API calls" } // No value/unit for unlimited
|
|
553
|
+
* ];
|
|
554
|
+
* ```
|
|
555
|
+
*
|
|
556
|
+
* @since 1.0.0
|
|
557
|
+
* @public
|
|
558
|
+
* @group UI Configuration
|
|
559
|
+
*/
|
|
60
560
|
interface PriceLimit {
|
|
561
|
+
/** Human-readable description of the limit */
|
|
61
562
|
text: string;
|
|
563
|
+
/** Numeric value of the limit (omit for unlimited) */
|
|
62
564
|
value?: number;
|
|
565
|
+
/** Unit of measurement for the limit */
|
|
63
566
|
unit?: string;
|
|
64
567
|
}
|
|
568
|
+
/**
|
|
569
|
+
* UI-ready product data structure for pricing tables
|
|
570
|
+
*
|
|
571
|
+
* Extended product interface that includes pre-processed display data
|
|
572
|
+
* optimized for rendering pricing tables and marketing pages. Contains
|
|
573
|
+
* formatted prices, organized features, and display-ready content.
|
|
574
|
+
*
|
|
575
|
+
* This interface is returned by [`getAvailableProducts()`](config.ts) and provides
|
|
576
|
+
* everything needed to render a complete pricing table without additional
|
|
577
|
+
* data processing.
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```typescript
|
|
581
|
+
* const products: ProductWithPricingUI[] = await configManager.getAvailableProducts();
|
|
582
|
+
*
|
|
583
|
+
* products.forEach(product => {
|
|
584
|
+
* const display = product.pricing_display;
|
|
585
|
+
* console.log(`${display.name}: ${display.tagline}`);
|
|
586
|
+
*
|
|
587
|
+
* display.prices.forEach(price => {
|
|
588
|
+
* console.log(` ${price.display_name}: ${price.formatted_price}`);
|
|
589
|
+
* });
|
|
590
|
+
* });
|
|
591
|
+
* ```
|
|
592
|
+
*
|
|
593
|
+
* @since 1.0.0
|
|
594
|
+
* @public
|
|
595
|
+
* @group UI Configuration
|
|
596
|
+
*/
|
|
65
597
|
interface ProductWithPricingUI extends Product {
|
|
598
|
+
/** Pre-processed display data for UI rendering */
|
|
66
599
|
pricing_display: {
|
|
600
|
+
/** Display name for the product */
|
|
67
601
|
name: string;
|
|
602
|
+
/** Marketing tagline or subtitle */
|
|
68
603
|
tagline?: string;
|
|
604
|
+
/** Key features to highlight */
|
|
69
605
|
features: string[];
|
|
606
|
+
/** Optional badge text */
|
|
70
607
|
badge?: string;
|
|
608
|
+
/** Call-to-action button text */
|
|
71
609
|
cta_text: string;
|
|
610
|
+
/** Whether this product should be visually highlighted */
|
|
72
611
|
highlighted: boolean;
|
|
612
|
+
/** Sort order for display */
|
|
73
613
|
sort_order: number;
|
|
614
|
+
/** UI-ready price information */
|
|
74
615
|
prices: Array<{
|
|
616
|
+
/** Price identifier */
|
|
75
617
|
id: string;
|
|
618
|
+
/** Display name for this price option */
|
|
76
619
|
display_name: string;
|
|
620
|
+
/** Formatted price string ready for display */
|
|
77
621
|
formatted_price: string;
|
|
622
|
+
/** Billing period description */
|
|
78
623
|
billing_period: string;
|
|
624
|
+
/** Price-specific features */
|
|
79
625
|
features: string[];
|
|
626
|
+
/** Usage limits and quotas */
|
|
80
627
|
limits: Array<{
|
|
628
|
+
/** Limit description */
|
|
81
629
|
text: string;
|
|
630
|
+
/** Numeric value (if applicable) */
|
|
82
631
|
value?: number;
|
|
632
|
+
/** Unit of measurement */
|
|
83
633
|
unit?: string;
|
|
84
634
|
}>;
|
|
85
635
|
}>;
|
|
86
636
|
};
|
|
87
637
|
}
|
|
88
638
|
|
|
639
|
+
declare class ConfigManager {
|
|
640
|
+
private omnibaseClient;
|
|
641
|
+
constructor(omnibaseClient: OmnibaseClient);
|
|
642
|
+
/**
|
|
643
|
+
* Get the current Stripe configuration from the database
|
|
644
|
+
*
|
|
645
|
+
* Retrieves the latest Stripe configuration including products, prices,
|
|
646
|
+
* and UI customization data. This configuration represents the current
|
|
647
|
+
* active pricing structure with all UI elements for pricing table rendering.
|
|
648
|
+
*
|
|
649
|
+
* @returns Promise resolving to the current Stripe configuration
|
|
650
|
+
*
|
|
651
|
+
* @throws {Error} When the API request fails due to network issues
|
|
652
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* Basic usage:
|
|
656
|
+
* ```typescript
|
|
657
|
+
* const config = await getStripeConfig();
|
|
658
|
+
* console.log(`Found ${config.data.config.products.length} products`);
|
|
659
|
+
*
|
|
660
|
+
* // Access product UI configuration
|
|
661
|
+
* config.data.config.products.forEach(product => {
|
|
662
|
+
* console.log(`${product.name}: ${product.ui?.tagline || 'No tagline'}`);
|
|
663
|
+
* });
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
getStripeConfig(): Promise<StripeConfigResponse>;
|
|
667
|
+
/**
|
|
668
|
+
* Get available products with UI-ready pricing data
|
|
669
|
+
*
|
|
670
|
+
* Transforms the raw Stripe configuration into UI-ready format for pricing
|
|
671
|
+
* table rendering. Includes formatted pricing, features, limits, and all
|
|
672
|
+
* display customizations needed for marketing pages.
|
|
673
|
+
*
|
|
674
|
+
* @returns Promise resolving to products ready for UI consumption
|
|
675
|
+
*
|
|
676
|
+
* @throws {Error} When the API request fails or configuration is invalid
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* Pricing table rendering:
|
|
680
|
+
* ```typescript
|
|
681
|
+
* const products = await getAvailableProducts();
|
|
682
|
+
*
|
|
683
|
+
* products.forEach(product => {
|
|
684
|
+
* const display = product.pricing_display;
|
|
685
|
+
* console.log(`${display.name} - ${display.tagline}`);
|
|
686
|
+
*
|
|
687
|
+
* display.prices.forEach(price => {
|
|
688
|
+
* console.log(` ${price.display_name}: ${price.formatted_price}`);
|
|
689
|
+
* });
|
|
690
|
+
* });
|
|
691
|
+
* ```
|
|
692
|
+
*/
|
|
693
|
+
getAvailableProducts(): Promise<ProductWithPricingUI[]>;
|
|
694
|
+
/**
|
|
695
|
+
* Get a specific product by ID
|
|
696
|
+
*
|
|
697
|
+
* Retrieves a single product configuration by its ID from the current
|
|
698
|
+
* Stripe configuration. Useful for product-specific operations.
|
|
699
|
+
*
|
|
700
|
+
* @param productId - The configuration product ID to retrieve
|
|
701
|
+
* @returns Promise resolving to the product or null if not found
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```typescript
|
|
705
|
+
* const product = await getProduct('starter_plan');
|
|
706
|
+
* if (product) {
|
|
707
|
+
* console.log(`Found product: ${product.name}`);
|
|
708
|
+
* }
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
711
|
+
getProduct(productId: string): Promise<Product | null>;
|
|
712
|
+
}
|
|
713
|
+
|
|
89
714
|
/**
|
|
90
|
-
*
|
|
715
|
+
* Configuration options for creating a Stripe customer portal session
|
|
716
|
+
*
|
|
717
|
+
* Defines the parameters needed to create a customer portal session
|
|
718
|
+
* that allows customers to manage their subscription, payment methods,
|
|
719
|
+
* billing history, and other account settings.
|
|
91
720
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
721
|
+
* @example
|
|
722
|
+
* ```typescript
|
|
723
|
+
* const options: PortalOptions = {
|
|
724
|
+
* customer_id: 'cus_1234567890',
|
|
725
|
+
* return_url: 'https://app.com/billing'
|
|
726
|
+
* };
|
|
727
|
+
* ```
|
|
95
728
|
*
|
|
96
|
-
* @
|
|
729
|
+
* @since 1.0.0
|
|
730
|
+
* @public
|
|
731
|
+
* @group Portal
|
|
732
|
+
*/
|
|
733
|
+
type PortalOptions = {
|
|
734
|
+
/** Stripe customer ID for the user accessing the portal */
|
|
735
|
+
customer_id: string;
|
|
736
|
+
/** URL to redirect the customer to when they exit the portal */
|
|
737
|
+
return_url: string;
|
|
738
|
+
};
|
|
739
|
+
/**
|
|
740
|
+
* Response from creating a customer portal session
|
|
97
741
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
742
|
+
* Contains the portal session URL for redirecting customers to
|
|
743
|
+
* Stripe's hosted customer portal where they can manage their
|
|
744
|
+
* billing and subscription settings.
|
|
745
|
+
*
|
|
746
|
+
* @since 1.0.0
|
|
747
|
+
* @public
|
|
748
|
+
* @group Portal
|
|
749
|
+
*/
|
|
750
|
+
type CreateCustomerPortalResponse = ApiResponse<{
|
|
751
|
+
/** URL to redirect the customer to for accessing their portal */
|
|
752
|
+
url: string;
|
|
753
|
+
}>;
|
|
754
|
+
/**
|
|
755
|
+
* Manager for Stripe customer portal operations
|
|
756
|
+
*
|
|
757
|
+
* Handles creation of customer portal sessions that allow customers
|
|
758
|
+
* to manage their own billing information, subscriptions, payment methods,
|
|
759
|
+
* and download invoices through Stripe's hosted portal interface.
|
|
760
|
+
*
|
|
761
|
+
* The customer portal provides a secure, self-service interface that
|
|
762
|
+
* reduces support burden by allowing customers to handle common
|
|
763
|
+
* billing tasks independently.
|
|
101
764
|
*
|
|
102
765
|
* @example
|
|
103
|
-
*
|
|
766
|
+
* Creating a customer portal session:
|
|
104
767
|
* ```typescript
|
|
105
|
-
* const
|
|
106
|
-
* console.log(`Found ${config.data.config.products.length} products`);
|
|
768
|
+
* const portalManager = new PortalManager(paymentHandler);
|
|
107
769
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
770
|
+
* const portal = await portalManager.create({
|
|
771
|
+
* customer_id: 'cus_customer123',
|
|
772
|
+
* return_url: 'https://app.com/billing'
|
|
111
773
|
* });
|
|
774
|
+
*
|
|
775
|
+
* // Redirect customer to portal
|
|
776
|
+
* window.location.href = portal.data.url;
|
|
112
777
|
* ```
|
|
778
|
+
*
|
|
779
|
+
* @since 1.0.0
|
|
780
|
+
* @public
|
|
781
|
+
* @group Portal
|
|
113
782
|
*/
|
|
114
|
-
declare
|
|
783
|
+
declare class PortalManager {
|
|
784
|
+
private omnibaseClient;
|
|
785
|
+
/**
|
|
786
|
+
* Initialize the portal manager
|
|
787
|
+
*
|
|
788
|
+
* @param paymentHandler - Payment handler instance for API communication
|
|
789
|
+
*
|
|
790
|
+
* @group Portal
|
|
791
|
+
*/
|
|
792
|
+
constructor(omnibaseClient: OmnibaseClient);
|
|
793
|
+
/**
|
|
794
|
+
* Create a new customer portal session
|
|
795
|
+
*
|
|
796
|
+
* Creates a portal session that allows the specified customer to
|
|
797
|
+
* manage their billing information, subscriptions, and payment methods.
|
|
798
|
+
* Returns a URL that the customer should be redirected to.
|
|
799
|
+
*
|
|
800
|
+
* The portal session is temporary and expires after a short period
|
|
801
|
+
* for security. Each access requires creating a new session.
|
|
802
|
+
*
|
|
803
|
+
* @param options - Configuration options for the portal session
|
|
804
|
+
* @param options.customer_id - Stripe customer ID for the user
|
|
805
|
+
* @param options.return_url - URL to redirect to when exiting the portal
|
|
806
|
+
*
|
|
807
|
+
* @returns Promise resolving to portal session response with access URL
|
|
808
|
+
*
|
|
809
|
+
* @throws {Error} When the API request fails due to network issues
|
|
810
|
+
* @throws {Error} When the server returns an error response (invalid customer_id, etc.)
|
|
811
|
+
* @throws {ValidationError} When required parameters are missing or invalid
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
* Basic portal creation:
|
|
815
|
+
* ```typescript
|
|
816
|
+
* const portal = await portalManager.create({
|
|
817
|
+
* customer_id: 'cus_abc123',
|
|
818
|
+
* return_url: 'https://myapp.com/account/billing'
|
|
819
|
+
* });
|
|
820
|
+
*
|
|
821
|
+
* // Redirect user to portal
|
|
822
|
+
* window.location.href = portal.data.url;
|
|
823
|
+
* ```
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
* With error handling:
|
|
827
|
+
* ```typescript
|
|
828
|
+
* try {
|
|
829
|
+
* const portal = await portalManager.create({
|
|
830
|
+
* customer_id: currentUser.stripeCustomerId,
|
|
831
|
+
* return_url: window.location.origin + '/billing'
|
|
832
|
+
* });
|
|
833
|
+
*
|
|
834
|
+
* window.location.href = portal.data.url;
|
|
835
|
+
* } catch (error) {
|
|
836
|
+
* console.error('Failed to create portal session:', error);
|
|
837
|
+
* showErrorMessage('Unable to access billing portal. Please try again.');
|
|
838
|
+
* }
|
|
839
|
+
* ```
|
|
840
|
+
*
|
|
841
|
+
* @since 1.0.0
|
|
842
|
+
* @group Portal
|
|
843
|
+
*/
|
|
844
|
+
create(options: PortalOptions): Promise<CreateCustomerPortalResponse>;
|
|
845
|
+
}
|
|
846
|
+
|
|
115
847
|
/**
|
|
116
|
-
*
|
|
848
|
+
* Configuration options for recording usage events
|
|
849
|
+
*
|
|
850
|
+
* Defines the parameters needed to record a usage event for metered billing.
|
|
851
|
+
* Usage events are used to track consumption of metered products and calculate
|
|
852
|
+
* charges based on actual usage rather than fixed pricing.
|
|
117
853
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
854
|
+
* @example
|
|
855
|
+
* ```typescript
|
|
856
|
+
* const options: UsageOptions = {
|
|
857
|
+
* meter_event_name: 'api_calls',
|
|
858
|
+
* customer_id: 'cus_1234567890',
|
|
859
|
+
* value: '1'
|
|
860
|
+
* };
|
|
861
|
+
* ```
|
|
862
|
+
*
|
|
863
|
+
* @since 1.0.0
|
|
864
|
+
* @public
|
|
865
|
+
* @group Usage
|
|
866
|
+
*/
|
|
867
|
+
type UsageOptions = {
|
|
868
|
+
/**
|
|
869
|
+
* Name of the meter event to record usage for
|
|
870
|
+
* Must match a meter configured in your Stripe billing configuration
|
|
871
|
+
*/
|
|
872
|
+
meter_event_name: string;
|
|
873
|
+
/** Stripe customer ID to record usage for */
|
|
874
|
+
customer_id: string;
|
|
875
|
+
/**
|
|
876
|
+
* Usage value to record as a string
|
|
877
|
+
* Typically represents quantity consumed (e.g., "1" for single API call, "250" for MB of storage)
|
|
878
|
+
*/
|
|
879
|
+
value: string;
|
|
880
|
+
};
|
|
881
|
+
/**
|
|
882
|
+
* Manager for usage tracking and metered billing operations
|
|
121
883
|
*
|
|
122
|
-
*
|
|
884
|
+
* Handles recording of usage events for metered billing products. Usage events
|
|
885
|
+
* are used by Stripe to calculate charges for products with usage-based pricing,
|
|
886
|
+
* such as API calls, data transfer, or storage consumption.
|
|
123
887
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
888
|
+
* Usage tracking is essential for accurate metered billing and provides
|
|
889
|
+
* transparency to customers about their consumption patterns.
|
|
126
890
|
*
|
|
127
891
|
* @example
|
|
128
|
-
*
|
|
892
|
+
* Recording API usage:
|
|
129
893
|
* ```typescript
|
|
130
|
-
* const
|
|
894
|
+
* const usageManager = new UsageManager(paymentHandler);
|
|
131
895
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
896
|
+
* // Record a single API call
|
|
897
|
+
* await usageManager.recordUsage({
|
|
898
|
+
* meter_event_name: 'api_calls',
|
|
899
|
+
* customer_id: 'cus_customer123',
|
|
900
|
+
* value: '1'
|
|
901
|
+
* });
|
|
135
902
|
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
903
|
+
* // Record bulk data transfer
|
|
904
|
+
* await usageManager.recordUsage({
|
|
905
|
+
* meter_event_name: 'data_transfer_gb',
|
|
906
|
+
* customer_id: 'cus_customer123',
|
|
907
|
+
* value: '2.5'
|
|
139
908
|
* });
|
|
140
909
|
* ```
|
|
910
|
+
*
|
|
911
|
+
* @since 1.0.0
|
|
912
|
+
* @public
|
|
913
|
+
* @group Usage
|
|
141
914
|
*/
|
|
142
|
-
declare
|
|
915
|
+
declare class UsageManager {
|
|
916
|
+
private omnibaseClient;
|
|
917
|
+
/**
|
|
918
|
+
* Initialize the usage manager
|
|
919
|
+
*
|
|
920
|
+
* @param paymentHandler - Payment handler instance for API communication
|
|
921
|
+
*
|
|
922
|
+
* @group Usage
|
|
923
|
+
*/
|
|
924
|
+
constructor(omnibaseClient: OmnibaseClient);
|
|
925
|
+
/**
|
|
926
|
+
* Record a usage event for metered billing
|
|
927
|
+
*
|
|
928
|
+
* Records a usage event against a specific meter for billing calculation.
|
|
929
|
+
* The event will be aggregated with other usage events for the billing period
|
|
930
|
+
* to determine the customer's charges for metered products.
|
|
931
|
+
*
|
|
932
|
+
* Usage events should be recorded in real-time or as close to real-time as
|
|
933
|
+
* possible to ensure accurate billing and provide up-to-date usage visibility
|
|
934
|
+
* to customers.
|
|
935
|
+
*
|
|
936
|
+
* @param options - Usage recording options
|
|
937
|
+
* @param options.meter_event_name - Name of the meter to record against
|
|
938
|
+
* @param options.customer_id - Stripe customer ID
|
|
939
|
+
* @param options.value - Usage quantity as string
|
|
940
|
+
*
|
|
941
|
+
* @returns Promise resolving to API response confirmation
|
|
942
|
+
*
|
|
943
|
+
* @throws {Error} When the API request fails due to network issues
|
|
944
|
+
* @throws {Error} When the server returns an error response (invalid meter name, customer, etc.)
|
|
945
|
+
* @throws {ValidationError} When required parameters are missing or invalid
|
|
946
|
+
*
|
|
947
|
+
* @example
|
|
948
|
+
* API call tracking:
|
|
949
|
+
* ```typescript
|
|
950
|
+
* // Record each API call
|
|
951
|
+
* await usageManager.recordUsage({
|
|
952
|
+
* meter_event_name: 'api_requests',
|
|
953
|
+
* customer_id: user.stripeCustomerId,
|
|
954
|
+
* value: '1'
|
|
955
|
+
* });
|
|
956
|
+
* ```
|
|
957
|
+
*
|
|
958
|
+
* @example
|
|
959
|
+
* Batch usage recording:
|
|
960
|
+
* ```typescript
|
|
961
|
+
* // Record multiple operations at once
|
|
962
|
+
* const usageEvents = [
|
|
963
|
+
* { meter_event_name: 'compute_hours', customer_id: 'cus_123', value: '0.5' },
|
|
964
|
+
* { meter_event_name: 'storage_gb', customer_id: 'cus_123', value: '10' },
|
|
965
|
+
* { meter_event_name: 'api_calls', customer_id: 'cus_123', value: '50' }
|
|
966
|
+
* ];
|
|
967
|
+
*
|
|
968
|
+
* for (const event of usageEvents) {
|
|
969
|
+
* await usageManager.recordUsage(event);
|
|
970
|
+
* }
|
|
971
|
+
* ```
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
* With error handling:
|
|
975
|
+
* ```typescript
|
|
976
|
+
* try {
|
|
977
|
+
* await usageManager.recordUsage({
|
|
978
|
+
* meter_event_name: 'file_uploads',
|
|
979
|
+
* customer_id: currentUser.stripeCustomerId,
|
|
980
|
+
* value: String(uploadedFiles.length)
|
|
981
|
+
* });
|
|
982
|
+
* } catch (error) {
|
|
983
|
+
* console.error('Failed to record usage:', error);
|
|
984
|
+
* // Usage recording failure shouldn't block user operations
|
|
985
|
+
* // but should be logged for billing accuracy
|
|
986
|
+
* }
|
|
987
|
+
* ```
|
|
988
|
+
*
|
|
989
|
+
* @since 1.0.0
|
|
990
|
+
* @group Usage
|
|
991
|
+
*/
|
|
992
|
+
recordUsage(options: UsageOptions): Promise<ApiResponse<"">>;
|
|
993
|
+
}
|
|
994
|
+
|
|
143
995
|
/**
|
|
144
|
-
*
|
|
996
|
+
* Main payment handler for all payment-related operations
|
|
145
997
|
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
998
|
+
* This class serves as the central coordinator for all payment functionality,
|
|
999
|
+
* providing access to checkout sessions, billing configuration, customer portals,
|
|
1000
|
+
* and usage tracking. It handles the low-level HTTP communication with the
|
|
1001
|
+
* payment API and delegates specific operations to specialized managers.
|
|
148
1002
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
1003
|
+
* The handler automatically manages authentication, request formatting, and
|
|
1004
|
+
* provides a consistent interface across all payment operations.
|
|
151
1005
|
*
|
|
152
1006
|
* @example
|
|
153
1007
|
* ```typescript
|
|
154
|
-
* const
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
1008
|
+
* const paymentHandler = new PaymentHandler('https://api.example.com');
|
|
1009
|
+
*
|
|
1010
|
+
* // Create a checkout session
|
|
1011
|
+
* const checkout = await paymentHandler.checkout.createSession({
|
|
1012
|
+
* price_id: 'price_123',
|
|
1013
|
+
* mode: 'subscription',
|
|
1014
|
+
* success_url: 'https://app.com/success',
|
|
1015
|
+
* cancel_url: 'https://app.com/cancel'
|
|
1016
|
+
* });
|
|
1017
|
+
*
|
|
1018
|
+
* // Get available products
|
|
1019
|
+
* const products = await paymentHandler.config.getAvailableProducts();
|
|
158
1020
|
* ```
|
|
1021
|
+
*
|
|
1022
|
+
* @since 1.0.0
|
|
1023
|
+
* @public
|
|
1024
|
+
* @group Client
|
|
159
1025
|
*/
|
|
160
|
-
declare
|
|
1026
|
+
declare class PaymentHandler {
|
|
1027
|
+
private omnibaseClient;
|
|
1028
|
+
/**
|
|
1029
|
+
* Initialize the payment handler with API configuration
|
|
1030
|
+
*
|
|
1031
|
+
* Creates a new payment handler instance that will communicate with
|
|
1032
|
+
* the specified API endpoint. The handler automatically handles
|
|
1033
|
+
* request formatting and authentication headers.
|
|
1034
|
+
*
|
|
1035
|
+
* @param apiUrl - Base URL for the payment API endpoint
|
|
1036
|
+
*
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```typescript
|
|
1039
|
+
* const paymentHandler = new PaymentHandler('https://api.myapp.com');
|
|
1040
|
+
* ```
|
|
1041
|
+
*
|
|
1042
|
+
* @since 1.0.0
|
|
1043
|
+
* @group Client
|
|
1044
|
+
*/
|
|
1045
|
+
constructor(omnibaseClient: OmnibaseClient);
|
|
1046
|
+
/**
|
|
1047
|
+
* Checkout session management
|
|
1048
|
+
*
|
|
1049
|
+
* Provides functionality for creating and managing Stripe checkout sessions
|
|
1050
|
+
* for both one-time payments and subscription billing.
|
|
1051
|
+
*
|
|
1052
|
+
* @example
|
|
1053
|
+
* ```typescript
|
|
1054
|
+
* const session = await paymentHandler.checkout.createSession({
|
|
1055
|
+
* price_id: 'price_monthly',
|
|
1056
|
+
* mode: 'subscription',
|
|
1057
|
+
* success_url: window.location.origin + '/success',
|
|
1058
|
+
* cancel_url: window.location.origin + '/pricing'
|
|
1059
|
+
* });
|
|
1060
|
+
* ```
|
|
1061
|
+
*/
|
|
1062
|
+
readonly checkout: CheckoutManager;
|
|
1063
|
+
/**
|
|
1064
|
+
* Stripe configuration management
|
|
1065
|
+
*
|
|
1066
|
+
* Handles retrieval and processing of database-backed Stripe configurations,
|
|
1067
|
+
* providing UI-ready product and pricing data for rendering pricing tables.
|
|
1068
|
+
*
|
|
1069
|
+
* @example
|
|
1070
|
+
* ```typescript
|
|
1071
|
+
* const products = await paymentHandler.config.getAvailableProducts();
|
|
1072
|
+
* const config = await paymentHandler.config.getStripeConfig();
|
|
1073
|
+
* ```
|
|
1074
|
+
*/
|
|
1075
|
+
readonly config: ConfigManager;
|
|
1076
|
+
/**
|
|
1077
|
+
* Customer portal management
|
|
1078
|
+
*
|
|
1079
|
+
* Creates customer portal sessions for subscription management,
|
|
1080
|
+
* billing history, and payment method updates.
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* ```typescript
|
|
1084
|
+
* const portal = await paymentHandler.portal.create({
|
|
1085
|
+
* customer_id: 'cus_123',
|
|
1086
|
+
* return_url: 'https://app.com/billing'
|
|
1087
|
+
* });
|
|
1088
|
+
* ```
|
|
1089
|
+
*/
|
|
1090
|
+
readonly portal: PortalManager;
|
|
1091
|
+
/**
|
|
1092
|
+
* Usage tracking and metered billing
|
|
1093
|
+
*
|
|
1094
|
+
* Records usage events for metered billing products and manages
|
|
1095
|
+
* usage-based pricing calculations.
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* ```typescript
|
|
1099
|
+
* await paymentHandler.usage.recordUsage({
|
|
1100
|
+
* meter_event_name: 'api_calls',
|
|
1101
|
+
* customer_id: 'cus_123',
|
|
1102
|
+
* value: '1'
|
|
1103
|
+
* });
|
|
1104
|
+
* ```
|
|
1105
|
+
*/
|
|
1106
|
+
readonly usage: UsageManager;
|
|
1107
|
+
}
|
|
161
1108
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
1109
|
+
/**
|
|
1110
|
+
* Request data for accepting a tenant invitation
|
|
1111
|
+
*
|
|
1112
|
+
* Contains the secure token that was provided in the invitation.
|
|
1113
|
+
* This token is validated server-side to ensure the invitation
|
|
1114
|
+
* is legitimate, not expired, and hasn't been used before.
|
|
1115
|
+
*
|
|
1116
|
+
* @example
|
|
1117
|
+
* ```typescript
|
|
1118
|
+
* const acceptData: AcceptTenantInviteRequest = {
|
|
1119
|
+
* token: 'inv_secure_token_abc123xyz'
|
|
1120
|
+
* };
|
|
1121
|
+
* ```
|
|
1122
|
+
*
|
|
1123
|
+
* @since 1.0.0
|
|
1124
|
+
* @public
|
|
1125
|
+
* @group User Management
|
|
1126
|
+
*/
|
|
1127
|
+
type AcceptTenantInviteRequest = {
|
|
1128
|
+
/** Secure invitation token from the email invitation */
|
|
1129
|
+
token: string;
|
|
168
1130
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
1131
|
+
/**
|
|
1132
|
+
* Response structure for accepting a tenant invitation
|
|
1133
|
+
*
|
|
1134
|
+
* Contains the ID of the tenant that the user has successfully joined
|
|
1135
|
+
* along with a confirmation message. After accepting an invitation,
|
|
1136
|
+
* the user becomes a member of the tenant with the role specified
|
|
1137
|
+
* in the original invitation.
|
|
1138
|
+
*
|
|
1139
|
+
* @example
|
|
1140
|
+
* ```typescript
|
|
1141
|
+
* const response: AcceptTenantInviteResponse = {
|
|
1142
|
+
* data: {
|
|
1143
|
+
* tenant_id: 'tenant_abc123',
|
|
1144
|
+
* message: 'Successfully joined tenant'
|
|
1145
|
+
* },
|
|
1146
|
+
* status: 200
|
|
1147
|
+
* };
|
|
1148
|
+
* ```
|
|
1149
|
+
*
|
|
1150
|
+
* @since 1.0.0
|
|
1151
|
+
* @public
|
|
1152
|
+
* @group User Management
|
|
1153
|
+
*/
|
|
1154
|
+
type AcceptTenantInviteResponse = ApiResponse<{
|
|
1155
|
+
/** ID of the tenant the user has joined */
|
|
1156
|
+
tenant_id: string;
|
|
1157
|
+
/** Success message confirming the invitation acceptance */
|
|
1158
|
+
message: string;
|
|
1159
|
+
/** JWT token for postgrest RLS */
|
|
1160
|
+
token: string;
|
|
172
1161
|
}>;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
1162
|
+
/**
|
|
1163
|
+
* Response structure for tenant user invite creation
|
|
1164
|
+
*
|
|
1165
|
+
* Contains the newly created invite information including the secure token
|
|
1166
|
+
* that will be sent to the invitee. The invite has an expiration time and
|
|
1167
|
+
* can only be used once to join the specified tenant.
|
|
1168
|
+
*
|
|
1169
|
+
* @example
|
|
1170
|
+
* ```typescript
|
|
1171
|
+
* const response: CreateTenantUserInviteResponse = {
|
|
1172
|
+
* data: {
|
|
1173
|
+
* invite: {
|
|
1174
|
+
* id: 'invite_123',
|
|
1175
|
+
* tenant_id: 'tenant_abc',
|
|
1176
|
+
* email: 'colleague@company.com',
|
|
1177
|
+
* role: 'member',
|
|
1178
|
+
* token: 'inv_secure_token_xyz',
|
|
1179
|
+
* expires_at: '2024-02-15T10:30:00Z'
|
|
1180
|
+
* },
|
|
1181
|
+
* message: 'Invite created successfully'
|
|
1182
|
+
* },
|
|
1183
|
+
* status: 201
|
|
1184
|
+
* };
|
|
1185
|
+
* ```
|
|
1186
|
+
*
|
|
1187
|
+
* @since 1.0.0
|
|
1188
|
+
* @public
|
|
1189
|
+
* @group User Management
|
|
1190
|
+
*/
|
|
1191
|
+
type CreateTenantUserInviteResponse = ApiResponse<{
|
|
1192
|
+
/** The newly created tenant invite */
|
|
1193
|
+
invite: TenantInvite;
|
|
1194
|
+
/** Success message confirming invite creation */
|
|
1195
|
+
message: string;
|
|
1196
|
+
}>;
|
|
1197
|
+
/**
|
|
1198
|
+
* Tenant invitation entity structure
|
|
1199
|
+
*
|
|
1200
|
+
* Represents a pending invitation for a user to join a specific tenant
|
|
1201
|
+
* with a defined role. The invite contains a secure token that expires
|
|
1202
|
+
* after a certain time period and can only be used once.
|
|
1203
|
+
*
|
|
1204
|
+
* @example
|
|
1205
|
+
* ```typescript
|
|
1206
|
+
* const invite: TenantInvite = {
|
|
1207
|
+
* id: 'invite_abc123',
|
|
1208
|
+
* tenant_id: 'tenant_xyz789',
|
|
1209
|
+
* email: 'newuser@company.com',
|
|
1210
|
+
* role: 'member',
|
|
1211
|
+
* token: 'inv_secure_abc123xyz',
|
|
1212
|
+
* inviter_id: 'user_owner123',
|
|
1213
|
+
* expires_at: '2024-02-01T12:00:00Z',
|
|
1214
|
+
* created_at: '2024-01-25T12:00:00Z',
|
|
1215
|
+
* used_at: undefined // null until invite is accepted
|
|
1216
|
+
* };
|
|
1217
|
+
* ```
|
|
1218
|
+
*
|
|
1219
|
+
* @since 1.0.0
|
|
1220
|
+
* @public
|
|
1221
|
+
* @group User Management
|
|
1222
|
+
*/
|
|
1223
|
+
type TenantInvite = {
|
|
1224
|
+
/** Unique identifier for the invitation */
|
|
1225
|
+
id: string;
|
|
1226
|
+
/** ID of the tenant the user is being invited to */
|
|
1227
|
+
tenant_id: string;
|
|
1228
|
+
/** Email address of the invited user */
|
|
1229
|
+
email: string;
|
|
1230
|
+
/** Role the user will have in the tenant (e.g., 'owner', 'admin', 'member') */
|
|
1231
|
+
role: string;
|
|
1232
|
+
/** Secure token used to accept the invitation */
|
|
1233
|
+
token: string;
|
|
1234
|
+
/** ID of the user who created this invitation */
|
|
1235
|
+
inviter_id: string;
|
|
1236
|
+
/** ISO 8601 timestamp when the invitation expires */
|
|
1237
|
+
expires_at: string;
|
|
1238
|
+
/** ISO 8601 timestamp when the invitation was created */
|
|
1239
|
+
created_at: string;
|
|
1240
|
+
/** ISO 8601 timestamp when the invitation was accepted (null if unused) */
|
|
1241
|
+
used_at?: string;
|
|
178
1242
|
};
|
|
179
|
-
|
|
180
|
-
|
|
1243
|
+
/**
|
|
1244
|
+
* Required data for creating a tenant user invitation
|
|
1245
|
+
*
|
|
1246
|
+
* Specifies the email address of the user to invite and their intended
|
|
1247
|
+
* role within the tenant. The role determines what permissions the user
|
|
1248
|
+
* will have once they accept the invitation.
|
|
1249
|
+
*
|
|
1250
|
+
* @example
|
|
1251
|
+
* ```typescript
|
|
1252
|
+
* const inviteData: CreateTenantUserInviteRequest = {
|
|
1253
|
+
* email: 'developer@company.com',
|
|
1254
|
+
* role: 'admin'
|
|
1255
|
+
* };
|
|
1256
|
+
* ```
|
|
1257
|
+
*
|
|
1258
|
+
* @since 1.0.0
|
|
1259
|
+
* @public
|
|
1260
|
+
* @group User Management
|
|
1261
|
+
*/
|
|
1262
|
+
type CreateTenantUserInviteRequest = {
|
|
1263
|
+
/** Email address of the user to invite */
|
|
1264
|
+
email: string;
|
|
1265
|
+
/** Role the invited user will have in the tenant */
|
|
1266
|
+
role: string;
|
|
1267
|
+
};
|
|
1268
|
+
/**
|
|
1269
|
+
* Tenant invitation management handler
|
|
1270
|
+
*
|
|
1271
|
+
* This class handles all tenant invitation operations including creating
|
|
1272
|
+
* invitations for new users and processing invitation acceptances. It provides
|
|
1273
|
+
* a secure, email-based invitation workflow with role-based access control
|
|
1274
|
+
* and token-based security.
|
|
1275
|
+
*
|
|
1276
|
+
* The manager handles:
|
|
1277
|
+
* - Creating secure invitations with time-limited tokens
|
|
1278
|
+
* - Processing invitation acceptances with validation
|
|
1279
|
+
* - Email workflow integration (server-side)
|
|
1280
|
+
* - Role assignment and permission setup
|
|
1281
|
+
* - Security validation and anti-abuse measures
|
|
1282
|
+
*
|
|
1283
|
+
* All invitation operations respect tenant permissions and ensure that only
|
|
1284
|
+
* authorized users can invite others to their tenants.
|
|
1285
|
+
*
|
|
1286
|
+
* @example
|
|
1287
|
+
* ```typescript
|
|
1288
|
+
* const inviteManager = new TenantInviteManager(omnibaseClient);
|
|
1289
|
+
*
|
|
1290
|
+
* // Create an invitation
|
|
1291
|
+
* const invite = await inviteManager.create('tenant_123', {
|
|
1292
|
+
* email: 'colleague@company.com',
|
|
1293
|
+
* role: 'member'
|
|
1294
|
+
* });
|
|
1295
|
+
*
|
|
1296
|
+
* // Accept an invitation (from the invited user's session)
|
|
1297
|
+
* const result = await inviteManager.accept('invite_token_xyz');
|
|
1298
|
+
* console.log(`Joined tenant: ${result.data.tenant_id}`);
|
|
1299
|
+
* ```
|
|
1300
|
+
*
|
|
1301
|
+
* @since 1.0.0
|
|
1302
|
+
* @public
|
|
1303
|
+
* @group Tenant Invitations
|
|
1304
|
+
*/
|
|
1305
|
+
declare class TenantInviteManager {
|
|
1306
|
+
private omnibaseClient;
|
|
1307
|
+
/**
|
|
1308
|
+
* Creates a new TenantInviteManager instance
|
|
1309
|
+
*
|
|
1310
|
+
* Initializes the manager with the provided Omnibase client for making
|
|
1311
|
+
* authenticated API requests to tenant invitation endpoints.
|
|
1312
|
+
*
|
|
1313
|
+
* @param omnibaseClient - Configured Omnibase client instance
|
|
1314
|
+
*
|
|
1315
|
+
* @group Tenant Invitations
|
|
1316
|
+
*/
|
|
1317
|
+
constructor(omnibaseClient: OmnibaseClient);
|
|
1318
|
+
/**
|
|
1319
|
+
* Accepts a tenant invitation using a secure token
|
|
1320
|
+
*
|
|
1321
|
+
* Processes a tenant invitation by validating the provided token and
|
|
1322
|
+
* adding the authenticated user to the specified tenant. The invitation
|
|
1323
|
+
* token is consumed during this process and cannot be used again.
|
|
1324
|
+
*
|
|
1325
|
+
* The function performs several validations:
|
|
1326
|
+
* - Verifies the token exists and is valid
|
|
1327
|
+
* - Checks that the invitation hasn't expired
|
|
1328
|
+
* - Ensures the invitation hasn't already been used
|
|
1329
|
+
* - Confirms the user is authenticated via session cookies
|
|
1330
|
+
*
|
|
1331
|
+
* Upon successful acceptance, the user is granted access to the tenant
|
|
1332
|
+
* with the role specified in the original invitation. The invitation
|
|
1333
|
+
* record is marked as used and cannot be accepted again.
|
|
1334
|
+
*
|
|
1335
|
+
* @param token - The secure invitation token from the email invitation
|
|
1336
|
+
*
|
|
1337
|
+
* @returns Promise resolving to the tenant ID and success confirmation
|
|
1338
|
+
*
|
|
1339
|
+
* @throws {Error} When the token parameter is missing or empty
|
|
1340
|
+
* @throws {Error} When the invitation token is invalid or expired
|
|
1341
|
+
* @throws {Error} When the invitation has already been accepted
|
|
1342
|
+
* @throws {Error} When the user is not authenticated
|
|
1343
|
+
* @throws {Error} When the API request fails due to network issues
|
|
1344
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
1345
|
+
*
|
|
1346
|
+
* @example
|
|
1347
|
+
* Basic invitation acceptance:
|
|
1348
|
+
* ```typescript
|
|
1349
|
+
* const result = await acceptTenantInvite('inv_secure_token_abc123');
|
|
1350
|
+
*
|
|
1351
|
+
* console.log(`Successfully joined tenant: ${result.data.tenant_id}`);
|
|
1352
|
+
* // User can now access tenant resources
|
|
1353
|
+
* await switchActiveTenant(result.data.tenant_id);
|
|
1354
|
+
* ```
|
|
1355
|
+
*
|
|
1356
|
+
* @example
|
|
1357
|
+
* Handling the invitation flow:
|
|
1358
|
+
* ```typescript
|
|
1359
|
+
* // Typically called from an invitation link like:
|
|
1360
|
+
* // https://app.com/accept-invite?token=inv_secure_token_abc123
|
|
1361
|
+
*
|
|
1362
|
+
* const urlParams = new URLSearchParams(window.location.search);
|
|
1363
|
+
* const inviteToken = urlParams.get('token');
|
|
1364
|
+
*
|
|
1365
|
+
* if (inviteToken) {
|
|
1366
|
+
* try {
|
|
1367
|
+
* const result = await acceptTenantInvite(inviteToken);
|
|
1368
|
+
*
|
|
1369
|
+
* // Success - redirect to tenant dashboard
|
|
1370
|
+
* window.location.href = `/dashboard?tenant=${result.data.tenant_id}`;
|
|
1371
|
+
* } catch (error) {
|
|
1372
|
+
* console.error('Failed to accept invitation:', error.message);
|
|
1373
|
+
* // Show error to user
|
|
1374
|
+
* }
|
|
1375
|
+
* }
|
|
1376
|
+
* ```
|
|
1377
|
+
*
|
|
1378
|
+
*
|
|
1379
|
+
* @since 1.0.0
|
|
1380
|
+
* @public
|
|
1381
|
+
* @group User Management
|
|
1382
|
+
*/
|
|
1383
|
+
accept(token: string): Promise<AcceptTenantInviteResponse>;
|
|
1384
|
+
/**
|
|
1385
|
+
* Creates a new user invitation for a specific tenant
|
|
1386
|
+
*
|
|
1387
|
+
* Generates a secure invitation that allows a user to join the specified
|
|
1388
|
+
* tenant with the defined role. The invitation is sent to the provided
|
|
1389
|
+
* email address and includes a time-limited token for security.
|
|
1390
|
+
*
|
|
1391
|
+
* The function creates the invitation record in the database and can
|
|
1392
|
+
* trigger email notifications (depending on server configuration).
|
|
1393
|
+
* The invitation expires after a predefined time period and can only
|
|
1394
|
+
* be used once.
|
|
1395
|
+
*
|
|
1396
|
+
* Only existing tenant members with appropriate permissions can create
|
|
1397
|
+
* invitations. The inviter's authentication is validated via HTTP-only
|
|
1398
|
+
* cookies sent with the request.
|
|
1399
|
+
*
|
|
1400
|
+
* @param tenantId - Unique identifier of the tenant to invite the user to
|
|
1401
|
+
* @param inviteData - Configuration object for the invitation
|
|
1402
|
+
* @param inviteData.email - Email address of the user to invite
|
|
1403
|
+
* @param inviteData.role - Role the user will have after joining (e.g., 'member', 'admin')
|
|
1404
|
+
*
|
|
1405
|
+
* @returns Promise resolving to the created invitation with secure token
|
|
1406
|
+
*
|
|
1407
|
+
* @throws {Error} When tenantId parameter is missing or empty
|
|
1408
|
+
* @throws {Error} When required fields (email, role) are missing or empty
|
|
1409
|
+
* @throws {Error} When the API request fails due to network issues
|
|
1410
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
1411
|
+
*
|
|
1412
|
+
* @example
|
|
1413
|
+
* Basic invitation creation:
|
|
1414
|
+
* ```typescript
|
|
1415
|
+
* const invite = await createTenantUserInvite('tenant_123', {
|
|
1416
|
+
* email: 'colleague@company.com',
|
|
1417
|
+
* role: 'member'
|
|
1418
|
+
* });
|
|
1419
|
+
*
|
|
1420
|
+
* console.log(`Invite sent to: ${invite.data.invite.email}`);
|
|
1421
|
+
* // The invite token can be used to generate invitation links
|
|
1422
|
+
* const inviteLink = `https://app.com/accept-invite?token=${invite.data.invite.token}`;
|
|
1423
|
+
* ```
|
|
1424
|
+
*
|
|
1425
|
+
* @example
|
|
1426
|
+
* Creating admin invitation:
|
|
1427
|
+
* ```typescript
|
|
1428
|
+
* const adminInvite = await createTenantUserInvite('tenant_456', {
|
|
1429
|
+
* email: 'admin@company.com',
|
|
1430
|
+
* role: 'admin'
|
|
1431
|
+
* });
|
|
1432
|
+
*
|
|
1433
|
+
* // Admin users get elevated permissions
|
|
1434
|
+
* console.log(`Admin invite created with ID: ${adminInvite.data.invite.id}`);
|
|
1435
|
+
* ```
|
|
1436
|
+
*
|
|
1437
|
+
*
|
|
1438
|
+
* @since 1.0.0
|
|
1439
|
+
* @public
|
|
1440
|
+
* @group User Management
|
|
1441
|
+
*/
|
|
1442
|
+
create(tenantId: string, inviteData: CreateTenantUserInviteRequest): Promise<CreateTenantUserInviteResponse>;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
/**
|
|
1446
|
+
* Response structure for switching the active tenant
|
|
1447
|
+
*
|
|
1448
|
+
* Contains a new JWT token that includes the updated tenant context
|
|
1449
|
+
* and a confirmation message. The new token should replace the previous
|
|
1450
|
+
* token for all subsequent API calls to ensure requests are made within
|
|
1451
|
+
* the context of the newly active tenant.
|
|
1452
|
+
*
|
|
1453
|
+
* The token includes updated tenant-specific claims and permissions,
|
|
1454
|
+
* ensuring that row-level security policies are enforced correctly
|
|
1455
|
+
* for the new active tenant context.
|
|
1456
|
+
*
|
|
1457
|
+
* @example
|
|
1458
|
+
* ```typescript
|
|
1459
|
+
* const response: SwitchActiveTenantResponse = {
|
|
1460
|
+
* data: {
|
|
1461
|
+
* token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
|
1462
|
+
* message: 'Active tenant switched successfully'
|
|
1463
|
+
* },
|
|
1464
|
+
* status: 200
|
|
1465
|
+
* };
|
|
1466
|
+
* ```
|
|
1467
|
+
*
|
|
1468
|
+
* @since 1.0.0
|
|
1469
|
+
* @public
|
|
1470
|
+
* @group Tenant Management
|
|
1471
|
+
*/
|
|
1472
|
+
type SwitchActiveTenantResponse = ApiResponse<{
|
|
1473
|
+
/** New JWT token with updated tenant context */
|
|
1474
|
+
token: string;
|
|
1475
|
+
/** Success message confirming the tenant switch */
|
|
1476
|
+
message: string;
|
|
1477
|
+
}>;
|
|
1478
|
+
/**
|
|
1479
|
+
* Response structure for deleting a tenant
|
|
1480
|
+
*
|
|
1481
|
+
* Contains a confirmation message indicating successful tenant deletion.
|
|
1482
|
+
* This response is only returned after the tenant and all associated data
|
|
1483
|
+
* have been permanently removed from the system.
|
|
1484
|
+
*
|
|
1485
|
+
* @example
|
|
1486
|
+
* ```typescript
|
|
1487
|
+
* const response: DeleteTenantResponse = {
|
|
1488
|
+
* data: {
|
|
1489
|
+
* message: 'Tenant deleted successfully'
|
|
1490
|
+
* },
|
|
1491
|
+
* status: 200
|
|
1492
|
+
* };
|
|
1493
|
+
* ```
|
|
1494
|
+
*
|
|
1495
|
+
* @since 1.0.0
|
|
1496
|
+
* @public
|
|
1497
|
+
* @group Tenant Management
|
|
1498
|
+
*/
|
|
1499
|
+
type DeleteTenantResponse = ApiResponse<{
|
|
1500
|
+
/** Confirmation message indicating successful deletion */
|
|
1501
|
+
message: string;
|
|
1502
|
+
}>;
|
|
1503
|
+
/**
|
|
1504
|
+
* Response structure for tenant creation operations
|
|
1505
|
+
*
|
|
1506
|
+
* Contains the newly created tenant information along with an authentication
|
|
1507
|
+
* token that provides Row-Level Security (RLS) access to the tenant's data.
|
|
1508
|
+
* The token should be stored securely and used for subsequent API calls
|
|
1509
|
+
* that require tenant-specific access.
|
|
1510
|
+
*
|
|
1511
|
+
* @example
|
|
1512
|
+
* ```typescript
|
|
1513
|
+
* const response: CreateTenantResponse = {
|
|
1514
|
+
* data: {
|
|
1515
|
+
* tenant: {
|
|
1516
|
+
* id: 'tenant_123',
|
|
1517
|
+
* name: 'My Company',
|
|
1518
|
+
* stripe_customer_id: 'cus_abc123'
|
|
1519
|
+
* },
|
|
1520
|
+
* message: 'Tenant created successfully',
|
|
1521
|
+
* token: 'eyJhbGciOiJIUzI1NiIs...'
|
|
1522
|
+
* },
|
|
1523
|
+
* status: 201
|
|
1524
|
+
* };
|
|
1525
|
+
* ```
|
|
1526
|
+
*
|
|
1527
|
+
* @since 1.0.0
|
|
1528
|
+
* @public
|
|
1529
|
+
* @group Tenant Management
|
|
1530
|
+
*/
|
|
1531
|
+
type CreateTenantResponse = ApiResponse<{
|
|
1532
|
+
/** The newly created tenant object */
|
|
1533
|
+
tenant: Tenant;
|
|
1534
|
+
/** Success message confirming tenant creation */
|
|
1535
|
+
message: string;
|
|
1536
|
+
/** JWT token for RLS policies specific to the active tenant */
|
|
1537
|
+
token: string;
|
|
181
1538
|
}>;
|
|
182
|
-
|
|
1539
|
+
/**
|
|
1540
|
+
* Tenant entity structure that maps to the database schema
|
|
1541
|
+
*
|
|
1542
|
+
* Represents a tenant in the multi-tenant system with billing integration
|
|
1543
|
+
* via Stripe. Each tenant can have multiple users with different roles
|
|
1544
|
+
* and maintains its own isolated data through RLS policies.
|
|
1545
|
+
*
|
|
1546
|
+
* @example
|
|
1547
|
+
* ```typescript
|
|
1548
|
+
* const tenant: Tenant = {
|
|
1549
|
+
* id: 'tenant_abc123',
|
|
1550
|
+
* name: 'Acme Corporation',
|
|
1551
|
+
* stripe_customer_id: 'cus_stripe123',
|
|
1552
|
+
* type: 'business',
|
|
1553
|
+
* created_at: '2024-01-15T10:30:00Z',
|
|
1554
|
+
* updated_at: '2024-01-15T10:30:00Z'
|
|
1555
|
+
* };
|
|
1556
|
+
* ```
|
|
1557
|
+
*
|
|
1558
|
+
* @since 1.0.0
|
|
1559
|
+
* @public
|
|
1560
|
+
* @group Tenant Management
|
|
1561
|
+
*/
|
|
1562
|
+
type Tenant = {
|
|
1563
|
+
/** Unique identifier for the tenant */
|
|
1564
|
+
id: string;
|
|
1565
|
+
/** Display name of the tenant organization */
|
|
1566
|
+
name: string;
|
|
1567
|
+
/** Associated Stripe customer ID for billing */
|
|
1568
|
+
stripe_customer_id: string;
|
|
1569
|
+
/** Type of tenant (e.g., 'individual', 'organization') */
|
|
1570
|
+
type: string;
|
|
1571
|
+
/** ISO 8601 timestamp when the tenant was created */
|
|
1572
|
+
created_at: string;
|
|
1573
|
+
/** ISO 8601 timestamp when the tenant was last updated */
|
|
1574
|
+
updated_at: string;
|
|
1575
|
+
};
|
|
1576
|
+
/**
|
|
1577
|
+
* Required data for creating a new tenant
|
|
1578
|
+
*
|
|
1579
|
+
* Contains the essential information needed to establish a new tenant
|
|
1580
|
+
* in the system, including billing setup and initial user assignment.
|
|
1581
|
+
*
|
|
1582
|
+
* @example
|
|
1583
|
+
* ```typescript
|
|
1584
|
+
* const tenantData: CreateTenantRequest = {
|
|
1585
|
+
* name: 'My New Company',
|
|
1586
|
+
* billing_email: 'billing@mynewcompany.com',
|
|
1587
|
+
* user_id: 'user_abc123'
|
|
1588
|
+
* };
|
|
1589
|
+
* ```
|
|
1590
|
+
*
|
|
1591
|
+
* @since 1.0.0
|
|
1592
|
+
* @public
|
|
1593
|
+
* @group Tenant Management
|
|
1594
|
+
*/
|
|
1595
|
+
type CreateTenantRequest = {
|
|
1596
|
+
/** Name of the tenant organization */
|
|
1597
|
+
name: string;
|
|
1598
|
+
/** Email address for billing notifications */
|
|
1599
|
+
billing_email: string;
|
|
1600
|
+
/** ID of the user who will own the tenant */
|
|
1601
|
+
user_id: string;
|
|
1602
|
+
};
|
|
1603
|
+
/**
|
|
1604
|
+
* Tenant management operations handler
|
|
1605
|
+
*
|
|
1606
|
+
* This class provides core tenant lifecycle management operations including
|
|
1607
|
+
* creation, deletion, and active tenant switching. It handles all the fundamental
|
|
1608
|
+
* operations needed to manage tenants in a multi-tenant application with
|
|
1609
|
+
* integrated billing and row-level security.
|
|
1610
|
+
*
|
|
1611
|
+
* The manager handles:
|
|
1612
|
+
* - Tenant creation with Stripe billing integration
|
|
1613
|
+
* - Secure tenant deletion with data cleanup
|
|
1614
|
+
* - Active tenant switching with JWT token management
|
|
1615
|
+
* - User permission validation for all operations
|
|
1616
|
+
*
|
|
1617
|
+
* All operations are performed within the authenticated user context and
|
|
1618
|
+
* respect tenant ownership and permission rules.
|
|
1619
|
+
*
|
|
1620
|
+
* @example
|
|
1621
|
+
* ```typescript
|
|
1622
|
+
* const tenantManager = new TenantManger(omnibaseClient);
|
|
1623
|
+
*
|
|
1624
|
+
* // Create a new tenant
|
|
1625
|
+
* const tenant = await tenantManager.createTenant({
|
|
1626
|
+
* name: 'Acme Corp',
|
|
1627
|
+
* billing_email: 'billing@acme.com',
|
|
1628
|
+
* user_id: 'user_123'
|
|
1629
|
+
* });
|
|
1630
|
+
*
|
|
1631
|
+
* // Switch to the new tenant
|
|
1632
|
+
* await tenantManager.switchActiveTenant(tenant.data.tenant.id);
|
|
1633
|
+
*
|
|
1634
|
+
* // Delete tenant (owner only)
|
|
1635
|
+
* await tenantManager.deleteTenant(tenant.data.tenant.id);
|
|
1636
|
+
* ```
|
|
1637
|
+
*
|
|
1638
|
+
* @since 1.0.0
|
|
1639
|
+
* @public
|
|
1640
|
+
* @group Tenant Management
|
|
1641
|
+
*/
|
|
1642
|
+
declare class TenantManger {
|
|
1643
|
+
private omnibaseClient;
|
|
1644
|
+
/**
|
|
1645
|
+
* Creates a new TenantManger instance
|
|
1646
|
+
*
|
|
1647
|
+
* Initializes the manager with the provided Omnibase client for making
|
|
1648
|
+
* authenticated API requests to tenant management endpoints.
|
|
1649
|
+
*
|
|
1650
|
+
* @param omnibaseClient - Configured Omnibase client instance
|
|
1651
|
+
*
|
|
1652
|
+
* @group Tenant Management
|
|
1653
|
+
*/
|
|
1654
|
+
constructor(omnibaseClient: OmnibaseClient);
|
|
1655
|
+
/**
|
|
1656
|
+
* Creates a new tenant in the multi-tenant system
|
|
1657
|
+
*
|
|
1658
|
+
* Establishes a new tenant with integrated Stripe billing setup and assigns
|
|
1659
|
+
* the specified user as the tenant owner. The operation creates the necessary
|
|
1660
|
+
* database records and returns a JWT token that enables Row-Level Security
|
|
1661
|
+
* access to the tenant's isolated data.
|
|
1662
|
+
*
|
|
1663
|
+
* The function automatically handles Stripe customer creation for billing
|
|
1664
|
+
* integration and sets up the initial tenant configuration. The returned
|
|
1665
|
+
* token should be stored securely for subsequent API calls.
|
|
1666
|
+
*
|
|
1667
|
+
* @param tenantData - Configuration object for the new tenant
|
|
1668
|
+
* @param tenantData.name - Display name for the tenant organization
|
|
1669
|
+
* @param tenantData.billing_email - Email address for Stripe billing notifications
|
|
1670
|
+
* @param tenantData.user_id - Unique identifier of the user who will own this tenant
|
|
1671
|
+
*
|
|
1672
|
+
* @returns Promise resolving to the created tenant with authentication token
|
|
1673
|
+
*
|
|
1674
|
+
* @throws {Error} When required fields (name, user_id) are missing or empty
|
|
1675
|
+
* @throws {Error} When the API request fails due to network issues
|
|
1676
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
1677
|
+
*
|
|
1678
|
+
* @example
|
|
1679
|
+
* Basic tenant creation:
|
|
1680
|
+
* ```typescript
|
|
1681
|
+
* const newTenant = await createTenant({
|
|
1682
|
+
* name: 'Acme Corporation',
|
|
1683
|
+
* billing_email: 'billing@acme.com',
|
|
1684
|
+
* user_id: 'user_123'
|
|
1685
|
+
* });
|
|
1686
|
+
*
|
|
1687
|
+
* console.log(`Created tenant: ${newTenant.data.tenant.name}`);
|
|
1688
|
+
* // Store the token for authenticated requests
|
|
1689
|
+
* localStorage.setItem('tenant_token', newTenant.data.token);
|
|
1690
|
+
* ```
|
|
1691
|
+
*
|
|
1692
|
+
*
|
|
1693
|
+
* @since 1.0.0
|
|
1694
|
+
* @public
|
|
1695
|
+
* @group Tenant Management
|
|
1696
|
+
*/
|
|
1697
|
+
createTenant(tenantData: CreateTenantRequest): Promise<CreateTenantResponse>;
|
|
1698
|
+
/**
|
|
1699
|
+
* Permanently deletes a tenant and all associated data
|
|
1700
|
+
*
|
|
1701
|
+
* ⚠️ **WARNING: This operation is irreversible and will permanently delete:**
|
|
1702
|
+
* - The tenant record and all metadata
|
|
1703
|
+
* - All user memberships and invitations for this tenant
|
|
1704
|
+
* - All tenant-specific data protected by row-level security
|
|
1705
|
+
* - Any tenant-related billing information
|
|
1706
|
+
* - All tenant configuration and settings
|
|
1707
|
+
*
|
|
1708
|
+
* **Access Control:**
|
|
1709
|
+
* Only tenant owners can delete a tenant. This operation requires:
|
|
1710
|
+
* - User must be authenticated
|
|
1711
|
+
* - User must have 'owner' role for the specified tenant
|
|
1712
|
+
* - Tenant must exist and be accessible to the user
|
|
1713
|
+
*
|
|
1714
|
+
* **Security Considerations:**
|
|
1715
|
+
* - All tenant data is immediately and permanently removed
|
|
1716
|
+
* - Other tenant members lose access immediately
|
|
1717
|
+
* - Any active sessions for this tenant are invalidated
|
|
1718
|
+
* - Billing subscriptions are cancelled (if applicable)
|
|
1719
|
+
* - Audit logs for deletion are maintained for compliance
|
|
1720
|
+
*
|
|
1721
|
+
* @param tenantId - The unique identifier of the tenant to delete
|
|
1722
|
+
*
|
|
1723
|
+
* @returns Promise resolving to a confirmation message
|
|
1724
|
+
*
|
|
1725
|
+
* @throws {Error} When the tenantId parameter is missing or empty
|
|
1726
|
+
* @throws {Error} When the user is not authenticated
|
|
1727
|
+
* @throws {Error} When the user is not an owner of the specified tenant
|
|
1728
|
+
* @throws {Error} When the tenant doesn't exist or is not accessible
|
|
1729
|
+
* @throws {Error} When the API request fails due to network issues
|
|
1730
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
1731
|
+
*
|
|
1732
|
+
* @example
|
|
1733
|
+
* Basic tenant deletion with confirmation:
|
|
1734
|
+
* ```typescript
|
|
1735
|
+
* const tenantToDelete = 'tenant_abc123';
|
|
1736
|
+
*
|
|
1737
|
+
* // Always confirm before deleting
|
|
1738
|
+
* const userConfirmed = confirm(
|
|
1739
|
+
* 'Are you sure you want to delete this tenant? This action cannot be undone.'
|
|
1740
|
+
* );
|
|
1741
|
+
*
|
|
1742
|
+
* if (userConfirmed) {
|
|
1743
|
+
* try {
|
|
1744
|
+
* const result = await deleteTenant(tenantToDelete);
|
|
1745
|
+
* console.log(result.data.message); // "Tenant deleted successfully"
|
|
1746
|
+
*
|
|
1747
|
+
* // Redirect user away from deleted tenant
|
|
1748
|
+
* window.location.href = '/dashboard';
|
|
1749
|
+
* } catch (error) {
|
|
1750
|
+
* console.error('Failed to delete tenant:', error);
|
|
1751
|
+
* }
|
|
1752
|
+
* }
|
|
1753
|
+
* ```
|
|
1754
|
+
*
|
|
1755
|
+
* @since 1.0.0
|
|
1756
|
+
* @public
|
|
1757
|
+
* @group Tenant Management
|
|
1758
|
+
*/
|
|
1759
|
+
deleteTenant(tenantId: string): Promise<DeleteTenantResponse>;
|
|
1760
|
+
/**
|
|
1761
|
+
* Switches the user's active tenant context
|
|
1762
|
+
*
|
|
1763
|
+
* Changes the user's active tenant to the specified tenant ID, updating
|
|
1764
|
+
* their authentication context and permissions. This function is essential
|
|
1765
|
+
* for multi-tenant applications where users belong to multiple tenants
|
|
1766
|
+
* and need to switch between them.
|
|
1767
|
+
*
|
|
1768
|
+
* The function performs several operations:
|
|
1769
|
+
* - Validates that the user has access to the specified tenant
|
|
1770
|
+
* - Updates the user's active tenant in their session
|
|
1771
|
+
* - Generates a new JWT token with updated tenant claims
|
|
1772
|
+
* - Updates any cached tenant-specific data
|
|
1773
|
+
*
|
|
1774
|
+
* After switching tenants, all subsequent API calls will be made within
|
|
1775
|
+
* the context of the new active tenant, with row-level security policies
|
|
1776
|
+
* applied accordingly. The new JWT token should be used for all future
|
|
1777
|
+
* authenticated requests.
|
|
1778
|
+
*
|
|
1779
|
+
* @param tenantId - The ID of the tenant to switch to (must be a tenant the user belongs to)
|
|
1780
|
+
*
|
|
1781
|
+
* @returns Promise resolving to a new JWT token and success confirmation
|
|
1782
|
+
*
|
|
1783
|
+
* @throws {Error} When the tenantId parameter is missing or empty
|
|
1784
|
+
* @throws {Error} When the user doesn't have access to the specified tenant
|
|
1785
|
+
* @throws {Error} When the user is not authenticated
|
|
1786
|
+
* @throws {Error} When the specified tenant doesn't exist
|
|
1787
|
+
* @throws {Error} When the API request fails due to network issues
|
|
1788
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
1789
|
+
*
|
|
1790
|
+
* @example
|
|
1791
|
+
* Basic tenant switching:
|
|
1792
|
+
* ```typescript
|
|
1793
|
+
* const result = await switchActiveTenant('tenant_xyz789');
|
|
1794
|
+
*
|
|
1795
|
+
* // Now all API calls will be in the context of tenant_xyz789
|
|
1796
|
+
* const tenantData = await getCurrentTenantData();
|
|
1797
|
+
* ```
|
|
1798
|
+
*
|
|
1799
|
+
* @example
|
|
1800
|
+
* Using with tenant-aware data fetching:
|
|
1801
|
+
* ```typescript
|
|
1802
|
+
* // Switch tenant and immediately fetch tenant-specific data
|
|
1803
|
+
* const switchAndLoadTenant = async (tenantId: string) => {
|
|
1804
|
+
* try {
|
|
1805
|
+
* // Switch to new tenant context
|
|
1806
|
+
* const switchResult = await switchActiveTenant(tenantId);
|
|
1807
|
+
*
|
|
1808
|
+
* // Update authentication token
|
|
1809
|
+
* setAuthToken(switchResult.data.token);
|
|
1810
|
+
*
|
|
1811
|
+
* // Fetch data in new tenant context
|
|
1812
|
+
* const [tenantInfo, userPermissions, tenantSettings] = await Promise.all([
|
|
1813
|
+
* getTenantInfo(),
|
|
1814
|
+
* getUserPermissions(),
|
|
1815
|
+
* getTenantSettings()
|
|
1816
|
+
* ]);
|
|
1817
|
+
*
|
|
1818
|
+
* return {
|
|
1819
|
+
* tenant: tenantInfo,
|
|
1820
|
+
* permissions: userPermissions,
|
|
1821
|
+
* settings: tenantSettings
|
|
1822
|
+
* };
|
|
1823
|
+
* } catch (error) {
|
|
1824
|
+
* console.error('Failed to switch tenant and load data:', error);
|
|
1825
|
+
* throw error;
|
|
1826
|
+
* }
|
|
1827
|
+
* };
|
|
1828
|
+
* ```
|
|
1829
|
+
*
|
|
1830
|
+
* @since 1.0.0
|
|
1831
|
+
* @public
|
|
1832
|
+
* @group Tenant Management
|
|
1833
|
+
*/
|
|
1834
|
+
switchActiveTenant(tenantId: string): Promise<SwitchActiveTenantResponse>;
|
|
1835
|
+
}
|
|
183
1836
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
1837
|
+
/**
|
|
1838
|
+
* Main tenant management handler
|
|
1839
|
+
*
|
|
1840
|
+
* This is the primary entry point for all tenant-related operations in the
|
|
1841
|
+
* Omnibase SDK. It provides a unified interface to both tenant management
|
|
1842
|
+
* and invitation functionality through dedicated manager instances.
|
|
1843
|
+
*
|
|
1844
|
+
* The handler follows the composition pattern, combining specialized managers
|
|
1845
|
+
* for different aspects of tenant functionality:
|
|
1846
|
+
* - `tenants`: Core tenant operations (create, delete, switch)
|
|
1847
|
+
* - `invites`: User invitation management (create, accept)
|
|
1848
|
+
*
|
|
1849
|
+
* All operations are performed within the context of the authenticated user
|
|
1850
|
+
* and respect tenant-level permissions and row-level security policies.
|
|
1851
|
+
*
|
|
1852
|
+
* @example
|
|
1853
|
+
* ```typescript
|
|
1854
|
+
* import { OmnibaseClient } from '@omnibase/core-js';
|
|
1855
|
+
* import { TenantHandler } from '@omnibase/core-js/tenants';
|
|
1856
|
+
*
|
|
1857
|
+
* const client = new OmnibaseClient({ apiKey: 'your-api-key' });
|
|
1858
|
+
* const tenantHandler = new TenantHandler(client);
|
|
1859
|
+
*
|
|
1860
|
+
* // Create a new tenant
|
|
1861
|
+
* const tenant = await tenantHandler.tenants.createTenant({
|
|
1862
|
+
* name: 'My Company',
|
|
1863
|
+
* billing_email: 'billing@company.com',
|
|
1864
|
+
* user_id: 'user_123'
|
|
1865
|
+
* });
|
|
1866
|
+
*
|
|
1867
|
+
* // Invite users to the tenant
|
|
1868
|
+
* const invite = await tenantHandler.invites.create(tenant.data.tenant.id, {
|
|
1869
|
+
* email: 'colleague@company.com',
|
|
1870
|
+
* role: 'member'
|
|
1871
|
+
* });
|
|
1872
|
+
*
|
|
1873
|
+
* // Switch to the new tenant
|
|
1874
|
+
* await tenantHandler.tenants.switchActiveTenant(tenant.data.tenant.id);
|
|
1875
|
+
* ```
|
|
1876
|
+
*
|
|
1877
|
+
* @since 1.0.0
|
|
1878
|
+
* @public
|
|
1879
|
+
* @group Tenant Management
|
|
1880
|
+
*/
|
|
1881
|
+
declare class TenantHandler {
|
|
1882
|
+
private omnibaseClient;
|
|
1883
|
+
/**
|
|
1884
|
+
* Creates a new TenantHandler instance
|
|
1885
|
+
*
|
|
1886
|
+
* Initializes the handler with the provided Omnibase client and sets up
|
|
1887
|
+
* the specialized manager instances for tenant and invitation operations.
|
|
1888
|
+
* The client is used for all underlying HTTP requests and authentication.
|
|
1889
|
+
*
|
|
1890
|
+
* @param omnibaseClient - Configured Omnibase client instance
|
|
1891
|
+
*
|
|
1892
|
+
* @example
|
|
1893
|
+
* ```typescript
|
|
1894
|
+
* const client = new OmnibaseClient({
|
|
1895
|
+
* apiKey: 'your-api-key',
|
|
1896
|
+
* baseURL: 'https://api.yourapp.com'
|
|
1897
|
+
* });
|
|
1898
|
+
* const tenantHandler = new TenantHandler(client);
|
|
1899
|
+
* ```
|
|
1900
|
+
*
|
|
1901
|
+
* @group Tenant Management
|
|
1902
|
+
*/
|
|
1903
|
+
constructor(omnibaseClient: OmnibaseClient);
|
|
1904
|
+
/**
|
|
1905
|
+
* Core tenant management operations
|
|
1906
|
+
*
|
|
1907
|
+
* Provides access to tenant lifecycle operations including creation,
|
|
1908
|
+
* deletion, and active tenant switching. All operations respect user
|
|
1909
|
+
* permissions and tenant ownership rules.
|
|
1910
|
+
*
|
|
1911
|
+
* @example
|
|
1912
|
+
* ```typescript
|
|
1913
|
+
* // Create a new tenant
|
|
1914
|
+
* const tenant = await tenantHandler.tenants.createTenant({
|
|
1915
|
+
* name: 'New Company',
|
|
1916
|
+
* billing_email: 'billing@newcompany.com',
|
|
1917
|
+
* user_id: 'user_456'
|
|
1918
|
+
* });
|
|
1919
|
+
*
|
|
1920
|
+
* // Switch to the tenant
|
|
1921
|
+
* await tenantHandler.tenants.switchActiveTenant(tenant.data.tenant.id);
|
|
1922
|
+
*
|
|
1923
|
+
* // Delete the tenant (owner only)
|
|
1924
|
+
* await tenantHandler.tenants.deleteTenant(tenant.data.tenant.id);
|
|
1925
|
+
* ```
|
|
1926
|
+
*/
|
|
1927
|
+
readonly tenants: TenantManger;
|
|
1928
|
+
/**
|
|
1929
|
+
* Tenant invitation management operations
|
|
1930
|
+
*
|
|
1931
|
+
* Provides access to user invitation functionality including creating
|
|
1932
|
+
* invitations for new users and accepting existing invitations.
|
|
1933
|
+
* Supports role-based access control and secure token-based workflows.
|
|
1934
|
+
*
|
|
1935
|
+
* @example
|
|
1936
|
+
* ```typescript
|
|
1937
|
+
* // Create an invitation
|
|
1938
|
+
* const invite = await tenantHandler.invites.create('tenant_123', {
|
|
1939
|
+
* email: 'newuser@company.com',
|
|
1940
|
+
* role: 'admin'
|
|
1941
|
+
* });
|
|
1942
|
+
*
|
|
1943
|
+
* // Accept an invitation (from the invited user's session)
|
|
1944
|
+
* const result = await tenantHandler.invites.accept('invite_token_xyz');
|
|
1945
|
+
* ```
|
|
1946
|
+
*/
|
|
1947
|
+
readonly invites: TenantInviteManager;
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
type OmnibaseClientConfig = {
|
|
1951
|
+
api_url: string;
|
|
188
1952
|
};
|
|
189
|
-
declare
|
|
1953
|
+
declare class OmnibaseClient {
|
|
1954
|
+
private config;
|
|
1955
|
+
constructor(config: OmnibaseClientConfig);
|
|
1956
|
+
/**
|
|
1957
|
+
* Main payment handler for all payment-related operations
|
|
1958
|
+
*
|
|
1959
|
+
* This class serves as the central coordinator for all payment functionality,
|
|
1960
|
+
* providing access to checkout sessions, billing configuration, customer portals,
|
|
1961
|
+
* and usage tracking. It handles the low-level HTTP communication with the
|
|
1962
|
+
* payment API and delegates specific operations to specialized managers.
|
|
1963
|
+
*
|
|
1964
|
+
* The handler automatically manages authentication, request formatting, and
|
|
1965
|
+
* provides a consistent interface across all payment operations.
|
|
1966
|
+
*
|
|
1967
|
+
* @example
|
|
1968
|
+
* ```typescript
|
|
1969
|
+
* // Create a checkout session
|
|
1970
|
+
* const checkout = await omnibase.payments.checkout.createSession({
|
|
1971
|
+
* price_id: 'price_123',
|
|
1972
|
+
* mode: 'subscription',
|
|
1973
|
+
* success_url: 'https://app.com/success',
|
|
1974
|
+
* cancel_url: 'https://app.com/cancel'
|
|
1975
|
+
* });
|
|
1976
|
+
*
|
|
1977
|
+
* // Get available products
|
|
1978
|
+
* const products = await omnibase.payments.config.getAvailableProducts();
|
|
1979
|
+
* ```
|
|
1980
|
+
*/
|
|
1981
|
+
readonly payments: PaymentHandler;
|
|
1982
|
+
readonly tenants: TenantHandler;
|
|
1983
|
+
readonly permissions: PermissionsClient;
|
|
1984
|
+
fetch(endpoint: string, options?: RequestInit): Promise<Response>;
|
|
1985
|
+
}
|
|
190
1986
|
|
|
191
|
-
export { type CheckoutOptions, type CreateCheckoutResponse, type CreateCustomerPortalResponse, type PortalOptions, type Price, type PriceDisplay, type PriceLimit, type PriceUI, type Product, type ProductUI, type ProductWithPricingUI, type StripeConfigResponse, type StripeConfiguration, type Tier, type UsageOptions,
|
|
1987
|
+
export { type AcceptTenantInviteRequest as A, type CreateTenantUserInviteResponse as C, CheckoutManager, type CheckoutOptions, ConfigManager, type CreateCheckoutResponse, type CreateCustomerPortalResponse, type DeleteTenantResponse as D, type OmnibaseClientConfig as O, PaymentHandler, PortalManager, type PortalOptions, type Price, type PriceDisplay, type PriceLimit, type PriceUI, type Product, type ProductUI, type ProductWithPricingUI, type SwitchActiveTenantResponse as S, type StripeConfigResponse, type StripeConfiguration, TenantHandler as T, type Tier, UsageManager, type UsageOptions, type AcceptTenantInviteResponse as a, type TenantInvite as b, type CreateTenantUserInviteRequest as c, TenantInviteManager as d, type CreateTenantResponse as e, type Tenant as f, type CreateTenantRequest as g, TenantManger as h, OmnibaseClient as i };
|