@goralys/core 1.1.0 → 1.1.1

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +27 -27
  2. package/dist/index.js +101 -101
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,3 +1,30 @@
1
+ interface GoralysClientConfig {
2
+ apiDomain: string;
3
+ }
4
+ declare function configureGoralysClient(cfg: GoralysClientConfig): void;
5
+ declare function getGoralysClientConfig(): GoralysClientConfig;
6
+
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>;
11
+ }
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>;
16
+
17
+ interface PHPDateTime {
18
+ date: string;
19
+ timezone_type: number;
20
+ timezone: string;
21
+ }
22
+ type CookieValue = string | boolean | number | null | undefined;
23
+
24
+ type CheckAuthImpl = () => boolean;
25
+ declare function configureCheckAuth(impl: CheckAuthImpl): void;
26
+ declare function isAuthenticated(): boolean;
27
+
1
28
  type UserRole = {
2
29
  role: "admin" | "teacher" | "student" | "none";
3
30
  };
@@ -72,13 +99,6 @@ declare function useSubjects(role: UserRole["role"], showToast: ToastFn): {
72
99
  syncKey: string;
73
100
  };
74
101
 
75
- interface PHPDateTime {
76
- date: string;
77
- timezone_type: number;
78
- timezone: string;
79
- }
80
- type CookieValue = string | boolean | number | null | undefined;
81
-
82
102
  declare const reasonsConfig: {
83
103
  readonly "password-forgot": {
84
104
  readonly label: "Mot de passe oublié";
@@ -176,19 +196,9 @@ declare const parsePhpDateTime: (phpDate: PHPDateTime) => string;
176
196
  declare function emitAuthEvent(event: AuthEvent): void;
177
197
  declare function onAuthEvent(callback: (event: AuthEvent) => void): () => void;
178
198
 
179
- type CheckAuthImpl = () => boolean;
180
- declare function configureCheckAuth(impl: CheckAuthImpl): void;
181
- declare function isAuthenticated(): boolean;
182
-
183
199
  declare function emitUserEvent(event: UserEvent): void;
184
200
  declare function onUserEvent(callback: (event: UserEvent) => void): () => void;
185
201
 
186
- interface GoralysClientConfig {
187
- apiDomain: string;
188
- }
189
- declare function configureGoralysClient(cfg: GoralysClientConfig): void;
190
- declare function getGoralysClientConfig(): GoralysClientConfig;
191
-
192
202
  /**
193
203
  * This filed is a slightly modified version of Next.js own http method declaration.
194
204
  */
@@ -225,16 +235,6 @@ type Listener = (event: NavigationEvent) => void;
225
235
  declare function emitNavigationEvent(event: NavigationEvent): void;
226
236
  declare function onNavigationEvent(listener: Listener): () => void;
227
237
 
228
- interface StorageAdapter {
229
- getItem(key: string): string | null | Promise<string | null>;
230
- setItem(key: string, value: string): void | Promise<void>;
231
- removeItem(key: string): void | Promise<void>;
232
- }
233
- declare function configureStorage(customAdapter: StorageAdapter): void;
234
- declare function storageGet(key: string): Promise<string | null>;
235
- declare function storageSet(key: string, value: string): Promise<void>;
236
- declare function storageRemove(key: string): Promise<void>;
237
-
238
238
  /**
239
239
  * Returns the full name of a subject based on its short name or an alias.
240
240
  * It searches for the first subject in {@link SUBJECTS} whose short name starts with the given string.
package/dist/index.js CHANGED
@@ -1,5 +1,65 @@
1
- // src/hooks/useSubjects.ts
2
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
1
+ // src/lib/fetch/config.ts
2
+ var config = null;
3
+ function configureGoralysClient(cfg) {
4
+ config = cfg;
5
+ }
6
+ function getGoralysClientConfig() {
7
+ if (!config) {
8
+ throw new Error("Goralys client not configured. Call configureGoralysClient() first.");
9
+ }
10
+ return config;
11
+ }
12
+
13
+ // src/lib/storage/storage-adapter.ts
14
+ var adapter = null;
15
+ function configureStorage(customAdapter) {
16
+ adapter = customAdapter;
17
+ }
18
+ function getAdapter() {
19
+ if (!adapter) {
20
+ throw new Error("Storage not configured. Call configureStorage() first.");
21
+ }
22
+ return adapter;
23
+ }
24
+ async function storageGet(key) {
25
+ return getAdapter().getItem(key);
26
+ }
27
+ async function storageSet(key, value) {
28
+ await getAdapter().setItem(key, value);
29
+ }
30
+ async function storageRemove(key) {
31
+ await getAdapter().removeItem(key);
32
+ }
33
+
34
+ // src/lib/storage/cookies-adapter.ts
35
+ var adapter2 = null;
36
+ function getAdapter2() {
37
+ if (!adapter2) {
38
+ throw new Error("Cookies not configured. Call configureCookies() first.");
39
+ }
40
+ return adapter2;
41
+ }
42
+ function cookiesGet(key) {
43
+ return getAdapter2().getCookies(key);
44
+ }
45
+ function cookiesSet(key, value, path = "/", maxAge = 1.5 * 60) {
46
+ getAdapter2().setCookies(key, value, path, maxAge);
47
+ }
48
+ function cookiesOnChange(callback) {
49
+ return getAdapter2().onChange(callback);
50
+ }
51
+
52
+ // src/lib/auth/check-auth.ts
53
+ var checkAuthImpl;
54
+ function configureCheckAuth(impl) {
55
+ checkAuthImpl = impl;
56
+ }
57
+ function isAuthenticated() {
58
+ if (!checkAuthImpl) {
59
+ throw new Error("Auth check not configured. Call configureAuthCheck() first.");
60
+ }
61
+ return checkAuthImpl();
62
+ }
3
63
 
4
64
  // src/lib/auth/auth-event.ts
5
65
  var listeners = /* @__PURE__ */ new Set();
@@ -23,42 +83,6 @@ function onNavigationEvent(listener) {
23
83
  return () => listeners2.delete(listener);
24
84
  }
25
85
 
26
- // src/lib/user/user.client.ts
27
- var cacheUserClient;
28
- var emptyCacheUserClient;
29
- function configureUserCacheCallbacks(cache, empty) {
30
- cacheUserClient = cache;
31
- emptyCacheUserClient = empty;
32
- }
33
- async function cacheUserDataClient() {
34
- if (!cacheUserClient) {
35
- throw new Error("User cache not configured. Call configUserCacheCallbacks() first.");
36
- }
37
- return await cacheUserClient();
38
- }
39
- function emptyUserCacheClient() {
40
- if (!emptyCacheUserClient) {
41
- throw new Error("User cache not configured. Call configUserCacheCallbacks() first.");
42
- }
43
- return emptyCacheUserClient();
44
- }
45
- async function fetchUsersClient() {
46
- const csrfToken = await fetchCsrfClient("get-all-users");
47
- return await goralysFetchClient("GET", buildApiUrl("users/all", { "csrf-token": csrfToken }));
48
- }
49
- async function fetchVirtualUsersClient() {
50
- const csrfToken = await fetchCsrfClient("get-virtual-users");
51
- return await goralysFetchClient("GET", buildApiUrl("users/virtual", { "csrf-token": csrfToken }));
52
- }
53
- async function fetchAdminsClient() {
54
- const csrfToken = await fetchCsrfClient("get-all-admins");
55
- return await goralysFetchClient("GET", buildApiUrl("admins/all", { "csrf-token": csrfToken }));
56
- }
57
- async function fetchVirtualAdminsClient() {
58
- const csrfToken = await fetchCsrfClient("get-virtual-admins");
59
- return await goralysFetchClient("GET", buildApiUrl("admins/virtual", { "csrf-token": csrfToken }));
60
- }
61
-
62
86
  // src/lib/auth/user-event.ts
63
87
  var listeners3 = /* @__PURE__ */ new Set();
64
88
  function emitUserEvent(event) {
@@ -93,18 +117,6 @@ var GoralysActionHandler = class {
93
117
  }
94
118
  };
95
119
 
96
- // src/lib/fetch/config.ts
97
- var config = null;
98
- function configureGoralysClient(cfg) {
99
- config = cfg;
100
- }
101
- function getGoralysClientConfig() {
102
- if (!config) {
103
- throw new Error("Goralys client not configured. Call configureGoralysClient() first.");
104
- }
105
- return config;
106
- }
107
-
108
120
  // src/lib/fetch/fetch.client.ts
109
121
  var actionHandler = new GoralysActionHandler();
110
122
  async function goralysFetchClient(method, input, payload, requestOptions) {
@@ -174,6 +186,45 @@ async function handleToastRequest(r, showToast, redirect = true, duration) {
174
186
  return false;
175
187
  }
176
188
 
189
+ // src/lib/user/user.client.ts
190
+ var cacheUserClient;
191
+ var emptyCacheUserClient;
192
+ function configureUserCacheCallbacks(cache, empty) {
193
+ cacheUserClient = cache;
194
+ emptyCacheUserClient = empty;
195
+ }
196
+ async function cacheUserDataClient() {
197
+ if (!cacheUserClient) {
198
+ throw new Error("User cache not configured. Call configUserCacheCallbacks() first.");
199
+ }
200
+ return await cacheUserClient();
201
+ }
202
+ function emptyUserCacheClient() {
203
+ if (!emptyCacheUserClient) {
204
+ throw new Error("User cache not configured. Call configUserCacheCallbacks() first.");
205
+ }
206
+ return emptyCacheUserClient();
207
+ }
208
+ async function fetchUsersClient() {
209
+ const csrfToken = await fetchCsrfClient("get-all-users");
210
+ return await goralysFetchClient("GET", buildApiUrl("users/all", { "csrf-token": csrfToken }));
211
+ }
212
+ async function fetchVirtualUsersClient() {
213
+ const csrfToken = await fetchCsrfClient("get-virtual-users");
214
+ return await goralysFetchClient("GET", buildApiUrl("users/virtual", { "csrf-token": csrfToken }));
215
+ }
216
+ async function fetchAdminsClient() {
217
+ const csrfToken = await fetchCsrfClient("get-all-admins");
218
+ return await goralysFetchClient("GET", buildApiUrl("admins/all", { "csrf-token": csrfToken }));
219
+ }
220
+ async function fetchVirtualAdminsClient() {
221
+ const csrfToken = await fetchCsrfClient("get-virtual-admins");
222
+ return await goralysFetchClient("GET", buildApiUrl("admins/virtual", { "csrf-token": csrfToken }));
223
+ }
224
+
225
+ // src/hooks/useSubjects.ts
226
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
227
+
177
228
  // src/lib/subjects/subjects.client.ts
178
229
  async function fetchStudentSubjectsClient() {
179
230
  const csrfToken = await fetchCsrfClient("get-student-subjects");
@@ -447,57 +498,6 @@ Attention : les administrateurs ont acc\xE8s \xE0 toutes les fonctionnalit\xE9s
447
498
  }
448
499
  ];
449
500
 
450
- // src/lib/auth/check-auth.ts
451
- var checkAuthImpl;
452
- function configureCheckAuth(impl) {
453
- checkAuthImpl = impl;
454
- }
455
- function isAuthenticated() {
456
- if (!checkAuthImpl) {
457
- throw new Error("Auth check not configured. Call configureAuthCheck() first.");
458
- }
459
- return checkAuthImpl();
460
- }
461
-
462
- // src/lib/storage/storage-adapter.ts
463
- var adapter = null;
464
- function configureStorage(customAdapter) {
465
- adapter = customAdapter;
466
- }
467
- function getAdapter() {
468
- if (!adapter) {
469
- throw new Error("Storage not configured. Call configureStorage() first.");
470
- }
471
- return adapter;
472
- }
473
- async function storageGet(key) {
474
- return getAdapter().getItem(key);
475
- }
476
- async function storageSet(key, value) {
477
- await getAdapter().setItem(key, value);
478
- }
479
- async function storageRemove(key) {
480
- await getAdapter().removeItem(key);
481
- }
482
-
483
- // src/lib/storage/cookies-adapter.ts
484
- var adapter2 = null;
485
- function getAdapter2() {
486
- if (!adapter2) {
487
- throw new Error("Cookies not configured. Call configureCookies() first.");
488
- }
489
- return adapter2;
490
- }
491
- function cookiesGet(key) {
492
- return getAdapter2().getCookies(key);
493
- }
494
- function cookiesSet(key, value, path = "/", maxAge = 1.5 * 60) {
495
- getAdapter2().setCookies(key, value, path, maxAge);
496
- }
497
- function cookiesOnChange(callback) {
498
- return getAdapter2().onChange(callback);
499
- }
500
-
501
501
  // src/hooks/useSubjects.ts
502
502
  function useSubjects(role, showToast) {
503
503
  const [subjects, setSubjects] = useState(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goralys/core",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "license": "LGPL-2.1-or-later",
5
5
  "description": "Shared business logic for the Goralys web application",
6
6
  "repository": {