@omnibase/core-js 0.7.4 → 0.7.6
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-TFAV5P6I.js +869 -0
- package/dist/chunk-V6HVRJCU.js +693 -0
- package/dist/index.cjs +228 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/payments/index.d.cts +323 -1
- package/dist/payments/index.d.ts +323 -1
- package/dist/tenants/index.cjs +228 -0
- package/dist/tenants/index.d.cts +1 -1
- package/dist/tenants/index.d.ts +1 -1
- package/dist/tenants/index.js +1 -1
- package/package.json +1 -1
package/dist/payments/index.d.ts
CHANGED
|
@@ -2440,6 +2440,263 @@ declare class TenantManger {
|
|
|
2440
2440
|
switchActiveTenant(tenantId: string): Promise<SwitchActiveTenantResponse>;
|
|
2441
2441
|
}
|
|
2442
2442
|
|
|
2443
|
+
/**
|
|
2444
|
+
* Active subscription data returned from the API
|
|
2445
|
+
*
|
|
2446
|
+
* Represents a tenant's active Stripe subscription with config-based price IDs
|
|
2447
|
+
* instead of raw Stripe IDs. Includes legacy price detection for historical
|
|
2448
|
+
* billing configurations.
|
|
2449
|
+
*
|
|
2450
|
+
* @example
|
|
2451
|
+
* ```typescript
|
|
2452
|
+
* const subscription: TenantSubscription = {
|
|
2453
|
+
* subscription_id: 'sub_1234567890',
|
|
2454
|
+
* config_price_id: 'price_pro_monthly',
|
|
2455
|
+
* status: 'active',
|
|
2456
|
+
* is_legacy_price: false,
|
|
2457
|
+
* current_period_end: 1735416000
|
|
2458
|
+
* };
|
|
2459
|
+
* ```
|
|
2460
|
+
*
|
|
2461
|
+
* @since 0.6.0
|
|
2462
|
+
* @public
|
|
2463
|
+
* @group Tenant Subscriptions
|
|
2464
|
+
*/
|
|
2465
|
+
type TenantSubscription = {
|
|
2466
|
+
/** Stripe subscription ID */
|
|
2467
|
+
subscription_id: string;
|
|
2468
|
+
/** Config-based price ID from your billing configuration */
|
|
2469
|
+
config_price_id: string;
|
|
2470
|
+
/** Subscription status (active, trialing, past_due) */
|
|
2471
|
+
status: string;
|
|
2472
|
+
/** Whether this price is from a legacy billing configuration */
|
|
2473
|
+
is_legacy_price: boolean;
|
|
2474
|
+
/** Unix timestamp when the current billing period ends */
|
|
2475
|
+
current_period_end: number;
|
|
2476
|
+
};
|
|
2477
|
+
/**
|
|
2478
|
+
* Response structure for getting active subscriptions
|
|
2479
|
+
*
|
|
2480
|
+
* @since 0.6.0
|
|
2481
|
+
* @public
|
|
2482
|
+
* @group Tenant Subscriptions
|
|
2483
|
+
*/
|
|
2484
|
+
type GetActiveSubscriptionsResponse = ApiResponse<TenantSubscription[]>;
|
|
2485
|
+
/**
|
|
2486
|
+
* Billing status information for a tenant
|
|
2487
|
+
*
|
|
2488
|
+
* Indicates whether the tenant has valid billing information configured
|
|
2489
|
+
* in their Stripe customer account.
|
|
2490
|
+
*
|
|
2491
|
+
* @example
|
|
2492
|
+
* ```typescript
|
|
2493
|
+
* const status: BillingStatus = {
|
|
2494
|
+
* has_billing_info: true,
|
|
2495
|
+
* is_active: true
|
|
2496
|
+
* };
|
|
2497
|
+
* ```
|
|
2498
|
+
*
|
|
2499
|
+
* @since 0.6.0
|
|
2500
|
+
* @public
|
|
2501
|
+
* @group Tenant Subscriptions
|
|
2502
|
+
*/
|
|
2503
|
+
type BillingStatus = {
|
|
2504
|
+
/** Whether the tenant has payment method(s) configured */
|
|
2505
|
+
has_billing_info: boolean;
|
|
2506
|
+
/** Whether the billing information is active and valid */
|
|
2507
|
+
is_active: boolean;
|
|
2508
|
+
};
|
|
2509
|
+
/**
|
|
2510
|
+
* Response structure for billing status check
|
|
2511
|
+
*
|
|
2512
|
+
* @since 0.6.0
|
|
2513
|
+
* @public
|
|
2514
|
+
* @group Tenant Subscriptions
|
|
2515
|
+
*/
|
|
2516
|
+
type GetBillingStatusResponse = ApiResponse<BillingStatus>;
|
|
2517
|
+
/**
|
|
2518
|
+
* Tenant subscription and billing management
|
|
2519
|
+
*
|
|
2520
|
+
* Provides access to the active tenant's Stripe subscriptions and billing
|
|
2521
|
+
* status. All operations are automatically scoped to the user's currently
|
|
2522
|
+
* active tenant via session authentication.
|
|
2523
|
+
*
|
|
2524
|
+
* Key features:
|
|
2525
|
+
* - View all active subscriptions with config-based price IDs
|
|
2526
|
+
* - Legacy price detection for historical billing configurations
|
|
2527
|
+
* - Billing status verification (payment method availability)
|
|
2528
|
+
* - Automatic tenant scoping via session context
|
|
2529
|
+
*
|
|
2530
|
+
* @example
|
|
2531
|
+
* ```typescript
|
|
2532
|
+
* const subscriptionManager = new TenantSubscriptionManager(omnibaseClient);
|
|
2533
|
+
*
|
|
2534
|
+
* // Get all active subscriptions for the current tenant
|
|
2535
|
+
* const subscriptions = await subscriptionManager.getActive();
|
|
2536
|
+
* console.log(`Active subscriptions: ${subscriptions.data.length}`);
|
|
2537
|
+
*
|
|
2538
|
+
* // Check if tenant has billing configured
|
|
2539
|
+
* const status = await subscriptionManager.getBillingStatus();
|
|
2540
|
+
* if (!status.data.has_billing_info) {
|
|
2541
|
+
* console.log('Please add a payment method');
|
|
2542
|
+
* }
|
|
2543
|
+
* ```
|
|
2544
|
+
*
|
|
2545
|
+
* @since 0.6.0
|
|
2546
|
+
* @public
|
|
2547
|
+
* @group Tenant Subscriptions
|
|
2548
|
+
*/
|
|
2549
|
+
declare class TenantSubscriptionManager {
|
|
2550
|
+
private omnibaseClient;
|
|
2551
|
+
/**
|
|
2552
|
+
* Creates a new TenantSubscriptionManager instance
|
|
2553
|
+
*
|
|
2554
|
+
* @param omnibaseClient - Configured Omnibase client instance
|
|
2555
|
+
*
|
|
2556
|
+
* @group Tenant Subscriptions
|
|
2557
|
+
*/
|
|
2558
|
+
constructor(omnibaseClient: OmnibaseClient);
|
|
2559
|
+
/**
|
|
2560
|
+
* Get all active subscriptions for the current tenant
|
|
2561
|
+
*
|
|
2562
|
+
* Retrieves all active Stripe subscriptions associated with the user's
|
|
2563
|
+
* currently active tenant. Returns subscriptions with config-based price IDs
|
|
2564
|
+
* instead of raw Stripe IDs, making it easier to match against your billing
|
|
2565
|
+
* configuration.
|
|
2566
|
+
*
|
|
2567
|
+
* The endpoint automatically:
|
|
2568
|
+
* - Fetches subscriptions from Stripe API
|
|
2569
|
+
* - Maps Stripe price IDs to your config price IDs
|
|
2570
|
+
* - Checks both current and historical price mappings
|
|
2571
|
+
* - Flags legacy prices from old billing configurations
|
|
2572
|
+
* - Filters to only active/trialing/past_due subscriptions
|
|
2573
|
+
*
|
|
2574
|
+
* Returns an empty array if:
|
|
2575
|
+
* - Tenant has no Stripe customer ID configured
|
|
2576
|
+
* - Tenant has no active subscriptions
|
|
2577
|
+
* - User is not authenticated
|
|
2578
|
+
*
|
|
2579
|
+
* @returns Promise resolving to array of active subscriptions
|
|
2580
|
+
*
|
|
2581
|
+
* @throws {Error} When the user is not authenticated
|
|
2582
|
+
* @throws {Error} When the API request fails due to network issues
|
|
2583
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx)
|
|
2584
|
+
*
|
|
2585
|
+
* @example
|
|
2586
|
+
* ```typescript
|
|
2587
|
+
* const response = await subscriptionManager.getActive();
|
|
2588
|
+
*
|
|
2589
|
+
* if (response.data.length === 0) {
|
|
2590
|
+
* console.log('No active subscriptions');
|
|
2591
|
+
* } else {
|
|
2592
|
+
* response.data.forEach(sub => {
|
|
2593
|
+
* console.log(`Plan: ${sub.config_price_id}`);
|
|
2594
|
+
* console.log(`Status: ${sub.status}`);
|
|
2595
|
+
* if (sub.is_legacy_price) {
|
|
2596
|
+
* console.log('⚠️ Using legacy pricing');
|
|
2597
|
+
* }
|
|
2598
|
+
* });
|
|
2599
|
+
* }
|
|
2600
|
+
* ```
|
|
2601
|
+
*
|
|
2602
|
+
* @since 0.6.0
|
|
2603
|
+
* @public
|
|
2604
|
+
* @group Tenant Subscriptions
|
|
2605
|
+
*/
|
|
2606
|
+
getActive(): Promise<GetActiveSubscriptionsResponse>;
|
|
2607
|
+
/**
|
|
2608
|
+
* Check if the current tenant has billing information configured
|
|
2609
|
+
*
|
|
2610
|
+
* Verifies whether the tenant has valid payment methods attached to their
|
|
2611
|
+
* Stripe customer account. This is useful for:
|
|
2612
|
+
* - Showing billing setup prompts
|
|
2613
|
+
* - Gating premium features behind payment method requirement
|
|
2614
|
+
* - Displaying billing status indicators in UI
|
|
2615
|
+
* - Determining if customer portal access should be shown
|
|
2616
|
+
*
|
|
2617
|
+
* The check verifies:
|
|
2618
|
+
* - Default payment source (card, bank account, etc.)
|
|
2619
|
+
* - Default payment method in invoice settings
|
|
2620
|
+
* - Whether the payment method is valid and active
|
|
2621
|
+
*
|
|
2622
|
+
* Returns `false` if:
|
|
2623
|
+
* - Tenant has no Stripe customer ID
|
|
2624
|
+
* - No payment methods are configured
|
|
2625
|
+
* - User is not authenticated
|
|
2626
|
+
*
|
|
2627
|
+
* @returns Promise resolving to billing status information
|
|
2628
|
+
*
|
|
2629
|
+
* @throws {Error} When the user is not authenticated
|
|
2630
|
+
* @throws {Error} When the API request fails due to network issues
|
|
2631
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx)
|
|
2632
|
+
*
|
|
2633
|
+
* @example
|
|
2634
|
+
* ```typescript
|
|
2635
|
+
* const response = await subscriptionManager.getBillingStatus();
|
|
2636
|
+
*
|
|
2637
|
+
* if (!response.data.has_billing_info) {
|
|
2638
|
+
* // Show billing setup prompt
|
|
2639
|
+
* showBillingSetupModal();
|
|
2640
|
+
* } else if (!response.data.is_active) {
|
|
2641
|
+
* // Payment method exists but may be expired/invalid
|
|
2642
|
+
* showPaymentMethodUpdatePrompt();
|
|
2643
|
+
* } else {
|
|
2644
|
+
* // All good - show customer portal link
|
|
2645
|
+
* showManageBillingButton();
|
|
2646
|
+
* }
|
|
2647
|
+
* ```
|
|
2648
|
+
*
|
|
2649
|
+
* @since 0.6.0
|
|
2650
|
+
* @public
|
|
2651
|
+
* @group Tenant Subscriptions
|
|
2652
|
+
*/
|
|
2653
|
+
getBillingStatus(): Promise<GetBillingStatusResponse>;
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2656
|
+
/**
|
|
2657
|
+
* Response structure for a tenant user
|
|
2658
|
+
*
|
|
2659
|
+
* Represents a user's information within a tenant, including their
|
|
2660
|
+
* identification details and assigned role.
|
|
2661
|
+
*
|
|
2662
|
+
* @example
|
|
2663
|
+
* ```typescript
|
|
2664
|
+
* const user: TenantUser = {
|
|
2665
|
+
* user_id: 'user_abc123',
|
|
2666
|
+
* first_name: 'John',
|
|
2667
|
+
* last_name: 'Doe',
|
|
2668
|
+
* email: 'john@example.com',
|
|
2669
|
+
* role: 'admin'
|
|
2670
|
+
* };
|
|
2671
|
+
* ```
|
|
2672
|
+
*
|
|
2673
|
+
* @since 1.0.0
|
|
2674
|
+
* @public
|
|
2675
|
+
* @group Tenant User Management
|
|
2676
|
+
*/
|
|
2677
|
+
type TenantUser = {
|
|
2678
|
+
/** Unique identifier for the user */
|
|
2679
|
+
user_id: string;
|
|
2680
|
+
/** User's first name */
|
|
2681
|
+
first_name: string;
|
|
2682
|
+
/** User's last name */
|
|
2683
|
+
last_name: string;
|
|
2684
|
+
/** User's email address */
|
|
2685
|
+
email: string;
|
|
2686
|
+
/** User's role within the tenant */
|
|
2687
|
+
role: string;
|
|
2688
|
+
};
|
|
2689
|
+
/**
|
|
2690
|
+
* Response from fetching all users in a tenant
|
|
2691
|
+
*
|
|
2692
|
+
* This type represents the API response structure returned when fetching
|
|
2693
|
+
* the list of all users in the active tenant.
|
|
2694
|
+
*
|
|
2695
|
+
* @since 1.0.0
|
|
2696
|
+
* @public
|
|
2697
|
+
* @group Tenant User Management
|
|
2698
|
+
*/
|
|
2699
|
+
type GetAllUsersResponse = ApiResponse<TenantUser[]>;
|
|
2443
2700
|
/**
|
|
2444
2701
|
* Request parameters for updating a user's role within a tenant
|
|
2445
2702
|
*
|
|
@@ -2536,6 +2793,47 @@ declare class TenantUserManager {
|
|
|
2536
2793
|
* @group Tenant User Management
|
|
2537
2794
|
*/
|
|
2538
2795
|
constructor(omnibaseClient: OmnibaseClient);
|
|
2796
|
+
/**
|
|
2797
|
+
* Retrieves all users in the active tenant
|
|
2798
|
+
*
|
|
2799
|
+
* This method fetches a list of all users who are members of the current active tenant,
|
|
2800
|
+
* including their basic information (name, email) and assigned role. The operation
|
|
2801
|
+
* requires the requesting user to have appropriate permissions to view tenant users
|
|
2802
|
+
* (typically requires `view_users` permission).
|
|
2803
|
+
*
|
|
2804
|
+
* The returned list includes all tenant members regardless of their role, ordered by
|
|
2805
|
+
* when they joined the tenant (newest first).
|
|
2806
|
+
*
|
|
2807
|
+
* @returns Promise resolving to an array of tenant users with their details
|
|
2808
|
+
*
|
|
2809
|
+
* @throws {Error} When the API request fails (includes status code and error details)
|
|
2810
|
+
* @throws {Error} When the user doesn't have permission to view users
|
|
2811
|
+
* @throws {Error} When the user is not authenticated or no active tenant is set
|
|
2812
|
+
*
|
|
2813
|
+
* @example
|
|
2814
|
+
* ```typescript
|
|
2815
|
+
* // Fetch all users in the active tenant
|
|
2816
|
+
* try {
|
|
2817
|
+
* const result = await userManager.getAll();
|
|
2818
|
+
* console.log(`Found ${result.data.length} users`);
|
|
2819
|
+
*
|
|
2820
|
+
* result.data.forEach(user => {
|
|
2821
|
+
* console.log(`${user.first_name} ${user.last_name} (${user.email}) - ${user.role}`);
|
|
2822
|
+
* });
|
|
2823
|
+
* } catch (error) {
|
|
2824
|
+
* if (error.message.includes('403')) {
|
|
2825
|
+
* console.error('Insufficient permissions to view users');
|
|
2826
|
+
* } else {
|
|
2827
|
+
* console.error('Failed to fetch users:', error);
|
|
2828
|
+
* }
|
|
2829
|
+
* }
|
|
2830
|
+
* ```
|
|
2831
|
+
*
|
|
2832
|
+
* @since 1.0.0
|
|
2833
|
+
* @public
|
|
2834
|
+
* @group Tenant User Management
|
|
2835
|
+
*/
|
|
2836
|
+
getAll(): Promise<GetAllUsersResponse>;
|
|
2539
2837
|
/**
|
|
2540
2838
|
* Removes a user from the active tenant
|
|
2541
2839
|
*
|
|
@@ -2759,6 +3057,30 @@ declare class TenantHandler {
|
|
|
2759
3057
|
* ```
|
|
2760
3058
|
*/
|
|
2761
3059
|
readonly invites: TenantInviteManager;
|
|
3060
|
+
/**
|
|
3061
|
+
* Tenant subscription and billing management
|
|
3062
|
+
*
|
|
3063
|
+
* Provides access to subscription data and billing status for the
|
|
3064
|
+
* active tenant, including legacy price detection and payment method
|
|
3065
|
+
* verification. All operations are automatically scoped to the user's
|
|
3066
|
+
* currently active tenant.
|
|
3067
|
+
*
|
|
3068
|
+
* @example
|
|
3069
|
+
* ```typescript
|
|
3070
|
+
* // Get active subscriptions
|
|
3071
|
+
* const subs = await tenantHandler.subscriptions.getActive();
|
|
3072
|
+
*
|
|
3073
|
+
* // Check billing status
|
|
3074
|
+
* const status = await tenantHandler.subscriptions.getBillingStatus();
|
|
3075
|
+
* if (!status.data.has_billing_info) {
|
|
3076
|
+
* console.log('No payment method configured');
|
|
3077
|
+
* }
|
|
3078
|
+
* ```
|
|
3079
|
+
*
|
|
3080
|
+
* @since 0.6.0
|
|
3081
|
+
* @group Tenant Management
|
|
3082
|
+
*/
|
|
3083
|
+
readonly subscriptions: TenantSubscriptionManager;
|
|
2762
3084
|
}
|
|
2763
3085
|
|
|
2764
3086
|
type OmnibaseClientConfig = {
|
|
@@ -2895,4 +3217,4 @@ declare class OmnibaseClient {
|
|
|
2895
3217
|
fetch(endpoint: string, options?: RequestInit): Promise<Response>;
|
|
2896
3218
|
}
|
|
2897
3219
|
|
|
2898
|
-
export { type AssignRoleRequest as A, type CreateRoleRequest as C, CheckoutManager, type CheckoutOptions, ConfigManager, type CreateCheckoutResponse, type CreateCustomerPortalResponse, type DownloadResult as D, type NamespaceDefinition as N, type OmnibaseClientConfig as O, PermissionsClient as P, PaymentHandler, PortalManager, type PortalOptions, type Price, type PriceDisplay, type PriceLimit, type PriceUI, type Product, type ProductUI, type ProductWithPricingUI, RolesHandler as R, StorageClient as S, type StripeConfigResponse, type StripeConfiguration, TenantHandler as T, type Tier, type UpdateRoleRequest as U, UsageManager, type UsageOptions, type Role as a, type UploadOptions as b, type UploadResult as c, type AcceptTenantInviteRequest as d, type AcceptTenantInviteResponse as e, type CreateTenantUserInviteResponse as f, type TenantInvite as g, type CreateTenantUserInviteRequest as h, TenantInviteManager as i, type SwitchActiveTenantResponse as j, type DeleteTenantResponse as k, type CreateTenantResponse as l, type Tenant as m, type CreateTenantRequest as n, TenantManger as o,
|
|
3220
|
+
export { type AssignRoleRequest as A, type BillingStatus as B, type CreateRoleRequest as C, CheckoutManager, type CheckoutOptions, ConfigManager, type CreateCheckoutResponse, type CreateCustomerPortalResponse, type DownloadResult as D, type GetActiveSubscriptionsResponse as G, type NamespaceDefinition as N, type OmnibaseClientConfig as O, PermissionsClient as P, PaymentHandler, PortalManager, type PortalOptions, type Price, type PriceDisplay, type PriceLimit, type PriceUI, type Product, type ProductUI, type ProductWithPricingUI, RolesHandler as R, StorageClient as S, type StripeConfigResponse, type StripeConfiguration, TenantHandler as T, type Tier, type UpdateRoleRequest as U, UsageManager, type UsageOptions, type Role as a, type UploadOptions as b, type UploadResult as c, type AcceptTenantInviteRequest as d, type AcceptTenantInviteResponse as e, type CreateTenantUserInviteResponse as f, type TenantInvite as g, type CreateTenantUserInviteRequest as h, TenantInviteManager as i, type SwitchActiveTenantResponse as j, type DeleteTenantResponse as k, type CreateTenantResponse as l, type Tenant as m, type CreateTenantRequest as n, TenantManger as o, type TenantSubscription as p, type GetBillingStatusResponse as q, TenantSubscriptionManager as r, OmnibaseClient as s, type ApiResponse as t };
|
package/dist/tenants/index.cjs
CHANGED
|
@@ -437,6 +437,157 @@ var TenantManger = class {
|
|
|
437
437
|
}
|
|
438
438
|
};
|
|
439
439
|
|
|
440
|
+
// src/tenants/subscriptions.ts
|
|
441
|
+
var TenantSubscriptionManager = class {
|
|
442
|
+
/**
|
|
443
|
+
* Creates a new TenantSubscriptionManager instance
|
|
444
|
+
*
|
|
445
|
+
* @param omnibaseClient - Configured Omnibase client instance
|
|
446
|
+
*
|
|
447
|
+
* @group Tenant Subscriptions
|
|
448
|
+
*/
|
|
449
|
+
constructor(omnibaseClient) {
|
|
450
|
+
this.omnibaseClient = omnibaseClient;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Get all active subscriptions for the current tenant
|
|
454
|
+
*
|
|
455
|
+
* Retrieves all active Stripe subscriptions associated with the user's
|
|
456
|
+
* currently active tenant. Returns subscriptions with config-based price IDs
|
|
457
|
+
* instead of raw Stripe IDs, making it easier to match against your billing
|
|
458
|
+
* configuration.
|
|
459
|
+
*
|
|
460
|
+
* The endpoint automatically:
|
|
461
|
+
* - Fetches subscriptions from Stripe API
|
|
462
|
+
* - Maps Stripe price IDs to your config price IDs
|
|
463
|
+
* - Checks both current and historical price mappings
|
|
464
|
+
* - Flags legacy prices from old billing configurations
|
|
465
|
+
* - Filters to only active/trialing/past_due subscriptions
|
|
466
|
+
*
|
|
467
|
+
* Returns an empty array if:
|
|
468
|
+
* - Tenant has no Stripe customer ID configured
|
|
469
|
+
* - Tenant has no active subscriptions
|
|
470
|
+
* - User is not authenticated
|
|
471
|
+
*
|
|
472
|
+
* @returns Promise resolving to array of active subscriptions
|
|
473
|
+
*
|
|
474
|
+
* @throws {Error} When the user is not authenticated
|
|
475
|
+
* @throws {Error} When the API request fails due to network issues
|
|
476
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx)
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```typescript
|
|
480
|
+
* const response = await subscriptionManager.getActive();
|
|
481
|
+
*
|
|
482
|
+
* if (response.data.length === 0) {
|
|
483
|
+
* console.log('No active subscriptions');
|
|
484
|
+
* } else {
|
|
485
|
+
* response.data.forEach(sub => {
|
|
486
|
+
* console.log(`Plan: ${sub.config_price_id}`);
|
|
487
|
+
* console.log(`Status: ${sub.status}`);
|
|
488
|
+
* if (sub.is_legacy_price) {
|
|
489
|
+
* console.log('⚠️ Using legacy pricing');
|
|
490
|
+
* }
|
|
491
|
+
* });
|
|
492
|
+
* }
|
|
493
|
+
* ```
|
|
494
|
+
*
|
|
495
|
+
* @since 0.6.0
|
|
496
|
+
* @public
|
|
497
|
+
* @group Tenant Subscriptions
|
|
498
|
+
*/
|
|
499
|
+
async getActive() {
|
|
500
|
+
try {
|
|
501
|
+
const response = await this.omnibaseClient.fetch(
|
|
502
|
+
`/api/v1/tenants/subscriptions`,
|
|
503
|
+
{
|
|
504
|
+
method: "GET",
|
|
505
|
+
credentials: "include"
|
|
506
|
+
}
|
|
507
|
+
);
|
|
508
|
+
if (!response.ok) {
|
|
509
|
+
const errorData = await response.text();
|
|
510
|
+
throw new Error(
|
|
511
|
+
`Failed to fetch subscriptions: ${response.status} - ${errorData}`
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
const data = await response.json();
|
|
515
|
+
return data;
|
|
516
|
+
} catch (error) {
|
|
517
|
+
console.error("Error fetching tenant subscriptions:", error);
|
|
518
|
+
throw error;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Check if the current tenant has billing information configured
|
|
523
|
+
*
|
|
524
|
+
* Verifies whether the tenant has valid payment methods attached to their
|
|
525
|
+
* Stripe customer account. This is useful for:
|
|
526
|
+
* - Showing billing setup prompts
|
|
527
|
+
* - Gating premium features behind payment method requirement
|
|
528
|
+
* - Displaying billing status indicators in UI
|
|
529
|
+
* - Determining if customer portal access should be shown
|
|
530
|
+
*
|
|
531
|
+
* The check verifies:
|
|
532
|
+
* - Default payment source (card, bank account, etc.)
|
|
533
|
+
* - Default payment method in invoice settings
|
|
534
|
+
* - Whether the payment method is valid and active
|
|
535
|
+
*
|
|
536
|
+
* Returns `false` if:
|
|
537
|
+
* - Tenant has no Stripe customer ID
|
|
538
|
+
* - No payment methods are configured
|
|
539
|
+
* - User is not authenticated
|
|
540
|
+
*
|
|
541
|
+
* @returns Promise resolving to billing status information
|
|
542
|
+
*
|
|
543
|
+
* @throws {Error} When the user is not authenticated
|
|
544
|
+
* @throws {Error} When the API request fails due to network issues
|
|
545
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx)
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* ```typescript
|
|
549
|
+
* const response = await subscriptionManager.getBillingStatus();
|
|
550
|
+
*
|
|
551
|
+
* if (!response.data.has_billing_info) {
|
|
552
|
+
* // Show billing setup prompt
|
|
553
|
+
* showBillingSetupModal();
|
|
554
|
+
* } else if (!response.data.is_active) {
|
|
555
|
+
* // Payment method exists but may be expired/invalid
|
|
556
|
+
* showPaymentMethodUpdatePrompt();
|
|
557
|
+
* } else {
|
|
558
|
+
* // All good - show customer portal link
|
|
559
|
+
* showManageBillingButton();
|
|
560
|
+
* }
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* @since 0.6.0
|
|
564
|
+
* @public
|
|
565
|
+
* @group Tenant Subscriptions
|
|
566
|
+
*/
|
|
567
|
+
async getBillingStatus() {
|
|
568
|
+
try {
|
|
569
|
+
const response = await this.omnibaseClient.fetch(
|
|
570
|
+
`/api/v1/tenants/billing-status`,
|
|
571
|
+
{
|
|
572
|
+
method: "GET",
|
|
573
|
+
credentials: "include"
|
|
574
|
+
}
|
|
575
|
+
);
|
|
576
|
+
if (!response.ok) {
|
|
577
|
+
const errorData = await response.text();
|
|
578
|
+
throw new Error(
|
|
579
|
+
`Failed to fetch billing status: ${response.status} - ${errorData}`
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
const data = await response.json();
|
|
583
|
+
return data;
|
|
584
|
+
} catch (error) {
|
|
585
|
+
console.error("Error fetching billing status:", error);
|
|
586
|
+
throw error;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
|
|
440
591
|
// src/tenants/user.ts
|
|
441
592
|
var TenantUserManager = class {
|
|
442
593
|
/**
|
|
@@ -449,6 +600,58 @@ var TenantUserManager = class {
|
|
|
449
600
|
constructor(omnibaseClient) {
|
|
450
601
|
this.omnibaseClient = omnibaseClient;
|
|
451
602
|
}
|
|
603
|
+
/**
|
|
604
|
+
* Retrieves all users in the active tenant
|
|
605
|
+
*
|
|
606
|
+
* This method fetches a list of all users who are members of the current active tenant,
|
|
607
|
+
* including their basic information (name, email) and assigned role. The operation
|
|
608
|
+
* requires the requesting user to have appropriate permissions to view tenant users
|
|
609
|
+
* (typically requires `view_users` permission).
|
|
610
|
+
*
|
|
611
|
+
* The returned list includes all tenant members regardless of their role, ordered by
|
|
612
|
+
* when they joined the tenant (newest first).
|
|
613
|
+
*
|
|
614
|
+
* @returns Promise resolving to an array of tenant users with their details
|
|
615
|
+
*
|
|
616
|
+
* @throws {Error} When the API request fails (includes status code and error details)
|
|
617
|
+
* @throws {Error} When the user doesn't have permission to view users
|
|
618
|
+
* @throws {Error} When the user is not authenticated or no active tenant is set
|
|
619
|
+
*
|
|
620
|
+
* @example
|
|
621
|
+
* ```typescript
|
|
622
|
+
* // Fetch all users in the active tenant
|
|
623
|
+
* try {
|
|
624
|
+
* const result = await userManager.getAll();
|
|
625
|
+
* console.log(`Found ${result.data.length} users`);
|
|
626
|
+
*
|
|
627
|
+
* result.data.forEach(user => {
|
|
628
|
+
* console.log(`${user.first_name} ${user.last_name} (${user.email}) - ${user.role}`);
|
|
629
|
+
* });
|
|
630
|
+
* } catch (error) {
|
|
631
|
+
* if (error.message.includes('403')) {
|
|
632
|
+
* console.error('Insufficient permissions to view users');
|
|
633
|
+
* } else {
|
|
634
|
+
* console.error('Failed to fetch users:', error);
|
|
635
|
+
* }
|
|
636
|
+
* }
|
|
637
|
+
* ```
|
|
638
|
+
*
|
|
639
|
+
* @since 1.0.0
|
|
640
|
+
* @public
|
|
641
|
+
* @group Tenant User Management
|
|
642
|
+
*/
|
|
643
|
+
async getAll() {
|
|
644
|
+
const response = await this.omnibaseClient.fetch("/api/v1/tenants/users", {
|
|
645
|
+
method: "GET"
|
|
646
|
+
});
|
|
647
|
+
if (!response.ok) {
|
|
648
|
+
const errorData = await response.text();
|
|
649
|
+
throw new Error(
|
|
650
|
+
`Failed to fetch tenant users: ${response.status} - ${errorData}`
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
return await response.json();
|
|
654
|
+
}
|
|
452
655
|
/**
|
|
453
656
|
* Removes a user from the active tenant
|
|
454
657
|
*
|
|
@@ -596,6 +799,7 @@ var TenantHandler = class {
|
|
|
596
799
|
constructor(omnibaseClient) {
|
|
597
800
|
this.invites = new TenantInviteManager(omnibaseClient);
|
|
598
801
|
this.manage = new TenantManger(omnibaseClient);
|
|
802
|
+
this.subscriptions = new TenantSubscriptionManager(omnibaseClient);
|
|
599
803
|
this.user = new TenantUserManager(omnibaseClient);
|
|
600
804
|
}
|
|
601
805
|
/**
|
|
@@ -660,6 +864,30 @@ var TenantHandler = class {
|
|
|
660
864
|
* ```
|
|
661
865
|
*/
|
|
662
866
|
invites;
|
|
867
|
+
/**
|
|
868
|
+
* Tenant subscription and billing management
|
|
869
|
+
*
|
|
870
|
+
* Provides access to subscription data and billing status for the
|
|
871
|
+
* active tenant, including legacy price detection and payment method
|
|
872
|
+
* verification. All operations are automatically scoped to the user's
|
|
873
|
+
* currently active tenant.
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
876
|
+
* ```typescript
|
|
877
|
+
* // Get active subscriptions
|
|
878
|
+
* const subs = await tenantHandler.subscriptions.getActive();
|
|
879
|
+
*
|
|
880
|
+
* // Check billing status
|
|
881
|
+
* const status = await tenantHandler.subscriptions.getBillingStatus();
|
|
882
|
+
* if (!status.data.has_billing_info) {
|
|
883
|
+
* console.log('No payment method configured');
|
|
884
|
+
* }
|
|
885
|
+
* ```
|
|
886
|
+
*
|
|
887
|
+
* @since 0.6.0
|
|
888
|
+
* @group Tenant Management
|
|
889
|
+
*/
|
|
890
|
+
subscriptions;
|
|
663
891
|
};
|
|
664
892
|
// Annotate the CommonJS export names for ESM import in node:
|
|
665
893
|
0 && (module.exports = {
|
package/dist/tenants/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { d as AcceptTenantInviteRequest, e as AcceptTenantInviteResponse, n as CreateTenantRequest, l as CreateTenantResponse, h as CreateTenantUserInviteRequest, f as CreateTenantUserInviteResponse, k as DeleteTenantResponse, j as SwitchActiveTenantResponse, m as Tenant, T as TenantHandler, g as TenantInvite, i as TenantInviteManager, o as TenantManger } from '../payments/index.cjs';
|
|
1
|
+
export { d as AcceptTenantInviteRequest, e as AcceptTenantInviteResponse, B as BillingStatus, n as CreateTenantRequest, l as CreateTenantResponse, h as CreateTenantUserInviteRequest, f as CreateTenantUserInviteResponse, k as DeleteTenantResponse, G as GetActiveSubscriptionsResponse, q as GetBillingStatusResponse, j as SwitchActiveTenantResponse, m as Tenant, T as TenantHandler, g as TenantInvite, i as TenantInviteManager, o as TenantManger, p as TenantSubscription, r as TenantSubscriptionManager } from '../payments/index.cjs';
|
|
2
2
|
import '@ory/client';
|
package/dist/tenants/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { d as AcceptTenantInviteRequest, e as AcceptTenantInviteResponse, n as CreateTenantRequest, l as CreateTenantResponse, h as CreateTenantUserInviteRequest, f as CreateTenantUserInviteResponse, k as DeleteTenantResponse, j as SwitchActiveTenantResponse, m as Tenant, T as TenantHandler, g as TenantInvite, i as TenantInviteManager, o as TenantManger } from '../payments/index.js';
|
|
1
|
+
export { d as AcceptTenantInviteRequest, e as AcceptTenantInviteResponse, B as BillingStatus, n as CreateTenantRequest, l as CreateTenantResponse, h as CreateTenantUserInviteRequest, f as CreateTenantUserInviteResponse, k as DeleteTenantResponse, G as GetActiveSubscriptionsResponse, q as GetBillingStatusResponse, j as SwitchActiveTenantResponse, m as Tenant, T as TenantHandler, g as TenantInvite, i as TenantInviteManager, o as TenantManger, p as TenantSubscription, r as TenantSubscriptionManager } from '../payments/index.js';
|
|
2
2
|
import '@ory/client';
|
package/dist/tenants/index.js
CHANGED