@m4l/core 0.1.0 → 0.1.3

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.
Files changed (51) hide show
  1. package/package.json +7 -2
  2. package/index.html +0 -13
  3. package/src/contexts/EnvironmentContext/index.tsx +0 -45
  4. package/src/contexts/EnvironmentContext/types.ts +0 -8
  5. package/src/contexts/FlagsContext/index.tsx +0 -50
  6. package/src/contexts/FlagsContext/types.ts +0 -16
  7. package/src/contexts/HostToolsContext/index.tsx +0 -35
  8. package/src/contexts/HostToolsContext/types.ts +0 -8
  9. package/src/contexts/ModuleDictionaryContext/index.tsx +0 -109
  10. package/src/contexts/ModuleDictionaryContext/types.ts +0 -18
  11. package/src/contexts/ModulePrivilegesContext/index.tsx +0 -88
  12. package/src/contexts/ModulePrivilegesContext/types.ts +0 -12
  13. package/src/contexts/ModuleSkeletonContext/index.tsx +0 -35
  14. package/src/contexts/ModuleSkeletonContext/types.ts +0 -11
  15. package/src/contexts/NetworkContext/index.tsx +0 -44
  16. package/src/contexts/NetworkContext/types.ts +0 -15
  17. package/src/contexts/index.ts +0 -7
  18. package/src/hooks/index.ts +0 -12
  19. package/src/hooks/useEnvironment/index.test.tsx +0 -44
  20. package/src/hooks/useEnvironment/index.ts +0 -13
  21. package/src/hooks/useFlags/index.ts +0 -35
  22. package/src/hooks/useHostTools/index.ts +0 -13
  23. package/src/hooks/useLocalStorage/index.ts +0 -23
  24. package/src/hooks/useModuleDictionary/index.ts +0 -11
  25. package/src/hooks/useModulePrivileges/index.ts +0 -11
  26. package/src/hooks/useModuleSkeleton/index.ts +0 -11
  27. package/src/hooks/useNetwork/index.ts +0 -13
  28. package/src/hooks/usePaginate/index.ts +0 -109
  29. package/src/hooks/usePaginate/types.ts +0 -18
  30. package/src/index.ts +0 -43
  31. package/src/isolation/App.tsx +0 -105
  32. package/src/isolation/components/Paginate.tsx +0 -65
  33. package/src/isolation/components/TestHooks/CallBack.tsx +0 -43
  34. package/src/isolation/components/TestHooks/SimpleUseEffect.tsx +0 -33
  35. package/src/jest.d.ts +0 -1
  36. package/src/main.tsx +0 -5
  37. package/src/test/setup.ts +0 -1
  38. package/src/test/utils.tsx +0 -20
  39. package/src/types/dictionary.ts +0 -17
  40. package/src/types/index.ts +0 -66
  41. package/src/utils/axiosOperation/index.ts +0 -150
  42. package/src/utils/axiosOperation/types.ts +0 -5
  43. package/src/utils/getLocalStorage.ts +0 -8
  44. package/src/utils/getPropertyByString.ts +0 -10
  45. package/src/utils/index.ts +0 -5
  46. package/src/utils/setLocalStorage.ts +0 -12
  47. package/src/utils/voidFunction.ts +0 -2
  48. package/src/vite-env.d.ts +0 -4
  49. package/tsconfig.json +0 -20
  50. package/tsconfig.node.json +0 -10
  51. package/vite.config.ts +0 -200
@@ -1,150 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- import axios from 'axios';
4
- import qs from 'qs';
5
- import type { AxiosError } from 'axios';
6
-
7
- import { EmitEvents } from '../../types';
8
- import type { EnvironmentType, HostToolsType, NetworkProps } from '../../types';
9
-
10
- import { AxiosOperationError } from './types';
11
-
12
- // config
13
-
14
- // const axiosInstance = axios.create({});
15
-
16
- // ----------------------------------------------------------------------
17
-
18
- function getResponse(endPoint: string, response: any, hostTools: HostToolsType) {
19
- console.log('Axios response', response, typeof response.data);
20
- const { toast } = hostTools;
21
-
22
- if (response && response.data && typeof response.data === 'object') {
23
- if (
24
- response.data.error &&
25
- response.data.error?.code &&
26
- response.data.error?.msg !== undefined
27
- ) {
28
- // Si respondió con codigo de error interno
29
- return Promise.reject({ ...response.data.error, status: response.status });
30
- }
31
- if (response.data.message) {
32
- toast(response.data.message, { type: 'success', autoClose: 10000 });
33
- }
34
- return response.data;
35
- }
36
-
37
- return Promise.reject({
38
- code: 1,
39
- msg: `Incorrect endpoint: ${endPoint}`,
40
- status: response.status,
41
- });
42
- }
43
-
44
- function getError(error: any, hostTools: HostToolsType, checkUnAuthorized = true) {
45
- const { toast } = hostTools;
46
-
47
- let err: AxiosOperationError = {
48
- message: '',
49
- status: 1,
50
- code: 0,
51
- };
52
-
53
- console.log('getError', error);
54
- if (
55
- error?.code !== undefined &&
56
- err.status !== undefined &&
57
- (error as any).message !== undefined
58
- ) {
59
- err = { ...err, ...error };
60
- } else if (error?.response) {
61
- // The request was made and the server responded with a status code
62
- // that falls out of the range of 2xx
63
- if (
64
- error.response.data &&
65
- typeof error.response.data === 'object' &&
66
- error.response.data.error &&
67
- error.response.data.error?.code &&
68
- error.response.data.error?.message !== undefined
69
- ) {
70
- // Si respondió con codigo de error interno
71
-
72
- err = { ...error.response.data.error, status: error.response.status };
73
- } else {
74
- err.message = error.message;
75
- err.status = error.response.status;
76
- err.code = 0;
77
- }
78
-
79
- if (checkUnAuthorized && error.response.status === 401) {
80
- // unauthorized
81
- hostTools.events_emit(EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {});
82
- }
83
- } else if (error?.request) {
84
- // The request was made but no response was received
85
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
86
- // http.ClientRequest in node.js
87
- err.message = `${error?.code} ${error.message}`;
88
- err.code = -1;
89
- } else {
90
- // Something happened in setting up the request that triggered an Error
91
- err.message = `${error?.code} ${error.message}`;
92
- err.status = 0;
93
- err.code = -2;
94
- }
95
-
96
- if (checkUnAuthorized) {
97
- toast(`${err.message} - status: ${err.status} - code: ${err.code}`, { type: 'error' });
98
- }
99
-
100
- return err;
101
- }
102
-
103
- export const axiosOperation = async (
104
- props: NetworkProps,
105
- enviroment: EnvironmentType,
106
- hostTools: HostToolsType,
107
- ): Promise<any> => {
108
- /// /console.log("Axios getWithParms request", endPoint);
109
-
110
- const {
111
- method,
112
- endPoint,
113
- timeout = 5000,
114
- parms = {},
115
- data = {},
116
- isRemote = true,
117
- checkUnAuthorized = true,
118
- headers,
119
- } = props;
120
-
121
- let baseURL: string;
122
-
123
- if (isRemote) {
124
- baseURL = enviroment.host_api_remote;
125
- } else {
126
- baseURL = enviroment.host_api_local;
127
- }
128
-
129
- hostTools.startProgress();
130
-
131
- return axios({
132
- baseURL,
133
- withCredentials: isRemote,
134
- method,
135
- url: `/${endPoint}`,
136
- data: data,
137
- params: {},
138
- paramsSerializer: () => {
139
- // console.log('axios qs', qs.stringify(parms));
140
- return qs.stringify(parms, { encode: true });
141
- },
142
- headers,
143
- timeout,
144
- })
145
- .then((response: any) => getResponse(endPoint, response, hostTools))
146
- .catch((error: AxiosError) => Promise.reject(getError(error, hostTools, checkUnAuthorized)))
147
- .finally(() => {
148
- hostTools.stopProgress();
149
- });
150
- };
@@ -1,5 +0,0 @@
1
- export type AxiosOperationError = {
2
- message: string;
3
- status: number;
4
- code: string | number;
5
- };
@@ -1,8 +0,0 @@
1
- export function getLocalStorage<ValueType>(key: string, initialValue: ValueType): ValueType {
2
- try {
3
- const item = window.localStorage.getItem(key);
4
- return item !== null ? JSON.parse(item) : initialValue;
5
- } catch (e) {
6
- return initialValue;
7
- }
8
- }
@@ -1,10 +0,0 @@
1
- export function getPropertyByString(object: Record<string, unknown>, propString: string) {
2
- let value: any = object;
3
-
4
- const props = propString.split('.');
5
- for (let index = 0; index < props.length; index += 1) {
6
- if (props[index] === undefined) break;
7
- value = value[props[index]];
8
- }
9
- return value;
10
- }
@@ -1,5 +0,0 @@
1
- export { voidFunction } from './voidFunction';
2
- export { getPropertyByString } from './getPropertyByString';
3
- export { getLocalStorage } from './getLocalStorage';
4
- export { setLocalStorage } from './setLocalStorage';
5
- export { axiosOperation } from './axiosOperation';
@@ -1,12 +0,0 @@
1
- export function setLocalStorage<ValueType>(key: string, value: ValueType) {
2
- try {
3
- const item: string | null = window.localStorage.getItem(key);
4
-
5
- let newValue = item !== null ? JSON.parse(item) : {};
6
- newValue = { ...newValue, ...value };
7
-
8
- window.localStorage.setItem(key, JSON.stringify(newValue));
9
- } catch (e) {
10
- console.error(e);
11
- }
12
- }
@@ -1,2 +0,0 @@
1
- // eslint-disable-next-line prettier/prettier
2
- export function voidFunction() {}
package/src/vite-env.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /// <reference types="vite/client" />
2
- /// <reference types="vitest" />
3
- /// <reference types="vitest/importMeta" />
4
- /// <reference types="vite-plugin-mkcert" />
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "lib": ["DOM", "DOM.Iterable", "ESNext"],
5
- "types": ["vite/client"],
6
- "allowJs": false,
7
- "skipLibCheck": true,
8
- "esModuleInterop": false,
9
- "allowSyntheticDefaultImports": true,
10
- "strict": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "module": "ESNext",
13
- "moduleResolution": "Node",
14
- "resolveJsonModule": true,
15
- "isolatedModules": true,
16
- "noEmit": true,
17
- "jsx": "preserve"
18
- },
19
- "include": ["./src"]
20
- }
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "composite": true,
4
- "target": "esNext",
5
- "module": "ES2020",
6
- "moduleResolution": "node",
7
- "resolveJsonModule": true
8
- },
9
- "include": ["vite.config.ts","package.json"]
10
- }
package/vite.config.ts DELETED
@@ -1,200 +0,0 @@
1
- import react from '@vitejs/plugin-react';
2
- import * as path from 'path';
3
- import { defineConfig } from 'vite';
4
- import dts from 'vite-plugin-dts';
5
- // import { dependencies } from './package.json';
6
- // import { terser } from 'rollup-plugin-terser';
7
-
8
- function manualChunks(id: string, _api: any) {
9
- //Contextos
10
-
11
- if (id.includes('EnvironmentContext')) {
12
- return 'contexts/EnvironmentContext/index';
13
- }
14
-
15
- if (id.includes('HostToolsContext')) {
16
- return 'contexts/HostToolsContext/index';
17
- }
18
-
19
- if (id.includes('FlagsContext')) {
20
- return 'contexts/FlagsContext/index';
21
- }
22
-
23
- if (id.includes('NetworkContext')) {
24
- return 'contexts/NetworkContext/index';
25
- }
26
-
27
- if (id.includes('ModuleDictionaryContext')) {
28
- return 'contexts/ModuleDictionaryContext/index';
29
- }
30
-
31
- if (id.includes('ModulePrivilegesContext')) {
32
- return 'contexts/ModulePrivilegesContext/index';
33
- }
34
- if (id.includes('ModuleSkeletonContext')) {
35
- return 'contexts/ModuleSkeletonContext/index';
36
- }
37
-
38
- //hooks
39
- if (id.includes('useEnvironment')) {
40
- return 'hooks/useEnvironment/index';
41
- }
42
- if (id.includes('useFlags')) {
43
- return 'hooks/useFlags/index';
44
- }
45
- if (id.includes('useHostTools')) {
46
- return 'hooks/useHostTools/index';
47
- }
48
- if (id.includes('useModuleDictionary')) {
49
- return 'hooks/useModuleDictionary/index';
50
- }
51
- if (id.includes('useModulePrivileges')) {
52
- return 'hooks/useModulePrivileges/index';
53
- }
54
- if (id.includes('useModuleSkeleton')) {
55
- return 'hooks/useModuleSkeleton/index';
56
- }
57
-
58
- if (id.includes('useNetwork')) {
59
- return 'hooks/useNetwork/index';
60
- }
61
- if (id.includes('usePaginate')) {
62
- return 'hooks/usePaginate/index';
63
- }
64
- if (id.includes('useLocalStorage')) {
65
- return 'hooks/useLocalStorage/index';
66
- }
67
-
68
- // utils
69
- if (id.includes('src/utils/axiosOperation')) {
70
- return 'utils/axiosOperation';
71
- }
72
-
73
- if (id.includes('axios')) {
74
- return 'external/axios';
75
- }
76
-
77
- if (id.includes('snakecase-keys')) {
78
- return 'external/snakecase-keys';
79
- }
80
-
81
- //utils
82
-
83
- if (id.includes('src/utils')) {
84
- return 'utils/index';
85
- }
86
- //emums
87
- if (id.includes('src/types')) {
88
- return 'types/index';
89
- }
90
-
91
- //node_modules no reconocidos
92
- if (id.includes('node_modules')) {
93
- return 'node_modules';
94
- }
95
-
96
- console.log('manualChunks', id, 'api', _api);
97
-
98
- return 'vendor';
99
- }
100
-
101
- const examined_libs: Array<string> = [];
102
-
103
- const isExternal = (source: string, importer: string | undefined, isResolved: boolean): boolean => {
104
- const internal_exact_libs = ['axios', 'snakecase-keys'];
105
- const external_exact_libs = [
106
- 'react',
107
- 'react-dom',
108
- 'react/jsx-runtime',
109
- '@m4l/core',
110
- 'qs',
111
- 'side-channel', //qs dependencia
112
- 'call-bind', //side chanell dependencia
113
- 'get-intrinsic', //side chanell dependencia
114
- 'object-inspec', //side chanell dependencia
115
- ];
116
- const external_parcial_libs = [];
117
-
118
- if (internal_exact_libs.findIndex(l => source === l) > -1) {
119
- return false;
120
- }
121
-
122
- const isExt =
123
- external_exact_libs.findIndex(l => source === l) > -1 ||
124
- external_parcial_libs.findIndex(pl => source.indexOf(pl) > -1) > -1;
125
- if (isExt) {
126
- if (examined_libs.findIndex(l => source === l) < 0) {
127
- console.log(
128
- 'Source: ',
129
- source,
130
- ' Importer:',
131
- ' isResolved:',
132
- isResolved,
133
- ' IsExt:',
134
- isExt,
135
- );
136
- examined_libs.push(source);
137
- }
138
- }
139
-
140
- return isExt;
141
- };
142
-
143
- export default defineConfig({
144
- server: { https: true, port: 4002 },
145
- // test: {
146
- // globals: true,
147
- // include: ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
148
- // environment: 'jsdom',
149
- // setupFiles: './src/test/setup.ts',
150
- // coverage: {
151
- // all: true,
152
- // include: ['**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
153
- // reporter: ['text', 'json', 'html'],
154
- // },
155
- // },
156
-
157
- plugins: [
158
- react(),
159
- // terser(),
160
-
161
- dts({
162
- // insertTypesEntry: true,
163
- beforeWriteFile: (filePath: string, content: string) => {
164
- // console.log('beforeWriteFile', filePath);
165
- //En algunas librerias no pone el nombre del paquete, esta funciona arregla esto, pero todavia no se la causa.
166
- return { filePath: filePath.replace('m4l_core/src/', ''), content };
167
- },
168
- }),
169
- ],
170
- // mode: 'production',
171
- build: {
172
- //manifest: true,
173
- target: 'esNext', //Compila en esNext teniendo en cuenta que va a ser leida no por el navedado,sino por otros proyectos
174
- lib: {
175
- entry: path.resolve(__dirname, 'src/index.ts'),
176
- name: 'm4l_core',
177
- formats: ['es'],
178
- fileName: () => `index.js`,
179
- },
180
- rollupOptions: {
181
- external: isExternal,
182
-
183
- // input: ['src/index.ts'],
184
-
185
- output: {
186
- manualChunks,
187
- exports: 'auto',
188
- format: 'esm',
189
- generatedCode: 'es2015',
190
-
191
- dir: 'dist', // Carpenta donde se genera el bundle
192
- globals: {
193
- react: 'React',
194
- 'react-dom': 'ReactDOM',
195
- 'react/jsx-runtime': 'react/jsx-runtime',
196
- },
197
- },
198
- },
199
- },
200
- });