@demokit-ai/core 0.4.0 → 0.5.0

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/dist/index.cjs CHANGED
@@ -362,7 +362,9 @@ function createDemoInterceptor(config) {
362
362
  baseUrl = "http://localhost",
363
363
  detection,
364
364
  canDisable,
365
- onMutationIntercepted
365
+ onMutationIntercepted,
366
+ pathAliases,
367
+ warnOnCatchAll = typeof process !== "undefined" && process.env?.NODE_ENV !== "production"
366
368
  } = config;
367
369
  const detectionResult = detectDemoMode(detection);
368
370
  let enabled = detectionResult.detected || (initialEnabled ?? loadDemoState(storageKey));
@@ -377,20 +379,29 @@ function createDemoInterceptor(config) {
377
379
  originalFetch = globalThis.fetch;
378
380
  globalThis.fetch = async function interceptedFetch(input, init) {
379
381
  if (!enabled) {
380
- console.log("[DemoKit] Demo mode disabled, passing through");
381
382
  return originalFetch(input, init);
382
383
  }
383
384
  const method = init?.method?.toUpperCase() || "GET";
384
385
  const pathname = extractPathname(input, baseUrl);
385
- console.log("[DemoKit] Intercepting request:", { method, pathname, enabled });
386
- console.log("[DemoKit] Available fixtures:", Object.keys(currentFixtures));
387
- const match = findMatchingPattern(currentFixtures, method, pathname);
386
+ let match = findMatchingPattern(currentFixtures, method, pathname);
387
+ if (!match && pathAliases) {
388
+ for (const [from, to] of Object.entries(pathAliases)) {
389
+ if (pathname.startsWith(from)) {
390
+ const aliasedPath = to + pathname.slice(from.length);
391
+ match = findMatchingPattern(currentFixtures, method, aliasedPath);
392
+ if (match) break;
393
+ }
394
+ }
395
+ }
388
396
  if (!match) {
389
- console.log("[DemoKit] No matching fixture for:", `${method} ${pathname}`);
390
397
  return originalFetch(input, init);
391
398
  }
392
- console.log("[DemoKit] Found matching fixture:", match[0]);
393
399
  const [pattern, matchResult] = match;
400
+ if (warnOnCatchAll && pattern.includes("*")) {
401
+ console.warn(
402
+ `[DemoKit] Catch-all fixture matched: ${method} ${pathname} \u2192 "${pattern}". Consider adding a specific fixture.`
403
+ );
404
+ }
394
405
  const handler = currentFixtures[pattern];
395
406
  const url = extractUrl(input, baseUrl);
396
407
  const headers = new Headers(init?.headers);