@ctil/gql 1.0.12 → 1.0.14

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 CHANGED
@@ -2749,6 +2749,7 @@ __export(index_exports, {
2749
2749
  getBrowserDeviceInfo: () => getBrowserDeviceInfo,
2750
2750
  getClient: () => getClient,
2751
2751
  getDeviceInfo: () => getDeviceInfo,
2752
+ getRateLimitConfig: () => getRateLimitConfig,
2752
2753
  gql: () => gql,
2753
2754
  initGraphQLClient: () => initGraphQLClient,
2754
2755
  mutation: () => mutation,
@@ -2759,6 +2760,7 @@ __export(index_exports, {
2759
2760
  setEndpoint: () => setEndpoint,
2760
2761
  setHeader: () => setHeader,
2761
2762
  setHeaders: () => setHeaders,
2763
+ setRateLimitConfig: () => setRateLimitConfig,
2762
2764
  setToken: () => setToken,
2763
2765
  sms: () => sms,
2764
2766
  useInterceptor: () => useInterceptor
@@ -4172,8 +4174,8 @@ function buildGraphQLGetFilePreview(resourceId) {
4172
4174
  // src/rateLimit/rateLimitConfig.ts
4173
4175
  var rateLimitConfig = {
4174
4176
  defaultRules: {
4175
- query: { max: 10, window: 1, debounce: 0 },
4176
- mutation: { max: 3, window: 1, debounce: 200 }
4177
+ query: { max: 20, window: 1, debounce: 0 },
4178
+ mutation: { max: 10, window: 1, debounce: 200 }
4177
4179
  },
4178
4180
  custom: {
4179
4181
  login: { max: 1, window: 5, debounce: 0 },
@@ -4182,11 +4184,18 @@ var rateLimitConfig = {
4182
4184
  };
4183
4185
 
4184
4186
  // src/rateLimit/rateLimit.ts
4187
+ var globalConfig = rateLimitConfig;
4188
+ function setRateLimitConfig(newConfig) {
4189
+ globalConfig = newConfig;
4190
+ }
4191
+ function getRateLimitConfig() {
4192
+ return globalConfig;
4193
+ }
4185
4194
  var trackers = /* @__PURE__ */ new Map();
4186
4195
  function getRule(operateName, type, config) {
4187
4196
  return config.custom?.[operateName] || config.defaultRules[type];
4188
4197
  }
4189
- function rateLimit(operateName, type, fn, config = rateLimitConfig) {
4198
+ function rateLimit(operateName, type, fn, config = globalConfig) {
4190
4199
  const rule = getRule(operateName, type, config);
4191
4200
  const now = Date.now();
4192
4201
  const key = `${type}::${operateName}`;
@@ -4241,7 +4250,7 @@ var auth = {
4241
4250
  setLoginInfo(result.login, input.remember);
4242
4251
  clearCache();
4243
4252
  return result;
4244
- }, rateLimitConfig);
4253
+ });
4245
4254
  },
4246
4255
  async refreshToken(input) {
4247
4256
  return rateLimit("refreshToken", "mutation", async () => {
@@ -4250,7 +4259,7 @@ var auth = {
4250
4259
  setLoginInfo(result.refreshToken, input.remember);
4251
4260
  clearCache();
4252
4261
  return result;
4253
- }, rateLimitConfig);
4262
+ });
4254
4263
  },
4255
4264
  async register(input) {
4256
4265
  return rateLimit("registerUser", "mutation", async () => {
@@ -4258,7 +4267,7 @@ var auth = {
4258
4267
  const result = await execute({ query: query2, variables });
4259
4268
  clearCache();
4260
4269
  return result;
4261
- }, rateLimitConfig);
4270
+ });
4262
4271
  },
4263
4272
  async logout() {
4264
4273
  return rateLimit("logout", "mutation", async () => {
@@ -4267,7 +4276,7 @@ var auth = {
4267
4276
  removeLoginInfo();
4268
4277
  clearCache();
4269
4278
  return result;
4270
- }, rateLimitConfig);
4279
+ });
4271
4280
  },
4272
4281
  async logoutAllDevices() {
4273
4282
  return rateLimit("logoutAllDevices", "mutation", async () => {
@@ -4276,7 +4285,7 @@ var auth = {
4276
4285
  removeLoginInfo();
4277
4286
  clearCache();
4278
4287
  return result;
4279
- }, rateLimitConfig);
4288
+ });
4280
4289
  },
4281
4290
  async logoutDevice(deviceId) {
4282
4291
  return rateLimit("logoutDevice", "mutation", async () => {
@@ -4287,7 +4296,7 @@ var auth = {
4287
4296
  }
4288
4297
  clearCache();
4289
4298
  return result;
4290
- }, rateLimitConfig);
4299
+ });
4291
4300
  }
4292
4301
  };
4293
4302
 
@@ -4371,6 +4380,7 @@ var CCRequest = class {
4371
4380
  console.error("Failed to persist login info to file:", err);
4372
4381
  }
4373
4382
  }
4383
+ this.config.loginInfo = loginInfo;
4374
4384
  }
4375
4385
  /** 加载登录信息(仅负责加载,不负责刷新) */
4376
4386
  /** 加载登录信息 */
@@ -4447,6 +4457,7 @@ var CCRequest = class {
4447
4457
  this.removeLoginInfo();
4448
4458
  throw new Error("Login expired. Please login again.");
4449
4459
  }
4460
+ console.log("refreshExpired", refreshExpired);
4450
4461
  if (accessExpired && !refreshExpired) {
4451
4462
  try {
4452
4463
  const refreshResult = await auth.refreshToken({
@@ -4456,9 +4467,10 @@ var CCRequest = class {
4456
4467
  });
4457
4468
  const newInfo = refreshResult.refreshToken ?? refreshResult;
4458
4469
  this.setLoginInfo(newInfo, this._remember);
4459
- } catch {
4470
+ } catch (err) {
4471
+ console.log("err", err);
4460
4472
  this.removeLoginInfo();
4461
- throw new Error("Failed to refresh token. Please login again.");
4473
+ throw new Error("Failed to refresh token. Please login again." + err?.message);
4462
4474
  }
4463
4475
  }
4464
4476
  }
@@ -4741,7 +4753,7 @@ var oss = {
4741
4753
  const { query: query2, variables } = buildGraphQLUploadPresignedUrl(presignedInput);
4742
4754
  const result = await execute({ query: query2, variables });
4743
4755
  return result;
4744
- }, rateLimitConfig);
4756
+ });
4745
4757
  console.log("presignedResult====>", presignedResult);
4746
4758
  if (!presignedResult.uploadPresignedUrl) throw new Error("\u83B7\u53D6\u9884\u7B7E\u540D URL \u5931\u8D25");
4747
4759
  const { uploadUrl, uploadHeaders, downloadUrl, resourceId, contentType, originalFileName } = presignedResult.uploadPresignedUrl;
@@ -4802,7 +4814,7 @@ var oss = {
4802
4814
  const { query: query2, variables } = buildGraphQLUploadPresignedUrl(presignedInput);
4803
4815
  const result = await execute({ query: query2, variables });
4804
4816
  return result;
4805
- }, rateLimitConfig);
4817
+ });
4806
4818
  if (!presignedResult.uploadPresignedUrl) throw new Error("\u83B7\u53D6\u9884\u7B7E\u540D URL \u5931\u8D25");
4807
4819
  const { uploadUrl, uploadHeaders, downloadUrl, resourceId, contentType, originalFileName } = presignedResult.uploadPresignedUrl;
4808
4820
  const headers = {};
@@ -4830,7 +4842,7 @@ var oss = {
4830
4842
  const { query: query2, variables } = buildGraphQLGetFilePreview(resourceId);
4831
4843
  const result = await execute({ query: query2, variables });
4832
4844
  return result;
4833
- }, rateLimitConfig);
4845
+ });
4834
4846
  }
4835
4847
  };
4836
4848
  // Annotate the CommonJS export names for ESM import in node:
@@ -4840,6 +4852,7 @@ var oss = {
4840
4852
  getBrowserDeviceInfo,
4841
4853
  getClient,
4842
4854
  getDeviceInfo,
4855
+ getRateLimitConfig,
4843
4856
  gql,
4844
4857
  initGraphQLClient,
4845
4858
  mutation,
@@ -4850,6 +4863,7 @@ var oss = {
4850
4863
  setEndpoint,
4851
4864
  setHeader,
4852
4865
  setHeaders,
4866
+ setRateLimitConfig,
4853
4867
  setToken,
4854
4868
  sms,
4855
4869
  useInterceptor