@tagadapay/plugin-sdk 2.7.4 → 2.7.5
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.
|
@@ -31,7 +31,7 @@ export declare const loadPluginConfig: (configVariant?: string, rawConfig?: RawP
|
|
|
31
31
|
* Helper to load local config file for development (from /config directory)
|
|
32
32
|
* Returns the config object that can be passed to TagadaProvider
|
|
33
33
|
*/
|
|
34
|
-
export declare function loadLocalConfig(configName?: string): Promise<Record<string, unknown> | null>;
|
|
34
|
+
export declare function loadLocalConfig(configName?: string, defaultConfig?: any): Promise<Record<string, unknown> | null>;
|
|
35
35
|
export interface CreateRawPluginConfigOptions {
|
|
36
36
|
config?: any;
|
|
37
37
|
}
|
|
@@ -158,7 +158,7 @@ export const loadPluginConfig = async (configVariant = 'default', rawConfig) =>
|
|
|
158
158
|
* Helper to load local config file for development (from /config directory)
|
|
159
159
|
* Returns the config object that can be passed to TagadaProvider
|
|
160
160
|
*/
|
|
161
|
-
export async function loadLocalConfig(configName = 'default') {
|
|
161
|
+
export async function loadLocalConfig(configName = 'default', defaultConfig) {
|
|
162
162
|
try {
|
|
163
163
|
// Only load in localhost
|
|
164
164
|
const isLocalhost = typeof window !== 'undefined' &&
|
|
@@ -168,6 +168,9 @@ export async function loadLocalConfig(configName = 'default') {
|
|
|
168
168
|
if (!isLocalhost) {
|
|
169
169
|
return null;
|
|
170
170
|
}
|
|
171
|
+
if (defaultConfig) {
|
|
172
|
+
return defaultConfig;
|
|
173
|
+
}
|
|
171
174
|
// Try .tgd.json first, then .json, then .config.json
|
|
172
175
|
const possiblePaths = [
|
|
173
176
|
`/config/${configName}.config.json`,
|
|
@@ -225,8 +228,11 @@ export async function createRawPluginConfig(options) {
|
|
|
225
228
|
console.warn('[createRawPluginConfig] No storeId provided');
|
|
226
229
|
return undefined;
|
|
227
230
|
}
|
|
228
|
-
const resolvedConfig =
|
|
229
|
-
|
|
231
|
+
const resolvedConfig = await loadLocalConfig(configName, options?.config);
|
|
232
|
+
if (!resolvedConfig) {
|
|
233
|
+
console.warn('[createRawPluginConfig] No config found');
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
230
236
|
const rawConfig = {
|
|
231
237
|
storeId: storeId,
|
|
232
238
|
accountId: accountId,
|
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
* Products Hook using TanStack Query
|
|
3
3
|
* Replaces manual fetching with automatic caching
|
|
4
4
|
*/
|
|
5
|
-
import { useMemo, useCallback } from 'react';
|
|
6
5
|
import { useQuery } from '@tanstack/react-query';
|
|
6
|
+
import { useCallback, useMemo } from 'react';
|
|
7
7
|
import { ProductsResource } from '../../core/resources/products';
|
|
8
|
-
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
9
|
-
import { usePluginConfig } from './usePluginConfig';
|
|
10
8
|
import { getGlobalApiClient } from './useApiQuery';
|
|
9
|
+
import { usePluginConfig } from './usePluginConfig';
|
|
11
10
|
export function useProductsQuery(options = {}) {
|
|
12
11
|
const { productIds = [], enabled = true, includeVariants = true, includePrices = true } = options;
|
|
13
12
|
const { storeId } = usePluginConfig();
|
|
14
|
-
const { isSessionInitialized } = useTagadaContext();
|
|
15
13
|
// Create products resource client
|
|
16
14
|
const productsResource = useMemo(() => {
|
|
17
15
|
try {
|
|
@@ -26,7 +24,7 @@ export function useProductsQuery(options = {}) {
|
|
|
26
24
|
// Use TanStack Query for fetching products
|
|
27
25
|
const { data: products = [], isLoading, error, refetch } = useQuery({
|
|
28
26
|
queryKey,
|
|
29
|
-
enabled: enabled && !!storeId
|
|
27
|
+
enabled: enabled && !!storeId,
|
|
30
28
|
queryFn: async () => {
|
|
31
29
|
if (!storeId) {
|
|
32
30
|
throw new Error('Store ID not found. Make sure the TagadaProvider is properly configured.');
|