@wspc/cli 0.0.19 → 0.0.21

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/cli.js CHANGED
@@ -1321,13 +1321,6 @@ var SERVICE_HEADERS = {
1321
1321
  email: "x-cb-email",
1322
1322
  push: "x-cb-push"
1323
1323
  };
1324
- var SERVICE_PREFIXES = [
1325
- { service: "auth", prefix: "/auth" },
1326
- { service: "todo", prefix: "/todo" },
1327
- { service: "calendar", prefix: "/calendar" },
1328
- { service: "email", prefix: "/email" },
1329
- { service: "push", prefix: "/push" }
1330
- ];
1331
1324
  var KNOWN_HEADERS = Object.values(SERVICE_HEADERS);
1332
1325
  function normalizeBasePath(pathname) {
1333
1326
  const trimmed = pathname.replace(/\/+$/, "");
@@ -1338,23 +1331,11 @@ function isUnderApiBase(url, apiBase) {
1338
1331
  const basePath = normalizeBasePath(base.pathname);
1339
1332
  return url.origin === base.origin && (basePath === "/" || url.pathname === basePath || url.pathname.startsWith(`${basePath}/`));
1340
1333
  }
1341
- function pathWithinApiBase(url, apiBase) {
1342
- const basePath = normalizeBasePath(new URL(apiBase).pathname);
1343
- if (basePath === "/") return url.pathname;
1344
- if (url.pathname === basePath) return "/";
1345
- return url.pathname.slice(basePath.length) || "/";
1346
- }
1347
- function pathMatchesPrefix(pathname, prefix) {
1348
- return pathname === prefix || pathname.startsWith(`${prefix}/`);
1349
- }
1350
- function serviceForPath(pathname) {
1351
- return SERVICE_PREFIXES.find(({ prefix }) => pathMatchesPrefix(pathname, prefix))?.service;
1352
- }
1353
- function stripKnownBookmarkHeaders(request, keep) {
1354
- if (!KNOWN_HEADERS.some((header) => header !== keep && request.headers.has(header))) return request;
1334
+ function stripKnownBookmarkHeaders(request) {
1335
+ if (!KNOWN_HEADERS.some((header) => request.headers.has(header))) return request;
1355
1336
  const headers = new Headers(request.headers);
1356
1337
  for (const header of KNOWN_HEADERS) {
1357
- if (header !== keep) headers.delete(header);
1338
+ headers.delete(header);
1358
1339
  }
1359
1340
  return new Request(request, { headers });
1360
1341
  }
@@ -1378,21 +1359,22 @@ function createConsistencyFetch(opts) {
1378
1359
  const request = new Request(input, init);
1379
1360
  const url = new URL(request.url);
1380
1361
  const applies = isUnderApiBase(url, opts.apiBase);
1381
- let outgoing = request;
1382
- let injectedService;
1383
- const service = applies ? serviceForPath(pathWithinApiBase(url, opts.apiBase)) : void 0;
1384
- const serviceHeader = service ? SERVICE_HEADERS[service] : void 0;
1385
- outgoing = stripKnownBookmarkHeaders(outgoing, applies ? serviceHeader : void 0);
1386
- if (applies && service) {
1387
- const header = SERVICE_HEADERS[service];
1388
- if (!outgoing.headers.has(header)) {
1389
- const config = await opts.store.read();
1390
- const bookmark = config.envs[opts.envName]?.consistency_bookmarks?.[service];
1391
- if (bookmark) {
1392
- const headers = new Headers(outgoing.headers);
1362
+ let outgoing = stripKnownBookmarkHeaders(request);
1363
+ const injectedBookmarks = [];
1364
+ if (applies) {
1365
+ const config = await opts.store.read();
1366
+ const bookmarks = config.envs[opts.envName]?.consistency_bookmarks;
1367
+ if (bookmarks) {
1368
+ const headers = new Headers(outgoing.headers);
1369
+ for (const [serviceName, header] of Object.entries(SERVICE_HEADERS)) {
1370
+ const service = serviceName;
1371
+ const bookmark = bookmarks[service];
1372
+ if (!bookmark) continue;
1393
1373
  headers.set(header, bookmark);
1374
+ injectedBookmarks.push([service, bookmark]);
1375
+ }
1376
+ if (injectedBookmarks.length > 0) {
1394
1377
  outgoing = new Request(outgoing, { headers });
1395
- injectedService = service;
1396
1378
  }
1397
1379
  }
1398
1380
  }
@@ -1402,7 +1384,7 @@ function createConsistencyFetch(opts) {
1402
1384
  const value = response.headers.get(header);
1403
1385
  return value ? [[serviceName, value]] : [];
1404
1386
  });
1405
- const shouldCheckInvalidBookmark = injectedService !== void 0;
1387
+ const shouldCheckInvalidBookmark = injectedBookmarks.length > 0;
1406
1388
  const invalidBookmark = shouldCheckInvalidBookmark ? await responseHasInvalidBookmark(response) : false;
1407
1389
  if (nextBookmarks.length === 0 && !invalidBookmark) return response;
1408
1390
  await opts.store.update((config) => {
@@ -1412,8 +1394,12 @@ function createConsistencyFetch(opts) {
1412
1394
  for (const [serviceName, value] of nextBookmarks) {
1413
1395
  env.consistency_bookmarks[serviceName] = value;
1414
1396
  }
1415
- if (invalidBookmark && injectedService) {
1416
- delete env.consistency_bookmarks[injectedService];
1397
+ if (invalidBookmark) {
1398
+ for (const [service, injectedValue] of injectedBookmarks) {
1399
+ if (env.consistency_bookmarks[service] === injectedValue) {
1400
+ delete env.consistency_bookmarks[service];
1401
+ }
1402
+ }
1417
1403
  }
1418
1404
  if (Object.keys(env.consistency_bookmarks).length === 0) {
1419
1405
  delete env.consistency_bookmarks;
@@ -1424,9 +1410,9 @@ function createConsistencyFetch(opts) {
1424
1410
  }
1425
1411
 
1426
1412
  // src/version.ts
1427
- var VERSION = "0.0.19";
1428
- var SPEC_SHA = "d0ccc741";
1429
- var SPEC_FETCHED_AT = "2026-06-17T07:38:57.087Z";
1413
+ var VERSION = "0.0.21";
1414
+ var SPEC_SHA = "dcbc193f";
1415
+ var SPEC_FETCHED_AT = "2026-06-17T16:32:49.096Z";
1430
1416
  var API_BASE = "https://api.wspc.ai";
1431
1417
 
1432
1418
  // src/index.ts