@goralys/core 1.1.3 → 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 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 | Promise<string | null>;
9
- setItem(key: string, value: string): void | Promise<void>;
10
- removeItem(key: string): void | Promise<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): Promise<string | null>;
14
- declare function storageSet(key: string, value: string): Promise<void>;
15
- declare function storageRemove(key: string): Promise<void>;
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,12 +23,14 @@ type CookieValue = string | boolean | number | null | undefined;
23
23
 
24
24
  interface CookiesAdapter {
25
25
  onChange(callback: () => void): () => void;
26
- getCookies(key: string): string | null;
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
  }
30
31
  declare function configureCookies(customAdapter: CookiesAdapter): void;
31
- declare function cookiesGet(key: string): string | null;
32
+ declare function cookiesGet(key: string): CookieValue;
33
+ declare function cookiesGetAll(): Record<string, CookieValue>;
32
34
  declare function cookiesSet(key: string, value: string, path?: string, maxAge?: number): void;
33
35
  declare function cookiesRemove(key: string): void;
34
36
  declare function cookiesOnChange(callback: () => void): () => void;
@@ -279,4 +281,4 @@ declare function fetchVirtualUsersClient(): Promise<Response>;
279
281
  declare function fetchAdminsClient(): Promise<Response>;
280
282
  declare function fetchVirtualAdminsClient(): Promise<Response>;
281
283
 
282
- 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, 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 };
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
- async function storageGet(key) {
24
+ function storageGet(key) {
25
25
  return getAdapter().getItem(key);
26
26
  }
27
- async function storageSet(key, value) {
28
- await getAdapter().setItem(key, value);
27
+ function storageSet(key, value) {
28
+ getAdapter().setItem(key, value);
29
29
  }
30
- async function storageRemove(key) {
31
- await getAdapter().removeItem(key);
30
+ function storageRemove(key) {
31
+ getAdapter().removeItem(key);
32
32
  }
33
33
 
34
34
  // src/lib/storage/cookies-adapter.ts
@@ -45,6 +45,9 @@ 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
  }
@@ -55,7 +58,7 @@ function cookiesOnChange(callback) {
55
58
  return getAdapter2().onChange(callback);
56
59
  }
57
60
  function setCookiesExpire(duration) {
58
- storageSet("goralys-cookies-expire", String(Date.now() + duration * 1e3)).then();
61
+ storageSet("goralys-cookies-expire", String(Date.now() + duration * 1e3));
59
62
  }
60
63
 
61
64
  // src/lib/auth/check-auth.ts
@@ -543,10 +546,10 @@ function useSubjects(role, showToast) {
543
546
  try {
544
547
  const syncValue = cookiesGet(syncKey);
545
548
  if (syncValue == "1") {
546
- const raw = await storageGet(cacheKey);
549
+ const raw = storageGet(cacheKey);
547
550
  if (raw === null || raw === void 0) {
548
551
  cookiesSet(syncKey, "0");
549
- await storageRemove(cacheKey);
552
+ storageRemove(cacheKey);
550
553
  await fetchSubjects();
551
554
  return;
552
555
  }
@@ -563,7 +566,7 @@ function useSubjects(role, showToast) {
563
566
  await handleToastRequest(res, showToastRef.current, false);
564
567
  const data = await res?.json();
565
568
  cookiesSet(syncKey, "1");
566
- await storageSet(cacheKey, JSON.stringify(data));
569
+ storageSet(cacheKey, JSON.stringify(data));
567
570
  console.log("[useSubjects] set syncKey and cached to localStorage");
568
571
  const result = Array.isArray(data) ? data : null;
569
572
  setSubjects((prev) => {
@@ -623,10 +626,10 @@ function useSupportTickets(showToast) {
623
626
  try {
624
627
  const syncValue = cookiesGet(syncKey);
625
628
  if (syncValue == "1") {
626
- const raw = await storageGet(cacheKey);
629
+ const raw = storageGet(cacheKey);
627
630
  if (raw === null || raw === void 0) {
628
631
  cookiesSet(syncKey, "0");
629
- await storageRemove(cacheKey);
632
+ storageRemove(cacheKey);
630
633
  await fetchSupportTickets();
631
634
  return;
632
635
  }
@@ -643,7 +646,7 @@ function useSupportTickets(showToast) {
643
646
  await handleToastRequest(res, showToastRef.current, false);
644
647
  const data = await res?.json();
645
648
  cookiesSet(syncKey, "1");
646
- await storageSet(cacheKey, JSON.stringify(data));
649
+ storageSet(cacheKey, JSON.stringify(data));
647
650
  const result = Array.isArray(data) ? data : null;
648
651
  setSupportTickets((prev) => {
649
652
  if (JSON.stringify(prev) === JSON.stringify(result))
@@ -654,7 +657,7 @@ function useSupportTickets(showToast) {
654
657
  inFlightRef.current = null;
655
658
  resolve();
656
659
  }
657
- }, []);
660
+ }, [showToastRef]);
658
661
  useEffect2(() => {
659
662
  const onChange = () => {
660
663
  if (inFlightRef.current)
@@ -700,10 +703,10 @@ function useUserCollection(fetchFn, type, showToast) {
700
703
  try {
701
704
  const syncValue = cookiesGet(syncKey);
702
705
  if (syncValue == "1") {
703
- const raw = await storageGet(cacheKey);
706
+ const raw = storageGet(cacheKey);
704
707
  if (raw === null || raw === void 0) {
705
708
  cookiesSet(syncKey, "0");
706
- await storageRemove(cacheKey);
709
+ storageRemove(cacheKey);
707
710
  await fetchUsers();
708
711
  return;
709
712
  }
@@ -721,7 +724,7 @@ function useUserCollection(fetchFn, type, showToast) {
721
724
  const data = await res?.json();
722
725
  if (res?.ok) {
723
726
  cookiesSet(syncKey, "1");
724
- await storageSet(cacheKey, JSON.stringify(data));
727
+ storageSet(cacheKey, JSON.stringify(data));
725
728
  }
726
729
  const result = Array.isArray(data) ? data : null;
727
730
  setUsers((prev) => {
@@ -912,6 +915,7 @@ export {
912
915
  configureStorage,
913
916
  configureUserCacheCallbacks,
914
917
  cookiesGet,
918
+ cookiesGetAll,
915
919
  cookiesOnChange,
916
920
  cookiesRemove,
917
921
  cookiesSet,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goralys/core",
3
- "version": "1.1.3",
3
+ "version": "1.2.0",
4
4
  "license": "LGPL-2.1-or-later",
5
5
  "description": "Shared business logic for the Goralys web application",
6
6
  "repository": {