@tagadapay/plugin-sdk 2.4.39 → 2.5.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/react/hooks/useCheckout.js +19 -2
- package/dist/react/hooks/useCheckoutSession.d.ts +19 -0
- package/dist/react/hooks/useCheckoutSession.js +108 -0
- package/dist/react/hooks/useCheckoutToken.d.ts +17 -0
- package/dist/react/hooks/useCheckoutToken.js +80 -0
- package/dist/react/hooks/useOrderBump.js +92 -13
- package/dist/react/hooks/useOrderBumpV2.d.ts +17 -0
- package/dist/react/hooks/useOrderBumpV2.js +95 -0
- package/dist/react/hooks/useOrderBumpV3.d.ts +23 -0
- package/dist/react/hooks/useOrderBumpV3.js +109 -0
- package/dist/react/hooks/usePostPurchases.js +11 -5
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.js +4 -0
- package/dist/react/services/apiService.d.ts +1 -0
- package/dist/react/services/apiService.js +3 -0
- package/dist/v2/core/googleAutocomplete.d.ts +65 -0
- package/dist/v2/core/googleAutocomplete.js +94 -0
- package/dist/v2/core/index.d.ts +8 -0
- package/dist/v2/core/index.js +11 -0
- package/dist/v2/core/isoData.d.ts +50 -0
- package/dist/v2/core/isoData.js +103 -0
- package/dist/v2/core/resources/apiClient.d.ts +25 -0
- package/dist/v2/core/resources/apiClient.js +95 -0
- package/dist/v2/core/resources/checkout.d.ts +189 -0
- package/dist/v2/core/resources/checkout.js +119 -0
- package/dist/v2/core/resources/index.d.ts +13 -0
- package/dist/v2/core/resources/index.js +13 -0
- package/dist/v2/core/resources/offers.d.ts +98 -0
- package/dist/v2/core/resources/offers.js +115 -0
- package/dist/v2/core/resources/orders.d.ts +40 -0
- package/dist/v2/core/resources/orders.js +59 -0
- package/dist/v2/core/resources/payments.d.ts +140 -0
- package/dist/v2/core/resources/payments.js +126 -0
- package/dist/v2/core/resources/postPurchases.d.ts +182 -0
- package/dist/v2/core/resources/postPurchases.js +116 -0
- package/dist/v2/core/resources/products.d.ts +29 -0
- package/dist/v2/core/resources/products.js +49 -0
- package/dist/v2/core/resources/promotions.d.ts +45 -0
- package/dist/v2/core/resources/promotions.js +87 -0
- package/dist/v2/core/resources/threeds.d.ts +23 -0
- package/dist/v2/core/resources/threeds.js +15 -0
- package/dist/v2/core/utils/checkout.d.ts +24 -0
- package/dist/v2/core/utils/checkout.js +30 -0
- package/dist/v2/core/utils/currency.d.ts +28 -0
- package/dist/v2/core/utils/currency.js +272 -0
- package/dist/v2/core/utils/index.d.ts +12 -0
- package/dist/v2/core/utils/index.js +12 -0
- package/dist/v2/core/utils/order.d.ts +159 -0
- package/dist/v2/core/utils/order.js +42 -0
- package/dist/v2/core/utils/orderBump.d.ts +40 -0
- package/dist/v2/core/utils/orderBump.js +47 -0
- package/dist/v2/core/utils/pluginConfig.d.ts +43 -0
- package/dist/v2/core/utils/pluginConfig.js +155 -0
- package/dist/v2/core/utils/postPurchases.d.ts +32 -0
- package/dist/v2/core/utils/postPurchases.js +42 -0
- package/dist/v2/core/utils/products.d.ts +58 -0
- package/dist/v2/core/utils/products.js +64 -0
- package/dist/v2/core/utils/promotions.d.ts +24 -0
- package/dist/v2/core/utils/promotions.js +30 -0
- package/dist/v2/index.d.ts +19 -0
- package/dist/v2/index.js +15 -0
- package/dist/v2/react/components/DebugDrawer.d.ts +7 -0
- package/dist/v2/react/components/DebugDrawer.js +383 -0
- package/dist/v2/react/hooks/useApiQuery.d.ts +28 -0
- package/dist/v2/react/hooks/useApiQuery.js +84 -0
- package/dist/v2/react/hooks/useCheckoutQuery.d.ts +39 -0
- package/dist/v2/react/hooks/useCheckoutQuery.js +194 -0
- package/dist/v2/react/hooks/useCheckoutToken.d.ts +17 -0
- package/dist/v2/react/hooks/useCheckoutToken.js +65 -0
- package/dist/v2/react/hooks/useCurrency.d.ts +9 -0
- package/dist/v2/react/hooks/useCurrency.js +21 -0
- package/dist/v2/react/hooks/useGeoLocation.d.ts +138 -0
- package/dist/v2/react/hooks/useGeoLocation.js +123 -0
- package/dist/v2/react/hooks/useGoogleAutocomplete.d.ts +74 -0
- package/dist/v2/react/hooks/useGoogleAutocomplete.js +196 -0
- package/dist/v2/react/hooks/useISOData.d.ts +61 -0
- package/dist/v2/react/hooks/useISOData.js +175 -0
- package/dist/v2/react/hooks/useOffersQuery.d.ts +65 -0
- package/dist/v2/react/hooks/useOffersQuery.js +342 -0
- package/dist/v2/react/hooks/useOrderBumpQuery.d.ts +20 -0
- package/dist/v2/react/hooks/useOrderBumpQuery.js +92 -0
- package/dist/v2/react/hooks/useOrderQuery.d.ts +29 -0
- package/dist/v2/react/hooks/useOrderQuery.js +98 -0
- package/dist/v2/react/hooks/usePaymentPolling.d.ts +45 -0
- package/dist/v2/react/hooks/usePaymentPolling.js +140 -0
- package/dist/v2/react/hooks/usePaymentQuery.d.ts +19 -0
- package/dist/v2/react/hooks/usePaymentQuery.js +272 -0
- package/dist/v2/react/hooks/usePluginConfig.d.ts +16 -0
- package/dist/v2/react/hooks/usePluginConfig.js +35 -0
- package/dist/v2/react/hooks/usePostPurchasesQuery.d.ts +63 -0
- package/dist/v2/react/hooks/usePostPurchasesQuery.js +343 -0
- package/dist/v2/react/hooks/useProductsQuery.d.ts +31 -0
- package/dist/v2/react/hooks/useProductsQuery.js +102 -0
- package/dist/v2/react/hooks/usePromotionsQuery.d.ts +28 -0
- package/dist/v2/react/hooks/usePromotionsQuery.js +97 -0
- package/dist/v2/react/hooks/useThreeds.d.ts +36 -0
- package/dist/v2/react/hooks/useThreeds.js +150 -0
- package/dist/v2/react/hooks/useThreedsModal.d.ts +13 -0
- package/dist/v2/react/hooks/useThreedsModal.js +343 -0
- package/dist/v2/react/index.d.ts +38 -0
- package/dist/v2/react/index.js +27 -0
- package/dist/v2/react/providers/TagadaProvider.d.ts +63 -0
- package/dist/v2/react/providers/TagadaProvider.js +680 -0
- package/package.json +10 -3
|
@@ -24,7 +24,7 @@ export function usePostPurchases(options) {
|
|
|
24
24
|
// Auto-initialize checkout sessions if enabled
|
|
25
25
|
if (autoInitializeCheckout && fetchedOffers.length > 0) {
|
|
26
26
|
for (const offer of fetchedOffers) {
|
|
27
|
-
|
|
27
|
+
void initializeOfferCheckout(offer.id);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -69,9 +69,13 @@ export function usePostPurchases(options) {
|
|
|
69
69
|
method: 'POST',
|
|
70
70
|
body: JSON.stringify({
|
|
71
71
|
checkoutSessionId,
|
|
72
|
+
draft: false,
|
|
73
|
+
returnUrl: window.location.href,
|
|
72
74
|
metadata: {
|
|
73
75
|
comingFromPostPurchase: true,
|
|
74
76
|
postOrder: orderId,
|
|
77
|
+
upsell: true,
|
|
78
|
+
source: 'post_purchase_offer',
|
|
75
79
|
},
|
|
76
80
|
}),
|
|
77
81
|
});
|
|
@@ -244,6 +248,8 @@ export function usePostPurchases(options) {
|
|
|
244
248
|
metadata: {
|
|
245
249
|
comingFromPostPurchase: true,
|
|
246
250
|
postOrder: orderId,
|
|
251
|
+
upsell: true,
|
|
252
|
+
source: 'post_purchase_offer',
|
|
247
253
|
},
|
|
248
254
|
}),
|
|
249
255
|
});
|
|
@@ -268,17 +274,17 @@ export function usePostPurchases(options) {
|
|
|
268
274
|
}));
|
|
269
275
|
}, [checkoutSessions]);
|
|
270
276
|
const getOrderSummary = useCallback((offerId) => {
|
|
271
|
-
return checkoutSessions[offerId]?.orderSummary
|
|
277
|
+
return checkoutSessions[offerId]?.orderSummary ?? null;
|
|
272
278
|
}, [checkoutSessions]);
|
|
273
279
|
const isLoadingVariants = useCallback((offerId, productId) => {
|
|
274
|
-
return checkoutSessions[offerId]?.loadingVariants?.[productId]
|
|
280
|
+
return checkoutSessions[offerId]?.loadingVariants?.[productId] ?? false;
|
|
275
281
|
}, [checkoutSessions]);
|
|
276
282
|
const isUpdatingOrderSummary = useCallback((offerId) => {
|
|
277
|
-
return checkoutSessions[offerId]?.isUpdatingSummary
|
|
283
|
+
return checkoutSessions[offerId]?.isUpdatingSummary ?? false;
|
|
278
284
|
}, [checkoutSessions]);
|
|
279
285
|
useEffect(() => {
|
|
280
286
|
if (enabled && orderId) {
|
|
281
|
-
fetchOffers();
|
|
287
|
+
void fetchOffers();
|
|
282
288
|
}
|
|
283
289
|
}, [enabled, orderId, fetchOffers]);
|
|
284
290
|
const getOffer = useCallback((offerId) => {
|
package/dist/react/index.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export { useLocale } from './hooks/useLocale';
|
|
|
15
15
|
export { useLogin } from './hooks/useLogin';
|
|
16
16
|
export { useOffers } from './hooks/useOffers';
|
|
17
17
|
export { useOrderBump } from './hooks/useOrderBump';
|
|
18
|
+
export { useOrderBumpV2 } from './hooks/useOrderBumpV2';
|
|
19
|
+
export { useOrderBumpV3 } from './hooks/useOrderBumpV3';
|
|
20
|
+
export { useCheckoutToken } from './hooks/useCheckoutToken';
|
|
21
|
+
export { useCheckoutSession } from './hooks/useCheckoutSession';
|
|
18
22
|
export { usePostPurchases } from './hooks/usePostPurchases';
|
|
19
23
|
export { useProducts } from './hooks/useProducts';
|
|
20
24
|
export { useSession } from './hooks/useSession';
|
|
@@ -41,6 +45,10 @@ export type { AuthState, Currency, Customer, Environment, EnvironmentConfig, Loc
|
|
|
41
45
|
export type { CheckoutData, CheckoutInitParams, CheckoutLineItem, CheckoutSession, CheckoutSessionPreview, Promotion, UseCheckoutOptions, UseCheckoutResult } from './hooks/useCheckout';
|
|
42
46
|
export type { Discount, DiscountCodeValidation, UseDiscountsOptions, UseDiscountsResult } from './hooks/useDiscounts';
|
|
43
47
|
export type { OrderBumpPreview, UseOrderBumpOptions, UseOrderBumpResult } from './hooks/useOrderBump';
|
|
48
|
+
export type { UseOrderBumpV2Options, UseOrderBumpV2Result } from './hooks/useOrderBumpV2';
|
|
49
|
+
export type { UseOrderBumpV3Options, UseOrderBumpV3Result } from './hooks/useOrderBumpV3';
|
|
50
|
+
export type { UseCheckoutTokenOptions, UseCheckoutTokenResult } from './hooks/useCheckoutToken';
|
|
51
|
+
export type { UseCheckoutSessionOptions, UseCheckoutSessionResult } from './hooks/useCheckoutSession';
|
|
44
52
|
export type { UseVipOffersOptions, UseVipOffersResult, VipOffer, VipPreviewResponse } from './hooks/useVipOffers';
|
|
45
53
|
export type { PostPurchaseOffer, PostPurchaseOfferItem, PostPurchaseOfferLineItem, PostPurchaseOfferSummary, UsePostPurchasesOptions, UsePostPurchasesResult } from './hooks/usePostPurchases';
|
|
46
54
|
export type { Payment, PaymentPollingHook, PollingOptions } from './hooks/usePaymentPolling';
|
package/dist/react/index.js
CHANGED
|
@@ -18,6 +18,10 @@ export { useLocale } from './hooks/useLocale';
|
|
|
18
18
|
export { useLogin } from './hooks/useLogin';
|
|
19
19
|
export { useOffers } from './hooks/useOffers';
|
|
20
20
|
export { useOrderBump } from './hooks/useOrderBump';
|
|
21
|
+
export { useOrderBumpV2 } from './hooks/useOrderBumpV2';
|
|
22
|
+
export { useOrderBumpV3 } from './hooks/useOrderBumpV3';
|
|
23
|
+
export { useCheckoutToken } from './hooks/useCheckoutToken';
|
|
24
|
+
export { useCheckoutSession } from './hooks/useCheckoutSession';
|
|
21
25
|
export { usePostPurchases } from './hooks/usePostPurchases';
|
|
22
26
|
export { useProducts } from './hooks/useProducts';
|
|
23
27
|
export { useSession } from './hooks/useSession';
|
|
@@ -49,6 +49,7 @@ export declare class ApiService {
|
|
|
49
49
|
private onTokenClear?;
|
|
50
50
|
constructor(options: ApiServiceOptions);
|
|
51
51
|
updateToken(token: string | null): void;
|
|
52
|
+
getCurrentToken(): string | null;
|
|
52
53
|
updateConfig(config: EnvironmentConfig): void;
|
|
53
54
|
/**
|
|
54
55
|
* Store the store ID in localStorage (deprecated - use usePluginConfig instead)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Autocomplete Core
|
|
3
|
+
* Pure functions for Google Places API integration
|
|
4
|
+
*/
|
|
5
|
+
export interface GooglePrediction {
|
|
6
|
+
place_id: string;
|
|
7
|
+
description: string;
|
|
8
|
+
structured_formatting?: {
|
|
9
|
+
main_text: string;
|
|
10
|
+
secondary_text: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface GooglePlaceDetails {
|
|
14
|
+
place_id: string;
|
|
15
|
+
formatted_address: string;
|
|
16
|
+
address_components: {
|
|
17
|
+
long_name: string;
|
|
18
|
+
short_name: string;
|
|
19
|
+
types: string[];
|
|
20
|
+
}[];
|
|
21
|
+
geometry: {
|
|
22
|
+
location: {
|
|
23
|
+
lat: number;
|
|
24
|
+
lng: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface AddressComponents {
|
|
29
|
+
streetNumber?: string;
|
|
30
|
+
route?: string;
|
|
31
|
+
city?: string;
|
|
32
|
+
state?: string;
|
|
33
|
+
postalCode?: string;
|
|
34
|
+
country?: string;
|
|
35
|
+
countryCode?: string;
|
|
36
|
+
locality?: string;
|
|
37
|
+
administrativeAreaLevel1?: string;
|
|
38
|
+
administrativeAreaLevel1Long?: string;
|
|
39
|
+
iso?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare class GoogleAutocompleteCore {
|
|
42
|
+
private static apiKey;
|
|
43
|
+
private static service;
|
|
44
|
+
/**
|
|
45
|
+
* Initialize Google Places API
|
|
46
|
+
*/
|
|
47
|
+
static initialize(apiKey: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Search for places
|
|
50
|
+
*/
|
|
51
|
+
static searchPlaces(input: string, options?: {
|
|
52
|
+
types?: string[];
|
|
53
|
+
componentRestrictions?: {
|
|
54
|
+
country: string;
|
|
55
|
+
};
|
|
56
|
+
}): Promise<GooglePrediction[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Get place details
|
|
59
|
+
*/
|
|
60
|
+
static getPlaceDetails(placeId: string): Promise<GooglePlaceDetails | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Extract address components from place details
|
|
63
|
+
*/
|
|
64
|
+
static extractAddressComponents(placeDetails: GooglePlaceDetails): AddressComponents;
|
|
65
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Autocomplete Core
|
|
3
|
+
* Pure functions for Google Places API integration
|
|
4
|
+
*/
|
|
5
|
+
export class GoogleAutocompleteCore {
|
|
6
|
+
/**
|
|
7
|
+
* Initialize Google Places API
|
|
8
|
+
*/
|
|
9
|
+
static initialize(apiKey) {
|
|
10
|
+
this.apiKey = apiKey;
|
|
11
|
+
if (typeof window !== 'undefined' && window.google) {
|
|
12
|
+
this.service = new window.google.maps.places.AutocompleteService();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Search for places
|
|
17
|
+
*/
|
|
18
|
+
static async searchPlaces(input, options = {}) {
|
|
19
|
+
if (!this.service || !input.trim()) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
this.service.getPlacePredictions({
|
|
24
|
+
input,
|
|
25
|
+
types: options.types || ['address'],
|
|
26
|
+
componentRestrictions: options.componentRestrictions,
|
|
27
|
+
}, (predictions, status) => {
|
|
28
|
+
if (status === window.google.maps.places.PlacesServiceStatus.OK && predictions) {
|
|
29
|
+
resolve(predictions);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
resolve([]);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get place details
|
|
39
|
+
*/
|
|
40
|
+
static async getPlaceDetails(placeId) {
|
|
41
|
+
if (typeof window === 'undefined' || !window.google) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const service = new window.google.maps.places.PlacesService(document.createElement('div'));
|
|
46
|
+
service.getDetails({
|
|
47
|
+
placeId,
|
|
48
|
+
fields: ['place_id', 'formatted_address', 'address_components', 'geometry'],
|
|
49
|
+
}, (place, status) => {
|
|
50
|
+
if (status === window.google.maps.places.PlacesServiceStatus.OK && place) {
|
|
51
|
+
resolve(place);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
resolve(null);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Extract address components from place details
|
|
61
|
+
*/
|
|
62
|
+
static extractAddressComponents(placeDetails) {
|
|
63
|
+
const components = {};
|
|
64
|
+
for (const component of placeDetails.address_components) {
|
|
65
|
+
const types = component.types;
|
|
66
|
+
if (types.includes('street_number')) {
|
|
67
|
+
components.streetNumber = component.long_name;
|
|
68
|
+
}
|
|
69
|
+
else if (types.includes('route')) {
|
|
70
|
+
components.route = component.long_name;
|
|
71
|
+
}
|
|
72
|
+
else if (types.includes('locality')) {
|
|
73
|
+
components.city = component.long_name;
|
|
74
|
+
components.locality = component.long_name;
|
|
75
|
+
}
|
|
76
|
+
else if (types.includes('administrative_area_level_1')) {
|
|
77
|
+
components.state = component.long_name;
|
|
78
|
+
components.administrativeAreaLevel1 = component.short_name;
|
|
79
|
+
components.administrativeAreaLevel1Long = component.long_name;
|
|
80
|
+
}
|
|
81
|
+
else if (types.includes('postal_code')) {
|
|
82
|
+
components.postalCode = component.long_name;
|
|
83
|
+
}
|
|
84
|
+
else if (types.includes('country')) {
|
|
85
|
+
components.country = component.long_name;
|
|
86
|
+
components.countryCode = component.short_name;
|
|
87
|
+
components.iso = component.short_name;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return components;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
GoogleAutocompleteCore.apiKey = null;
|
|
94
|
+
GoogleAutocompleteCore.service = null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core functions and utilities for TagadaPay Plugin SDK v2
|
|
3
|
+
* Structured with utils (pure functions) and resources (API clients)
|
|
4
|
+
*/
|
|
5
|
+
export * from './utils';
|
|
6
|
+
export * from './resources';
|
|
7
|
+
export * from './googleAutocomplete';
|
|
8
|
+
export * from './isoData';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core functions and utilities for TagadaPay Plugin SDK v2
|
|
3
|
+
* Structured with utils (pure functions) and resources (API clients)
|
|
4
|
+
*/
|
|
5
|
+
// Export utilities (pure functions)
|
|
6
|
+
export * from './utils';
|
|
7
|
+
// Export resources (axios-based API clients)
|
|
8
|
+
export * from './resources';
|
|
9
|
+
// Export legacy files that are still needed
|
|
10
|
+
export * from './googleAutocomplete';
|
|
11
|
+
export * from './isoData';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISO Data Core
|
|
3
|
+
* Pure functions for country and region data management
|
|
4
|
+
* Uses the existing iso3166 data functions
|
|
5
|
+
*/
|
|
6
|
+
import { type SupportedLanguage } from '../../data/iso3166';
|
|
7
|
+
export interface ISOCountry {
|
|
8
|
+
iso: string;
|
|
9
|
+
iso3: string;
|
|
10
|
+
numeric: number;
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ISORegion {
|
|
14
|
+
iso: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class ISODataCore {
|
|
18
|
+
/**
|
|
19
|
+
* Get countries data for a specific language
|
|
20
|
+
*/
|
|
21
|
+
static getCountriesData(language?: SupportedLanguage): Record<string, ISOCountry>;
|
|
22
|
+
/**
|
|
23
|
+
* Get regions for a specific country
|
|
24
|
+
*/
|
|
25
|
+
static getRegions(countryCode: string, language?: SupportedLanguage): ISORegion[];
|
|
26
|
+
/**
|
|
27
|
+
* Find a specific region by ISO code
|
|
28
|
+
*/
|
|
29
|
+
static findRegion(countryCode: string, regionCode: string, language?: SupportedLanguage): ISORegion | null;
|
|
30
|
+
/**
|
|
31
|
+
* Map Google Places state to ISO region (proven 100% success rate)
|
|
32
|
+
*/
|
|
33
|
+
static mapGoogleToISO(googleState: string, googleStateLong: string, countryCode: string, language?: SupportedLanguage): ISORegion | null;
|
|
34
|
+
/**
|
|
35
|
+
* Check if language is registered
|
|
36
|
+
*/
|
|
37
|
+
static isLanguageRegistered(language: SupportedLanguage): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Get registered languages
|
|
40
|
+
*/
|
|
41
|
+
static getRegisteredLanguages(): SupportedLanguage[];
|
|
42
|
+
/**
|
|
43
|
+
* Import language data
|
|
44
|
+
*/
|
|
45
|
+
static importLanguage(language: SupportedLanguage): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Get available languages for ISO data
|
|
48
|
+
*/
|
|
49
|
+
static getAvailableLanguages(): SupportedLanguage[];
|
|
50
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISO Data Core
|
|
3
|
+
* Pure functions for country and region data management
|
|
4
|
+
* Uses the existing iso3166 data functions
|
|
5
|
+
*/
|
|
6
|
+
// Import the pre-built ISO data functions
|
|
7
|
+
import { getCountries, getStatesForCountry, importLanguage, isLanguageRegistered, getRegisteredLanguages } from '../../data/iso3166';
|
|
8
|
+
export class ISODataCore {
|
|
9
|
+
/**
|
|
10
|
+
* Get countries data for a specific language
|
|
11
|
+
*/
|
|
12
|
+
static getCountriesData(language = 'en') {
|
|
13
|
+
try {
|
|
14
|
+
// Get countries from pre-built data with language support
|
|
15
|
+
const countriesArray = getCountries(language);
|
|
16
|
+
// Transform to our expected format (Record<string, ISOCountry>)
|
|
17
|
+
const countries = {};
|
|
18
|
+
countriesArray.forEach((country) => {
|
|
19
|
+
countries[country.code] = {
|
|
20
|
+
iso: country.code,
|
|
21
|
+
iso3: country.iso3 || '',
|
|
22
|
+
numeric: country.numeric || 0,
|
|
23
|
+
name: country.name,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return countries;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(`Failed to load ISO data for language: ${language}`, error);
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get regions for a specific country
|
|
35
|
+
*/
|
|
36
|
+
static getRegions(countryCode, language = 'en') {
|
|
37
|
+
try {
|
|
38
|
+
const states = getStatesForCountry(countryCode, language);
|
|
39
|
+
return states.map((state) => ({
|
|
40
|
+
iso: state.code,
|
|
41
|
+
name: state.name,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return []; // Return empty array if no regions
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Find a specific region by ISO code
|
|
50
|
+
*/
|
|
51
|
+
static findRegion(countryCode, regionCode, language = 'en') {
|
|
52
|
+
const regions = this.getRegions(countryCode, language);
|
|
53
|
+
return regions.find((region) => region.iso === regionCode) ?? null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Map Google Places state to ISO region (proven 100% success rate)
|
|
57
|
+
*/
|
|
58
|
+
static mapGoogleToISO(googleState, googleStateLong, countryCode, language = 'en') {
|
|
59
|
+
const regions = this.getRegions(countryCode, language);
|
|
60
|
+
if (regions.length === 0)
|
|
61
|
+
return null;
|
|
62
|
+
// Strategy 1: Exact ISO code match (86% success rate)
|
|
63
|
+
let match = regions.find((r) => r.iso === googleState);
|
|
64
|
+
if (match)
|
|
65
|
+
return match;
|
|
66
|
+
// Strategy 2: Name matching (14% success rate)
|
|
67
|
+
match = regions.find((r) => r.name.toLowerCase() === googleState.toLowerCase());
|
|
68
|
+
if (match)
|
|
69
|
+
return match;
|
|
70
|
+
match = regions.find((r) => r.name.toLowerCase() === googleStateLong.toLowerCase());
|
|
71
|
+
if (match)
|
|
72
|
+
return match;
|
|
73
|
+
// Strategy 3: Partial name matching (fallback)
|
|
74
|
+
match = regions.find((r) => r.name.toLowerCase().includes(googleStateLong.toLowerCase()) ||
|
|
75
|
+
googleStateLong.toLowerCase().includes(r.name.toLowerCase()));
|
|
76
|
+
return match ?? null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if language is registered
|
|
80
|
+
*/
|
|
81
|
+
static isLanguageRegistered(language) {
|
|
82
|
+
return isLanguageRegistered(language);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get registered languages
|
|
86
|
+
*/
|
|
87
|
+
static getRegisteredLanguages() {
|
|
88
|
+
return getRegisteredLanguages();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Import language data
|
|
92
|
+
*/
|
|
93
|
+
static async importLanguage(language) {
|
|
94
|
+
return importLanguage(language);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get available languages for ISO data
|
|
98
|
+
*/
|
|
99
|
+
static getAvailableLanguages() {
|
|
100
|
+
// Return all available languages (not just registered ones)
|
|
101
|
+
return ['en', 'ru', 'de', 'fr', 'es', 'zh', 'hi', 'pt', 'ja', 'ar', 'it', 'he'];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base API Client using Axios
|
|
3
|
+
* Shared between all resource clients
|
|
4
|
+
*/
|
|
5
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
6
|
+
export interface ApiClientConfig {
|
|
7
|
+
baseURL: string;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class ApiClient {
|
|
12
|
+
axios: AxiosInstance;
|
|
13
|
+
private currentToken;
|
|
14
|
+
constructor(config: ApiClientConfig);
|
|
15
|
+
get<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
16
|
+
post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
17
|
+
put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
18
|
+
patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
19
|
+
delete<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
20
|
+
setHeader(key: string, value: string): void;
|
|
21
|
+
removeHeader(key: string): void;
|
|
22
|
+
updateToken(token: string | null): void;
|
|
23
|
+
getCurrentToken(): string | null;
|
|
24
|
+
updateConfig(config: Partial<ApiClientConfig>): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base API Client using Axios
|
|
3
|
+
* Shared between all resource clients
|
|
4
|
+
*/
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
export class ApiClient {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.currentToken = null;
|
|
9
|
+
this.axios = axios.create({
|
|
10
|
+
baseURL: config.baseURL,
|
|
11
|
+
timeout: config.timeout || 30000,
|
|
12
|
+
headers: {
|
|
13
|
+
'Content-Type': 'application/json',
|
|
14
|
+
...config.headers,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
// Request interceptor for logging and auth
|
|
18
|
+
this.axios.interceptors.request.use((config) => {
|
|
19
|
+
console.log(`[SDK] Making ${config.method?.toUpperCase()} request to: ${config.baseURL}${config.url}`);
|
|
20
|
+
console.log('[SDK] Request headers:', config.headers);
|
|
21
|
+
if (config.data) {
|
|
22
|
+
console.log('[SDK] Request body:', config.data);
|
|
23
|
+
}
|
|
24
|
+
return config;
|
|
25
|
+
}, (error) => {
|
|
26
|
+
console.error('[SDK] Request error:', error);
|
|
27
|
+
return Promise.reject(error instanceof Error ? error : new Error(String(error)));
|
|
28
|
+
});
|
|
29
|
+
// Response interceptor for logging
|
|
30
|
+
this.axios.interceptors.response.use((response) => {
|
|
31
|
+
console.log('[SDK] Response status:', response.status);
|
|
32
|
+
console.log('[SDK] Response data:', response.data);
|
|
33
|
+
return response;
|
|
34
|
+
}, (error) => {
|
|
35
|
+
console.error('[SDK] Response error:', error);
|
|
36
|
+
return Promise.reject(error instanceof Error ? error : new Error(String(error)));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// Convenience methods
|
|
40
|
+
async get(url, config) {
|
|
41
|
+
const response = await this.axios.get(url, config);
|
|
42
|
+
return response.data;
|
|
43
|
+
}
|
|
44
|
+
async post(url, data, config) {
|
|
45
|
+
const response = await this.axios.post(url, data, config);
|
|
46
|
+
return response.data;
|
|
47
|
+
}
|
|
48
|
+
async put(url, data, config) {
|
|
49
|
+
const response = await this.axios.put(url, data, config);
|
|
50
|
+
return response.data;
|
|
51
|
+
}
|
|
52
|
+
async patch(url, data, config) {
|
|
53
|
+
const response = await this.axios.patch(url, data, config);
|
|
54
|
+
return response.data;
|
|
55
|
+
}
|
|
56
|
+
async delete(url, config) {
|
|
57
|
+
const response = await this.axios.delete(url, config);
|
|
58
|
+
return response.data;
|
|
59
|
+
}
|
|
60
|
+
// Update headers (useful for auth tokens)
|
|
61
|
+
setHeader(key, value) {
|
|
62
|
+
this.axios.defaults.headers.common[key] = value;
|
|
63
|
+
}
|
|
64
|
+
removeHeader(key) {
|
|
65
|
+
delete this.axios.defaults.headers.common[key];
|
|
66
|
+
}
|
|
67
|
+
// Token management methods (matching old ApiService pattern)
|
|
68
|
+
updateToken(token) {
|
|
69
|
+
this.currentToken = token;
|
|
70
|
+
if (token) {
|
|
71
|
+
this.setHeader('x-cms-token', token);
|
|
72
|
+
console.log('[SDK] Token updated in ApiClient:', token.substring(0, 8) + '...');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.removeHeader('x-cms-token');
|
|
76
|
+
console.log('[SDK] Token removed from ApiClient');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
getCurrentToken() {
|
|
80
|
+
return this.currentToken;
|
|
81
|
+
}
|
|
82
|
+
// Update configuration (useful for environment changes)
|
|
83
|
+
updateConfig(config) {
|
|
84
|
+
if (config.baseURL) {
|
|
85
|
+
this.axios.defaults.baseURL = config.baseURL;
|
|
86
|
+
}
|
|
87
|
+
if (config.timeout) {
|
|
88
|
+
this.axios.defaults.timeout = config.timeout;
|
|
89
|
+
}
|
|
90
|
+
if (config.headers) {
|
|
91
|
+
Object.assign(this.axios.defaults.headers.common, config.headers);
|
|
92
|
+
}
|
|
93
|
+
console.log('[SDK] ApiClient configuration updated');
|
|
94
|
+
}
|
|
95
|
+
}
|