@goralys/core 1.1.1 → 1.1.2

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
@@ -21,10 +21,29 @@ interface PHPDateTime {
21
21
  }
22
22
  type CookieValue = string | boolean | number | null | undefined;
23
23
 
24
+ interface CookiesAdapter {
25
+ onChange(callback: () => void): () => void;
26
+ getCookies(key: string): string | null;
27
+ setCookies(key: string, value: CookieValue, path: string, maxAge: number): void;
28
+ removeCookies(key: string): void;
29
+ }
30
+
24
31
  type CheckAuthImpl = () => boolean;
25
32
  declare function configureCheckAuth(impl: CheckAuthImpl): void;
26
33
  declare function isAuthenticated(): boolean;
27
34
 
35
+ interface GoralysCoreConfig {
36
+ client: GoralysClientConfig;
37
+ storage: StorageAdapter;
38
+ cookies: CookiesAdapter;
39
+ auth: CheckAuthImpl;
40
+ cache: {
41
+ cache: () => Promise<void>;
42
+ empty: () => void;
43
+ };
44
+ }
45
+ declare function configGoralysCore(cfg: GoralysCoreConfig): void;
46
+
28
47
  type UserRole = {
29
48
  role: "admin" | "teacher" | "student" | "none";
30
49
  };
@@ -254,4 +273,4 @@ declare function fetchVirtualUsersClient(): Promise<Response>;
254
273
  declare function fetchAdminsClient(): Promise<Response>;
255
274
  declare function fetchVirtualAdminsClient(): Promise<Response>;
256
275
 
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 };
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 };
package/dist/index.js CHANGED
@@ -33,6 +33,9 @@ async function storageRemove(key) {
33
33
 
34
34
  // src/lib/storage/cookies-adapter.ts
35
35
  var adapter2 = null;
36
+ function configureCookies(customAdapter) {
37
+ adapter2 = customAdapter;
38
+ }
36
39
  function getAdapter2() {
37
40
  if (!adapter2) {
38
41
  throw new Error("Cookies not configured. Call configureCookies() first.");
@@ -222,6 +225,15 @@ async function fetchVirtualAdminsClient() {
222
225
  return await goralysFetchClient("GET", buildApiUrl("admins/virtual", { "csrf-token": csrfToken }));
223
226
  }
224
227
 
228
+ // src/config.ts
229
+ function configGoralysCore(cfg) {
230
+ configureGoralysClient(cfg.client);
231
+ configureCookies(cfg.cookies);
232
+ configureStorage(cfg.storage);
233
+ configureCheckAuth(cfg.auth);
234
+ configureUserCacheCallbacks(cfg.cache.cache, cfg.cache.empty);
235
+ }
236
+
225
237
  // src/hooks/useSubjects.ts
226
238
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
227
239
 
@@ -887,6 +899,7 @@ export {
887
899
  buildApiUrl,
888
900
  buildArray,
889
901
  cacheUserDataClient,
902
+ configGoralysCore,
890
903
  configureCheckAuth,
891
904
  configureGoralysClient,
892
905
  configureStorage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goralys/core",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "license": "LGPL-2.1-or-later",
5
5
  "description": "Shared business logic for the Goralys web application",
6
6
  "repository": {