@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/index.d.ts CHANGED
@@ -622,9 +622,9 @@ interface TDataShape {
622
622
  type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
623
623
  type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
624
624
 
625
- declare const VERSION = "0.1.9";
625
+ declare const VERSION = "0.1.11";
626
626
  declare const SPEC_SHA = "bec760cd";
627
- declare const SPEC_FETCHED_AT = "2026-07-06T07:30:04.295Z";
627
+ declare const SPEC_FETCHED_AT = "2026-07-08T01:27:32.122Z";
628
628
  declare const API_BASE = "https://api.wspc.ai";
629
629
 
630
630
  type WspcClientOptions = {
package/dist/index.js CHANGED
@@ -784,9 +784,9 @@ var createClient = (config = {}) => {
784
784
  };
785
785
 
786
786
  // src/version.ts
787
- var VERSION = "0.1.9";
787
+ var VERSION = "0.1.11";
788
788
  var SPEC_SHA = "bec760cd";
789
- var SPEC_FETCHED_AT = "2026-07-06T07:30:04.295Z";
789
+ var SPEC_FETCHED_AT = "2026-07-08T01:27:32.122Z";
790
790
  var API_BASE = "https://api.wspc.ai";
791
791
 
792
792
  // src/handwritten/auth/sdk-auth.ts
@@ -819,8 +819,33 @@ function createAuthInterceptor(mode) {
819
819
  }
820
820
  let accessToken = mode.accessToken;
821
821
  let refreshToken = mode.refreshToken;
822
+ let expiresAt = mode.expiresAt;
823
+ const { baseUrl, clientId, onTokenRefresh } = mode;
822
824
  const fetchImpl = mode.fetchImpl ?? fetch;
823
825
  const now = mode.now ?? Date.now;
826
+ const SKEW_MS = 3e4;
827
+ async function refresh() {
828
+ const refreshRes = await fetchImpl(`${baseUrl}/auth/oauth/token`, {
829
+ method: "POST",
830
+ headers: {
831
+ "content-type": "application/x-www-form-urlencoded",
832
+ "user-agent": USER_AGENT
833
+ },
834
+ body: new URLSearchParams({
835
+ grant_type: "refresh_token",
836
+ refresh_token: refreshToken,
837
+ client_id: clientId
838
+ })
839
+ });
840
+ if (!refreshRes.ok) {
841
+ throw new WspcAuthExpiredError(await expiredMessage(refreshRes));
842
+ }
843
+ const tokens = await refreshRes.json();
844
+ accessToken = tokens.access_token;
845
+ refreshToken = tokens.refresh_token;
846
+ expiresAt = now() + tokens.expires_in * 1e3;
847
+ await onTokenRefresh({ accessToken, refreshToken, expiresAt });
848
+ }
824
849
  return {
825
850
  async onRequest(req) {
826
851
  req.headers.set("authorization", `Bearer ${accessToken}`);
@@ -828,31 +853,12 @@ function createAuthInterceptor(mode) {
828
853
  return req;
829
854
  },
830
855
  async execute(req) {
856
+ if (expiresAt !== void 0 && now() >= expiresAt - SKEW_MS) {
857
+ await refresh();
858
+ }
831
859
  const first = await fetchImpl(await this.onRequest(req.clone()));
832
860
  if (first.status !== 401) return first;
833
- const refreshRes = await fetchImpl(`${mode.baseUrl}/auth/oauth/token`, {
834
- method: "POST",
835
- headers: {
836
- "content-type": "application/x-www-form-urlencoded",
837
- "user-agent": USER_AGENT
838
- },
839
- body: new URLSearchParams({
840
- grant_type: "refresh_token",
841
- refresh_token: refreshToken,
842
- client_id: mode.clientId
843
- })
844
- });
845
- if (!refreshRes.ok) {
846
- throw new WspcAuthExpiredError(await expiredMessage(refreshRes));
847
- }
848
- const tokens = await refreshRes.json();
849
- accessToken = tokens.access_token;
850
- refreshToken = tokens.refresh_token;
851
- await mode.onTokenRefresh({
852
- accessToken,
853
- refreshToken,
854
- expiresAt: now() + tokens.expires_in * 1e3
855
- });
861
+ await refresh();
856
862
  return fetchImpl(await this.onRequest(req.clone()));
857
863
  }
858
864
  };