@umituz/web-polar-payment 1.0.14 → 1.0.16

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
@@ -1,11 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as react from 'react';
3
2
  import { ReactNode } from 'react';
4
3
 
5
- /**
6
- * Subscription Entity
7
- * @description Types for subscription status and billing cycles
8
- */
9
4
  type SubscriptionStatusValue = 'active' | 'canceled' | 'revoked' | 'trialing' | 'past_due' | 'incomplete' | 'incomplete_expired' | 'unpaid' | 'none';
10
5
  type BillingCycle = 'monthly' | 'yearly';
11
6
  interface SubscriptionStatus {
@@ -16,14 +11,9 @@ interface SubscriptionStatus {
16
11
  currentPeriodEnd?: string;
17
12
  billingCycle?: BillingCycle;
18
13
  polarCustomerId?: string;
19
- /** Token balance (for token-based projects like Aria) */
20
14
  tokens?: number;
21
15
  }
22
16
 
23
- /**
24
- * Order Entity
25
- * @description Types for billing history items
26
- */
27
17
  interface OrderItem {
28
18
  id: string;
29
19
  createdAt: string;
@@ -35,16 +25,11 @@ interface OrderItem {
35
25
  invoiceUrl?: string;
36
26
  }
37
27
 
38
- /**
39
- * Checkout Entity
40
- * @description Types for initiating and following process of checkouts
41
- */
42
28
  interface CheckoutParams {
43
29
  productId: string;
44
30
  planKey?: string;
45
31
  billingCycle?: 'monthly' | 'yearly';
46
32
  successUrl?: string;
47
- /** Injected automatically by PolarProvider — do not pass manually */
48
33
  userId?: string;
49
34
  }
50
35
  interface CheckoutResult {
@@ -52,43 +37,47 @@ interface CheckoutResult {
52
37
  id: string;
53
38
  }
54
39
 
55
- /**
56
- * Cancellation Entity
57
- * @description Types for subscription cancellation reasons and outcomes
58
- */
59
40
  type CancellationReason = 'too_expensive' | 'missing_features' | 'switched_service' | 'unused' | 'customer_service' | 'low_quality' | 'too_complex' | 'other';
60
41
  interface CancelResult {
61
42
  success: boolean;
62
43
  endsAt?: string;
63
44
  }
64
45
 
65
- /**
66
- * Sync Entity
67
- * @description Type for subscription synchronization results
68
- */
69
46
  interface SyncResult {
70
47
  synced: boolean;
71
48
  plan?: string;
72
49
  }
73
50
 
74
- /**
75
- * Backend-agnostic interface every adapter must implement.
76
- * @description Contract for Polar billing adapters (Firebase, Supabase, etc.)
77
- */
78
51
  interface PolarAdapter {
79
52
  getStatus(userId: string): Promise<SubscriptionStatus>;
80
53
  createCheckout(params: CheckoutParams): Promise<CheckoutResult>;
81
- /** checkoutId is read from URL by the context and passed explicitly */
82
54
  syncSubscription(userId: string, checkoutId?: string): Promise<SyncResult>;
83
55
  getBillingHistory(userId: string): Promise<OrderItem[]>;
84
56
  cancelSubscription(reason?: CancellationReason): Promise<CancelResult>;
85
57
  getPortalUrl(userId: string): Promise<string>;
86
58
  }
87
59
 
60
+ interface PolarProviderProps {
61
+ adapter: PolarAdapter;
62
+ userId?: string;
63
+ children: ReactNode;
64
+ }
65
+ declare function PolarProvider({ adapter, userId, children }: PolarProviderProps): react_jsx_runtime.JSX.Element;
66
+
67
+ interface PolarContextValue {
68
+ status: SubscriptionStatus;
69
+ loading: boolean;
70
+ refresh: () => Promise<void>;
71
+ startCheckout: (params: CheckoutParams) => Promise<void>;
72
+ syncSubscription: () => Promise<SyncResult>;
73
+ getBillingHistory: () => Promise<OrderItem[]>;
74
+ cancelSubscription: (reason?: CancellationReason) => Promise<CancelResult>;
75
+ getPortalUrl: () => Promise<string>;
76
+ }
77
+ declare function usePolarBilling(): PolarContextValue;
78
+
88
79
  interface FirebaseAdapterConfig {
89
- /** Firebase Functions instance from firebase/functions */
90
80
  functions: unknown;
91
- /** Firebase Firestore instance from firebase/firestore */
92
81
  firestore: unknown;
93
82
  callables?: {
94
83
  createCheckout?: string;
@@ -108,16 +97,8 @@ interface FirebaseAdapterConfig {
108
97
  currentPeriodEndField?: string;
109
98
  };
110
99
  }
111
- /**
112
- * Firebase Billing Service
113
- * @description Implementation of PolarAdapter for Firebase Functions and Firestore.
114
- */
115
100
  declare function createFirebaseAdapter(config: FirebaseAdapterConfig): PolarAdapter;
116
101
 
117
- /**
118
- * Billing Constants
119
- * @description Standardized subscription states and plan names
120
- */
121
102
  declare const SUBSCRIPTION_STATUS: Readonly<{
122
103
  ACTIVE: "active";
123
104
  CANCELED: "canceled";
@@ -129,46 +110,5 @@ declare const SUBSCRIPTION_STATUS: Readonly<{
129
110
  UNPAID: "unpaid";
130
111
  NONE: "none";
131
112
  }>;
132
- declare const FREE_PLAN = "free";
133
-
134
- /**
135
- * Normalize a raw Polar status string to a known value.
136
- * @description Defaults to 'none' for unknown statuses or non-string input.
137
- */
138
- declare function normalizeStatus(raw: string): SubscriptionStatusValue;
139
- /**
140
- * Normalize billing interval
141
- * @description Maps 'month'/'year' to 'monthly'/'yearly'. Defaults to 'monthly' for unknown values or non-string input.
142
- */
143
- declare function normalizeBillingCycle(interval: string): BillingCycle;
144
-
145
- /**
146
- * PolarProvider Component
147
- * @description Context provider for Polar billing management.
148
- */
149
- interface PolarProviderProps {
150
- adapter: PolarAdapter;
151
- userId?: string;
152
- children: ReactNode;
153
- }
154
- declare function PolarProvider({ adapter, userId, children }: PolarProviderProps): react_jsx_runtime.JSX.Element;
155
-
156
- interface PolarContextValue {
157
- status: SubscriptionStatus;
158
- loading: boolean;
159
- refresh: () => Promise<void>;
160
- startCheckout: (params: CheckoutParams) => Promise<void>;
161
- syncSubscription: () => Promise<SyncResult>;
162
- getBillingHistory: () => Promise<OrderItem[]>;
163
- cancelSubscription: (reason?: CancellationReason) => Promise<CancelResult>;
164
- getPortalUrl: () => Promise<string>;
165
- }
166
- declare const PolarContext: react.Context<PolarContextValue | undefined>;
167
- /**
168
- * usePolarBilling Hook
169
- * @description Hook to access Polar billing context
170
- */
171
- declare function usePolarBilling(): PolarContextValue;
172
- declare const useSubscription: typeof usePolarBilling;
173
113
 
174
- export { type BillingCycle, type CancelResult, type CancellationReason, type CheckoutParams, type CheckoutResult, FREE_PLAN, type FirebaseAdapterConfig, type OrderItem, type PolarAdapter, PolarContext, type PolarContextValue, PolarProvider, SUBSCRIPTION_STATUS, type SubscriptionStatus, type SubscriptionStatusValue, type SyncResult, createFirebaseAdapter, normalizeBillingCycle, normalizeStatus, usePolarBilling, useSubscription };
114
+ export { type BillingCycle, type CancelResult, type CancellationReason, type CheckoutParams, type CheckoutResult, type FirebaseAdapterConfig, type OrderItem, type PolarAdapter, type PolarContextValue, PolarProvider, SUBSCRIPTION_STATUS, type SubscriptionStatus, type SubscriptionStatusValue, type SyncResult, createFirebaseAdapter, usePolarBilling };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as react from 'react';
3
2
  import { ReactNode } from 'react';
4
3
 
5
- /**
6
- * Subscription Entity
7
- * @description Types for subscription status and billing cycles
8
- */
9
4
  type SubscriptionStatusValue = 'active' | 'canceled' | 'revoked' | 'trialing' | 'past_due' | 'incomplete' | 'incomplete_expired' | 'unpaid' | 'none';
10
5
  type BillingCycle = 'monthly' | 'yearly';
11
6
  interface SubscriptionStatus {
@@ -16,14 +11,9 @@ interface SubscriptionStatus {
16
11
  currentPeriodEnd?: string;
17
12
  billingCycle?: BillingCycle;
18
13
  polarCustomerId?: string;
19
- /** Token balance (for token-based projects like Aria) */
20
14
  tokens?: number;
21
15
  }
22
16
 
23
- /**
24
- * Order Entity
25
- * @description Types for billing history items
26
- */
27
17
  interface OrderItem {
28
18
  id: string;
29
19
  createdAt: string;
@@ -35,16 +25,11 @@ interface OrderItem {
35
25
  invoiceUrl?: string;
36
26
  }
37
27
 
38
- /**
39
- * Checkout Entity
40
- * @description Types for initiating and following process of checkouts
41
- */
42
28
  interface CheckoutParams {
43
29
  productId: string;
44
30
  planKey?: string;
45
31
  billingCycle?: 'monthly' | 'yearly';
46
32
  successUrl?: string;
47
- /** Injected automatically by PolarProvider — do not pass manually */
48
33
  userId?: string;
49
34
  }
50
35
  interface CheckoutResult {
@@ -52,43 +37,47 @@ interface CheckoutResult {
52
37
  id: string;
53
38
  }
54
39
 
55
- /**
56
- * Cancellation Entity
57
- * @description Types for subscription cancellation reasons and outcomes
58
- */
59
40
  type CancellationReason = 'too_expensive' | 'missing_features' | 'switched_service' | 'unused' | 'customer_service' | 'low_quality' | 'too_complex' | 'other';
60
41
  interface CancelResult {
61
42
  success: boolean;
62
43
  endsAt?: string;
63
44
  }
64
45
 
65
- /**
66
- * Sync Entity
67
- * @description Type for subscription synchronization results
68
- */
69
46
  interface SyncResult {
70
47
  synced: boolean;
71
48
  plan?: string;
72
49
  }
73
50
 
74
- /**
75
- * Backend-agnostic interface every adapter must implement.
76
- * @description Contract for Polar billing adapters (Firebase, Supabase, etc.)
77
- */
78
51
  interface PolarAdapter {
79
52
  getStatus(userId: string): Promise<SubscriptionStatus>;
80
53
  createCheckout(params: CheckoutParams): Promise<CheckoutResult>;
81
- /** checkoutId is read from URL by the context and passed explicitly */
82
54
  syncSubscription(userId: string, checkoutId?: string): Promise<SyncResult>;
83
55
  getBillingHistory(userId: string): Promise<OrderItem[]>;
84
56
  cancelSubscription(reason?: CancellationReason): Promise<CancelResult>;
85
57
  getPortalUrl(userId: string): Promise<string>;
86
58
  }
87
59
 
60
+ interface PolarProviderProps {
61
+ adapter: PolarAdapter;
62
+ userId?: string;
63
+ children: ReactNode;
64
+ }
65
+ declare function PolarProvider({ adapter, userId, children }: PolarProviderProps): react_jsx_runtime.JSX.Element;
66
+
67
+ interface PolarContextValue {
68
+ status: SubscriptionStatus;
69
+ loading: boolean;
70
+ refresh: () => Promise<void>;
71
+ startCheckout: (params: CheckoutParams) => Promise<void>;
72
+ syncSubscription: () => Promise<SyncResult>;
73
+ getBillingHistory: () => Promise<OrderItem[]>;
74
+ cancelSubscription: (reason?: CancellationReason) => Promise<CancelResult>;
75
+ getPortalUrl: () => Promise<string>;
76
+ }
77
+ declare function usePolarBilling(): PolarContextValue;
78
+
88
79
  interface FirebaseAdapterConfig {
89
- /** Firebase Functions instance from firebase/functions */
90
80
  functions: unknown;
91
- /** Firebase Firestore instance from firebase/firestore */
92
81
  firestore: unknown;
93
82
  callables?: {
94
83
  createCheckout?: string;
@@ -108,16 +97,8 @@ interface FirebaseAdapterConfig {
108
97
  currentPeriodEndField?: string;
109
98
  };
110
99
  }
111
- /**
112
- * Firebase Billing Service
113
- * @description Implementation of PolarAdapter for Firebase Functions and Firestore.
114
- */
115
100
  declare function createFirebaseAdapter(config: FirebaseAdapterConfig): PolarAdapter;
116
101
 
117
- /**
118
- * Billing Constants
119
- * @description Standardized subscription states and plan names
120
- */
121
102
  declare const SUBSCRIPTION_STATUS: Readonly<{
122
103
  ACTIVE: "active";
123
104
  CANCELED: "canceled";
@@ -129,46 +110,5 @@ declare const SUBSCRIPTION_STATUS: Readonly<{
129
110
  UNPAID: "unpaid";
130
111
  NONE: "none";
131
112
  }>;
132
- declare const FREE_PLAN = "free";
133
-
134
- /**
135
- * Normalize a raw Polar status string to a known value.
136
- * @description Defaults to 'none' for unknown statuses or non-string input.
137
- */
138
- declare function normalizeStatus(raw: string): SubscriptionStatusValue;
139
- /**
140
- * Normalize billing interval
141
- * @description Maps 'month'/'year' to 'monthly'/'yearly'. Defaults to 'monthly' for unknown values or non-string input.
142
- */
143
- declare function normalizeBillingCycle(interval: string): BillingCycle;
144
-
145
- /**
146
- * PolarProvider Component
147
- * @description Context provider for Polar billing management.
148
- */
149
- interface PolarProviderProps {
150
- adapter: PolarAdapter;
151
- userId?: string;
152
- children: ReactNode;
153
- }
154
- declare function PolarProvider({ adapter, userId, children }: PolarProviderProps): react_jsx_runtime.JSX.Element;
155
-
156
- interface PolarContextValue {
157
- status: SubscriptionStatus;
158
- loading: boolean;
159
- refresh: () => Promise<void>;
160
- startCheckout: (params: CheckoutParams) => Promise<void>;
161
- syncSubscription: () => Promise<SyncResult>;
162
- getBillingHistory: () => Promise<OrderItem[]>;
163
- cancelSubscription: (reason?: CancellationReason) => Promise<CancelResult>;
164
- getPortalUrl: () => Promise<string>;
165
- }
166
- declare const PolarContext: react.Context<PolarContextValue | undefined>;
167
- /**
168
- * usePolarBilling Hook
169
- * @description Hook to access Polar billing context
170
- */
171
- declare function usePolarBilling(): PolarContextValue;
172
- declare const useSubscription: typeof usePolarBilling;
173
113
 
174
- export { type BillingCycle, type CancelResult, type CancellationReason, type CheckoutParams, type CheckoutResult, FREE_PLAN, type FirebaseAdapterConfig, type OrderItem, type PolarAdapter, PolarContext, type PolarContextValue, PolarProvider, SUBSCRIPTION_STATUS, type SubscriptionStatus, type SubscriptionStatusValue, type SyncResult, createFirebaseAdapter, normalizeBillingCycle, normalizeStatus, usePolarBilling, useSubscription };
114
+ export { type BillingCycle, type CancelResult, type CancellationReason, type CheckoutParams, type CheckoutResult, type FirebaseAdapterConfig, type OrderItem, type PolarAdapter, type PolarContextValue, PolarProvider, SUBSCRIPTION_STATUS, type SubscriptionStatus, type SubscriptionStatusValue, type SyncResult, createFirebaseAdapter, usePolarBilling };