@ichaingo/request 1.2.8 → 1.2.9

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/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import x, { isAxiosError as C, AxiosError as A } from "axios";
2
- import $ from "qs";
3
- import N from "js-cookie";
4
- import { logger as _ } from "@ichaingo/logger";
5
- import O, { isTokenExpired as q, getToken as b } from "@ichaingo/token";
6
- const P = () => /^(zh-hans|zh-cn|zh-sg|zh-my)$/.test(window == null ? void 0 : window.navigator.language.toLowerCase()), B = () => P() ? "zh-hans" : "";
1
+ import $, { isAxiosError as C, AxiosError as w } from "axios";
2
+ import N from "qs";
3
+ import x from "js-cookie";
4
+ import { logger as R } from "@ichaingo/logger";
5
+ import q, { isTokenExpired as O, getToken as b } from "@ichaingo/token";
6
+ const B = () => /^(zh-hans|zh-cn|zh-sg|zh-my)$/.test(window == null ? void 0 : window.navigator.language.toLowerCase()), P = () => B() ? "zh-hans" : "";
7
7
  async function S(e) {
8
8
  var n;
9
9
  let t = "", o = "";
@@ -23,13 +23,13 @@ async function S(e) {
23
23
  console.error("Error accessing cookies in server component:", s);
24
24
  }
25
25
  } else
26
- t = N.get("access_token") || "", o = N.get("NEXT_LOCALE") || B() || "en";
26
+ t = x.get("access_token") || "", o = x.get("NEXT_LOCALE") || P() || "en";
27
27
  const i = e.headers.isRefreshToken;
28
28
  return e.headers["Accept-Language"] = o, t && !i && (e.headers.Authorization = `Bearer ${t}`), e.headers.devicetype = 1, e;
29
29
  }
30
- function H(e) {
31
- var g, r, I, T, y, h, f, L, U, v, k;
32
- const t = (r = (g = e.config) == null ? void 0 : g.method) == null ? void 0 : r.toUpperCase(), o = ((I = e.config) == null ? void 0 : I.baseURL) || "", i = (T = e.config) != null && T.url ? `${o || ""}${e.config.url}` : "", n = (y = e.response) == null ? void 0 : y.status, c = (h = e.response) == null ? void 0 : h.statusText, s = (f = e.response) == null ? void 0 : f.data, a = ((U = (L = e.response) == null ? void 0 : L.headers) == null ? void 0 : U["x-request-id"]) || ((v = s == null ? void 0 : s.status) == null ? void 0 : v.requestId), u = (s == null ? void 0 : s.message) || (s == null ? void 0 : s.msg) || ((k = s == null ? void 0 : s.status) == null ? void 0 : k.msg), m = [
30
+ function z(e) {
31
+ var g, r, T, y, L, h, f, _, I, v, k;
32
+ const t = (r = (g = e.config) == null ? void 0 : g.method) == null ? void 0 : r.toUpperCase(), o = ((T = e.config) == null ? void 0 : T.baseURL) || "", i = (y = e.config) != null && y.url ? `${o || ""}${e.config.url}` : "", n = (L = e.response) == null ? void 0 : L.status, c = (h = e.response) == null ? void 0 : h.statusText, s = (f = e.response) == null ? void 0 : f.data, a = ((I = (_ = e.response) == null ? void 0 : _.headers) == null ? void 0 : I["x-request-id"]) || ((v = s == null ? void 0 : s.status) == null ? void 0 : v.requestId), u = (s == null ? void 0 : s.message) || (s == null ? void 0 : s.msg) || ((k = s == null ? void 0 : s.status) == null ? void 0 : k.msg), m = [
33
33
  n ? `HTTP ${n}` : "HTTP ERROR",
34
34
  t,
35
35
  i,
@@ -58,34 +58,34 @@ function E(e) {
58
58
  responseData: (r = e.response) == null ? void 0 : r.data
59
59
  };
60
60
  }
61
- function w(e) {
61
+ function A(e) {
62
62
  var n, c, s, a;
63
- const t = C(e) ? e : new A(String(e));
63
+ const t = C(e) ? e : new w(String(e));
64
64
  if (t.code === "ECONNABORTED" || /timeout/i.test(t.message || "")) {
65
65
  const u = (c = (n = t.config) == null ? void 0 : n.method) == null ? void 0 : c.toUpperCase(), m = ((s = t.config) == null ? void 0 : s.baseURL) || "", d = (a = t.config) != null && a.url ? `${m || ""}${t.config.url}` : "", l = ["TIMEOUT", u, d].filter(Boolean).join(" | ");
66
- return t.summary = l, t.details = JSON.stringify(E(t)), _.error({ message: l, details: t.details, errType: "timeout" }), Promise.reject(t);
66
+ return t.summary = l, t.details = JSON.stringify(E(t)), R.error({ message: l, details: t.details, errType: "timeout" }), Promise.reject(t);
67
67
  }
68
- const i = H(t);
69
- return t.summary = i, t.details = JSON.stringify(E(t)), _.error({ message: i, details: t.details, errType: "server error" }), Promise.reject(t);
68
+ const i = z(t);
69
+ return t.summary = i, t.details = JSON.stringify(E(t)), R.error({ message: i, details: t.details, errType: "server error" }), Promise.reject(t);
70
70
  }
71
- function z(e) {
71
+ function H(e) {
72
72
  var o, i, n, c, s, a, u, m, d, l;
73
73
  if (e.config.returnFullResponse)
74
74
  return e;
75
75
  if (e.status === 401)
76
- return O.removeAllToken(), window.location.href = `${process.env.NEXT_PUBLIC_AUTH_URL}/login`, e;
76
+ return q.removeAllToken(), window.location.href = `${process.env.NEXT_PUBLIC_AUTH_URL}/login`, e;
77
77
  if (e.status === 200) {
78
78
  if ((o = e.headers["content-type"]) != null && o.includes("text/event-stream"))
79
79
  return e;
80
80
  const g = e.data, r = g.status;
81
81
  if (r && typeof r.code == "number" && ![0, 200].includes(r.code)) {
82
- const I = new A(
82
+ const T = new w(
83
83
  (r == null ? void 0 : r.msg) || "Business error",
84
84
  String(r.code),
85
85
  e.config,
86
86
  e.request,
87
87
  e
88
- ), T = `BIZ ${r.code} | ${(n = (i = e.config) == null ? void 0 : i.method) == null ? void 0 : n.toUpperCase()} | ${((c = e.config) == null ? void 0 : c.baseURL) || ""}${((s = e.config) == null ? void 0 : s.url) || ""} | server: ${r == null ? void 0 : r.msg}`, y = {
88
+ ), y = `BIZ ${r.code} | ${(n = (i = e.config) == null ? void 0 : i.method) == null ? void 0 : n.toUpperCase()} | ${((c = e.config) == null ? void 0 : c.baseURL) || ""}${((s = e.config) == null ? void 0 : s.url) || ""} | server: ${r == null ? void 0 : r.msg}`, L = {
89
89
  method: (u = (a = e.config) == null ? void 0 : a.method) == null ? void 0 : u.toUpperCase(),
90
90
  url: (m = e.config) != null && m.baseURL ? `${e.config.baseURL}${e.config.url || ""}` : e.config.url,
91
91
  params: (d = e.config) == null ? void 0 : d.params,
@@ -104,23 +104,25 @@ function z(e) {
104
104
  requestId: ((l = e.headers) == null ? void 0 : l["x-request-id"]) || (r == null ? void 0 : r.requestId),
105
105
  responseData: g
106
106
  };
107
- throw process.env.NODE_ENV !== "development" && _.error({ summary: T, details: y, errType: "business error" }), I;
107
+ throw process.env.NODE_ENV !== "development" && R.error({ summary: y, details: L, errType: "business error" }), T;
108
108
  }
109
109
  return g;
110
110
  }
111
111
  return e;
112
112
  }
113
113
  let p = null;
114
- const j = x.create({
115
- baseURL: process.env.ICHAINGO_INNER_API_URL || process.env.NEXT_PUBLIC_ICHAINGO_API_URL,
114
+ const j = $.create({
115
+ baseURL: process.env.NEXT_PUBLIC_AUTH_URL,
116
116
  timeout: 1e4,
117
+ withCredentials: !0,
118
+ // Always include credentials by default
117
119
  paramsSerializer: function(e) {
118
- return $.stringify(e, { arrayFormat: "brackets" });
120
+ return N.stringify(e, { arrayFormat: "brackets" });
119
121
  }
120
122
  });
121
123
  async function M(e) {
122
124
  const t = e.headers;
123
- return p ? (await p, e) : (q() && (p = (async () => {
125
+ return p ? (await p, e) : (O() && (p = (async () => {
124
126
  await j.get("/api/refresh/token", {
125
127
  params: {
126
128
  grant_type: "refresh_token",
@@ -134,18 +136,18 @@ async function M(e) {
134
136
  p = null;
135
137
  }), await p), e);
136
138
  }
137
- const R = x.create({
139
+ const U = $.create({
138
140
  baseURL: process.env.ICHAINGO_INNER_API_URL || process.env.NEXT_PUBLIC_ICHAINGO_API_URL,
139
141
  timeout: 1e4,
140
142
  withCredentials: !0,
141
143
  // Always include credentials by default
142
144
  paramsSerializer: function(e) {
143
- return $.stringify(e, { arrayFormat: "brackets" });
145
+ return N.stringify(e, { arrayFormat: "brackets" });
144
146
  }
145
147
  });
146
- R.interceptors.request.use(M);
147
- R.interceptors.request.use(S, w);
148
- R.interceptors.response.use(z, w);
148
+ U.interceptors.request.use(M);
149
+ U.interceptors.request.use(S, A);
150
+ U.interceptors.response.use(H, A);
149
151
  export {
150
- R as default
152
+ U as default
151
153
  };
@@ -1 +1 @@
1
- {"version":3,"file":"refreshToken.d.ts","sourceRoot":"","sources":["../../src/interceptors/refreshToken.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,0BAA0B,EAAE,MAAM,OAAO,CAAC;AAW1D,wBAA8B,YAAY,CACxC,MAAM,EAAE,0BAA0B,4CA0BnC"}
1
+ {"version":3,"file":"refreshToken.d.ts","sourceRoot":"","sources":["../../src/interceptors/refreshToken.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,0BAA0B,EAAE,MAAM,OAAO,CAAC;AAY1D,wBAA8B,YAAY,CACxC,MAAM,EAAE,0BAA0B,4CA0BnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ichaingo/request",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -22,8 +22,8 @@
22
22
  "js-cookie": "3.0.5",
23
23
  "next": "^15.4.5",
24
24
  "qs": "6.14.0",
25
- "@ichaingo/logger": "1.2.8",
26
- "@ichaingo/token": "1.2.8"
25
+ "@ichaingo/logger": "1.2.9",
26
+ "@ichaingo/token": "1.2.9"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/js-cookie": "^3.0.6",