@goralys/core 1.0.0 → 1.1.1
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.
- package/dist/index.d.ts +29 -31
- package/dist/index.js +150 -101
- package/package.json +41 -41
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
interface GoralysClientConfig {
|
|
2
|
+
apiDomain: string;
|
|
3
|
+
}
|
|
4
|
+
declare function configureGoralysClient(cfg: GoralysClientConfig): void;
|
|
5
|
+
declare function getGoralysClientConfig(): GoralysClientConfig;
|
|
6
|
+
|
|
7
|
+
interface StorageAdapter {
|
|
8
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
9
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
10
|
+
removeItem(key: string): void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
declare function configureStorage(customAdapter: StorageAdapter): void;
|
|
13
|
+
declare function storageGet(key: string): Promise<string | null>;
|
|
14
|
+
declare function storageSet(key: string, value: string): Promise<void>;
|
|
15
|
+
declare function storageRemove(key: string): Promise<void>;
|
|
16
|
+
|
|
17
|
+
interface PHPDateTime {
|
|
18
|
+
date: string;
|
|
19
|
+
timezone_type: number;
|
|
20
|
+
timezone: string;
|
|
21
|
+
}
|
|
22
|
+
type CookieValue = string | boolean | number | null | undefined;
|
|
23
|
+
|
|
24
|
+
type CheckAuthImpl = () => boolean;
|
|
25
|
+
declare function configureCheckAuth(impl: CheckAuthImpl): void;
|
|
26
|
+
declare function isAuthenticated(): boolean;
|
|
27
|
+
|
|
1
28
|
type UserRole = {
|
|
2
29
|
role: "admin" | "teacher" | "student" | "none";
|
|
3
30
|
};
|
|
@@ -72,13 +99,6 @@ declare function useSubjects(role: UserRole["role"], showToast: ToastFn): {
|
|
|
72
99
|
syncKey: string;
|
|
73
100
|
};
|
|
74
101
|
|
|
75
|
-
interface PHPDateTime {
|
|
76
|
-
date: string;
|
|
77
|
-
timezone_type: number;
|
|
78
|
-
timezone: string;
|
|
79
|
-
}
|
|
80
|
-
type CookieValue = string | boolean | number | null | undefined;
|
|
81
|
-
|
|
82
102
|
declare const reasonsConfig: {
|
|
83
103
|
readonly "password-forgot": {
|
|
84
104
|
readonly label: "Mot de passe oublié";
|
|
@@ -168,8 +188,6 @@ type Section = {
|
|
|
168
188
|
};
|
|
169
189
|
declare const helpContent: Section[];
|
|
170
190
|
|
|
171
|
-
declare function setCookiesExpire(duration: number): void;
|
|
172
|
-
|
|
173
191
|
declare function isFoolsDay(): boolean;
|
|
174
192
|
|
|
175
193
|
declare function buildArray<T>(...items: (T | false | null | undefined)[]): T[];
|
|
@@ -178,19 +196,9 @@ declare const parsePhpDateTime: (phpDate: PHPDateTime) => string;
|
|
|
178
196
|
declare function emitAuthEvent(event: AuthEvent): void;
|
|
179
197
|
declare function onAuthEvent(callback: (event: AuthEvent) => void): () => void;
|
|
180
198
|
|
|
181
|
-
type CheckAuthImpl = () => boolean;
|
|
182
|
-
declare function configureCheckAuth(impl: CheckAuthImpl): void;
|
|
183
|
-
declare function isAuthenticated(): boolean;
|
|
184
|
-
|
|
185
199
|
declare function emitUserEvent(event: UserEvent): void;
|
|
186
200
|
declare function onUserEvent(callback: (event: UserEvent) => void): () => void;
|
|
187
201
|
|
|
188
|
-
interface GoralysClientConfig {
|
|
189
|
-
apiDomain: string;
|
|
190
|
-
}
|
|
191
|
-
declare function configureGoralysClient(cfg: GoralysClientConfig): void;
|
|
192
|
-
declare function getGoralysClientConfig(): GoralysClientConfig;
|
|
193
|
-
|
|
194
202
|
/**
|
|
195
203
|
* This filed is a slightly modified version of Next.js own http method declaration.
|
|
196
204
|
*/
|
|
@@ -227,16 +235,6 @@ type Listener = (event: NavigationEvent) => void;
|
|
|
227
235
|
declare function emitNavigationEvent(event: NavigationEvent): void;
|
|
228
236
|
declare function onNavigationEvent(listener: Listener): () => void;
|
|
229
237
|
|
|
230
|
-
interface StorageAdapter {
|
|
231
|
-
getItem(key: string): string | null | Promise<string | null>;
|
|
232
|
-
setItem(key: string, value: string): void | Promise<void>;
|
|
233
|
-
removeItem(key: string): void | Promise<void>;
|
|
234
|
-
}
|
|
235
|
-
declare function configureStorage(customAdapter: StorageAdapter): void;
|
|
236
|
-
declare function storageGet(key: string): Promise<string | null>;
|
|
237
|
-
declare function storageSet(key: string, value: string): Promise<void>;
|
|
238
|
-
declare function storageRemove(key: string): Promise<void>;
|
|
239
|
-
|
|
240
238
|
/**
|
|
241
239
|
* Returns the full name of a subject based on its short name or an alias.
|
|
242
240
|
* It searches for the first subject in {@link SUBJECTS} whose short name starts with the given string.
|
|
@@ -248,7 +246,7 @@ declare function getLongFromShort(short: string): string;
|
|
|
248
246
|
|
|
249
247
|
declare function fetchSubjectsForRoleClient(role: UserRole): Promise<Response | null>;
|
|
250
248
|
|
|
251
|
-
declare function
|
|
249
|
+
declare function configureUserCacheCallbacks(cache: () => Promise<void>, empty: () => void): void;
|
|
252
250
|
declare function cacheUserDataClient(): Promise<void>;
|
|
253
251
|
declare function emptyUserCacheClient(): void;
|
|
254
252
|
declare function fetchUsersClient(): Promise<Response>;
|
|
@@ -256,4 +254,4 @@ declare function fetchVirtualUsersClient(): Promise<Response>;
|
|
|
256
254
|
declare function fetchAdminsClient(): Promise<Response>;
|
|
257
255
|
declare function fetchVirtualAdminsClient(): Promise<Response>;
|
|
258
256
|
|
|
259
|
-
export { ADMIN_CACHE_RADIX, ADMIN_SYNC_RADIX, type AuthEvent, type ConfirmOptions, type CookieValue, type DraftModalResult, EMAIL_KEY, FULL_NAME_KEY, GoralysActionHandler, type GoralysClientConfig, HTTP_METHODS, type HttpMethod, LOGO_PATH, PERSISTANT_COOKIES, PERSISTANT_LOCALS, type PHPDateTime, PUB_ID_KEY, ROLE_KEY, SUBJECT_CACHES, SUBJECT_CACHE_RADIX, SUBJECT_SYNCS, SUBJECT_SYNC_RADIX, SUPPORT_TICKET_CACHE, SUPPORT_TICKET_SYNC, type StorageAdapter, type Subject, type SubjectStatus, SubjectStatusConfig, type SubjectsSearchField, type SupportReasons, type SupportTicket, type Toast, type ToastFn, USERNAME_KEY, USER_CACHES, USER_CACHE_RADIX, USER_ROLES, USER_SYNCS, USER_SYNC_RADIX, type User, type UserData, type UserEvent, type UserRole, type UserType, buildApiUrl, buildArray, cacheUserDataClient,
|
|
257
|
+
export { ADMIN_CACHE_RADIX, ADMIN_SYNC_RADIX, type AuthEvent, type CheckAuthImpl, type ConfirmOptions, type CookieValue, type DraftModalResult, EMAIL_KEY, FULL_NAME_KEY, GoralysActionHandler, type GoralysClientConfig, HTTP_METHODS, type HttpMethod, LOGO_PATH, PERSISTANT_COOKIES, PERSISTANT_LOCALS, type PHPDateTime, PUB_ID_KEY, ROLE_KEY, SUBJECT_CACHES, SUBJECT_CACHE_RADIX, SUBJECT_SYNCS, SUBJECT_SYNC_RADIX, SUPPORT_TICKET_CACHE, SUPPORT_TICKET_SYNC, type StorageAdapter, type Subject, type SubjectStatus, SubjectStatusConfig, type SubjectsSearchField, type SupportReasons, type SupportTicket, type Toast, type ToastFn, USERNAME_KEY, USER_CACHES, USER_CACHE_RADIX, USER_ROLES, USER_SYNCS, USER_SYNC_RADIX, type User, type UserData, type UserEvent, type UserRole, type UserType, buildApiUrl, buildArray, cacheUserDataClient, configureCheckAuth, configureGoralysClient, configureStorage, configureUserCacheCallbacks, emitAuthEvent, emitNavigationEvent, emitUserEvent, emptyUserCacheClient, fetchAdminsClient, fetchCsrfClient, fetchSubjectsForRoleClient, fetchUsersClient, fetchVirtualAdminsClient, fetchVirtualUsersClient, getGoralysClientConfig, getLongFromShort, getStatusHelper, getStatusLabel, goralysFetchClient, handleToastRequest, helpContent, isAuthenticated, isFoolsDay, isHTTPMethod, onAuthEvent, onNavigationEvent, onUserEvent, parsePhpDateTime, reasonsConfig, searchFields, storageGet, storageRemove, storageSet, useAdmins, useSubjects, useSupportTickets, useUsers, useVirtualAdmins, useVirtualUsers };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
1
|
+
// src/lib/fetch/config.ts
|
|
2
|
+
var config = null;
|
|
3
|
+
function configureGoralysClient(cfg) {
|
|
4
|
+
config = cfg;
|
|
5
|
+
}
|
|
6
|
+
function getGoralysClientConfig() {
|
|
7
|
+
if (!config) {
|
|
8
|
+
throw new Error("Goralys client not configured. Call configureGoralysClient() first.");
|
|
9
|
+
}
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/lib/storage/storage-adapter.ts
|
|
14
|
+
var adapter = null;
|
|
15
|
+
function configureStorage(customAdapter) {
|
|
16
|
+
adapter = customAdapter;
|
|
17
|
+
}
|
|
18
|
+
function getAdapter() {
|
|
19
|
+
if (!adapter) {
|
|
20
|
+
throw new Error("Storage not configured. Call configureStorage() first.");
|
|
21
|
+
}
|
|
22
|
+
return adapter;
|
|
23
|
+
}
|
|
24
|
+
async function storageGet(key) {
|
|
25
|
+
return getAdapter().getItem(key);
|
|
26
|
+
}
|
|
27
|
+
async function storageSet(key, value) {
|
|
28
|
+
await getAdapter().setItem(key, value);
|
|
29
|
+
}
|
|
30
|
+
async function storageRemove(key) {
|
|
31
|
+
await getAdapter().removeItem(key);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/lib/storage/cookies-adapter.ts
|
|
35
|
+
var adapter2 = null;
|
|
36
|
+
function getAdapter2() {
|
|
37
|
+
if (!adapter2) {
|
|
38
|
+
throw new Error("Cookies not configured. Call configureCookies() first.");
|
|
39
|
+
}
|
|
40
|
+
return adapter2;
|
|
41
|
+
}
|
|
42
|
+
function cookiesGet(key) {
|
|
43
|
+
return getAdapter2().getCookies(key);
|
|
44
|
+
}
|
|
45
|
+
function cookiesSet(key, value, path = "/", maxAge = 1.5 * 60) {
|
|
46
|
+
getAdapter2().setCookies(key, value, path, maxAge);
|
|
47
|
+
}
|
|
48
|
+
function cookiesOnChange(callback) {
|
|
49
|
+
return getAdapter2().onChange(callback);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/lib/auth/check-auth.ts
|
|
53
|
+
var checkAuthImpl;
|
|
54
|
+
function configureCheckAuth(impl) {
|
|
55
|
+
checkAuthImpl = impl;
|
|
56
|
+
}
|
|
57
|
+
function isAuthenticated() {
|
|
58
|
+
if (!checkAuthImpl) {
|
|
59
|
+
throw new Error("Auth check not configured. Call configureAuthCheck() first.");
|
|
60
|
+
}
|
|
61
|
+
return checkAuthImpl();
|
|
62
|
+
}
|
|
3
63
|
|
|
4
64
|
// src/lib/auth/auth-event.ts
|
|
5
65
|
var listeners = /* @__PURE__ */ new Set();
|
|
@@ -23,42 +83,6 @@ function onNavigationEvent(listener) {
|
|
|
23
83
|
return () => listeners2.delete(listener);
|
|
24
84
|
}
|
|
25
85
|
|
|
26
|
-
// src/lib/user/user.client.ts
|
|
27
|
-
var cacheUserClient;
|
|
28
|
-
var emptyCacheUserClient;
|
|
29
|
-
function configUserCacheCallbacks(cache, empty) {
|
|
30
|
-
cacheUserClient = cache;
|
|
31
|
-
emptyCacheUserClient = empty;
|
|
32
|
-
}
|
|
33
|
-
async function cacheUserDataClient() {
|
|
34
|
-
if (!cacheUserClient) {
|
|
35
|
-
throw new Error("User cache not configured. Call configUserCacheCallbacks() first.");
|
|
36
|
-
}
|
|
37
|
-
return await cacheUserClient();
|
|
38
|
-
}
|
|
39
|
-
function emptyUserCacheClient() {
|
|
40
|
-
if (!emptyCacheUserClient) {
|
|
41
|
-
throw new Error("User cache not configured. Call configUserCacheCallbacks() first.");
|
|
42
|
-
}
|
|
43
|
-
return emptyCacheUserClient();
|
|
44
|
-
}
|
|
45
|
-
async function fetchUsersClient() {
|
|
46
|
-
const csrfToken = await fetchCsrfClient("get-all-users");
|
|
47
|
-
return await goralysFetchClient("GET", buildApiUrl("users/all", { "csrf-token": csrfToken }));
|
|
48
|
-
}
|
|
49
|
-
async function fetchVirtualUsersClient() {
|
|
50
|
-
const csrfToken = await fetchCsrfClient("get-virtual-users");
|
|
51
|
-
return await goralysFetchClient("GET", buildApiUrl("users/virtual", { "csrf-token": csrfToken }));
|
|
52
|
-
}
|
|
53
|
-
async function fetchAdminsClient() {
|
|
54
|
-
const csrfToken = await fetchCsrfClient("get-all-admins");
|
|
55
|
-
return await goralysFetchClient("GET", buildApiUrl("admins/all", { "csrf-token": csrfToken }));
|
|
56
|
-
}
|
|
57
|
-
async function fetchVirtualAdminsClient() {
|
|
58
|
-
const csrfToken = await fetchCsrfClient("get-virtual-admins");
|
|
59
|
-
return await goralysFetchClient("GET", buildApiUrl("admins/virtual", { "csrf-token": csrfToken }));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
86
|
// src/lib/auth/user-event.ts
|
|
63
87
|
var listeners3 = /* @__PURE__ */ new Set();
|
|
64
88
|
function emitUserEvent(event) {
|
|
@@ -93,18 +117,6 @@ var GoralysActionHandler = class {
|
|
|
93
117
|
}
|
|
94
118
|
};
|
|
95
119
|
|
|
96
|
-
// src/lib/fetch/config.ts
|
|
97
|
-
var config = null;
|
|
98
|
-
function configureGoralysClient(cfg) {
|
|
99
|
-
config = cfg;
|
|
100
|
-
}
|
|
101
|
-
function getGoralysClientConfig() {
|
|
102
|
-
if (!config) {
|
|
103
|
-
throw new Error("Goralys client not configured. Call configureGoralysClient() first.");
|
|
104
|
-
}
|
|
105
|
-
return config;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
120
|
// src/lib/fetch/fetch.client.ts
|
|
109
121
|
var actionHandler = new GoralysActionHandler();
|
|
110
122
|
async function goralysFetchClient(method, input, payload, requestOptions) {
|
|
@@ -174,6 +186,45 @@ async function handleToastRequest(r, showToast, redirect = true, duration) {
|
|
|
174
186
|
return false;
|
|
175
187
|
}
|
|
176
188
|
|
|
189
|
+
// src/lib/user/user.client.ts
|
|
190
|
+
var cacheUserClient;
|
|
191
|
+
var emptyCacheUserClient;
|
|
192
|
+
function configureUserCacheCallbacks(cache, empty) {
|
|
193
|
+
cacheUserClient = cache;
|
|
194
|
+
emptyCacheUserClient = empty;
|
|
195
|
+
}
|
|
196
|
+
async function cacheUserDataClient() {
|
|
197
|
+
if (!cacheUserClient) {
|
|
198
|
+
throw new Error("User cache not configured. Call configUserCacheCallbacks() first.");
|
|
199
|
+
}
|
|
200
|
+
return await cacheUserClient();
|
|
201
|
+
}
|
|
202
|
+
function emptyUserCacheClient() {
|
|
203
|
+
if (!emptyCacheUserClient) {
|
|
204
|
+
throw new Error("User cache not configured. Call configUserCacheCallbacks() first.");
|
|
205
|
+
}
|
|
206
|
+
return emptyCacheUserClient();
|
|
207
|
+
}
|
|
208
|
+
async function fetchUsersClient() {
|
|
209
|
+
const csrfToken = await fetchCsrfClient("get-all-users");
|
|
210
|
+
return await goralysFetchClient("GET", buildApiUrl("users/all", { "csrf-token": csrfToken }));
|
|
211
|
+
}
|
|
212
|
+
async function fetchVirtualUsersClient() {
|
|
213
|
+
const csrfToken = await fetchCsrfClient("get-virtual-users");
|
|
214
|
+
return await goralysFetchClient("GET", buildApiUrl("users/virtual", { "csrf-token": csrfToken }));
|
|
215
|
+
}
|
|
216
|
+
async function fetchAdminsClient() {
|
|
217
|
+
const csrfToken = await fetchCsrfClient("get-all-admins");
|
|
218
|
+
return await goralysFetchClient("GET", buildApiUrl("admins/all", { "csrf-token": csrfToken }));
|
|
219
|
+
}
|
|
220
|
+
async function fetchVirtualAdminsClient() {
|
|
221
|
+
const csrfToken = await fetchCsrfClient("get-virtual-admins");
|
|
222
|
+
return await goralysFetchClient("GET", buildApiUrl("admins/virtual", { "csrf-token": csrfToken }));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/hooks/useSubjects.ts
|
|
226
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
227
|
+
|
|
177
228
|
// src/lib/subjects/subjects.client.ts
|
|
178
229
|
async function fetchStudentSubjectsClient() {
|
|
179
230
|
const csrfToken = await fetchCsrfClient("get-student-subjects");
|
|
@@ -447,39 +498,6 @@ Attention : les administrateurs ont acc\xE8s \xE0 toutes les fonctionnalit\xE9s
|
|
|
447
498
|
}
|
|
448
499
|
];
|
|
449
500
|
|
|
450
|
-
// src/lib/auth/check-auth.ts
|
|
451
|
-
var checkAuthImpl;
|
|
452
|
-
function configureCheckAuth(impl) {
|
|
453
|
-
checkAuthImpl = impl;
|
|
454
|
-
}
|
|
455
|
-
function isAuthenticated() {
|
|
456
|
-
if (!checkAuthImpl) {
|
|
457
|
-
throw new Error("Auth check not configured. Call configureAuthCheck() first.");
|
|
458
|
-
}
|
|
459
|
-
return checkAuthImpl();
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// src/lib/storage/storage-adapter.ts
|
|
463
|
-
var adapter = null;
|
|
464
|
-
function configureStorage(customAdapter) {
|
|
465
|
-
adapter = customAdapter;
|
|
466
|
-
}
|
|
467
|
-
function getAdapter() {
|
|
468
|
-
if (!adapter) {
|
|
469
|
-
throw new Error("Storage not configured. Call configureStorage() first.");
|
|
470
|
-
}
|
|
471
|
-
return adapter;
|
|
472
|
-
}
|
|
473
|
-
async function storageGet(key) {
|
|
474
|
-
return getAdapter().getItem(key);
|
|
475
|
-
}
|
|
476
|
-
async function storageSet(key, value) {
|
|
477
|
-
await getAdapter().setItem(key, value);
|
|
478
|
-
}
|
|
479
|
-
async function storageRemove(key) {
|
|
480
|
-
await getAdapter().removeItem(key);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
501
|
// src/hooks/useSubjects.ts
|
|
484
502
|
function useSubjects(role, showToast) {
|
|
485
503
|
const [subjects, setSubjects] = useState(null);
|
|
@@ -505,11 +523,11 @@ function useSubjects(role, showToast) {
|
|
|
505
523
|
resolve = r;
|
|
506
524
|
});
|
|
507
525
|
try {
|
|
508
|
-
const syncValue =
|
|
526
|
+
const syncValue = cookiesGet(syncKey);
|
|
509
527
|
if (syncValue == "1") {
|
|
510
528
|
const raw = await storageGet(cacheKey);
|
|
511
529
|
if (raw === null || raw === void 0) {
|
|
512
|
-
|
|
530
|
+
cookiesSet(syncKey, "0");
|
|
513
531
|
await storageRemove(cacheKey);
|
|
514
532
|
await fetchSubjects();
|
|
515
533
|
return;
|
|
@@ -526,7 +544,7 @@ function useSubjects(role, showToast) {
|
|
|
526
544
|
if (res)
|
|
527
545
|
await handleToastRequest(res, showToastRef.current, false);
|
|
528
546
|
const data = await res?.json();
|
|
529
|
-
|
|
547
|
+
cookiesSet(syncKey, "1");
|
|
530
548
|
await storageSet(cacheKey, JSON.stringify(data));
|
|
531
549
|
console.log("[useSubjects] set syncKey and cached to localStorage");
|
|
532
550
|
const result = Array.isArray(data) ? data : null;
|
|
@@ -540,6 +558,16 @@ function useSubjects(role, showToast) {
|
|
|
540
558
|
resolve();
|
|
541
559
|
}
|
|
542
560
|
}, [role]);
|
|
561
|
+
useEffect(() => {
|
|
562
|
+
const onChange = () => {
|
|
563
|
+
if (inFlightRef.current)
|
|
564
|
+
return;
|
|
565
|
+
if (cookiesGet(SUBJECT_SYNCS[role]) != "1") {
|
|
566
|
+
void fetchSubjects();
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
return cookiesOnChange(onChange);
|
|
570
|
+
}, [fetchSubjects, role]);
|
|
543
571
|
useEffect(() => {
|
|
544
572
|
void fetchSubjects();
|
|
545
573
|
}, [fetchSubjects]);
|
|
@@ -575,11 +603,11 @@ function useSupportTickets(showToast) {
|
|
|
575
603
|
resolve = r;
|
|
576
604
|
});
|
|
577
605
|
try {
|
|
578
|
-
const syncValue =
|
|
606
|
+
const syncValue = cookiesGet(syncKey);
|
|
579
607
|
if (syncValue == "1") {
|
|
580
608
|
const raw = await storageGet(cacheKey);
|
|
581
609
|
if (raw === null || raw === void 0) {
|
|
582
|
-
|
|
610
|
+
cookiesSet(syncKey, "0");
|
|
583
611
|
await storageRemove(cacheKey);
|
|
584
612
|
await fetchSupportTickets();
|
|
585
613
|
return;
|
|
@@ -596,9 +624,8 @@ function useSupportTickets(showToast) {
|
|
|
596
624
|
if (res)
|
|
597
625
|
await handleToastRequest(res, showToastRef.current, false);
|
|
598
626
|
const data = await res?.json();
|
|
599
|
-
|
|
627
|
+
cookiesSet(syncKey, "1");
|
|
600
628
|
await storageSet(cacheKey, JSON.stringify(data));
|
|
601
|
-
console.log("[useSupportTickets] set syncKey and cached to localStorage");
|
|
602
629
|
const result = Array.isArray(data) ? data : null;
|
|
603
630
|
setSupportTickets((prev) => {
|
|
604
631
|
if (JSON.stringify(prev) === JSON.stringify(result))
|
|
@@ -610,13 +637,23 @@ function useSupportTickets(showToast) {
|
|
|
610
637
|
resolve();
|
|
611
638
|
}
|
|
612
639
|
}, []);
|
|
640
|
+
useEffect2(() => {
|
|
641
|
+
const onChange = () => {
|
|
642
|
+
if (inFlightRef.current)
|
|
643
|
+
return;
|
|
644
|
+
if (cookiesGet(SUPPORT_TICKET_SYNC) != "1") {
|
|
645
|
+
void fetchSupportTickets();
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
return cookiesOnChange(onChange);
|
|
649
|
+
}, [fetchSupportTickets]);
|
|
613
650
|
useEffect2(() => {
|
|
614
651
|
void fetchSupportTickets();
|
|
615
652
|
}, [fetchSupportTickets]);
|
|
616
653
|
return useMemo2(() => ({
|
|
617
654
|
supportTickets,
|
|
618
655
|
refetch: fetchSupportTickets,
|
|
619
|
-
syncKey:
|
|
656
|
+
syncKey: SUPPORT_TICKET_SYNC
|
|
620
657
|
}), [supportTickets, fetchSupportTickets]);
|
|
621
658
|
}
|
|
622
659
|
|
|
@@ -643,8 +680,16 @@ function useUserCollection(fetchFn, type, showToast) {
|
|
|
643
680
|
resolve = r;
|
|
644
681
|
});
|
|
645
682
|
try {
|
|
646
|
-
|
|
647
|
-
|
|
683
|
+
const syncValue = cookiesGet(syncKey);
|
|
684
|
+
if (syncValue == "1") {
|
|
685
|
+
const raw = await storageGet(cacheKey);
|
|
686
|
+
if (raw === null || raw === void 0) {
|
|
687
|
+
cookiesSet(syncKey, "0");
|
|
688
|
+
await storageRemove(cacheKey);
|
|
689
|
+
await fetchUsers();
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
const cached = JSON.parse(raw ?? "null");
|
|
648
693
|
setUsers((prev) => {
|
|
649
694
|
if (JSON.stringify(prev) === JSON.stringify(cached))
|
|
650
695
|
return prev;
|
|
@@ -657,7 +702,7 @@ function useUserCollection(fetchFn, type, showToast) {
|
|
|
657
702
|
await handleToastRequest(res, showToastRef.current, false);
|
|
658
703
|
const data = await res?.json();
|
|
659
704
|
if (res?.ok) {
|
|
660
|
-
|
|
705
|
+
cookiesSet(syncKey, "1");
|
|
661
706
|
await storageSet(cacheKey, JSON.stringify(data));
|
|
662
707
|
}
|
|
663
708
|
const result = Array.isArray(data) ? data : null;
|
|
@@ -671,6 +716,16 @@ function useUserCollection(fetchFn, type, showToast) {
|
|
|
671
716
|
resolve();
|
|
672
717
|
}
|
|
673
718
|
}, [fetchFn, cacheKey, syncKey]);
|
|
719
|
+
useEffect3(() => {
|
|
720
|
+
const onChange = () => {
|
|
721
|
+
if (inFlightRef.current)
|
|
722
|
+
return;
|
|
723
|
+
if (cookiesGet(syncKey) != "1") {
|
|
724
|
+
void fetchUsers();
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
return cookiesOnChange(onChange);
|
|
728
|
+
}, [fetchUsers, syncKey]);
|
|
674
729
|
useEffect3(() => {
|
|
675
730
|
void fetchUsers();
|
|
676
731
|
}, [fetchUsers]);
|
|
@@ -695,11 +750,6 @@ var LOGO_PATH = {
|
|
|
695
750
|
eye: "m599.07,393.76c7.76-.04,14.2,5.96,14.22,13.26.02,7.46-6.23,13.52-14.08,13.54-7.79.02-14.18-6.07-14.2-13.46-.02-7.3,6.32-13.3,14.06-13.34Z"
|
|
696
751
|
};
|
|
697
752
|
|
|
698
|
-
// src/lib/cookies.ts
|
|
699
|
-
function setCookiesExpire(duration) {
|
|
700
|
-
storageSet("goralys-cookies-expire", String(Date.now() + duration * 1e3));
|
|
701
|
-
}
|
|
702
|
-
|
|
703
753
|
// src/lib/fools.ts
|
|
704
754
|
function isFoolsDay() {
|
|
705
755
|
const today = /* @__PURE__ */ new Date();
|
|
@@ -837,10 +887,10 @@ export {
|
|
|
837
887
|
buildApiUrl,
|
|
838
888
|
buildArray,
|
|
839
889
|
cacheUserDataClient,
|
|
840
|
-
configUserCacheCallbacks,
|
|
841
890
|
configureCheckAuth,
|
|
842
891
|
configureGoralysClient,
|
|
843
892
|
configureStorage,
|
|
893
|
+
configureUserCacheCallbacks,
|
|
844
894
|
emitAuthEvent,
|
|
845
895
|
emitNavigationEvent,
|
|
846
896
|
emitUserEvent,
|
|
@@ -866,7 +916,6 @@ export {
|
|
|
866
916
|
parsePhpDateTime,
|
|
867
917
|
reasonsConfig,
|
|
868
918
|
searchFields,
|
|
869
|
-
setCookiesExpire,
|
|
870
919
|
storageGet,
|
|
871
920
|
storageRemove,
|
|
872
921
|
storageSet,
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
"name": "@goralys/core",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"license": "LGPL-2.1-or-later",
|
|
5
|
+
"description": "Shared business logic for the Goralys web application",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/SAMSAM-55/Goralys",
|
|
9
|
+
"directory": "goralys-core"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"dev": "tsup --watch"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"barrelsby": "^2.8.1",
|
|
38
|
+
"esbuild-plugin-tsconfig-paths": "^1.0.2",
|
|
39
|
+
"react": "^18.0.0",
|
|
40
|
+
"tsup": "^8.0.0",
|
|
41
|
+
"typescript": "^5.0.0"
|
|
19
42
|
}
|
|
20
|
-
|
|
21
|
-
"files": [
|
|
22
|
-
"dist",
|
|
23
|
-
"LICENSE",
|
|
24
|
-
"README.md"
|
|
25
|
-
],
|
|
26
|
-
"publishConfig": {
|
|
27
|
-
"access": "public"
|
|
28
|
-
},
|
|
29
|
-
"peerDependencies": {
|
|
30
|
-
"react": ">=18"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"barrelsby": "^2.8.1",
|
|
34
|
-
"esbuild-plugin-tsconfig-paths": "^1.0.2",
|
|
35
|
-
"react": "^18.0.0",
|
|
36
|
-
"tsup": "^8.0.0",
|
|
37
|
-
"typescript": "^5.0.0"
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "tsup",
|
|
41
|
-
"dev": "tsup --watch"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
43
|
+
}
|