@goralys/core 1.5.0 → 1.6.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/LICENSE CHANGED
@@ -1,165 +1,165 @@
1
- GNU LESSER GENERAL PUBLIC LICENSE
2
- Version 3, 29 June 2007
3
-
4
- Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
- Everyone is permitted to copy and distribute verbatim copies
6
- of this license document, but changing it is not allowed.
7
-
8
-
9
- This version of the GNU Lesser General Public License incorporates
10
- the terms and conditions of version 3 of the GNU General Public
11
- License, supplemented by the additional permissions listed below.
12
-
13
- 0. Additional Definitions.
14
-
15
- As used herein, "this License" refers to version 3 of the GNU Lesser
16
- General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
- General Public License.
18
-
19
- "The Library" refers to a covered work governed by this License,
20
- other than an Application or a Combined Work as defined below.
21
-
22
- An "Application" is any work that makes use of an interface provided
23
- by the Library, but which is not otherwise based on the Library.
24
- Defining a subclass of a class defined by the Library is deemed a mode
25
- of using an interface provided by the Library.
26
-
27
- A "Combined Work" is a work produced by combining or linking an
28
- Application with the Library. The particular version of the Library
29
- with which the Combined Work was made is also called the "Linked
30
- Version".
31
-
32
- The "Minimal Corresponding Source" for a Combined Work means the
33
- Corresponding Source for the Combined Work, excluding any source code
34
- for portions of the Combined Work that, considered in isolation, are
35
- based on the Application, and not on the Linked Version.
36
-
37
- The "Corresponding Application Code" for a Combined Work means the
38
- object code and/or source code for the Application, including any data
39
- and utility programs needed for reproducing the Combined Work from the
40
- Application, but excluding the System Libraries of the Combined Work.
41
-
42
- 1. Exception to Section 3 of the GNU GPL.
43
-
44
- You may convey a covered work under sections 3 and 4 of this License
45
- without being bound by section 3 of the GNU GPL.
46
-
47
- 2. Conveying Modified Versions.
48
-
49
- If you modify a copy of the Library, and, in your modifications, a
50
- facility refers to a function or data to be supplied by an Application
51
- that uses the facility (other than as an argument passed when the
52
- facility is invoked), then you may convey a copy of the modified
53
- version:
54
-
55
- a) under this License, provided that you make a good faith effort to
56
- ensure that, in the event an Application does not supply the
57
- function or data, the facility still operates, and performs
58
- whatever part of its purpose remains meaningful, or
59
-
60
- b) under the GNU GPL, with none of the additional permissions of
61
- this License applicable to that copy.
62
-
63
- 3. Object Code Incorporating Material from Library Header Files.
64
-
65
- The object code form of an Application may incorporate material from
66
- a header file that is part of the Library. You may convey such object
67
- code under terms of your choice, provided that, if the incorporated
68
- material is not limited to numerical parameters, data structure
69
- layouts and accessors, or small macros, inline functions and templates
70
- (ten or fewer lines in length), you do both of the following:
71
-
72
- a) Give prominent notice with each copy of the object code that the
73
- Library is used in it and that the Library and its use are
74
- covered by this License.
75
-
76
- b) Accompany the object code with a copy of the GNU GPL and this license
77
- document.
78
-
79
- 4. Combined Works.
80
-
81
- You may convey a Combined Work under terms of your choice that,
82
- taken together, effectively do not restrict modification of the
83
- portions of the Library contained in the Combined Work and reverse
84
- engineering for debugging such modifications, if you also do each of
85
- the following:
86
-
87
- a) Give prominent notice with each copy of the Combined Work that
88
- the Library is used in it and that the Library and its use are
89
- covered by this License.
90
-
91
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
- document.
93
-
94
- c) For a Combined Work that displays copyright notices during
95
- execution, include the copyright notice for the Library among
96
- these notices, as well as a reference directing the user to the
97
- copies of the GNU GPL and this license document.
98
-
99
- d) Do one of the following:
100
-
101
- 0) Convey the Minimal Corresponding Source under the terms of this
102
- License, and the Corresponding Application Code in a form
103
- suitable for, and under terms that permit, the user to
104
- recombine or relink the Application with a modified version of
105
- the Linked Version to produce a modified Combined Work, in the
106
- manner specified by section 6 of the GNU GPL for conveying
107
- Corresponding Source.
108
-
109
- 1) Use a suitable shared library mechanism for linking with the
110
- Library. A suitable mechanism is one that (a) uses at run time
111
- a copy of the Library already present on the user's computer
112
- system, and (b) will operate properly with a modified version
113
- of the Library that is interface-compatible with the Linked
114
- Version.
115
-
116
- e) Provide Installation Information, but only if you would otherwise
117
- be required to provide such information under section 6 of the
118
- GNU GPL, and only to the extent that such information is
119
- necessary to install and execute a modified version of the
120
- Combined Work produced by recombining or relinking the
121
- Application with a modified version of the Linked Version. (If
122
- you use option 4d0, the Installation Information must accompany
123
- the Minimal Corresponding Source and Corresponding Application
124
- Code. If you use option 4d1, you must provide the Installation
125
- Information in the manner specified by section 6 of the GNU GPL
126
- for conveying Corresponding Source.)
127
-
128
- 5. Combined Libraries.
129
-
130
- You may place library facilities that are a work based on the
131
- Library side by side in a single library together with other library
132
- facilities that are not Applications and are not covered by this
133
- License, and convey such a combined library under terms of your
134
- choice, if you do both of the following:
135
-
136
- a) Accompany the combined library with a copy of the same work based
137
- on the Library, uncombined with any other library facilities,
138
- conveyed under the terms of this License.
139
-
140
- b) Give prominent notice with the combined library that part of it
141
- is a work based on the Library, and explaining where to find the
142
- accompanying uncombined form of the same work.
143
-
144
- 6. Revised Versions of the GNU Lesser General Public License.
145
-
146
- The Free Software Foundation may publish revised and/or new versions
147
- of the GNU Lesser General Public License from time to time. Such new
148
- versions will be similar in spirit to the present version, but may
149
- differ in detail to address new problems or concerns.
150
-
151
- Each version is given a distinguishing version number. If the
152
- Library as you received it specifies that a certain numbered version
153
- of the GNU Lesser General Public License "or any later version"
154
- applies to it, you have the option of following the terms and
155
- conditions either of that published version or of any later version
156
- published by the Free Software Foundation. If the Library as you
157
- received it does not specify a version number of the GNU Lesser
158
- General Public License, you may choose any version of the GNU Lesser
159
- General Public License ever published by the Free Software Foundation.
160
-
161
- If the Library as you received it specifies that a proxy can decide
162
- whether future versions of the GNU Lesser General Public License shall
163
- apply, that proxy's public statement of acceptance of any version is
164
- permanent authorization for you to choose that version for the
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
165
  Library.
package/README.md CHANGED
@@ -1,47 +1,47 @@
1
- ## Goralys Core
2
-
3
- ---
4
-
5
- This package contains the shared business logic for the [Goralys](https://github.com/SAMSAM-55/Goralys) applications –
6
- web
7
- and mobile.
8
-
9
- This package bundles the reusable code for the web frontend and the mobile app to avoid code redundancy and duplication
10
- accross
11
- platforms.
12
-
13
- ### Content Overview
14
-
15
- - `hooks/` – Reusable React hooks (independant from the DOM)
16
- - `lib/` – Fetch logic, event listeners, etc.
17
- - `types/` – Shared TypeScript types
18
-
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).
22
-
23
- ### Setup
24
-
25
- ```bash
26
- pnpm add @goralys/core
27
- ```
28
-
29
- ### Development
30
-
31
- This package is part of the Goralys monorepo and is managed via pnpm workspaces
32
-
33
- ```bash
34
- # From the project root
35
- cd goralys-core
36
- pnpm install
37
- pnpm build
38
- pnpm dev
39
- ```
40
-
41
- ### License
42
-
43
- This package is distributed under the LGPL-2.1-or-later license, see [LICENSE](LICENSE) for more information.
44
-
45
- ### Contact
46
-
1
+ ## Goralys Core
2
+
3
+ ---
4
+
5
+ This package contains the shared business logic for the [Goralys](https://github.com/SAMSAM-55/Goralys) applications –
6
+ web
7
+ and mobile.
8
+
9
+ This package bundles the reusable code for the web frontend and the mobile app to avoid code redundancy and duplication
10
+ accross
11
+ platforms.
12
+
13
+ ### Content Overview
14
+
15
+ - `hooks/` – Reusable React hooks (independant from the DOM)
16
+ - `lib/` – Fetch logic, event listeners, etc.
17
+ - `types/` – Shared TypeScript types
18
+
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).
22
+
23
+ ### Setup
24
+
25
+ ```bash
26
+ pnpm add @goralys/core
27
+ ```
28
+
29
+ ### Development
30
+
31
+ This package is part of the Goralys monorepo and is managed via pnpm workspaces
32
+
33
+ ```bash
34
+ # From the project root
35
+ cd goralys-core
36
+ pnpm install
37
+ pnpm build
38
+ pnpm dev
39
+ ```
40
+
41
+ ### License
42
+
43
+ This package is distributed under the LGPL-2.1-or-later license, see [LICENSE](LICENSE) for more information.
44
+
45
+ ### Contact
46
+
47
47
  sami.saubion@gmail.com – main developer and maintainer of the project
package/dist/index.d.ts CHANGED
@@ -74,11 +74,20 @@ type UserRole = {
74
74
  declare const USER_ROLES: readonly ["admin", "teacher", "student", "none"];
75
75
  type UserData = {
76
76
  username: string;
77
- full_name: string;
77
+ fullName: string;
78
78
  role: UserRole["role"];
79
- public_id: string;
79
+ publicId: string;
80
80
  email: string | null | undefined;
81
81
  };
82
+ type UserProfile = {
83
+ id: number;
84
+ username: string;
85
+ pubId: string;
86
+ fullName: string;
87
+ role: UserRole["role"];
88
+ email: string;
89
+ createdAt: PHPDateTime;
90
+ };
82
91
  type User = {
83
92
  username: string;
84
93
  publicId: string;
@@ -95,8 +104,8 @@ type AuthTokenContext = "admin-panel" | "profile";
95
104
  type AuthToken = {
96
105
  username: string;
97
106
  name: string;
98
- expires: Date;
99
- created: Date;
107
+ expires: PHPDateTime;
108
+ created: PHPDateTime;
100
109
  };
101
110
 
102
111
  declare function useAuthTokens(context: AuthTokenContext, target?: string | null): {
@@ -179,8 +188,8 @@ declare function useSupportTickets(): {
179
188
 
180
189
  interface UseSyncedResourceOptions<T> {
181
190
  name: string;
182
- cacheKey: string;
183
- syncKey: string;
191
+ cacheKey?: string;
192
+ syncKey?: string;
184
193
  fetcher: () => Promise<Response | null | undefined>;
185
194
  parse: (data: unknown) => T | null;
186
195
  requireAuth?: boolean;
@@ -232,8 +241,8 @@ declare const SUPPORT_TICKET_CACHE = "support-tickets-cache";
232
241
  declare const SUPPORT_TICKET_SYNC = "support-tickets-synced";
233
242
  declare const SUBJECT_SYNCS: Record<UserRole["role"], string>;
234
243
  declare const SUBJECT_CACHES: Record<UserRole["role"], string>;
235
- declare const AUTH_TOKEN_SYNCS: Record<AuthTokenContext, string>;
236
- declare const AUTH_TOKEN_CACHES: Record<AuthTokenContext, string>;
244
+ declare const AUTH_TOKEN_SYNCS: Record<AuthTokenContext, string | undefined>;
245
+ declare const AUTH_TOKEN_CACHES: Record<AuthTokenContext, string | undefined>;
237
246
  type UserType = {
238
247
  type: "users-virtual" | "users-real" | "admins-virtual" | "admins-real";
239
248
  };
@@ -266,6 +275,10 @@ declare function isFoolsDay(): boolean;
266
275
  declare function buildArray<T>(...items: (T | false | null | undefined)[]): T[];
267
276
  declare const fromPhpDate: (phpDate: PHPDateTime) => Date;
268
277
  declare const parsePhpDateTime: (phpDate: PHPDateTime) => string;
278
+ declare function separateNames(fullName: string): {
279
+ firstName: string;
280
+ lastName: string;
281
+ };
269
282
 
270
283
  declare function emitAuthEvent(event: AuthEvent): void;
271
284
  declare function onAuthEvent(callback: (event: AuthEvent) => void): () => void;
@@ -339,4 +352,4 @@ declare function fetchVirtualUsersClient(): Promise<Response>;
339
352
  declare function fetchAdminsClient(): Promise<Response>;
340
353
  declare function fetchVirtualAdminsClient(): Promise<Response>;
341
354
 
342
- 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, 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 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, storageGet, storageKeyAt, storageRemove, storageSet, storageSize, useAdmins, useAuthTokens, useSubjects, useSupportTickets, useSyncedResource, useUsers, useVirtualAdmins, useVirtualUsers };
355
+ 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, 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, storageRemove, storageSet, storageSize, useAdmins, useAuthTokens, useSubjects, useSupportTickets, useSyncedResource, useUsers, useVirtualAdmins, useVirtualUsers };
package/dist/index.js CHANGED
@@ -111,11 +111,12 @@ var SUBJECT_CACHES = {
111
111
  none: SUBJECT_CACHE_RADIX + "unknown"
112
112
  };
113
113
  var AUTH_TOKEN_SYNCS = {
114
- "admin-panel": AUTH_TOKEN_SYNC_RADIX + "admin-panel",
114
+ "admin-panel": void 0,
115
115
  profile: AUTH_TOKEN_SYNC_RADIX + "profile"
116
116
  };
117
117
  var AUTH_TOKEN_CACHES = {
118
- "admin-panel": AUTH_TOKEN_CACHE_RADIX + "admin-panel",
118
+ "admin-panel": void 0,
119
+ // no caching
119
120
  profile: AUTH_TOKEN_CACHE_RADIX + "profile"
120
121
  };
121
122
  var USER_SYNCS = {
@@ -361,9 +362,9 @@ async function cacheUserDataClient() {
361
362
  }
362
363
  const data = (await res.json())["data"];
363
364
  cookiesSet(USERNAME_KEY, data.username, "/", 1.5 * 60 * 60);
364
- cookiesSet(FULL_NAME_KEY, data.full_name, "/", 1.5 * 60 * 60);
365
+ cookiesSet(FULL_NAME_KEY, data.fullName, "/", 1.5 * 60 * 60);
365
366
  cookiesSet(ROLE_KEY, data.role, "/", 1.5 * 60 * 60);
366
- cookiesSet(PUB_ID_KEY, data.public_id, "/", 1.5 * 60 * 60);
367
+ cookiesSet(PUB_ID_KEY, data.publicId, "/", 1.5 * 60 * 60);
367
368
  if (data?.email)
368
369
  cookiesSet(EMAIL_KEY, data.email, "/", 1.5 * 60 * 60);
369
370
  else
@@ -523,7 +524,8 @@ async function fetchTokensProfile() {
523
524
  console.error("[fetchTokensProfile] No username cookies, aborting");
524
525
  return null;
525
526
  }
526
- return await goralysFetchClient("GET", "user/tokens");
527
+ const csrf = await fetchCsrfClient("get-auth-tokens");
528
+ return await goralysFetchClient("GET", buildApiUrl("user/tokens", { "csrf-token": csrf }));
527
529
  }
528
530
  async function fetchTokensAdminPanel(target) {
529
531
  const username = cookiesGet(USERNAME_KEY);
@@ -531,7 +533,8 @@ async function fetchTokensAdminPanel(target) {
531
533
  console.error("[fetchTokensProfile] No username cookies, aborting");
532
534
  return null;
533
535
  }
534
- return await goralysFetchClient("GET", "user/tokens/any", { username: target });
536
+ const csrf = await fetchCsrfClient("get-auth-tokens");
537
+ return await goralysFetchClient("GET", buildApiUrl("user/tokens/any", { pubId: target, "csrf-token": csrf }));
535
538
  }
536
539
  async function fetchAuthTokensForContext(ctx, target = null) {
537
540
  switch (ctx) {
@@ -545,6 +548,7 @@ async function fetchAuthTokensForContext(ctx, target = null) {
545
548
  // src/hooks/use-synced-ressource.ts
546
549
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
547
550
  function useSyncedResource({ name, cacheKey, syncKey, fetcher, parse, requireAuth = true, guard }) {
551
+ const caching = !!cacheKey && !!syncKey;
548
552
  const [data, setData] = useState(null);
549
553
  const showToast = getToastConfig().getShowToast();
550
554
  const showToastRef = useRef(showToast);
@@ -569,48 +573,52 @@ function useSyncedResource({ name, cacheKey, syncKey, fetcher, parse, requireAut
569
573
  resolve = r;
570
574
  });
571
575
  try {
572
- const syncValue = cookiesGet(syncKey);
573
- if (syncValue == "1") {
574
- const raw2 = storageGet(cacheKey);
575
- if (raw2 === null || raw2 === void 0) {
576
- cookiesSet(syncKey, "0");
577
- storageRemove(cacheKey);
578
- inFlightRef.current = null;
579
- resolve();
580
- await fetchResource();
576
+ if (caching) {
577
+ const syncValue = cookiesGet(syncKey);
578
+ if (syncValue == "1") {
579
+ const raw2 = storageGet(cacheKey);
580
+ if (raw2 === null || raw2 === void 0) {
581
+ cookiesSet(syncKey, "0");
582
+ storageRemove(cacheKey);
583
+ inFlightRef.current = null;
584
+ resolve();
585
+ await fetchResource();
586
+ return;
587
+ }
588
+ const cached = JSON.parse(raw2 ?? "null");
589
+ setData((prev) => JSON.stringify(prev) === JSON.stringify(cached) ? prev : cached);
581
590
  return;
582
591
  }
583
- const cached = JSON.parse(raw2 ?? "null");
584
- setData((prev) => JSON.stringify(prev) === JSON.stringify(cached) ? prev : cached);
585
- return;
586
592
  }
587
593
  const res = await fetcher();
588
594
  if (res)
589
595
  await handleToastRequest(res, showToastRef.current, false);
590
596
  const raw = await res?.json();
591
- cookiesSet(syncKey, "1");
592
- storageSet(cacheKey, JSON.stringify(raw));
597
+ if (caching) {
598
+ cookiesSet(syncKey, "1");
599
+ storageSet(cacheKey, JSON.stringify(raw));
600
+ }
593
601
  const result = parse(raw);
594
602
  setData((prev) => JSON.stringify(prev) === JSON.stringify(result) ? prev : result);
595
603
  } finally {
596
604
  inFlightRef.current = null;
597
605
  resolve();
598
606
  }
599
- }, [cacheKey, syncKey, fetcher, parse, requireAuth, guard, name]);
607
+ }, [cacheKey, syncKey, fetcher, parse, requireAuth, guard, name, caching]);
600
608
  useEffect(() => {
601
609
  const onChange = () => {
602
- if (inFlightRef.current)
610
+ if (inFlightRef.current || !caching)
603
611
  return;
604
612
  if (cookiesGet(syncKey) != "1") {
605
613
  void fetchResource();
606
614
  }
607
615
  };
608
616
  return cookiesOnChange(onChange);
609
- }, [fetchResource, syncKey]);
617
+ }, [fetchResource, syncKey, caching]);
610
618
  useEffect(() => {
611
619
  void fetchResource();
612
620
  }, [fetchResource]);
613
- return useMemo(() => ({ data, refetch: fetchResource, syncKey }), [data, fetchResource, syncKey]);
621
+ return useMemo(() => ({ data, refetch: fetchResource, syncKey: syncKey ?? "" }), [data, fetchResource, syncKey]);
614
622
  }
615
623
 
616
624
  // src/hooks/use-auth-tokens.ts
@@ -749,6 +757,25 @@ var parsePhpDateTime = (phpDate) => {
749
757
  minute: "2-digit"
750
758
  });
751
759
  };
760
+ function separateNames(fullName) {
761
+ const parts = fullName.split(" ");
762
+ const firstNameParts = [];
763
+ const lastNameParts = [];
764
+ let current = "first";
765
+ parts.forEach((p) => {
766
+ if (p.toUpperCase() === p)
767
+ current = "last";
768
+ switch (current) {
769
+ case "first":
770
+ firstNameParts.push(p);
771
+ break;
772
+ case "last":
773
+ lastNameParts.push(p);
774
+ break;
775
+ }
776
+ });
777
+ return { firstName: firstNameParts.join(" "), lastName: lastNameParts.join(" ") };
778
+ }
752
779
 
753
780
  // src/lib/subjects/subjects-utils.ts
754
781
  var SUBJECTS = [
@@ -976,6 +1003,7 @@ export {
976
1003
  parsePhpDateTime,
977
1004
  reasonsConfig,
978
1005
  searchFields,
1006
+ separateNames,
979
1007
  storageGet,
980
1008
  storageKeyAt,
981
1009
  storageRemove,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goralys/core",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "license": "LGPL-2.1-or-later",
5
5
  "description": "Shared business logic for the Goralys web application",
6
6
  "repository": {
@@ -31,7 +31,7 @@
31
31
  "build": "tsup",
32
32
  "typeCheck": "tsgo --noEmit",
33
33
  "dev": "tsup --watch",
34
- "barrel": "rm ./src/index.ts && barrelsby -d ./src -l top"
34
+ "barrel": "node -e \"require('fs').rmSync('./src/index.ts',{force:true})\" && barrelsby -d ./src -l top"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "react": ">=18"