@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.d.cts CHANGED
@@ -163,6 +163,21 @@ interface DemoKitConfig {
163
163
  * or when specific query parameters are present
164
164
  */
165
165
  detection?: DetectionConfig;
166
+ /**
167
+ * Path aliases for matching fixtures across equivalent URL prefixes.
168
+ * Common in Next.js apps where `/api/*` rewrites to `/v1/*`.
169
+ * A fixture defined for `/v1/users` will also match `/api/users`.
170
+ *
171
+ * @example
172
+ * pathAliases: { '/api/': '/v1/' }
173
+ */
174
+ pathAliases?: Record<string, string>;
175
+ /**
176
+ * Log a warning when a catch-all pattern (containing `*`) matches a request.
177
+ * Helps identify fixtures that need specific patterns.
178
+ * @default true in development, false in production
179
+ */
180
+ warnOnCatchAll?: boolean;
166
181
  /**
167
182
  * Guard callback that controls whether demo mode can be disabled.
168
183
  * Return `true` to allow disabling, `false` to prevent it,
package/dist/index.d.ts CHANGED
@@ -163,6 +163,21 @@ interface DemoKitConfig {
163
163
  * or when specific query parameters are present
164
164
  */
165
165
  detection?: DetectionConfig;
166
+ /**
167
+ * Path aliases for matching fixtures across equivalent URL prefixes.
168
+ * Common in Next.js apps where `/api/*` rewrites to `/v1/*`.
169
+ * A fixture defined for `/v1/users` will also match `/api/users`.
170
+ *
171
+ * @example
172
+ * pathAliases: { '/api/': '/v1/' }
173
+ */
174
+ pathAliases?: Record<string, string>;
175
+ /**
176
+ * Log a warning when a catch-all pattern (containing `*`) matches a request.
177
+ * Helps identify fixtures that need specific patterns.
178
+ * @default true in development, false in production
179
+ */
180
+ warnOnCatchAll?: boolean;
166
181
  /**
167
182
  * Guard callback that controls whether demo mode can be disabled.
168
183
  * Return `true` to allow disabling, `false` to prevent it,
package/dist/index.js CHANGED
@@ -360,7 +360,9 @@ function createDemoInterceptor(config) {
360
360
  baseUrl = "http://localhost",
361
361
  detection,
362
362
  canDisable,
363
- onMutationIntercepted
363
+ onMutationIntercepted,
364
+ pathAliases,
365
+ warnOnCatchAll = typeof process !== "undefined" && process.env?.NODE_ENV !== "production"
364
366
  } = config;
365
367
  const detectionResult = detectDemoMode(detection);
366
368
  let enabled = detectionResult.detected || (initialEnabled ?? loadDemoState(storageKey));
@@ -375,20 +377,29 @@ function createDemoInterceptor(config) {
375
377
  originalFetch = globalThis.fetch;
376
378
  globalThis.fetch = async function interceptedFetch(input, init) {
377
379
  if (!enabled) {
378
- console.log("[DemoKit] Demo mode disabled, passing through");
379
380
  return originalFetch(input, init);
380
381
  }
381
382
  const method = init?.method?.toUpperCase() || "GET";
382
383
  const pathname = extractPathname(input, baseUrl);
383
- console.log("[DemoKit] Intercepting request:", { method, pathname, enabled });
384
- console.log("[DemoKit] Available fixtures:", Object.keys(currentFixtures));
385
- const match = findMatchingPattern(currentFixtures, method, pathname);
384
+ let match = findMatchingPattern(currentFixtures, method, pathname);
385
+ if (!match && pathAliases) {
386
+ for (const [from, to] of Object.entries(pathAliases)) {
387
+ if (pathname.startsWith(from)) {
388
+ const aliasedPath = to + pathname.slice(from.length);
389
+ match = findMatchingPattern(currentFixtures, method, aliasedPath);
390
+ if (match) break;
391
+ }
392
+ }
393
+ }
386
394
  if (!match) {
387
- console.log("[DemoKit] No matching fixture for:", `${method} ${pathname}`);
388
395
  return originalFetch(input, init);
389
396
  }
390
- console.log("[DemoKit] Found matching fixture:", match[0]);
391
397
  const [pattern, matchResult] = match;
398
+ if (warnOnCatchAll && pattern.includes("*")) {
399
+ console.warn(
400
+ `[DemoKit] Catch-all fixture matched: ${method} ${pathname} \u2192 "${pattern}". Consider adding a specific fixture.`
401
+ );
402
+ }
392
403
  const handler = currentFixtures[pattern];
393
404
  const url = extractUrl(input, baseUrl);
394
405
  const headers = new Headers(init?.headers);