@goralys/core 1.2.2 → 1.2.3

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
@@ -172,6 +172,7 @@ declare const LOGO_PATH: {
172
172
 
173
173
  declare const COOKIES_DISMISSED_KEY = "cookie-banner-dismissed";
174
174
  declare const PERSISTANT_COOKIES: string[];
175
+ declare const FLASH_TOAST_KEY = "flash-toast";
175
176
  declare const PERSISTANT_LOCALS: string[];
176
177
  declare const USERNAME_KEY = "username";
177
178
  declare const ROLE_KEY = "user-role";
@@ -270,6 +271,14 @@ declare function onNavigationEvent(listener: Listener): () => void;
270
271
  * @returns The full subject name if a match is found; otherwise, returns the input string itself.
271
272
  */
272
273
  declare function getLongFromShort(short: string): string;
274
+ /**
275
+ * Returns the full name of a subject based on its short name or an alias.
276
+ * It searches for the first subject in {@link SUBJECTS} whose short name starts with the given string.
277
+ *
278
+ * @param long The long name tp search for.
279
+ * @returns The subject short name, alias, or prefix if a match is found; otherwise, returns the input string itself.
280
+ */
281
+ declare function getShortFromLong(long: string): string;
273
282
 
274
283
  declare function fetchSubjectsForRoleClient(role: UserRole): Promise<Response | null>;
275
284
 
@@ -280,4 +289,4 @@ declare function fetchVirtualUsersClient(): Promise<Response>;
280
289
  declare function fetchAdminsClient(): Promise<Response>;
281
290
  declare function fetchVirtualAdminsClient(): Promise<Response>;
282
291
 
283
- export { ADMIN_CACHE_RADIX, ADMIN_SYNC_RADIX, type AuthEvent, COOKIES_DISMISSED_KEY, 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, 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, storageGet, storageKeyAt, storageRemove, storageSet, storageSize, useAdmins, useSubjects, useSupportTickets, useUsers, useVirtualAdmins, useVirtualUsers };
292
+ export { ADMIN_CACHE_RADIX, ADMIN_SYNC_RADIX, type AuthEvent, COOKIES_DISMISSED_KEY, type CheckAuthImpl, type ConfirmOptions, type CookieValue, type CookiesAdapter, type DraftModalResult, EMAIL_KEY, FLASH_TOAST_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, cookiesGet, cookiesGetAll, cookiesOnChange, cookiesRemove, cookiesSet, emitAuthEvent, emitNavigationEvent, emitUserEvent, emptyUserCacheClient, fetchAdminsClient, fetchCsrfClient, fetchSubjectsForRoleClient, fetchUsersClient, fetchVirtualAdminsClient, fetchVirtualUsersClient, getGoralysClientConfig, getLongFromShort, getShortFromLong, getStatusHelper, getStatusLabel, goralysFetchClient, handleToastRequest, helpContent, isAuthenticated, isFoolsDay, isHTTPMethod, onAuthEvent, onNavigationEvent, onUserEvent, parsePhpDateTime, reasonsConfig, searchFields, storageGet, storageKeyAt, storageRemove, storageSet, storageSize, useAdmins, useSubjects, useSupportTickets, useUsers, useVirtualAdmins, useVirtualUsers };
package/dist/index.js CHANGED
@@ -92,7 +92,8 @@ function onNavigationEvent(listener) {
92
92
  // src/lib/config.ts
93
93
  var COOKIES_DISMISSED_KEY = "cookie-banner-dismissed";
94
94
  var PERSISTANT_COOKIES = [COOKIES_DISMISSED_KEY, "rate_limit_token"];
95
- var PERSISTANT_LOCALS = ["goralys-cookies-expire", "flash_toast"];
95
+ var FLASH_TOAST_KEY = "flash-toast";
96
+ var PERSISTANT_LOCALS = ["goralys-cookies-expire", FLASH_TOAST_KEY];
96
97
  var USERNAME_KEY = "username";
97
98
  var ROLE_KEY = "user-role";
98
99
  var FULL_NAME_KEY = "full-name";
@@ -789,31 +790,96 @@ var parsePhpDateTime = (phpDate) => {
789
790
 
790
791
  // src/lib/subjects/subjects-utils.ts
791
792
  var SUBJECTS = [
793
+ // Arts plastiques
794
+ ["arts", "arts plastiques"],
795
+ ["arpla", "arts plastiques"],
792
796
  ["apla", "arts plastiques"],
793
797
  ["arts-plastiques", "arts plastiques"],
794
- ["arts", "arts plastiques"],
798
+ // Cinéma - audiovisuel
799
+ ["cine.av", "cin\xE9ma audiovisuel"],
795
800
  ["ciav", "cin\xE9ma audiovisuel"],
796
801
  ["cinema", "cin\xE9ma audiovisuel"],
797
802
  ["cav", "cin\xE9ma audiovisuel"],
803
+ // Arts du cirque
804
+ ["a.cirque", "arts du cirque"],
805
+ ["cirque", "arts du cirque"],
806
+ // Danse
807
+ ["danse", "danse"],
808
+ // Histoire des arts
809
+ ["hist.arts", "histoire des arts"],
810
+ ["histoire-arts", "histoire des arts"],
811
+ ["hda", "histoire des arts"],
812
+ // Musique
813
+ ["mus", "musique"],
814
+ ["musique", "musique"],
815
+ // Théâtre
816
+ ["thea", "th\xE9\xE2tre"],
817
+ ["th\xE9\xE2tre", "th\xE9\xE2tre"],
818
+ ["theatre", "th\xE9\xE2tre"],
819
+ // Histoire-géographie, géopolitique et sciences politiques
820
+ ["HGGSP", "histoire g\xE9ographie g\xE9opolitique et sciences politiques"],
798
821
  ["hggsp", "histoire g\xE9ographie g\xE9opolitique et sciences politiques"],
799
- ["hlphi", "humanit\xE9 litt\xE9rature et philosophie"],
822
+ // Humanités, littérature et philosophie
823
+ ["HLP", "humanit\xE9 litt\xE9rature et philosophie"],
800
824
  ["hlp", "humanit\xE9 litt\xE9rature et philosophie"],
825
+ ["hlphi", "humanit\xE9 litt\xE9rature et philosophie"],
826
+ // Langues, littératures et cultures étrangères et régionales
827
+ ["LLCER", "langue litt\xE9rature et culture \xE9trang\xE8re"],
801
828
  ["llce", "langue litt\xE9rature et culture \xE9trang\xE8re"],
802
829
  ["llcer", "langue litt\xE9rature et culture \xE9trang\xE8re"],
830
+ // Littérature et langues et cultures de l'Antiquité
831
+ ["LLCA", "litt\xE9rature et langues et cultures de l'antiquit\xE9"],
832
+ ["llca", "litt\xE9rature et langues et cultures de l'antiquit\xE9"],
833
+ ["lca", "litt\xE9rature et langues et cultures de l'antiquit\xE9"],
834
+ // Mathématiques
803
835
  ["maths", "math\xE9matiques"],
804
836
  ["math", "math\xE9matiques"],
805
- ["nsinf", "num\xE9rique et sciences informatiques"],
837
+ // Numérique et sciences informatiques
838
+ ["num.sci.inf", "num\xE9rique et sciences informatiques"],
806
839
  ["nsi", "num\xE9rique et sciences informatiques"],
840
+ ["nsinf", "num\xE9rique et sciences informatiques"],
841
+ ["n.s.i", "num\xE9rique et sciences informatiques"],
842
+ // Physique-chimie
843
+ ["PCH", "physique-chimie"],
807
844
  ["phch", "physique-chimie"],
808
845
  ["pc", "physique-chimie"],
846
+ // Sciences de la vie et de la Terre
847
+ ["SVT", "sciences et vie de la terre"],
848
+ ["svt", "sciences et vie de la terre"],
849
+ // Sciences économiques et sociales
850
+ ["SES", "sciences \xE9conomiques et sociales"],
809
851
  ["ses", "sciences \xE9conomiques et sociales"],
810
- ["svt", "sciences et vie de la terre"]
852
+ // Sciences de l'ingénieur
853
+ ["sci.ing", "sciences de l'ing\xE9nieur"],
854
+ ["si", "sciences de l'ing\xE9nieur"],
855
+ ["scing", "sciences de l'ing\xE9nieur"],
856
+ // Éducation physique, pratiques et culture sportives
857
+ ["EPS", "\xE9ducation physique pratiques et culture sportives"],
858
+ ["sport", "\xE9ducation physique pratiques et culture sportives"],
859
+ ["eppcs", "\xE9ducation physique pratiques et culture sportives"]
811
860
  ];
861
+ function formatAlias(a) {
862
+ if (a.toUpperCase() === a)
863
+ return a;
864
+ const hasPoints = a.includes(".");
865
+ if (!hasPoints)
866
+ return capitalize(a);
867
+ let result = "";
868
+ const clean = a.toLowerCase().replace(" ", "");
869
+ clean.split(".").forEach((part) => result += capitalize(part) + ". ");
870
+ return result.trim();
871
+ }
872
+ var capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
812
873
  function getLongFromShort(short) {
813
874
  const search = short.toLowerCase().trim();
814
875
  const match = SUBJECTS.find(([key]) => key.startsWith(search));
815
876
  return match ? match[1] : search;
816
877
  }
878
+ function getShortFromLong(long) {
879
+ const search = long.toLowerCase().trim();
880
+ const match = SUBJECTS.find(([, value]) => value.startsWith(search));
881
+ return match ? formatAlias(match[0]) : search;
882
+ }
817
883
 
818
884
  // src/types/subjects.ts
819
885
  var SubjectStatusConfig = {
@@ -878,6 +944,7 @@ export {
878
944
  ADMIN_SYNC_RADIX,
879
945
  COOKIES_DISMISSED_KEY,
880
946
  EMAIL_KEY,
947
+ FLASH_TOAST_KEY,
881
948
  FULL_NAME_KEY,
882
949
  GoralysActionHandler,
883
950
  LOGO_PATH,
@@ -923,6 +990,7 @@ export {
923
990
  fetchVirtualUsersClient,
924
991
  getGoralysClientConfig,
925
992
  getLongFromShort,
993
+ getShortFromLong,
926
994
  getStatusHelper,
927
995
  getStatusLabel,
928
996
  goralysFetchClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goralys/core",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "license": "LGPL-2.1-or-later",
5
5
  "description": "Shared business logic for the Goralys web application",
6
6
  "repository": {