@seayoo-web/kms 2.0.0 → 2.0.1

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/README.md CHANGED
@@ -3,4 +3,5 @@
3
3
  - dsi 查询工具
4
4
  - `queryDsi` 以 ajax 方式查询 dsi 数据
5
5
  - `jsonpDsi` 以 jsonp 方式查询 dsi 数据
6
+ - `jsonxDsi` 以 script 方式查询 dsi 数据
6
7
  - `convertDsiParam` 工具函数,将 dsi query 参数转成 request param
package/dist/index.js CHANGED
@@ -1,35 +1,32 @@
1
- import { NetRequest as k, jsonp as q } from "@seayoo-web/request";
2
- const { get: x } = k({ timeout: 15e3 });
3
- function b(a) {
4
- const r = {}, { group: i, filter: t, filterLogic: s, range: y, created: l, updated: j, size: m, page: A, sort: n } = a, { sn: d, fields: o, dataFields: e, multi: v, combo: w, pure: $ = "items", label: f, value: c, option: g } = a;
5
- if (d && (r.sn = d), i && (r.g = Array.isArray(i) ? i.join(",") : i), t) {
6
- const D = s === "or" ? "|" : "+", h = Object.keys(t);
7
- r.filter = h.map((p) => {
8
- const u = t[p];
1
+ import { NetRequest as L, jsonp as k, jsonx as q } from "@seayoo-web/request";
2
+ const { get: z } = L({ timeout: 15e3 });
3
+ function y(t) {
4
+ const r = {}, { group: i, filter: a, filterLogic: n, range: l, created: d, updated: m, size: A, page: $, sort: s } = t, { sn: g, fields: o, dataFields: e, multi: h, combo: v, pure: b = "items", label: f, value: c, option: w } = t;
5
+ if (g && (r.sn = g), i && (r.g = Array.isArray(i) ? i.join(",") : i), a) {
6
+ const D = n === "or" ? "|" : "+", x = Object.keys(a);
7
+ r.filter = x.map((p) => {
8
+ const u = a[p];
9
9
  return Array.isArray(u) ? `${p}:${u.join(",")}` : `${p}:${u}`;
10
10
  }).join(D);
11
11
  }
12
- return y && (r.r = y), l && (r.created = l.join("-")), j && (r.updated = j.join("-")), n && (r.sort = Array.isArray(n) ? n.join(",") : n), v === !1 && (r.m = "n"), m && (r.s = `${m}`), A && (r.p = `${A}`), o && (r.f = Array.isArray(o) ? o.join(",") : o), e && (r.df = Array.isArray(e) ? e.join(",") : e), w === !0 && (o ? r.c = "y" : console.warn("设置 combo:true 必须要同步设置 fields")), $ && (r.pure = $ === "items" ? "items" : "y"), f && (r.label = Array.isArray(f) ? f.join(",") : f), c && (r.value = Array.isArray(c) ? c.join(",") : c), g && (r.option = g), r;
12
+ return l && (r.r = l), d && (r.created = d.join("-")), m && (r.updated = m.join("-")), s && (r.sort = Array.isArray(s) ? s.join(",") : s), h === !1 && (r.m = "n"), A && (r.s = `${A}`), $ && (r.p = `${$}`), o && (r.f = Array.isArray(o) ? o.join(",") : o), e && (r.df = Array.isArray(e) ? e.join(",") : e), v === !0 && (o ? r.c = "y" : console.warn("设置 combo:true 必须要同步设置 fields")), b && (r.pure = b === "items" ? "items" : "y"), f && (r.label = Array.isArray(f) ? f.join(",") : f), c && (r.value = Array.isArray(c) ? c.join(",") : c), w && (r.option = w), r;
13
13
  }
14
- async function F({
15
- endpoint: a,
16
- key: r,
17
- query: i,
18
- guard: t
19
- }) {
20
- const { data: s } = await x(`https://${a}/${r}`, t, { params: b(i) });
21
- return s;
14
+ async function E({ endpoint: t, key: r, query: i, guard: a }) {
15
+ const { data: n } = await z(`https://${j(t)}/${r}`, a, { params: y(i) });
16
+ return n;
22
17
  }
23
- async function L({
24
- endpoint: a,
25
- key: r,
26
- query: i,
27
- guard: t
28
- }) {
29
- return await q(`https://${a}/${r}/jsonp`, t, b(i));
18
+ async function F({ endpoint: t, key: r, query: i, guard: a }) {
19
+ return await k(`https://${j(t)}/${r}/jsonp`, a, y(i));
20
+ }
21
+ async function N({ endpoint: t, key: r, query: i, guard: a }) {
22
+ return await q(`https://${j(t)}/${r}/script`, a, y(i));
23
+ }
24
+ function j(t) {
25
+ return t.replace(/(?:^https?:\/\/|\/*$)/gi, "").toLowerCase();
30
26
  }
31
27
  export {
32
- b as convertDsiParam,
33
- L as jsonpDsi,
34
- F as queryDsi
28
+ y as convertDsiParam,
29
+ F as jsonpDsi,
30
+ N as jsonxDsi,
31
+ E as queryDsi
35
32
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/kms",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "agent for seayoo.kms",
5
5
  "type": "module",
6
6
  "source": "index.ts",
@@ -1,6 +1,3 @@
1
- type DsiProdEndpoint = `${string}.dsi.seayoo.com` | "dsi.seayoo.com" | `${string}.dsi.seayoo.io` | "dsi.seayoo.io";
2
- type DsiDevEndpoint = `${string}.dsi.dev.seayoo.com` | "dsi.dev.seayoo.com" | `${string}.dsi.dev.seayoo.io` | "dsi.dev.seayoo.io";
3
- export type DsiEndpoint = DsiProdEndpoint | DsiDevEndpoint;
4
1
  type BaseFieldType = string | number | null;
5
2
  type QuerySortBaseField = "start" | "end" | "created" | "order" | "updated" | `data.${string}`;
6
3
  type QuerySortField = QuerySortBaseField | `-${QuerySortBaseField}`;
@@ -143,22 +140,26 @@ export interface DsiQueryParam {
143
140
  * 将查询配置转成 dsi 查询参数
144
141
  */
145
142
  export declare function convertDsiParam(query: DsiQueryParam): Record<string, string>;
146
- /**
147
- * 查询 Dsi 数据接口并返回接口响应
148
- */
149
- export declare function queryDsi<T = unknown>({ endpoint, key, query, guard, }: {
150
- endpoint: DsiEndpoint;
143
+ interface DsiQueryOption<T> {
144
+ /** dsi 服务器地址,比如 xxx.dsi.seayoo.com */
145
+ endpoint: string;
146
+ /** dsi key / alias */
151
147
  key: string;
148
+ /** 查询参数 */
152
149
  query: DsiQueryParam;
150
+ /** 响应数据守卫函数 */
153
151
  guard: (data: unknown) => data is T;
154
- }): Promise<T | null>;
152
+ }
153
+ /**
154
+ * 查询 Dsi 数据接口并返回接口响应
155
+ */
156
+ export declare function queryDsi<T = unknown>({ endpoint, key, query, guard }: DsiQueryOption<T>): Promise<T | null>;
155
157
  /**
156
158
  * 通过 jsonp 方式加载 dsi 数据
157
159
  */
158
- export declare function jsonpDsi<T = unknown>({ endpoint, key, query, guard, }: {
159
- endpoint: DsiEndpoint;
160
- key: string;
161
- query: DsiQueryParam;
162
- guard: (data: unknown) => data is T;
163
- }): Promise<T | null>;
160
+ export declare function jsonpDsi<T = unknown>({ endpoint, key, query, guard }: DsiQueryOption<T>): Promise<T | null>;
161
+ /**
162
+ * 通过 jsonx(script) 方式加载 dsi 数据
163
+ */
164
+ export declare function jsonxDsi<T = unknown>({ endpoint, key, query, guard }: DsiQueryOption<T>): Promise<T | null>;
164
165
  export {};