@tagadapay/plugin-sdk 2.7.3 → 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,21 +168,20 @@ 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 = [
|
|
176
|
+
`/config/${configName}.config.json`,
|
|
173
177
|
`/config/${configName}.tgd.json`,
|
|
174
178
|
`/config/${configName}.json`,
|
|
175
|
-
`/config/${configName}.config.json`,
|
|
176
179
|
];
|
|
177
180
|
for (const path of possiblePaths) {
|
|
178
181
|
try {
|
|
179
182
|
const response = await fetch(path);
|
|
180
183
|
if (response.ok) {
|
|
181
184
|
const config = await response.json();
|
|
182
|
-
console.log(`✅ [loadLocalConfig] Loaded config from ${path}:`, {
|
|
183
|
-
configName: config.configName,
|
|
184
|
-
hasBranding: !!config.branding,
|
|
185
|
-
});
|
|
186
185
|
return config;
|
|
187
186
|
}
|
|
188
187
|
}
|
|
@@ -205,15 +204,35 @@ export async function loadLocalConfig(configName = 'default') {
|
|
|
205
204
|
*/
|
|
206
205
|
export async function createRawPluginConfig(options) {
|
|
207
206
|
try {
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
207
|
+
const resolveEnv = (key) => {
|
|
208
|
+
const prefixes = ['', 'VITE_', 'REACT_APP_', 'NEXT_PUBLIC_'];
|
|
209
|
+
for (const prefix of prefixes) {
|
|
210
|
+
const envKey = prefix ? `${prefix}${key}` : key;
|
|
211
|
+
if (typeof process !== 'undefined' && process?.env?.[envKey]) {
|
|
212
|
+
return process.env[envKey];
|
|
213
|
+
}
|
|
214
|
+
if (typeof import.meta !== 'undefined' && import.meta?.env?.[envKey]) {
|
|
215
|
+
return import.meta.env[envKey];
|
|
216
|
+
}
|
|
217
|
+
if (typeof window !== 'undefined' && window?.__TAGADA_ENV__?.[envKey]) {
|
|
218
|
+
return window.__TAGADA_ENV__[envKey];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
222
|
+
};
|
|
223
|
+
const storeId = resolveEnv('TAGADA_STORE_ID');
|
|
224
|
+
const accountId = resolveEnv('TAGADA_ACCOUNT_ID');
|
|
225
|
+
const basePath = resolveEnv('TAGADA_BASE_PATH');
|
|
226
|
+
const configName = resolveEnv('TAGADA_CONFIG_NAME');
|
|
227
|
+
if (!storeId) {
|
|
213
228
|
console.warn('[createRawPluginConfig] No storeId provided');
|
|
214
229
|
return undefined;
|
|
215
230
|
}
|
|
216
|
-
const resolvedConfig =
|
|
231
|
+
const resolvedConfig = await loadLocalConfig(configName, options?.config);
|
|
232
|
+
if (!resolvedConfig) {
|
|
233
|
+
console.warn('[createRawPluginConfig] No config found');
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
217
236
|
const rawConfig = {
|
|
218
237
|
storeId: storeId,
|
|
219
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.');
|