@ctil/gql 1.1.6 → 1.1.7
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 +15 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4378,8 +4378,8 @@ var rateLimitConfig = {
|
|
|
4378
4378
|
mutation: { max: 10, window: 1, debounce: 200 }
|
|
4379
4379
|
},
|
|
4380
4380
|
custom: {
|
|
4381
|
-
login: { max:
|
|
4382
|
-
refreshToken: { max:
|
|
4381
|
+
login: { max: 2, window: 3, debounce: 0 },
|
|
4382
|
+
refreshToken: { max: 3, window: 5, debounce: 0 }
|
|
4383
4383
|
}
|
|
4384
4384
|
};
|
|
4385
4385
|
|
|
@@ -4515,6 +4515,7 @@ var CCRequest = class {
|
|
|
4515
4515
|
this.config = config;
|
|
4516
4516
|
this._remember = false;
|
|
4517
4517
|
this.interceptors = [];
|
|
4518
|
+
this.refreshPromise = null;
|
|
4518
4519
|
this.deviceInfoPromise = getDeviceInfo();
|
|
4519
4520
|
this.headers = this.buildHeaders(config);
|
|
4520
4521
|
const loginInfo = this.loadLoginInfo();
|
|
@@ -4662,26 +4663,29 @@ var CCRequest = class {
|
|
|
4662
4663
|
const loginInfo = this.getLoginInfo();
|
|
4663
4664
|
if (!loginInfo) return;
|
|
4664
4665
|
const now = Date.now();
|
|
4665
|
-
const accessExpired = new Date(loginInfo.expireAt).getTime() <=
|
|
4666
|
+
const accessExpired = new Date(loginInfo.expireAt).getTime() - now <= 6e5;
|
|
4666
4667
|
const refreshExpired = new Date(loginInfo.refreshExpireAt).getTime() <= now;
|
|
4667
4668
|
if (refreshExpired) {
|
|
4668
4669
|
this.removeLoginInfo();
|
|
4669
4670
|
throw new Error("Login expired. Please login again.");
|
|
4670
4671
|
}
|
|
4671
|
-
if (accessExpired
|
|
4672
|
+
if (!accessExpired) return;
|
|
4673
|
+
if (this.refreshPromise) {
|
|
4674
|
+
return this.refreshPromise;
|
|
4675
|
+
}
|
|
4676
|
+
this.refreshPromise = (async () => {
|
|
4672
4677
|
try {
|
|
4673
|
-
const
|
|
4678
|
+
const result = await auth.refreshToken({
|
|
4674
4679
|
refreshToken: loginInfo.refreshToken,
|
|
4675
4680
|
remember: this._remember
|
|
4676
|
-
// 使用持久化的 remember
|
|
4677
4681
|
});
|
|
4678
|
-
const newInfo =
|
|
4682
|
+
const newInfo = result.refreshToken ?? result;
|
|
4679
4683
|
this.setLoginInfo(newInfo, this._remember);
|
|
4680
|
-
}
|
|
4681
|
-
this.
|
|
4682
|
-
throw new Error("Failed to refresh token. Please login again." + err?.message);
|
|
4684
|
+
} finally {
|
|
4685
|
+
this.refreshPromise = null;
|
|
4683
4686
|
}
|
|
4684
|
-
}
|
|
4687
|
+
})();
|
|
4688
|
+
return this.refreshPromise;
|
|
4685
4689
|
}
|
|
4686
4690
|
// ===== 请求逻辑 =====
|
|
4687
4691
|
async request(query2, variables) {
|