@goralys/core 1.1.2 → 1.2.0
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 +16 -8
- package/dist/index.js +31 -15
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,14 +5,14 @@ declare function configureGoralysClient(cfg: GoralysClientConfig): void;
|
|
|
5
5
|
declare function getGoralysClientConfig(): GoralysClientConfig;
|
|
6
6
|
|
|
7
7
|
interface StorageAdapter {
|
|
8
|
-
getItem(key: string): string | null
|
|
9
|
-
setItem(key: string, value: string): void
|
|
10
|
-
removeItem(key: string): void
|
|
8
|
+
getItem(key: string): string | null;
|
|
9
|
+
setItem(key: string, value: string): void;
|
|
10
|
+
removeItem(key: string): void;
|
|
11
11
|
}
|
|
12
12
|
declare function configureStorage(customAdapter: StorageAdapter): void;
|
|
13
|
-
declare function storageGet(key: string):
|
|
14
|
-
declare function storageSet(key: string, value: string):
|
|
15
|
-
declare function storageRemove(key: string):
|
|
13
|
+
declare function storageGet(key: string): string | null;
|
|
14
|
+
declare function storageSet(key: string, value: string): void;
|
|
15
|
+
declare function storageRemove(key: string): void;
|
|
16
16
|
|
|
17
17
|
interface PHPDateTime {
|
|
18
18
|
date: string;
|
|
@@ -23,10 +23,18 @@ type CookieValue = string | boolean | number | null | undefined;
|
|
|
23
23
|
|
|
24
24
|
interface CookiesAdapter {
|
|
25
25
|
onChange(callback: () => void): () => void;
|
|
26
|
-
getCookies(key: string):
|
|
26
|
+
getCookies(key: string): CookieValue;
|
|
27
|
+
getAll(): Record<string, CookieValue>;
|
|
27
28
|
setCookies(key: string, value: CookieValue, path: string, maxAge: number): void;
|
|
28
29
|
removeCookies(key: string): void;
|
|
29
30
|
}
|
|
31
|
+
declare function configureCookies(customAdapter: CookiesAdapter): void;
|
|
32
|
+
declare function cookiesGet(key: string): CookieValue;
|
|
33
|
+
declare function cookiesGetAll(): Record<string, CookieValue>;
|
|
34
|
+
declare function cookiesSet(key: string, value: string, path?: string, maxAge?: number): void;
|
|
35
|
+
declare function cookiesRemove(key: string): void;
|
|
36
|
+
declare function cookiesOnChange(callback: () => void): () => void;
|
|
37
|
+
declare function setCookiesExpire(duration: number): void;
|
|
30
38
|
|
|
31
39
|
type CheckAuthImpl = () => boolean;
|
|
32
40
|
declare function configureCheckAuth(impl: CheckAuthImpl): void;
|
|
@@ -273,4 +281,4 @@ declare function fetchVirtualUsersClient(): Promise<Response>;
|
|
|
273
281
|
declare function fetchAdminsClient(): Promise<Response>;
|
|
274
282
|
declare function fetchVirtualAdminsClient(): Promise<Response>;
|
|
275
283
|
|
|
276
|
-
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, configGoralysCore, 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 };
|
|
284
|
+
export { ADMIN_CACHE_RADIX, ADMIN_SYNC_RADIX, type AuthEvent, type CheckAuthImpl, type ConfirmOptions, type CookieValue, type CookiesAdapter, 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, configGoralysCore, configureCheckAuth, configureCookies, configureGoralysClient, configureStorage, configureUserCacheCallbacks, cookiesGet, cookiesGetAll, cookiesOnChange, cookiesRemove, cookiesSet, 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, setCookiesExpire, storageGet, storageRemove, storageSet, useAdmins, useSubjects, useSupportTickets, useUsers, useVirtualAdmins, useVirtualUsers };
|
package/dist/index.js
CHANGED
|
@@ -21,14 +21,14 @@ function getAdapter() {
|
|
|
21
21
|
}
|
|
22
22
|
return adapter;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
function storageGet(key) {
|
|
25
25
|
return getAdapter().getItem(key);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
function storageSet(key, value) {
|
|
28
|
+
getAdapter().setItem(key, value);
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
function storageRemove(key) {
|
|
31
|
+
getAdapter().removeItem(key);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// src/lib/storage/cookies-adapter.ts
|
|
@@ -45,12 +45,21 @@ function getAdapter2() {
|
|
|
45
45
|
function cookiesGet(key) {
|
|
46
46
|
return getAdapter2().getCookies(key);
|
|
47
47
|
}
|
|
48
|
+
function cookiesGetAll() {
|
|
49
|
+
return getAdapter2().getAll();
|
|
50
|
+
}
|
|
48
51
|
function cookiesSet(key, value, path = "/", maxAge = 1.5 * 60) {
|
|
49
52
|
getAdapter2().setCookies(key, value, path, maxAge);
|
|
50
53
|
}
|
|
54
|
+
function cookiesRemove(key) {
|
|
55
|
+
getAdapter2().removeCookies(key);
|
|
56
|
+
}
|
|
51
57
|
function cookiesOnChange(callback) {
|
|
52
58
|
return getAdapter2().onChange(callback);
|
|
53
59
|
}
|
|
60
|
+
function setCookiesExpire(duration) {
|
|
61
|
+
storageSet("goralys-cookies-expire", String(Date.now() + duration * 1e3));
|
|
62
|
+
}
|
|
54
63
|
|
|
55
64
|
// src/lib/auth/check-auth.ts
|
|
56
65
|
var checkAuthImpl;
|
|
@@ -537,10 +546,10 @@ function useSubjects(role, showToast) {
|
|
|
537
546
|
try {
|
|
538
547
|
const syncValue = cookiesGet(syncKey);
|
|
539
548
|
if (syncValue == "1") {
|
|
540
|
-
const raw =
|
|
549
|
+
const raw = storageGet(cacheKey);
|
|
541
550
|
if (raw === null || raw === void 0) {
|
|
542
551
|
cookiesSet(syncKey, "0");
|
|
543
|
-
|
|
552
|
+
storageRemove(cacheKey);
|
|
544
553
|
await fetchSubjects();
|
|
545
554
|
return;
|
|
546
555
|
}
|
|
@@ -557,7 +566,7 @@ function useSubjects(role, showToast) {
|
|
|
557
566
|
await handleToastRequest(res, showToastRef.current, false);
|
|
558
567
|
const data = await res?.json();
|
|
559
568
|
cookiesSet(syncKey, "1");
|
|
560
|
-
|
|
569
|
+
storageSet(cacheKey, JSON.stringify(data));
|
|
561
570
|
console.log("[useSubjects] set syncKey and cached to localStorage");
|
|
562
571
|
const result = Array.isArray(data) ? data : null;
|
|
563
572
|
setSubjects((prev) => {
|
|
@@ -617,10 +626,10 @@ function useSupportTickets(showToast) {
|
|
|
617
626
|
try {
|
|
618
627
|
const syncValue = cookiesGet(syncKey);
|
|
619
628
|
if (syncValue == "1") {
|
|
620
|
-
const raw =
|
|
629
|
+
const raw = storageGet(cacheKey);
|
|
621
630
|
if (raw === null || raw === void 0) {
|
|
622
631
|
cookiesSet(syncKey, "0");
|
|
623
|
-
|
|
632
|
+
storageRemove(cacheKey);
|
|
624
633
|
await fetchSupportTickets();
|
|
625
634
|
return;
|
|
626
635
|
}
|
|
@@ -637,7 +646,7 @@ function useSupportTickets(showToast) {
|
|
|
637
646
|
await handleToastRequest(res, showToastRef.current, false);
|
|
638
647
|
const data = await res?.json();
|
|
639
648
|
cookiesSet(syncKey, "1");
|
|
640
|
-
|
|
649
|
+
storageSet(cacheKey, JSON.stringify(data));
|
|
641
650
|
const result = Array.isArray(data) ? data : null;
|
|
642
651
|
setSupportTickets((prev) => {
|
|
643
652
|
if (JSON.stringify(prev) === JSON.stringify(result))
|
|
@@ -648,7 +657,7 @@ function useSupportTickets(showToast) {
|
|
|
648
657
|
inFlightRef.current = null;
|
|
649
658
|
resolve();
|
|
650
659
|
}
|
|
651
|
-
}, []);
|
|
660
|
+
}, [showToastRef]);
|
|
652
661
|
useEffect2(() => {
|
|
653
662
|
const onChange = () => {
|
|
654
663
|
if (inFlightRef.current)
|
|
@@ -694,10 +703,10 @@ function useUserCollection(fetchFn, type, showToast) {
|
|
|
694
703
|
try {
|
|
695
704
|
const syncValue = cookiesGet(syncKey);
|
|
696
705
|
if (syncValue == "1") {
|
|
697
|
-
const raw =
|
|
706
|
+
const raw = storageGet(cacheKey);
|
|
698
707
|
if (raw === null || raw === void 0) {
|
|
699
708
|
cookiesSet(syncKey, "0");
|
|
700
|
-
|
|
709
|
+
storageRemove(cacheKey);
|
|
701
710
|
await fetchUsers();
|
|
702
711
|
return;
|
|
703
712
|
}
|
|
@@ -715,7 +724,7 @@ function useUserCollection(fetchFn, type, showToast) {
|
|
|
715
724
|
const data = await res?.json();
|
|
716
725
|
if (res?.ok) {
|
|
717
726
|
cookiesSet(syncKey, "1");
|
|
718
|
-
|
|
727
|
+
storageSet(cacheKey, JSON.stringify(data));
|
|
719
728
|
}
|
|
720
729
|
const result = Array.isArray(data) ? data : null;
|
|
721
730
|
setUsers((prev) => {
|
|
@@ -901,9 +910,15 @@ export {
|
|
|
901
910
|
cacheUserDataClient,
|
|
902
911
|
configGoralysCore,
|
|
903
912
|
configureCheckAuth,
|
|
913
|
+
configureCookies,
|
|
904
914
|
configureGoralysClient,
|
|
905
915
|
configureStorage,
|
|
906
916
|
configureUserCacheCallbacks,
|
|
917
|
+
cookiesGet,
|
|
918
|
+
cookiesGetAll,
|
|
919
|
+
cookiesOnChange,
|
|
920
|
+
cookiesRemove,
|
|
921
|
+
cookiesSet,
|
|
907
922
|
emitAuthEvent,
|
|
908
923
|
emitNavigationEvent,
|
|
909
924
|
emitUserEvent,
|
|
@@ -929,6 +944,7 @@ export {
|
|
|
929
944
|
parsePhpDateTime,
|
|
930
945
|
reasonsConfig,
|
|
931
946
|
searchFields,
|
|
947
|
+
setCookiesExpire,
|
|
932
948
|
storageGet,
|
|
933
949
|
storageRemove,
|
|
934
950
|
storageSet,
|