@tagadapay/plugin-sdk 2.1.2 → 2.2.0
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/data/iso3166.d.ts +10 -8
- package/dist/data/iso3166.js +79 -16
- package/dist/react/hooks/useCheckout.d.ts +0 -5
- package/dist/react/hooks/useCheckout.js +15 -32
- package/dist/react/hooks/useISOData.d.ts +7 -6
- package/dist/react/hooks/useISOData.js +20 -27
- package/dist/react/hooks/useLogin.js +4 -4
- package/dist/react/hooks/useOffers.js +7 -2
- package/dist/react/hooks/useProducts.js +3 -2
- package/dist/react/index.d.ts +2 -4
- package/dist/react/index.js +1 -3
- package/dist/react/providers/TagadaProvider.d.ts +1 -3
- package/dist/react/providers/TagadaProvider.js +89 -43
- package/dist/react/services/apiService.d.ts +4 -2
- package/dist/react/services/apiService.js +6 -2
- package/package.json +1 -2
- package/dist/react/components/AddressForm.example.d.ts +0 -1
- package/dist/react/components/AddressForm.example.js +0 -32
- package/dist/react/hooks/useAddress.d.ts +0 -59
- package/dist/react/hooks/useAddress.js +0 -557
- package/dist/react/hooks/useAddressV2.d.ts +0 -53
- package/dist/react/hooks/useAddressV2.js +0 -379
package/dist/data/iso3166.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare const AVAILABLE_LANGUAGES: readonly ["en", "ru", "de", "fr", "es", "zh", "hi", "pt", "ja", "ar", "it", "he"];
|
|
2
|
+
export type SupportedLanguage = typeof AVAILABLE_LANGUAGES[number];
|
|
1
3
|
export interface Country {
|
|
2
4
|
code: string;
|
|
3
5
|
name: string;
|
|
@@ -11,14 +13,14 @@ export interface State {
|
|
|
11
13
|
countryCode: string;
|
|
12
14
|
uniqueKey?: string;
|
|
13
15
|
}
|
|
14
|
-
export declare const getCountries: () => Country[];
|
|
15
|
-
export declare const getAllStates: () => State[];
|
|
16
|
-
export declare const getStatesForCountry: (countryCode: string) => State[];
|
|
17
|
-
export declare const findCountryByName: (countryName: string) => Country | null;
|
|
18
|
-
export declare const findRegionByCode: (regionCode: string) => State | null;
|
|
19
|
-
export declare const isValidCountryCode: (countryCode: string) => boolean;
|
|
20
|
-
export declare const isValidStateCode: (countryCode: string, stateCode: string) => boolean;
|
|
21
|
-
export declare const getCountryWithRegions: (countryCode: string) => {
|
|
16
|
+
export declare const getCountries: (language?: SupportedLanguage) => Country[];
|
|
17
|
+
export declare const getAllStates: (language?: SupportedLanguage) => State[];
|
|
18
|
+
export declare const getStatesForCountry: (countryCode: string, language?: SupportedLanguage) => State[];
|
|
19
|
+
export declare const findCountryByName: (countryName: string, language?: SupportedLanguage) => Country | null;
|
|
20
|
+
export declare const findRegionByCode: (regionCode: string, language?: SupportedLanguage) => State | null;
|
|
21
|
+
export declare const isValidCountryCode: (countryCode: string, language?: SupportedLanguage) => boolean;
|
|
22
|
+
export declare const isValidStateCode: (countryCode: string, stateCode: string, language?: SupportedLanguage) => boolean;
|
|
23
|
+
export declare const getCountryWithRegions: (countryCode: string, language?: SupportedLanguage) => {
|
|
22
24
|
country: {
|
|
23
25
|
code: any;
|
|
24
26
|
name: any;
|
package/dist/data/iso3166.js
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
|
-
// Import
|
|
1
|
+
// Import static language databases for better browser compatibility
|
|
2
|
+
// All supported languages from iso3166-2-db package
|
|
2
3
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
4
|
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
4
|
-
import
|
|
5
|
-
//
|
|
6
|
-
|
|
5
|
+
import enDatabase from 'iso3166-2-db/i18n/dispute/UN/en';
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
7
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
8
|
+
import ruDatabase from 'iso3166-2-db/i18n/dispute/UN/ru';
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
11
|
+
import deDatabase from 'iso3166-2-db/i18n/dispute/UN/de';
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
13
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
14
|
+
import frDatabase from 'iso3166-2-db/i18n/dispute/UN/fr';
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
17
|
+
import esDatabase from 'iso3166-2-db/i18n/dispute/UN/es';
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
20
|
+
import zhDatabase from 'iso3166-2-db/i18n/dispute/UN/zh';
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
23
|
+
import hiDatabase from 'iso3166-2-db/i18n/dispute/UN/hi';
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
25
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
26
|
+
import ptDatabase from 'iso3166-2-db/i18n/dispute/UN/pt';
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
29
|
+
import jaDatabase from 'iso3166-2-db/i18n/dispute/UN/ja';
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
31
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
32
|
+
import arDatabase from 'iso3166-2-db/i18n/dispute/UN/ar';
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
34
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
35
|
+
import itDatabase from 'iso3166-2-db/i18n/dispute/UN/it';
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
37
|
+
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
38
|
+
import heDatabase from 'iso3166-2-db/i18n/dispute/UN/he';
|
|
39
|
+
// All available languages from iso3166-2-db package
|
|
40
|
+
export const AVAILABLE_LANGUAGES = ['en', 'ru', 'de', 'fr', 'es', 'zh', 'hi', 'pt', 'ja', 'ar', 'it', 'he'];
|
|
41
|
+
// Static language database mapping for all supported languages
|
|
42
|
+
const languageDatabases = {
|
|
43
|
+
en: enDatabase, // English
|
|
44
|
+
ru: ruDatabase, // Russian
|
|
45
|
+
de: deDatabase, // German
|
|
46
|
+
fr: frDatabase, // French
|
|
47
|
+
es: esDatabase, // Spanish
|
|
48
|
+
zh: zhDatabase, // Chinese
|
|
49
|
+
hi: hiDatabase, // Hindi
|
|
50
|
+
pt: ptDatabase, // Portuguese
|
|
51
|
+
ja: jaDatabase, // Japanese
|
|
52
|
+
ar: arDatabase, // Arabic
|
|
53
|
+
it: itDatabase, // Italian
|
|
54
|
+
he: heDatabase, // Hebrew
|
|
55
|
+
};
|
|
56
|
+
// Function to get language-specific database
|
|
57
|
+
function getWorldDatabase(language = 'en') {
|
|
58
|
+
const database = languageDatabases[language];
|
|
59
|
+
if (!database) {
|
|
60
|
+
console.warn(`Language ${language} not available, falling back to English`);
|
|
61
|
+
return languageDatabases.en;
|
|
62
|
+
}
|
|
63
|
+
return database;
|
|
64
|
+
}
|
|
7
65
|
// Transform the ISO3166 data into our expected format
|
|
8
|
-
export const getCountries = () => {
|
|
66
|
+
export const getCountries = (language = 'en') => {
|
|
67
|
+
const worldDatabase = getWorldDatabase(language);
|
|
9
68
|
const countries = [];
|
|
10
69
|
Object.keys(worldDatabase).forEach((countryCode) => {
|
|
11
70
|
const countryData = worldDatabase[countryCode];
|
|
@@ -21,7 +80,8 @@ export const getCountries = () => {
|
|
|
21
80
|
return countries.sort((a, b) => a.name.localeCompare(b.name));
|
|
22
81
|
};
|
|
23
82
|
// Get all states/regions for all countries
|
|
24
|
-
export const getAllStates = () => {
|
|
83
|
+
export const getAllStates = (language = 'en') => {
|
|
84
|
+
const worldDatabase = getWorldDatabase(language);
|
|
25
85
|
const states = [];
|
|
26
86
|
Object.keys(worldDatabase).forEach((countryCode) => {
|
|
27
87
|
const countryData = worldDatabase[countryCode];
|
|
@@ -40,7 +100,8 @@ export const getAllStates = () => {
|
|
|
40
100
|
return states.sort((a, b) => a.name.localeCompare(b.name));
|
|
41
101
|
};
|
|
42
102
|
// Get states for a specific country
|
|
43
|
-
export const getStatesForCountry = (countryCode) => {
|
|
103
|
+
export const getStatesForCountry = (countryCode, language = 'en') => {
|
|
104
|
+
const worldDatabase = getWorldDatabase(language);
|
|
44
105
|
const countryData = worldDatabase[countryCode];
|
|
45
106
|
if (!countryData?.regions || !Array.isArray(countryData.regions)) {
|
|
46
107
|
return [];
|
|
@@ -55,8 +116,8 @@ export const getStatesForCountry = (countryCode) => {
|
|
|
55
116
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
56
117
|
};
|
|
57
118
|
// Find country by name (fuzzy search)
|
|
58
|
-
export const findCountryByName = (countryName) => {
|
|
59
|
-
const countries = getCountries();
|
|
119
|
+
export const findCountryByName = (countryName, language = 'en') => {
|
|
120
|
+
const countries = getCountries(language);
|
|
60
121
|
const normalizedSearchName = countryName.toLowerCase().trim();
|
|
61
122
|
// Exact match first
|
|
62
123
|
const exactMatch = countries.find((country) => country.name.toLowerCase() === normalizedSearchName);
|
|
@@ -68,24 +129,26 @@ export const findCountryByName = (countryName) => {
|
|
|
68
129
|
return partialMatch ?? null;
|
|
69
130
|
};
|
|
70
131
|
// Find region by ISO code (e.g., "US-CA" for California)
|
|
71
|
-
export const findRegionByCode = (regionCode) => {
|
|
132
|
+
export const findRegionByCode = (regionCode, language = 'en') => {
|
|
72
133
|
const [countryCode, stateCode] = regionCode.split('-');
|
|
73
134
|
if (!countryCode || !stateCode)
|
|
74
135
|
return null;
|
|
75
|
-
const states = getStatesForCountry(countryCode);
|
|
136
|
+
const states = getStatesForCountry(countryCode, language);
|
|
76
137
|
return states.find((state) => state.code === stateCode) ?? null;
|
|
77
138
|
};
|
|
78
139
|
// Validate if a country code exists
|
|
79
|
-
export const isValidCountryCode = (countryCode) => {
|
|
140
|
+
export const isValidCountryCode = (countryCode, language = 'en') => {
|
|
141
|
+
const worldDatabase = getWorldDatabase(language);
|
|
80
142
|
return Object.prototype.hasOwnProperty.call(worldDatabase, countryCode);
|
|
81
143
|
};
|
|
82
144
|
// Validate if a state code exists for a given country
|
|
83
|
-
export const isValidStateCode = (countryCode, stateCode) => {
|
|
84
|
-
const states = getStatesForCountry(countryCode);
|
|
145
|
+
export const isValidStateCode = (countryCode, stateCode, language = 'en') => {
|
|
146
|
+
const states = getStatesForCountry(countryCode, language);
|
|
85
147
|
return states.some((state) => state.code === stateCode);
|
|
86
148
|
};
|
|
87
149
|
// Get country info including regions
|
|
88
|
-
export const getCountryWithRegions = (countryCode) => {
|
|
150
|
+
export const getCountryWithRegions = (countryCode, language = 'en') => {
|
|
151
|
+
const worldDatabase = getWorldDatabase(language);
|
|
89
152
|
const countryData = worldDatabase[countryCode];
|
|
90
153
|
if (!countryData)
|
|
91
154
|
return null;
|
|
@@ -97,6 +160,6 @@ export const getCountryWithRegions = (countryCode) => {
|
|
|
97
160
|
numeric: countryData.numeric,
|
|
98
161
|
uniqueKey: `country-${countryData.iso}`,
|
|
99
162
|
},
|
|
100
|
-
regions: getStatesForCountry(countryCode),
|
|
163
|
+
regions: getStatesForCountry(countryCode, language),
|
|
101
164
|
};
|
|
102
165
|
};
|
|
@@ -228,12 +228,7 @@ export interface CheckoutData {
|
|
|
228
228
|
availablePromotions: Promotion[];
|
|
229
229
|
}
|
|
230
230
|
export interface UseCheckoutOptions {
|
|
231
|
-
autoRefresh?: boolean;
|
|
232
|
-
refreshInterval?: number;
|
|
233
|
-
realTimeUpdates?: boolean;
|
|
234
|
-
autoInitFromUrl?: boolean;
|
|
235
231
|
checkoutToken?: string;
|
|
236
|
-
fallbackToken?: string;
|
|
237
232
|
autoLoadFromToken?: boolean;
|
|
238
233
|
}
|
|
239
234
|
export interface UseCheckoutResult {
|
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { useCurrency } from '../hooks/useCurrency';
|
|
3
3
|
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
4
|
-
import { getCheckoutToken } from '../utils/urlUtils';
|
|
5
4
|
import { collectTrackingData } from '../utils/trackingUtils';
|
|
5
|
+
import { usePluginConfig } from './usePluginConfig';
|
|
6
6
|
export function useCheckout(options = {}) {
|
|
7
|
-
const { apiService, updateCheckoutDebugData, refreshCoordinator,
|
|
7
|
+
const { apiService, updateCheckoutDebugData, refreshCoordinator, currency } = useTagadaContext();
|
|
8
|
+
const { storeId } = usePluginConfig();
|
|
8
9
|
const { code: currentCurrency } = useCurrency();
|
|
9
10
|
const [checkout, setCheckout] = useState(null);
|
|
10
11
|
const [isLoading, setIsLoading] = useState(false);
|
|
11
12
|
const [error, setError] = useState(null);
|
|
12
13
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
13
|
-
const {
|
|
14
|
-
const refreshTimeoutRef = useRef(null);
|
|
14
|
+
const { checkoutToken: providedToken, autoLoadFromToken = true, } = options;
|
|
15
15
|
const currentCheckoutTokenRef = useRef(null);
|
|
16
16
|
const hasAutoLoadedRef = useRef(false);
|
|
17
|
-
// Clear refresh timeout on unmount
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
return () => {
|
|
20
|
-
if (refreshTimeoutRef.current) {
|
|
21
|
-
clearTimeout(refreshTimeoutRef.current);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}, []);
|
|
25
17
|
// Update debug data whenever checkout state changes with comprehensive information
|
|
26
18
|
useEffect(() => {
|
|
27
19
|
const debugData = checkout
|
|
@@ -73,6 +65,7 @@ export function useCheckout(options = {}) {
|
|
|
73
65
|
};
|
|
74
66
|
const requestBody = {
|
|
75
67
|
...params,
|
|
68
|
+
storeId: params.storeId || storeId, // Use storeId from params or from usePluginConfig
|
|
76
69
|
returnUrl: params.returnUrl || window.location.origin,
|
|
77
70
|
customer: {
|
|
78
71
|
...params.customer,
|
|
@@ -111,7 +104,7 @@ export function useCheckout(options = {}) {
|
|
|
111
104
|
finally {
|
|
112
105
|
setIsLoading(false);
|
|
113
106
|
}
|
|
114
|
-
}, [apiService, currentCurrency, providedToken]);
|
|
107
|
+
}, [apiService, currentCurrency, providedToken, storeId]);
|
|
115
108
|
const getCheckout = useCallback(async (checkoutToken) => {
|
|
116
109
|
setIsLoading(true);
|
|
117
110
|
setError(null);
|
|
@@ -425,7 +418,7 @@ export function useCheckout(options = {}) {
|
|
|
425
418
|
method: 'POST',
|
|
426
419
|
body: {
|
|
427
420
|
lineItems,
|
|
428
|
-
storeId
|
|
421
|
+
storeId,
|
|
429
422
|
currency: currency.code,
|
|
430
423
|
promotionIds: promotionIds ?? [],
|
|
431
424
|
},
|
|
@@ -436,41 +429,31 @@ export function useCheckout(options = {}) {
|
|
|
436
429
|
const error = err instanceof Error ? err : new Error('Failed to preview checkout session');
|
|
437
430
|
throw error;
|
|
438
431
|
}
|
|
439
|
-
}, [apiService,
|
|
432
|
+
}, [apiService, storeId, currency.code]);
|
|
440
433
|
const clear = useCallback(() => {
|
|
441
434
|
setCheckout(null);
|
|
442
435
|
setError(null);
|
|
443
436
|
setIsInitialized(false);
|
|
444
437
|
currentCheckoutTokenRef.current = null;
|
|
445
438
|
hasAutoLoadedRef.current = false;
|
|
446
|
-
if (refreshTimeoutRef.current) {
|
|
447
|
-
clearTimeout(refreshTimeoutRef.current);
|
|
448
|
-
}
|
|
449
439
|
}, []);
|
|
450
|
-
// Auto-load existing checkout session from provided token
|
|
440
|
+
// Auto-load existing checkout session from provided token
|
|
451
441
|
useEffect(() => {
|
|
452
|
-
if (!autoLoadFromToken || hasAutoLoadedRef.current || isInitialized) {
|
|
442
|
+
if (!autoLoadFromToken || hasAutoLoadedRef.current || isInitialized || !providedToken) {
|
|
453
443
|
return;
|
|
454
444
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
currentUrl: true,
|
|
459
|
-
fallbackToken,
|
|
460
|
-
});
|
|
461
|
-
if (token && !isLoading) {
|
|
462
|
-
console.debug('[Checkout] Auto-loading from token:', {
|
|
463
|
-
source: providedToken ? 'provided' : 'url/fallback',
|
|
464
|
-
tokenPreview: token.substring(0, 8) + '...',
|
|
445
|
+
if (!isLoading) {
|
|
446
|
+
console.debug('[Checkout] Auto-loading from provided token:', {
|
|
447
|
+
tokenPreview: providedToken.substring(0, 8) + '...',
|
|
465
448
|
});
|
|
466
449
|
hasAutoLoadedRef.current = true;
|
|
467
|
-
getCheckout(
|
|
450
|
+
getCheckout(providedToken).catch((err) => {
|
|
468
451
|
console.error('Auto-load failed:', err);
|
|
469
452
|
setError(err instanceof Error ? err : new Error('Auto-load failed'));
|
|
470
453
|
hasAutoLoadedRef.current = false; // Reset to allow retry
|
|
471
454
|
});
|
|
472
455
|
}
|
|
473
|
-
}, [autoLoadFromToken, providedToken,
|
|
456
|
+
}, [autoLoadFromToken, providedToken, isInitialized, isLoading, getCheckout]);
|
|
474
457
|
return {
|
|
475
458
|
checkout,
|
|
476
459
|
isLoading,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SupportedLanguage } from '../../data/iso3166';
|
|
1
2
|
export interface ISOCountry {
|
|
2
3
|
iso: string;
|
|
3
4
|
iso3: string;
|
|
@@ -16,26 +17,26 @@ export interface UseISODataResult {
|
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* React hook for accessing ISO3166 countries and regions data
|
|
19
|
-
* @param language - Language code (en,
|
|
20
|
-
* @param disputeSetting - Territorial dispute perspective (UN
|
|
20
|
+
* @param language - Language code (supports: en, ru, de, fr, es, zh, hi, pt, ja, ar, it, he)
|
|
21
|
+
* @param disputeSetting - Territorial dispute perspective (currently only UN is supported)
|
|
21
22
|
* @returns Object with countries data and helper functions
|
|
22
23
|
*/
|
|
23
|
-
export declare function useISOData(language?:
|
|
24
|
+
export declare function useISOData(language?: SupportedLanguage, disputeSetting?: string): UseISODataResult;
|
|
24
25
|
/**
|
|
25
26
|
* Get available languages for ISO data
|
|
26
27
|
*/
|
|
27
|
-
export declare function getAvailableLanguages():
|
|
28
|
+
export declare function getAvailableLanguages(): SupportedLanguage[];
|
|
28
29
|
/**
|
|
29
30
|
* Get list of countries as options for select components
|
|
30
31
|
*/
|
|
31
|
-
export declare function useCountryOptions(language?:
|
|
32
|
+
export declare function useCountryOptions(language?: SupportedLanguage): {
|
|
32
33
|
value: string;
|
|
33
34
|
label: string;
|
|
34
35
|
}[];
|
|
35
36
|
/**
|
|
36
37
|
* Get list of regions/states for a country as options for select components
|
|
37
38
|
*/
|
|
38
|
-
export declare function useRegionOptions(countryCode: string, language?:
|
|
39
|
+
export declare function useRegionOptions(countryCode: string, language?: SupportedLanguage): {
|
|
39
40
|
value: string;
|
|
40
41
|
label: string;
|
|
41
42
|
}[];
|
|
@@ -1,43 +1,35 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
import { getDataSet, reduce } from 'iso3166-2-db';
|
|
2
|
+
// Import the pre-built ISO data functions
|
|
3
|
+
import { getCountries, getStatesForCountry } from '../../data/iso3166';
|
|
5
4
|
/**
|
|
6
5
|
* React hook for accessing ISO3166 countries and regions data
|
|
7
|
-
* @param language - Language code (en,
|
|
8
|
-
* @param disputeSetting - Territorial dispute perspective (UN
|
|
6
|
+
* @param language - Language code (supports: en, ru, de, fr, es, zh, hi, pt, ja, ar, it, he)
|
|
7
|
+
* @param disputeSetting - Territorial dispute perspective (currently only UN is supported)
|
|
9
8
|
* @returns Object with countries data and helper functions
|
|
10
9
|
*/
|
|
11
10
|
export function useISOData(language = 'en', disputeSetting = 'UN') {
|
|
12
11
|
const data = useMemo(() => {
|
|
13
12
|
try {
|
|
14
|
-
// Get
|
|
15
|
-
const
|
|
16
|
-
// Transform to our expected format
|
|
13
|
+
// Get countries from pre-built data with language support (now synchronous)
|
|
14
|
+
const countriesArray = getCountries(language);
|
|
15
|
+
// Transform to our expected format (Record<string, ISOCountry>)
|
|
17
16
|
const countries = {};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
name: countryData.name,
|
|
17
|
+
countriesArray.forEach((country) => {
|
|
18
|
+
countries[country.code] = {
|
|
19
|
+
iso: country.code,
|
|
20
|
+
iso3: country.iso3 || '',
|
|
21
|
+
numeric: country.numeric || 0,
|
|
22
|
+
name: country.name,
|
|
25
23
|
};
|
|
26
24
|
});
|
|
27
25
|
// Helper to load regions for a specific country
|
|
28
26
|
const getRegions = (countryCode) => {
|
|
29
27
|
try {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const regionData = countryData.regions[regionCode];
|
|
36
|
-
return {
|
|
37
|
-
iso: regionData.iso,
|
|
38
|
-
name: regionData.name,
|
|
39
|
-
};
|
|
40
|
-
});
|
|
28
|
+
const states = getStatesForCountry(countryCode, language);
|
|
29
|
+
return states.map((state) => ({
|
|
30
|
+
iso: state.code,
|
|
31
|
+
name: state.name,
|
|
32
|
+
}));
|
|
41
33
|
}
|
|
42
34
|
catch {
|
|
43
35
|
return []; // Return empty array if no regions
|
|
@@ -92,7 +84,8 @@ export function useISOData(language = 'en', disputeSetting = 'UN') {
|
|
|
92
84
|
* Get available languages for ISO data
|
|
93
85
|
*/
|
|
94
86
|
export function getAvailableLanguages() {
|
|
95
|
-
|
|
87
|
+
// Return all statically imported languages for browser compatibility
|
|
88
|
+
return ['en', 'ru', 'de', 'fr', 'es', 'zh', 'hi', 'pt', 'ja', 'ar', 'it', 'he'];
|
|
96
89
|
}
|
|
97
90
|
/**
|
|
98
91
|
* Get list of countries as options for select components
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { useCallback, useState } from 'react';
|
|
2
2
|
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
3
|
+
import { usePluginConfig } from './usePluginConfig';
|
|
3
4
|
import { setClientToken } from '../utils/tokenStorage';
|
|
4
5
|
export function useLogin() {
|
|
5
6
|
const [isLoading, setIsLoading] = useState(false);
|
|
6
7
|
const [error, setError] = useState(null);
|
|
7
8
|
const { apiService } = useTagadaContext();
|
|
9
|
+
const { storeId } = usePluginConfig();
|
|
8
10
|
const requestCode = useCallback(async (email) => {
|
|
9
11
|
setIsLoading(true);
|
|
10
12
|
try {
|
|
11
|
-
const storeId = apiService.getStoredStoreId();
|
|
12
13
|
if (!storeId) {
|
|
13
14
|
throw new Error('Store ID not found. Make sure the TagadaProvider is properly configured.');
|
|
14
15
|
}
|
|
@@ -33,11 +34,10 @@ export function useLogin() {
|
|
|
33
34
|
finally {
|
|
34
35
|
setIsLoading(false);
|
|
35
36
|
}
|
|
36
|
-
}, [apiService]);
|
|
37
|
+
}, [apiService, storeId]);
|
|
37
38
|
const verifyCode = useCallback(async (email, code) => {
|
|
38
39
|
setIsLoading(true);
|
|
39
40
|
try {
|
|
40
|
-
const storeId = apiService.getStoredStoreId();
|
|
41
41
|
if (!storeId) {
|
|
42
42
|
throw new Error('Store ID not found. Make sure the TagadaProvider is properly configured.');
|
|
43
43
|
}
|
|
@@ -65,7 +65,7 @@ export function useLogin() {
|
|
|
65
65
|
finally {
|
|
66
66
|
setIsLoading(false);
|
|
67
67
|
}
|
|
68
|
-
}, [apiService]);
|
|
68
|
+
}, [apiService, storeId]);
|
|
69
69
|
return {
|
|
70
70
|
error,
|
|
71
71
|
isLoading,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
3
|
+
import { usePluginConfig } from './usePluginConfig';
|
|
3
4
|
export function useOffers(options) {
|
|
4
5
|
const { apiService, environment } = useTagadaContext();
|
|
6
|
+
const { storeId } = usePluginConfig();
|
|
5
7
|
const [offers, setOffers] = useState([]);
|
|
6
8
|
const [isLoading, setIsLoading] = useState(false);
|
|
7
9
|
const [error, setError] = useState(null);
|
|
@@ -12,7 +14,10 @@ export function useOffers(options) {
|
|
|
12
14
|
setIsLoading(true);
|
|
13
15
|
setError(null);
|
|
14
16
|
try {
|
|
15
|
-
|
|
17
|
+
if (!storeId) {
|
|
18
|
+
throw new Error('Store ID not found. Make sure the TagadaProvider is properly configured.');
|
|
19
|
+
}
|
|
20
|
+
const responseData = await apiService.fetch(`/api/v1/stores/${storeId}/offers`, {
|
|
16
21
|
method: 'GET',
|
|
17
22
|
headers: {
|
|
18
23
|
'Content-Type': 'application/json',
|
|
@@ -31,7 +36,7 @@ export function useOffers(options) {
|
|
|
31
36
|
finally {
|
|
32
37
|
setIsLoading(false);
|
|
33
38
|
}
|
|
34
|
-
}, [apiService, environment.apiConfig.baseUrl, offerIds, enabled]);
|
|
39
|
+
}, [apiService, storeId, environment.apiConfig.baseUrl, offerIds, enabled]);
|
|
35
40
|
const initCheckoutSession = useCallback(async (offerId, orderId) => {
|
|
36
41
|
const response = await apiService.fetch(`/api/v1/checkout/offer/init`, {
|
|
37
42
|
method: 'POST',
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useState, useCallback, useEffect, useMemo } from 'react';
|
|
2
2
|
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
3
|
+
import { usePluginConfig } from './usePluginConfig';
|
|
3
4
|
export function useProducts(options = {}) {
|
|
4
5
|
const { apiService } = useTagadaContext();
|
|
6
|
+
const { storeId } = usePluginConfig();
|
|
5
7
|
const [products, setProducts] = useState([]);
|
|
6
8
|
const [isLoading, setIsLoading] = useState(false);
|
|
7
9
|
const [error, setError] = useState(null);
|
|
@@ -27,7 +29,6 @@ export function useProducts(options = {}) {
|
|
|
27
29
|
setIsLoading(true);
|
|
28
30
|
setError(null);
|
|
29
31
|
try {
|
|
30
|
-
const storeId = apiService.getStoredStoreId();
|
|
31
32
|
if (!storeId) {
|
|
32
33
|
throw new Error('Store ID not found. Make sure the TagadaProvider is properly configured.');
|
|
33
34
|
}
|
|
@@ -67,7 +68,7 @@ export function useProducts(options = {}) {
|
|
|
67
68
|
finally {
|
|
68
69
|
setIsLoading(false);
|
|
69
70
|
}
|
|
70
|
-
}, [apiService, productIds, enabled, includeVariants, includePrices]);
|
|
71
|
+
}, [apiService, storeId, productIds, enabled, includeVariants, includePrices]);
|
|
71
72
|
const getProduct = useCallback((productId) => {
|
|
72
73
|
return products.find((product) => product.id === productId);
|
|
73
74
|
}, [products]);
|
package/dist/react/index.d.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* React SDK exports
|
|
3
3
|
*/
|
|
4
4
|
export { TagadaProvider } from './providers/TagadaProvider';
|
|
5
|
-
export { useAddress } from './hooks/useAddress';
|
|
6
5
|
export { useAuth } from './hooks/useAuth';
|
|
7
6
|
export { useCheckout } from './hooks/useCheckout';
|
|
8
7
|
export { useCurrency } from './hooks/useCurrency';
|
|
9
8
|
export { useCustomer } from './hooks/useCustomer';
|
|
10
9
|
export { useEnvironment } from './hooks/useEnvironment';
|
|
10
|
+
export { useGoogleAutocomplete } from './hooks/useGoogleAutocomplete';
|
|
11
11
|
export { useLocale } from './hooks/useLocale';
|
|
12
12
|
export { useLogin } from './hooks/useLogin';
|
|
13
13
|
export { useOffers } from './hooks/useOffers';
|
|
@@ -18,10 +18,9 @@ export { useSession } from './hooks/useSession';
|
|
|
18
18
|
export { useTagadaContext } from './providers/TagadaProvider';
|
|
19
19
|
export { usePluginConfig, useBasePath, getPluginConfig, clearPluginConfigCache, debugPluginConfig } from './hooks/usePluginConfig';
|
|
20
20
|
export type { PluginConfig } from './hooks/usePluginConfig';
|
|
21
|
-
export { useGoogleAutocomplete, useGoogleMapsLoaded } from './hooks/useGoogleAutocomplete';
|
|
22
|
-
export type { GooglePrediction, GoogleAddressComponent, GooglePlaceDetails, ExtractedAddress, UseGoogleAutocompleteOptions, UseGoogleAutocompleteResult } from './hooks/useGoogleAutocomplete';
|
|
23
21
|
export { useISOData, useCountryOptions, useRegionOptions, getAvailableLanguages } from './hooks/useISOData';
|
|
24
22
|
export type { ISOCountry, ISORegion, UseISODataResult } from './hooks/useISOData';
|
|
23
|
+
export type { GooglePrediction, GoogleAddressComponent, GooglePlaceDetails, ExtractedAddress, UseGoogleAutocompleteOptions, UseGoogleAutocompleteResult } from './hooks/useGoogleAutocomplete';
|
|
25
24
|
export { useOrder } from './hooks/useOrder';
|
|
26
25
|
export type { UseOrderOptions, UseOrderResult } from './hooks/useOrder';
|
|
27
26
|
export { usePayment } from './hooks/usePayment';
|
|
@@ -32,7 +31,6 @@ export type { AuthState, Currency, Customer, Environment, EnvironmentConfig, Loc
|
|
|
32
31
|
export type { CheckoutSessionPreview, CheckoutData, CheckoutInitParams, CheckoutLineItem, CheckoutSession, Promotion, UseCheckoutOptions, UseCheckoutResult, } from './hooks/useCheckout';
|
|
33
32
|
export type { OrderBumpPreview, UseOrderBumpOptions, UseOrderBumpResult } from './hooks/useOrderBump';
|
|
34
33
|
export type { PostPurchaseOffer, PostPurchaseOfferItem, PostPurchaseOfferLineItem, PostPurchaseOfferSummary, UsePostPurchasesOptions, UsePostPurchasesResult, } from './hooks/usePostPurchases';
|
|
35
|
-
export type { AddressData, AddressField, Country, State, UseAddressOptions, UseAddressResult, } from './hooks/useAddress';
|
|
36
34
|
export type { Payment, PaymentPollingHook, PollingOptions } from './hooks/usePaymentPolling';
|
|
37
35
|
export type { PaymentInstrument, ThreedsChallenge, ThreedsHook, ThreedsOptions, ThreedsProvider, ThreedsSession, } from './hooks/useThreeds';
|
|
38
36
|
export type { ApplePayToken, CardPaymentMethod, PaymentHook, PaymentInstrumentResponse, PaymentOptions, PaymentResponse, } from './hooks/usePayment';
|
package/dist/react/index.js
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
// Provider exports
|
|
6
6
|
export { TagadaProvider } from './providers/TagadaProvider';
|
|
7
7
|
// Hook exports
|
|
8
|
-
export { useAddress } from './hooks/useAddress';
|
|
9
8
|
export { useAuth } from './hooks/useAuth';
|
|
10
9
|
export { useCheckout } from './hooks/useCheckout';
|
|
11
10
|
export { useCurrency } from './hooks/useCurrency';
|
|
12
11
|
export { useCustomer } from './hooks/useCustomer';
|
|
13
12
|
export { useEnvironment } from './hooks/useEnvironment';
|
|
13
|
+
export { useGoogleAutocomplete } from './hooks/useGoogleAutocomplete';
|
|
14
14
|
export { useLocale } from './hooks/useLocale';
|
|
15
15
|
export { useLogin } from './hooks/useLogin';
|
|
16
16
|
export { useOffers } from './hooks/useOffers';
|
|
@@ -21,8 +21,6 @@ export { useSession } from './hooks/useSession';
|
|
|
21
21
|
export { useTagadaContext } from './providers/TagadaProvider';
|
|
22
22
|
// Plugin configuration hooks
|
|
23
23
|
export { usePluginConfig, useBasePath, getPluginConfig, clearPluginConfigCache, debugPluginConfig } from './hooks/usePluginConfig';
|
|
24
|
-
// Google Places hooks
|
|
25
|
-
export { useGoogleAutocomplete, useGoogleMapsLoaded } from './hooks/useGoogleAutocomplete';
|
|
26
24
|
// ISO Data hooks
|
|
27
25
|
export { useISOData, useCountryOptions, useRegionOptions, getAvailableLanguages } from './hooks/useISOData';
|
|
28
26
|
// Order hook exports
|
|
@@ -51,11 +51,9 @@ interface TagadaProviderProps {
|
|
|
51
51
|
environment?: Environment;
|
|
52
52
|
customApiConfig?: Partial<EnvironmentConfig>;
|
|
53
53
|
debugMode?: boolean;
|
|
54
|
-
storeId?: string;
|
|
55
|
-
accountId?: string;
|
|
56
54
|
localConfig?: string;
|
|
57
55
|
}
|
|
58
56
|
export declare function TagadaProvider({ children, environment, customApiConfig, debugMode, // Remove default, will be set based on environment
|
|
59
|
-
|
|
57
|
+
localConfig, }: TagadaProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
60
58
|
export declare function useTagadaContext(): TagadaContextValue;
|
|
61
59
|
export {};
|