egova-admin-jssdk 0.1.0 → 0.1.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.
@@ -74,7 +74,8 @@ export function getPublicKey() {
74
74
  */
75
75
  export async function changeUserCryptogram(oldPwd, newPwd) {
76
76
  if (!saltData.publicKey) {
77
- const publicKeyRes = await getPublicKey();
77
+ const bodyReponse = await getPublicKey();
78
+ const publicKeyRes = bodyReponse?.data || {};
78
79
  if (publicKeyRes && !publicKeyRes.hasError) {
79
80
  const data = publicKeyRes.result?.data || [];
80
81
  if (data && data.length === 2) {
@@ -6,7 +6,7 @@ import { random as j, merge as d, isNil as m } from "lodash-es";
6
6
  import P from "crypto-js";
7
7
  import O from "qs";
8
8
  import { sm4 as K, sm2 as v } from "sm-crypto";
9
- /*! egova-admin-jssdk v0.0.11 */
9
+ /*! egova-admin-jssdk v0.1.1 */
10
10
  function C(r) {
11
11
  return r instanceof Element ? "element" : Object.prototype.toString.call(r).replace(/\[object\s(.+)\]/, "$1").toLowerCase();
12
12
  }
@@ -44,11 +44,11 @@ class N {
44
44
  */
45
45
  getRandomPassword(t) {
46
46
  const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", n = "abcdefghijklmnopqrstuvwxyz", o = "0123456789", s = ".~!@#$%^&*)(_+}{|:?><", i = e + n + o + s;
47
- let a = "";
48
- a += this.getRandomChar(e), a += this.getRandomChar(n), a += this.getRandomChar(o), a += this.getRandomChar(s);
49
- for (let c = a.length; c < t; c++)
50
- a += this.getRandomChar(i);
51
- return a = a.split("").sort(() => j(!0) - 0.5).join(""), a;
47
+ let c = "";
48
+ c += this.getRandomChar(e), c += this.getRandomChar(n), c += this.getRandomChar(o), c += this.getRandomChar(s);
49
+ for (let a = c.length; a < t; a++)
50
+ c += this.getRandomChar(i);
51
+ return c = c.split("").sort(() => j(!0) - 0.5).join(""), c;
52
52
  }
53
53
  getRandomChar(t) {
54
54
  const e = Math.floor(j(!0) * t.length);
@@ -67,7 +67,7 @@ class H {
67
67
  return t.replace(/([^:]|^)\/{2,}/g, "$1/");
68
68
  }
69
69
  }
70
- const R = new H();
70
+ const T = new H();
71
71
  class _ {
72
72
  constructor(t) {
73
73
  /**
@@ -179,8 +179,8 @@ class _ {
179
179
  try {
180
180
  const { pathname: e, origin: n } = new URL(t, window.location.origin), o = this.urlSearchParams(t), s = this.generateSignatureOption();
181
181
  d(o, s);
182
- const i = this.sortParamByKey(o), c = `${R.cleanUrl(`/${e}`)}?${i}`, p = this.cryptoHash(c);
183
- t = `${n}${c}&signature=${p}`;
182
+ const i = this.sortParamByKey(o), a = `${T.cleanUrl(`/${e}`)}?${i}`, p = this.cryptoHash(a);
183
+ t = `${n}${a}&signature=${p}`;
184
184
  } catch {
185
185
  console.error("签名失败,请使用有效的链接", t);
186
186
  }
@@ -195,25 +195,25 @@ class _ {
195
195
  signatureConfig(t) {
196
196
  var e, n, o, s;
197
197
  try {
198
- const a = ((e = t.method) == null ? void 0 : e.toUpperCase()) === "GET", c = t.data, p = c !== null && typeof c == "object", y = ((o = (n = t.headers) == null ? void 0 : n["Content-Type"]) == null ? void 0 : o.toString()) || "", g = y.includes("multipart/form-data");
198
+ const c = ((e = t.method) == null ? void 0 : e.toUpperCase()) === "GET", a = t.data, p = a !== null && typeof a == "object", y = ((o = (n = t.headers) == null ? void 0 : n["Content-Type"]) == null ? void 0 : o.toString()) || "", g = y.includes("multipart/form-data");
199
199
  let u = y.includes("application/json");
200
- !a && !y && p && (u = !0), d(t, { headers: { "App-Id": this.appIdCode.id } });
200
+ !c && !y && p && (u = !0), d(t, { headers: { "App-Id": this.appIdCode.id } });
201
201
  const f = {}, x = this.urlSearchParams(t.url);
202
202
  if (d(f, x), !m(t.params)) {
203
203
  const S = t.params;
204
204
  this.removeNilValue(S), t.params = S, d(f, O.parse(O.stringify(S)));
205
205
  }
206
- !m(c) && p && !g && !u && d(f, c);
206
+ !m(a) && p && !g && !u && d(f, a);
207
207
  const A = this.generateSignatureOption();
208
208
  d(f, A);
209
209
  let b = this.sortParamByKey(f);
210
210
  if (u) {
211
- const S = JSON.stringify(c);
212
- this.isStringOverKB(S, 128) || (p ? b += this.formatEncodeValue(S) : b += this.formatEncodeValue(c));
211
+ const S = JSON.stringify(a);
212
+ this.isStringOverKB(S, 128) || (p ? b += this.formatEncodeValue(S) : b += this.formatEncodeValue(a));
213
213
  }
214
214
  let E = "";
215
215
  (s = t.url) != null && s.startsWith("http") ? E = t.url : E = `${t.baseURL}/${t.url || ""}`;
216
- const { pathname: U } = new URL(E, window.location.origin), B = `${R.cleanUrl(`/${U}`)}?${b}`;
216
+ const { pathname: U } = new URL(E, window.location.origin), B = `${T.cleanUrl(`/${U}`)}?${b}`;
217
217
  A.signature = this.cryptoHash(B), t.params = d({}, t.params, A);
218
218
  } catch (i) {
219
219
  console.error("签名失败", i);
@@ -279,17 +279,17 @@ class z {
279
279
  return P.enc.Hex.stringify(e);
280
280
  }
281
281
  }
282
- const I = new z(W), T = /* @__PURE__ */ new Map(), J = [
282
+ const I = new z(W), R = /* @__PURE__ */ new Map(), J = [
283
283
  {
284
284
  type: "sm2WithSalt",
285
285
  encrypt: (r, t) => {
286
286
  const { type: e, publicKey: n } = t || {};
287
287
  if (!e || !n) return;
288
- let o = T.get(e);
289
- (!o || o === "") && (o = I.cryptRandom(16), T.set(e, o));
290
- const s = I.cryptRandom(16), i = I.cryptRandom(3), a = v.doEncrypt(i + o, n, 1), c = K.encrypt(r, o, { iv: s, mode: "cbc" });
291
- if (a && c) {
292
- const p = a, y = s + c;
288
+ let o = R.get(e);
289
+ (!o || o === "") && (o = I.cryptRandom(16), R.set(e, o));
290
+ const s = I.cryptRandom(16), i = I.cryptRandom(3), c = v.doEncrypt(i + o, n, 1), a = K.encrypt(r, o, { iv: s, mode: "cbc" });
291
+ if (c && a) {
292
+ const p = c, y = s + a;
293
293
  return {
294
294
  data: p + y
295
295
  };
@@ -298,7 +298,7 @@ const I = new z(W), T = /* @__PURE__ */ new Map(), J = [
298
298
  }
299
299
  ];
300
300
  function q(r, t) {
301
- var s, i, a, c, p, y;
301
+ var s, i, c, a, p, y;
302
302
  const e = r, { changeContentTypeEnabled: n } = t || {}, o = {
303
303
  type: $.type,
304
304
  publicKey: $.publicKey
@@ -310,8 +310,8 @@ function q(r, t) {
310
310
  const u = e.data;
311
311
  if (m(u))
312
312
  return e;
313
- let x = u !== null && typeof u == "object" && Object.prototype.toString.call(u) === "[object FormData]" || ((a = (i = e.headers) == null ? void 0 : i["Content-Type"]) == null ? void 0 : a.includes("multipart/form-data"));
314
- if (x || (x = u instanceof FormData || typeof (u == null ? void 0 : u.append) == "function" && typeof (u == null ? void 0 : u.entries) == "function"), x || ((p = (c = e.headers) == null ? void 0 : c["Content-Type"]) == null ? void 0 : p.includes("application/x-www-form-urlencoded")))
313
+ let x = u !== null && typeof u == "object" && Object.prototype.toString.call(u) === "[object FormData]" || ((c = (i = e.headers) == null ? void 0 : i["Content-Type"]) == null ? void 0 : c.includes("multipart/form-data"));
314
+ if (x || (x = u instanceof FormData || typeof (u == null ? void 0 : u.append) == "function" && typeof (u == null ? void 0 : u.entries) == "function"), x || ((p = (a = e.headers) == null ? void 0 : a["Content-Type"]) == null ? void 0 : p.includes("application/x-www-form-urlencoded")))
315
315
  return e;
316
316
  const b = o.type;
317
317
  if (b && b === "sm2WithSalt") {
@@ -413,9 +413,9 @@ function X() {
413
413
  async function dt(r, t) {
414
414
  var o, s;
415
415
  if (!w.publicKey) {
416
- const i = await X();
417
- if (i && !i.hasError) {
418
- const a = ((o = i.result) == null ? void 0 : o.data) || [];
416
+ const i = await X(), c = (i == null ? void 0 : i.data) || {};
417
+ if (!c.hasError) {
418
+ const a = ((o = c.result) == null ? void 0 : o.data) || [];
419
419
  a.length === 2 && (w.type = a[0], w.publicKey = a[1]);
420
420
  }
421
421
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "egova-admin-jssdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "build": "run-p type-check build-lib build-type",