@tagadapay/plugin-sdk 2.6.18 → 2.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/react/hooks/usePluginConfig.js +15 -7
  2. package/dist/v2/core/index.d.ts +1 -0
  3. package/dist/v2/core/index.js +2 -0
  4. package/dist/v2/core/pathRemapping.d.ts +156 -0
  5. package/dist/v2/core/pathRemapping.js +440 -0
  6. package/dist/v2/core/resources/credits.d.ts +42 -0
  7. package/dist/v2/core/resources/credits.js +21 -0
  8. package/dist/v2/core/resources/customer.d.ts +150 -0
  9. package/dist/v2/core/resources/customer.js +53 -0
  10. package/dist/v2/core/resources/index.d.ts +4 -1
  11. package/dist/v2/core/resources/index.js +4 -1
  12. package/dist/v2/core/resources/session.d.ts +27 -0
  13. package/dist/v2/core/resources/session.js +56 -0
  14. package/dist/v2/core/utils/pluginConfig.d.ts +14 -0
  15. package/dist/v2/core/utils/pluginConfig.js +96 -29
  16. package/dist/v2/index.d.ts +11 -2
  17. package/dist/v2/index.js +3 -1
  18. package/dist/v2/react/hooks/useAuth.d.ts +8 -0
  19. package/dist/v2/react/hooks/useAuth.js +9 -0
  20. package/dist/v2/react/hooks/useClubOffers.d.ts +101 -0
  21. package/dist/v2/react/hooks/useClubOffers.js +126 -0
  22. package/dist/v2/react/hooks/useCredits.d.ts +67 -0
  23. package/dist/v2/react/hooks/useCredits.js +80 -0
  24. package/dist/v2/react/hooks/useCustomer.d.ts +11 -0
  25. package/dist/v2/react/hooks/useCustomer.js +11 -0
  26. package/dist/v2/react/hooks/useCustomerInfos.d.ts +12 -0
  27. package/dist/v2/react/hooks/useCustomerInfos.js +53 -0
  28. package/dist/v2/react/hooks/useCustomerOrders.d.ts +17 -0
  29. package/dist/v2/react/hooks/useCustomerOrders.js +51 -0
  30. package/dist/v2/react/hooks/useCustomerSubscriptions.d.ts +23 -0
  31. package/dist/v2/react/hooks/useCustomerSubscriptions.js +94 -0
  32. package/dist/v2/react/hooks/useLogin.d.ts +53 -0
  33. package/dist/v2/react/hooks/useLogin.js +75 -0
  34. package/dist/v2/react/hooks/useTranslation.d.ts +40 -3
  35. package/dist/v2/react/hooks/useTranslation.js +128 -16
  36. package/dist/v2/react/index.d.ts +18 -1
  37. package/dist/v2/react/index.js +9 -0
  38. package/package.json +2 -1
  39. package/dist/v2/react/hooks/useDiscountQuery.d.ts +0 -79
  40. package/dist/v2/react/hooks/useDiscountQuery.js +0 -24
@@ -0,0 +1,53 @@
1
+ export interface UseLoginOptions {
2
+ /**
3
+ * Callback when login is successful
4
+ */
5
+ onSuccess?: (token: string) => void;
6
+ /**
7
+ * Callback when an error occurs
8
+ */
9
+ onError?: (error: Error) => void;
10
+ }
11
+ export interface UseLoginResult {
12
+ /**
13
+ * Request verification code for email
14
+ */
15
+ requestCode: (email: string) => Promise<{
16
+ success: boolean;
17
+ error?: string;
18
+ }>;
19
+ /**
20
+ * Verify code and complete login
21
+ */
22
+ verifyCode: (email: string, code: string) => Promise<{
23
+ success: boolean;
24
+ token?: string;
25
+ sessionId?: string;
26
+ error?: string;
27
+ }>;
28
+ /**
29
+ * Combined loading state (true if either request or verify is loading)
30
+ */
31
+ isLoading: boolean;
32
+ /**
33
+ * Loading state for request code
34
+ */
35
+ isRequestingCode: boolean;
36
+ /**
37
+ * Loading state for verify code
38
+ */
39
+ isVerifyingCode: boolean;
40
+ /**
41
+ * Combined error state
42
+ */
43
+ error: Error | null;
44
+ /**
45
+ * Error from request code
46
+ */
47
+ requestCodeError: Error | null;
48
+ /**
49
+ * Error from verify code
50
+ */
51
+ verifyCodeError: Error | null;
52
+ }
53
+ export declare function useLogin(options?: UseLoginOptions): UseLoginResult;
@@ -0,0 +1,75 @@
1
+ 'use client';
2
+ /**
3
+ * useLogin - Hook for authentication (v2)
4
+ * Handles email/code authentication flow
5
+ */
6
+ import { useMutation } from '@tanstack/react-query';
7
+ import { useCallback, useMemo } from 'react';
8
+ import { setClientToken } from '../../../react/utils/tokenStorage';
9
+ import { SessionResource } from '../../core/resources/session';
10
+ import { getGlobalApiClient } from './useApiQuery';
11
+ import { usePluginConfig } from './usePluginConfig';
12
+ export function useLogin(options = {}) {
13
+ const { onSuccess, onError } = options;
14
+ const { storeId } = usePluginConfig();
15
+ // Create session resource client
16
+ const sessionResource = useMemo(() => {
17
+ try {
18
+ return new SessionResource(getGlobalApiClient());
19
+ }
20
+ catch (error) {
21
+ throw new Error('Failed to initialize session resource: ' +
22
+ (error instanceof Error ? error.message : 'Unknown error'));
23
+ }
24
+ }, []);
25
+ // Request code mutation
26
+ const requestCodeMutation = useMutation({
27
+ mutationFn: async (email) => {
28
+ if (!storeId) {
29
+ throw new Error('Store ID not found. Make sure the TagadaProvider is properly configured.');
30
+ }
31
+ return await sessionResource.requestCode(email, storeId);
32
+ },
33
+ onError: (error) => {
34
+ console.error('[SDK] Failed to request code:', error);
35
+ onError?.(error);
36
+ },
37
+ });
38
+ // Verify code mutation
39
+ const verifyCodeMutation = useMutation({
40
+ mutationFn: async ({ email, code }) => {
41
+ if (!storeId) {
42
+ throw new Error('Store ID not found. Make sure the TagadaProvider is properly configured.');
43
+ }
44
+ const result = await sessionResource.verifyCode(email, code, storeId);
45
+ if (result.success && result.token) {
46
+ // Store the token
47
+ setClientToken(result.token);
48
+ // Call success callback
49
+ onSuccess?.(result.token);
50
+ }
51
+ return result;
52
+ },
53
+ onError: (error) => {
54
+ console.error('[SDK] Failed to verify code:', error);
55
+ onError?.(error);
56
+ },
57
+ });
58
+ // Action functions
59
+ const requestCode = useCallback(async (email) => {
60
+ return await requestCodeMutation.mutateAsync(email);
61
+ }, [requestCodeMutation]);
62
+ const verifyCode = useCallback(async (email, code) => {
63
+ return await verifyCodeMutation.mutateAsync({ email, code });
64
+ }, [verifyCodeMutation]);
65
+ return {
66
+ requestCode,
67
+ verifyCode,
68
+ isLoading: requestCodeMutation.isPending || verifyCodeMutation.isPending,
69
+ isRequestingCode: requestCodeMutation.isPending,
70
+ isVerifyingCode: verifyCodeMutation.isPending,
71
+ error: requestCodeMutation.error || verifyCodeMutation.error,
72
+ requestCodeError: requestCodeMutation.error,
73
+ verifyCodeError: verifyCodeMutation.error,
74
+ };
75
+ }
@@ -1,3 +1,4 @@
1
+ import { ReactNode } from 'react';
1
2
  import { LanguageCode } from '../../../data/languages';
2
3
  export type TranslationText = {
3
4
  [key in LanguageCode | string]?: string;
@@ -5,14 +6,22 @@ export type TranslationText = {
5
6
  export interface UseTranslationOptions {
6
7
  defaultLanguage?: string;
7
8
  }
8
- export type TranslateFunction = (text: TranslationText | string | undefined, fallback?: string, languageCode?: string) => string;
9
+ export type TranslationParams = {
10
+ [key: string]: string | number | ((children: ReactNode) => ReactNode);
11
+ };
12
+ export interface TranslateFunction {
13
+ (text: TranslationText | string | undefined, fallback?: string): string;
14
+ (text: TranslationText | string | undefined, fallback: string | undefined, params: undefined, languageCode: string): string;
15
+ (text: TranslationText | string | undefined, fallback?: string, params?: TranslationParams, languageCode?: string): string | ReactNode;
16
+ }
9
17
  export interface UseTranslationResult {
10
18
  /**
11
19
  * Translate function that handles multi-language text objects
12
20
  * @param text - The text to translate (can be a string or MultiLangText object)
13
21
  * @param fallback - Optional fallback text if translation is not found
22
+ * @param params - Optional parameters for string interpolation (e.g., {count: 10} for 'User has {count} points') or tag wrapping with functions (e.g., {i: (val) => <b>{val}</b>} for '<i>text</i>')
14
23
  * @param languageCode - Optional language code to override the current locale
15
- * @returns The translated string
24
+ * @returns The translated string or ReactNode (when using function params for tag wrapping)
16
25
  */
17
26
  t: TranslateFunction;
18
27
  /**
@@ -39,8 +48,36 @@ export interface UseTranslationResult {
39
48
  * // With fallback
40
49
  * const withFallback = t(multiLangText, 'Default text');
41
50
  *
51
+ * // With params interpolation
52
+ * const withParams = t('User has {count} points', '', { count: 10 });
53
+ * // Result: 'User has 10 points'
54
+ *
55
+ * // Escaped brackets are treated as literal text
56
+ * const escaped = t('Use \\{count\\} as placeholder', '', { count: 10 });
57
+ * // Result: 'Use {count} as placeholder'
58
+ *
59
+ * // With function params for tag wrapping
60
+ * const withTags = t('This is <i>formatted</i>', '', {
61
+ * i: (value) => <b>{value}</b>
62
+ * });
63
+ * // Result: ReactNode with <b>formatted</b>
64
+ *
65
+ * // Escaped tags are treated as literal text
66
+ * const escapedTags = t('This is \\<i>not formatted\\</i>', '', {
67
+ * i: (value) => <b>{value}</b>
68
+ * });
69
+ * // Result: 'This is <i>not formatted</i>'
70
+ *
71
+ * // Mix of placeholders and tags
72
+ * const mixed = t('User {name} has <b>{count}</b> points', '', {
73
+ * name: 'John',
74
+ * count: 10,
75
+ * b: (value) => <strong>{value}</strong>
76
+ * });
77
+ * // Result: ReactNode with 'User John has <strong>10</strong> points'
78
+ *
42
79
  * // Override locale
43
- * const inFrench = t(multiLangText, '', 'fr');
80
+ * const inFrench = t(multiLangText, '', undefined, 'fr');
44
81
  * ```
45
82
  */
46
83
  export declare const useTranslation: (options?: UseTranslationOptions) => UseTranslationResult;
@@ -1,4 +1,4 @@
1
- import { useCallback, useMemo } from 'react';
1
+ import React, { useCallback, useMemo } from 'react';
2
2
  /**
3
3
  * Hook for translating multi-language text objects
4
4
  *
@@ -18,8 +18,36 @@ import { useCallback, useMemo } from 'react';
18
18
  * // With fallback
19
19
  * const withFallback = t(multiLangText, 'Default text');
20
20
  *
21
+ * // With params interpolation
22
+ * const withParams = t('User has {count} points', '', { count: 10 });
23
+ * // Result: 'User has 10 points'
24
+ *
25
+ * // Escaped brackets are treated as literal text
26
+ * const escaped = t('Use \\{count\\} as placeholder', '', { count: 10 });
27
+ * // Result: 'Use {count} as placeholder'
28
+ *
29
+ * // With function params for tag wrapping
30
+ * const withTags = t('This is <i>formatted</i>', '', {
31
+ * i: (value) => <b>{value}</b>
32
+ * });
33
+ * // Result: ReactNode with <b>formatted</b>
34
+ *
35
+ * // Escaped tags are treated as literal text
36
+ * const escapedTags = t('This is \\<i>not formatted\\</i>', '', {
37
+ * i: (value) => <b>{value}</b>
38
+ * });
39
+ * // Result: 'This is <i>not formatted</i>'
40
+ *
41
+ * // Mix of placeholders and tags
42
+ * const mixed = t('User {name} has <b>{count}</b> points', '', {
43
+ * name: 'John',
44
+ * count: 10,
45
+ * b: (value) => <strong>{value}</strong>
46
+ * });
47
+ * // Result: ReactNode with 'User John has <strong>10</strong> points'
48
+ *
21
49
  * // Override locale
22
- * const inFrench = t(multiLangText, '', 'fr');
50
+ * const inFrench = t(multiLangText, '', undefined, 'fr');
23
51
  * ```
24
52
  */
25
53
  export const useTranslation = (options = {}) => {
@@ -29,7 +57,7 @@ export const useTranslation = (options = {}) => {
29
57
  // Check for language query parameter
30
58
  if (typeof window !== 'undefined') {
31
59
  const urlParams = new URLSearchParams(window.location.search);
32
- const langFromQuery = urlParams.get('language');
60
+ const langFromQuery = urlParams.get('locale');
33
61
  if (langFromQuery)
34
62
  return langFromQuery;
35
63
  }
@@ -40,22 +68,106 @@ export const useTranslation = (options = {}) => {
40
68
  }
41
69
  return defaultLanguage;
42
70
  }, [defaultLanguage]);
43
- const t = useCallback((text, fallback, languageCode) => {
71
+ const t = useCallback((text, fallback, params, languageCode) => {
72
+ // Helper function to interpolate params into the translated string
73
+ const interpolate = (str, params) => {
74
+ if (!params) {
75
+ // Even without params, we need to unescape any escaped characters
76
+ return str.replace(/\\([{}<>])/g, '$1');
77
+ }
78
+ // First, process tag-based interpolation for functions
79
+ // Match tags like <i>content</i> but not \<i>content</i>
80
+ const tagRegex = /(?<!\\)<(\w+)>(.*?)(?<!\\)<\/\1>/g;
81
+ const hasTags = tagRegex.test(str);
82
+ if (hasTags) {
83
+ // Reset regex lastIndex for reuse
84
+ tagRegex.lastIndex = 0;
85
+ const parts = [];
86
+ let lastIndex = 0;
87
+ let match;
88
+ let hasReactNodes = false;
89
+ while ((match = tagRegex.exec(str)) !== null) {
90
+ const [fullMatch, tagName, content] = match;
91
+ const param = params[tagName];
92
+ // Add text before the match
93
+ if (match.index > lastIndex) {
94
+ parts.push(str.substring(lastIndex, match.index));
95
+ }
96
+ // If param is a function, call it with the content
97
+ if (typeof param === 'function') {
98
+ parts.push(param(content));
99
+ hasReactNodes = true;
100
+ }
101
+ else {
102
+ // If not a function, keep the original tag
103
+ parts.push(fullMatch);
104
+ }
105
+ lastIndex = match.index + fullMatch.length;
106
+ }
107
+ // Add remaining text after last match
108
+ if (lastIndex < str.length) {
109
+ parts.push(str.substring(lastIndex));
110
+ }
111
+ // If we have React nodes, process placeholder interpolation for each string part
112
+ if (hasReactNodes) {
113
+ const processedParts = parts.map((part, index) => {
114
+ if (typeof part === 'string') {
115
+ // Process {key} placeholders in string parts
116
+ let processed = Object.entries(params).reduce((acc, [key, value]) => {
117
+ if (typeof value !== 'function') {
118
+ const regex = new RegExp(`(?<!\\\\)\\{${key}\\}`, 'g');
119
+ return acc.replace(regex, String(value));
120
+ }
121
+ return acc;
122
+ }, part);
123
+ // Unescape escaped characters
124
+ processed = processed.replace(/\\([{}<>])/g, '$1');
125
+ return processed;
126
+ }
127
+ return part;
128
+ });
129
+ // If only one part and it's a string, return as string
130
+ if (processedParts.length === 1 && typeof processedParts[0] === 'string') {
131
+ return processedParts[0];
132
+ }
133
+ // Return array of React nodes
134
+ return processedParts.map((part, index) => typeof part === 'string' ? part : React.createElement('span', { key: index }, part));
135
+ }
136
+ // If no React nodes, continue with normal string processing
137
+ str = parts.join('');
138
+ }
139
+ // Process {key} placeholders for string/number values
140
+ let result = Object.entries(params).reduce((acc, [key, value]) => {
141
+ if (typeof value !== 'function') {
142
+ const regex = new RegExp(`(?<!\\\\)\\{${key}\\}`, 'g');
143
+ return acc.replace(regex, String(value));
144
+ }
145
+ return acc;
146
+ }, str);
147
+ // Remove escape characters from escaped characters (\{ -> {, \} -> }, \< -> <, \> -> >)
148
+ result = result.replace(/\\([{}<>])/g, '$1');
149
+ return result;
150
+ };
44
151
  if (!text)
45
- return fallback || '';
152
+ return interpolate(fallback || '', params);
46
153
  if (typeof text === 'string')
47
- return text;
154
+ return interpolate(text, params);
48
155
  const targetLocale = languageCode || locale;
49
- if (text[targetLocale])
50
- return text[targetLocale];
51
- if (fallback)
52
- return fallback;
53
- if (text[defaultLanguage])
54
- return text[defaultLanguage];
55
- const firstAvailable = Object.values(text).find((value) => value !== undefined && value !== '');
56
- if (firstAvailable)
57
- return firstAvailable;
58
- return '';
156
+ let translatedText = '';
157
+ if (text[targetLocale]) {
158
+ translatedText = text[targetLocale];
159
+ }
160
+ else if (fallback) {
161
+ translatedText = fallback;
162
+ }
163
+ else if (text[defaultLanguage]) {
164
+ translatedText = text[defaultLanguage];
165
+ }
166
+ else {
167
+ const firstAvailable = Object.values(text).find((value) => value !== undefined && value !== '');
168
+ translatedText = firstAvailable || '';
169
+ }
170
+ return interpolate(translatedText, params);
59
171
  }, [locale, defaultLanguage]);
60
172
  return { t, locale };
61
173
  };
@@ -6,11 +6,19 @@ export { ExpressPaymentMethodsProvider } from './providers/ExpressPaymentMethods
6
6
  export { TagadaProvider, useTagadaContext } from './providers/TagadaProvider';
7
7
  export { ApplePayButton } from './components/ApplePayButton';
8
8
  export { GooglePayButton } from './components/GooglePayButton';
9
+ export { useAuth } from './hooks/useAuth';
9
10
  export { useCheckoutToken } from './hooks/useCheckoutToken';
11
+ export { useClubOffers } from './hooks/useClubOffers';
12
+ export { useCredits } from './hooks/useCredits';
13
+ export { useCustomer } from './hooks/useCustomer';
14
+ export { useCustomerInfos } from './hooks/useCustomerInfos';
15
+ export { useCustomerOrders } from './hooks/useCustomerOrders';
16
+ export { useCustomerSubscriptions } from './hooks/useCustomerSubscriptions';
10
17
  export { useExpressPaymentMethods } from './hooks/useExpressPaymentMethods';
11
18
  export { useGeoLocation } from './hooks/useGeoLocation';
12
19
  export { useGoogleAutocomplete } from './hooks/useGoogleAutocomplete';
13
20
  export { getAvailableLanguages, useCountryOptions, useISOData, useLanguageImport, useRegionOptions } from './hooks/useISOData';
21
+ export { useLogin } from './hooks/useLogin';
14
22
  export { usePluginConfig } from './hooks/usePluginConfig';
15
23
  export { queryKeys, useApiMutation, useApiQuery, useInvalidateQuery, usePreloadQuery } from './hooks/useApiQuery';
16
24
  export { useCheckoutQuery as useCheckout } from './hooks/useCheckoutQuery';
@@ -27,18 +35,28 @@ export { useShippingRatesQuery as useShippingRates } from './hooks/useShippingRa
27
35
  export { useStoreConfigQuery as useStoreConfig } from './hooks/useStoreConfigQuery';
28
36
  export { useThreeds } from './hooks/useThreeds';
29
37
  export { useThreedsModal } from './hooks/useThreedsModal';
38
+ export { useTranslation } from './hooks/useTranslation';
30
39
  export { useVipOffersQuery as useVipOffers } from './hooks/useVipOffersQuery';
31
40
  export { useFunnel, useSimpleFunnel } from './hooks/useFunnel';
32
41
  export type { UseCheckoutTokenOptions, UseCheckoutTokenResult } from './hooks/useCheckoutToken';
42
+ export type { ClubOffer, ClubOfferItem, ClubOfferLineItem, ClubOfferSummary, UseClubOffersOptions, UseClubOffersResult } from './hooks/useClubOffers';
43
+ export type { UseCreditsOptions, UseCreditsResult } from './hooks/useCredits';
44
+ export type { UseCustomerResult } from './hooks/useCustomer';
45
+ export type { UseCustomerInfosOptions, UseCustomerInfosResult } from './hooks/useCustomerInfos';
46
+ export type { UseCustomerOrdersOptions, UseCustomerOrdersResult } from './hooks/useCustomerOrders';
47
+ export type { UseCustomerSubscriptionsOptions, UseCustomerSubscriptionsResult } from './hooks/useCustomerSubscriptions';
33
48
  export type { ExpressPaymentMethodsContextType, ExpressPaymentMethodsProviderProps } from './hooks/useExpressPaymentMethods';
49
+ export type { UseLoginOptions, UseLoginResult } from './hooks/useLogin';
34
50
  export type { ApplePayButtonProps } from './components/ApplePayButton';
35
51
  export type { GooglePayButtonProps } from './components/GooglePayButton';
36
52
  export type { GeoLocationData, UseGeoLocationOptions, UseGeoLocationReturn } from './hooks/useGeoLocation';
37
53
  export type { ExtractedAddress, GooglePlaceDetails, GooglePrediction, UseGoogleAutocompleteOptions, UseGoogleAutocompleteResult } from './hooks/useGoogleAutocomplete';
38
54
  export type { ISOCountry, ISORegion, UseISODataResult } from './hooks/useISOData';
39
55
  export type { UsePluginConfigOptions, UsePluginConfigResult } from './hooks/usePluginConfig';
56
+ export type { TranslateFunction, UseTranslationOptions, UseTranslationResult } from './hooks/useTranslation';
40
57
  export type { UseCheckoutQueryOptions as UseCheckoutOptions, UseCheckoutQueryResult as UseCheckoutResult } from './hooks/useCheckoutQuery';
41
58
  export type { UseDiscountsQueryOptions as UseDiscountsOptions, UseDiscountsQueryResult as UseDiscountsResult } from './hooks/useDiscountsQuery';
59
+ export type { FunnelEvent, FunnelNavigationAction, FunnelNavigationResult, SimpleFunnelContext, UseFunnelOptions, UseFunnelResult } from './hooks/useFunnel';
42
60
  export type { UseOffersQueryOptions as UseOffersOptions, UseOffersQueryResult as UseOffersResult } from './hooks/useOffersQuery';
43
61
  export type { UseOrderBumpQueryOptions as UseOrderBumpOptions, UseOrderBumpQueryResult as UseOrderBumpResult } from './hooks/useOrderBumpQuery';
44
62
  export type { UseOrderQueryOptions as UseOrderOptions, UseOrderQueryResult as UseOrderResult } from './hooks/useOrderQuery';
@@ -50,6 +68,5 @@ export type { UseShippingRatesQueryOptions as UseShippingRatesOptions, UseShippi
50
68
  export type { UseStoreConfigQueryOptions as UseStoreConfigOptions, UseStoreConfigQueryResult as UseStoreConfigResult } from './hooks/useStoreConfigQuery';
51
69
  export type { PaymentInstrument, ThreedsChallenge, ThreedsHook, ThreedsOptions, ThreedsProvider, ThreedsSession } from './hooks/useThreeds';
52
70
  export type { UseVipOffersQueryOptions as UseVipOffersOptions, UseVipOffersQueryResult as UseVipOffersResult } from './hooks/useVipOffersQuery';
53
- export type { UseFunnelOptions, UseFunnelResult, FunnelEvent, FunnelNavigationAction, FunnelNavigationResult, SimpleFunnelContext } from './hooks/useFunnel';
54
71
  export { formatMoney } from '../../react/utils/money';
55
72
  export type OrderItem = import('../core/utils/order').OrderLineItem;
@@ -9,11 +9,19 @@ export { TagadaProvider, useTagadaContext } from './providers/TagadaProvider';
9
9
  export { ApplePayButton } from './components/ApplePayButton';
10
10
  export { GooglePayButton } from './components/GooglePayButton';
11
11
  // Hooks
12
+ export { useAuth } from './hooks/useAuth';
12
13
  export { useCheckoutToken } from './hooks/useCheckoutToken';
14
+ export { useClubOffers } from './hooks/useClubOffers';
15
+ export { useCredits } from './hooks/useCredits';
16
+ export { useCustomer } from './hooks/useCustomer';
17
+ export { useCustomerInfos } from './hooks/useCustomerInfos';
18
+ export { useCustomerOrders } from './hooks/useCustomerOrders';
19
+ export { useCustomerSubscriptions } from './hooks/useCustomerSubscriptions';
13
20
  export { useExpressPaymentMethods } from './hooks/useExpressPaymentMethods';
14
21
  export { useGeoLocation } from './hooks/useGeoLocation';
15
22
  export { useGoogleAutocomplete } from './hooks/useGoogleAutocomplete';
16
23
  export { getAvailableLanguages, useCountryOptions, useISOData, useLanguageImport, useRegionOptions } from './hooks/useISOData';
24
+ export { useLogin } from './hooks/useLogin';
17
25
  export { usePluginConfig } from './hooks/usePluginConfig';
18
26
  // TanStack Query hooks (recommended)
19
27
  export { queryKeys, useApiMutation, useApiQuery, useInvalidateQuery, usePreloadQuery } from './hooks/useApiQuery';
@@ -31,6 +39,7 @@ export { useShippingRatesQuery as useShippingRates } from './hooks/useShippingRa
31
39
  export { useStoreConfigQuery as useStoreConfig } from './hooks/useStoreConfigQuery';
32
40
  export { useThreeds } from './hooks/useThreeds';
33
41
  export { useThreedsModal } from './hooks/useThreedsModal';
42
+ export { useTranslation } from './hooks/useTranslation';
34
43
  export { useVipOffersQuery as useVipOffers } from './hooks/useVipOffersQuery';
35
44
  // Funnel hooks
36
45
  export { useFunnel, useSimpleFunnel } from './hooks/useFunnel';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.6.18",
3
+ "version": "2.7.2",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -63,6 +63,7 @@
63
63
  "@tanstack/react-query": "^5.90.2",
64
64
  "axios": "^1.10.0",
65
65
  "iso3166-2-db": "^2.3.11",
66
+ "path-to-regexp": "^8.2.0",
66
67
  "react-intl": "^7.1.11",
67
68
  "swr": "^2.3.6"
68
69
  },
@@ -1,79 +0,0 @@
1
- /**
2
- * Single Discount Hook using TanStack Query
3
- * Fetches a specific discount for a given store
4
- */
5
- import { UseQueryResult } from '@tanstack/react-query';
6
- export interface StoreDiscountRuleAmount {
7
- rate: number;
8
- amount: number;
9
- lock: boolean;
10
- date: string;
11
- }
12
- export interface StoreDiscountRule {
13
- id: string;
14
- createdAt: string;
15
- updatedAt: string;
16
- promotionId: string;
17
- type: string;
18
- productId: string | null;
19
- minimumQuantity: number | null;
20
- minimumAmount: Record<string, StoreDiscountRuleAmount> | null;
21
- variantIds: string[] | null;
22
- }
23
- export interface StoreDiscountAction {
24
- id: string;
25
- createdAt: string;
26
- updatedAt: string;
27
- promotionId: string;
28
- type: string;
29
- adjustmentAmount: number | null;
30
- adjustmentPercentage: number | null;
31
- adjustmentType: string | null;
32
- freeShipping: boolean | null;
33
- priceIdToAdd: string | null;
34
- productIdToAdd: string | null;
35
- variantIdToAdd: string | null;
36
- subscriptionFreeTrialDuration: number | null;
37
- subscriptionFreeTrialDurationType: string | null;
38
- targetProductId: string | null;
39
- targetVariantIds: string[] | null;
40
- maxQuantityDiscounted: number | null;
41
- appliesOnEachItem: boolean | null;
42
- }
43
- export interface StoreDiscount {
44
- id: string;
45
- createdAt: string;
46
- updatedAt: string;
47
- storeId: string;
48
- accountId: string;
49
- name: string;
50
- code: string;
51
- automatic: boolean;
52
- usageLimit: number | null;
53
- usageCount: number;
54
- startDate: string;
55
- endDate: string | null;
56
- enabled: boolean;
57
- archived: boolean;
58
- ruleOperator: string;
59
- externalId: string | null;
60
- combinesWithOrderLevelDiscounts: boolean;
61
- combinesWithLineItemDiscounts: boolean;
62
- combinesWithShippingDiscounts: boolean;
63
- forceCombine: boolean;
64
- isTemporary: boolean;
65
- rules: StoreDiscountRule[];
66
- actions: StoreDiscountAction[];
67
- }
68
- export interface UseDiscountQueryOptions {
69
- storeId?: string;
70
- discountId?: string;
71
- enabled?: boolean;
72
- }
73
- export interface UseDiscountQueryResult<TData = StoreDiscount> {
74
- discount: TData | undefined;
75
- isLoading: boolean;
76
- error: Error | null;
77
- refetch: UseQueryResult<TData>['refetch'];
78
- }
79
- export declare function useDiscountQuery<TData = StoreDiscount>(options: UseDiscountQueryOptions): UseDiscountQueryResult<TData>;
@@ -1,24 +0,0 @@
1
- /**
2
- * Single Discount Hook using TanStack Query
3
- * Fetches a specific discount for a given store
4
- */
5
- import { useMemo } from 'react';
6
- import { useApiQuery } from './useApiQuery';
7
- import { usePluginConfig } from './usePluginConfig';
8
- export function useDiscountQuery(options) {
9
- const { storeId: storeIdFromConfig } = usePluginConfig();
10
- const { storeId = storeIdFromConfig, discountId, enabled = true } = options;
11
- const key = useMemo(() => ['discount', storeId, discountId], [storeId, discountId]);
12
- const url = useMemo(() => {
13
- if (!storeId || !discountId)
14
- return null;
15
- return `/api/v1/stores/${storeId}/discounts/${discountId}`;
16
- }, [storeId, discountId]);
17
- const query = useApiQuery(key, url, { enabled });
18
- return {
19
- discount: query.data,
20
- isLoading: query.isLoading,
21
- error: query.error || null,
22
- refetch: query.refetch,
23
- };
24
- }