@tagadapay/plugin-sdk 1.0.2

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.
Files changed (63) hide show
  1. package/README.md +475 -0
  2. package/dist/data/currencies.json +2410 -0
  3. package/dist/index.d.ts +33 -0
  4. package/dist/index.js +37 -0
  5. package/dist/react/components/DebugDrawer.d.ts +7 -0
  6. package/dist/react/components/DebugDrawer.js +368 -0
  7. package/dist/react/components/OffersDemo.d.ts +1 -0
  8. package/dist/react/components/OffersDemo.js +50 -0
  9. package/dist/react/components/index.d.ts +1 -0
  10. package/dist/react/components/index.js +1 -0
  11. package/dist/react/config/environment.d.ts +22 -0
  12. package/dist/react/config/environment.js +132 -0
  13. package/dist/react/config/payment.d.ts +23 -0
  14. package/dist/react/config/payment.js +52 -0
  15. package/dist/react/hooks/useAuth.d.ts +4 -0
  16. package/dist/react/hooks/useAuth.js +12 -0
  17. package/dist/react/hooks/useCheckout.d.ts +262 -0
  18. package/dist/react/hooks/useCheckout.js +325 -0
  19. package/dist/react/hooks/useCurrency.d.ts +4 -0
  20. package/dist/react/hooks/useCurrency.js +640 -0
  21. package/dist/react/hooks/useCustomer.d.ts +7 -0
  22. package/dist/react/hooks/useCustomer.js +14 -0
  23. package/dist/react/hooks/useEnvironment.d.ts +7 -0
  24. package/dist/react/hooks/useEnvironment.js +18 -0
  25. package/dist/react/hooks/useLocale.d.ts +2 -0
  26. package/dist/react/hooks/useLocale.js +43 -0
  27. package/dist/react/hooks/useOffers.d.ts +99 -0
  28. package/dist/react/hooks/useOffers.js +115 -0
  29. package/dist/react/hooks/useOrder.d.ts +44 -0
  30. package/dist/react/hooks/useOrder.js +77 -0
  31. package/dist/react/hooks/usePayment.d.ts +60 -0
  32. package/dist/react/hooks/usePayment.js +343 -0
  33. package/dist/react/hooks/usePaymentPolling.d.ts +45 -0
  34. package/dist/react/hooks/usePaymentPolling.js +146 -0
  35. package/dist/react/hooks/useProducts.d.ts +95 -0
  36. package/dist/react/hooks/useProducts.js +120 -0
  37. package/dist/react/hooks/useSession.d.ts +10 -0
  38. package/dist/react/hooks/useSession.js +17 -0
  39. package/dist/react/hooks/useThreeds.d.ts +38 -0
  40. package/dist/react/hooks/useThreeds.js +162 -0
  41. package/dist/react/hooks/useThreedsModal.d.ts +16 -0
  42. package/dist/react/hooks/useThreedsModal.js +328 -0
  43. package/dist/react/index.d.ts +26 -0
  44. package/dist/react/index.js +27 -0
  45. package/dist/react/providers/TagadaProvider.d.ts +55 -0
  46. package/dist/react/providers/TagadaProvider.js +471 -0
  47. package/dist/react/services/apiService.d.ts +149 -0
  48. package/dist/react/services/apiService.js +168 -0
  49. package/dist/react/types.d.ts +151 -0
  50. package/dist/react/types.js +4 -0
  51. package/dist/react/utils/__tests__/urlUtils.test.d.ts +1 -0
  52. package/dist/react/utils/__tests__/urlUtils.test.js +189 -0
  53. package/dist/react/utils/deviceInfo.d.ts +39 -0
  54. package/dist/react/utils/deviceInfo.js +163 -0
  55. package/dist/react/utils/jwtDecoder.d.ts +14 -0
  56. package/dist/react/utils/jwtDecoder.js +86 -0
  57. package/dist/react/utils/money.d.ts +2273 -0
  58. package/dist/react/utils/money.js +104 -0
  59. package/dist/react/utils/tokenStorage.d.ts +16 -0
  60. package/dist/react/utils/tokenStorage.js +52 -0
  61. package/dist/react/utils/urlUtils.d.ts +239 -0
  62. package/dist/react/utils/urlUtils.js +449 -0
  63. package/package.json +64 -0
@@ -0,0 +1,163 @@
1
+ 'use client';
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
+ }
@@ -0,0 +1,14 @@
1
+ import { Session } from '../types';
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;
@@ -0,0 +1,86 @@
1
+ 'use client';
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
+ }