@solvapay/react 1.0.8-preview.8 → 1.0.8-preview.9
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 +2 -6
- package/dist/index.js +2 -6
- package/package.json +2 -2
- package/dist/CancelPlanButton-BKH_yv1d.d.ts +0 -1113
- package/dist/CancelPlanButton-Bb7cvym9.d.cts +0 -1105
- package/dist/CancelPlanButton-Cq117t7h.d.ts +0 -1105
- package/dist/CancelPlanButton-DQXUTHmF.d.cts +0 -1113
- package/dist/PaymentForm-B5dw0i1X.d.ts +0 -934
- package/dist/PaymentForm-CesoRQWu.d.cts +0 -934
- package/dist/chunk-5FZBOPIW.js +0 -4763
- package/dist/chunk-C7SKOENW.js +0 -1889
- package/dist/chunk-ISYAH4ZL.js +0 -1889
- package/dist/chunk-Q7GPX6X4.js +0 -4748
- package/dist/chunk-TP4JPKE2.js +0 -3126
- package/dist/chunk-VTGIXJQU.js +0 -4755
- package/dist/chunk-XMQ4GBWQ.js +0 -4752
- package/dist/index-DLl3UwO3.d.ts +0 -798
- package/dist/index-Sj2lHLl8.d.cts +0 -798
- package/dist/src/PaymentForm.d.ts +0 -56
- package/dist/src/PaymentForm.d.ts.map +0 -1
- package/dist/src/PaymentForm.js +0 -212
- package/dist/src/PaymentForm.js.map +0 -1
- package/dist/src/SolvaPayProvider.d.ts +0 -84
- package/dist/src/SolvaPayProvider.d.ts.map +0 -1
- package/dist/src/SolvaPayProvider.js +0 -537
- package/dist/src/SolvaPayProvider.js.map +0 -1
- package/dist/src/adapters/auth.d.ts +0 -43
- package/dist/src/adapters/auth.d.ts.map +0 -1
- package/dist/src/adapters/auth.js +0 -38
- package/dist/src/adapters/auth.js.map +0 -1
- package/dist/src/components/PlanBadge.d.ts +0 -31
- package/dist/src/components/PlanBadge.d.ts.map +0 -1
- package/dist/src/components/PlanBadge.js +0 -119
- package/dist/src/components/PlanBadge.js.map +0 -1
- package/dist/src/components/PlanSelector.d.ts +0 -49
- package/dist/src/components/PlanSelector.d.ts.map +0 -1
- package/dist/src/components/PlanSelector.js +0 -82
- package/dist/src/components/PlanSelector.js.map +0 -1
- package/dist/src/components/Spinner.d.ts +0 -10
- package/dist/src/components/Spinner.d.ts.map +0 -1
- package/dist/src/components/Spinner.js +0 -14
- package/dist/src/components/Spinner.js.map +0 -1
- package/dist/src/components/StripePaymentFormWrapper.d.ts +0 -17
- package/dist/src/components/StripePaymentFormWrapper.d.ts.map +0 -1
- package/dist/src/components/StripePaymentFormWrapper.js +0 -158
- package/dist/src/components/StripePaymentFormWrapper.js.map +0 -1
- package/dist/src/components/SubscriptionGate.d.ts +0 -21
- package/dist/src/components/SubscriptionGate.d.ts.map +0 -1
- package/dist/src/components/SubscriptionGate.js +0 -32
- package/dist/src/components/SubscriptionGate.js.map +0 -1
- package/dist/src/hooks/__tests__/useSubscription.test.d.ts +0 -2
- package/dist/src/hooks/__tests__/useSubscription.test.d.ts.map +0 -1
- package/dist/src/hooks/__tests__/useSubscription.test.js +0 -554
- package/dist/src/hooks/__tests__/useSubscription.test.js.map +0 -1
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.d.ts +0 -2
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.d.ts.map +0 -1
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.js +0 -719
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.js.map +0 -1
- package/dist/src/hooks/useCheckout.d.ts +0 -59
- package/dist/src/hooks/useCheckout.d.ts.map +0 -1
- package/dist/src/hooks/useCheckout.js +0 -138
- package/dist/src/hooks/useCheckout.js.map +0 -1
- package/dist/src/hooks/useCustomer.d.ts +0 -43
- package/dist/src/hooks/useCustomer.d.ts.map +0 -1
- package/dist/src/hooks/useCustomer.js +0 -31
- package/dist/src/hooks/useCustomer.js.map +0 -1
- package/dist/src/hooks/usePlans.d.ts +0 -28
- package/dist/src/hooks/usePlans.d.ts.map +0 -1
- package/dist/src/hooks/usePlans.js +0 -181
- package/dist/src/hooks/usePlans.js.map +0 -1
- package/dist/src/hooks/useSolvaPay.d.ts +0 -44
- package/dist/src/hooks/useSolvaPay.d.ts.map +0 -1
- package/dist/src/hooks/useSolvaPay.js +0 -52
- package/dist/src/hooks/useSolvaPay.js.map +0 -1
- package/dist/src/hooks/useSubscription.d.ts +0 -46
- package/dist/src/hooks/useSubscription.d.ts.map +0 -1
- package/dist/src/hooks/useSubscription.js +0 -50
- package/dist/src/hooks/useSubscription.js.map +0 -1
- package/dist/src/hooks/useSubscriptionStatus.d.ts +0 -19
- package/dist/src/hooks/useSubscriptionStatus.d.ts.map +0 -1
- package/dist/src/hooks/useSubscriptionStatus.js +0 -68
- package/dist/src/hooks/useSubscriptionStatus.js.map +0 -1
- package/dist/src/index.d.ts +0 -24
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -26
- package/dist/src/index.js.map +0 -1
- package/dist/src/types/index.d.ts +0 -339
- package/dist/src/types/index.d.ts.map +0 -1
- package/dist/src/types/index.js +0 -5
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/utils/__tests__/subscriptions.test.d.ts +0 -2
- package/dist/src/utils/__tests__/subscriptions.test.d.ts.map +0 -1
- package/dist/src/utils/__tests__/subscriptions.test.js +0 -121
- package/dist/src/utils/__tests__/subscriptions.test.js.map +0 -1
- package/dist/src/utils/subscriptions.d.ts +0 -57
- package/dist/src/utils/subscriptions.d.ts.map +0 -1
- package/dist/src/utils/subscriptions.js +0 -85
- package/dist/src/utils/subscriptions.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,537 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
|
4
|
-
import { filterSubscriptions, isPaidSubscription, getPrimarySubscription, } from './utils/subscriptions';
|
|
5
|
-
import { defaultAuthAdapter } from './adapters/auth';
|
|
6
|
-
export const SolvaPayContext = createContext(null);
|
|
7
|
-
// localStorage cache keys
|
|
8
|
-
const CUSTOMER_REF_KEY = 'solvapay_customerRef';
|
|
9
|
-
const CUSTOMER_REF_EXPIRY = 'solvapay_customerRef_expiry';
|
|
10
|
-
const CUSTOMER_REF_USER_ID_KEY = 'solvapay_customerRef_userId'; // Track which userId this customerRef belongs to
|
|
11
|
-
const CACHE_DURATION = 24 * 60 * 60 * 1000; // 24 hours
|
|
12
|
-
/**
|
|
13
|
-
* Get cached customer reference from localStorage
|
|
14
|
-
* Only returns it if it belongs to the current userId (if provided)
|
|
15
|
-
*/
|
|
16
|
-
function getCachedCustomerRef(userId) {
|
|
17
|
-
if (typeof window === 'undefined')
|
|
18
|
-
return null;
|
|
19
|
-
const cached = localStorage.getItem(CUSTOMER_REF_KEY);
|
|
20
|
-
const expiry = localStorage.getItem(CUSTOMER_REF_EXPIRY);
|
|
21
|
-
const cachedUserId = localStorage.getItem(CUSTOMER_REF_USER_ID_KEY);
|
|
22
|
-
if (!cached || !expiry)
|
|
23
|
-
return null;
|
|
24
|
-
if (Date.now() > parseInt(expiry)) {
|
|
25
|
-
localStorage.removeItem(CUSTOMER_REF_KEY);
|
|
26
|
-
localStorage.removeItem(CUSTOMER_REF_EXPIRY);
|
|
27
|
-
localStorage.removeItem(CUSTOMER_REF_USER_ID_KEY);
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
// CRITICAL: If userId is provided, only return cached customerRef if it belongs to this userId
|
|
31
|
-
// This prevents using a customerRef from a different user after sign out/sign in
|
|
32
|
-
if (userId !== undefined && userId !== null) {
|
|
33
|
-
if (cachedUserId !== userId) {
|
|
34
|
-
// CustomerRef belongs to a different user - clear it
|
|
35
|
-
clearCachedCustomerRef();
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return cached;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Set cached customer reference in localStorage
|
|
43
|
-
* Also stores the userId to prevent cross-user contamination
|
|
44
|
-
*
|
|
45
|
-
* SECURITY: If userId is not provided, we don't cache the customerRef
|
|
46
|
-
* This prevents caching customerRef for unauthenticated users or during auth transitions
|
|
47
|
-
*/
|
|
48
|
-
function setCachedCustomerRef(customerRef, userId) {
|
|
49
|
-
if (typeof window === 'undefined')
|
|
50
|
-
return;
|
|
51
|
-
// SECURITY: Only cache customerRef if we have a userId to associate it with
|
|
52
|
-
// This prevents cross-user contamination and ensures we can validate ownership
|
|
53
|
-
if (userId === undefined || userId === null) {
|
|
54
|
-
// Don't cache if no userId - this prevents security issues
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
localStorage.setItem(CUSTOMER_REF_KEY, customerRef);
|
|
58
|
-
localStorage.setItem(CUSTOMER_REF_EXPIRY, String(Date.now() + CACHE_DURATION));
|
|
59
|
-
localStorage.setItem(CUSTOMER_REF_USER_ID_KEY, userId);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Clear cached customer reference from localStorage
|
|
63
|
-
*/
|
|
64
|
-
function clearCachedCustomerRef() {
|
|
65
|
-
if (typeof window === 'undefined')
|
|
66
|
-
return;
|
|
67
|
-
localStorage.removeItem(CUSTOMER_REF_KEY);
|
|
68
|
-
localStorage.removeItem(CUSTOMER_REF_EXPIRY);
|
|
69
|
-
localStorage.removeItem(CUSTOMER_REF_USER_ID_KEY);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Get the auth adapter to use (adapter > deprecated functions > default)
|
|
73
|
-
*/
|
|
74
|
-
function getAuthAdapter(config) {
|
|
75
|
-
// Use adapter if provided (preferred)
|
|
76
|
-
if (config?.auth?.adapter) {
|
|
77
|
-
return config.auth.adapter;
|
|
78
|
-
}
|
|
79
|
-
// Support deprecated getToken/getUserId functions for backward compatibility
|
|
80
|
-
if (config?.auth?.getToken || config?.auth?.getUserId) {
|
|
81
|
-
return {
|
|
82
|
-
async getToken() {
|
|
83
|
-
return config?.auth?.getToken?.() || null;
|
|
84
|
-
},
|
|
85
|
-
async getUserId() {
|
|
86
|
-
return config?.auth?.getUserId?.() || null;
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
// Default adapter (localStorage only)
|
|
91
|
-
return defaultAuthAdapter;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* SolvaPay Provider - Headless Context Provider for React.
|
|
95
|
-
*
|
|
96
|
-
* Provides subscription state, payment methods, and customer data to child components
|
|
97
|
-
* via React Context. This is the root component that must wrap your app to use
|
|
98
|
-
* SolvaPay React hooks and components.
|
|
99
|
-
*
|
|
100
|
-
* Features:
|
|
101
|
-
* - Automatic subscription status checking
|
|
102
|
-
* - Customer reference caching in localStorage
|
|
103
|
-
* - Payment intent creation and processing
|
|
104
|
-
* - Authentication adapter support (Supabase, custom, etc.)
|
|
105
|
-
* - Zero-config with sensible defaults, or full customization
|
|
106
|
-
*
|
|
107
|
-
* @param props - Provider configuration
|
|
108
|
-
* @param props.config - Configuration object for API routes and authentication
|
|
109
|
-
* @param props.config.api - API route configuration (optional, uses defaults if not provided)
|
|
110
|
-
* @param props.config.api.checkSubscription - Endpoint for checking subscription status (default: '/api/check-subscription')
|
|
111
|
-
* @param props.config.api.createPayment - Endpoint for creating payment intents (default: '/api/create-payment-intent')
|
|
112
|
-
* @param props.config.api.processPayment - Endpoint for processing payments (default: '/api/process-payment')
|
|
113
|
-
* @param props.config.auth - Authentication configuration (optional)
|
|
114
|
-
* @param props.config.auth.adapter - Auth adapter for extracting user ID and token
|
|
115
|
-
* @param props.children - React children components
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```tsx
|
|
119
|
-
* import { SolvaPayProvider } from '@solvapay/react';
|
|
120
|
-
*
|
|
121
|
-
* // Zero config (uses defaults)
|
|
122
|
-
* function App() {
|
|
123
|
-
* return (
|
|
124
|
-
* <SolvaPayProvider>
|
|
125
|
-
* <YourApp />
|
|
126
|
-
* </SolvaPayProvider>
|
|
127
|
-
* );
|
|
128
|
-
* }
|
|
129
|
-
*
|
|
130
|
-
* // Custom API routes
|
|
131
|
-
* function App() {
|
|
132
|
-
* return (
|
|
133
|
-
* <SolvaPayProvider
|
|
134
|
-
* config={{
|
|
135
|
-
* api: {
|
|
136
|
-
* checkSubscription: '/custom/api/subscription',
|
|
137
|
-
* createPayment: '/custom/api/payment'
|
|
138
|
-
* }
|
|
139
|
-
* }}
|
|
140
|
-
* >
|
|
141
|
-
* <YourApp />
|
|
142
|
-
* </SolvaPayProvider>
|
|
143
|
-
* );
|
|
144
|
-
* }
|
|
145
|
-
*
|
|
146
|
-
* // With Supabase auth adapter
|
|
147
|
-
* import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
|
|
148
|
-
*
|
|
149
|
-
* function App() {
|
|
150
|
-
* const adapter = createSupabaseAuthAdapter({
|
|
151
|
-
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
152
|
-
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
153
|
-
* });
|
|
154
|
-
*
|
|
155
|
-
* return (
|
|
156
|
-
* <SolvaPayProvider
|
|
157
|
-
* config={{
|
|
158
|
-
* auth: { adapter }
|
|
159
|
-
* }}
|
|
160
|
-
* >
|
|
161
|
-
* <YourApp />
|
|
162
|
-
* </SolvaPayProvider>
|
|
163
|
-
* );
|
|
164
|
-
* }
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* @see {@link useSubscription} for accessing subscription data
|
|
168
|
-
* @see {@link useCheckout} for payment checkout flow
|
|
169
|
-
* @see {@link useSolvaPay} for accessing provider methods
|
|
170
|
-
* @since 1.0.0
|
|
171
|
-
*/
|
|
172
|
-
export const SolvaPayProvider = ({ config, createPayment: customCreatePayment, checkSubscription: customCheckSubscription, processPayment: customProcessPayment, children, }) => {
|
|
173
|
-
const [subscriptionData, setSubscriptionData] = useState({
|
|
174
|
-
subscriptions: [],
|
|
175
|
-
});
|
|
176
|
-
const [loading, setLoading] = useState(false);
|
|
177
|
-
const [internalCustomerRef, setInternalCustomerRef] = useState(undefined);
|
|
178
|
-
const [userId, setUserId] = useState(null);
|
|
179
|
-
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
180
|
-
// Track in-flight requests to prevent duplicate calls
|
|
181
|
-
const inFlightRef = useRef(null);
|
|
182
|
-
// Track what we've already fetched to prevent unnecessary refetches
|
|
183
|
-
const lastFetchedRef = useRef(null);
|
|
184
|
-
// Store functions in refs to avoid dependency issues
|
|
185
|
-
const checkSubscriptionRef = useRef(null);
|
|
186
|
-
const createPaymentRef = useRef(null);
|
|
187
|
-
const processPaymentRef = useRef(null);
|
|
188
|
-
const configRef = useRef(config);
|
|
189
|
-
const buildDefaultCheckSubscriptionRef = useRef(null);
|
|
190
|
-
// Update refs when props change
|
|
191
|
-
useEffect(() => {
|
|
192
|
-
configRef.current = config;
|
|
193
|
-
}, [config]);
|
|
194
|
-
useEffect(() => {
|
|
195
|
-
checkSubscriptionRef.current = customCheckSubscription || null;
|
|
196
|
-
}, [customCheckSubscription]);
|
|
197
|
-
useEffect(() => {
|
|
198
|
-
createPaymentRef.current = customCreatePayment || null;
|
|
199
|
-
}, [customCreatePayment]);
|
|
200
|
-
useEffect(() => {
|
|
201
|
-
processPaymentRef.current = customProcessPayment || null;
|
|
202
|
-
}, [customProcessPayment]);
|
|
203
|
-
// Build default checkSubscription implementation - store in ref to keep it stable
|
|
204
|
-
const buildDefaultCheckSubscription = useCallback(async () => {
|
|
205
|
-
const currentConfig = configRef.current;
|
|
206
|
-
const adapter = getAuthAdapter(currentConfig);
|
|
207
|
-
const token = await adapter.getToken();
|
|
208
|
-
const detectedUserId = await adapter.getUserId();
|
|
209
|
-
const route = currentConfig?.api?.checkSubscription || '/api/check-subscription';
|
|
210
|
-
const fetchFn = currentConfig?.fetch || fetch;
|
|
211
|
-
// Get cached customerRef from localStorage, validated against current userId
|
|
212
|
-
const cachedRef = getCachedCustomerRef(detectedUserId);
|
|
213
|
-
const headers = {
|
|
214
|
-
'Content-Type': 'application/json',
|
|
215
|
-
};
|
|
216
|
-
if (token) {
|
|
217
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
218
|
-
}
|
|
219
|
-
if (cachedRef) {
|
|
220
|
-
headers['x-solvapay-customer-ref'] = cachedRef;
|
|
221
|
-
}
|
|
222
|
-
// Add custom headers
|
|
223
|
-
if (currentConfig?.headers) {
|
|
224
|
-
const customHeaders = typeof currentConfig.headers === 'function'
|
|
225
|
-
? await currentConfig.headers()
|
|
226
|
-
: currentConfig.headers;
|
|
227
|
-
Object.assign(headers, customHeaders);
|
|
228
|
-
}
|
|
229
|
-
const res = await fetchFn(route, {
|
|
230
|
-
method: 'GET',
|
|
231
|
-
headers,
|
|
232
|
-
});
|
|
233
|
-
if (!res.ok) {
|
|
234
|
-
const error = new Error(`Failed to check subscription: ${res.statusText}`);
|
|
235
|
-
currentConfig?.onError?.(error, 'checkSubscription');
|
|
236
|
-
throw error;
|
|
237
|
-
}
|
|
238
|
-
return res.json();
|
|
239
|
-
}, []);
|
|
240
|
-
// Store in ref so it doesn't need to be in dependency arrays
|
|
241
|
-
useEffect(() => {
|
|
242
|
-
buildDefaultCheckSubscriptionRef.current = buildDefaultCheckSubscription;
|
|
243
|
-
}, [buildDefaultCheckSubscription]);
|
|
244
|
-
// Build default createPayment implementation
|
|
245
|
-
const buildDefaultCreatePayment = useCallback(async (params) => {
|
|
246
|
-
const currentConfig = configRef.current;
|
|
247
|
-
const adapter = getAuthAdapter(currentConfig);
|
|
248
|
-
const token = await adapter.getToken();
|
|
249
|
-
const detectedUserId = await adapter.getUserId();
|
|
250
|
-
const route = currentConfig?.api?.createPayment || '/api/create-payment-intent';
|
|
251
|
-
const fetchFn = currentConfig?.fetch || fetch;
|
|
252
|
-
// Get cached customerRef from localStorage, validated against current userId
|
|
253
|
-
const cachedRef = getCachedCustomerRef(detectedUserId);
|
|
254
|
-
const headers = {
|
|
255
|
-
'Content-Type': 'application/json',
|
|
256
|
-
};
|
|
257
|
-
if (token) {
|
|
258
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
259
|
-
}
|
|
260
|
-
if (cachedRef) {
|
|
261
|
-
headers['x-solvapay-customer-ref'] = cachedRef;
|
|
262
|
-
}
|
|
263
|
-
// Add custom headers
|
|
264
|
-
if (currentConfig?.headers) {
|
|
265
|
-
const customHeaders = typeof currentConfig.headers === 'function'
|
|
266
|
-
? await currentConfig.headers()
|
|
267
|
-
: currentConfig.headers;
|
|
268
|
-
Object.assign(headers, customHeaders);
|
|
269
|
-
}
|
|
270
|
-
// Build request body with planRef and agentRef if provided
|
|
271
|
-
const body = { planRef: params.planRef };
|
|
272
|
-
if (params.agentRef) {
|
|
273
|
-
body.agentRef = params.agentRef;
|
|
274
|
-
}
|
|
275
|
-
const res = await fetchFn(route, {
|
|
276
|
-
method: 'POST',
|
|
277
|
-
headers,
|
|
278
|
-
body: JSON.stringify(body),
|
|
279
|
-
});
|
|
280
|
-
if (!res.ok) {
|
|
281
|
-
const error = new Error(`Failed to create payment: ${res.statusText}`);
|
|
282
|
-
currentConfig?.onError?.(error, 'createPayment');
|
|
283
|
-
throw error;
|
|
284
|
-
}
|
|
285
|
-
return res.json();
|
|
286
|
-
}, []);
|
|
287
|
-
// Build default processPayment implementation
|
|
288
|
-
const buildDefaultProcessPayment = useCallback(async (params) => {
|
|
289
|
-
const currentConfig = configRef.current;
|
|
290
|
-
const adapter = getAuthAdapter(currentConfig);
|
|
291
|
-
const token = await adapter.getToken();
|
|
292
|
-
const detectedUserId = await adapter.getUserId();
|
|
293
|
-
const route = currentConfig?.api?.processPayment || '/api/process-payment';
|
|
294
|
-
const fetchFn = currentConfig?.fetch || fetch;
|
|
295
|
-
// Get cached customerRef from localStorage, validated against current userId
|
|
296
|
-
const cachedRef = getCachedCustomerRef(detectedUserId);
|
|
297
|
-
const headers = {
|
|
298
|
-
'Content-Type': 'application/json',
|
|
299
|
-
};
|
|
300
|
-
if (token) {
|
|
301
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
302
|
-
}
|
|
303
|
-
if (cachedRef) {
|
|
304
|
-
headers['x-solvapay-customer-ref'] = cachedRef;
|
|
305
|
-
}
|
|
306
|
-
// Add custom headers
|
|
307
|
-
if (currentConfig?.headers) {
|
|
308
|
-
const customHeaders = typeof currentConfig.headers === 'function'
|
|
309
|
-
? await currentConfig.headers()
|
|
310
|
-
: currentConfig.headers;
|
|
311
|
-
Object.assign(headers, customHeaders);
|
|
312
|
-
}
|
|
313
|
-
const res = await fetchFn(route, {
|
|
314
|
-
method: 'POST',
|
|
315
|
-
headers,
|
|
316
|
-
body: JSON.stringify(params),
|
|
317
|
-
});
|
|
318
|
-
if (!res.ok) {
|
|
319
|
-
const error = new Error(`Failed to process payment: ${res.statusText}`);
|
|
320
|
-
currentConfig?.onError?.(error, 'processPayment');
|
|
321
|
-
throw error;
|
|
322
|
-
}
|
|
323
|
-
return res.json();
|
|
324
|
-
}, []);
|
|
325
|
-
// Get the actual functions to use (priority: custom > config > defaults)
|
|
326
|
-
// Use refs to avoid dependency issues - this keeps the function stable
|
|
327
|
-
const checkSubscription = useCallback(async () => {
|
|
328
|
-
if (checkSubscriptionRef.current) {
|
|
329
|
-
return checkSubscriptionRef.current();
|
|
330
|
-
}
|
|
331
|
-
if (buildDefaultCheckSubscriptionRef.current) {
|
|
332
|
-
return buildDefaultCheckSubscriptionRef.current();
|
|
333
|
-
}
|
|
334
|
-
// Fallback (shouldn't happen, but TypeScript needs it)
|
|
335
|
-
return buildDefaultCheckSubscription();
|
|
336
|
-
}, []);
|
|
337
|
-
const createPayment = useCallback(async (params) => {
|
|
338
|
-
if (createPaymentRef.current) {
|
|
339
|
-
return createPaymentRef.current(params);
|
|
340
|
-
}
|
|
341
|
-
return buildDefaultCreatePayment(params);
|
|
342
|
-
}, [buildDefaultCreatePayment]);
|
|
343
|
-
const processPayment = useCallback(async (params) => {
|
|
344
|
-
if (processPaymentRef.current) {
|
|
345
|
-
return processPaymentRef.current(params);
|
|
346
|
-
}
|
|
347
|
-
return buildDefaultProcessPayment(params);
|
|
348
|
-
}, [buildDefaultProcessPayment]);
|
|
349
|
-
// Detect authentication state and user ID
|
|
350
|
-
useEffect(() => {
|
|
351
|
-
const detectAuth = async () => {
|
|
352
|
-
const currentConfig = configRef.current;
|
|
353
|
-
const adapter = getAuthAdapter(currentConfig);
|
|
354
|
-
const token = await adapter.getToken();
|
|
355
|
-
const detectedUserId = await adapter.getUserId();
|
|
356
|
-
// Track previous userId to detect user changes
|
|
357
|
-
const prevUserId = userId;
|
|
358
|
-
setIsAuthenticated(!!token);
|
|
359
|
-
setUserId(detectedUserId);
|
|
360
|
-
// CRITICAL: Clear customerRef cache if userId changes (user switched accounts)
|
|
361
|
-
// This prevents purchasing for the wrong user
|
|
362
|
-
if (prevUserId !== null && detectedUserId !== prevUserId) {
|
|
363
|
-
clearCachedCustomerRef();
|
|
364
|
-
setInternalCustomerRef(undefined);
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
// If we have a cached customerRef and are authenticated, validate it belongs to current user
|
|
368
|
-
const cachedRef = getCachedCustomerRef(detectedUserId);
|
|
369
|
-
if (cachedRef && token) {
|
|
370
|
-
setInternalCustomerRef(cachedRef);
|
|
371
|
-
}
|
|
372
|
-
else if (!token) {
|
|
373
|
-
// Clear cache on sign-out
|
|
374
|
-
clearCachedCustomerRef();
|
|
375
|
-
setInternalCustomerRef(undefined);
|
|
376
|
-
}
|
|
377
|
-
else if (token && !cachedRef) {
|
|
378
|
-
// Authenticated but no valid cached customerRef - clear internal ref
|
|
379
|
-
setInternalCustomerRef(undefined);
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
detectAuth();
|
|
383
|
-
// Set up polling to detect auth changes (e.g., token refresh)
|
|
384
|
-
const interval = setInterval(detectAuth, 5000); // Check every 5 seconds
|
|
385
|
-
return () => clearInterval(interval);
|
|
386
|
-
}, [userId]); // Include userId in deps to detect changes
|
|
387
|
-
// Fetch subscription function - memoized to prevent unnecessary re-renders
|
|
388
|
-
// Use refs for checkSubscription to avoid dependency issues
|
|
389
|
-
const fetchSubscription = useCallback(async (force = false) => {
|
|
390
|
-
// Only fetch if authenticated or if we have a customerRef
|
|
391
|
-
if (!isAuthenticated && !internalCustomerRef) {
|
|
392
|
-
setSubscriptionData({ subscriptions: [] });
|
|
393
|
-
setLoading(false);
|
|
394
|
-
inFlightRef.current = null;
|
|
395
|
-
lastFetchedRef.current = null;
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
const cacheKey = internalCustomerRef || userId || 'anonymous';
|
|
399
|
-
// Skip if we've already fetched this cacheKey (unless it's in-flight or forced)
|
|
400
|
-
if (!force && lastFetchedRef.current === cacheKey && inFlightRef.current !== cacheKey) {
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
// Prevent duplicate concurrent requests for the same cacheKey
|
|
404
|
-
if (inFlightRef.current === cacheKey) {
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
inFlightRef.current = cacheKey;
|
|
408
|
-
setLoading(true);
|
|
409
|
-
try {
|
|
410
|
-
// Use ref to get the current checkSubscription function
|
|
411
|
-
const checkFn = checkSubscriptionRef.current || buildDefaultCheckSubscriptionRef.current;
|
|
412
|
-
if (!checkFn) {
|
|
413
|
-
throw new Error('checkSubscription function not available');
|
|
414
|
-
}
|
|
415
|
-
const data = await checkFn();
|
|
416
|
-
// Store customerRef from response if available
|
|
417
|
-
// Only cache if we have a userId to prevent cross-user contamination
|
|
418
|
-
if (data.customerRef) {
|
|
419
|
-
setInternalCustomerRef(data.customerRef);
|
|
420
|
-
// Get current userId to associate with customerRef
|
|
421
|
-
const currentAdapter = getAuthAdapter(configRef.current);
|
|
422
|
-
const currentUserId = await currentAdapter.getUserId();
|
|
423
|
-
setCachedCustomerRef(data.customerRef, currentUserId);
|
|
424
|
-
}
|
|
425
|
-
// Only update if this is still the current cacheKey (might have changed during fetch)
|
|
426
|
-
if (inFlightRef.current === cacheKey) {
|
|
427
|
-
// Filter subscriptions using shared utility
|
|
428
|
-
const filteredData = {
|
|
429
|
-
...data,
|
|
430
|
-
subscriptions: filterSubscriptions(data.subscriptions || []),
|
|
431
|
-
};
|
|
432
|
-
setSubscriptionData(filteredData);
|
|
433
|
-
lastFetchedRef.current = cacheKey;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
catch (error) {
|
|
437
|
-
console.error('[SolvaPayProvider] Failed to fetch subscription:', error);
|
|
438
|
-
// On error, set empty subscriptions
|
|
439
|
-
if (inFlightRef.current === cacheKey) {
|
|
440
|
-
setSubscriptionData({
|
|
441
|
-
subscriptions: [],
|
|
442
|
-
});
|
|
443
|
-
lastFetchedRef.current = cacheKey;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
finally {
|
|
447
|
-
if (inFlightRef.current === cacheKey) {
|
|
448
|
-
setLoading(false);
|
|
449
|
-
inFlightRef.current = null;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}, [isAuthenticated, internalCustomerRef, userId]);
|
|
453
|
-
// Refetch subscription function - forces a fresh fetch by clearing cache
|
|
454
|
-
// Use ref to get fetchSubscription to avoid dependency issues
|
|
455
|
-
const fetchSubscriptionRef = useRef(fetchSubscription);
|
|
456
|
-
useEffect(() => {
|
|
457
|
-
fetchSubscriptionRef.current = fetchSubscription;
|
|
458
|
-
}, [fetchSubscription]);
|
|
459
|
-
const refetchSubscription = useCallback(async () => {
|
|
460
|
-
// Always clear cache state before refetching to ensure fresh data
|
|
461
|
-
// Clear both the cache key tracking and in-flight requests
|
|
462
|
-
lastFetchedRef.current = null;
|
|
463
|
-
inFlightRef.current = null;
|
|
464
|
-
// Also clear subscription data temporarily to ensure UI reflects loading state
|
|
465
|
-
// This prevents showing stale data while fetching
|
|
466
|
-
setSubscriptionData({ subscriptions: [] });
|
|
467
|
-
// Force a fresh fetch by passing force=true
|
|
468
|
-
// This bypasses the cache check and ensures we get the latest data from the server
|
|
469
|
-
await fetchSubscriptionRef.current(true);
|
|
470
|
-
}, []);
|
|
471
|
-
// Auto-fetch subscriptions on mount and when auth state changes
|
|
472
|
-
// Only depend on actual values, not the function itself
|
|
473
|
-
useEffect(() => {
|
|
474
|
-
// Clear cache when userId or customerRef changes to prevent stale data
|
|
475
|
-
// This is important when switching accounts or when customerRef is updated
|
|
476
|
-
lastFetchedRef.current = null;
|
|
477
|
-
inFlightRef.current = null;
|
|
478
|
-
if (isAuthenticated || internalCustomerRef) {
|
|
479
|
-
fetchSubscription();
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
setSubscriptionData({ subscriptions: [] });
|
|
483
|
-
setLoading(false);
|
|
484
|
-
}
|
|
485
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
486
|
-
}, [isAuthenticated, internalCustomerRef, userId]);
|
|
487
|
-
// Update customer ref method
|
|
488
|
-
const updateCustomerRef = useCallback((newCustomerRef) => {
|
|
489
|
-
setInternalCustomerRef(newCustomerRef);
|
|
490
|
-
// Store with current userId to prevent cross-user contamination
|
|
491
|
-
setCachedCustomerRef(newCustomerRef, userId);
|
|
492
|
-
// Trigger refetch
|
|
493
|
-
fetchSubscription(true);
|
|
494
|
-
}, [fetchSubscription, userId]);
|
|
495
|
-
// Build subscription status with helper methods - memoized to prevent unnecessary re-renders
|
|
496
|
-
const subscription = useMemo(() => {
|
|
497
|
-
// Get primary active subscription (paid or free) - most recent active subscription
|
|
498
|
-
const activeSubscription = getPrimarySubscription(subscriptionData.subscriptions);
|
|
499
|
-
// Compute active paid subscriptions
|
|
500
|
-
// Backend keeps subscriptions as 'active' until expiration, even when cancelled
|
|
501
|
-
const activePaidSubscriptions = subscriptionData.subscriptions.filter(sub => sub.status === 'active' && isPaidSubscription(sub));
|
|
502
|
-
// Get most recent active paid subscription (sorted by startDate)
|
|
503
|
-
const activePaidSubscription = activePaidSubscriptions.sort((a, b) => new Date(b.startDate).getTime() - new Date(a.startDate).getTime())[0] || null;
|
|
504
|
-
return {
|
|
505
|
-
loading,
|
|
506
|
-
customerRef: subscriptionData.customerRef || internalCustomerRef,
|
|
507
|
-
email: subscriptionData.email,
|
|
508
|
-
name: subscriptionData.name,
|
|
509
|
-
subscriptions: subscriptionData.subscriptions,
|
|
510
|
-
hasPlan: (planName) => {
|
|
511
|
-
return subscriptionData.subscriptions.some(sub => sub.planName.toLowerCase() === planName.toLowerCase() && sub.status === 'active');
|
|
512
|
-
},
|
|
513
|
-
activeSubscription,
|
|
514
|
-
hasPaidSubscription: activePaidSubscriptions.length > 0,
|
|
515
|
-
activePaidSubscription,
|
|
516
|
-
};
|
|
517
|
-
}, [loading, subscriptionData, internalCustomerRef]);
|
|
518
|
-
// Memoize context value to prevent unnecessary re-renders of consumers
|
|
519
|
-
const contextValue = useMemo(() => ({
|
|
520
|
-
subscription,
|
|
521
|
-
refetchSubscription,
|
|
522
|
-
createPayment,
|
|
523
|
-
processPayment,
|
|
524
|
-
customerRef: subscriptionData.customerRef || internalCustomerRef,
|
|
525
|
-
updateCustomerRef,
|
|
526
|
-
}), [
|
|
527
|
-
subscription,
|
|
528
|
-
refetchSubscription,
|
|
529
|
-
createPayment,
|
|
530
|
-
processPayment,
|
|
531
|
-
subscriptionData.customerRef,
|
|
532
|
-
internalCustomerRef,
|
|
533
|
-
updateCustomerRef,
|
|
534
|
-
]);
|
|
535
|
-
return _jsx(SolvaPayContext.Provider, { value: contextValue, children: children });
|
|
536
|
-
};
|
|
537
|
-
//# sourceMappingURL=SolvaPayProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SolvaPayProvider.js","sourceRoot":"","sources":["../../src/SolvaPayProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AACZ,OAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAU/F,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,G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AE,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,QAAQ,CAAC,WAAW,EAAE,IAAI,GAAG,CAAC,MAAM,KAAK,QAAQ,CACxF,CAAA;YACH,CAAC;YACD,kBAAkB;YAClB,mBAAmB,EAAE,uBAAuB,CAAC,MAAM,GAAG,CAAC;YACvD,sBAAsB;SACvB,CAAA;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,CAAC,CAAC,CAAA;IAEpD,uEAAuE;IACvE,MAAM,YAAY,GAAyB,OAAO,CAChD,GAAG,EAAE,CAAC,CAAC;QACL,YAAY;QACZ,mBAAmB;QACnB,aAAa;QACb,cAAc;QACd,WAAW,EAAE,gBAAgB,CAAC,WAAW,IAAI,mBAAmB;QAChE,iBAAiB;KAClB,CAAC,EACF;QACE,YAAY;QACZ,mBAAmB;QACnB,aAAa;QACb,cAAc;QACd,gBAAgB,CAAC,WAAW;QAC5B,mBAAmB;QACnB,iBAAiB;KAClB,CACF,CAAA;IAED,OAAO,KAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAAG,QAAQ,GAA4B,CAAA;AAC7F,CAAC,CAAA"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auth Adapter Interface for Client-Side Authentication
|
|
3
|
-
*
|
|
4
|
-
* Defines the contract for authentication adapters used by SolvaPayProvider.
|
|
5
|
-
* Adapters handle token retrieval and user ID extraction in the browser.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Auth adapter interface for client-side authentication
|
|
9
|
-
*
|
|
10
|
-
* Used by SolvaPayProvider to get auth tokens and user IDs.
|
|
11
|
-
* Adapters should handle their own error cases and return null when
|
|
12
|
-
* authentication is not available or fails.
|
|
13
|
-
*/
|
|
14
|
-
export interface AuthAdapter {
|
|
15
|
-
/**
|
|
16
|
-
* Get the authentication token
|
|
17
|
-
*
|
|
18
|
-
* @returns The auth token string if available, null otherwise
|
|
19
|
-
*
|
|
20
|
-
* @remarks
|
|
21
|
-
* This method should never throw. If authentication fails or is missing,
|
|
22
|
-
* return null and let the caller decide how to handle unauthenticated requests.
|
|
23
|
-
*/
|
|
24
|
-
getToken: () => Promise<string | null>;
|
|
25
|
-
/**
|
|
26
|
-
* Get the authenticated user ID
|
|
27
|
-
*
|
|
28
|
-
* @returns The user ID string if authenticated, null otherwise
|
|
29
|
-
*
|
|
30
|
-
* @remarks
|
|
31
|
-
* This method should never throw. If authentication fails or is missing,
|
|
32
|
-
* return null and let the caller decide how to handle unauthenticated requests.
|
|
33
|
-
*/
|
|
34
|
-
getUserId: () => Promise<string | null>;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Default auth adapter that only checks localStorage
|
|
38
|
-
*
|
|
39
|
-
* This is a fallback adapter that doesn't depend on any specific auth provider.
|
|
40
|
-
* It checks for a token in localStorage under the 'auth_token' key.
|
|
41
|
-
*/
|
|
42
|
-
export declare const defaultAuthAdapter: AuthAdapter;
|
|
43
|
-
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/adapters/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;;OAQG;IACH,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;IAEtC;;;;;;;;OAQG;IACH,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;CACxC;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAyBhC,CAAA"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auth Adapter Interface for Client-Side Authentication
|
|
3
|
-
*
|
|
4
|
-
* Defines the contract for authentication adapters used by SolvaPayProvider.
|
|
5
|
-
* Adapters handle token retrieval and user ID extraction in the browser.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Default auth adapter that only checks localStorage
|
|
9
|
-
*
|
|
10
|
-
* This is a fallback adapter that doesn't depend on any specific auth provider.
|
|
11
|
-
* It checks for a token in localStorage under the 'auth_token' key.
|
|
12
|
-
*/
|
|
13
|
-
export const defaultAuthAdapter = {
|
|
14
|
-
async getToken() {
|
|
15
|
-
if (typeof window === 'undefined')
|
|
16
|
-
return null;
|
|
17
|
-
const token = localStorage.getItem('auth_token');
|
|
18
|
-
return token || null;
|
|
19
|
-
},
|
|
20
|
-
async getUserId() {
|
|
21
|
-
const token = await this.getToken();
|
|
22
|
-
if (!token)
|
|
23
|
-
return null;
|
|
24
|
-
// Try to extract user ID from JWT token
|
|
25
|
-
try {
|
|
26
|
-
const parts = token.split('.');
|
|
27
|
-
if (parts.length === 3) {
|
|
28
|
-
const payload = JSON.parse(atob(parts[1]));
|
|
29
|
-
return payload.sub || payload.user_id || null;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
// Not a JWT or invalid format
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=auth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/adapters/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiCH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAgB;IAC7C,KAAK,CAAC,QAAQ;QACZ,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,IAAI,CAAA;QAE9C,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QAChD,OAAO,KAAK,IAAI,IAAI,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,SAAS;QACb,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAA;QACnC,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAA;QAEvB,wCAAwC;QACxC,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAC9B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;gBAC1C,OAAO,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,OAAO,IAAI,IAAI,CAAA;YAC/C,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,8BAA8B;QAChC,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA"}
|