@wspc/cli 0.1.9 → 0.1.11

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
@@ -1520,9 +1520,9 @@ function createConsistencyFetch(opts) {
1520
1520
  }
1521
1521
 
1522
1522
  // src/version.ts
1523
- var VERSION = "0.1.9";
1523
+ var VERSION = "0.1.11";
1524
1524
  var SPEC_SHA = "bec760cd";
1525
- var SPEC_FETCHED_AT = "2026-07-06T07:30:04.295Z";
1525
+ var SPEC_FETCHED_AT = "2026-07-08T01:27:32.122Z";
1526
1526
  var API_BASE = "https://api.wspc.ai";
1527
1527
 
1528
1528
  // src/index.ts
@@ -1564,8 +1564,33 @@ function createAuthInterceptor(mode) {
1564
1564
  }
1565
1565
  let accessToken = mode.accessToken;
1566
1566
  let refreshToken = mode.refreshToken;
1567
+ let expiresAt = mode.expiresAt;
1568
+ const { baseUrl, clientId, onTokenRefresh } = mode;
1567
1569
  const fetchImpl = mode.fetchImpl ?? fetch;
1568
1570
  const now = mode.now ?? Date.now;
1571
+ const SKEW_MS = 3e4;
1572
+ async function refresh() {
1573
+ const refreshRes = await fetchImpl(`${baseUrl}/auth/oauth/token`, {
1574
+ method: "POST",
1575
+ headers: {
1576
+ "content-type": "application/x-www-form-urlencoded",
1577
+ "user-agent": USER_AGENT
1578
+ },
1579
+ body: new URLSearchParams({
1580
+ grant_type: "refresh_token",
1581
+ refresh_token: refreshToken,
1582
+ client_id: clientId
1583
+ })
1584
+ });
1585
+ if (!refreshRes.ok) {
1586
+ throw new WspcAuthExpiredError(await expiredMessage(refreshRes));
1587
+ }
1588
+ const tokens = await refreshRes.json();
1589
+ accessToken = tokens.access_token;
1590
+ refreshToken = tokens.refresh_token;
1591
+ expiresAt = now() + tokens.expires_in * 1e3;
1592
+ await onTokenRefresh({ accessToken, refreshToken, expiresAt });
1593
+ }
1569
1594
  return {
1570
1595
  async onRequest(req) {
1571
1596
  req.headers.set("authorization", `Bearer ${accessToken}`);
@@ -1573,31 +1598,12 @@ function createAuthInterceptor(mode) {
1573
1598
  return req;
1574
1599
  },
1575
1600
  async execute(req) {
1601
+ if (expiresAt !== void 0 && now() >= expiresAt - SKEW_MS) {
1602
+ await refresh();
1603
+ }
1576
1604
  const first = await fetchImpl(await this.onRequest(req.clone()));
1577
1605
  if (first.status !== 401) return first;
1578
- const refreshRes = await fetchImpl(`${mode.baseUrl}/auth/oauth/token`, {
1579
- method: "POST",
1580
- headers: {
1581
- "content-type": "application/x-www-form-urlencoded",
1582
- "user-agent": USER_AGENT
1583
- },
1584
- body: new URLSearchParams({
1585
- grant_type: "refresh_token",
1586
- refresh_token: refreshToken,
1587
- client_id: mode.clientId
1588
- })
1589
- });
1590
- if (!refreshRes.ok) {
1591
- throw new WspcAuthExpiredError(await expiredMessage(refreshRes));
1592
- }
1593
- const tokens = await refreshRes.json();
1594
- accessToken = tokens.access_token;
1595
- refreshToken = tokens.refresh_token;
1596
- await mode.onTokenRefresh({
1597
- accessToken,
1598
- refreshToken,
1599
- expiresAt: now() + tokens.expires_in * 1e3
1600
- });
1606
+ await refresh();
1601
1607
  return fetchImpl(await this.onRequest(req.clone()));
1602
1608
  }
1603
1609
  };
@@ -1654,6 +1660,7 @@ function buildInterceptor(store, resolved, fetchImpl) {
1654
1660
  return createAuthInterceptor({
1655
1661
  accessToken: creds.access_token,
1656
1662
  refreshToken: creds.refresh_token,
1663
+ expiresAt: creds.access_token_expires_at,
1657
1664
  baseUrl: apiBase,
1658
1665
  clientId,
1659
1666
  fetchImpl,
@@ -6295,6 +6302,7 @@ function containsVersionConflict(value) {
6295
6302
  // src/handwritten/commands/drive/watch.ts
6296
6303
  import { Command as Command81 } from "commander";
6297
6304
  import chokidar from "chokidar";
6305
+ import { watch as fsWatch } from "fs";
6298
6306
  import { relative as relative2, resolve as resolve4 } from "path";
6299
6307
 
6300
6308
  // src/handwritten/commands/drive/realtime.ts
@@ -6711,7 +6719,7 @@ async function runDriveWatch(root, options = {}) {
6711
6719
  writeRealtimeState: (next) => writeDriveRealtimeState(root, next)
6712
6720
  });
6713
6721
  }
6714
- source = options.source ?? createChokidarSource(root);
6722
+ source = options.source ?? createDefaultWatchSource(root);
6715
6723
  source.onChange((path) => {
6716
6724
  if (isDriveInternalPath(root, path)) return;
6717
6725
  scheduleSync(debounceMs);
@@ -6760,6 +6768,27 @@ function driveWatchCommand(options = {}) {
6760
6768
  await runDriveWatch(resolve4(path), options);
6761
6769
  });
6762
6770
  }
6771
+ function createDefaultWatchSource(root) {
6772
+ return process.platform === "win32" ? createNativeRecursiveSource(root) : createChokidarSource(root);
6773
+ }
6774
+ function createNativeRecursiveSource(root) {
6775
+ const handlers = [];
6776
+ const watcher = fsWatch(root, { recursive: true }, (_event, filename) => {
6777
+ if (filename === null) return;
6778
+ const path = resolve4(root, filename.toString());
6779
+ for (const handler of handlers) handler(path);
6780
+ });
6781
+ watcher.on("error", () => {
6782
+ });
6783
+ return {
6784
+ onChange(handler) {
6785
+ handlers.push(handler);
6786
+ },
6787
+ async close() {
6788
+ watcher.close();
6789
+ }
6790
+ };
6791
+ }
6763
6792
  function createChokidarSource(root) {
6764
6793
  const watcher = chokidar.watch(root, {
6765
6794
  ignoreInitial: true,