@snack-kit/lib 0.3.0 → 0.4.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.
@@ -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.3.0";
11628
+ var version = "0.4.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 DEBUGGER_ACTIVE_KEY = "__snackkit_debugger__active";
15379
15380
  var HttpContext = class {
15380
15381
  constructor() {
15381
15382
  this._store = /* @__PURE__ */ new Map();
@@ -15384,12 +15385,24 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
15384
15385
  /**
15385
15386
  * 加载服务地址映射
15386
15387
  *
15388
+ * 支持三种调用方式:
15389
+ * - **传入字符串**:作为网关地址,自动请求 `GET /ngw/context` 获取映射表
15390
+ * - **传入对象**:直接注入键值映射,不发起网络请求
15391
+ * - **不传参数**:
15392
+ * - 生产环境(`NODE_ENV === 'production'`):以当前页面 `Origin` 为网关地址自动加载
15393
+ * - 开发环境:立即返回,不做任何操作(应由 `Debugger.init()` 接管加载流程)
15394
+ *
15387
15395
  * 远程加载时,响应中的 `$info` 元数据字段会被单独存储,不计入路由映射表。
15388
15396
  *
15389
- * @param source 远程加载传入网关 URL;本地注入传入键值对象
15397
+ * @param source 网关 URL / 键值对象 / 省略
15390
15398
  * @param timeout 远程加载超时(ms),默认 5000
15391
15399
  *
15392
- * @example 远程加载
15400
+ * @example 不传参——生产环境自动使用当前页面 Origin
15401
+ * ```ts
15402
+ * await Context.load()
15403
+ * ```
15404
+ *
15405
+ * @example 传入网关地址
15393
15406
  * ```ts
15394
15407
  * await Context.load('http://172.16.32.155:20000', 3000)
15395
15408
  * ```
@@ -15400,6 +15413,11 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
15400
15413
  * ```
15401
15414
  */
15402
15415
  async load(source, timeout = 5e3) {
15416
+ if (source === void 0) {
15417
+ if (globalThis[DEBUGGER_ACTIVE_KEY]) return;
15418
+ if (!Origin) return;
15419
+ source = Origin;
15420
+ }
15403
15421
  if (typeof source === "string") {
15404
15422
  const url2 = `${source}/ngw/context`;
15405
15423
  const res = await axios_default.get(url2, { timeout });
@@ -15553,20 +15571,35 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
15553
15571
  Unregister(cancelId);
15554
15572
  }
15555
15573
  }
15556
- function Get(url2, config) {
15557
- return Request({ ...config, method: "GET", url: url2 });
15574
+ function Get(urlOrConfig, config) {
15575
+ if (typeof urlOrConfig === "string") {
15576
+ return Request({ ...config, method: "GET", url: urlOrConfig });
15577
+ }
15578
+ return Request({ ...urlOrConfig, method: "GET" });
15558
15579
  }
15559
- function Post(url2, data, config) {
15560
- return Request({ ...config, method: "POST", url: url2, data });
15580
+ function Post(urlOrConfig, data, config) {
15581
+ if (typeof urlOrConfig === "string") {
15582
+ return Request({ ...config, method: "POST", url: urlOrConfig, data });
15583
+ }
15584
+ return Request({ ...urlOrConfig, method: "POST" });
15561
15585
  }
15562
- function Put(url2, data, config) {
15563
- return Request({ ...config, method: "PUT", url: url2, data });
15586
+ function Put(urlOrConfig, data, config) {
15587
+ if (typeof urlOrConfig === "string") {
15588
+ return Request({ ...config, method: "PUT", url: urlOrConfig, data });
15589
+ }
15590
+ return Request({ ...urlOrConfig, method: "PUT" });
15564
15591
  }
15565
- function Patch(url2, data, config) {
15566
- return Request({ ...config, method: "PATCH", url: url2, data });
15592
+ function Patch(urlOrConfig, data, config) {
15593
+ if (typeof urlOrConfig === "string") {
15594
+ return Request({ ...config, method: "PATCH", url: urlOrConfig, data });
15595
+ }
15596
+ return Request({ ...urlOrConfig, method: "PATCH" });
15567
15597
  }
15568
- function Del(url2, config) {
15569
- return Request({ ...config, method: "DELETE", url: url2 });
15598
+ function Del(urlOrConfig, config) {
15599
+ if (typeof urlOrConfig === "string") {
15600
+ return Request({ ...config, method: "DELETE", url: urlOrConfig });
15601
+ }
15602
+ return Request({ ...urlOrConfig, method: "DELETE" });
15570
15603
  }
15571
15604
 
15572
15605
  // src/debugger/debugger.ts
@@ -16139,6 +16172,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
16139
16172
  * ```
16140
16173
  */
16141
16174
  static async init(options) {
16175
+ globalThis[DEBUGGER_ACTIVE_KEY] = true;
16142
16176
  const instance = new _Debugger({ timeout: 1e4, ...options });
16143
16177
  instance.injectStyle();
16144
16178
  instance.buildDOM();
@@ -16679,6 +16713,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
16679
16713
  exports.CleanObject = CleanObject;
16680
16714
  exports.Context = Context;
16681
16715
  exports.Ctx = Ctx;
16716
+ exports.DEBUGGER_ACTIVE_KEY = DEBUGGER_ACTIVE_KEY;
16682
16717
  exports.Debounce = Debounce;
16683
16718
  exports.Debugger = Debugger;
16684
16719
  exports.DeepClone = DeepClone;