@fctc/edu-logic-lib 1.0.8 → 1.0.10

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 (47) hide show
  1. package/dist/config.js +257 -6
  2. package/dist/config.mjs +256 -2
  3. package/dist/constants.js +152 -53
  4. package/dist/constants.mjs +141 -2
  5. package/dist/environment.js +839 -16
  6. package/dist/environment.mjs +840 -4
  7. package/dist/hooks.js +4850 -180
  8. package/dist/hooks.mjs +4813 -9
  9. package/dist/index.js +5320 -626
  10. package/dist/index.mjs +5165 -12
  11. package/dist/models.js +1107 -18
  12. package/dist/models.mjs +1107 -9
  13. package/dist/provider.js +1115 -17
  14. package/dist/provider.mjs +1115 -8
  15. package/dist/services.js +1922 -31
  16. package/dist/services.mjs +1922 -7
  17. package/dist/store.js +576 -248
  18. package/dist/store.mjs +519 -1
  19. package/dist/types.js +0 -2
  20. package/dist/types.mjs +1 -1
  21. package/dist/utils.js +2355 -61
  22. package/dist/utils.mjs +2344 -1
  23. package/package.json +2 -1
  24. package/dist/chunk-4K3QAEZ6.js +0 -90
  25. package/dist/chunk-6BLY7NZ6.mjs +0 -120
  26. package/dist/chunk-6QXB3XX7.mjs +0 -256
  27. package/dist/chunk-7JD5GMIZ.js +0 -2
  28. package/dist/chunk-AYUH66EE.mjs +0 -62
  29. package/dist/chunk-CZHZLKNA.mjs +0 -585
  30. package/dist/chunk-EK43MEN4.js +0 -635
  31. package/dist/chunk-ELARQVCE.mjs +0 -2344
  32. package/dist/chunk-FVGPSTJ7.js +0 -122
  33. package/dist/chunk-GGOFXFSX.js +0 -2362
  34. package/dist/chunk-IXDDYGKE.js +0 -61
  35. package/dist/chunk-MLJQPO4Q.mjs +0 -57
  36. package/dist/chunk-OADBRQ4A.js +0 -32
  37. package/dist/chunk-OBR6UTC5.mjs +0 -1
  38. package/dist/chunk-OFUXC2LA.mjs +0 -86
  39. package/dist/chunk-P2IGWJDZ.js +0 -1068
  40. package/dist/chunk-QLUONJPQ.mjs +0 -519
  41. package/dist/chunk-RWRHCIQI.mjs +0 -1059
  42. package/dist/chunk-RZBHZYXG.js +0 -582
  43. package/dist/chunk-S7B3VKMJ.mjs +0 -85
  44. package/dist/chunk-S7YF2I23.js +0 -95
  45. package/dist/chunk-UY6GNZNB.js +0 -262
  46. package/dist/chunk-XYVK476U.mjs +0 -29
  47. package/dist/chunk-YOV6KAT2.js +0 -66
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fctc/edu-logic-lib",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -8,6 +8,7 @@
8
8
  "registry": "https://registry.npmjs.org/",
9
9
  "access": "public"
10
10
  },
11
+ "sideEffects": false,
11
12
  "exports": {
12
13
  ".": {
13
14
  "types": "./dist/index.d.ts",
@@ -1,90 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkRZBHZYXG_js = require('./chunk-RZBHZYXG.js');
4
- var chunkUY6GNZNB_js = require('./chunk-UY6GNZNB.js');
5
-
6
- // src/environment/EnvStore.ts
7
- var EnvStore = class {
8
- envStore;
9
- baseUrl;
10
- requests;
11
- context;
12
- defaultCompany;
13
- config;
14
- companies;
15
- user;
16
- db;
17
- localStorageUtils;
18
- sessionStorageUtils;
19
- constructor(envStore2, localStorageUtils, sessionStorageUtils) {
20
- this.envStore = envStore2;
21
- this.localStorageUtils = localStorageUtils;
22
- this.sessionStorageUtils = sessionStorageUtils;
23
- this.setup();
24
- }
25
- setup() {
26
- const env2 = this.envStore.getState().env;
27
- this.baseUrl = env2?.baseUrl;
28
- this.requests = env2?.requests;
29
- this.context = env2?.context;
30
- this.defaultCompany = env2?.defaultCompany;
31
- this.config = env2?.config;
32
- this.companies = env2?.companies || [];
33
- this.user = env2?.user;
34
- this.db = env2?.db;
35
- }
36
- setupEnv(envConfig) {
37
- const dispatch = this.envStore.dispatch;
38
- const env2 = {
39
- ...envConfig,
40
- localStorageUtils: this.localStorageUtils,
41
- sessionStorageUtils: this.sessionStorageUtils
42
- };
43
- const requests = chunkUY6GNZNB_js.axiosClient.init(env2);
44
- dispatch(chunkRZBHZYXG_js.setEnv({ ...env2, requests }));
45
- this.setup();
46
- }
47
- setUid(uid) {
48
- const dispatch = this.envStore.dispatch;
49
- dispatch(chunkRZBHZYXG_js.setUid(uid));
50
- this.setup();
51
- }
52
- setLang(lang) {
53
- const dispatch = this.envStore.dispatch;
54
- dispatch(chunkRZBHZYXG_js.setLang(lang));
55
- this.setup();
56
- }
57
- setAllowCompanies(allowCompanies) {
58
- const dispatch = this.envStore.dispatch;
59
- dispatch(chunkRZBHZYXG_js.setAllowCompanies(allowCompanies));
60
- this.setup();
61
- }
62
- setCompanies(companies) {
63
- const dispatch = this.envStore.dispatch;
64
- dispatch(chunkRZBHZYXG_js.setCompanies(companies));
65
- this.setup();
66
- }
67
- setDefaultCompany(company) {
68
- const dispatch = this.envStore.dispatch;
69
- dispatch(chunkRZBHZYXG_js.setDefaultCompany(company));
70
- this.setup();
71
- }
72
- setUserInfo(userInfo) {
73
- const dispatch = this.envStore.dispatch;
74
- dispatch(chunkRZBHZYXG_js.setUser(userInfo));
75
- this.setup();
76
- }
77
- };
78
- exports.env = null;
79
- function initEnv({}) {
80
- exports.env = new EnvStore(chunkRZBHZYXG_js.envStore);
81
- return exports.env;
82
- }
83
- function getEnv() {
84
- if (!exports.env) exports.env = new EnvStore(chunkRZBHZYXG_js.envStore);
85
- return exports.env;
86
- }
87
-
88
- exports.EnvStore = EnvStore;
89
- exports.getEnv = getEnv;
90
- exports.initEnv = initEnv;
@@ -1,120 +0,0 @@
1
- import { WIDGETAVATAR } from './chunk-S7B3VKMJ.mjs';
2
-
3
- // src/models/base-model/index.ts
4
- var BaseModel = class {
5
- name;
6
- view;
7
- actContext;
8
- fields;
9
- constructor(init) {
10
- this.name = init.name;
11
- this.view = init.view;
12
- this.actContext = init.actContext;
13
- this.fields = init.fields;
14
- }
15
- getSpecificationByFields({
16
- fields = [],
17
- specification = {},
18
- modelsData,
19
- model,
20
- modelRoot
21
- }) {
22
- if (Array.isArray(fields)) {
23
- let spec = { ...specification };
24
- fields.forEach((field) => {
25
- if (!field?.type_co || field?.name && field?.type_co === "field" /* FIELD */) {
26
- if (modelsData?.[model]?.[field?.name]) {
27
- if (modelsData?.[model]?.[field?.name]?.type === "one2many" /* ONE2MANY */ || modelsData?.[model]?.[field?.name]?.type === "many2many" /* MANY2MANY */) {
28
- const relation = modelsData?.[model]?.[field?.name]?.relation;
29
- const modelRelation = modelsData?.[relation];
30
- if (modelRelation) {
31
- spec[field?.name] = {
32
- fields: {}
33
- };
34
- if (modelRoot && modelRoot === relation) {
35
- spec[field?.name].fields = { id: {} };
36
- } else {
37
- spec[field?.name].fields = this.getSpecificationByFields({
38
- fields: Object.values(modelRelation),
39
- specification: {},
40
- modelsData,
41
- model: relation,
42
- modelRoot: model
43
- });
44
- }
45
- } else {
46
- spec[field?.name] = {
47
- fields: {
48
- id: {},
49
- display_name: {}
50
- }
51
- };
52
- }
53
- } else if (modelsData?.[model]?.[field?.name]?.type === "many2one" /* MANY2ONE */) {
54
- spec[field?.name] = {
55
- fields: {
56
- id: {},
57
- display_name: {},
58
- ...WIDGETAVATAR[field?.widget] ? { image_256: {} } : {},
59
- ...field?.name === "currency_id" && fields?.find((item) => item?.widget === "monetary") ? { symbol: {} } : {},
60
- ...field?.widget === "many2many_binary" ? { mimetype: {} } : {}
61
- }
62
- };
63
- } else {
64
- spec[field?.name] = {};
65
- }
66
- }
67
- } else if (field?.type_co === "group" /* GROUP */ || field?.type_co === "div" /* DIV */ || field?.type_co === "span" /* SPAN */) {
68
- const specGroup = this.getSpecificationByFields({
69
- fields: field?.fields,
70
- specification: spec,
71
- modelsData,
72
- model
73
- });
74
- spec = { ...spec, ...specGroup };
75
- } else if (field?.type_co === "tree" /* TREE */ || field?.type_co === "list" /* LIST */) {
76
- const relation = modelsData?.[model]?.[field?.name]?.relation;
77
- const specTreee = this.getSpecificationByFields({
78
- fields: field?.fields,
79
- specification: {},
80
- modelsData,
81
- model: relation,
82
- modelRoot: model
83
- });
84
- spec = {
85
- ...spec,
86
- [field?.name]: {
87
- fields: { ...spec?.[field?.name]?.fields, ...specTreee }
88
- }
89
- };
90
- }
91
- });
92
- return spec;
93
- } else {
94
- console.warn("fields is not array");
95
- }
96
- }
97
- getTreeProps() {
98
- const props = this.view?.views?.list || {};
99
- return props;
100
- }
101
- getTreeFields() {
102
- const fields = this.view?.views?.list?.fields || [];
103
- return fields;
104
- }
105
- getSpecification() {
106
- const specInit = {};
107
- const modelData = this.view?.models || {};
108
- const specification = this.getSpecificationByFields({
109
- fields: this.fields,
110
- specification: specInit,
111
- modelsData: modelData,
112
- model: this.name,
113
- modelRoot: ""
114
- });
115
- return specification;
116
- }
117
- };
118
- var base_model_default = BaseModel;
119
-
120
- export { base_model_default };
@@ -1,256 +0,0 @@
1
- import axios from 'axios';
2
-
3
- // src/config/axios-client.ts
4
- var MAINT_KEY = "MAINTENANCE_ACTIVE";
5
- var MAINT_AT = "MAINTENANCE_AT";
6
- var MAINT_LAST_PATH = "MAINTENANCE_LAST_PATH";
7
- var hasRedirectedToMaintenance = false;
8
- function setMaintenanceFlags() {
9
- if (typeof window === "undefined") return;
10
- const { pathname, search } = window.location;
11
- const lastPath = pathname + (search || "");
12
- if (pathname !== "/maintenance" && !window.localStorage.getItem(MAINT_LAST_PATH)) {
13
- window.localStorage.setItem(MAINT_LAST_PATH, lastPath);
14
- }
15
- window.localStorage.setItem(MAINT_KEY, "true");
16
- window.localStorage.setItem(MAINT_AT, String(Date.now()));
17
- }
18
- async function clearMaintenanceAndExit(getToken, opts) {
19
- if (typeof window === "undefined") return;
20
- const forceLogin = opts?.forceLogin === true;
21
- const clearTokenOnForce = opts?.clearTokenOnForce !== false;
22
- window.localStorage.removeItem(MAINT_KEY);
23
- window.localStorage.removeItem(MAINT_AT);
24
- const lastPath = window.localStorage.getItem(MAINT_LAST_PATH);
25
- window.localStorage.removeItem(MAINT_LAST_PATH);
26
- try {
27
- if (forceLogin) {
28
- if (clearTokenOnForce) {
29
- try {
30
- await opts?.clearToken?.();
31
- } catch {
32
- }
33
- }
34
- window.location.replace("/login");
35
- return;
36
- }
37
- const token = await getToken();
38
- if (token) {
39
- const target = lastPath && lastPath !== "/maintenance" ? lastPath : "/";
40
- window.location.replace(target);
41
- } else {
42
- window.location.replace("/login");
43
- }
44
- } catch {
45
- window.location.replace("/login");
46
- }
47
- }
48
- var axiosClient = {
49
- init(config) {
50
- const localStorage = config.localStorageUtils;
51
- const sessionStorage = config.sessionStorageUtils;
52
- const db = config.db;
53
- let isRefreshing = false;
54
- let failedQueue = [];
55
- const processQueue = (error, token = null) => {
56
- failedQueue?.forEach((prom) => {
57
- if (error) {
58
- prom.reject(error);
59
- } else {
60
- prom.resolve(token);
61
- }
62
- });
63
- failedQueue = [];
64
- };
65
- const instance = axios.create({
66
- adapter: axios.defaults.adapter,
67
- baseURL: config.baseUrl,
68
- timeout: 5e4,
69
- paramsSerializer: (params) => new URLSearchParams(params).toString()
70
- });
71
- if (typeof window !== "undefined") {
72
- const isMaint = window.localStorage.getItem(MAINT_KEY) === "true";
73
- const onMaintenancePage = window.location.pathname === "/maintenance";
74
- if (isMaint && !onMaintenancePage) {
75
- hasRedirectedToMaintenance = true;
76
- window.location.replace("/maintenance");
77
- }
78
- if (isMaint && onMaintenancePage) {
79
- const healthUrl = config.healthUrl || `${(config.baseUrl || "").replace(/\/+$/, "")}/health`;
80
- (async () => {
81
- try {
82
- await axios.get(healthUrl, { timeout: 8e3 });
83
- await clearMaintenanceAndExit(() => localStorage.getAccessToken(), {
84
- forceLogin: true,
85
- clearTokenOnForce: true,
86
- clearToken: () => localStorage.clearToken()
87
- });
88
- } catch {
89
- }
90
- })();
91
- }
92
- }
93
- instance.interceptors.request.use(
94
- async (configReq) => {
95
- const token = await localStorage.getAccessToken();
96
- if (token) {
97
- configReq.headers["Authorization"] = "Bearer " + token;
98
- }
99
- return configReq;
100
- },
101
- (error) => Promise.reject(error)
102
- );
103
- instance.interceptors.response.use(
104
- (response) => {
105
- if (typeof window !== "undefined") {
106
- const isMaint = window.localStorage.getItem(MAINT_KEY) === "true";
107
- const onMaintenancePage = window.location.pathname === "/maintenance";
108
- if (isMaint && onMaintenancePage) {
109
- (async () => {
110
- await clearMaintenanceAndExit(
111
- () => localStorage.getAccessToken(),
112
- {
113
- forceLogin: true,
114
- clearTokenOnForce: true,
115
- clearToken: () => localStorage.clearToken()
116
- }
117
- );
118
- })();
119
- } else if (isMaint) {
120
- window.localStorage.removeItem(MAINT_KEY);
121
- window.localStorage.removeItem(MAINT_AT);
122
- window.localStorage.removeItem(MAINT_LAST_PATH);
123
- }
124
- }
125
- return handleResponse(response);
126
- },
127
- async (error) => {
128
- const status = error?.response?.status;
129
- if (status === 503) {
130
- if (typeof window !== "undefined") {
131
- setMaintenanceFlags();
132
- if (!hasRedirectedToMaintenance && window.location.pathname !== "/maintenance") {
133
- hasRedirectedToMaintenance = true;
134
- window.location.replace("/maintenance");
135
- }
136
- }
137
- return Promise.reject({
138
- code: 503,
139
- message: "SERVICE_UNAVAILABLE",
140
- original: error?.response?.data
141
- });
142
- }
143
- const handleError = async (err) => {
144
- if (!err.response) {
145
- return err;
146
- }
147
- const { data } = err.response;
148
- if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
149
- await clearAuthToken();
150
- }
151
- return data;
152
- };
153
- const originalRequest = error.config;
154
- if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401].includes(
155
- error.response.data.code
156
- )) {
157
- if (isRefreshing) {
158
- return new Promise(function(resolve, reject) {
159
- failedQueue.push({ resolve, reject });
160
- }).then((token) => {
161
- originalRequest.headers["Authorization"] = "Bearer " + token;
162
- return instance.request(originalRequest);
163
- }).catch(async (err) => {
164
- if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
165
- await clearAuthToken();
166
- }
167
- });
168
- }
169
- const browserSession = await sessionStorage.getBrowserSession();
170
- const refreshToken = await localStorage.getRefreshToken();
171
- const accessTokenExp = await localStorage.getAccessToken();
172
- isRefreshing = true;
173
- if (!refreshToken && (!browserSession || browserSession == "unActive")) {
174
- await clearAuthToken();
175
- } else {
176
- const payload = Object.fromEntries(
177
- Object.entries({
178
- refresh_token: refreshToken,
179
- grant_type: "refresh_token",
180
- client_id: config.config.clientId,
181
- client_secret: config.config.clientSecret
182
- }).filter(([_, value]) => !!value)
183
- );
184
- return new Promise(function(resolve) {
185
- axios.post(
186
- `${config.baseUrl}${"/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
187
- payload,
188
- {
189
- headers: {
190
- "Content-Type": "multipart/form-data",
191
- Authorization: `Bearer ${accessTokenExp}`
192
- }
193
- }
194
- ).then(async (res) => {
195
- const data = res.data;
196
- await localStorage.setToken(data.access_token);
197
- await localStorage.setRefreshToken(data.refresh_token);
198
- axios.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
199
- originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
200
- processQueue(null, data.access_token);
201
- resolve(instance.request(originalRequest));
202
- }).catch(async (err) => {
203
- if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST")) {
204
- await clearAuthToken();
205
- }
206
- if (err && err.response) {
207
- const { error_code } = err.response?.data || {};
208
- if (error_code === "AUTHEN_FAIL") {
209
- await clearAuthToken();
210
- }
211
- }
212
- processQueue(err, null);
213
- }).finally(() => {
214
- isRefreshing = false;
215
- });
216
- });
217
- }
218
- }
219
- return Promise.reject(await handleError(error));
220
- }
221
- );
222
- const handleResponse = (res) => {
223
- if (res && res.data) {
224
- return res.data;
225
- }
226
- return res;
227
- };
228
- const clearAuthToken = async () => {
229
- await localStorage.clearToken();
230
- if (typeof window !== "undefined") {
231
- window.location.href = `/login`;
232
- }
233
- };
234
- function formatUrl(url, db2) {
235
- return url + (db2 ? "?db=" + db2 : "");
236
- }
237
- const responseBody = (response) => response;
238
- const requests = {
239
- get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
240
- post: (url, body, headers) => instance.post(formatUrl(url, db), body, { headers }).then(responseBody),
241
- post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
242
- responseType: "arraybuffer",
243
- headers: {
244
- "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
245
- Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
246
- }
247
- }).then(responseBody),
248
- put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
249
- patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
250
- delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
251
- };
252
- return requests;
253
- }
254
- };
255
-
256
- export { axiosClient };
@@ -1,2 +0,0 @@
1
- 'use strict';
2
-
@@ -1,62 +0,0 @@
1
- import { view_service_default } from './chunk-RWRHCIQI.mjs';
2
- import { envStore } from './chunk-QLUONJPQ.mjs';
3
- import { useState, useEffect } from 'react';
4
- import { QueryClient, QueryClientProvider, useQueryClient } from '@tanstack/react-query';
5
- import { jsx, Fragment } from 'react/jsx-runtime';
6
- import { Provider } from 'react-redux';
7
-
8
- var ReactQueryProvider = ({ children }) => {
9
- const [queryClient] = useState(
10
- () => new QueryClient({
11
- defaultOptions: {
12
- queries: {
13
- refetchOnWindowFocus: false,
14
- refetchOnMount: false,
15
- refetchOnReconnect: false,
16
- retry: false
17
- }
18
- }
19
- })
20
- );
21
- return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children });
22
- };
23
- var ReduxProvider = ({ children }) => {
24
- return /* @__PURE__ */ jsx(Provider, { store: envStore, children });
25
- };
26
- var MainProvider = ({ children }) => {
27
- return /* @__PURE__ */ jsx(ReduxProvider, { children: /* @__PURE__ */ jsx(ReactQueryProvider, { children }) });
28
- };
29
- var VersionGate = ({ children }) => {
30
- const queryClient = useQueryClient();
31
- const [ready, setReady] = useState(false);
32
- useEffect(() => {
33
- const clearVersion = () => {
34
- queryClient.clear();
35
- localStorage.removeItem("__api_version__");
36
- };
37
- const validateVersion = async () => {
38
- const serverVersion = await view_service_default.getVersion();
39
- const cached = localStorage.getItem("__api_version__");
40
- if (cached !== serverVersion?.api_version) {
41
- clearVersion();
42
- localStorage.setItem("__api_version__", serverVersion?.api_version);
43
- } else {
44
- console.log("Api version:", serverVersion?.api_version);
45
- }
46
- setReady(true);
47
- };
48
- validateVersion();
49
- if (typeof window !== "undefined") {
50
- const onKey = (e) => {
51
- const key = e.key.toLowerCase();
52
- const isHardRefresh = (key === "f5" || key === "r") && e.ctrlKey && (key !== "r" || e.shiftKey) || key === "r" && e.metaKey && e.shiftKey || key === "r" && e.metaKey && e.altKey;
53
- if (isHardRefresh) clearVersion();
54
- };
55
- window.addEventListener("keydown", onKey);
56
- return () => window.removeEventListener("keydown", onKey);
57
- }
58
- }, [queryClient]);
59
- return ready ? /* @__PURE__ */ jsx(Fragment, { children }) : null;
60
- };
61
-
62
- export { MainProvider, ReactQueryProvider, VersionGate };