@tagadapay/plugin-sdk 3.1.12 → 3.1.24
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/build-cdn.js +397 -11
- package/dist/data/iso3166.d.ts +23 -33
- package/dist/data/iso3166.js +134 -198
- package/dist/data/languages.d.ts +5 -64
- package/dist/data/languages.js +23 -143
- package/dist/external-tracker.js +623 -3426
- package/dist/external-tracker.min.js +2 -25
- package/dist/external-tracker.min.js.map +4 -4
- package/dist/react/config/payment.d.ts +14 -4
- package/dist/react/config/payment.js +47 -9
- package/dist/react/hooks/useCheckout.d.ts +3 -0
- package/dist/react/hooks/useCheckout.js +4 -1
- package/dist/react/hooks/useISOData.js +1 -1
- package/dist/react/hooks/usePaymentPolling.d.ts +3 -3
- package/dist/react/hooks/usePluginConfig.js +9 -10
- package/dist/react/providers/TagadaProvider.js +1 -1
- package/dist/tagada-react-sdk-minimal.min.js +36 -0
- package/dist/tagada-react-sdk-minimal.min.js.map +7 -0
- package/dist/tagada-react-sdk.js +37821 -0
- package/dist/tagada-react-sdk.min.js +78 -0
- package/dist/tagada-react-sdk.min.js.map +7 -0
- package/dist/tagada-sdk.js +16044 -0
- package/dist/tagada-sdk.min.js +32 -0
- package/dist/tagada-sdk.min.js.map +7 -0
- package/dist/v2/cdn-react-minimal.d.ts +23 -0
- package/dist/v2/cdn-react-minimal.js +26 -0
- package/dist/v2/core/client.d.ts +4 -2
- package/dist/v2/core/client.js +5 -4
- package/dist/v2/core/config/environment.js +2 -1
- package/dist/v2/core/errors.d.ts +75 -0
- package/dist/v2/core/errors.js +104 -0
- package/dist/v2/core/funnelClient.d.ts +100 -10
- package/dist/v2/core/funnelClient.js +121 -27
- package/dist/v2/core/isoData.d.ts +4 -4
- package/dist/v2/core/isoData.js +7 -7
- package/dist/v2/core/pixelMapping.d.ts +49 -0
- package/dist/v2/core/pixelMapping.js +363 -0
- package/dist/v2/core/resources/apiClient.d.ts +2 -0
- package/dist/v2/core/resources/apiClient.js +52 -9
- package/dist/v2/core/resources/checkout.d.ts +99 -30
- package/dist/v2/core/resources/checkout.js +14 -0
- package/dist/v2/core/resources/customer.d.ts +20 -19
- package/dist/v2/core/resources/expressPaymentMethods.d.ts +1 -0
- package/dist/v2/core/resources/funnel.d.ts +17 -17
- package/dist/v2/core/resources/payments.d.ts +89 -13
- package/dist/v2/core/resources/payments.js +27 -9
- package/dist/v2/core/resources/postPurchases.d.ts +17 -0
- package/dist/v2/core/resources/postPurchases.js +20 -0
- package/dist/v2/core/types.d.ts +50 -12
- package/dist/v2/core/types.js +0 -3
- package/dist/v2/core/utils/checkout.d.ts +2 -2
- package/dist/v2/core/utils/checkout.js +7 -2
- package/dist/v2/core/utils/currency.d.ts +14 -0
- package/dist/v2/core/utils/currency.js +40 -0
- package/dist/v2/core/utils/deviceInfo.d.ts +0 -10
- package/dist/v2/core/utils/deviceInfo.js +152 -76
- package/dist/v2/core/utils/index.d.ts +1 -0
- package/dist/v2/core/utils/index.js +2 -0
- package/dist/v2/core/utils/order.d.ts +13 -9
- package/dist/v2/core/utils/pluginConfig.d.ts +8 -0
- package/dist/v2/core/utils/pluginConfig.js +36 -12
- package/dist/v2/index.d.ts +6 -3
- package/dist/v2/index.js +4 -2
- package/dist/v2/react/components/FunnelScriptInjector.js +166 -77
- package/dist/v2/react/components/StripeExpressButton.d.ts +13 -0
- package/dist/v2/react/components/StripeExpressButton.js +171 -0
- package/dist/v2/react/components/WhopCheckout.d.ts +24 -0
- package/dist/v2/react/components/WhopCheckout.js +237 -0
- package/dist/v2/react/hooks/__examples__/FunnelContextExample.js +1 -1
- package/dist/v2/react/hooks/payment-actions/useAirwallexRadarAction.d.ts +14 -0
- package/dist/v2/react/hooks/payment-actions/useAirwallexRadarAction.js +181 -0
- package/dist/v2/react/hooks/payment-actions/useErrorAction.d.ts +9 -0
- package/dist/v2/react/hooks/payment-actions/useErrorAction.js +21 -0
- package/dist/v2/react/hooks/payment-actions/useFinixRadarAction.d.ts +14 -0
- package/dist/v2/react/hooks/payment-actions/useFinixRadarAction.js +187 -0
- package/dist/v2/react/hooks/payment-actions/useKessPayAction.d.ts +11 -0
- package/dist/v2/react/hooks/payment-actions/useKessPayAction.js +91 -0
- package/dist/v2/react/hooks/payment-actions/useMasterCardAction.d.ts +24 -0
- package/dist/v2/react/hooks/payment-actions/useMasterCardAction.js +221 -0
- package/dist/v2/react/hooks/payment-actions/usePaymentActionHandler.d.ts +15 -0
- package/dist/v2/react/hooks/payment-actions/usePaymentActionHandler.js +142 -0
- package/dist/v2/react/hooks/payment-actions/useProcessorAuthAction.d.ts +3 -0
- package/dist/v2/react/hooks/payment-actions/useProcessorAuthAction.js +31 -0
- package/dist/v2/react/hooks/payment-actions/useRedirectAction.d.ts +10 -0
- package/dist/v2/react/hooks/payment-actions/useRedirectAction.js +35 -0
- package/dist/v2/react/hooks/payment-actions/useStripeRadarAction.d.ts +14 -0
- package/dist/v2/react/hooks/payment-actions/useStripeRadarAction.js +192 -0
- package/dist/v2/react/hooks/payment-actions/useThreedsAuthAction.d.ts +14 -0
- package/dist/v2/react/hooks/payment-actions/useThreedsAuthAction.js +81 -0
- package/dist/v2/react/hooks/payment-actions/useTrustFlowAction.d.ts +11 -0
- package/dist/v2/react/hooks/payment-actions/useTrustFlowAction.js +84 -0
- package/dist/v2/react/hooks/payment-processing/usePaymentInstruments.d.ts +14 -0
- package/dist/v2/react/hooks/payment-processing/usePaymentInstruments.js +36 -0
- package/dist/v2/react/hooks/payment-processing/usePaymentProcessors.d.ts +31 -0
- package/dist/v2/react/hooks/payment-processing/usePaymentProcessors.js +212 -0
- package/dist/v2/react/hooks/payment-redirect/useAirwallex3dsReturn.d.ts +14 -0
- package/dist/v2/react/hooks/payment-redirect/useAirwallex3dsReturn.js +207 -0
- package/dist/v2/react/hooks/payment-redirect/useGenericPaymentReturn.d.ts +12 -0
- package/dist/v2/react/hooks/payment-redirect/useGenericPaymentReturn.js +101 -0
- package/dist/v2/react/hooks/useApplePayCheckout.js +8 -8
- package/dist/v2/react/hooks/useCheckoutQuery.d.ts +16 -0
- package/dist/v2/react/hooks/useCheckoutQuery.js +63 -10
- package/dist/v2/react/hooks/useFunnel.d.ts +15 -4
- package/dist/v2/react/hooks/useFunnel.js +8 -4
- package/dist/v2/react/hooks/useGeoLocation.d.ts +2 -1
- package/dist/v2/react/hooks/useGeoLocation.js +4 -2
- package/dist/v2/react/hooks/useGoogleAutocomplete.d.ts +2 -0
- package/dist/v2/react/hooks/useGoogleAutocomplete.js +29 -15
- package/dist/v2/react/hooks/useISOData.d.ts +2 -5
- package/dist/v2/react/hooks/useISOData.js +26 -27
- package/dist/v2/react/hooks/usePaymentPolling.d.ts +3 -3
- package/dist/v2/react/hooks/usePaymentQuery.d.ts +18 -5
- package/dist/v2/react/hooks/usePaymentQuery.js +63 -1015
- package/dist/v2/react/hooks/usePaymentRetrieve.d.ts +3 -2
- package/dist/v2/react/hooks/usePaymentRetrieve.js +3 -1
- package/dist/v2/react/hooks/usePixelTracking.d.ts +5 -48
- package/dist/v2/react/hooks/usePixelTracking.js +283 -504
- package/dist/v2/react/hooks/usePostPurchasesQuery.js +34 -2
- package/dist/v2/react/hooks/useRemappableParams.d.ts +2 -6
- package/dist/v2/react/hooks/useRemappableParams.js +23 -23
- package/dist/v2/react/hooks/useSetPaymentMethod.d.ts +16 -0
- package/dist/v2/react/hooks/useSetPaymentMethod.js +33 -0
- package/dist/v2/react/hooks/useShippingRatesQuery.js +13 -5
- package/dist/v2/react/hooks/useStepConfig.d.ts +23 -6
- package/dist/v2/react/hooks/useStepConfig.js +14 -7
- package/dist/v2/react/hooks/useTranslation.js +23 -8
- package/dist/v2/react/hooks/useWhopPaymentPolling.d.ts +30 -0
- package/dist/v2/react/hooks/useWhopPaymentPolling.js +61 -0
- package/dist/v2/react/index.d.ts +15 -1
- package/dist/v2/react/index.js +7 -0
- package/dist/v2/react/providers/ExpressPaymentMethodsProvider.d.ts +3 -1
- package/dist/v2/react/providers/ExpressPaymentMethodsProvider.js +12 -2
- package/dist/v2/react/providers/TagadaProvider.js +74 -5
- package/dist/v2/standalone/external-tracker.d.ts +52 -46
- package/dist/v2/standalone/external-tracker.js +205 -98
- package/dist/v2/standalone/index.d.ts +40 -0
- package/dist/v2/standalone/index.js +148 -1
- package/dist/v2/standalone/payment-service.d.ts +134 -0
- package/dist/v2/standalone/payment-service.js +928 -0
- package/package.json +6 -4
- package/dist/react/utils/__tests__/urlUtils.test.d.ts +0 -1
- package/dist/react/utils/__tests__/urlUtils.test.js +0 -189
- package/dist/v2/core/__tests__/pathRemapping.test.d.ts +0 -11
- package/dist/v2/core/__tests__/pathRemapping.test.js +0 -776
package/dist/data/iso3166.js
CHANGED
|
@@ -1,230 +1,166 @@
|
|
|
1
|
-
// Modular language database system - import only what you need
|
|
2
|
-
// English is imported by default as fallback
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
5
|
-
import enDatabase from 'iso3166-2-db/i18n/dispute/UN/en';
|
|
6
|
-
// All available languages from iso3166-2-db package
|
|
7
|
-
export const AVAILABLE_LANGUAGES = ['en', 'ru', 'de', 'fr', 'es', 'zh', 'hi', 'pt', 'ja', 'ar', 'it', 'he'];
|
|
8
|
-
// Dynamic language database registry - starts with English only
|
|
9
|
-
const languageDatabases = {
|
|
10
|
-
en: enDatabase, // English (always available)
|
|
11
|
-
};
|
|
12
1
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
2
|
+
* Geodata — CDN-backed country/region data.
|
|
3
|
+
*
|
|
4
|
+
* Instead of bundling the 775KB iso3166-2-db package, we fetch slim JSON
|
|
5
|
+
* from Vercel Blob CDN on demand:
|
|
6
|
+
* - countries.json (~10KB) — fetched once on first getCountries() call
|
|
7
|
+
* - regions.json (~95KB) — fetched lazily on first getStatesForCountry() call
|
|
8
|
+
*
|
|
9
|
+
* Both are cached in memory after first fetch. The API surface is identical
|
|
10
|
+
* to the previous static-import version so all consumers work unchanged.
|
|
19
11
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
// CDN base serving the pre-built slim geodata (uploaded by scripts/build-geodata-cdn.ts)
|
|
13
|
+
const GEODATA_CDN_BASE = 'https://cvwnizdbugpz6jwk.public.blob.vercel-storage.com/geodata/v1';
|
|
14
|
+
export const AVAILABLE_LANGUAGES = ['en', 'ru', 'de', 'da', 'fr', 'es', 'zh', 'hi', 'pt', 'ja', 'ar', 'it', 'he'];
|
|
15
|
+
// ─── In-memory cache ─────────────────────────────────────────────────────────
|
|
16
|
+
const countriesCache = new Map();
|
|
17
|
+
const regionsCache = new Map();
|
|
18
|
+
const inflightCountries = new Map();
|
|
19
|
+
const inflightRegions = new Map();
|
|
20
|
+
// ─── CDN fetchers (deduplicated, cached) ─────────────────────────────────────
|
|
21
|
+
async function fetchCountriesRaw(language) {
|
|
22
|
+
const cached = countriesCache.get(language);
|
|
23
|
+
if (cached)
|
|
24
|
+
return cached;
|
|
25
|
+
// Deduplicate concurrent fetches for the same language
|
|
26
|
+
let inflight = inflightCountries.get(language);
|
|
27
|
+
if (inflight)
|
|
28
|
+
return inflight;
|
|
29
|
+
inflight = (async () => {
|
|
30
|
+
const url = `${GEODATA_CDN_BASE}/${language}/countries.json`;
|
|
31
|
+
const res = await fetch(url);
|
|
32
|
+
if (!res.ok)
|
|
33
|
+
throw new Error(`Geodata fetch failed: ${url} (${res.status})`);
|
|
34
|
+
const data = await res.json();
|
|
35
|
+
countriesCache.set(language, data);
|
|
36
|
+
inflightCountries.delete(language);
|
|
37
|
+
return data;
|
|
38
|
+
})();
|
|
39
|
+
inflightCountries.set(language, inflight);
|
|
40
|
+
return inflight;
|
|
26
41
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
async function fetchRegionsRaw(language) {
|
|
43
|
+
const cached = regionsCache.get(language);
|
|
44
|
+
if (cached)
|
|
45
|
+
return cached;
|
|
46
|
+
let inflight = inflightRegions.get(language);
|
|
47
|
+
if (inflight)
|
|
48
|
+
return inflight;
|
|
49
|
+
inflight = (async () => {
|
|
50
|
+
const url = `${GEODATA_CDN_BASE}/${language}/regions.json`;
|
|
51
|
+
const res = await fetch(url);
|
|
52
|
+
if (!res.ok)
|
|
53
|
+
throw new Error(`Geodata fetch failed: ${url} (${res.status})`);
|
|
54
|
+
const data = await res.json();
|
|
55
|
+
regionsCache.set(language, data);
|
|
56
|
+
inflightRegions.delete(language);
|
|
57
|
+
return data;
|
|
58
|
+
})();
|
|
59
|
+
inflightRegions.set(language, inflight);
|
|
60
|
+
return inflight;
|
|
34
61
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return Object.keys(languageDatabases);
|
|
62
|
+
// ─── Synchronous accessors (return cached data, empty if not yet loaded) ─────
|
|
63
|
+
// These preserve the existing synchronous API. Consumers should call
|
|
64
|
+
// ensureCountriesLoaded / ensureRegionsLoaded first (the useISOData hook does).
|
|
65
|
+
function getCountriesCached(language) {
|
|
66
|
+
return countriesCache.get(language) || countriesCache.get('en') || {};
|
|
41
67
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* @param language - Language code to import
|
|
45
|
-
* @returns Promise that resolves when language is registered
|
|
46
|
-
* @example
|
|
47
|
-
* await importLanguage('ru');
|
|
48
|
-
*/
|
|
49
|
-
export async function importLanguage(language) {
|
|
50
|
-
if (isLanguageRegistered(language)) {
|
|
51
|
-
return; // Already registered
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
let database;
|
|
55
|
-
switch (language) {
|
|
56
|
-
case 'ru':
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
58
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
59
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/ru')).default;
|
|
60
|
-
break;
|
|
61
|
-
case 'de':
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
63
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
64
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/de')).default;
|
|
65
|
-
break;
|
|
66
|
-
case 'fr':
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
68
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
69
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/fr')).default;
|
|
70
|
-
break;
|
|
71
|
-
case 'es':
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
74
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/es')).default;
|
|
75
|
-
break;
|
|
76
|
-
case 'zh':
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
78
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
79
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/zh')).default;
|
|
80
|
-
break;
|
|
81
|
-
case 'hi':
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
83
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
84
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/hi')).default;
|
|
85
|
-
break;
|
|
86
|
-
case 'pt':
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
88
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
89
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/pt')).default;
|
|
90
|
-
break;
|
|
91
|
-
case 'ja':
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
93
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
94
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/ja')).default;
|
|
95
|
-
break;
|
|
96
|
-
case 'ar':
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
98
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
99
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/ar')).default;
|
|
100
|
-
break;
|
|
101
|
-
case 'it':
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
103
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
104
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/it')).default;
|
|
105
|
-
break;
|
|
106
|
-
case 'he':
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
108
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
109
|
-
database = (await import('iso3166-2-db/i18n/dispute/UN/he')).default;
|
|
110
|
-
break;
|
|
111
|
-
default:
|
|
112
|
-
throw new Error(`Language ${language} is not supported`);
|
|
113
|
-
}
|
|
114
|
-
registerLanguage(language, database);
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
console.error(`Failed to import language ${language}:`, error);
|
|
118
|
-
throw new Error(`Failed to import language ${language}`);
|
|
119
|
-
}
|
|
68
|
+
function getRegionsCached(language) {
|
|
69
|
+
return regionsCache.get(language) || regionsCache.get('en') || {};
|
|
120
70
|
}
|
|
121
|
-
//
|
|
122
|
-
function
|
|
123
|
-
|
|
124
|
-
if (!database) {
|
|
125
|
-
console.warn(`Language ${language} not available, falling back to English. Use importLanguage('${language}') to load it.`);
|
|
126
|
-
return languageDatabases.en;
|
|
127
|
-
}
|
|
128
|
-
return database;
|
|
71
|
+
// ─── Public async loaders (call these before using sync getters) ─────────────
|
|
72
|
+
export async function ensureCountriesLoaded(language = 'en') {
|
|
73
|
+
await fetchCountriesRaw(language);
|
|
129
74
|
}
|
|
130
|
-
|
|
75
|
+
export async function ensureRegionsLoaded(language = 'en') {
|
|
76
|
+
await fetchRegionsRaw(language);
|
|
77
|
+
}
|
|
78
|
+
export async function ensureGeoDataLoaded(language = 'en') {
|
|
79
|
+
await Promise.all([fetchCountriesRaw(language), fetchRegionsRaw(language)]);
|
|
80
|
+
}
|
|
81
|
+
// ─── Backward-compatible sync API ────────────────────────────────────────────
|
|
82
|
+
// These match the old iso3166.ts signatures exactly.
|
|
131
83
|
export const getCountries = (language = 'en') => {
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
// Sort countries alphabetically by name
|
|
145
|
-
return countries.sort((a, b) => a.name.localeCompare(b.name));
|
|
146
|
-
};
|
|
147
|
-
// Get all states/regions for all countries
|
|
148
|
-
export const getAllStates = (language = 'en') => {
|
|
149
|
-
const worldDatabase = getWorldDatabase(language);
|
|
150
|
-
const states = [];
|
|
151
|
-
Object.keys(worldDatabase).forEach((countryCode) => {
|
|
152
|
-
const countryData = worldDatabase[countryCode];
|
|
153
|
-
if (countryData.regions && Array.isArray(countryData.regions)) {
|
|
154
|
-
countryData.regions.forEach((region, index) => {
|
|
155
|
-
states.push({
|
|
156
|
-
code: region.iso, // iso3166-2 code (the part after the dash)
|
|
157
|
-
name: region.name,
|
|
158
|
-
countryCode: countryData.iso,
|
|
159
|
-
uniqueKey: `state-${countryData.iso}-${region.iso}-${index}`,
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
// Sort states alphabetically by name
|
|
165
|
-
return states.sort((a, b) => a.name.localeCompare(b.name));
|
|
84
|
+
const raw = getCountriesCached(language);
|
|
85
|
+
return Object.entries(raw)
|
|
86
|
+
.map(([code, c]) => ({
|
|
87
|
+
code,
|
|
88
|
+
name: c.n,
|
|
89
|
+
iso3: c.i3,
|
|
90
|
+
numeric: c.nu,
|
|
91
|
+
uniqueKey: `country-${code}`,
|
|
92
|
+
}))
|
|
93
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
166
94
|
};
|
|
167
|
-
// Get states for a specific country
|
|
168
95
|
export const getStatesForCountry = (countryCode, language = 'en') => {
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
if (!
|
|
96
|
+
const raw = getRegionsCached(language);
|
|
97
|
+
const tuples = raw[countryCode];
|
|
98
|
+
if (!tuples)
|
|
172
99
|
return [];
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
uniqueKey: `state-${countryData.iso}-${region.iso}-${index}`,
|
|
100
|
+
return tuples
|
|
101
|
+
.map(([iso, name], i) => ({
|
|
102
|
+
code: iso,
|
|
103
|
+
name,
|
|
104
|
+
countryCode,
|
|
105
|
+
uniqueKey: `state-${countryCode}-${iso}-${i}`,
|
|
180
106
|
}))
|
|
181
107
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
182
108
|
};
|
|
183
|
-
|
|
109
|
+
export const getAllStates = (language = 'en') => {
|
|
110
|
+
const raw = getRegionsCached(language);
|
|
111
|
+
const states = [];
|
|
112
|
+
for (const [countryCode, tuples] of Object.entries(raw)) {
|
|
113
|
+
tuples.forEach(([iso, name], i) => {
|
|
114
|
+
states.push({ code: iso, name, countryCode, uniqueKey: `state-${countryCode}-${iso}-${i}` });
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return states.sort((a, b) => a.name.localeCompare(b.name));
|
|
118
|
+
};
|
|
184
119
|
export const findCountryByName = (countryName, language = 'en') => {
|
|
185
120
|
const countries = getCountries(language);
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return exactMatch;
|
|
191
|
-
// Partial match
|
|
192
|
-
const partialMatch = countries.find((country) => country.name.toLowerCase().includes(normalizedSearchName) ||
|
|
193
|
-
normalizedSearchName.includes(country.name.toLowerCase()));
|
|
194
|
-
return partialMatch ?? null;
|
|
121
|
+
const needle = countryName.toLowerCase().trim();
|
|
122
|
+
return countries.find(c => c.name.toLowerCase() === needle)
|
|
123
|
+
|| countries.find(c => c.name.toLowerCase().includes(needle) || needle.includes(c.name.toLowerCase()))
|
|
124
|
+
|| null;
|
|
195
125
|
};
|
|
196
|
-
// Find region by ISO code (e.g., "US-CA" for California)
|
|
197
126
|
export const findRegionByCode = (regionCode, language = 'en') => {
|
|
198
127
|
const [countryCode, stateCode] = regionCode.split('-');
|
|
199
128
|
if (!countryCode || !stateCode)
|
|
200
129
|
return null;
|
|
201
|
-
|
|
202
|
-
return states.find((state) => state.code === stateCode) ?? null;
|
|
130
|
+
return getStatesForCountry(countryCode, language).find(s => s.code === stateCode) ?? null;
|
|
203
131
|
};
|
|
204
|
-
// Validate if a country code exists
|
|
205
132
|
export const isValidCountryCode = (countryCode, language = 'en') => {
|
|
206
|
-
|
|
207
|
-
return Object.prototype.hasOwnProperty.call(worldDatabase, countryCode);
|
|
133
|
+
return countryCode in getCountriesCached(language);
|
|
208
134
|
};
|
|
209
|
-
// Validate if a state code exists for a given country
|
|
210
135
|
export const isValidStateCode = (countryCode, stateCode, language = 'en') => {
|
|
211
|
-
|
|
212
|
-
return states.some((state) => state.code === stateCode);
|
|
136
|
+
return getStatesForCountry(countryCode, language).some(s => s.code === stateCode);
|
|
213
137
|
};
|
|
214
|
-
// Get country info including regions
|
|
215
138
|
export const getCountryWithRegions = (countryCode, language = 'en') => {
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
if (!
|
|
139
|
+
const raw = getCountriesCached(language);
|
|
140
|
+
const c = raw[countryCode];
|
|
141
|
+
if (!c)
|
|
219
142
|
return null;
|
|
220
143
|
return {
|
|
221
|
-
country: {
|
|
222
|
-
code: countryData.iso,
|
|
223
|
-
name: countryData.name,
|
|
224
|
-
iso3: countryData.iso3,
|
|
225
|
-
numeric: countryData.numeric,
|
|
226
|
-
uniqueKey: `country-${countryData.iso}`,
|
|
227
|
-
},
|
|
144
|
+
country: { code: countryCode, name: c.n, iso3: c.i3, numeric: c.nu, uniqueKey: `country-${countryCode}` },
|
|
228
145
|
regions: getStatesForCountry(countryCode, language),
|
|
229
146
|
};
|
|
230
147
|
};
|
|
148
|
+
// ─── Language management (backward-compat) ───────────────────────────────────
|
|
149
|
+
export function registerLanguage(_language, _database) {
|
|
150
|
+
// No-op: CDN mode doesn't need manual registration
|
|
151
|
+
}
|
|
152
|
+
export function isLanguageRegistered(language) {
|
|
153
|
+
return countriesCache.has(language);
|
|
154
|
+
}
|
|
155
|
+
export function getRegisteredLanguages() {
|
|
156
|
+
return [...countriesCache.keys()];
|
|
157
|
+
}
|
|
158
|
+
export async function importLanguage(language) {
|
|
159
|
+
await ensureGeoDataLoaded(language);
|
|
160
|
+
}
|
|
161
|
+
// ─── Prefetch ────────────────────────────────────────────────────────────────
|
|
162
|
+
// Kick off English fetch the moment this module is imported so the country
|
|
163
|
+
// dropdown is populated by the time the React tree renders.
|
|
164
|
+
if (typeof globalThis !== 'undefined' && typeof fetch !== 'undefined') {
|
|
165
|
+
ensureGeoDataLoaded('en').catch(() => { });
|
|
166
|
+
}
|
package/dist/data/languages.d.ts
CHANGED
|
@@ -1,81 +1,22 @@
|
|
|
1
|
-
import type { SupportedLanguage } from './iso3166';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* await importRussian();
|
|
2
|
+
* Language import utilities — CDN-backed.
|
|
3
|
+
* All language-specific geodata is now fetched from Vercel Blob CDN,
|
|
4
|
+
* so these helpers are thin wrappers around ensureGeoDataLoaded().
|
|
7
5
|
*/
|
|
6
|
+
import type { SupportedLanguage } from './iso3166';
|
|
8
7
|
export declare function importRussian(): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* Import and register German language data
|
|
11
|
-
*/
|
|
12
8
|
export declare function importGerman(): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Import and register French language data
|
|
15
|
-
*/
|
|
16
9
|
export declare function importFrench(): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* Import and register Spanish language data
|
|
19
|
-
*/
|
|
20
10
|
export declare function importSpanish(): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Import and register Chinese language data
|
|
23
|
-
*/
|
|
24
11
|
export declare function importChinese(): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* Import and register Hindi language data
|
|
27
|
-
*/
|
|
28
12
|
export declare function importHindi(): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Import and register Portuguese language data
|
|
31
|
-
*/
|
|
32
13
|
export declare function importPortuguese(): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Import and register Japanese language data
|
|
35
|
-
*/
|
|
36
14
|
export declare function importJapanese(): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Import and register Arabic language data
|
|
39
|
-
*/
|
|
40
15
|
export declare function importArabic(): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Import and register Italian language data
|
|
43
|
-
*/
|
|
44
16
|
export declare function importItalian(): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Import and register Hebrew language data
|
|
47
|
-
*/
|
|
48
17
|
export declare function importHebrew(): Promise<void>;
|
|
49
|
-
|
|
50
|
-
* Language import functions mapping
|
|
51
|
-
*/
|
|
52
|
-
export declare const languageImports: {
|
|
53
|
-
readonly ru: typeof importRussian;
|
|
54
|
-
readonly de: typeof importGerman;
|
|
55
|
-
readonly fr: typeof importFrench;
|
|
56
|
-
readonly es: typeof importSpanish;
|
|
57
|
-
readonly zh: typeof importChinese;
|
|
58
|
-
readonly hi: typeof importHindi;
|
|
59
|
-
readonly pt: typeof importPortuguese;
|
|
60
|
-
readonly ja: typeof importJapanese;
|
|
61
|
-
readonly ar: typeof importArabic;
|
|
62
|
-
readonly it: typeof importItalian;
|
|
63
|
-
readonly he: typeof importHebrew;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Import multiple languages at once
|
|
67
|
-
* @param languages - Array of language codes to import
|
|
68
|
-
* @example
|
|
69
|
-
* import { importLanguages } from '@tagadapay/plugin-sdk/data/languages';
|
|
70
|
-
* await importLanguages(['ru', 'de', 'fr']);
|
|
71
|
-
*/
|
|
18
|
+
export declare const languageImports: Record<string, () => Promise<void>>;
|
|
72
19
|
export declare function importLanguages(languages: SupportedLanguage[]): Promise<void>;
|
|
73
|
-
/**
|
|
74
|
-
* Import all available languages (except English which is already imported)
|
|
75
|
-
* @example
|
|
76
|
-
* import { importAllLanguages } from '@tagadapay/plugin-sdk/data/languages';
|
|
77
|
-
* await importAllLanguages();
|
|
78
|
-
*/
|
|
79
20
|
export declare function importAllLanguages(): Promise<void>;
|
|
80
21
|
export declare const LANGUAGES: {
|
|
81
22
|
aa: {
|
package/dist/data/languages.js
CHANGED
|
@@ -1,153 +1,33 @@
|
|
|
1
|
-
// Language import utilities for modular ISO data loading
|
|
2
|
-
// This file provides convenient functions to import specific languages
|
|
3
|
-
import { registerLanguage } from './iso3166';
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* await importRussian();
|
|
9
|
-
*/
|
|
10
|
-
export async function importRussian() {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
12
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
13
|
-
const ruDatabase = (await import('iso3166-2-db/i18n/dispute/UN/ru')).default;
|
|
14
|
-
registerLanguage('ru', ruDatabase);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Import and register German language data
|
|
18
|
-
*/
|
|
19
|
-
export async function importGerman() {
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
21
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
22
|
-
const deDatabase = (await import('iso3166-2-db/i18n/dispute/UN/de')).default;
|
|
23
|
-
registerLanguage('de', deDatabase);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Import and register French language data
|
|
27
|
-
*/
|
|
28
|
-
export async function importFrench() {
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
30
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
31
|
-
const frDatabase = (await import('iso3166-2-db/i18n/dispute/UN/fr')).default;
|
|
32
|
-
registerLanguage('fr', frDatabase);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Import and register Spanish language data
|
|
36
|
-
*/
|
|
37
|
-
export async function importSpanish() {
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
39
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
40
|
-
const esDatabase = (await import('iso3166-2-db/i18n/dispute/UN/es')).default;
|
|
41
|
-
registerLanguage('es', esDatabase);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Import and register Chinese language data
|
|
45
|
-
*/
|
|
46
|
-
export async function importChinese() {
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
48
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
49
|
-
const zhDatabase = (await import('iso3166-2-db/i18n/dispute/UN/zh')).default;
|
|
50
|
-
registerLanguage('zh', zhDatabase);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Import and register Hindi language data
|
|
54
|
-
*/
|
|
55
|
-
export async function importHindi() {
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
57
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
58
|
-
const hiDatabase = (await import('iso3166-2-db/i18n/dispute/UN/hi')).default;
|
|
59
|
-
registerLanguage('hi', hiDatabase);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Import and register Portuguese language data
|
|
63
|
-
*/
|
|
64
|
-
export async function importPortuguese() {
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
66
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
67
|
-
const ptDatabase = (await import('iso3166-2-db/i18n/dispute/UN/pt')).default;
|
|
68
|
-
registerLanguage('pt', ptDatabase);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Import and register Japanese language data
|
|
72
|
-
*/
|
|
73
|
-
export async function importJapanese() {
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
75
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
76
|
-
const jaDatabase = (await import('iso3166-2-db/i18n/dispute/UN/ja')).default;
|
|
77
|
-
registerLanguage('ja', jaDatabase);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Import and register Arabic language data
|
|
81
|
-
*/
|
|
82
|
-
export async function importArabic() {
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
84
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
85
|
-
const arDatabase = (await import('iso3166-2-db/i18n/dispute/UN/ar')).default;
|
|
86
|
-
registerLanguage('ar', arDatabase);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Import and register Italian language data
|
|
90
|
-
*/
|
|
91
|
-
export async function importItalian() {
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
93
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
94
|
-
const itDatabase = (await import('iso3166-2-db/i18n/dispute/UN/it')).default;
|
|
95
|
-
registerLanguage('it', itDatabase);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Import and register Hebrew language data
|
|
99
|
-
*/
|
|
100
|
-
export async function importHebrew() {
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
102
|
-
// @ts-ignore - iso3166-2-db doesn't have TypeScript definitions
|
|
103
|
-
const heDatabase = (await import('iso3166-2-db/i18n/dispute/UN/he')).default;
|
|
104
|
-
registerLanguage('he', heDatabase);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Language import functions mapping
|
|
2
|
+
* Language import utilities — CDN-backed.
|
|
3
|
+
* All language-specific geodata is now fetched from Vercel Blob CDN,
|
|
4
|
+
* so these helpers are thin wrappers around ensureGeoDataLoaded().
|
|
108
5
|
*/
|
|
6
|
+
import { ensureGeoDataLoaded } from './iso3166';
|
|
7
|
+
export async function importRussian() { await ensureGeoDataLoaded('ru'); }
|
|
8
|
+
export async function importGerman() { await ensureGeoDataLoaded('de'); }
|
|
9
|
+
export async function importFrench() { await ensureGeoDataLoaded('fr'); }
|
|
10
|
+
export async function importSpanish() { await ensureGeoDataLoaded('es'); }
|
|
11
|
+
export async function importChinese() { await ensureGeoDataLoaded('zh'); }
|
|
12
|
+
export async function importHindi() { await ensureGeoDataLoaded('hi'); }
|
|
13
|
+
export async function importPortuguese() { await ensureGeoDataLoaded('pt'); }
|
|
14
|
+
export async function importJapanese() { await ensureGeoDataLoaded('ja'); }
|
|
15
|
+
export async function importArabic() { await ensureGeoDataLoaded('ar'); }
|
|
16
|
+
export async function importItalian() { await ensureGeoDataLoaded('it'); }
|
|
17
|
+
export async function importHebrew() { await ensureGeoDataLoaded('he'); }
|
|
109
18
|
export const languageImports = {
|
|
110
|
-
ru: importRussian,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
es: importSpanish,
|
|
114
|
-
zh: importChinese,
|
|
115
|
-
hi: importHindi,
|
|
116
|
-
pt: importPortuguese,
|
|
117
|
-
ja: importJapanese,
|
|
118
|
-
ar: importArabic,
|
|
119
|
-
it: importItalian,
|
|
120
|
-
he: importHebrew,
|
|
19
|
+
ru: importRussian, de: importGerman, fr: importFrench, es: importSpanish,
|
|
20
|
+
zh: importChinese, hi: importHindi, pt: importPortuguese, ja: importJapanese,
|
|
21
|
+
ar: importArabic, it: importItalian, he: importHebrew,
|
|
121
22
|
};
|
|
122
|
-
/**
|
|
123
|
-
* Import multiple languages at once
|
|
124
|
-
* @param languages - Array of language codes to import
|
|
125
|
-
* @example
|
|
126
|
-
* import { importLanguages } from '@tagadapay/plugin-sdk/data/languages';
|
|
127
|
-
* await importLanguages(['ru', 'de', 'fr']);
|
|
128
|
-
*/
|
|
129
23
|
export async function importLanguages(languages) {
|
|
130
|
-
|
|
131
|
-
.filter(lang => lang !== 'en')
|
|
132
|
-
.map(lang =>
|
|
133
|
-
const importFn = languageImports[lang];
|
|
134
|
-
if (!importFn) {
|
|
135
|
-
console.warn(`No import function found for language: ${lang}`);
|
|
136
|
-
return Promise.resolve();
|
|
137
|
-
}
|
|
138
|
-
return importFn();
|
|
139
|
-
});
|
|
140
|
-
await Promise.all(importPromises);
|
|
24
|
+
await Promise.all(languages
|
|
25
|
+
.filter(lang => lang !== 'en')
|
|
26
|
+
.map(lang => ensureGeoDataLoaded(lang)));
|
|
141
27
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Import all available languages (except English which is already imported)
|
|
144
|
-
* @example
|
|
145
|
-
* import { importAllLanguages } from '@tagadapay/plugin-sdk/data/languages';
|
|
146
|
-
* await importAllLanguages();
|
|
147
|
-
*/
|
|
148
28
|
export async function importAllLanguages() {
|
|
149
|
-
const
|
|
150
|
-
await importLanguages(
|
|
29
|
+
const all = ['ru', 'de', 'fr', 'es', 'zh', 'hi', 'pt', 'ja', 'ar', 'it', 'he'];
|
|
30
|
+
await importLanguages(all);
|
|
151
31
|
}
|
|
152
32
|
export const LANGUAGES = {
|
|
153
33
|
aa: {
|