@snack-kit/lib 0.5.0 → 0.7.0

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.
Files changed (38) hide show
  1. package/README.md +22 -0
  2. package/dist/cjs/{chunk-ZJMTV2GJ.cjs → chunk-LQ5WJVQX.cjs} +40 -29
  3. package/dist/cjs/chunk-LQ5WJVQX.cjs.map +1 -0
  4. package/dist/cjs/chunk-UM4J7HF4.cjs +123 -0
  5. package/dist/cjs/chunk-UM4J7HF4.cjs.map +1 -0
  6. package/dist/cjs/{chunk-XEQEQWDB.cjs → chunk-UNFUIZVY.cjs} +4 -109
  7. package/dist/cjs/chunk-UNFUIZVY.cjs.map +1 -0
  8. package/dist/cjs/debugger.cjs +4 -4
  9. package/dist/cjs/http.cjs +29 -29
  10. package/dist/cjs/index.cjs +35 -35
  11. package/dist/cjs/index.cjs.map +1 -1
  12. package/dist/es/chunk-2YYI2T2B.js +105 -0
  13. package/dist/es/chunk-2YYI2T2B.js.map +1 -0
  14. package/dist/es/{chunk-YV6SGXUJ.js → chunk-M5R2NQYU.js} +6 -103
  15. package/dist/es/chunk-M5R2NQYU.js.map +1 -0
  16. package/dist/es/{chunk-4SGFAIRT.js → chunk-YXJTZURC.js} +33 -26
  17. package/dist/es/chunk-YXJTZURC.js.map +1 -0
  18. package/dist/es/debugger.js +2 -2
  19. package/dist/es/http.js +2 -2
  20. package/dist/es/index.js +4 -4
  21. package/dist/es/index.js.map +1 -1
  22. package/dist/types/debugger.d.ts +16 -11
  23. package/dist/types/index.d.ts +1 -1
  24. package/dist/umd/debugger.global.js +49 -104
  25. package/dist/umd/debugger.global.js.map +1 -1
  26. package/dist/umd/http.global.js +2 -1
  27. package/dist/umd/http.global.js.map +1 -1
  28. package/dist/umd/index.global.js +32 -24
  29. package/dist/umd/index.global.js.map +1 -1
  30. package/package.json +1 -1
  31. package/dist/cjs/chunk-IMHC6CTK.cjs +0 -13
  32. package/dist/cjs/chunk-IMHC6CTK.cjs.map +0 -1
  33. package/dist/cjs/chunk-XEQEQWDB.cjs.map +0 -1
  34. package/dist/cjs/chunk-ZJMTV2GJ.cjs.map +0 -1
  35. package/dist/es/chunk-4SGFAIRT.js.map +0 -1
  36. package/dist/es/chunk-MHCY2PIP.js +0 -3
  37. package/dist/es/chunk-MHCY2PIP.js.map +0 -1
  38. package/dist/es/chunk-YV6SGXUJ.js.map +0 -1
@@ -11625,7 +11625,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
11625
11625
  });
11626
11626
 
11627
11627
  // package.json
11628
- var version = "0.5.0";
11628
+ var version = "0.7.0";
11629
11629
 
11630
11630
  // node_modules/axios/lib/helpers/bind.js
11631
11631
  function bind(fn, thisArg) {
@@ -15376,6 +15376,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
15376
15376
  } = axios_default;
15377
15377
 
15378
15378
  // src/http/context.ts
15379
+ var _http = axios_default.create();
15379
15380
  var DEBUGGER_ACTIVE_KEY = "__snackkit_debugger__active";
15380
15381
  var HttpContext = class {
15381
15382
  constructor() {
@@ -15420,7 +15421,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
15420
15421
  }
15421
15422
  if (typeof source === "string") {
15422
15423
  const url2 = `${source}/ngw/context`;
15423
- const res = await axios_default.get(url2, { timeout });
15424
+ const res = await _http.get(url2, { timeout });
15424
15425
  const data = res.data;
15425
15426
  if (data && typeof data === "object") {
15426
15427
  this._store.clear();
@@ -15603,6 +15604,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
15603
15604
  }
15604
15605
 
15605
15606
  // src/debugger/debugger.ts
15607
+ var _http2 = axios_default.create();
15606
15608
  var STORAGE_PREFIX = "__snackkit_debugger__";
15607
15609
  var KEY_GATEWAY = `${STORAGE_PREFIX}gateway`;
15608
15610
  var KEY_TYPE = `${STORAGE_PREFIX}type`;
@@ -16137,24 +16139,21 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
16137
16139
  /**
16138
16140
  * 初始化并渲染调试面板
16139
16141
  *
16142
+ * 支持两种调用形式:
16143
+ * - **配置对象**:传入 `DebuggerOptions`,可配置网关列表和超时时间
16144
+ * - **数组简写**:直接传入网关 URL 数组,等价于 `{ gateways: [...] }`
16145
+ *
16140
16146
  * 调用后在页面右下角插入浮动按钮,点击展开调试面板。
16141
16147
  * 面板支持:选择调试网关、切换目标服务、查看并复制路由 ctx。
16142
16148
  * 网关/服务选择通过 `localStorage` 持久化,刷新后自动恢复。
16143
16149
  *
16144
- * @param options 配置项
16150
+ * @param options 配置对象 或 网关 URL 数组
16145
16151
  *
16146
- * @example 单网关
16152
+ * @example 配置对象形式
16147
16153
  * ```ts
16148
16154
  * import { Debugger } from '@snack-kit/lib/debugger'
16149
16155
  *
16150
16156
  * await Debugger.init({
16151
- * gateways: 'http://dev-gateway.example.com',
16152
- * })
16153
- * ```
16154
- *
16155
- * @example 多网关(开发/测试环境切换)
16156
- * ```ts
16157
- * await Debugger.init({
16158
16157
  * gateways: [
16159
16158
  * 'http://dev-gateway.example.com',
16160
16159
  * 'http://test-gateway.example.com',
@@ -16163,17 +16162,26 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
16163
16162
  * })
16164
16163
  * ```
16165
16164
  *
16165
+ * @example 数组简写形式
16166
+ * ```ts
16167
+ * await Debugger.init([
16168
+ * 'http://dev-gateway.example.com',
16169
+ * 'http://test-gateway.example.com',
16170
+ * ])
16171
+ * ```
16172
+ *
16166
16173
  * @example 仅在非生产环境加载
16167
16174
  * ```ts
16168
16175
  * if (import.meta.env.DEV) {
16169
16176
  * const { Debugger } = await import('@snack-kit/lib/debugger')
16170
- * await Debugger.init({ gateways: 'http://dev-gateway.example.com' })
16177
+ * await Debugger.init(['http://dev-gateway.example.com'])
16171
16178
  * }
16172
16179
  * ```
16173
16180
  */
16174
16181
  static async init(options) {
16175
16182
  globalThis[DEBUGGER_ACTIVE_KEY] = true;
16176
- const instance = new _Debugger({ timeout: 1e4, ...options });
16183
+ const normalized = Array.isArray(options) ? { gateways: options } : options;
16184
+ const instance = new _Debugger({ timeout: 1e4, ...normalized });
16177
16185
  instance.injectStyle();
16178
16186
  instance.buildDOM();
16179
16187
  await instance.restoreState();
@@ -16323,19 +16331,19 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
16323
16331
  async loadServers(gwUrl) {
16324
16332
  this.setHeader("loading");
16325
16333
  this.setFooter(T.loading(), "");
16326
- const result = await Get(`${gwUrl}/web-debug/host/list`, {
16327
- cache: true,
16328
- timeout: this.options.timeout
16329
- });
16330
- if (result.error) {
16334
+ try {
16335
+ const res = await _http2.get(`${gwUrl}/web-debug/host/list`, {
16336
+ timeout: this.options.timeout
16337
+ });
16338
+ this.servers = res.data ?? [];
16339
+ this.renderTypeOptions();
16340
+ this.setHeader("ok");
16341
+ this.setFooter(T.loaded(this.servers.length), "ok");
16342
+ } catch (err) {
16343
+ const message = err instanceof Error ? err.message : String(err);
16331
16344
  this.setHeader("err");
16332
- this.setFooter(T.loadFailed(result.error.message), "err");
16333
- return;
16345
+ this.setFooter(T.loadFailed(message), "err");
16334
16346
  }
16335
- this.servers = result.data ?? [];
16336
- this.renderTypeOptions();
16337
- this.setHeader("ok");
16338
- this.setFooter(T.loaded(this.servers.length), "ok");
16339
16347
  }
16340
16348
  /** 渲染标签选项 */
16341
16349
  renderTypeOptions() {