@tagadapay/plugin-sdk 2.6.6 → 2.6.8

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/README.md CHANGED
@@ -15,6 +15,7 @@ A comprehensive React SDK for building plugins on the TagadaPay platform. Create
15
15
  - **[useCheckout (V2)](#usecheckout)** - TanStack Query-based checkout management
16
16
  - **[useOffers (V2)](#useoffers)** - Dynamic pricing with automatic caching
17
17
  - **[useProducts (V2)](#useproducts)** - Product data management
18
+ - **[useStoreConfig (V2)](#usestoreconfig)** - Store configuration with automatic caching
18
19
  - **[usePayment (V2)](#usepayment)** - Payment processing with 3DS support
19
20
  - **[V2 Utility Functions](#v2-utility-functions--advanced-features)** - Enhanced utilities and TanStack Query integration
20
21
 
@@ -708,6 +709,44 @@ const {
708
709
  } = useProducts({ storeId, enabled });
709
710
  ```
710
711
 
712
+ #### useStoreConfig()
713
+
714
+ Hook for fetching store configuration with automatic caching.
715
+
716
+ ```typescript
717
+ const {
718
+ // Query data
719
+ storeConfig, // StoreConfig | undefined
720
+ isLoading, // boolean
721
+ error, // Error | null
722
+ isSuccess, // boolean
723
+
724
+ // Actions
725
+ refetch, // () => Promise<void>
726
+ } = useStoreConfig({ storeId, enabled });
727
+ ```
728
+
729
+ **Example:**
730
+
731
+ ```tsx
732
+ import { useStoreConfig } from '@tagadapay/plugin-sdk/v2';
733
+
734
+ function StoreInfo() {
735
+ const { storeConfig, isLoading } = useStoreConfig();
736
+
737
+ if (isLoading) return <div>Loading...</div>;
738
+
739
+ return (
740
+ <div>
741
+ <h1>{storeConfig?.storeName}</h1>
742
+ <p>Currency: {storeConfig?.currency}</p>
743
+ </div>
744
+ );
745
+ }
746
+ ```
747
+
748
+ See [useStoreConfig documentation](./docs/README-useStoreConfig.md) for more details.
749
+
711
750
  #### useOrder()
712
751
 
713
752
  Hook for order management and tracking.
@@ -12,5 +12,6 @@ export * from './postPurchases';
12
12
  export * from './products';
13
13
  export * from './promotions';
14
14
  export * from './shippingRates';
15
+ export * from './storeConfig';
15
16
  export * from './threeds';
16
17
  export * from './vipOffers';
@@ -12,5 +12,6 @@ export * from './postPurchases';
12
12
  export * from './products';
13
13
  export * from './promotions';
14
14
  export * from './shippingRates';
15
+ export * from './storeConfig';
15
16
  export * from './threeds';
16
17
  export * from './vipOffers';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Store Config Resource Client
3
+ * Axios-based API client for store configuration endpoints
4
+ */
5
+ import { ApiClient } from './apiClient';
6
+ export interface StoreConfig {
7
+ storeId: string;
8
+ storeName?: string;
9
+ storeUrl?: string;
10
+ currency?: string;
11
+ locale?: string;
12
+ timezone?: string;
13
+ [key: string]: any;
14
+ }
15
+ export interface GetStoreConfigOptions {
16
+ storeId: string;
17
+ }
18
+ export declare class StoreConfigResource {
19
+ private apiClient;
20
+ constructor(apiClient: ApiClient);
21
+ /**
22
+ * Get store configuration by store ID
23
+ */
24
+ getStoreConfig(storeId: string): Promise<StoreConfig>;
25
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Store Config Resource Client
3
+ * Axios-based API client for store configuration endpoints
4
+ */
5
+ export class StoreConfigResource {
6
+ constructor(apiClient) {
7
+ this.apiClient = apiClient;
8
+ }
9
+ /**
10
+ * Get store configuration by store ID
11
+ */
12
+ async getStoreConfig(storeId) {
13
+ const response = await this.apiClient.get(`/api/v1/checkout/config?storeId=${storeId}`);
14
+ return response;
15
+ }
16
+ }
@@ -19,4 +19,5 @@ export type { ApplePayToken, CardPaymentMethod, Payment, PaymentInstrumentCustom
19
19
  export type { ShippingRate, ShippingRatesResponse } from './core/resources/shippingRates';
20
20
  export type { ApplyDiscountResponse, Discount, DiscountCodeValidation, RemoveDiscountResponse } from './core/resources/discounts';
21
21
  export type { ToggleOrderBumpResponse, VipOffer, VipPreviewResponse } from './core/resources/vipOffers';
22
- export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscounts, useExpressPaymentMethods, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useTagadaContext, useThreeds, useThreedsModal, useVipOffers } from './react';
22
+ export type { StoreConfig } from './core/resources/storeConfig';
23
+ export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscounts, useExpressPaymentMethods, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useVipOffers } from './react';
package/dist/v2/index.js CHANGED
@@ -12,4 +12,4 @@ export * from './core/utils/currency';
12
12
  export * from './core/utils/pluginConfig';
13
13
  export * from './core/utils/products';
14
14
  // React exports (hooks and components only, types are exported above)
15
- export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscounts, useExpressPaymentMethods, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useTagadaContext, useThreeds, useThreedsModal, useVipOffers } from './react';
15
+ export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscounts, useExpressPaymentMethods, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useVipOffers } from './react';
@@ -16,6 +16,7 @@ export declare const queryKeys: {
16
16
  readonly vipPreview: (sessionId: string, offerIds: string[]) => (string | string[])[];
17
17
  readonly products: (productIds: string[], options?: Record<string, any>) => (string | string[] | Record<string, any> | undefined)[];
18
18
  readonly store: (storeId: string) => string[];
19
+ readonly storeConfig: (storeId: string) => string[];
19
20
  readonly order: (orderId: string) => string[];
20
21
  };
21
22
  export declare function useApiQuery<T = unknown>(key: readonly unknown[], url: string | null, options?: Omit<UseQueryOptions<T>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<import("@tanstack/react-query").NoInfer<T>, Error>;
@@ -27,6 +27,7 @@ export const queryKeys = {
27
27
  vipPreview: (sessionId, offerIds) => ['vip-preview', sessionId, offerIds],
28
28
  products: (productIds, options) => ['products', productIds, options],
29
29
  store: (storeId) => ['store', storeId],
30
+ storeConfig: (storeId) => ['storeConfig', storeId],
30
31
  order: (orderId) => ['order', orderId],
31
32
  };
32
33
  // Main query hook
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Store Config Hook using TanStack Query
3
+ * Fetches store configuration with automatic caching
4
+ */
5
+ import { StoreConfig } from '../../core/resources/storeConfig';
6
+ export interface UseStoreConfigQueryOptions {
7
+ storeId?: string;
8
+ enabled?: boolean;
9
+ }
10
+ export interface UseStoreConfigQueryResult {
11
+ storeConfig: StoreConfig | undefined;
12
+ isLoading: boolean;
13
+ error: Error | null;
14
+ isSuccess: boolean;
15
+ refetch: () => Promise<void>;
16
+ }
17
+ export declare function useStoreConfigQuery(options?: UseStoreConfigQueryOptions): UseStoreConfigQueryResult;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Store Config Hook using TanStack Query
3
+ * Fetches store configuration with automatic caching
4
+ */
5
+ import { useQuery } from '@tanstack/react-query';
6
+ import { useCallback, useMemo } from 'react';
7
+ import { StoreConfigResource } from '../../core/resources/storeConfig';
8
+ import { useTagadaContext } from '../providers/TagadaProvider';
9
+ import { getGlobalApiClient } from './useApiQuery';
10
+ import { usePluginConfig } from './usePluginConfig';
11
+ export function useStoreConfigQuery(options = {}) {
12
+ const { storeId: providedStoreId, enabled = true } = options;
13
+ const { storeId: contextStoreId } = usePluginConfig();
14
+ const { isSessionInitialized } = useTagadaContext();
15
+ // Use provided storeId or fall back to context storeId
16
+ const storeId = providedStoreId || contextStoreId;
17
+ // Create store config resource client
18
+ const storeConfigResource = useMemo(() => {
19
+ try {
20
+ return new StoreConfigResource(getGlobalApiClient());
21
+ }
22
+ catch (error) {
23
+ throw new Error('Failed to initialize store config resource: ' + (error instanceof Error ? error.message : 'Unknown error'));
24
+ }
25
+ }, []);
26
+ // Use TanStack Query for fetching store config
27
+ const { data: storeConfig, isLoading, error, isSuccess, refetch } = useQuery({
28
+ queryKey: ['storeConfig', storeId],
29
+ enabled: enabled && !!storeId && isSessionInitialized,
30
+ queryFn: async () => {
31
+ if (!storeId) {
32
+ throw new Error('Store ID not found. Make sure the TagadaProvider is properly configured.');
33
+ }
34
+ return await storeConfigResource.getStoreConfig(storeId);
35
+ },
36
+ staleTime: 5 * 60 * 1000, // 5 minutes - config doesn't change often
37
+ gcTime: 10 * 60 * 1000, // 10 minutes cache time
38
+ });
39
+ // Refetch function
40
+ const refetchConfig = useCallback(async () => {
41
+ await refetch();
42
+ }, [refetch]);
43
+ return {
44
+ // Query data
45
+ storeConfig,
46
+ isLoading,
47
+ error,
48
+ isSuccess,
49
+ // Actions
50
+ refetch: refetchConfig,
51
+ };
52
+ }
@@ -24,6 +24,7 @@ export { usePostPurchasesQuery as usePostPurchases } from './hooks/usePostPurcha
24
24
  export { useProductsQuery as useProducts } from './hooks/useProductsQuery';
25
25
  export { usePromotionsQuery as usePromotions } from './hooks/usePromotionsQuery';
26
26
  export { useShippingRatesQuery as useShippingRates } from './hooks/useShippingRatesQuery';
27
+ export { useStoreConfigQuery as useStoreConfig } from './hooks/useStoreConfigQuery';
27
28
  export { useThreeds } from './hooks/useThreeds';
28
29
  export { useThreedsModal } from './hooks/useThreedsModal';
29
30
  export { useVipOffersQuery as useVipOffers } from './hooks/useVipOffersQuery';
@@ -45,6 +46,7 @@ export type { UsePostPurchasesQueryOptions as UsePostPurchasesOptions, UsePostPu
45
46
  export type { UseProductsQueryOptions as UseProductsOptions, UseProductsQueryResult as UseProductsResult } from './hooks/useProductsQuery';
46
47
  export type { UsePromotionsQueryOptions as UsePromotionsOptions, UsePromotionsQueryResult as UsePromotionsResult } from './hooks/usePromotionsQuery';
47
48
  export type { UseShippingRatesQueryOptions as UseShippingRatesOptions, UseShippingRatesQueryResult as UseShippingRatesResult } from './hooks/useShippingRatesQuery';
49
+ export type { UseStoreConfigQueryOptions as UseStoreConfigOptions, UseStoreConfigQueryResult as UseStoreConfigResult } from './hooks/useStoreConfigQuery';
48
50
  export type { PaymentInstrument, ThreedsChallenge, ThreedsHook, ThreedsOptions, ThreedsProvider, ThreedsSession } from './hooks/useThreeds';
49
51
  export type { UseVipOffersQueryOptions as UseVipOffersOptions, UseVipOffersQueryResult as UseVipOffersResult } from './hooks/useVipOffersQuery';
50
52
  export { formatMoney } from '../../react/utils/money';
@@ -28,6 +28,7 @@ export { usePostPurchasesQuery as usePostPurchases } from './hooks/usePostPurcha
28
28
  export { useProductsQuery as useProducts } from './hooks/useProductsQuery';
29
29
  export { usePromotionsQuery as usePromotions } from './hooks/usePromotionsQuery';
30
30
  export { useShippingRatesQuery as useShippingRates } from './hooks/useShippingRatesQuery';
31
+ export { useStoreConfigQuery as useStoreConfig } from './hooks/useStoreConfigQuery';
31
32
  export { useThreeds } from './hooks/useThreeds';
32
33
  export { useThreedsModal } from './hooks/useThreedsModal';
33
34
  export { useVipOffersQuery as useVipOffers } from './hooks/useVipOffersQuery';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.6.6",
3
+ "version": "2.6.8",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",