@goralys/core 1.1.1 → 1.1.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 +26 -1
- package/dist/index.js +25 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,10 +21,35 @@ 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
|
+
declare function configureCookies(customAdapter: CookiesAdapter): void;
|
|
31
|
+
declare function cookiesGet(key: string): string | null;
|
|
32
|
+
declare function cookiesSet(key: string, value: string, path?: string, maxAge?: number): void;
|
|
33
|
+
declare function cookiesRemove(key: string): void;
|
|
34
|
+
declare function cookiesOnChange(callback: () => void): () => void;
|
|
35
|
+
declare function setCookiesExpire(duration: number): void;
|
|
36
|
+
|
|
24
37
|
type CheckAuthImpl = () => boolean;
|
|
25
38
|
declare function configureCheckAuth(impl: CheckAuthImpl): void;
|
|
26
39
|
declare function isAuthenticated(): boolean;
|
|
27
40
|
|
|
41
|
+
interface GoralysCoreConfig {
|
|
42
|
+
client: GoralysClientConfig;
|
|
43
|
+
storage: StorageAdapter;
|
|
44
|
+
cookies: CookiesAdapter;
|
|
45
|
+
auth: CheckAuthImpl;
|
|
46
|
+
cache: {
|
|
47
|
+
cache: () => Promise<void>;
|
|
48
|
+
empty: () => void;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
declare function configGoralysCore(cfg: GoralysCoreConfig): void;
|
|
52
|
+
|
|
28
53
|
type UserRole = {
|
|
29
54
|
role: "admin" | "teacher" | "student" | "none";
|
|
30
55
|
};
|
|
@@ -254,4 +279,4 @@ declare function fetchVirtualUsersClient(): Promise<Response>;
|
|
|
254
279
|
declare function fetchAdminsClient(): Promise<Response>;
|
|
255
280
|
declare function fetchVirtualAdminsClient(): Promise<Response>;
|
|
256
281
|
|
|
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 };
|
|
282
|
+
export { ADMIN_CACHE_RADIX, ADMIN_SYNC_RADIX, type AuthEvent, 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, configureUserCacheCallbacks, cookiesGet, 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, setCookiesExpire, 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.");
|
|
@@ -45,9 +48,15 @@ function cookiesGet(key) {
|
|
|
45
48
|
function cookiesSet(key, value, path = "/", maxAge = 1.5 * 60) {
|
|
46
49
|
getAdapter2().setCookies(key, value, path, maxAge);
|
|
47
50
|
}
|
|
51
|
+
function cookiesRemove(key) {
|
|
52
|
+
getAdapter2().removeCookies(key);
|
|
53
|
+
}
|
|
48
54
|
function cookiesOnChange(callback) {
|
|
49
55
|
return getAdapter2().onChange(callback);
|
|
50
56
|
}
|
|
57
|
+
function setCookiesExpire(duration) {
|
|
58
|
+
storageSet("goralys-cookies-expire", String(Date.now() + duration * 1e3)).then();
|
|
59
|
+
}
|
|
51
60
|
|
|
52
61
|
// src/lib/auth/check-auth.ts
|
|
53
62
|
var checkAuthImpl;
|
|
@@ -222,6 +231,15 @@ async function fetchVirtualAdminsClient() {
|
|
|
222
231
|
return await goralysFetchClient("GET", buildApiUrl("admins/virtual", { "csrf-token": csrfToken }));
|
|
223
232
|
}
|
|
224
233
|
|
|
234
|
+
// src/config.ts
|
|
235
|
+
function configGoralysCore(cfg) {
|
|
236
|
+
configureGoralysClient(cfg.client);
|
|
237
|
+
configureCookies(cfg.cookies);
|
|
238
|
+
configureStorage(cfg.storage);
|
|
239
|
+
configureCheckAuth(cfg.auth);
|
|
240
|
+
configureUserCacheCallbacks(cfg.cache.cache, cfg.cache.empty);
|
|
241
|
+
}
|
|
242
|
+
|
|
225
243
|
// src/hooks/useSubjects.ts
|
|
226
244
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
227
245
|
|
|
@@ -887,10 +905,16 @@ export {
|
|
|
887
905
|
buildApiUrl,
|
|
888
906
|
buildArray,
|
|
889
907
|
cacheUserDataClient,
|
|
908
|
+
configGoralysCore,
|
|
890
909
|
configureCheckAuth,
|
|
910
|
+
configureCookies,
|
|
891
911
|
configureGoralysClient,
|
|
892
912
|
configureStorage,
|
|
893
913
|
configureUserCacheCallbacks,
|
|
914
|
+
cookiesGet,
|
|
915
|
+
cookiesOnChange,
|
|
916
|
+
cookiesRemove,
|
|
917
|
+
cookiesSet,
|
|
894
918
|
emitAuthEvent,
|
|
895
919
|
emitNavigationEvent,
|
|
896
920
|
emitUserEvent,
|
|
@@ -916,6 +940,7 @@ export {
|
|
|
916
940
|
parsePhpDateTime,
|
|
917
941
|
reasonsConfig,
|
|
918
942
|
searchFields,
|
|
943
|
+
setCookiesExpire,
|
|
919
944
|
storageGet,
|
|
920
945
|
storageRemove,
|
|
921
946
|
storageSet,
|