@goralys/core 1.6.4 → 1.6.6

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/README.md CHANGED
@@ -3,12 +3,10 @@
3
3
  ---
4
4
 
5
5
  This package contains the shared business logic for the [Goralys](https://github.com/SAMSAM-55/Goralys) applications –
6
- web
7
- and mobile.
6
+ web and mobile.
8
7
 
9
8
  This package bundles the reusable code for the web frontend and the mobile app to avoid code redundancy and duplication
10
- accross
11
- platforms.
9
+ across platforms.
12
10
 
13
11
  ### Content Overview
14
12
 
@@ -16,9 +14,7 @@ platforms.
16
14
  - `lib/` – Fetch logic, event listeners, etc.
17
15
  - `types/` – Shared TypeScript types
18
16
 
19
- The UI components are **not** part of this package as they are specific to each platform (web / mobile), because the
20
- technologies
21
- used for rendering are different (HTML/CSS for the web vs React Native components).
17
+ The UI components are **not** part of this package.
22
18
 
23
19
  ### Setup
24
20
 
package/dist/index.d.ts CHANGED
@@ -53,7 +53,7 @@ type Toast = {
53
53
  message: string;
54
54
  expires?: number;
55
55
  };
56
- type ToastFn = (toast: Toast, duration?: number) => void;
56
+ type ToastFn = (toast: Toast, animate?: boolean, duration?: number) => void;
57
57
 
58
58
  interface ToastConfig {
59
59
  getShowToast: () => ToastFn;
@@ -109,6 +109,12 @@ type AuthToken = {
109
109
  expires: PHPDateTime;
110
110
  created: PHPDateTime;
111
111
  };
112
+ type AuditAction = {
113
+ initiator: string;
114
+ type: "add" | "update" | "delete" | "other";
115
+ description: string;
116
+ at: PHPDateTime;
117
+ };
112
118
 
113
119
  declare function useAuthTokens(context: AuthTokenContext, target?: string | null): {
114
120
  tokens: AuthToken[] | null;
@@ -132,8 +138,13 @@ type Subject = {
132
138
  teacher: string;
133
139
  teacherToken: string;
134
140
  topic: string;
141
+ topicCode: string;
135
142
  interdisciplinary: boolean;
136
143
  };
144
+ type SubjectsFilterOptions = {
145
+ classrooms: Record<string, string[]>;
146
+ topics: Record<string, string[]>;
147
+ };
137
148
  declare const searchFields: {
138
149
  readonly all: "Tout";
139
150
  readonly student: "Élèves";
@@ -243,6 +254,8 @@ declare const SUPPORT_TICKET_CACHE = "support-tickets-cache";
243
254
  declare const SUPPORT_TICKET_SYNC = "support-tickets-synced";
244
255
  declare const SUBJECT_SYNCS: Record<UserRole["role"], string>;
245
256
  declare const SUBJECT_CACHES: Record<UserRole["role"], string>;
257
+ declare const FILTER_OPTIONS_SYNC = "filter-options-synced";
258
+ declare const FILTER_OPTIONS_CACHE = "filter-options-cache";
246
259
  declare const AUTH_TOKEN_SYNCS: Record<AuthTokenContext, string | undefined>;
247
260
  declare const AUTH_TOKEN_CACHES: Record<AuthTokenContext, string | undefined>;
248
261
  type UserType = {
@@ -307,8 +320,11 @@ declare function isHTTPMethod(maybeMethod: string): maybeMethod is HttpMethod;
307
320
  type GoralysFetchOptions = RequestInit & {
308
321
  suppressRedirect?: boolean;
309
322
  };
323
+ type Json = string | number | boolean | null | Json[] | {
324
+ [k: string]: Json;
325
+ };
310
326
 
311
- declare function goralysFetchClient(method: HttpMethod, input: string | URL | Request, payload?: Record<string, string | number | boolean | null> | FormData, requestOptions?: GoralysFetchOptions): Promise<Response>;
327
+ declare function goralysFetchClient(method: HttpMethod, input: string | URL | Request, payload?: Record<string, Json> | FormData, requestOptions?: GoralysFetchOptions): Promise<Response>;
312
328
  declare function fetchCsrfClient(formId: string): Promise<string | null>;
313
329
  declare function buildApiUrl(endpoint: string, params: Record<string, string | null>, domain?: boolean): string;
314
330
  declare function handleToastRequest(r: Response, showToast: ToastFn, redirect?: boolean, duration?: number): Promise<boolean>;
@@ -351,10 +367,11 @@ declare function getShortFromLong(long: string): string;
351
367
  declare function fetchSubjectsForRoleClient(role: UserRole): Promise<Response | null>;
352
368
 
353
369
  declare function cacheUserDataClient(): Promise<void>;
370
+ declare function arrayAny<T>(arr: T[], cond: (v: T) => boolean): boolean;
354
371
  declare function emptyUserCacheClient(): void;
355
372
  declare function fetchUsersClient(): Promise<Response>;
356
373
  declare function fetchVirtualUsersClient(): Promise<Response>;
357
374
  declare function fetchAdminsClient(): Promise<Response>;
358
375
  declare function fetchVirtualAdminsClient(): Promise<Response>;
359
376
 
360
- export { ADMIN_CACHE_RADIX, ADMIN_SYNC_RADIX, AUTH_TOKEN_CACHES, AUTH_TOKEN_CACHE_RADIX, AUTH_TOKEN_SYNCS, AUTH_TOKEN_SYNC_RADIX, type AuthEvent, type AuthToken, type AuthTokenContext, COOKIES_DISMISSED_KEY, type CheckAuthImpl, type ConfirmOptions, type CookieValue, type CookiesAdapter, type DraftModalResult, EMAIL_KEY, FLASH_TOAST_KEY, FULL_NAME_KEY, GoralysActionHandler, type GoralysClientConfig, type GoralysFetchOptions, 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 ToastConfig, type ToastFn, USERNAME_KEY, USER_CACHES, USER_CACHE_RADIX, USER_ROLES, USER_SYNCS, USER_SYNC_RADIX, type UseSyncedResourceOptions, type User, type UserData, type UserEvent, type UserProfile, type UserRole, type UserType, buildApiUrl, buildArray, cacheUserDataClient, configGoralysCore, configureCheckAuth, configureCookies, configureGoralysClient, configureStorage, configureToast, cookiesGet, cookiesGetAll, cookiesOnChange, cookiesRemove, cookiesSet, emitAuthEvent, emitNavigationEvent, emitUserEvent, emptyUserCacheClient, fetchAdminsClient, fetchAuthTokensForContext, fetchCsrfClient, fetchSubjectsForRoleClient, fetchTokensAdminPanel, fetchTokensProfile, fetchUsersClient, fetchVirtualAdminsClient, fetchVirtualUsersClient, fromPhpDate, getGoralysClientConfig, getLongFromShort, getShortFromLong, getStatusHelper, getStatusLabel, getToastConfig, goralysFetchClient, handleToastRequest, helpContent, isAuthenticated, isFoolsDay, isHTTPMethod, onAuthEvent, onNavigationEvent, onUserEvent, parsePhpDateTime, reasonsConfig, searchFields, separateNames, storageGet, storageKeyAt, storageKeys, storageRemove, storageSet, storageSize, useAdmins, useAuthTokens, useSubjects, useSupportTickets, useSyncedResource, useUsers, useVirtualAdmins, useVirtualUsers };
377
+ export { ADMIN_CACHE_RADIX, ADMIN_SYNC_RADIX, AUTH_TOKEN_CACHES, AUTH_TOKEN_CACHE_RADIX, AUTH_TOKEN_SYNCS, AUTH_TOKEN_SYNC_RADIX, type AuditAction, type AuthEvent, type AuthToken, type AuthTokenContext, COOKIES_DISMISSED_KEY, type CheckAuthImpl, type ConfirmOptions, type CookieValue, type CookiesAdapter, type DraftModalResult, EMAIL_KEY, FILTER_OPTIONS_CACHE, FILTER_OPTIONS_SYNC, FLASH_TOAST_KEY, FULL_NAME_KEY, GoralysActionHandler, type GoralysClientConfig, type GoralysFetchOptions, HTTP_METHODS, type HttpMethod, type Json, 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 SubjectsFilterOptions, type SubjectsSearchField, type SupportReasons, type SupportTicket, type Toast, type ToastConfig, type ToastFn, USERNAME_KEY, USER_CACHES, USER_CACHE_RADIX, USER_ROLES, USER_SYNCS, USER_SYNC_RADIX, type UseSyncedResourceOptions, type User, type UserData, type UserEvent, type UserProfile, type UserRole, type UserType, arrayAny, buildApiUrl, buildArray, cacheUserDataClient, configGoralysCore, configureCheckAuth, configureCookies, configureGoralysClient, configureStorage, configureToast, cookiesGet, cookiesGetAll, cookiesOnChange, cookiesRemove, cookiesSet, emitAuthEvent, emitNavigationEvent, emitUserEvent, emptyUserCacheClient, fetchAdminsClient, fetchAuthTokensForContext, fetchCsrfClient, fetchSubjectsForRoleClient, fetchTokensAdminPanel, fetchTokensProfile, fetchUsersClient, fetchVirtualAdminsClient, fetchVirtualUsersClient, fromPhpDate, getGoralysClientConfig, getLongFromShort, getShortFromLong, getStatusHelper, getStatusLabel, getToastConfig, goralysFetchClient, handleToastRequest, helpContent, isAuthenticated, isFoolsDay, isHTTPMethod, onAuthEvent, onNavigationEvent, onUserEvent, parsePhpDateTime, reasonsConfig, searchFields, separateNames, storageGet, storageKeyAt, storageKeys, storageRemove, storageSet, storageSize, useAdmins, useAuthTokens, useSubjects, useSupportTickets, useSyncedResource, useUsers, useVirtualAdmins, useVirtualUsers };
package/dist/index.js CHANGED
@@ -111,6 +111,8 @@ var SUBJECT_CACHES = {
111
111
  admin: SUBJECT_CACHE_RADIX + "admin",
112
112
  none: SUBJECT_CACHE_RADIX + "unknown"
113
113
  };
114
+ var FILTER_OPTIONS_SYNC = "filter-options-synced";
115
+ var FILTER_OPTIONS_CACHE = "filter-options-cache";
114
116
  var AUTH_TOKEN_SYNCS = {
115
117
  "admin-panel": void 0,
116
118
  profile: AUTH_TOKEN_SYNC_RADIX + "profile"
@@ -520,7 +522,7 @@ async function handleToastRequest(r, showToast, redirect = true, duration) {
520
522
  const res = r.clone();
521
523
  const data = await res.json();
522
524
  if (data?.toast) {
523
- showToast({ type: data.toastType, title: data.toastTitle, message: data.toastMessage }, duration);
525
+ showToast({ type: data.toastType, title: data.toastTitle, message: data.toastMessage }, true, duration);
524
526
  if (data?.redirect && redirect) {
525
527
  emitNavigationEvent({ type: "redirect", url: data.redirect });
526
528
  }
@@ -605,6 +607,8 @@ function useSyncedResource({ name, cacheKey, syncKey, fetcher, parse, requireAut
605
607
  const res = await fetcher();
606
608
  if (res)
607
609
  await handleToastRequest(res, showToastRef.current, false);
610
+ if (!res?.ok)
611
+ return;
608
612
  const raw = await res?.json();
609
613
  if (caching) {
610
614
  cookiesSet(syncKey, "1");
@@ -949,6 +953,8 @@ export {
949
953
  AUTH_TOKEN_SYNC_RADIX,
950
954
  COOKIES_DISMISSED_KEY,
951
955
  EMAIL_KEY,
956
+ FILTER_OPTIONS_CACHE,
957
+ FILTER_OPTIONS_SYNC,
952
958
  FLASH_TOAST_KEY,
953
959
  FULL_NAME_KEY,
954
960
  GoralysActionHandler,
@@ -970,6 +976,7 @@ export {
970
976
  USER_ROLES,
971
977
  USER_SYNCS,
972
978
  USER_SYNC_RADIX,
979
+ arrayAny,
973
980
  buildApiUrl,
974
981
  buildArray,
975
982
  cacheUserDataClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goralys/core",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "license": "LGPL-2.1-or-later",
5
5
  "description": "Shared business logic for the Goralys web application",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "scripts": {
30
30
  "prebuild": "pnpm barrel",
31
31
  "build": "tsup",
32
- "typeCheck": "tsgo --noEmit",
32
+ "typeCheck": "node ./node_modules/typescript-native/bin/tsc --noEmit",
33
33
  "dev": "tsup --watch",
34
34
  "barrel": "node -e \"require('fs').rmSync('./src/index.ts',{force:true})\" && barrelsby -d ./src -l top"
35
35
  },
@@ -37,11 +37,11 @@
37
37
  "react": ">=18"
38
38
  },
39
39
  "devDependencies": {
40
- "@typescript/native-preview": "7.0.0-dev.20260705.1",
40
+ "typescript": "^6.0.3",
41
+ "typescript-native": "npm:typescript@^7.0.2",
41
42
  "barrelsby": "^2.8.1",
42
43
  "esbuild-plugin-tsconfig-paths": "^1.0.2",
43
44
  "react": "^18.0.0",
44
- "tsup": "^8.0.0",
45
- "typescript": "^5.0.0"
45
+ "tsup": "^8.0.0"
46
46
  }
47
47
  }