@acrool/react-fetcher 0.0.4 → 0.0.5

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.
@@ -85,9 +85,7 @@ function Gt(e) {
85
85
  var de = /* @__PURE__ */ ((e) => (e.formData = "multipart/form-data", e.formUrlDecode = "application/x-www-form-urlencoded", e.json = "application/json", e))(de || {}), Zt = /* @__PURE__ */ ((e) => (e.GET = "GET", e.POST = "POST", e.PUT = "PUT", e.DELETE = "DELETE", e.PATCH = "PATCH", e))(Zt || {});
86
86
  const Qt = (e, t = {}) => [de.formData, de.formUrlDecode].includes(e) ? Gt(t) : JSON.stringify(t), en = (e) => de.json, Vr = (e, t, n = en) => async (r) => {
87
87
  var p;
88
- const s = (t == null ? void 0 : t.method) || "", o = r == null ? void 0 : r.fetchOptions, i = typeof r == "object" && r !== null && "body" in r ? r.body : void 0, c = typeof r == "object" && r !== null && "params" in r ? r.params : void 0;
89
- console.log("variables", r);
90
- const d = ((p = o == null ? void 0 : o.headers) == null ? void 0 : p.contentType) ?? n(s.toUpperCase()), l = {
88
+ const s = (t == null ? void 0 : t.method) || "", o = r == null ? void 0 : r.fetchOptions, i = typeof r == "object" && r !== null && "body" in r ? r.body : void 0, c = typeof r == "object" && r !== null && "params" in r ? r.params : void 0, d = ((p = o == null ? void 0 : o.headers) == null ? void 0 : p.contentType) ?? n(s.toUpperCase()), l = {
91
89
  url: t.url,
92
90
  method: s,
93
91
  params: c,
@@ -430,7 +428,7 @@ function ln(e, ...t) {
430
428
  ]).join(";");
431
429
  oe(e, n, ...t);
432
430
  }
433
- const F = {
431
+ const v = {
434
432
  primary: sn,
435
433
  success: on,
436
434
  info: an,
@@ -474,11 +472,11 @@ class K extends Error {
474
472
  const Rt = ft({
475
473
  lastUpdateTimestamp: 0,
476
474
  isAuth: !1,
477
- getTokens: () => (F.warning("AuthStateContext", "getTokens not yet ready"), null),
478
- updateTokens: () => F.warning("AuthStateContext", "updateTokens not yet ready"),
479
- forceLogout: () => F.warning("AuthStateContext", "forceLogout not yet ready"),
475
+ getTokens: () => (v.warning("AuthStateContext", "getTokens not yet ready"), null),
476
+ updateTokens: () => v.warning("AuthStateContext", "updateTokens not yet ready"),
477
+ forceLogout: () => v.warning("AuthStateContext", "forceLogout not yet ready"),
480
478
  refreshTokens: async () => {
481
- F.warning("AuthStateContext", "refreshToken not yet ready");
479
+ v.warning("AuthStateContext", "refreshToken not yet ready");
482
480
  }
483
481
  }), un = () => Vt(Rt), Yr = ({
484
482
  children: e,
@@ -497,11 +495,11 @@ const Rt = ft({
497
495
  var h;
498
496
  const T = (h = t()) == null ? void 0 : h.refreshToken;
499
497
  if (!T || !r)
500
- throw o && F.danger("[AuthStateProvider] handleOnRefreshTokens", "refreshToken|onRefreshTokens empty"), new K({ message: "refreshToken|onRefreshTokens empty", code: "REFRESH_TOKEN_EMPTY" });
498
+ throw o && v.danger("[AuthStateProvider] handleOnRefreshTokens", "refreshToken|onRefreshTokens empty"), new K({ message: "refreshToken|onRefreshTokens empty", code: "REFRESH_TOKEN_EMPTY" });
501
499
  try {
502
500
  const R = await r(T);
503
501
  if (Ue(R))
504
- throw o && F.danger("[AuthStateProvider] handleOnRefreshTokens", "new refresh token fail"), new K({ message: "new refresh token fail", code: "NEW_REFRESH_TOKEN_EMPTY" });
502
+ throw o && v.danger("[AuthStateProvider] handleOnRefreshTokens", "new refresh token fail"), new K({ message: "new refresh token fail", code: "NEW_REFRESH_TOKEN_EMPTY" });
505
503
  u(R);
506
504
  return;
507
505
  } catch {
@@ -622,12 +620,12 @@ const pn = ft(null), Xr = ({
622
620
  };
623
621
  }, [l, p, u, y]);
624
622
  const T = (E) => {
625
- d && F.warning("[FetcherProvider] runPendingRequest", { isSuccess: E }), ee = !1;
623
+ d && v.warning("[FetcherProvider] runPendingRequest", { isSuccess: E }), ee = !1;
626
624
  for (const O of _e)
627
625
  O(E);
628
626
  _e = [];
629
627
  }, h = (E, O) => (g) => {
630
- d && F.info("[FetcherProvider] Request add pending queue", { originConfig: g }), _e.push((x) => {
628
+ d && v.info("[FetcherProvider] Request add pending queue", { originConfig: g }), _e.push((x) => {
631
629
  x ? (g.pendingRequest = !0, E(t(g))) : O(new K({
632
630
  message: S(401),
633
631
  code: "UNAUTHORIZED",
@@ -646,19 +644,19 @@ const pn = ft(null), Xr = ({
646
644
  return;
647
645
  }
648
646
  O(E);
649
- }), m = (E) => (d && F.info("[FetcherProvider] interceptorsResponseSuccess", { response: E }), E), S = (E) => {
647
+ }), m = (E) => (d && v.info("[FetcherProvider] interceptorsResponseSuccess", { response: E }), E), S = (E) => {
650
648
  const O = (c == null ? void 0 : c[n]) || Ge[n] || Ge["en-US"];
651
649
  return (O == null ? void 0 : O[E]) || `Error: ${E}`;
652
650
  }, A = (E) => {
653
651
  const O = E.response, g = E.config, x = E.status, N = r(O);
654
- d && F.warning("[FetcherProvider] interceptorsResponseError", { status: x, responseFirstError: N }), s && s(N);
652
+ d && v.warning("[FetcherProvider] interceptorsResponseError", { status: x, responseFirstError: N }), s && s(N);
655
653
  const B = g && o ? o(g) : !1;
656
654
  if (O && g && (x === 401 || N.code === "UNAUTHENTICATED")) {
657
655
  const j = l();
658
- return d && F.warning("[FetcherProvider] enter refresh token flow", { refreshToken: j == null ? void 0 : j.refreshToken }), Ue(j == null ? void 0 : j.refreshToken) || B || g.pendingRequest ? (ee = !1, d && F.warning("[FetcherProvider] no refreshToken/refreshAPI|pendingRequest fail, force logout"), y(), Promise.reject(new K(N))) : (ee || (ee = !0, d && F.warning("[FetcherProvider] refreshTokens"), p().then(() => {
659
- d && F.info("[FetcherProvider] refreshTokens success"), T(!0);
656
+ return d && v.warning("[FetcherProvider] enter refresh token flow", { refreshToken: j == null ? void 0 : j.refreshToken }), Ue(j == null ? void 0 : j.refreshToken) || B || g.pendingRequest ? (ee = !1, d && v.warning("[FetcherProvider] no refreshToken/refreshAPI|pendingRequest fail, force logout"), y(), Promise.reject(new K(N))) : (ee || (ee = !0, d && v.warning("[FetcherProvider] refreshTokens"), p().then(() => {
657
+ d && v.info("[FetcherProvider] refreshTokens success"), T(!0);
660
658
  }).catch(() => {
661
- d && F.danger("[FetcherProvider] refreshTokens fail"), T(!1);
659
+ d && v.danger("[FetcherProvider] refreshTokens fail"), T(!1);
662
660
  })), new Promise((V, H) => {
663
661
  h(V, H)(g);
664
662
  }));
@@ -735,7 +733,7 @@ function Ce() {
735
733
  }
736
734
  const kn = (e, t, n, { allOwnKeys: r } = {}) => (ie(t, (s, o) => {
737
735
  n && L(s) ? e[o] = Et(s, n) : e[o] = s;
738
- }, { allOwnKeys: r }), e), vn = (e) => (e.charCodeAt(0) === 65279 && (e = e.slice(1)), e), Fn = (e, t, n, r) => {
736
+ }, { allOwnKeys: r }), e), Fn = (e) => (e.charCodeAt(0) === 65279 && (e = e.slice(1)), e), vn = (e, t, n, r) => {
739
737
  e.prototype = Object.create(t.prototype, r), e.prototype.constructor = e, Object.defineProperty(e, "super", {
740
738
  value: t.prototype
741
739
  }), n && Object.assign(e.prototype, n);
@@ -866,8 +864,8 @@ const Yn = (e) => {
866
864
  merge: Ce,
867
865
  extend: kn,
868
866
  trim: Cn,
869
- stripBOM: vn,
870
- inherits: Fn,
867
+ stripBOM: Fn,
868
+ inherits: vn,
871
869
  toFlatObject: jn,
872
870
  kindOf: Re,
873
871
  kindOfTest: D,
@@ -1138,22 +1136,22 @@ const Ct = {
1138
1136
  Blob: or
1139
1137
  },
1140
1138
  protocols: ["http", "https", "file", "blob", "url", "data"]
1141
- }, qe = typeof window < "u" && typeof document < "u", ve = typeof navigator == "object" && navigator || void 0, ar = qe && (!ve || ["ReactNative", "NativeScript", "NS"].indexOf(ve.product) < 0), cr = typeof WorkerGlobalScope < "u" && // eslint-disable-next-line no-undef
1139
+ }, qe = typeof window < "u" && typeof document < "u", Fe = typeof navigator == "object" && navigator || void 0, ar = qe && (!Fe || ["ReactNative", "NativeScript", "NS"].indexOf(Fe.product) < 0), cr = typeof WorkerGlobalScope < "u" && // eslint-disable-next-line no-undef
1142
1140
  self instanceof WorkerGlobalScope && typeof self.importScripts == "function", lr = qe && window.location.href || "http://localhost", ur = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1143
1141
  __proto__: null,
1144
1142
  hasBrowserEnv: qe,
1145
1143
  hasStandardBrowserEnv: ar,
1146
1144
  hasStandardBrowserWebWorkerEnv: cr,
1147
- navigator: ve,
1145
+ navigator: Fe,
1148
1146
  origin: lr
1149
- }, Symbol.toStringTag, { value: "Module" })), v = {
1147
+ }, Symbol.toStringTag, { value: "Module" })), F = {
1150
1148
  ...ur,
1151
1149
  ...ir
1152
1150
  };
1153
1151
  function fr(e, t) {
1154
- return ye(e, new v.classes.URLSearchParams(), Object.assign({
1152
+ return ye(e, new F.classes.URLSearchParams(), Object.assign({
1155
1153
  visitor: function(n, r, s, o) {
1156
- return v.isNode && a.isBuffer(n) ? (this.append(r, n.toString("base64")), !1) : o.defaultVisitor.apply(this, arguments);
1154
+ return F.isNode && a.isBuffer(n) ? (this.append(r, n.toString("base64")), !1) : o.defaultVisitor.apply(this, arguments);
1157
1155
  }
1158
1156
  }, t));
1159
1157
  }
@@ -1247,8 +1245,8 @@ const ae = {
1247
1245
  maxContentLength: -1,
1248
1246
  maxBodyLength: -1,
1249
1247
  env: {
1250
- FormData: v.classes.FormData,
1251
- Blob: v.classes.Blob
1248
+ FormData: F.classes.FormData,
1249
+ Blob: F.classes.Blob
1252
1250
  },
1253
1251
  validateStatus: function(t) {
1254
1252
  return t >= 200 && t < 300;
@@ -1471,7 +1469,7 @@ function xe(e, t) {
1471
1469
  o = c.call(n, o, s.normalize(), t ? t.status : void 0);
1472
1470
  }), s.normalize(), o;
1473
1471
  }
1474
- function vt(e) {
1472
+ function Ft(e) {
1475
1473
  return !!(e && e.__CANCEL__);
1476
1474
  }
1477
1475
  function G(e, t, n) {
@@ -1480,7 +1478,7 @@ function G(e, t, n) {
1480
1478
  a.inherits(G, b, {
1481
1479
  __CANCEL__: !0
1482
1480
  });
1483
- function Ft(e, t, n) {
1481
+ function vt(e, t, n) {
1484
1482
  const r = n.config.validateStatus;
1485
1483
  !n.status || !r || r(n.status) ? e(n) : t(new b(
1486
1484
  "Request failed with status code " + n.status,
@@ -1548,10 +1546,10 @@ const pe = (e, t, n = 3) => {
1548
1546
  total: e,
1549
1547
  loaded: r
1550
1548
  }), t[1]];
1551
- }, st = (e) => (...t) => a.asap(() => e(...t)), Or = v.hasStandardBrowserEnv ? /* @__PURE__ */ ((e, t) => (n) => (n = new URL(n, v.origin), e.protocol === n.protocol && e.host === n.host && (t || e.port === n.port)))(
1552
- new URL(v.origin),
1553
- v.navigator && /(msie|trident)/i.test(v.navigator.userAgent)
1554
- ) : () => !0, Ar = v.hasStandardBrowserEnv ? (
1549
+ }, st = (e) => (...t) => a.asap(() => e(...t)), Or = F.hasStandardBrowserEnv ? /* @__PURE__ */ ((e, t) => (n) => (n = new URL(n, F.origin), e.protocol === n.protocol && e.host === n.host && (t || e.port === n.port)))(
1550
+ new URL(F.origin),
1551
+ F.navigator && /(msie|trident)/i.test(F.navigator.userAgent)
1552
+ ) : () => !0, Ar = F.hasStandardBrowserEnv ? (
1555
1553
  // Standard browser envs support document.cookie
1556
1554
  {
1557
1555
  write(e, t, n, r, s, o) {
@@ -1662,14 +1660,14 @@ const Lt = (e) => {
1662
1660
  );
1663
1661
  let d;
1664
1662
  if (a.isFormData(n)) {
1665
- if (v.hasStandardBrowserEnv || v.hasStandardBrowserWebWorkerEnv)
1663
+ if (F.hasStandardBrowserEnv || F.hasStandardBrowserWebWorkerEnv)
1666
1664
  i.setContentType(void 0);
1667
1665
  else if ((d = i.getContentType()) !== !1) {
1668
1666
  const [l, ...u] = d ? d.split(";").map((p) => p.trim()).filter(Boolean) : [];
1669
1667
  i.setContentType([l || "multipart/form-data", ...u].join("; "));
1670
1668
  }
1671
1669
  }
1672
- if (v.hasStandardBrowserEnv && (r && a.isFunction(r) && (r = r(t)), r || r !== !1 && Or(t.url))) {
1670
+ if (F.hasStandardBrowserEnv && (r && a.isFunction(r) && (r = r(t)), r || r !== !1 && Or(t.url))) {
1673
1671
  const l = s && o && Ar.read(o);
1674
1672
  l && i.set(s, l);
1675
1673
  }
@@ -1698,7 +1696,7 @@ const Lt = (e) => {
1698
1696
  config: e,
1699
1697
  request: m
1700
1698
  };
1701
- Ft(function(N) {
1699
+ vt(function(N) {
1702
1700
  n(N), R();
1703
1701
  }, function(N) {
1704
1702
  r(N), R();
@@ -1725,7 +1723,7 @@ const Lt = (e) => {
1725
1723
  m && (r(!E || E.type ? new G(null, e, m) : E), m.abort(), m = null);
1726
1724
  }, s.cancelToken && s.cancelToken.subscribe(u), s.signal && (s.signal.aborted ? u() : s.signal.addEventListener("abort", u)));
1727
1725
  const A = Tr(s.url);
1728
- if (A && v.protocols.indexOf(A) === -1) {
1726
+ if (A && F.protocols.indexOf(A) === -1) {
1729
1727
  r(new b("Unsupported protocol " + A + ":", b.ERR_BAD_REQUEST, e));
1730
1728
  return;
1731
1729
  }
@@ -1763,10 +1761,10 @@ const Lt = (e) => {
1763
1761
  let r = 0, s;
1764
1762
  for (; r < n; )
1765
1763
  s = r + t, yield e.slice(r, s), r = s;
1766
- }, vr = async function* (e, t) {
1767
- for await (const n of Fr(e))
1764
+ }, Fr = async function* (e, t) {
1765
+ for await (const n of vr(e))
1768
1766
  yield* kr(n, t);
1769
- }, Fr = async function* (e) {
1767
+ }, vr = async function* (e) {
1770
1768
  if (e[Symbol.asyncIterator]) {
1771
1769
  yield* e;
1772
1770
  return;
@@ -1783,7 +1781,7 @@ const Lt = (e) => {
1783
1781
  await t.cancel();
1784
1782
  }
1785
1783
  }, it = (e, t, n, r) => {
1786
- const s = vr(e, t);
1784
+ const s = Fr(e, t);
1787
1785
  let o = 0, i, c = (d) => {
1788
1786
  i || (i = !0, r && r(d));
1789
1787
  };
@@ -1819,7 +1817,7 @@ const Lt = (e) => {
1819
1817
  }
1820
1818
  }, Lr = Ut && Dt(() => {
1821
1819
  let e = !1;
1822
- const t = new Request(v.origin, {
1820
+ const t = new Request(F.origin, {
1823
1821
  body: new ReadableStream(),
1824
1822
  method: "POST",
1825
1823
  get duplex() {
@@ -1827,8 +1825,8 @@ const Lt = (e) => {
1827
1825
  }
1828
1826
  }).headers.has("Content-Type");
1829
1827
  return e && !t;
1830
- }), at = 64 * 1024, Fe = Ut && Dt(() => a.isReadableStream(new Response("").body)), he = {
1831
- stream: Fe && ((e) => e.body)
1828
+ }), at = 64 * 1024, ve = Ut && Dt(() => a.isReadableStream(new Response("").body)), he = {
1829
+ stream: ve && ((e) => e.body)
1832
1830
  };
1833
1831
  we && ((e) => {
1834
1832
  ["text", "arrayBuffer", "blob", "formData", "stream"].forEach((t) => {
@@ -1843,7 +1841,7 @@ const Ur = async (e) => {
1843
1841
  if (a.isBlob(e))
1844
1842
  return e.size;
1845
1843
  if (a.isSpecCompliantForm(e))
1846
- return (await new Request(v.origin, {
1844
+ return (await new Request(F.origin, {
1847
1845
  method: "POST",
1848
1846
  body: e
1849
1847
  }).arrayBuffer()).byteLength;
@@ -1902,8 +1900,8 @@ const Ur = async (e) => {
1902
1900
  credentials: S ? p : void 0
1903
1901
  });
1904
1902
  let A = await fetch(h);
1905
- const E = Fe && (l === "stream" || l === "response");
1906
- if (Fe && (c || E && R)) {
1903
+ const E = ve && (l === "stream" || l === "response");
1904
+ if (ve && (c || E && R)) {
1907
1905
  const g = {};
1908
1906
  ["status", "statusText", "headers"].forEach((j) => {
1909
1907
  g[j] = A[j];
@@ -1922,7 +1920,7 @@ const Ur = async (e) => {
1922
1920
  l = l || "text";
1923
1921
  let O = await he[a.findKey(he, l) || "text"](A, e);
1924
1922
  return !E && R && R(), await new Promise((g, x) => {
1925
- Ft(g, x, {
1923
+ vt(g, x, {
1926
1924
  data: O,
1927
1925
  headers: U.from(A.headers),
1928
1926
  status: A.status,
@@ -1999,7 +1997,7 @@ function lt(e) {
1999
1997
  r
2000
1998
  ), r.headers = U.from(r.headers), r;
2001
1999
  }, function(r) {
2002
- return vt(r) || (Ne(e), r && r.response && (r.response.data = xe.call(
2000
+ return Ft(r) || (Ne(e), r && r.response && (r.response.data = xe.call(
2003
2001
  e,
2004
2002
  e.transformResponse,
2005
2003
  r.response
@@ -2338,7 +2336,7 @@ const P = $t(ae);
2338
2336
  P.Axios = J;
2339
2337
  P.CanceledError = G;
2340
2338
  P.CancelToken = $r;
2341
- P.isCancel = vt;
2339
+ P.isCancel = Ft;
2342
2340
  P.VERSION = qt;
2343
2341
  P.toFormData = ye;
2344
2342
  P.AxiosError = b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acrool/react-fetcher",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Fetcher library based for Reactjs",
5
5
  "keywords": [
6
6
  "acrool",