@tagadapay/plugin-sdk 2.7.2 → 2.7.4

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.
@@ -170,19 +170,15 @@ export async function loadLocalConfig(configName = 'default') {
170
170
  }
171
171
  // Try .tgd.json first, then .json, then .config.json
172
172
  const possiblePaths = [
173
+ `/config/${configName}.config.json`,
173
174
  `/config/${configName}.tgd.json`,
174
175
  `/config/${configName}.json`,
175
- `/config/${configName}.config.json`,
176
176
  ];
177
177
  for (const path of possiblePaths) {
178
178
  try {
179
179
  const response = await fetch(path);
180
180
  if (response.ok) {
181
181
  const config = await response.json();
182
- console.log(`✅ [loadLocalConfig] Loaded config from ${path}:`, {
183
- configName: config.configName,
184
- hasBranding: !!config.branding,
185
- });
186
182
  return config;
187
183
  }
188
184
  }
@@ -205,15 +201,32 @@ export async function loadLocalConfig(configName = 'default') {
205
201
  */
206
202
  export async function createRawPluginConfig(options) {
207
203
  try {
208
- const storeId = process.env.TAGADA_STORE_ID;
209
- const accountId = process.env.TAGADA_ACCOUNT_ID;
210
- const basePath = process.env.TAGADA_BASE_PATH;
211
- const configName = process.env.TAGADA_CONFIG_NAME;
212
- if (storeId) {
204
+ const resolveEnv = (key) => {
205
+ const prefixes = ['', 'VITE_', 'REACT_APP_', 'NEXT_PUBLIC_'];
206
+ for (const prefix of prefixes) {
207
+ const envKey = prefix ? `${prefix}${key}` : key;
208
+ if (typeof process !== 'undefined' && process?.env?.[envKey]) {
209
+ return process.env[envKey];
210
+ }
211
+ if (typeof import.meta !== 'undefined' && import.meta?.env?.[envKey]) {
212
+ return import.meta.env[envKey];
213
+ }
214
+ if (typeof window !== 'undefined' && window?.__TAGADA_ENV__?.[envKey]) {
215
+ return window.__TAGADA_ENV__[envKey];
216
+ }
217
+ }
218
+ return undefined;
219
+ };
220
+ const storeId = resolveEnv('TAGADA_STORE_ID');
221
+ const accountId = resolveEnv('TAGADA_ACCOUNT_ID');
222
+ const basePath = resolveEnv('TAGADA_BASE_PATH');
223
+ const configName = resolveEnv('TAGADA_CONFIG_NAME');
224
+ if (!storeId) {
213
225
  console.warn('[createRawPluginConfig] No storeId provided');
214
226
  return undefined;
215
227
  }
216
228
  const resolvedConfig = options?.config ?? await loadLocalConfig(configName);
229
+ console.log("resolvedConfig", resolvedConfig);
217
230
  const rawConfig = {
218
231
  storeId: storeId,
219
232
  accountId: accountId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.7.2",
3
+ "version": "2.7.4",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",