@stackbe/sdk 0.9.5 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -2396,6 +2396,195 @@ declare class CouponsClient {
2396
2396
  delete(couponId: string): Promise<void>;
2397
2397
  }
2398
2398
 
2399
+ interface DashboardMetrics {
2400
+ revenue: {
2401
+ mrr: number;
2402
+ arpu: number;
2403
+ };
2404
+ subscriptions: {
2405
+ active: number;
2406
+ churnRate: number;
2407
+ };
2408
+ trials: {
2409
+ active: number;
2410
+ conversionRate: number;
2411
+ avgDays: number;
2412
+ };
2413
+ growth: {
2414
+ newSubscribers: number;
2415
+ churnedSubscribers: number;
2416
+ netGrowth: number;
2417
+ growthRate: number;
2418
+ };
2419
+ conversion: {
2420
+ rate: number;
2421
+ };
2422
+ api: {
2423
+ errorRate: number;
2424
+ avgResponseTime: number;
2425
+ };
2426
+ }
2427
+ interface MRRHistoryPoint {
2428
+ date: string;
2429
+ mrr: number;
2430
+ }
2431
+ interface RevenueByPlan {
2432
+ planId: string;
2433
+ planName: string;
2434
+ mrr: number;
2435
+ subscriberCount: number;
2436
+ percentage: number;
2437
+ }
2438
+ interface TrialMetrics {
2439
+ trialStarts: number;
2440
+ trialConversions: number;
2441
+ trialConversionRate: number;
2442
+ avgTrialDays: number;
2443
+ activeTrials: number;
2444
+ }
2445
+ interface GrowthMetrics {
2446
+ newSubscribers: number;
2447
+ churnedSubscribers: number;
2448
+ netGrowth: number;
2449
+ growthRate: number;
2450
+ }
2451
+ interface GrowthChartPoint {
2452
+ date: string;
2453
+ new: number;
2454
+ churned: number;
2455
+ net: number;
2456
+ }
2457
+ interface PlanMetrics {
2458
+ planId: string;
2459
+ planName: string;
2460
+ subscriberCount: number;
2461
+ percentage: number;
2462
+ priceCents: number;
2463
+ interval: string;
2464
+ }
2465
+ interface RequestCountPoint {
2466
+ date: string;
2467
+ count: number;
2468
+ }
2469
+ interface PopularEndpoint {
2470
+ endpoint: string;
2471
+ count: number;
2472
+ }
2473
+ interface PerformanceMetrics {
2474
+ errorRate: number;
2475
+ avgResponseTime: number;
2476
+ }
2477
+ interface FeatureUsagePoint {
2478
+ date: string;
2479
+ count: number;
2480
+ }
2481
+ interface AnalyticsFilterOptions {
2482
+ appId?: string;
2483
+ }
2484
+ interface TimeRangeOptions extends AnalyticsFilterOptions {
2485
+ days?: number;
2486
+ }
2487
+ /**
2488
+ * Analytics client for accessing business metrics
2489
+ *
2490
+ * @example
2491
+ * ```typescript
2492
+ * const stackbe = new StackBE({ apiKey: '...', appId: '...' });
2493
+ *
2494
+ * // Get full dashboard
2495
+ * const dashboard = await stackbe.analytics.getDashboard();
2496
+ *
2497
+ * // Get MRR history
2498
+ * const mrrHistory = await stackbe.analytics.getMRRHistory({ days: 30 });
2499
+ *
2500
+ * // Get revenue by plan
2501
+ * const revenueByPlan = await stackbe.analytics.getRevenueByPlan();
2502
+ *
2503
+ * // Get trial metrics
2504
+ * const trials = await stackbe.analytics.getTrialMetrics({ days: 30 });
2505
+ *
2506
+ * // Get growth chart
2507
+ * const growth = await stackbe.analytics.getGrowthChart({ days: 30 });
2508
+ * ```
2509
+ */
2510
+ declare class AnalyticsClient {
2511
+ private readonly http;
2512
+ constructor(http: HttpClient);
2513
+ /**
2514
+ * Get the full analytics dashboard with all key metrics
2515
+ */
2516
+ getDashboard(options?: AnalyticsFilterOptions): Promise<DashboardMetrics>;
2517
+ /**
2518
+ * Get current Monthly Recurring Revenue
2519
+ */
2520
+ getMRR(options?: AnalyticsFilterOptions): Promise<{
2521
+ mrr: number;
2522
+ }>;
2523
+ /**
2524
+ * Get MRR history over time for trend analysis
2525
+ */
2526
+ getMRRHistory(options?: TimeRangeOptions): Promise<MRRHistoryPoint[]>;
2527
+ /**
2528
+ * Get revenue breakdown by plan
2529
+ */
2530
+ getRevenueByPlan(options?: AnalyticsFilterOptions): Promise<RevenueByPlan[]>;
2531
+ /**
2532
+ * Get Average Revenue Per User
2533
+ */
2534
+ getARPU(options?: AnalyticsFilterOptions): Promise<{
2535
+ arpu: number;
2536
+ }>;
2537
+ /**
2538
+ * Get subscription metrics (active count, churn rate)
2539
+ */
2540
+ getSubscriptionMetrics(options?: TimeRangeOptions): Promise<{
2541
+ active: number;
2542
+ churnRate: number;
2543
+ }>;
2544
+ /**
2545
+ * Get subscriber distribution by plan
2546
+ */
2547
+ getSubscribersByPlan(options?: AnalyticsFilterOptions): Promise<PlanMetrics[]>;
2548
+ /**
2549
+ * Get trial metrics (starts, conversions, conversion rate)
2550
+ * Useful for freemium and trial-based pricing models
2551
+ */
2552
+ getTrialMetrics(options?: TimeRangeOptions): Promise<TrialMetrics>;
2553
+ /**
2554
+ * Get growth metrics (new vs churned subscribers)
2555
+ */
2556
+ getGrowthMetrics(options?: TimeRangeOptions): Promise<GrowthMetrics>;
2557
+ /**
2558
+ * Get growth chart data (daily new vs churned for charting)
2559
+ */
2560
+ getGrowthChart(options?: TimeRangeOptions): Promise<GrowthChartPoint[]>;
2561
+ /**
2562
+ * Get checkout conversion rate
2563
+ */
2564
+ getConversionRate(options?: TimeRangeOptions): Promise<{
2565
+ rate: number;
2566
+ period: number;
2567
+ }>;
2568
+ /**
2569
+ * Get API request counts over time
2570
+ */
2571
+ getRequestCounts(options?: TimeRangeOptions): Promise<RequestCountPoint[]>;
2572
+ /**
2573
+ * Get most popular API endpoints
2574
+ */
2575
+ getPopularEndpoints(options?: AnalyticsFilterOptions & {
2576
+ limit?: number;
2577
+ }): Promise<PopularEndpoint[]>;
2578
+ /**
2579
+ * Get API performance metrics (error rate, response time)
2580
+ */
2581
+ getPerformance(options?: TimeRangeOptions): Promise<PerformanceMetrics>;
2582
+ /**
2583
+ * Get feature usage over time (entitlement checks)
2584
+ */
2585
+ getFeatureUsage(options?: TimeRangeOptions): Promise<FeatureUsagePoint[]>;
2586
+ }
2587
+
2399
2588
  declare class StackBE {
2400
2589
  private http;
2401
2590
  private appId;
@@ -2425,6 +2614,8 @@ declare class StackBE {
2425
2614
  readonly earlyAccess: EarlyAccessClient;
2426
2615
  /** Coupon/promo code management */
2427
2616
  readonly coupons: CouponsClient;
2617
+ /** Analytics and business metrics */
2618
+ readonly analytics: AnalyticsClient;
2428
2619
  /**
2429
2620
  * Create a new StackBE client.
2430
2621
  *
@@ -2525,4 +2716,4 @@ declare class StackBE {
2525
2716
  }): (req: any, res: any, next: any) => Promise<any>;
2526
2717
  }
2527
2718
 
2528
- export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, type CouponDuration, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, type DunningStatus, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type TrialStatus, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
2719
+ export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, AnalyticsClient, type AnalyticsFilterOptions, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, type CouponDuration, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, type DashboardMetrics, type DunningStatus, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type FeatureUsagePoint, type GetSubscriptionOptions, type GrowthChartPoint, type GrowthMetrics, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MRRHistoryPoint, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type PerformanceMetrics, type Plan, type PlanMetrics, PlansClient, type PopularEndpoint, type Product, ProductsClient, type RequestCountPoint, type RevenueByPlan, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TimeRangeOptions, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialMetrics, type TrialStartedEvent, type TrialStatus, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
package/dist/index.d.ts CHANGED
@@ -2396,6 +2396,195 @@ declare class CouponsClient {
2396
2396
  delete(couponId: string): Promise<void>;
2397
2397
  }
2398
2398
 
2399
+ interface DashboardMetrics {
2400
+ revenue: {
2401
+ mrr: number;
2402
+ arpu: number;
2403
+ };
2404
+ subscriptions: {
2405
+ active: number;
2406
+ churnRate: number;
2407
+ };
2408
+ trials: {
2409
+ active: number;
2410
+ conversionRate: number;
2411
+ avgDays: number;
2412
+ };
2413
+ growth: {
2414
+ newSubscribers: number;
2415
+ churnedSubscribers: number;
2416
+ netGrowth: number;
2417
+ growthRate: number;
2418
+ };
2419
+ conversion: {
2420
+ rate: number;
2421
+ };
2422
+ api: {
2423
+ errorRate: number;
2424
+ avgResponseTime: number;
2425
+ };
2426
+ }
2427
+ interface MRRHistoryPoint {
2428
+ date: string;
2429
+ mrr: number;
2430
+ }
2431
+ interface RevenueByPlan {
2432
+ planId: string;
2433
+ planName: string;
2434
+ mrr: number;
2435
+ subscriberCount: number;
2436
+ percentage: number;
2437
+ }
2438
+ interface TrialMetrics {
2439
+ trialStarts: number;
2440
+ trialConversions: number;
2441
+ trialConversionRate: number;
2442
+ avgTrialDays: number;
2443
+ activeTrials: number;
2444
+ }
2445
+ interface GrowthMetrics {
2446
+ newSubscribers: number;
2447
+ churnedSubscribers: number;
2448
+ netGrowth: number;
2449
+ growthRate: number;
2450
+ }
2451
+ interface GrowthChartPoint {
2452
+ date: string;
2453
+ new: number;
2454
+ churned: number;
2455
+ net: number;
2456
+ }
2457
+ interface PlanMetrics {
2458
+ planId: string;
2459
+ planName: string;
2460
+ subscriberCount: number;
2461
+ percentage: number;
2462
+ priceCents: number;
2463
+ interval: string;
2464
+ }
2465
+ interface RequestCountPoint {
2466
+ date: string;
2467
+ count: number;
2468
+ }
2469
+ interface PopularEndpoint {
2470
+ endpoint: string;
2471
+ count: number;
2472
+ }
2473
+ interface PerformanceMetrics {
2474
+ errorRate: number;
2475
+ avgResponseTime: number;
2476
+ }
2477
+ interface FeatureUsagePoint {
2478
+ date: string;
2479
+ count: number;
2480
+ }
2481
+ interface AnalyticsFilterOptions {
2482
+ appId?: string;
2483
+ }
2484
+ interface TimeRangeOptions extends AnalyticsFilterOptions {
2485
+ days?: number;
2486
+ }
2487
+ /**
2488
+ * Analytics client for accessing business metrics
2489
+ *
2490
+ * @example
2491
+ * ```typescript
2492
+ * const stackbe = new StackBE({ apiKey: '...', appId: '...' });
2493
+ *
2494
+ * // Get full dashboard
2495
+ * const dashboard = await stackbe.analytics.getDashboard();
2496
+ *
2497
+ * // Get MRR history
2498
+ * const mrrHistory = await stackbe.analytics.getMRRHistory({ days: 30 });
2499
+ *
2500
+ * // Get revenue by plan
2501
+ * const revenueByPlan = await stackbe.analytics.getRevenueByPlan();
2502
+ *
2503
+ * // Get trial metrics
2504
+ * const trials = await stackbe.analytics.getTrialMetrics({ days: 30 });
2505
+ *
2506
+ * // Get growth chart
2507
+ * const growth = await stackbe.analytics.getGrowthChart({ days: 30 });
2508
+ * ```
2509
+ */
2510
+ declare class AnalyticsClient {
2511
+ private readonly http;
2512
+ constructor(http: HttpClient);
2513
+ /**
2514
+ * Get the full analytics dashboard with all key metrics
2515
+ */
2516
+ getDashboard(options?: AnalyticsFilterOptions): Promise<DashboardMetrics>;
2517
+ /**
2518
+ * Get current Monthly Recurring Revenue
2519
+ */
2520
+ getMRR(options?: AnalyticsFilterOptions): Promise<{
2521
+ mrr: number;
2522
+ }>;
2523
+ /**
2524
+ * Get MRR history over time for trend analysis
2525
+ */
2526
+ getMRRHistory(options?: TimeRangeOptions): Promise<MRRHistoryPoint[]>;
2527
+ /**
2528
+ * Get revenue breakdown by plan
2529
+ */
2530
+ getRevenueByPlan(options?: AnalyticsFilterOptions): Promise<RevenueByPlan[]>;
2531
+ /**
2532
+ * Get Average Revenue Per User
2533
+ */
2534
+ getARPU(options?: AnalyticsFilterOptions): Promise<{
2535
+ arpu: number;
2536
+ }>;
2537
+ /**
2538
+ * Get subscription metrics (active count, churn rate)
2539
+ */
2540
+ getSubscriptionMetrics(options?: TimeRangeOptions): Promise<{
2541
+ active: number;
2542
+ churnRate: number;
2543
+ }>;
2544
+ /**
2545
+ * Get subscriber distribution by plan
2546
+ */
2547
+ getSubscribersByPlan(options?: AnalyticsFilterOptions): Promise<PlanMetrics[]>;
2548
+ /**
2549
+ * Get trial metrics (starts, conversions, conversion rate)
2550
+ * Useful for freemium and trial-based pricing models
2551
+ */
2552
+ getTrialMetrics(options?: TimeRangeOptions): Promise<TrialMetrics>;
2553
+ /**
2554
+ * Get growth metrics (new vs churned subscribers)
2555
+ */
2556
+ getGrowthMetrics(options?: TimeRangeOptions): Promise<GrowthMetrics>;
2557
+ /**
2558
+ * Get growth chart data (daily new vs churned for charting)
2559
+ */
2560
+ getGrowthChart(options?: TimeRangeOptions): Promise<GrowthChartPoint[]>;
2561
+ /**
2562
+ * Get checkout conversion rate
2563
+ */
2564
+ getConversionRate(options?: TimeRangeOptions): Promise<{
2565
+ rate: number;
2566
+ period: number;
2567
+ }>;
2568
+ /**
2569
+ * Get API request counts over time
2570
+ */
2571
+ getRequestCounts(options?: TimeRangeOptions): Promise<RequestCountPoint[]>;
2572
+ /**
2573
+ * Get most popular API endpoints
2574
+ */
2575
+ getPopularEndpoints(options?: AnalyticsFilterOptions & {
2576
+ limit?: number;
2577
+ }): Promise<PopularEndpoint[]>;
2578
+ /**
2579
+ * Get API performance metrics (error rate, response time)
2580
+ */
2581
+ getPerformance(options?: TimeRangeOptions): Promise<PerformanceMetrics>;
2582
+ /**
2583
+ * Get feature usage over time (entitlement checks)
2584
+ */
2585
+ getFeatureUsage(options?: TimeRangeOptions): Promise<FeatureUsagePoint[]>;
2586
+ }
2587
+
2399
2588
  declare class StackBE {
2400
2589
  private http;
2401
2590
  private appId;
@@ -2425,6 +2614,8 @@ declare class StackBE {
2425
2614
  readonly earlyAccess: EarlyAccessClient;
2426
2615
  /** Coupon/promo code management */
2427
2616
  readonly coupons: CouponsClient;
2617
+ /** Analytics and business metrics */
2618
+ readonly analytics: AnalyticsClient;
2428
2619
  /**
2429
2620
  * Create a new StackBE client.
2430
2621
  *
@@ -2525,4 +2716,4 @@ declare class StackBE {
2525
2716
  }): (req: any, res: any, next: any) => Promise<any>;
2526
2717
  }
2527
2718
 
2528
- export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, type CouponDuration, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, type DunningStatus, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type TrialStatus, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
2719
+ export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, AnalyticsClient, type AnalyticsFilterOptions, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, type CouponDuration, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, type DashboardMetrics, type DunningStatus, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type FeatureUsagePoint, type GetSubscriptionOptions, type GrowthChartPoint, type GrowthMetrics, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MRRHistoryPoint, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type PerformanceMetrics, type Plan, type PlanMetrics, PlansClient, type PopularEndpoint, type Product, ProductsClient, type RequestCountPoint, type RevenueByPlan, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TimeRangeOptions, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialMetrics, type TrialStartedEvent, type TrialStatus, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AffiliatesClient: () => AffiliatesClient,
24
+ AnalyticsClient: () => AnalyticsClient,
24
25
  AuthClient: () => AuthClient,
25
26
  CheckoutClient: () => CheckoutClient,
26
27
  CouponsClient: () => CouponsClient,
@@ -2277,6 +2278,159 @@ var CouponsClient = class {
2277
2278
  }
2278
2279
  };
2279
2280
 
2281
+ // src/analytics.ts
2282
+ var AnalyticsClient = class {
2283
+ constructor(http) {
2284
+ this.http = http;
2285
+ }
2286
+ /**
2287
+ * Get the full analytics dashboard with all key metrics
2288
+ */
2289
+ async getDashboard(options) {
2290
+ const params = new URLSearchParams();
2291
+ if (options?.appId) params.append("appId", options.appId);
2292
+ const query = params.toString();
2293
+ return this.http.get(`/v1/analytics/dashboard${query ? `?${query}` : ""}`);
2294
+ }
2295
+ /**
2296
+ * Get current Monthly Recurring Revenue
2297
+ */
2298
+ async getMRR(options) {
2299
+ const params = new URLSearchParams();
2300
+ if (options?.appId) params.append("appId", options.appId);
2301
+ const query = params.toString();
2302
+ return this.http.get(`/v1/analytics/revenue/mrr${query ? `?${query}` : ""}`);
2303
+ }
2304
+ /**
2305
+ * Get MRR history over time for trend analysis
2306
+ */
2307
+ async getMRRHistory(options) {
2308
+ const params = new URLSearchParams();
2309
+ if (options?.appId) params.append("appId", options.appId);
2310
+ if (options?.days) params.append("days", options.days.toString());
2311
+ const query = params.toString();
2312
+ return this.http.get(`/v1/analytics/revenue/history${query ? `?${query}` : ""}`);
2313
+ }
2314
+ /**
2315
+ * Get revenue breakdown by plan
2316
+ */
2317
+ async getRevenueByPlan(options) {
2318
+ const params = new URLSearchParams();
2319
+ if (options?.appId) params.append("appId", options.appId);
2320
+ const query = params.toString();
2321
+ return this.http.get(`/v1/analytics/revenue/by-plan${query ? `?${query}` : ""}`);
2322
+ }
2323
+ /**
2324
+ * Get Average Revenue Per User
2325
+ */
2326
+ async getARPU(options) {
2327
+ const params = new URLSearchParams();
2328
+ if (options?.appId) params.append("appId", options.appId);
2329
+ const query = params.toString();
2330
+ return this.http.get(`/v1/analytics/revenue/arpu${query ? `?${query}` : ""}`);
2331
+ }
2332
+ /**
2333
+ * Get subscription metrics (active count, churn rate)
2334
+ */
2335
+ async getSubscriptionMetrics(options) {
2336
+ const params = new URLSearchParams();
2337
+ if (options?.appId) params.append("appId", options.appId);
2338
+ if (options?.days) params.append("days", options.days.toString());
2339
+ const query = params.toString();
2340
+ return this.http.get(`/v1/analytics/subscriptions/metrics${query ? `?${query}` : ""}`);
2341
+ }
2342
+ /**
2343
+ * Get subscriber distribution by plan
2344
+ */
2345
+ async getSubscribersByPlan(options) {
2346
+ const params = new URLSearchParams();
2347
+ if (options?.appId) params.append("appId", options.appId);
2348
+ const query = params.toString();
2349
+ return this.http.get(`/v1/analytics/subscriptions/by-plan${query ? `?${query}` : ""}`);
2350
+ }
2351
+ /**
2352
+ * Get trial metrics (starts, conversions, conversion rate)
2353
+ * Useful for freemium and trial-based pricing models
2354
+ */
2355
+ async getTrialMetrics(options) {
2356
+ const params = new URLSearchParams();
2357
+ if (options?.appId) params.append("appId", options.appId);
2358
+ if (options?.days) params.append("days", options.days.toString());
2359
+ const query = params.toString();
2360
+ return this.http.get(`/v1/analytics/trials/metrics${query ? `?${query}` : ""}`);
2361
+ }
2362
+ /**
2363
+ * Get growth metrics (new vs churned subscribers)
2364
+ */
2365
+ async getGrowthMetrics(options) {
2366
+ const params = new URLSearchParams();
2367
+ if (options?.appId) params.append("appId", options.appId);
2368
+ if (options?.days) params.append("days", options.days.toString());
2369
+ const query = params.toString();
2370
+ return this.http.get(`/v1/analytics/growth/metrics${query ? `?${query}` : ""}`);
2371
+ }
2372
+ /**
2373
+ * Get growth chart data (daily new vs churned for charting)
2374
+ */
2375
+ async getGrowthChart(options) {
2376
+ const params = new URLSearchParams();
2377
+ if (options?.appId) params.append("appId", options.appId);
2378
+ if (options?.days) params.append("days", options.days.toString());
2379
+ const query = params.toString();
2380
+ return this.http.get(`/v1/analytics/growth/chart${query ? `?${query}` : ""}`);
2381
+ }
2382
+ /**
2383
+ * Get checkout conversion rate
2384
+ */
2385
+ async getConversionRate(options) {
2386
+ const params = new URLSearchParams();
2387
+ if (options?.appId) params.append("appId", options.appId);
2388
+ if (options?.days) params.append("days", options.days.toString());
2389
+ const query = params.toString();
2390
+ return this.http.get(`/v1/analytics/conversion/rate${query ? `?${query}` : ""}`);
2391
+ }
2392
+ /**
2393
+ * Get API request counts over time
2394
+ */
2395
+ async getRequestCounts(options) {
2396
+ const params = new URLSearchParams();
2397
+ if (options?.appId) params.append("appId", options.appId);
2398
+ if (options?.days) params.append("days", options.days.toString());
2399
+ const query = params.toString();
2400
+ return this.http.get(`/v1/analytics/api/requests${query ? `?${query}` : ""}`);
2401
+ }
2402
+ /**
2403
+ * Get most popular API endpoints
2404
+ */
2405
+ async getPopularEndpoints(options) {
2406
+ const params = new URLSearchParams();
2407
+ if (options?.appId) params.append("appId", options.appId);
2408
+ if (options?.limit) params.append("limit", options.limit.toString());
2409
+ const query = params.toString();
2410
+ return this.http.get(`/v1/analytics/api/endpoints${query ? `?${query}` : ""}`);
2411
+ }
2412
+ /**
2413
+ * Get API performance metrics (error rate, response time)
2414
+ */
2415
+ async getPerformance(options) {
2416
+ const params = new URLSearchParams();
2417
+ if (options?.appId) params.append("appId", options.appId);
2418
+ if (options?.days) params.append("days", options.days.toString());
2419
+ const query = params.toString();
2420
+ return this.http.get(`/v1/analytics/api/performance${query ? `?${query}` : ""}`);
2421
+ }
2422
+ /**
2423
+ * Get feature usage over time (entitlement checks)
2424
+ */
2425
+ async getFeatureUsage(options) {
2426
+ const params = new URLSearchParams();
2427
+ if (options?.appId) params.append("appId", options.appId);
2428
+ if (options?.days) params.append("days", options.days.toString());
2429
+ const query = params.toString();
2430
+ return this.http.get(`/v1/analytics/features/usage${query ? `?${query}` : ""}`);
2431
+ }
2432
+ };
2433
+
2280
2434
  // src/client.ts
2281
2435
  var DEFAULT_BASE_URL = "https://api.stackbe.io";
2282
2436
  var DEFAULT_TIMEOUT = 3e4;
@@ -2343,6 +2497,7 @@ var StackBE = class {
2343
2497
  this.affiliates = new AffiliatesClient(this.http);
2344
2498
  this.earlyAccess = new EarlyAccessClient(this.http, config.appId);
2345
2499
  this.coupons = new CouponsClient(this.http, config.appId);
2500
+ this.analytics = new AnalyticsClient(this.http);
2346
2501
  }
2347
2502
  /**
2348
2503
  * Create a middleware for Express that tracks usage automatically.
@@ -2477,6 +2632,7 @@ var StackBE = class {
2477
2632
  // Annotate the CommonJS export names for ESM import in node:
2478
2633
  0 && (module.exports = {
2479
2634
  AffiliatesClient,
2635
+ AnalyticsClient,
2480
2636
  AuthClient,
2481
2637
  CheckoutClient,
2482
2638
  CouponsClient,
package/dist/index.mjs CHANGED
@@ -2237,6 +2237,159 @@ var CouponsClient = class {
2237
2237
  }
2238
2238
  };
2239
2239
 
2240
+ // src/analytics.ts
2241
+ var AnalyticsClient = class {
2242
+ constructor(http) {
2243
+ this.http = http;
2244
+ }
2245
+ /**
2246
+ * Get the full analytics dashboard with all key metrics
2247
+ */
2248
+ async getDashboard(options) {
2249
+ const params = new URLSearchParams();
2250
+ if (options?.appId) params.append("appId", options.appId);
2251
+ const query = params.toString();
2252
+ return this.http.get(`/v1/analytics/dashboard${query ? `?${query}` : ""}`);
2253
+ }
2254
+ /**
2255
+ * Get current Monthly Recurring Revenue
2256
+ */
2257
+ async getMRR(options) {
2258
+ const params = new URLSearchParams();
2259
+ if (options?.appId) params.append("appId", options.appId);
2260
+ const query = params.toString();
2261
+ return this.http.get(`/v1/analytics/revenue/mrr${query ? `?${query}` : ""}`);
2262
+ }
2263
+ /**
2264
+ * Get MRR history over time for trend analysis
2265
+ */
2266
+ async getMRRHistory(options) {
2267
+ const params = new URLSearchParams();
2268
+ if (options?.appId) params.append("appId", options.appId);
2269
+ if (options?.days) params.append("days", options.days.toString());
2270
+ const query = params.toString();
2271
+ return this.http.get(`/v1/analytics/revenue/history${query ? `?${query}` : ""}`);
2272
+ }
2273
+ /**
2274
+ * Get revenue breakdown by plan
2275
+ */
2276
+ async getRevenueByPlan(options) {
2277
+ const params = new URLSearchParams();
2278
+ if (options?.appId) params.append("appId", options.appId);
2279
+ const query = params.toString();
2280
+ return this.http.get(`/v1/analytics/revenue/by-plan${query ? `?${query}` : ""}`);
2281
+ }
2282
+ /**
2283
+ * Get Average Revenue Per User
2284
+ */
2285
+ async getARPU(options) {
2286
+ const params = new URLSearchParams();
2287
+ if (options?.appId) params.append("appId", options.appId);
2288
+ const query = params.toString();
2289
+ return this.http.get(`/v1/analytics/revenue/arpu${query ? `?${query}` : ""}`);
2290
+ }
2291
+ /**
2292
+ * Get subscription metrics (active count, churn rate)
2293
+ */
2294
+ async getSubscriptionMetrics(options) {
2295
+ const params = new URLSearchParams();
2296
+ if (options?.appId) params.append("appId", options.appId);
2297
+ if (options?.days) params.append("days", options.days.toString());
2298
+ const query = params.toString();
2299
+ return this.http.get(`/v1/analytics/subscriptions/metrics${query ? `?${query}` : ""}`);
2300
+ }
2301
+ /**
2302
+ * Get subscriber distribution by plan
2303
+ */
2304
+ async getSubscribersByPlan(options) {
2305
+ const params = new URLSearchParams();
2306
+ if (options?.appId) params.append("appId", options.appId);
2307
+ const query = params.toString();
2308
+ return this.http.get(`/v1/analytics/subscriptions/by-plan${query ? `?${query}` : ""}`);
2309
+ }
2310
+ /**
2311
+ * Get trial metrics (starts, conversions, conversion rate)
2312
+ * Useful for freemium and trial-based pricing models
2313
+ */
2314
+ async getTrialMetrics(options) {
2315
+ const params = new URLSearchParams();
2316
+ if (options?.appId) params.append("appId", options.appId);
2317
+ if (options?.days) params.append("days", options.days.toString());
2318
+ const query = params.toString();
2319
+ return this.http.get(`/v1/analytics/trials/metrics${query ? `?${query}` : ""}`);
2320
+ }
2321
+ /**
2322
+ * Get growth metrics (new vs churned subscribers)
2323
+ */
2324
+ async getGrowthMetrics(options) {
2325
+ const params = new URLSearchParams();
2326
+ if (options?.appId) params.append("appId", options.appId);
2327
+ if (options?.days) params.append("days", options.days.toString());
2328
+ const query = params.toString();
2329
+ return this.http.get(`/v1/analytics/growth/metrics${query ? `?${query}` : ""}`);
2330
+ }
2331
+ /**
2332
+ * Get growth chart data (daily new vs churned for charting)
2333
+ */
2334
+ async getGrowthChart(options) {
2335
+ const params = new URLSearchParams();
2336
+ if (options?.appId) params.append("appId", options.appId);
2337
+ if (options?.days) params.append("days", options.days.toString());
2338
+ const query = params.toString();
2339
+ return this.http.get(`/v1/analytics/growth/chart${query ? `?${query}` : ""}`);
2340
+ }
2341
+ /**
2342
+ * Get checkout conversion rate
2343
+ */
2344
+ async getConversionRate(options) {
2345
+ const params = new URLSearchParams();
2346
+ if (options?.appId) params.append("appId", options.appId);
2347
+ if (options?.days) params.append("days", options.days.toString());
2348
+ const query = params.toString();
2349
+ return this.http.get(`/v1/analytics/conversion/rate${query ? `?${query}` : ""}`);
2350
+ }
2351
+ /**
2352
+ * Get API request counts over time
2353
+ */
2354
+ async getRequestCounts(options) {
2355
+ const params = new URLSearchParams();
2356
+ if (options?.appId) params.append("appId", options.appId);
2357
+ if (options?.days) params.append("days", options.days.toString());
2358
+ const query = params.toString();
2359
+ return this.http.get(`/v1/analytics/api/requests${query ? `?${query}` : ""}`);
2360
+ }
2361
+ /**
2362
+ * Get most popular API endpoints
2363
+ */
2364
+ async getPopularEndpoints(options) {
2365
+ const params = new URLSearchParams();
2366
+ if (options?.appId) params.append("appId", options.appId);
2367
+ if (options?.limit) params.append("limit", options.limit.toString());
2368
+ const query = params.toString();
2369
+ return this.http.get(`/v1/analytics/api/endpoints${query ? `?${query}` : ""}`);
2370
+ }
2371
+ /**
2372
+ * Get API performance metrics (error rate, response time)
2373
+ */
2374
+ async getPerformance(options) {
2375
+ const params = new URLSearchParams();
2376
+ if (options?.appId) params.append("appId", options.appId);
2377
+ if (options?.days) params.append("days", options.days.toString());
2378
+ const query = params.toString();
2379
+ return this.http.get(`/v1/analytics/api/performance${query ? `?${query}` : ""}`);
2380
+ }
2381
+ /**
2382
+ * Get feature usage over time (entitlement checks)
2383
+ */
2384
+ async getFeatureUsage(options) {
2385
+ const params = new URLSearchParams();
2386
+ if (options?.appId) params.append("appId", options.appId);
2387
+ if (options?.days) params.append("days", options.days.toString());
2388
+ const query = params.toString();
2389
+ return this.http.get(`/v1/analytics/features/usage${query ? `?${query}` : ""}`);
2390
+ }
2391
+ };
2392
+
2240
2393
  // src/client.ts
2241
2394
  var DEFAULT_BASE_URL = "https://api.stackbe.io";
2242
2395
  var DEFAULT_TIMEOUT = 3e4;
@@ -2303,6 +2456,7 @@ var StackBE = class {
2303
2456
  this.affiliates = new AffiliatesClient(this.http);
2304
2457
  this.earlyAccess = new EarlyAccessClient(this.http, config.appId);
2305
2458
  this.coupons = new CouponsClient(this.http, config.appId);
2459
+ this.analytics = new AnalyticsClient(this.http);
2306
2460
  }
2307
2461
  /**
2308
2462
  * Create a middleware for Express that tracks usage automatically.
@@ -2436,6 +2590,7 @@ var StackBE = class {
2436
2590
  };
2437
2591
  export {
2438
2592
  AffiliatesClient,
2593
+ AnalyticsClient,
2439
2594
  AuthClient,
2440
2595
  CheckoutClient,
2441
2596
  CouponsClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackbe/sdk",
3
- "version": "0.9.5",
3
+ "version": "0.11.0",
4
4
  "description": "Official JavaScript/TypeScript SDK for StackBE - the billing backend for your side project",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -20,7 +20,10 @@
20
20
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
21
21
  "lint": "eslint src/",
22
22
  "typecheck": "tsc --noEmit",
23
- "prepublishOnly": "npm run build"
23
+ "prepublishOnly": "npm run build",
24
+ "test": "jest",
25
+ "test:contract": "jest test/contract.test.ts",
26
+ "test:contract:prod": "API_URL=https://api.stackbe.io jest test/contract.test.ts"
24
27
  },
25
28
  "keywords": [
26
29
  "stackbe",
@@ -42,7 +45,10 @@
42
45
  "url": "https://github.com/Epic-Design-Labs/app-stackbe-sdk/issues"
43
46
  },
44
47
  "devDependencies": {
48
+ "@types/jest": "^30.0.0",
45
49
  "@types/node": "^20.10.0",
50
+ "jest": "^30.2.0",
51
+ "ts-jest": "^29.4.6",
46
52
  "tsup": "^8.0.1",
47
53
  "typescript": "^5.3.0"
48
54
  },