@tagadapay/plugin-sdk 2.8.8 → 2.8.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/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 +92 -0
- package/dist/v2/core/client.js +386 -0
- package/dist/v2/core/config/environment.d.ts +22 -0
- package/dist/v2/core/config/environment.js +140 -0
- package/dist/v2/core/pathRemapping.js +61 -3
- package/dist/v2/core/resources/apiClient.d.ts +8 -0
- package/dist/v2/core/resources/apiClient.js +30 -9
- package/dist/v2/core/resources/funnel.d.ts +14 -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.js +6 -0
- package/dist/v2/core/utils/tokenStorage.d.ts +19 -0
- package/dist/v2/core/utils/tokenStorage.js +52 -0
- 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 +1 -1
- package/dist/v2/react/hooks/useFunnel.js +209 -32
- 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 +24 -29
- package/dist/v2/react/hooks/useOffersQuery.js +164 -204
- package/dist/v2/react/hooks/usePaymentQuery.js +99 -6
- package/dist/v2/react/providers/TagadaProvider.d.ts +8 -21
- package/dist/v2/react/providers/TagadaProvider.js +79 -673
- package/package.json +1 -1
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Environment configurations for different deployment environments
|
|
4
|
-
*/
|
|
5
|
-
export declare const ENVIRONMENT_CONFIGS: Record<Environment, ApiConfig>;
|
|
6
|
-
/**
|
|
7
|
-
* Get the environment configuration based on the current environment
|
|
8
|
-
*/
|
|
9
|
-
export declare function getEnvironmentConfig(environment?: Environment): EnvironmentConfig;
|
|
10
|
-
/**
|
|
11
|
-
* Build a complete API URL from environment config and endpoint path
|
|
12
|
-
*/
|
|
13
|
-
export declare function buildApiUrl(config: EnvironmentConfig, endpointPath: string): string;
|
|
14
|
-
/**
|
|
15
|
-
* Get a specific endpoint URL
|
|
16
|
-
*/
|
|
17
|
-
export declare function getEndpointUrl(config: EnvironmentConfig, category: keyof ApiConfig['endpoints'], endpoint: string): string;
|
|
18
|
-
/**
|
|
19
|
-
* Auto-detect environment based on hostname, URL patterns, and deployment context
|
|
20
|
-
* Works with any build tool or deployment system
|
|
21
|
-
*/
|
|
22
|
-
export declare function detectEnvironment(): Environment;
|
|
1
|
+
export * from '../../v2/core/config/environment';
|
|
@@ -1,132 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Environment configurations for different deployment environments
|
|
4
|
-
*/
|
|
5
|
-
export const ENVIRONMENT_CONFIGS = {
|
|
6
|
-
production: {
|
|
7
|
-
baseUrl: 'https://app.tagadapay.com',
|
|
8
|
-
endpoints: {
|
|
9
|
-
checkout: {
|
|
10
|
-
sessionInit: '/api/v1/checkout/session/init',
|
|
11
|
-
sessionStatus: '/api/v1/checkout/session/status',
|
|
12
|
-
},
|
|
13
|
-
customer: {
|
|
14
|
-
profile: '/api/v1/customer/profile',
|
|
15
|
-
session: '/api/v1/customer/session',
|
|
16
|
-
},
|
|
17
|
-
store: {
|
|
18
|
-
config: '/api/v1/store/config',
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
development: {
|
|
23
|
-
baseUrl: 'https://app.tagadapay.dev',
|
|
24
|
-
endpoints: {
|
|
25
|
-
checkout: {
|
|
26
|
-
sessionInit: '/api/v1/checkout/session/init',
|
|
27
|
-
sessionStatus: '/api/v1/checkout/session/status',
|
|
28
|
-
},
|
|
29
|
-
customer: {
|
|
30
|
-
profile: '/api/v1/customer/profile',
|
|
31
|
-
session: '/api/v1/customer/session',
|
|
32
|
-
},
|
|
33
|
-
store: {
|
|
34
|
-
config: '/api/v1/store/config',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
local: {
|
|
39
|
-
baseUrl: 'http://app.localhost:3000',
|
|
40
|
-
endpoints: {
|
|
41
|
-
checkout: {
|
|
42
|
-
sessionInit: '/api/v1/checkout/session/init',
|
|
43
|
-
sessionStatus: '/api/v1/checkout/session/status',
|
|
44
|
-
},
|
|
45
|
-
customer: {
|
|
46
|
-
profile: '/api/v1/customer/profile',
|
|
47
|
-
session: '/api/v1/customer/session',
|
|
48
|
-
},
|
|
49
|
-
store: {
|
|
50
|
-
config: '/api/v1/store/config',
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Get the environment configuration based on the current environment
|
|
57
|
-
*/
|
|
58
|
-
export function getEnvironmentConfig(environment = 'local') {
|
|
59
|
-
const apiConfig = ENVIRONMENT_CONFIGS[environment];
|
|
60
|
-
if (!apiConfig) {
|
|
61
|
-
console.warn(`Unknown environment: ${environment}. Falling back to local.`);
|
|
62
|
-
return {
|
|
63
|
-
environment: 'local',
|
|
64
|
-
apiConfig: ENVIRONMENT_CONFIGS.local,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
environment,
|
|
69
|
-
apiConfig,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Build a complete API URL from environment config and endpoint path
|
|
74
|
-
*/
|
|
75
|
-
export function buildApiUrl(config, endpointPath) {
|
|
76
|
-
return `${config.apiConfig.baseUrl}${endpointPath}`;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Get a specific endpoint URL
|
|
80
|
-
*/
|
|
81
|
-
export function getEndpointUrl(config, category, endpoint) {
|
|
82
|
-
const categoryEndpoints = config.apiConfig.endpoints[category];
|
|
83
|
-
const endpointPath = categoryEndpoints[endpoint];
|
|
84
|
-
if (!endpointPath) {
|
|
85
|
-
throw new Error(`Endpoint not found: ${category}.${endpoint}`);
|
|
86
|
-
}
|
|
87
|
-
return buildApiUrl(config, endpointPath);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Auto-detect environment based on hostname, URL patterns, and deployment context
|
|
91
|
-
* Works with any build tool or deployment system
|
|
92
|
-
*/
|
|
93
|
-
export function detectEnvironment() {
|
|
94
|
-
// Check if we're in browser
|
|
95
|
-
if (typeof window === 'undefined') {
|
|
96
|
-
return 'local'; // SSR fallback
|
|
97
|
-
}
|
|
98
|
-
const hostname = window.location.hostname;
|
|
99
|
-
const href = window.location.href;
|
|
100
|
-
// Production: deployed to production domains
|
|
101
|
-
if (hostname === 'app.tagadapay.com' ||
|
|
102
|
-
hostname.includes('tagadapay.com') ||
|
|
103
|
-
hostname.includes('yourproductiondomain.com')) {
|
|
104
|
-
return 'production';
|
|
105
|
-
}
|
|
106
|
-
// Development: deployed to staging/dev domains or has dev indicators
|
|
107
|
-
if (hostname === 'app.tagadapay.dev' ||
|
|
108
|
-
hostname.includes('tagadapay.dev') || // ✅ app.tagadapay.dev and subdomains
|
|
109
|
-
hostname.includes('vercel.app') ||
|
|
110
|
-
hostname.includes('netlify.app') ||
|
|
111
|
-
hostname.includes('surge.sh') ||
|
|
112
|
-
hostname.includes('github.io') ||
|
|
113
|
-
hostname.includes('herokuapp.com') ||
|
|
114
|
-
hostname.includes('railway.app') ||
|
|
115
|
-
href.includes('?env=dev') ||
|
|
116
|
-
href.includes('?dev=true') ||
|
|
117
|
-
href.includes('#dev')) {
|
|
118
|
-
return 'development';
|
|
119
|
-
}
|
|
120
|
-
// Local: localhost, local IPs, or local domains
|
|
121
|
-
if (hostname === 'localhost' ||
|
|
122
|
-
hostname.startsWith('127.') ||
|
|
123
|
-
hostname.startsWith('192.168.') ||
|
|
124
|
-
hostname.startsWith('10.') ||
|
|
125
|
-
hostname.includes('.local') ||
|
|
126
|
-
hostname === '' ||
|
|
127
|
-
hostname === '0.0.0.0') {
|
|
128
|
-
return 'local';
|
|
129
|
-
}
|
|
130
|
-
// Default fallback for unknown domains (safer to use development)
|
|
131
|
-
return 'development';
|
|
132
|
-
}
|
|
1
|
+
export * from '../../v2/core/config/environment';
|
|
@@ -1,39 +1 @@
|
|
|
1
|
-
export
|
|
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
|
-
};
|
|
1
|
+
export * from '../../v2/core/utils/deviceInfo';
|
|
@@ -1,163 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Get basic browser information from user agent
|
|
4
|
-
*/
|
|
5
|
-
function getBrowserInfo() {
|
|
6
|
-
const userAgent = navigator.userAgent;
|
|
7
|
-
// Chrome
|
|
8
|
-
if (userAgent.includes('Chrome')) {
|
|
9
|
-
const match = /Chrome\/(\d+)/.exec(userAgent);
|
|
10
|
-
return { name: 'Chrome', version: match ? match[1] : 'unknown' };
|
|
11
|
-
}
|
|
12
|
-
// Firefox
|
|
13
|
-
if (userAgent.includes('Firefox')) {
|
|
14
|
-
const match = /Firefox\/(\d+)/.exec(userAgent);
|
|
15
|
-
return { name: 'Firefox', version: match ? match[1] : 'unknown' };
|
|
16
|
-
}
|
|
17
|
-
// Safari
|
|
18
|
-
if (userAgent.includes('Safari') && !userAgent.includes('Chrome')) {
|
|
19
|
-
const match = /Version\/(\d+)/.exec(userAgent);
|
|
20
|
-
return { name: 'Safari', version: match ? match[1] : 'unknown' };
|
|
21
|
-
}
|
|
22
|
-
// Edge
|
|
23
|
-
if (userAgent.includes('Edge')) {
|
|
24
|
-
const match = /Edge\/(\d+)/.exec(userAgent);
|
|
25
|
-
return { name: 'Edge', version: match ? match[1] : 'unknown' };
|
|
26
|
-
}
|
|
27
|
-
return { name: 'unknown', version: 'unknown' };
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Get basic OS information from user agent
|
|
31
|
-
*/
|
|
32
|
-
function getOSInfo() {
|
|
33
|
-
const userAgent = navigator.userAgent;
|
|
34
|
-
// Windows
|
|
35
|
-
if (userAgent.includes('Windows')) {
|
|
36
|
-
if (userAgent.includes('Windows NT 10.0'))
|
|
37
|
-
return { name: 'Windows', version: '10' };
|
|
38
|
-
if (userAgent.includes('Windows NT 6.3'))
|
|
39
|
-
return { name: 'Windows', version: '8.1' };
|
|
40
|
-
if (userAgent.includes('Windows NT 6.2'))
|
|
41
|
-
return { name: 'Windows', version: '8' };
|
|
42
|
-
if (userAgent.includes('Windows NT 6.1'))
|
|
43
|
-
return { name: 'Windows', version: '7' };
|
|
44
|
-
return { name: 'Windows', version: 'unknown' };
|
|
45
|
-
}
|
|
46
|
-
// macOS
|
|
47
|
-
if (userAgent.includes('Mac OS X')) {
|
|
48
|
-
const match = /Mac OS X (\d+[._]\d+)/.exec(userAgent);
|
|
49
|
-
return { name: 'macOS', version: match ? match[1].replace('_', '.') : 'unknown' };
|
|
50
|
-
}
|
|
51
|
-
// iOS
|
|
52
|
-
if (userAgent.includes('iPhone') || userAgent.includes('iPad')) {
|
|
53
|
-
const match = /OS (\d+[._]\d+)/.exec(userAgent);
|
|
54
|
-
return { name: 'iOS', version: match ? match[1].replace('_', '.') : 'unknown' };
|
|
55
|
-
}
|
|
56
|
-
// Android
|
|
57
|
-
if (userAgent.includes('Android')) {
|
|
58
|
-
const match = /Android (\d+[.\d]*)/.exec(userAgent);
|
|
59
|
-
return { name: 'Android', version: match ? match[1] : 'unknown' };
|
|
60
|
-
}
|
|
61
|
-
// Linux
|
|
62
|
-
if (userAgent.includes('Linux')) {
|
|
63
|
-
return { name: 'Linux', version: 'unknown' };
|
|
64
|
-
}
|
|
65
|
-
return { name: 'unknown', version: 'unknown' };
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Get device information
|
|
69
|
-
*/
|
|
70
|
-
function getDeviceInfo() {
|
|
71
|
-
const userAgent = navigator.userAgent;
|
|
72
|
-
// Mobile devices
|
|
73
|
-
if (userAgent.includes('iPhone')) {
|
|
74
|
-
return { type: 'mobile', model: 'iPhone' };
|
|
75
|
-
}
|
|
76
|
-
if (userAgent.includes('iPad')) {
|
|
77
|
-
return { type: 'tablet', model: 'iPad' };
|
|
78
|
-
}
|
|
79
|
-
if (userAgent.includes('Android')) {
|
|
80
|
-
if (userAgent.includes('Mobile')) {
|
|
81
|
-
return { type: 'mobile', model: 'Android' };
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return { type: 'tablet', model: 'Android' };
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// Desktop (no specific device info)
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Get screen resolution
|
|
92
|
-
*/
|
|
93
|
-
function getScreenResolution() {
|
|
94
|
-
return {
|
|
95
|
-
width: window.screen.width,
|
|
96
|
-
height: window.screen.height,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Get timezone
|
|
101
|
-
*/
|
|
102
|
-
function getTimeZone() {
|
|
103
|
-
try {
|
|
104
|
-
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
console.error('Failed to get timezone:', error);
|
|
108
|
-
return 'UTC';
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Get browser locale
|
|
113
|
-
*/
|
|
114
|
-
export function getBrowserLocale() {
|
|
115
|
-
try {
|
|
116
|
-
return navigator.language || 'en-US';
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.error('Failed to get browser locale:', error);
|
|
120
|
-
return 'en-US';
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Collect all device information
|
|
125
|
-
*/
|
|
126
|
-
export function collectDeviceInfo() {
|
|
127
|
-
if (typeof window === 'undefined') {
|
|
128
|
-
// Server-side fallback
|
|
129
|
-
return {
|
|
130
|
-
userAgent: {
|
|
131
|
-
browser: { name: 'unknown', version: 'unknown' },
|
|
132
|
-
os: { name: 'unknown', version: 'unknown' },
|
|
133
|
-
},
|
|
134
|
-
screenResolution: { width: 0, height: 0 },
|
|
135
|
-
timeZone: 'UTC',
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
userAgent: {
|
|
140
|
-
browser: getBrowserInfo(),
|
|
141
|
-
os: getOSInfo(),
|
|
142
|
-
device: getDeviceInfo(),
|
|
143
|
-
},
|
|
144
|
-
screenResolution: getScreenResolution(),
|
|
145
|
-
timeZone: getTimeZone(),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Get URL parameters for session initialization
|
|
150
|
-
*/
|
|
151
|
-
export function getUrlParams() {
|
|
152
|
-
if (typeof window === 'undefined') {
|
|
153
|
-
return {};
|
|
154
|
-
}
|
|
155
|
-
const params = new URLSearchParams(window.location.search);
|
|
156
|
-
return {
|
|
157
|
-
locale: params.get('locale') || undefined,
|
|
158
|
-
currency: params.get('currency') || undefined,
|
|
159
|
-
utmSource: params.get('utm_source') || undefined,
|
|
160
|
-
utmMedium: params.get('utm_medium') || undefined,
|
|
161
|
-
utmCampaign: params.get('utm_campaign') || undefined,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
1
|
+
export * from '../../v2/core/utils/deviceInfo';
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Decode a JWT token to extract session information
|
|
4
|
-
* This is a simple client-side decoder - do not use for security validation
|
|
5
|
-
*/
|
|
6
|
-
export declare function decodeJWTClient(token: string): Session | null;
|
|
7
|
-
/**
|
|
8
|
-
* Check if a JWT token is expired
|
|
9
|
-
*/
|
|
10
|
-
export declare function isTokenExpired(token: string): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Get token expiration time
|
|
13
|
-
*/
|
|
14
|
-
export declare function getTokenExpiration(token: string): Date | null;
|
|
1
|
+
export * from '../../v2/core/utils/jwtDecoder';
|
|
@@ -1,86 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Decode a JWT token to extract session information
|
|
4
|
-
* This is a simple client-side decoder - do not use for security validation
|
|
5
|
-
*/
|
|
6
|
-
export function decodeJWTClient(token) {
|
|
7
|
-
try {
|
|
8
|
-
// Split the token into parts
|
|
9
|
-
const parts = token.split('.');
|
|
10
|
-
if (parts.length !== 3) {
|
|
11
|
-
console.error('Invalid JWT token format');
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
// Decode the payload (second part)
|
|
15
|
-
const payload = parts[1];
|
|
16
|
-
// Add padding if needed
|
|
17
|
-
const paddedPayload = payload + '='.repeat((4 - (payload.length % 4)) % 4);
|
|
18
|
-
// Decode base64
|
|
19
|
-
const decoded = atob(paddedPayload);
|
|
20
|
-
// Parse JSON
|
|
21
|
-
const parsedPayload = JSON.parse(decoded);
|
|
22
|
-
// Check if token is expired
|
|
23
|
-
if (parsedPayload.exp && Date.now() >= parsedPayload.exp * 1000) {
|
|
24
|
-
console.warn('JWT token is expired');
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
// Return session data
|
|
28
|
-
return {
|
|
29
|
-
sessionId: parsedPayload.sessionId,
|
|
30
|
-
storeId: parsedPayload.storeId,
|
|
31
|
-
accountId: parsedPayload.accountId,
|
|
32
|
-
customerId: parsedPayload.customerId,
|
|
33
|
-
role: parsedPayload.role,
|
|
34
|
-
isValid: true,
|
|
35
|
-
isLoading: false,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
console.error('Failed to decode JWT token:', error);
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Check if a JWT token is expired
|
|
45
|
-
*/
|
|
46
|
-
export function isTokenExpired(token) {
|
|
47
|
-
try {
|
|
48
|
-
const parts = token.split('.');
|
|
49
|
-
if (parts.length !== 3)
|
|
50
|
-
return true;
|
|
51
|
-
const payload = parts[1];
|
|
52
|
-
const paddedPayload = payload + '='.repeat((4 - (payload.length % 4)) % 4);
|
|
53
|
-
const decoded = atob(paddedPayload);
|
|
54
|
-
const parsedPayload = JSON.parse(decoded);
|
|
55
|
-
if (parsedPayload.exp) {
|
|
56
|
-
return Date.now() >= parsedPayload.exp * 1000;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
console.error('Failed to check token expiration:', error);
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Get token expiration time
|
|
67
|
-
*/
|
|
68
|
-
export function getTokenExpiration(token) {
|
|
69
|
-
try {
|
|
70
|
-
const parts = token.split('.');
|
|
71
|
-
if (parts.length !== 3)
|
|
72
|
-
return null;
|
|
73
|
-
const payload = parts[1];
|
|
74
|
-
const paddedPayload = payload + '='.repeat((4 - (payload.length % 4)) % 4);
|
|
75
|
-
const decoded = atob(paddedPayload);
|
|
76
|
-
const parsedPayload = JSON.parse(decoded);
|
|
77
|
-
if (parsedPayload.exp) {
|
|
78
|
-
return new Date(parsedPayload.exp * 1000);
|
|
79
|
-
}
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
console.error('Failed to get token expiration:', error);
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
1
|
+
export * from '../../v2/core/utils/jwtDecoder';
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Set the CMS token in localStorage
|
|
3
|
-
*/
|
|
4
|
-
export declare function setClientToken(token: string): void;
|
|
5
|
-
/**
|
|
6
|
-
* Get the CMS token from localStorage
|
|
7
|
-
*/
|
|
8
|
-
export declare function getClientToken(): string | null;
|
|
9
|
-
/**
|
|
10
|
-
* Clear the CMS token from localStorage
|
|
11
|
-
*/
|
|
12
|
-
export declare function clearClientToken(): void;
|
|
13
|
-
/**
|
|
14
|
-
* Check if a token exists in localStorage
|
|
15
|
-
*/
|
|
16
|
-
export declare function hasClientToken(): boolean;
|
|
1
|
+
export * from '../../v2/core/utils/tokenStorage';
|
|
@@ -1,53 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Client-side token storage utilities
|
|
4
|
-
*/
|
|
5
|
-
const TOKEN_KEY = 'cms_token';
|
|
6
|
-
/**
|
|
7
|
-
* Set the CMS token in localStorage
|
|
8
|
-
*/
|
|
9
|
-
export function setClientToken(token) {
|
|
10
|
-
if (typeof window !== 'undefined') {
|
|
11
|
-
try {
|
|
12
|
-
localStorage.setItem(TOKEN_KEY, token);
|
|
13
|
-
window.dispatchEvent(new Event('storage'));
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
console.error('Failed to save token to localStorage:', error);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Get the CMS token from localStorage
|
|
22
|
-
*/
|
|
23
|
-
export function getClientToken() {
|
|
24
|
-
if (typeof window !== 'undefined') {
|
|
25
|
-
try {
|
|
26
|
-
return localStorage.getItem(TOKEN_KEY);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error('Failed to get token from localStorage:', error);
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Clear the CMS token from localStorage
|
|
37
|
-
*/
|
|
38
|
-
export function clearClientToken() {
|
|
39
|
-
if (typeof window !== 'undefined') {
|
|
40
|
-
try {
|
|
41
|
-
localStorage.removeItem(TOKEN_KEY);
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
console.error('Failed to clear token from localStorage:', error);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Check if a token exists in localStorage
|
|
50
|
-
*/
|
|
51
|
-
export function hasClientToken() {
|
|
52
|
-
return !!getClientToken();
|
|
53
|
-
}
|
|
1
|
+
export * from '../../v2/core/utils/tokenStorage';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ApiClient } from './resources/apiClient';
|
|
2
|
+
import { PluginConfig, RawPluginConfig } from './utils/pluginConfig';
|
|
3
|
+
import { Environment, EnvironmentConfig, Session, AuthState, Customer, Store, Locale, Currency } from './types';
|
|
4
|
+
export interface TagadaClientConfig {
|
|
5
|
+
environment?: Environment;
|
|
6
|
+
debugMode?: boolean;
|
|
7
|
+
localConfig?: string;
|
|
8
|
+
rawPluginConfig?: RawPluginConfig;
|
|
9
|
+
blockUntilSessionReady?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface TagadaState {
|
|
12
|
+
auth: AuthState;
|
|
13
|
+
session: Session | null;
|
|
14
|
+
customer: Customer | null;
|
|
15
|
+
locale: Locale;
|
|
16
|
+
currency: Currency;
|
|
17
|
+
store: Store | null;
|
|
18
|
+
environment: EnvironmentConfig;
|
|
19
|
+
isLoading: boolean;
|
|
20
|
+
isInitialized: boolean;
|
|
21
|
+
isSessionInitialized: boolean;
|
|
22
|
+
pluginConfig: PluginConfig;
|
|
23
|
+
pluginConfigLoading: boolean;
|
|
24
|
+
debugMode: boolean;
|
|
25
|
+
token: string | null;
|
|
26
|
+
}
|
|
27
|
+
export declare class TagadaClient {
|
|
28
|
+
apiClient: ApiClient;
|
|
29
|
+
state: TagadaState;
|
|
30
|
+
private eventDispatcher;
|
|
31
|
+
private tokenPromise;
|
|
32
|
+
private tokenResolver;
|
|
33
|
+
private boundHandleStorageChange;
|
|
34
|
+
private readonly config;
|
|
35
|
+
private instanceId;
|
|
36
|
+
constructor(config?: TagadaClientConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Cleanup client resources
|
|
39
|
+
*/
|
|
40
|
+
destroy(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Handle storage changes (e.g. token update in another tab)
|
|
43
|
+
*/
|
|
44
|
+
private handleStorageChange;
|
|
45
|
+
/**
|
|
46
|
+
* Subscribe to state changes
|
|
47
|
+
*/
|
|
48
|
+
subscribe(listener: (state: TagadaState) => void): () => void;
|
|
49
|
+
/**
|
|
50
|
+
* Get current state
|
|
51
|
+
*/
|
|
52
|
+
getState(): TagadaState;
|
|
53
|
+
/**
|
|
54
|
+
* Update state and notify listeners
|
|
55
|
+
*/
|
|
56
|
+
private updateState;
|
|
57
|
+
/**
|
|
58
|
+
* Resolve environment
|
|
59
|
+
*/
|
|
60
|
+
private resolveEnvironment;
|
|
61
|
+
/**
|
|
62
|
+
* Main initialization flow
|
|
63
|
+
*/
|
|
64
|
+
private initialize;
|
|
65
|
+
/**
|
|
66
|
+
* Load plugin configuration
|
|
67
|
+
*/
|
|
68
|
+
private initializePluginConfig;
|
|
69
|
+
/**
|
|
70
|
+
* Initialize token and session
|
|
71
|
+
*/
|
|
72
|
+
private initializeToken;
|
|
73
|
+
/**
|
|
74
|
+
* Set token and resolve waiting requests
|
|
75
|
+
*/
|
|
76
|
+
private setToken;
|
|
77
|
+
/**
|
|
78
|
+
* Wait for token to be available
|
|
79
|
+
*/
|
|
80
|
+
private waitForToken;
|
|
81
|
+
/**
|
|
82
|
+
* Create anonymous token
|
|
83
|
+
*/
|
|
84
|
+
createAnonymousToken(storeId: string): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Initialize session
|
|
87
|
+
*/
|
|
88
|
+
initializeSession(sessionData: Session): Promise<void>;
|
|
89
|
+
private updateSessionState;
|
|
90
|
+
private getCurrencySymbol;
|
|
91
|
+
private getCurrencyName;
|
|
92
|
+
}
|