@m4l/core 0.1.45 → 0.1.46

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.
@@ -1,39 +1,40 @@
1
- import { useState as s, useRef as x, useCallback as G, useEffect as p } from "react";
2
- import { u as H } from "../useHostTools/index.66d9a667.js";
3
- import { u as L } from "../useNetwork/index.acbf28d5.js";
1
+ import { useState as s, useRef as G, useCallback as H, useEffect as p } from "react";
2
+ import { u as L } from "../useHostTools/index.66d9a667.js";
3
+ import { u as N } from "../useNetwork/index.acbf28d5.js";
4
4
  const a = {
5
5
  page: 0,
6
6
  rowsPerPage: 25,
7
7
  totalRecords: 0
8
- }, B = (l) => {
8
+ }, D = (l) => {
9
9
  const {
10
10
  endPoint: m,
11
- timeout: h = 5e3,
11
+ timeout: w = 5e3,
12
12
  queryParams: P,
13
- fireOnChangeParms: u,
14
- fireOnFirstLoad: w = !0,
15
- rowsPerPage: c = a.rowsPerPage,
13
+ fireOnChangeParms: i,
14
+ fireOnFirstLoad: h = !0,
15
+ rowsPerPage: u = a.rowsPerPage,
16
16
  startProgress: R,
17
17
  stopProgress: C,
18
18
  isRemote: d = !0,
19
19
  bodyToSnakeCase: S = !1,
20
- responseToCamelCase: k = !1
21
- } = l, [i, o] = s(u ? 1 : 0), [y, n] = s([]), [T, g] = s({ ...a, rowsPerPage: c }), t = x({ ...a, rowsPerPage: c }), [O, b] = s(w), { startProgress: E, stopProgress: F } = H(), { networkOperation: Q } = L(), f = G(() => {
20
+ responseToCamelCase: k = !1,
21
+ initialRows: y = []
22
+ } = l, [c, o] = s(i ? 1 : 0), [T, n] = s(y), [O, g] = s({ ...a, rowsPerPage: u }), t = G({ ...a, rowsPerPage: u }), [b, E] = s(h), { startProgress: F, stopProgress: Q } = L(), { networkOperation: q } = N(), f = H(() => {
22
23
  o((r) => r + 1);
23
24
  }, []);
24
25
  return p(() => {
25
- if (O) {
26
- b(!1);
26
+ if (b) {
27
+ E(!1);
27
28
  return;
28
29
  }
29
- u && f();
30
+ i && f();
30
31
  }, [P]), p(() => {
31
32
  let r = !0;
32
- if (i !== 0)
33
- return Q({
33
+ if (c !== 0)
34
+ return q({
34
35
  method: "GET",
35
36
  endPoint: m,
36
- timeout: h,
37
+ timeout: w,
37
38
  parms: {
38
39
  ...P,
39
40
  page: t.current.page,
@@ -42,28 +43,28 @@ const a = {
42
43
  bodyToSnakeCase: S,
43
44
  responseToCamelCase: k,
44
45
  options: {
45
- startProgress: R || E,
46
- stopProgress: C || F
46
+ startProgress: R || F,
47
+ stopProgress: C || Q
47
48
  },
48
49
  isRemote: d
49
50
  }).then((e) => {
50
- r && (n(e.data), t.current.page = e.pager.page, g((q) => ({
51
- ...q,
51
+ r && (n(e.data), t.current.page = e.pager.page, g((x) => ({
52
+ ...x,
52
53
  page: e.pager.page,
53
54
  totalRecords: e.pager.total
54
55
  })));
55
56
  }), function() {
56
57
  r = !1;
57
58
  };
58
- }, [i]), { onPageChange: (r) => {
59
+ }, [c]), { onPageChange: (r) => {
59
60
  t.current.page = r, o((e) => e + 1);
60
61
  }, onRowsPerPageChange: (r) => {
61
62
  t.current.rowsPerPage = r, g((e) => ({ ...e, rowsPerPage: r })), o((e) => e + 1);
62
- }, pagerState: T, rows: y, clearRows: () => {
63
+ }, pagerState: O, rows: T, clearRows: () => {
63
64
  n([]), g(a);
64
65
  }, Refresh: f, setRows: n };
65
66
  };
66
67
  export {
67
68
  a as i,
68
- B as u
69
+ D as u
69
70
  };
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { UsePaginateProps } from './types';
3
3
  import type { PagerState } from './types';
4
- export declare const usePaginate: <TRow>(props: UsePaginateProps) => {
4
+ export declare const usePaginate: <TRow>(props: UsePaginateProps<TRow>) => {
5
5
  onPageChange: (newPage: number) => void;
6
6
  onRowsPerPageChange: (newRowsPerPage: number) => void;
7
7
  pagerState: PagerState;
@@ -6,9 +6,10 @@ export declare interface PagerState {
6
6
  totalRecords: number;
7
7
  }
8
8
  export declare const initialPagerState: PagerState;
9
- export interface UsePaginateProps extends Pick<NetworkProps, 'endPoint' | 'timeout' | 'isRemote' | 'bodyToSnakeCase' | 'responseToCamelCase'>, AxiosOptions {
9
+ export interface UsePaginateProps<TRow> extends Pick<NetworkProps, 'endPoint' | 'timeout' | 'isRemote' | 'bodyToSnakeCase' | 'responseToCamelCase'>, AxiosOptions {
10
10
  fireOnChangeParms?: boolean;
11
11
  fireOnFirstLoad?: boolean;
12
12
  queryParams: Record<string, unknown>;
13
13
  rowsPerPage?: number;
14
+ initialRows?: TRow[];
14
15
  }
package/index.js CHANGED
@@ -19,11 +19,11 @@ import { u as $ } from "./hooks/useModuleDictionary/index.c4454f46.js";
19
19
  import { u as eo } from "./hooks/useModulePrivileges/index.7a9da551.js";
20
20
  import { u as ao } from "./hooks/useModuleSkeleton/index.07843a4f.js";
21
21
  import { u as so } from "./hooks/useNetwork/index.acbf28d5.js";
22
- import { i as no, u as mo } from "./hooks/usePaginate/index.9ed61e68.js";
22
+ import { i as no, u as mo } from "./hooks/usePaginate/index.030f3b27.js";
23
23
  import { u as xo } from "./hooks/usePropageteMF/index.c440b829.js";
24
24
  import { C as lo, E as fo } from "./types/index.42c24946.js";
25
- import { e as go, a as Po, g as Co, s as Mo, v as Do } from "./utils/index.78881d49.js";
26
- import { a as co } from "./utils/axiosOperation.d83903ee.js";
25
+ import { e as go, a as Po, g as Co, s as Mo, v as Do } from "./utils/index.6d56ba04.js";
26
+ import { a as co } from "./utils/axiosOperation.30c7cc9d.js";
27
27
  import "react/jsx-runtime";
28
28
  import "axios";
29
29
  import "qs";
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
- "version": "0.1.45",
3
+ "version": "0.1.46",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team",
6
+ "private": false,
6
7
  "peerDependencies": {
7
8
  "@types/nprogress": "^0.2.0",
8
9
  "@types/qs": "^6.9.7",
@@ -31,6 +32,5 @@
31
32
  "dependencies": {
32
33
  "camelcase-keys": "^7.0.1",
33
34
  "snakecase-keys": "5.1.2"
34
- },
35
- "private": false
35
+ }
36
36
  }
@@ -1,11 +1,11 @@
1
- import C from "axios";
2
- import R from "qs";
3
- import j from "camelcase-keys";
1
+ import $ from "axios";
2
+ import j from "qs";
3
+ import C from "camelcase-keys";
4
4
  import v from "snakecase-keys";
5
5
  import { E as b } from "../types/index.42c24946.js";
6
6
  function h(e, t, a, i, o, s) {
7
7
  const { toast: d } = a;
8
- return i === "json" ? t && t.data && typeof t.data == "object" ? t.data.error && t.data.error?.code && t.data.error?.msg !== void 0 ? Promise.reject({ ...t.data.error, status: t.status }) : (t.data.messagen && o && d(t.data.message, { type: "success", autoClose: 1e4 }), s ? j(t.data, { deep: !0 }) : t.data) : Promise.reject({
8
+ return i === "json" ? t && t.data && typeof t.data == "object" ? t.data.error && t.data.error?.code && t.data.error?.msg !== void 0 ? Promise.reject({ ...t.data.error, status: t.status }) : (t.data.messagen && o && d(t.data.message, { type: "success", autoClose: 1e4 }), s ? C(t.data, { deep: !0 }) : t.data) : Promise.reject({
9
9
  code: 1,
10
10
  msg: `Incorrect endpoint: ${e}`,
11
11
  status: t.status
@@ -18,38 +18,38 @@ function x(e, t, a = !0, i = !0) {
18
18
  status: 1,
19
19
  code: 0
20
20
  };
21
- return e?.code !== void 0 && s.status !== void 0 && e.message !== void 0 && (s = { ...s, ...e }), e?.response ? e.response.data && typeof e.response.data == "object" && e.response.data.error && e.response.data.error?.code && e.response.data.error?.message !== void 0 ? s = { ...e.response.data.error, status: e.response.status } : (s.message = e.message, s.status = e.response.status, s.code = 0) : e?.request ? (s.message = `${e?.code} ${e.message}`, s.code = -1) : (s.message = `${e?.code} ${e.message}`, s.status = 0, s.code = -2), a && e?.response?.status === 401 && t.events_emit(b.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {}), e?.response?.data?.error?.message && (s.message = e?.response?.data?.error.message), a && (s.message.indexOf("ERR_CANCELED") > -1 || i && o(`${s.message} - status: ${s.status} - code: ${s.code}`, {
21
+ return e?.code !== void 0 && s.status !== void 0 && e.message !== void 0 && (s = { ...s, ...e }), e?.response ? e.response.data && typeof e.response.data == "object" && e.response.data.error && e.response.data.error?.code && e.response.data.error?.message !== void 0 ? s = { ...e.response.data.error, status: e.response.status } : (s.message = e.message, s.status = e.response.status, s.code = 0) : e?.request ? (s.message = `${e?.code} ${e.message}`, s.code = -1) : (s.message = `${e?.code} ${e.message}`, s.status = 0, s.code = -2), console.log("ERROR", e), console.log("err", s), a && e?.response?.status === 401 && t.events_emit(b.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {}), e?.response?.data?.error?.message && (s.message = e?.response?.data?.error.message), a && (s.message.indexOf("ERR_CANCELED") > -1 || i && o(`${s.message} - status: ${s.status} - code: ${s.code}`, {
22
22
  type: "error"
23
23
  })), s;
24
24
  }
25
- const D = async (e, t, a) => {
25
+ const S = async (e, t, a) => {
26
26
  const {
27
27
  method: i,
28
28
  endPoint: o,
29
29
  timeout: s = 6e4,
30
30
  parms: d = {},
31
31
  data: m = {},
32
- isRemote: u = !0,
32
+ isRemote: c = !0,
33
33
  checkUnAuthorized: g = !0,
34
34
  headers: l,
35
35
  onDownloadProgress: p,
36
- isExternalUrl: c,
36
+ isExternalUrl: u,
37
37
  responseType: f = "json",
38
38
  signal: E,
39
- toastSuccess: y = !0,
40
- toastError: _ = !0,
41
- bodyToSnakeCase: P = !1,
42
- responseToCamelCase: $ = !1
39
+ toastSuccess: R = !0,
40
+ toastError: y = !0,
41
+ bodyToSnakeCase: _ = !1,
42
+ responseToCamelCase: P = !1
43
43
  } = e;
44
44
  let r;
45
- return u ? r = t.host_api_remote : r = t.host_api_local, e?.options?.startProgress && e?.options?.startProgress(), C({
46
- baseURL: c ? void 0 : r,
47
- withCredentials: u,
45
+ return c ? r = t.host_api_remote : r = t.host_api_local, e?.options?.startProgress && e?.options?.startProgress(), $({
46
+ baseURL: u ? void 0 : r,
47
+ withCredentials: c,
48
48
  method: i,
49
- url: c ? o : `/${o}`,
50
- data: P ? v(m, { deep: !0 }) : m,
49
+ url: u ? o : `/${o}`,
50
+ data: _ ? v(m, { deep: !0 }) : m,
51
51
  params: {},
52
- paramsSerializer: () => R.stringify(d, { encode: !0 }),
52
+ paramsSerializer: () => j.stringify(d, { encode: !0 }),
53
53
  headers: l,
54
54
  timeout: s,
55
55
  onDownloadProgress: p,
@@ -60,14 +60,14 @@ const D = async (e, t, a) => {
60
60
  n,
61
61
  a,
62
62
  f,
63
- y,
64
- $
63
+ R,
64
+ P
65
65
  )).catch(
66
- (n) => Promise.reject(x(n, a, g, _))
66
+ (n) => (console.log("Reject de la promesa"), Promise.reject(x(n, a, g, y)))
67
67
  ).finally(() => {
68
68
  e?.options?.stopProgress && e?.options?.stopProgress();
69
69
  });
70
70
  };
71
71
  export {
72
- D as a
72
+ S as a
73
73
  };
@@ -0,0 +1,65 @@
1
+ import "axios";
2
+ import "qs";
3
+ import "camelcase-keys";
4
+ import "snakecase-keys";
5
+ function y() {
6
+ }
7
+ function p(n, e) {
8
+ const r = e.split(".");
9
+ let t = n;
10
+ for (const o of r) {
11
+ const a = o.match(/^(\w+)\[(\w+)\]$/);
12
+ if (a) {
13
+ const s = a[1], c = a[2];
14
+ if (t[s] && Array.isArray(t[s])) {
15
+ if (c === "lastIndex")
16
+ return t[s][t[s].length - 1];
17
+ {
18
+ const i = parseInt(c);
19
+ return t[s][i];
20
+ }
21
+ } else
22
+ return;
23
+ } else if (t[o] !== void 0)
24
+ t = t[o];
25
+ else
26
+ return;
27
+ }
28
+ return t;
29
+ }
30
+ function d(n, e) {
31
+ try {
32
+ const t = new Function(...Object.keys(n), `return \`${e}\``)(...Object.values(n));
33
+ return String(t).replace(/`/g, "");
34
+ } catch (r) {
35
+ return console.error(`Error evaluating expression: ${r}`), "";
36
+ }
37
+ }
38
+ function m(n, e) {
39
+ try {
40
+ const r = window.localStorage.getItem(n);
41
+ return r !== null ? typeof e == "string" ? r : JSON.parse(r) : e;
42
+ } catch {
43
+ return e;
44
+ }
45
+ }
46
+ function v(n, e, r = !1) {
47
+ try {
48
+ let t = null;
49
+ if (typeof e == "string") {
50
+ window.localStorage.setItem(n, e);
51
+ return;
52
+ }
53
+ r && (t = window.localStorage.getItem(n));
54
+ let o = t !== null ? JSON.parse(t) : {};
55
+ o = { ...o, ...e }, window.localStorage.setItem(n, JSON.stringify(o));
56
+ } catch {
57
+ }
58
+ }
59
+ export {
60
+ m as a,
61
+ d as e,
62
+ p as g,
63
+ v as s,
64
+ y as v
65
+ };
@@ -1,45 +0,0 @@
1
- import "axios";
2
- import "qs";
3
- import "camelcase-keys";
4
- import "snakecase-keys";
5
- function l() {
6
- }
7
- function u(r, t) {
8
- return t.split(".").reduce((e, o) => (e || {})[o], r);
9
- }
10
- function g(r, t) {
11
- try {
12
- const o = new Function(...Object.keys(r), `return \`${t}\``)(...Object.values(r));
13
- return String(o).replace(/`/g, "");
14
- } catch (e) {
15
- return console.error(`Error evaluating expression: ${e}`), "";
16
- }
17
- }
18
- function p(r, t) {
19
- try {
20
- const e = window.localStorage.getItem(r);
21
- return e !== null ? typeof t == "string" ? e : JSON.parse(e) : t;
22
- } catch {
23
- return t;
24
- }
25
- }
26
- function f(r, t, e = !1) {
27
- try {
28
- let o = null;
29
- if (typeof t == "string") {
30
- window.localStorage.setItem(r, t);
31
- return;
32
- }
33
- e && (o = window.localStorage.getItem(r));
34
- let n = o !== null ? JSON.parse(o) : {};
35
- n = { ...n, ...t }, window.localStorage.setItem(r, JSON.stringify(n));
36
- } catch {
37
- }
38
- }
39
- export {
40
- p as a,
41
- g as e,
42
- u as g,
43
- f as s,
44
- l as v
45
- };