@tagadapay/plugin-sdk 2.8.8 → 2.8.10
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/react/config/environment.d.ts +1 -22
- package/dist/react/config/environment.js +1 -132
- package/dist/react/utils/deviceInfo.d.ts +1 -39
- package/dist/react/utils/deviceInfo.js +1 -163
- package/dist/react/utils/jwtDecoder.d.ts +1 -14
- package/dist/react/utils/jwtDecoder.js +1 -86
- package/dist/react/utils/tokenStorage.d.ts +1 -16
- package/dist/react/utils/tokenStorage.js +1 -53
- package/dist/v2/core/client.d.ts +96 -0
- package/dist/v2/core/client.js +430 -0
- package/dist/v2/core/config/environment.d.ts +36 -0
- package/dist/v2/core/config/environment.js +155 -0
- package/dist/v2/core/pathRemapping.js +61 -3
- package/dist/v2/core/resources/apiClient.d.ts +13 -0
- package/dist/v2/core/resources/apiClient.js +77 -9
- package/dist/v2/core/resources/funnel.d.ts +21 -0
- package/dist/v2/core/resources/payments.d.ts +23 -0
- package/dist/v2/core/types.d.ts +271 -0
- package/dist/v2/core/types.js +4 -0
- package/dist/v2/core/utils/deviceInfo.d.ts +39 -0
- package/dist/v2/core/utils/deviceInfo.js +162 -0
- package/dist/v2/core/utils/eventDispatcher.d.ts +10 -0
- package/dist/v2/core/utils/eventDispatcher.js +24 -0
- package/dist/v2/core/utils/jwtDecoder.d.ts +14 -0
- package/dist/v2/core/utils/jwtDecoder.js +85 -0
- package/dist/v2/core/utils/pluginConfig.d.ts +1 -0
- package/dist/v2/core/utils/pluginConfig.js +64 -8
- package/dist/v2/core/utils/tokenStorage.d.ts +19 -0
- package/dist/v2/core/utils/tokenStorage.js +52 -0
- package/dist/v2/react/components/ApplePayButton.js +1 -1
- package/dist/v2/react/components/DebugDrawer.js +90 -1
- package/dist/v2/react/hooks/__examples__/FunnelContextExample.d.ts +12 -0
- package/dist/v2/react/hooks/__examples__/FunnelContextExample.js +54 -0
- package/dist/v2/react/hooks/useFunnel.d.ts +2 -1
- package/dist/v2/react/hooks/useFunnel.js +245 -69
- package/dist/v2/react/hooks/useGoogleAutocomplete.js +26 -18
- package/dist/v2/react/hooks/useISOData.js +4 -2
- package/dist/v2/react/hooks/useOffersQuery.d.ts +42 -29
- package/dist/v2/react/hooks/useOffersQuery.js +266 -204
- package/dist/v2/react/hooks/usePaymentQuery.js +99 -6
- package/dist/v2/react/providers/TagadaProvider.d.ts +13 -21
- package/dist/v2/react/providers/TagadaProvider.js +79 -673
- package/package.json +1 -1
|
@@ -395,6 +395,57 @@ function matchesPathPattern(pathname, pattern) {
|
|
|
395
395
|
return { matched: pathname === pattern, params: {} };
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Map parameter names from external pattern to internal pattern
|
|
400
|
+
* Assumes parameters appear in the same order in both patterns
|
|
401
|
+
*
|
|
402
|
+
* @param externalParams - Parameters extracted from external URL
|
|
403
|
+
* @param externalPattern - External path pattern (e.g., /off1/:lolo)
|
|
404
|
+
* @param internalPattern - Internal path pattern (e.g., /post/:orderId)
|
|
405
|
+
* @returns Mapped parameters with internal param names
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```typescript
|
|
409
|
+
* mapParamNames(
|
|
410
|
+
* {lolo: 'order_123'},
|
|
411
|
+
* '/off1/:lolo',
|
|
412
|
+
* '/post/:orderId'
|
|
413
|
+
* )
|
|
414
|
+
* // Returns: {orderId: 'order_123'}
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
function mapParamNames(externalParams, externalPattern, internalPattern) {
|
|
418
|
+
// Extract parameter names from patterns
|
|
419
|
+
const externalParamNames = extractParamNames(externalPattern);
|
|
420
|
+
const internalParamNames = extractParamNames(internalPattern);
|
|
421
|
+
// If no params or count mismatch, return original params
|
|
422
|
+
if (externalParamNames.length === 0 ||
|
|
423
|
+
externalParamNames.length !== internalParamNames.length) {
|
|
424
|
+
return externalParams;
|
|
425
|
+
}
|
|
426
|
+
// Map parameters by position
|
|
427
|
+
const mappedParams = {};
|
|
428
|
+
externalParamNames.forEach((externalName, index) => {
|
|
429
|
+
const internalName = internalParamNames[index];
|
|
430
|
+
const value = externalParams[externalName];
|
|
431
|
+
if (value !== undefined) {
|
|
432
|
+
mappedParams[internalName] = value;
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
return mappedParams;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Extract parameter names from a path pattern
|
|
439
|
+
*
|
|
440
|
+
* @param pattern - Path pattern (e.g., /post/:orderId/item/:itemId)
|
|
441
|
+
* @returns Array of parameter names (e.g., ['orderId', 'itemId'])
|
|
442
|
+
*/
|
|
443
|
+
function extractParamNames(pattern) {
|
|
444
|
+
const matches = pattern.match(/:([a-zA-Z0-9_]+)/g);
|
|
445
|
+
if (!matches)
|
|
446
|
+
return [];
|
|
447
|
+
return matches.map(m => m.substring(1)); // Remove ':' prefix
|
|
448
|
+
}
|
|
398
449
|
/**
|
|
399
450
|
* Match a route and extract URL parameters
|
|
400
451
|
*
|
|
@@ -496,9 +547,16 @@ export function matchRoute(internalPath) {
|
|
|
496
547
|
if (externalPattern) {
|
|
497
548
|
const externalMatch = matchesPathPattern(currentPath, externalPattern);
|
|
498
549
|
if (externalMatch.matched) {
|
|
499
|
-
//
|
|
500
|
-
//
|
|
501
|
-
|
|
550
|
+
// Map parameter names from external pattern to internal pattern
|
|
551
|
+
// External: /off1/:lolo → {lolo: 'value'}
|
|
552
|
+
// Internal: /post/:orderId → expects {orderId: 'value'}
|
|
553
|
+
console.log('[TagadaPay SDK] 🔄 Mapping params from external to internal pattern');
|
|
554
|
+
console.log('[TagadaPay SDK] External params:', externalMatch.params);
|
|
555
|
+
console.log('[TagadaPay SDK] External pattern:', externalPattern);
|
|
556
|
+
console.log('[TagadaPay SDK] Internal pattern:', internalPath);
|
|
557
|
+
const mappedParams = mapParamNames(externalMatch.params, externalPattern, internalPath);
|
|
558
|
+
console.log('[TagadaPay SDK] Mapped params:', mappedParams);
|
|
559
|
+
return { matched: true, params: mappedParams };
|
|
502
560
|
}
|
|
503
561
|
}
|
|
504
562
|
// Fallback: try to extract from current URL using internal pattern
|
|
@@ -3,15 +3,26 @@
|
|
|
3
3
|
* Shared between all resource clients
|
|
4
4
|
*/
|
|
5
5
|
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
6
|
+
declare module 'axios' {
|
|
7
|
+
interface AxiosRequestConfig {
|
|
8
|
+
skipAuth?: boolean;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
6
11
|
export interface ApiClientConfig {
|
|
7
12
|
baseURL: string;
|
|
8
13
|
headers?: Record<string, string>;
|
|
9
14
|
timeout?: number;
|
|
10
15
|
}
|
|
16
|
+
export type TokenProvider = () => Promise<string | null>;
|
|
11
17
|
export declare class ApiClient {
|
|
12
18
|
axios: AxiosInstance;
|
|
13
19
|
private currentToken;
|
|
20
|
+
private tokenProvider;
|
|
21
|
+
private requestHistory;
|
|
22
|
+
private readonly WINDOW_MS;
|
|
23
|
+
private readonly MAX_REQUESTS;
|
|
14
24
|
constructor(config: ApiClientConfig);
|
|
25
|
+
setTokenProvider(provider: TokenProvider): void;
|
|
15
26
|
get<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
16
27
|
post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
17
28
|
put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
@@ -22,4 +33,6 @@ export declare class ApiClient {
|
|
|
22
33
|
updateToken(token: string | null): void;
|
|
23
34
|
getCurrentToken(): string | null;
|
|
24
35
|
updateConfig(config: Partial<ApiClientConfig>): void;
|
|
36
|
+
private checkRequestLimit;
|
|
37
|
+
private cleanupHistory;
|
|
25
38
|
}
|
|
@@ -6,6 +6,11 @@ import axios from 'axios';
|
|
|
6
6
|
export class ApiClient {
|
|
7
7
|
constructor(config) {
|
|
8
8
|
this.currentToken = null;
|
|
9
|
+
this.tokenProvider = null;
|
|
10
|
+
// Circuit breaker state
|
|
11
|
+
this.requestHistory = new Map();
|
|
12
|
+
this.WINDOW_MS = 5000; // 5 seconds window
|
|
13
|
+
this.MAX_REQUESTS = 5; // Max 5 requests per endpoint in window
|
|
9
14
|
this.axios = axios.create({
|
|
10
15
|
baseURL: config.baseURL,
|
|
11
16
|
timeout: config.timeout || 30000,
|
|
@@ -14,13 +19,43 @@ export class ApiClient {
|
|
|
14
19
|
...config.headers,
|
|
15
20
|
},
|
|
16
21
|
});
|
|
22
|
+
// Cleanup interval for circuit breaker history
|
|
23
|
+
if (typeof setInterval !== 'undefined') {
|
|
24
|
+
setInterval(() => this.cleanupHistory(), 10000);
|
|
25
|
+
}
|
|
17
26
|
// Request interceptor for logging and auth
|
|
18
|
-
this.axios.interceptors.request.use((config) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
this.axios.interceptors.request.use(async (config) => {
|
|
28
|
+
// Circuit Breaker Check
|
|
29
|
+
if (config.url) {
|
|
30
|
+
try {
|
|
31
|
+
this.checkRequestLimit(`${config.method?.toUpperCase()}:${config.url}`);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error('[SDK] 🛑 Request blocked by Circuit Breaker:', error);
|
|
35
|
+
return Promise.reject(error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Check if we need to wait for token
|
|
39
|
+
if (!config.skipAuth && !this.currentToken && this.tokenProvider) {
|
|
40
|
+
try {
|
|
41
|
+
console.log('[SDK] Waiting for token...');
|
|
42
|
+
const token = await this.tokenProvider();
|
|
43
|
+
if (token) {
|
|
44
|
+
this.updateToken(token);
|
|
45
|
+
// Ensure header is set on this specific request config
|
|
46
|
+
config.headers['x-cms-token'] = token;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error('[SDK] Failed to get token from provider:', error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Ensure token is in headers if we have it (and not skipped)
|
|
54
|
+
if (!config.skipAuth && this.currentToken) {
|
|
55
|
+
config.headers['x-cms-token'] = this.currentToken;
|
|
23
56
|
}
|
|
57
|
+
console.log(`[SDK] Making ${config.method?.toUpperCase()} request to: ${config.baseURL || ''}${config.url}`);
|
|
58
|
+
// console.log('[SDK] Request headers:', config.headers);
|
|
24
59
|
return config;
|
|
25
60
|
}, (error) => {
|
|
26
61
|
console.error('[SDK] Request error:', error);
|
|
@@ -28,14 +63,18 @@ export class ApiClient {
|
|
|
28
63
|
});
|
|
29
64
|
// Response interceptor for logging
|
|
30
65
|
this.axios.interceptors.response.use((response) => {
|
|
31
|
-
console.log('[SDK] Response status:', response.status);
|
|
32
|
-
console.log('[SDK] Response data:', response.data);
|
|
66
|
+
// console.log('[SDK] Response status:', response.status);
|
|
33
67
|
return response;
|
|
34
68
|
}, (error) => {
|
|
35
|
-
console.error('[SDK] Response error:', error);
|
|
69
|
+
console.error('[SDK] Response error:', error.message);
|
|
36
70
|
return Promise.reject(error instanceof Error ? error : new Error(String(error)));
|
|
37
71
|
});
|
|
38
72
|
}
|
|
73
|
+
// Set a provider that returns a promise resolving to the token
|
|
74
|
+
// This allows requests to wait until the token is ready
|
|
75
|
+
setTokenProvider(provider) {
|
|
76
|
+
this.tokenProvider = provider;
|
|
77
|
+
}
|
|
39
78
|
// Convenience methods
|
|
40
79
|
async get(url, config) {
|
|
41
80
|
const response = await this.axios.get(url, config);
|
|
@@ -69,7 +108,7 @@ export class ApiClient {
|
|
|
69
108
|
this.currentToken = token;
|
|
70
109
|
if (token) {
|
|
71
110
|
this.setHeader('x-cms-token', token);
|
|
72
|
-
console.log('[SDK] Token updated in ApiClient:', token.substring(0, 8) + '...');
|
|
111
|
+
// console.log('[SDK] Token updated in ApiClient:', token.substring(0, 8) + '...');
|
|
73
112
|
}
|
|
74
113
|
else {
|
|
75
114
|
this.removeHeader('x-cms-token');
|
|
@@ -92,4 +131,33 @@ export class ApiClient {
|
|
|
92
131
|
}
|
|
93
132
|
console.log('[SDK] ApiClient configuration updated');
|
|
94
133
|
}
|
|
134
|
+
// Circuit Breaker Implementation
|
|
135
|
+
checkRequestLimit(key) {
|
|
136
|
+
const now = Date.now();
|
|
137
|
+
const history = this.requestHistory.get(key);
|
|
138
|
+
if (!history) {
|
|
139
|
+
this.requestHistory.set(key, { count: 1, firstRequestTime: now });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (now - history.firstRequestTime > this.WINDOW_MS) {
|
|
143
|
+
// Window expired, reset
|
|
144
|
+
this.requestHistory.set(key, { count: 1, firstRequestTime: now });
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
history.count++;
|
|
148
|
+
if (history.count > this.MAX_REQUESTS) {
|
|
149
|
+
const error = new Error(`Circuit Breaker: Too many requests to ${key} (${history.count} in ${this.WINDOW_MS}ms)`);
|
|
150
|
+
// Add a property to identify this as a circuit breaker error
|
|
151
|
+
error.isCircuitBreaker = true;
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
cleanupHistory() {
|
|
156
|
+
const now = Date.now();
|
|
157
|
+
for (const [key, history] of this.requestHistory.entries()) {
|
|
158
|
+
if (now - history.firstRequestTime > this.WINDOW_MS) {
|
|
159
|
+
this.requestHistory.delete(key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
95
163
|
}
|
|
@@ -391,6 +391,14 @@ export interface SimpleFunnelContext<TCustom = {}> {
|
|
|
391
391
|
* Only moves forward, never backward - used for analytics
|
|
392
392
|
*/
|
|
393
393
|
furthestStepId?: string;
|
|
394
|
+
/**
|
|
395
|
+
* ✅ Environment context (staging or production)
|
|
396
|
+
* - Determined at session initialization based on entry URL
|
|
397
|
+
* - Ensures all navigation stays in the same environment
|
|
398
|
+
* - 'staging': Uses funnel.config (alias domains like funnel--store.cdn.tagadapay.com)
|
|
399
|
+
* - 'production': Uses funnel.productionConfig (custom domains)
|
|
400
|
+
*/
|
|
401
|
+
environment?: 'staging' | 'production';
|
|
394
402
|
startedAt: number;
|
|
395
403
|
lastActivityAt: number;
|
|
396
404
|
/**
|
|
@@ -400,6 +408,13 @@ export interface SimpleFunnelContext<TCustom = {}> {
|
|
|
400
408
|
* - Standard keys provide IntelliSense, custom keys always allowed
|
|
401
409
|
*/
|
|
402
410
|
resources?: FunnelResourceMap<TCustom>;
|
|
411
|
+
/**
|
|
412
|
+
* Static resources from plugin manifest (type: "static")
|
|
413
|
+
* - Configured in funnel editor's Static Resources tab
|
|
414
|
+
* - Available at runtime as context.static
|
|
415
|
+
* - Example: context.static.offer.id for statically configured offers
|
|
416
|
+
*/
|
|
417
|
+
static?: Record<string, any>;
|
|
403
418
|
/**
|
|
404
419
|
* Legacy/Custom metadata
|
|
405
420
|
* For backward compatibility and flexible unstructured data
|
|
@@ -416,6 +431,12 @@ export interface FunnelInitializeRequest {
|
|
|
416
431
|
funnelId?: string;
|
|
417
432
|
entryStepId?: string;
|
|
418
433
|
existingSessionId?: string;
|
|
434
|
+
/**
|
|
435
|
+
* Current URL for session synchronization (browser back/forward handling)
|
|
436
|
+
* If not provided, SDK will automatically use window.location.href
|
|
437
|
+
* @example '/checkout', 'https://store.com/payment'
|
|
438
|
+
*/
|
|
439
|
+
currentUrl?: string;
|
|
419
440
|
}
|
|
420
441
|
export interface FunnelInitializeResponse {
|
|
421
442
|
success: boolean;
|
|
@@ -76,9 +76,32 @@ export interface PaymentOptions {
|
|
|
76
76
|
threedsProvider?: 'basis_theory';
|
|
77
77
|
initiatedBy?: 'customer' | 'merchant';
|
|
78
78
|
source?: 'upsell' | 'checkout' | 'offer' | 'missing_club' | 'forced';
|
|
79
|
+
/** @deprecated Use onPaymentSuccess instead - this will be removed in v3 */
|
|
79
80
|
onSuccess?: (response: PaymentResponse) => void;
|
|
81
|
+
/** @deprecated Use onPaymentFailed instead - this will be removed in v3 */
|
|
80
82
|
onFailure?: (error: string) => void;
|
|
81
83
|
onRequireAction?: (payment: Payment) => void;
|
|
84
|
+
/**
|
|
85
|
+
* Called when payment succeeds (matches FunnelActionType.PAYMENT_SUCCESS)
|
|
86
|
+
* Use this with useFunnel's next() to navigate to the next step
|
|
87
|
+
* This replaces automatic redirects to /post or /thankyou
|
|
88
|
+
*/
|
|
89
|
+
onPaymentSuccess?: (response: PaymentResponse) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Called when payment fails (matches FunnelActionType.PAYMENT_FAILED)
|
|
92
|
+
* Use this to handle retry logic, show errors, or trigger funnel failure flows
|
|
93
|
+
*/
|
|
94
|
+
onPaymentFailed?: (error: {
|
|
95
|
+
code: string;
|
|
96
|
+
message: string;
|
|
97
|
+
payment?: Payment;
|
|
98
|
+
}) => void;
|
|
99
|
+
/**
|
|
100
|
+
* Disable automatic redirects to /post or /thankyou (default: true)
|
|
101
|
+
* Set to false only for legacy implementations without funnel orchestrator
|
|
102
|
+
* The funnel orchestrator handles navigation automatically with useFunnel
|
|
103
|
+
*/
|
|
104
|
+
disableAutoRedirect?: boolean;
|
|
82
105
|
}
|
|
83
106
|
export interface CardPaymentMethod {
|
|
84
107
|
cardNumber: string;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the Tagada Pay SDK Core
|
|
3
|
+
*/
|
|
4
|
+
export type Environment = 'production' | 'development' | 'local';
|
|
5
|
+
export interface ApiConfig {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
endpoints: {
|
|
8
|
+
checkout: {
|
|
9
|
+
sessionInit: string;
|
|
10
|
+
sessionStatus: string;
|
|
11
|
+
};
|
|
12
|
+
customer: {
|
|
13
|
+
profile: string;
|
|
14
|
+
session: string;
|
|
15
|
+
};
|
|
16
|
+
store: {
|
|
17
|
+
config: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface EnvironmentConfig {
|
|
22
|
+
environment: Environment;
|
|
23
|
+
apiConfig: ApiConfig;
|
|
24
|
+
}
|
|
25
|
+
export interface Customer {
|
|
26
|
+
id: string;
|
|
27
|
+
email?: string;
|
|
28
|
+
firstName?: string;
|
|
29
|
+
lastName?: string;
|
|
30
|
+
phone?: string;
|
|
31
|
+
isAuthenticated: boolean;
|
|
32
|
+
role: 'authenticated' | 'anonymous';
|
|
33
|
+
}
|
|
34
|
+
export type SessionRole = 'authenticated' | 'anonymous';
|
|
35
|
+
export interface Session {
|
|
36
|
+
sessionId: string;
|
|
37
|
+
storeId: string;
|
|
38
|
+
accountId: string;
|
|
39
|
+
customerId: string;
|
|
40
|
+
role: SessionRole;
|
|
41
|
+
isValid: boolean;
|
|
42
|
+
isLoading: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface AuthState {
|
|
45
|
+
isAuthenticated: boolean;
|
|
46
|
+
isLoading: boolean;
|
|
47
|
+
customer: Customer | null;
|
|
48
|
+
session: Session | null;
|
|
49
|
+
}
|
|
50
|
+
export interface Locale {
|
|
51
|
+
locale: string;
|
|
52
|
+
language: string;
|
|
53
|
+
region: string;
|
|
54
|
+
messages?: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
export interface Currency {
|
|
57
|
+
code: string;
|
|
58
|
+
symbol: string;
|
|
59
|
+
name: string;
|
|
60
|
+
}
|
|
61
|
+
export interface Store {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
domain: string;
|
|
65
|
+
currency: string;
|
|
66
|
+
locale: string;
|
|
67
|
+
presentmentCurrencies: string[];
|
|
68
|
+
chargeCurrencies: string[];
|
|
69
|
+
}
|
|
70
|
+
export interface PickupPoint {
|
|
71
|
+
id: string;
|
|
72
|
+
name: string;
|
|
73
|
+
country: string;
|
|
74
|
+
postal_code: string;
|
|
75
|
+
city: string;
|
|
76
|
+
address: string;
|
|
77
|
+
address2?: string;
|
|
78
|
+
house_number?: string;
|
|
79
|
+
phone?: string;
|
|
80
|
+
email?: string;
|
|
81
|
+
latitude?: number;
|
|
82
|
+
longitude?: number;
|
|
83
|
+
opening_hours?: string;
|
|
84
|
+
extra_info?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface OrderItem {
|
|
87
|
+
id: string;
|
|
88
|
+
productId: string;
|
|
89
|
+
variantId: string;
|
|
90
|
+
quantity: number;
|
|
91
|
+
unitAmount: number;
|
|
92
|
+
amount: number;
|
|
93
|
+
adjustedAmount: number;
|
|
94
|
+
currency: string;
|
|
95
|
+
recurring?: boolean;
|
|
96
|
+
interval?: 'day' | 'week' | 'month' | 'year' | null;
|
|
97
|
+
intervalCount?: number | null;
|
|
98
|
+
orderLineItemProduct?: {
|
|
99
|
+
name: string;
|
|
100
|
+
};
|
|
101
|
+
orderLineItemVariant?: {
|
|
102
|
+
name: string;
|
|
103
|
+
imageUrl: string | null;
|
|
104
|
+
};
|
|
105
|
+
subscriptionSettings?: {
|
|
106
|
+
trial?: boolean;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export interface OrderSummary {
|
|
110
|
+
currency: string;
|
|
111
|
+
totalPromotionAmount: number;
|
|
112
|
+
totalTaxAmount: number;
|
|
113
|
+
shippingCost: number;
|
|
114
|
+
shippingCostIsFree: boolean;
|
|
115
|
+
subtotalAmount: number;
|
|
116
|
+
subtotalAdjustedAmount: number;
|
|
117
|
+
totalAdjustedAmount: number;
|
|
118
|
+
adjustments?: {
|
|
119
|
+
type: string;
|
|
120
|
+
amount: number;
|
|
121
|
+
description: string;
|
|
122
|
+
}[];
|
|
123
|
+
}
|
|
124
|
+
export interface OrderAddress {
|
|
125
|
+
firstName: string;
|
|
126
|
+
lastName: string;
|
|
127
|
+
address1: string;
|
|
128
|
+
address2?: string;
|
|
129
|
+
city: string;
|
|
130
|
+
state: string;
|
|
131
|
+
postal: string;
|
|
132
|
+
country: string;
|
|
133
|
+
phone?: string;
|
|
134
|
+
}
|
|
135
|
+
export interface Order {
|
|
136
|
+
id: string;
|
|
137
|
+
currency: string;
|
|
138
|
+
paidAmount: number;
|
|
139
|
+
status: string;
|
|
140
|
+
createdAt: string;
|
|
141
|
+
metadata?: Record<string, any>;
|
|
142
|
+
items: OrderItem[];
|
|
143
|
+
summaries?: OrderSummary[];
|
|
144
|
+
shippingAddress?: OrderAddress;
|
|
145
|
+
billingAddress?: OrderAddress;
|
|
146
|
+
pickupAddress?: PickupPoint;
|
|
147
|
+
checkoutSession?: {
|
|
148
|
+
returnUrl?: string;
|
|
149
|
+
[key: string]: any;
|
|
150
|
+
};
|
|
151
|
+
relatedOrders?: Order[];
|
|
152
|
+
}
|
|
153
|
+
export interface PaymentSummary {
|
|
154
|
+
id: string;
|
|
155
|
+
status: string;
|
|
156
|
+
amount: number;
|
|
157
|
+
currency: string;
|
|
158
|
+
createdAt: string;
|
|
159
|
+
updatedAt?: string;
|
|
160
|
+
provider?: string;
|
|
161
|
+
metadata?: Record<string, any>;
|
|
162
|
+
}
|
|
163
|
+
export interface PromotionSummary {
|
|
164
|
+
id: string;
|
|
165
|
+
code?: string | null;
|
|
166
|
+
type?: string;
|
|
167
|
+
amount?: number;
|
|
168
|
+
description?: string | null;
|
|
169
|
+
}
|
|
170
|
+
export interface OrderAdjustmentSummary {
|
|
171
|
+
type: string;
|
|
172
|
+
amount: number;
|
|
173
|
+
description: string;
|
|
174
|
+
}
|
|
175
|
+
export interface OrderWithRelations extends Order {
|
|
176
|
+
customer?: Customer;
|
|
177
|
+
store?: Store;
|
|
178
|
+
account?: {
|
|
179
|
+
id: string;
|
|
180
|
+
name?: string;
|
|
181
|
+
} | undefined;
|
|
182
|
+
items: OrderItem[];
|
|
183
|
+
payments?: PaymentSummary[];
|
|
184
|
+
summaries: OrderSummary[];
|
|
185
|
+
checkoutSession?: {
|
|
186
|
+
id?: string;
|
|
187
|
+
returnUrl?: string;
|
|
188
|
+
[key: string]: any;
|
|
189
|
+
};
|
|
190
|
+
promotions?: PromotionSummary[];
|
|
191
|
+
subscriptions?: any[];
|
|
192
|
+
adjustments: OrderAdjustmentSummary[];
|
|
193
|
+
}
|
|
194
|
+
export interface CustomerAddress {
|
|
195
|
+
company?: string;
|
|
196
|
+
firstName: string;
|
|
197
|
+
lastName: string;
|
|
198
|
+
address1: string;
|
|
199
|
+
city: string;
|
|
200
|
+
country: string;
|
|
201
|
+
state: string;
|
|
202
|
+
postal: string;
|
|
203
|
+
phone?: string;
|
|
204
|
+
email?: string;
|
|
205
|
+
}
|
|
206
|
+
export interface CustomerOrderSummary {
|
|
207
|
+
id: string;
|
|
208
|
+
storeId: string;
|
|
209
|
+
accountId: string;
|
|
210
|
+
createdAt: string;
|
|
211
|
+
updatedAt: string;
|
|
212
|
+
status: string;
|
|
213
|
+
cancelledAt: string | null;
|
|
214
|
+
cancelledReason: string | null;
|
|
215
|
+
paidAt: string | null;
|
|
216
|
+
paidAmount: number | null;
|
|
217
|
+
openAt: string | null;
|
|
218
|
+
abandonedAt: string | null;
|
|
219
|
+
currency: string;
|
|
220
|
+
externalCustomerType: string | null;
|
|
221
|
+
externalCustomerId: string | null;
|
|
222
|
+
externalOrderId: string | null;
|
|
223
|
+
billingAddress: CustomerAddress;
|
|
224
|
+
shippingAddress: Omit<CustomerAddress, 'email'>;
|
|
225
|
+
pickupAddress: any | null;
|
|
226
|
+
taxesIncluded: boolean;
|
|
227
|
+
draft: boolean;
|
|
228
|
+
checkoutSessionId: string | null;
|
|
229
|
+
sessionHash: string | null;
|
|
230
|
+
customerId: string;
|
|
231
|
+
createdFrom: string | null;
|
|
232
|
+
paymentInstrumentId: string | null;
|
|
233
|
+
refundedAt: string | null;
|
|
234
|
+
refundedAmount: number | null;
|
|
235
|
+
metadata?: Record<string, any>;
|
|
236
|
+
}
|
|
237
|
+
export interface CustomerInfos {
|
|
238
|
+
customer: {
|
|
239
|
+
id: string;
|
|
240
|
+
email: string | null;
|
|
241
|
+
firstName: string | null;
|
|
242
|
+
lastName: string | null;
|
|
243
|
+
externalCustomerId: string | null;
|
|
244
|
+
lastOrderId: string | null;
|
|
245
|
+
accountId: string;
|
|
246
|
+
storeId: string;
|
|
247
|
+
billingAddress: CustomerAddress | null;
|
|
248
|
+
shippingAddress: Omit<CustomerAddress, 'email'> | null;
|
|
249
|
+
currency: string | null;
|
|
250
|
+
locale: string | null;
|
|
251
|
+
draft: boolean;
|
|
252
|
+
acceptsMarketing: boolean;
|
|
253
|
+
createdAt: string;
|
|
254
|
+
updatedAt: string;
|
|
255
|
+
metadata: Record<string, any>;
|
|
256
|
+
device: any | null;
|
|
257
|
+
orders: CustomerOrderSummary[];
|
|
258
|
+
subscriptions: any[];
|
|
259
|
+
};
|
|
260
|
+
promotionCodes: any[];
|
|
261
|
+
}
|
|
262
|
+
export interface SessionInitResponse {
|
|
263
|
+
store: Store;
|
|
264
|
+
locale: string;
|
|
265
|
+
messages?: Record<string, string>;
|
|
266
|
+
customer?: Customer;
|
|
267
|
+
session?: Session;
|
|
268
|
+
}
|
|
269
|
+
export interface AnonymousTokenResponse {
|
|
270
|
+
token: string;
|
|
271
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface DeviceInfo {
|
|
2
|
+
userAgent: {
|
|
3
|
+
browser: {
|
|
4
|
+
name: string;
|
|
5
|
+
version: string;
|
|
6
|
+
};
|
|
7
|
+
os: {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
};
|
|
11
|
+
device?: {
|
|
12
|
+
type: string;
|
|
13
|
+
model: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
screenResolution: {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
timeZone: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get browser locale
|
|
24
|
+
*/
|
|
25
|
+
export declare function getBrowserLocale(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Collect all device information
|
|
28
|
+
*/
|
|
29
|
+
export declare function collectDeviceInfo(): DeviceInfo;
|
|
30
|
+
/**
|
|
31
|
+
* Get URL parameters for session initialization
|
|
32
|
+
*/
|
|
33
|
+
export declare function getUrlParams(): {
|
|
34
|
+
locale?: string;
|
|
35
|
+
currency?: string;
|
|
36
|
+
utmSource?: string;
|
|
37
|
+
utmMedium?: string;
|
|
38
|
+
utmCampaign?: string;
|
|
39
|
+
};
|