@acrool/react-fetcher 0.0.4-test.4 → 0.0.4-test.6

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