@omnibase/core-js 0.7.5 → 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/index.cjs CHANGED
@@ -1423,6 +1423,157 @@ var TenantManger = class {
1423
1423
  }
1424
1424
  };
1425
1425
 
1426
+ // src/tenants/subscriptions.ts
1427
+ var TenantSubscriptionManager = class {
1428
+ /**
1429
+ * Creates a new TenantSubscriptionManager instance
1430
+ *
1431
+ * @param omnibaseClient - Configured Omnibase client instance
1432
+ *
1433
+ * @group Tenant Subscriptions
1434
+ */
1435
+ constructor(omnibaseClient) {
1436
+ this.omnibaseClient = omnibaseClient;
1437
+ }
1438
+ /**
1439
+ * Get all active subscriptions for the current tenant
1440
+ *
1441
+ * Retrieves all active Stripe subscriptions associated with the user's
1442
+ * currently active tenant. Returns subscriptions with config-based price IDs
1443
+ * instead of raw Stripe IDs, making it easier to match against your billing
1444
+ * configuration.
1445
+ *
1446
+ * The endpoint automatically:
1447
+ * - Fetches subscriptions from Stripe API
1448
+ * - Maps Stripe price IDs to your config price IDs
1449
+ * - Checks both current and historical price mappings
1450
+ * - Flags legacy prices from old billing configurations
1451
+ * - Filters to only active/trialing/past_due subscriptions
1452
+ *
1453
+ * Returns an empty array if:
1454
+ * - Tenant has no Stripe customer ID configured
1455
+ * - Tenant has no active subscriptions
1456
+ * - User is not authenticated
1457
+ *
1458
+ * @returns Promise resolving to array of active subscriptions
1459
+ *
1460
+ * @throws {Error} When the user is not authenticated
1461
+ * @throws {Error} When the API request fails due to network issues
1462
+ * @throws {Error} When the server returns an error response (4xx, 5xx)
1463
+ *
1464
+ * @example
1465
+ * ```typescript
1466
+ * const response = await subscriptionManager.getActive();
1467
+ *
1468
+ * if (response.data.length === 0) {
1469
+ * console.log('No active subscriptions');
1470
+ * } else {
1471
+ * response.data.forEach(sub => {
1472
+ * console.log(`Plan: ${sub.config_price_id}`);
1473
+ * console.log(`Status: ${sub.status}`);
1474
+ * if (sub.is_legacy_price) {
1475
+ * console.log('⚠️ Using legacy pricing');
1476
+ * }
1477
+ * });
1478
+ * }
1479
+ * ```
1480
+ *
1481
+ * @since 0.6.0
1482
+ * @public
1483
+ * @group Tenant Subscriptions
1484
+ */
1485
+ async getActive() {
1486
+ try {
1487
+ const response = await this.omnibaseClient.fetch(
1488
+ `/api/v1/tenants/subscriptions`,
1489
+ {
1490
+ method: "GET",
1491
+ credentials: "include"
1492
+ }
1493
+ );
1494
+ if (!response.ok) {
1495
+ const errorData = await response.text();
1496
+ throw new Error(
1497
+ `Failed to fetch subscriptions: ${response.status} - ${errorData}`
1498
+ );
1499
+ }
1500
+ const data = await response.json();
1501
+ return data;
1502
+ } catch (error) {
1503
+ console.error("Error fetching tenant subscriptions:", error);
1504
+ throw error;
1505
+ }
1506
+ }
1507
+ /**
1508
+ * Check if the current tenant has billing information configured
1509
+ *
1510
+ * Verifies whether the tenant has valid payment methods attached to their
1511
+ * Stripe customer account. This is useful for:
1512
+ * - Showing billing setup prompts
1513
+ * - Gating premium features behind payment method requirement
1514
+ * - Displaying billing status indicators in UI
1515
+ * - Determining if customer portal access should be shown
1516
+ *
1517
+ * The check verifies:
1518
+ * - Default payment source (card, bank account, etc.)
1519
+ * - Default payment method in invoice settings
1520
+ * - Whether the payment method is valid and active
1521
+ *
1522
+ * Returns `false` if:
1523
+ * - Tenant has no Stripe customer ID
1524
+ * - No payment methods are configured
1525
+ * - User is not authenticated
1526
+ *
1527
+ * @returns Promise resolving to billing status information
1528
+ *
1529
+ * @throws {Error} When the user is not authenticated
1530
+ * @throws {Error} When the API request fails due to network issues
1531
+ * @throws {Error} When the server returns an error response (4xx, 5xx)
1532
+ *
1533
+ * @example
1534
+ * ```typescript
1535
+ * const response = await subscriptionManager.getBillingStatus();
1536
+ *
1537
+ * if (!response.data.has_billing_info) {
1538
+ * // Show billing setup prompt
1539
+ * showBillingSetupModal();
1540
+ * } else if (!response.data.is_active) {
1541
+ * // Payment method exists but may be expired/invalid
1542
+ * showPaymentMethodUpdatePrompt();
1543
+ * } else {
1544
+ * // All good - show customer portal link
1545
+ * showManageBillingButton();
1546
+ * }
1547
+ * ```
1548
+ *
1549
+ * @since 0.6.0
1550
+ * @public
1551
+ * @group Tenant Subscriptions
1552
+ */
1553
+ async getBillingStatus() {
1554
+ try {
1555
+ const response = await this.omnibaseClient.fetch(
1556
+ `/api/v1/tenants/billing-status`,
1557
+ {
1558
+ method: "GET",
1559
+ credentials: "include"
1560
+ }
1561
+ );
1562
+ if (!response.ok) {
1563
+ const errorData = await response.text();
1564
+ throw new Error(
1565
+ `Failed to fetch billing status: ${response.status} - ${errorData}`
1566
+ );
1567
+ }
1568
+ const data = await response.json();
1569
+ return data;
1570
+ } catch (error) {
1571
+ console.error("Error fetching billing status:", error);
1572
+ throw error;
1573
+ }
1574
+ }
1575
+ };
1576
+
1426
1577
  // src/tenants/user.ts
1427
1578
  var TenantUserManager = class {
1428
1579
  /**
@@ -1634,6 +1785,7 @@ var TenantHandler = class {
1634
1785
  constructor(omnibaseClient) {
1635
1786
  this.invites = new TenantInviteManager(omnibaseClient);
1636
1787
  this.manage = new TenantManger(omnibaseClient);
1788
+ this.subscriptions = new TenantSubscriptionManager(omnibaseClient);
1637
1789
  this.user = new TenantUserManager(omnibaseClient);
1638
1790
  }
1639
1791
  /**
@@ -1698,6 +1850,30 @@ var TenantHandler = class {
1698
1850
  * ```
1699
1851
  */
1700
1852
  invites;
1853
+ /**
1854
+ * Tenant subscription and billing management
1855
+ *
1856
+ * Provides access to subscription data and billing status for the
1857
+ * active tenant, including legacy price detection and payment method
1858
+ * verification. All operations are automatically scoped to the user's
1859
+ * currently active tenant.
1860
+ *
1861
+ * @example
1862
+ * ```typescript
1863
+ * // Get active subscriptions
1864
+ * const subs = await tenantHandler.subscriptions.getActive();
1865
+ *
1866
+ * // Check billing status
1867
+ * const status = await tenantHandler.subscriptions.getBillingStatus();
1868
+ * if (!status.data.has_billing_info) {
1869
+ * console.log('No payment method configured');
1870
+ * }
1871
+ * ```
1872
+ *
1873
+ * @since 0.6.0
1874
+ * @group Tenant Management
1875
+ */
1876
+ subscriptions;
1701
1877
  };
1702
1878
 
1703
1879
  // src/client.ts
package/dist/index.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- export { q as ApiResponse, A as AssignRoleRequest, C as CreateRoleRequest, D as DownloadResult, N as NamespaceDefinition, p as OmnibaseClient, O as OmnibaseClientConfig, P as PermissionsClient, a as Role, R as RolesHandler, S as StorageClient, U as UpdateRoleRequest, b as UploadOptions, c as UploadResult } from './payments/index.cjs';
1
+ export { t as ApiResponse, A as AssignRoleRequest, C as CreateRoleRequest, D as DownloadResult, N as NamespaceDefinition, s as OmnibaseClient, O as OmnibaseClientConfig, P as PermissionsClient, a as Role, R as RolesHandler, S as StorageClient, U as UpdateRoleRequest, b as UploadOptions, c as UploadResult } from './payments/index.cjs';
2
2
  import '@ory/client';
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { q as ApiResponse, A as AssignRoleRequest, C as CreateRoleRequest, D as DownloadResult, N as NamespaceDefinition, p as OmnibaseClient, O as OmnibaseClientConfig, P as PermissionsClient, a as Role, R as RolesHandler, S as StorageClient, U as UpdateRoleRequest, b as UploadOptions, c as UploadResult } from './payments/index.js';
1
+ export { t as ApiResponse, A as AssignRoleRequest, C as CreateRoleRequest, D as DownloadResult, N as NamespaceDefinition, s as OmnibaseClient, O as OmnibaseClientConfig, P as PermissionsClient, a as Role, R as RolesHandler, S as StorageClient, U as UpdateRoleRequest, b as UploadOptions, c as UploadResult } from './payments/index.js';
2
2
  import '@ory/client';
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-I6DMWC32.js";
11
11
  import {
12
12
  TenantHandler
13
- } from "./chunk-V6HVRJCU.js";
13
+ } from "./chunk-TFAV5P6I.js";
14
14
 
15
15
  // src/client.ts
16
16
  var OmnibaseClient = class {
@@ -2440,6 +2440,219 @@ 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
+
2443
2656
  /**
2444
2657
  * Response structure for a tenant user
2445
2658
  *
@@ -2844,6 +3057,30 @@ declare class TenantHandler {
2844
3057
  * ```
2845
3058
  */
2846
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;
2847
3084
  }
2848
3085
 
2849
3086
  type OmnibaseClientConfig = {
@@ -2980,4 +3217,4 @@ declare class OmnibaseClient {
2980
3217
  fetch(endpoint: string, options?: RequestInit): Promise<Response>;
2981
3218
  }
2982
3219
 
2983
- 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, OmnibaseClient as p, type ApiResponse as q };
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 };