@kevisual/api 0.0.64 → 0.0.65

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.
@@ -1,4 +1,4 @@
1
- // node_modules/.pnpm/@kevisual+remote-app@0.0.6/node_modules/@kevisual/remote-app/dist/app.js
1
+ // ../../node_modules/.pnpm/@kevisual+remote-app@0.0.7/node_modules/@kevisual/remote-app/dist/app.js
2
2
  var __create = Object.create;
3
3
  var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
@@ -213,10 +213,12 @@ class RemoteApp {
213
213
  reconnectAttempts = 0;
214
214
  reconnectTimer = null;
215
215
  isManuallyClosed = false;
216
+ isInitializing = false;
217
+ initId = 0;
216
218
  constructor(opts) {
217
219
  this.mainApp = opts?.app;
218
220
  const token = opts.token;
219
- const url = opts.url;
221
+ const url = opts.url || "https://kevisual.cn/ws/proxy";
220
222
  const id = opts.id;
221
223
  const username = opts.username;
222
224
  this.username = username;
@@ -282,10 +284,17 @@ class RemoteApp {
282
284
  return wsURL;
283
285
  }
284
286
  async init() {
287
+ if (this.isInitializing) {
288
+ return;
289
+ }
290
+ this.isInitializing = true;
291
+ const currentInitId = ++this.initId;
285
292
  if (!this.url) {
293
+ this.isInitializing = false;
286
294
  throw new Error("No url provided for remote app");
287
295
  }
288
296
  if (!this.id) {
297
+ this.isInitializing = false;
289
298
  throw new Error("No id provided for remote app");
290
299
  }
291
300
  this.isError = false;
@@ -295,11 +304,20 @@ class RemoteApp {
295
304
  const ws = new WebSocket(this.getWsURL(this.url));
296
305
  const that = this;
297
306
  ws.onopen = function() {
307
+ if (currentInitId !== that.initId) {
308
+ ws.close();
309
+ return;
310
+ }
298
311
  that.isConnected = true;
312
+ that.isInitializing = false;
299
313
  that.onOpen();
300
314
  console.log("[remote-app] WebSocket connection opened");
301
315
  };
302
316
  ws.onclose = function() {
317
+ if (currentInitId !== that.initId) {
318
+ return;
319
+ }
320
+ that.isInitializing = false;
303
321
  that.isConnected = false;
304
322
  that.onClose();
305
323
  };
@@ -307,6 +325,10 @@ class RemoteApp {
307
325
  that.onMessage(event.data);
308
326
  };
309
327
  ws.onerror = function(error) {
328
+ if (currentInitId !== that.initId) {
329
+ return;
330
+ }
331
+ that.isInitializing = false;
310
332
  that.onError(error);
311
333
  };
312
334
  this.ws = ws;
@@ -3,20 +3,34 @@ var __getProtoOf = Object.getPrototypeOf;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toESMCache_node;
10
+ var __toESMCache_esm;
6
11
  var __toESM = (mod, isNodeMode, target) => {
12
+ var canCache = mod != null && typeof mod === "object";
13
+ if (canCache) {
14
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
15
+ var cached = cache.get(mod);
16
+ if (cached)
17
+ return cached;
18
+ }
7
19
  target = mod != null ? __create(__getProtoOf(mod)) : {};
8
20
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
21
  for (let key of __getOwnPropNames(mod))
10
22
  if (!__hasOwnProp.call(to, key))
11
23
  __defProp(to, key, {
12
- get: () => mod[key],
24
+ get: __accessProp.bind(mod, key),
13
25
  enumerable: true
14
26
  });
27
+ if (canCache)
28
+ cache.set(mod, to);
15
29
  return to;
16
30
  };
17
31
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
18
32
 
19
- // node_modules/.pnpm/spark-md5@3.0.2/node_modules/spark-md5/spark-md5.js
33
+ // ../../node_modules/.pnpm/spark-md5@3.0.2/node_modules/spark-md5/spark-md5.js
20
34
  var require_spark_md5 = __commonJS((exports, module) => {
21
35
  (function(factory) {
22
36
  if (typeof exports === "object") {
@@ -446,7 +460,7 @@ var require_spark_md5 = __commonJS((exports, module) => {
446
460
  });
447
461
  });
448
462
 
449
- // node_modules/.pnpm/@kevisual+query@0.0.53/node_modules/@kevisual/query/dist/query-browser.js
463
+ // ../../node_modules/.pnpm/@kevisual+query@0.0.55/node_modules/@kevisual/query/dist/query-browser.js
450
464
  var isTextForContentType = (contentType) => {
451
465
  if (!contentType)
452
466
  return false;
@@ -557,7 +571,7 @@ var adapter = async (opts = {}, overloadOpts) => {
557
571
  });
558
572
  };
559
573
 
560
- // node_modules/.pnpm/path-browserify-esm@1.0.6/node_modules/path-browserify-esm/index.esm.js
574
+ // ../../node_modules/.pnpm/path-browserify-esm@1.0.6/node_modules/path-browserify-esm/index.esm.js
561
575
  function assertPath(path) {
562
576
  if (typeof path !== "string") {
563
577
  throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
@@ -1,4 +1,4 @@
1
- // node_modules/.pnpm/@kevisual+query@0.0.53/node_modules/@kevisual/query/dist/query-browser.js
1
+ // ../../node_modules/.pnpm/@kevisual+query@0.0.55/node_modules/@kevisual/query/dist/query-browser.js
2
2
  var isTextForContentType = (contentType) => {
3
3
  if (!contentType)
4
4
  return false;
@@ -201,10 +201,6 @@ class Query {
201
201
  });
202
202
  }
203
203
  }
204
- const headers2 = req.headers || {};
205
- if (options?.token && !headers2["Authorization"]) {
206
- headers2["Authorization"] = `Bearer ${options.token}`;
207
- }
208
204
  } catch (e) {
209
205
  console.error("request beforeFn error", e, req);
210
206
  return wrapperError({
@@ -265,20 +261,20 @@ class Query {
265
261
  this.afterResponse = fn;
266
262
  }
267
263
  async fetchText(urlOrOptions, options) {
268
- let _options = { method: "GET", ...options };
264
+ let _options = { ...options };
269
265
  if (typeof urlOrOptions === "string" && !_options.url) {
270
266
  _options.url = urlOrOptions;
271
267
  }
272
268
  if (typeof urlOrOptions === "object") {
273
269
  _options = { ...urlOrOptions, ..._options };
274
270
  }
275
- const headers = { ...this.headers, ..._options.headers };
276
- if (options?.token && !headers["Authorization"] && _options.method !== "GET") {
277
- headers["Authorization"] = `Bearer ${options.token}`;
278
- }
279
271
  const res = await adapter({
272
+ method: "GET",
280
273
  ..._options,
281
- headers
274
+ headers: {
275
+ ...this.headers,
276
+ ..._options?.headers || {}
277
+ }
282
278
  });
283
279
  if (res && !res.code) {
284
280
  return {
@@ -1,4 +1,4 @@
1
- // node_modules/.pnpm/@kevisual+query@0.0.53/node_modules/@kevisual/query/dist/query-browser.js
1
+ // ../../node_modules/.pnpm/@kevisual+query@0.0.55/node_modules/@kevisual/query/dist/query-browser.js
2
2
  var isTextForContentType = (contentType) => {
3
3
  if (!contentType)
4
4
  return false;
@@ -201,10 +201,6 @@ class Query {
201
201
  });
202
202
  }
203
203
  }
204
- const headers2 = req.headers || {};
205
- if (options?.token && !headers2["Authorization"]) {
206
- headers2["Authorization"] = `Bearer ${options.token}`;
207
- }
208
204
  } catch (e) {
209
205
  console.error("request beforeFn error", e, req);
210
206
  return wrapperError({
@@ -265,20 +261,20 @@ class Query {
265
261
  this.afterResponse = fn;
266
262
  }
267
263
  async fetchText(urlOrOptions, options) {
268
- let _options = { method: "GET", ...options };
264
+ let _options = { ...options };
269
265
  if (typeof urlOrOptions === "string" && !_options.url) {
270
266
  _options.url = urlOrOptions;
271
267
  }
272
268
  if (typeof urlOrOptions === "object") {
273
269
  _options = { ...urlOrOptions, ..._options };
274
270
  }
275
- const headers = { ...this.headers, ..._options.headers };
276
- if (options?.token && !headers["Authorization"] && _options.method !== "GET") {
277
- headers["Authorization"] = `Bearer ${options.token}`;
278
- }
279
271
  const res = await adapter({
272
+ method: "GET",
280
273
  ..._options,
281
- headers
274
+ headers: {
275
+ ...this.headers,
276
+ ..._options?.headers || {}
277
+ }
282
278
  });
283
279
  if (res && !res.code) {
284
280
  return {
@@ -290,7 +286,7 @@ class Query {
290
286
  }
291
287
  }
292
288
 
293
- // node_modules/.pnpm/@kevisual+router@0.1.1/node_modules/@kevisual/router/dist/router-define.js
289
+ // ../../node_modules/.pnpm/@kevisual+router@0.1.6/node_modules/@kevisual/router/dist/router-define.js
294
290
  class Chain {
295
291
  object;
296
292
  app;
@@ -439,7 +435,7 @@ var shopDefine = QueryUtil.create({
439
435
  }
440
436
  });
441
437
 
442
- // node_modules/.pnpm/@kevisual+query@0.0.53/node_modules/@kevisual/query/dist/query.js
438
+ // ../../node_modules/.pnpm/@kevisual+query@0.0.55/node_modules/@kevisual/query/dist/query.js
443
439
  class BaseQuery {
444
440
  query;
445
441
  queryDefine;
@@ -204,10 +204,6 @@ class Query {
204
204
  });
205
205
  }
206
206
  }
207
- const headers2 = req.headers || {};
208
- if (options?.token && !headers2["Authorization"]) {
209
- headers2["Authorization"] = `Bearer ${options.token}`;
210
- }
211
207
  } catch (e) {
212
208
  console.error("request beforeFn error", e, req);
213
209
  return wrapperError({
@@ -268,20 +264,20 @@ class Query {
268
264
  this.afterResponse = fn;
269
265
  }
270
266
  async fetchText(urlOrOptions, options) {
271
- let _options = { method: "GET", ...options };
267
+ let _options = { ...options };
272
268
  if (typeof urlOrOptions === "string" && !_options.url) {
273
269
  _options.url = urlOrOptions;
274
270
  }
275
271
  if (typeof urlOrOptions === "object") {
276
272
  _options = { ...urlOrOptions, ..._options };
277
273
  }
278
- const headers = { ...this.headers, ..._options.headers };
279
- if (options?.token && !headers["Authorization"] && _options.method !== "GET") {
280
- headers["Authorization"] = `Bearer ${options.token}`;
281
- }
282
274
  const res = await adapter({
275
+ method: "GET",
283
276
  ..._options,
284
- headers
277
+ headers: {
278
+ ...this.headers,
279
+ ..._options?.headers || {}
280
+ }
285
281
  });
286
282
  if (res && !res.code) {
287
283
  return {
@@ -367,8 +363,7 @@ class QueryMark extends QueryMarkBase {
367
363
  return super.updateMark(data, opts);
368
364
  }
369
365
  }
370
-
371
- // node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/uniqBy.mjs
366
+ // ../../node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/uniqBy.mjs
372
367
  function uniqBy(arr, mapper) {
373
368
  const map = new Map;
374
369
  for (let i = 0;i < arr.length; i++) {
@@ -1,4 +1,4 @@
1
- // node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
1
+ // ../../node_modules/.pnpm/nanoid@5.1.7/node_modules/nanoid/index.js
2
2
  import { webcrypto as crypto2 } from "node:crypto";
3
3
  var POOL_SIZE_MULTIPLIER = 128;
4
4
  var pool;
@@ -40,7 +40,7 @@ function customAlphabet(alphabet, size = 21) {
40
40
  return customRandom(alphabet, size, random);
41
41
  }
42
42
 
43
- // node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js
43
+ // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js
44
44
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
45
45
  var _32n = /* @__PURE__ */ BigInt(32);
46
46
  function fromBig(n, le = false) {
@@ -63,7 +63,7 @@ var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
63
63
  var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
64
64
  var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
65
65
 
66
- // node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
66
+ // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
67
67
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
68
68
  function isBytes(a) {
69
69
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
@@ -131,7 +131,7 @@ var oidNist = (suffix) => ({
131
131
  oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
132
132
  });
133
133
 
134
- // node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha3.js
134
+ // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha3.js
135
135
  var _0n = BigInt(0);
136
136
  var _1n = BigInt(1);
137
137
  var _2n = BigInt(2);
@@ -316,7 +316,7 @@ class Keccak {
316
316
  var genKeccak = (suffix, blockLen, outputLen, info = {}) => createHasher(() => new Keccak(blockLen, suffix, outputLen), info);
317
317
  var sha3_512 = /* @__PURE__ */ genKeccak(6, 72, 64, /* @__PURE__ */ oidNist(10));
318
318
 
319
- // node_modules/.pnpm/bignumber.js@9.3.1/node_modules/bignumber.js/bignumber.mjs
319
+ // ../../node_modules/.pnpm/bignumber.js@9.3.1/node_modules/bignumber.js/bignumber.mjs
320
320
  var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
321
321
  var mathceil = Math.ceil;
322
322
  var mathfloor = Math.floor;
@@ -1766,7 +1766,7 @@ function toFixedPoint(str, e, z) {
1766
1766
  var BigNumber = clone();
1767
1767
  var bignumber_default = BigNumber;
1768
1768
 
1769
- // node_modules/.pnpm/@paralleldrive+cuid2@3.3.0/node_modules/@paralleldrive/cuid2/src/index.js
1769
+ // ../../node_modules/.pnpm/@paralleldrive+cuid2@3.3.0/node_modules/@paralleldrive/cuid2/src/index.js
1770
1770
  var defaultLength = 24;
1771
1771
  var bigLength = 32;
1772
1772
  var createRandom = () => {
package/dist/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- // node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.browser.js
1
+ // ../../node_modules/.pnpm/nanoid@5.1.7/node_modules/nanoid/index.browser.js
2
2
  var random = (bytes) => crypto.getRandomValues(new Uint8Array(bytes));
3
3
  var customRandom = (alphabet, defaultSize, getRandom) => {
4
4
  let mask = (2 << Math.log2(alphabet.length - 1)) - 1;
@@ -18,7 +18,7 @@ var customRandom = (alphabet, defaultSize, getRandom) => {
18
18
  };
19
19
  var customAlphabet = (alphabet, size = 21) => customRandom(alphabet, size | 0, random);
20
20
 
21
- // node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js
21
+ // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js
22
22
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
23
23
  var _32n = /* @__PURE__ */ BigInt(32);
24
24
  function fromBig(n, le = false) {
@@ -41,7 +41,7 @@ var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
41
41
  var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
42
42
  var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
43
43
 
44
- // node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
44
+ // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
45
45
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
46
46
  function isBytes(a) {
47
47
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
@@ -109,7 +109,7 @@ var oidNist = (suffix) => ({
109
109
  oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
110
110
  });
111
111
 
112
- // node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha3.js
112
+ // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha3.js
113
113
  var _0n = BigInt(0);
114
114
  var _1n = BigInt(1);
115
115
  var _2n = BigInt(2);
@@ -294,7 +294,7 @@ class Keccak {
294
294
  var genKeccak = (suffix, blockLen, outputLen, info = {}) => createHasher(() => new Keccak(blockLen, suffix, outputLen), info);
295
295
  var sha3_512 = /* @__PURE__ */ genKeccak(6, 72, 64, /* @__PURE__ */ oidNist(10));
296
296
 
297
- // node_modules/.pnpm/bignumber.js@9.3.1/node_modules/bignumber.js/bignumber.mjs
297
+ // ../../node_modules/.pnpm/bignumber.js@9.3.1/node_modules/bignumber.js/bignumber.mjs
298
298
  var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
299
299
  var mathceil = Math.ceil;
300
300
  var mathfloor = Math.floor;
@@ -1744,7 +1744,7 @@ function toFixedPoint(str, e, z) {
1744
1744
  var BigNumber = clone();
1745
1745
  var bignumber_default = BigNumber;
1746
1746
 
1747
- // node_modules/.pnpm/@paralleldrive+cuid2@3.3.0/node_modules/@paralleldrive/cuid2/src/index.js
1747
+ // ../../node_modules/.pnpm/@paralleldrive+cuid2@3.3.0/node_modules/@paralleldrive/cuid2/src/index.js
1748
1748
  var defaultLength = 24;
1749
1749
  var bigLength = 32;
1750
1750
  var createRandom = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/api",
3
- "version": "0.0.64",
3
+ "version": "0.0.65",
4
4
  "description": "",
5
5
  "main": "mod.ts",
6
6
  "scripts": {
@@ -23,13 +23,13 @@
23
23
  "devDependencies": {
24
24
  "@kevisual/cache": "^0.0.5",
25
25
  "@kevisual/code-builder": "^0.0.6",
26
- "@kevisual/query": "^0.0.53",
27
- "@kevisual/remote-app": "^0.0.6",
28
- "@kevisual/router": "^0.1.1",
26
+ "@kevisual/query": "^0.0.55",
27
+ "@kevisual/remote-app": "^0.0.7",
28
+ "@kevisual/router": "^0.1.6",
29
29
  "@kevisual/types": "^0.0.12",
30
30
  "@kevisual/use-config": "^1.0.30",
31
- "@types/bun": "^1.3.10",
32
- "@types/node": "^25.4.0",
31
+ "@types/bun": "^1.3.11",
32
+ "@types/node": "^25.5.0",
33
33
  "@types/spark-md5": "^3.0.5",
34
34
  "dotenv": "^17.3.1",
35
35
  "fast-glob": "^3.3.3",
@@ -43,11 +43,12 @@
43
43
  "es-toolkit": "^1.45.1",
44
44
  "eventemitter3": "^5.0.4",
45
45
  "fuse.js": "^7.1.0",
46
- "nanoid": "^5.1.6",
46
+ "idb-keyval": "^6.2.2",
47
+ "nanoid": "^5.1.7",
47
48
  "path-browserify-esm": "^1.0.6",
48
49
  "sonner": "^2.0.7",
49
50
  "spark-md5": "^3.0.2",
50
- "zustand": "^5.0.11"
51
+ "zustand": "^5.0.12"
51
52
  },
52
53
  "exports": {
53
54
  ".": "./mod.ts",
@@ -383,6 +383,10 @@ export class QueryLogin<T extends Cache = Cache> extends BaseQuery {
383
383
  if (res.code === 200) {
384
384
  // 刷新成功,返回新的token
385
385
  return res.data?.accessToken || null;
386
+ } else {
387
+ // remove local token
388
+ this.storage.removeItem('token');
389
+ await this.cacheStore.clearCurrentUser();
386
390
  }
387
391
  return null;
388
392
  }