@djangocfg/api 2.1.582 → 2.1.584
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 +18 -0
- package/dist/OAuthTokenResponse-WEDM6IP5.mjs +19 -0
- package/dist/OAuthTokenResponse-WEDM6IP5.mjs.map +1 -0
- package/dist/OTPVerifyResponse-P5LDNM7H.mjs +20 -0
- package/dist/OTPVerifyResponse-P5LDNM7H.mjs.map +1 -0
- package/dist/PasswordLoginResponse-33B576NG.mjs +20 -0
- package/dist/PasswordLoginResponse-33B576NG.mjs.map +1 -0
- package/dist/auth.cjs +279 -103
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +14 -41
- package/dist/auth.d.ts +14 -41
- package/dist/auth.mjs +279 -101
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +242 -54
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +13 -41
- package/dist/clients.d.ts +13 -41
- package/dist/clients.mjs +242 -54
- package/dist/clients.mjs.map +1 -1
- package/dist/hooks.cjs +242 -54
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.mjs +242 -54
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +247 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -63
- package/dist/index.d.ts +90 -63
- package/dist/index.mjs +247 -54
- package/dist/index.mjs.map +1 -1
- package/dist/storage.cjs +268 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +84 -0
- package/dist/storage.d.ts +84 -0
- package/dist/storage.mjs +247 -0
- package/dist/storage.mjs.map +1 -0
- package/package.json +8 -2
- package/src/__tests__/noStorageLiterals.test.ts +27 -0
- package/src/__tests__/storage.test.ts +134 -0
- package/src/__tests__/storageSsr.test.ts +14 -0
- package/src/_api/generated/_cfg_accounts/openapi.json +1 -28
- package/src/_api/generated/_cfg_accounts/schemas/OAuthCallbackRequestRequest.ts +0 -1
- package/src/_api/generated/_cfg_accounts/schemas/OAuthTokenResponse.ts +0 -1
- package/src/_api/generated/_cfg_accounts/schemas/OTPVerifyRequest.ts +0 -1
- package/src/_api/generated/_cfg_accounts/schemas/OTPVerifyResponse.ts +0 -1
- package/src/_api/generated/_cfg_accounts/schemas/PasswordLoginRequest.ts +0 -1
- package/src/_api/generated/_cfg_accounts/schemas/PasswordLoginResponse.ts +0 -1
- package/src/_api/generated/_cfg_totp/openapi.json +0 -5
- package/src/_api/generated/_cfg_totp/schemas/VerifyResponse.ts +0 -1
- package/src/_api/generated/helpers/auth.ts +28 -65
- package/src/_api/generated/helpers/index.ts +12 -0
- package/src/_api/generated/helpers/keys.ts +327 -0
- package/src/_api/generated/openapi.json +1 -33
- package/src/_api/generated/types.gen.ts +4 -59
- package/src/auth/__tests__/authRedirect.test.ts +1 -1
- package/src/auth/__tests__/passwordLogin.test.tsx +1 -3
- package/src/auth/__tests__/profileCache.test.ts +1 -1
- package/src/auth/context/AccountsContext.tsx +6 -8
- package/src/auth/context/AuthContext.tsx +3 -5
- package/src/auth/context/types.ts +1 -1
- package/src/auth/hooks/useAuthForm.ts +3 -5
- package/src/auth/hooks/useAuthFormState.ts +0 -4
- package/src/auth/hooks/useAuthRedirect.ts +3 -2
- package/src/auth/hooks/useGithubAuth.ts +14 -16
- package/src/auth/hooks/useLocalStorage.ts +7 -7
- package/src/auth/hooks/useProfileCache.ts +2 -1
- package/src/auth/hooks/useSessionStorage.ts +7 -7
- package/src/auth/hooks/useTwoFactorVerify.ts +2 -2
- package/src/auth/types/form.ts +0 -5
- package/src/storage.ts +21 -0
package/dist/clients.d.cts
CHANGED
|
@@ -671,10 +671,6 @@ type OAuthCallbackRequestRequest = {
|
|
|
671
671
|
* Same redirect_uri used in authorize request. If not provided, uses config's site_url + callback_path
|
|
672
672
|
*/
|
|
673
673
|
redirect_uri?: string;
|
|
674
|
-
/**
|
|
675
|
-
* Keep this browser signed in for 30 days
|
|
676
|
-
*/
|
|
677
|
-
remember_me?: boolean;
|
|
678
674
|
};
|
|
679
675
|
/**
|
|
680
676
|
* Serializer for OAuth connection info (user-facing).
|
|
@@ -798,10 +794,6 @@ type OAuthTokenResponse = {
|
|
|
798
794
|
* True if user should be prompted to enable 2FA
|
|
799
795
|
*/
|
|
800
796
|
should_prompt_2fa?: boolean;
|
|
801
|
-
/**
|
|
802
|
-
* Whether this login should persist across browser restarts
|
|
803
|
-
*/
|
|
804
|
-
persistent_session?: boolean;
|
|
805
797
|
};
|
|
806
798
|
/**
|
|
807
799
|
* Typed error response for OTP operations.
|
|
@@ -885,10 +877,6 @@ type OtpVerifyRequest = {
|
|
|
885
877
|
* Source URL for tracking login (e.g., https://my.djangocfg.com)
|
|
886
878
|
*/
|
|
887
879
|
source_url?: string;
|
|
888
|
-
/**
|
|
889
|
-
* Keep this browser signed in for 30 days
|
|
890
|
-
*/
|
|
891
|
-
remember_me?: boolean;
|
|
892
880
|
};
|
|
893
881
|
/**
|
|
894
882
|
* OTP verification response.
|
|
@@ -928,10 +916,6 @@ type OtpVerifyResponse = {
|
|
|
928
916
|
* Whether user should be prompted to enable 2FA
|
|
929
917
|
*/
|
|
930
918
|
should_prompt_2fa?: boolean;
|
|
931
|
-
/**
|
|
932
|
-
* Whether this login should persist across browser restarts
|
|
933
|
-
*/
|
|
934
|
-
persistent_session?: boolean;
|
|
935
919
|
};
|
|
936
920
|
/**
|
|
937
921
|
* Typed error response for password login.
|
|
@@ -955,6 +939,18 @@ type PasswordLoginError = {
|
|
|
955
939
|
*/
|
|
956
940
|
retry_after?: number | null;
|
|
957
941
|
};
|
|
942
|
+
/**
|
|
943
|
+
* Validate email+password against live accounts only.
|
|
944
|
+
*
|
|
945
|
+
* Subclasses SimpleJWT so the field/validation contract stays theirs, but
|
|
946
|
+
* replaces ``validate()`` — the token pair itself is minted by the view via
|
|
947
|
+
* ``mint_tokens_for_request`` so the DPoP binding and token
|
|
948
|
+
* lifetime match OTP, OAuth and TOTP exactly.
|
|
949
|
+
*/
|
|
950
|
+
type PasswordLoginRequest = {
|
|
951
|
+
email: string;
|
|
952
|
+
password: string;
|
|
953
|
+
};
|
|
958
954
|
/**
|
|
959
955
|
* Password-login response.
|
|
960
956
|
*
|
|
@@ -986,10 +982,6 @@ type PasswordLoginResponse = {
|
|
|
986
982
|
* Whether user should be prompted to enable 2FA
|
|
987
983
|
*/
|
|
988
984
|
should_prompt_2fa?: boolean;
|
|
989
|
-
/**
|
|
990
|
-
* Whether this login should persist across browser restarts
|
|
991
|
-
*/
|
|
992
|
-
persistent_session?: boolean;
|
|
993
985
|
};
|
|
994
986
|
/**
|
|
995
987
|
* Serializer for updating user profile.
|
|
@@ -1179,10 +1171,6 @@ type VerifyResponse = {
|
|
|
1179
1171
|
* User profile data
|
|
1180
1172
|
*/
|
|
1181
1173
|
user: TotpVerifyUser;
|
|
1182
|
-
/**
|
|
1183
|
-
* Whether this login should persist across browser restarts
|
|
1184
|
-
*/
|
|
1185
|
-
persistent_session: boolean;
|
|
1186
1174
|
/**
|
|
1187
1175
|
* Number of remaining backup codes (if backup code was used)
|
|
1188
1176
|
*/
|
|
@@ -1323,22 +1311,6 @@ type CfgAccountsOauthDisconnectResponse200AutoRef = {
|
|
|
1323
1311
|
* 2FA disabled successfully
|
|
1324
1312
|
*/
|
|
1325
1313
|
type CfgTotpDisableResponse200AutoRef = unknown;
|
|
1326
|
-
/**
|
|
1327
|
-
* Validate email+password against live accounts only.
|
|
1328
|
-
*
|
|
1329
|
-
* Subclasses SimpleJWT so the field/validation contract stays theirs, but
|
|
1330
|
-
* replaces ``validate()`` — the token pair itself is minted by the view via
|
|
1331
|
-
* ``mint_tokens_for_request`` so the DPoP binding and remembered-session
|
|
1332
|
-
* lifetime match OTP, OAuth and TOTP exactly.
|
|
1333
|
-
*/
|
|
1334
|
-
type PasswordLoginRequestWritable = {
|
|
1335
|
-
/**
|
|
1336
|
-
* Keep this browser signed in for 30 days
|
|
1337
|
-
*/
|
|
1338
|
-
remember_me?: boolean;
|
|
1339
|
-
email: string;
|
|
1340
|
-
password: string;
|
|
1341
|
-
};
|
|
1342
1314
|
type CfgAccountsApiKeyRetrieveData = {
|
|
1343
1315
|
body?: never;
|
|
1344
1316
|
path?: never;
|
|
@@ -1619,7 +1591,7 @@ type CfgAccountsProfileUpdateUpdateResponses = {
|
|
|
1619
1591
|
200: User;
|
|
1620
1592
|
};
|
|
1621
1593
|
type CfgAccountsTokenCreateData = {
|
|
1622
|
-
body:
|
|
1594
|
+
body: PasswordLoginRequest;
|
|
1623
1595
|
path?: never;
|
|
1624
1596
|
query?: never;
|
|
1625
1597
|
url: '/cfg/accounts/token/';
|
package/dist/clients.d.ts
CHANGED
|
@@ -671,10 +671,6 @@ type OAuthCallbackRequestRequest = {
|
|
|
671
671
|
* Same redirect_uri used in authorize request. If not provided, uses config's site_url + callback_path
|
|
672
672
|
*/
|
|
673
673
|
redirect_uri?: string;
|
|
674
|
-
/**
|
|
675
|
-
* Keep this browser signed in for 30 days
|
|
676
|
-
*/
|
|
677
|
-
remember_me?: boolean;
|
|
678
674
|
};
|
|
679
675
|
/**
|
|
680
676
|
* Serializer for OAuth connection info (user-facing).
|
|
@@ -798,10 +794,6 @@ type OAuthTokenResponse = {
|
|
|
798
794
|
* True if user should be prompted to enable 2FA
|
|
799
795
|
*/
|
|
800
796
|
should_prompt_2fa?: boolean;
|
|
801
|
-
/**
|
|
802
|
-
* Whether this login should persist across browser restarts
|
|
803
|
-
*/
|
|
804
|
-
persistent_session?: boolean;
|
|
805
797
|
};
|
|
806
798
|
/**
|
|
807
799
|
* Typed error response for OTP operations.
|
|
@@ -885,10 +877,6 @@ type OtpVerifyRequest = {
|
|
|
885
877
|
* Source URL for tracking login (e.g., https://my.djangocfg.com)
|
|
886
878
|
*/
|
|
887
879
|
source_url?: string;
|
|
888
|
-
/**
|
|
889
|
-
* Keep this browser signed in for 30 days
|
|
890
|
-
*/
|
|
891
|
-
remember_me?: boolean;
|
|
892
880
|
};
|
|
893
881
|
/**
|
|
894
882
|
* OTP verification response.
|
|
@@ -928,10 +916,6 @@ type OtpVerifyResponse = {
|
|
|
928
916
|
* Whether user should be prompted to enable 2FA
|
|
929
917
|
*/
|
|
930
918
|
should_prompt_2fa?: boolean;
|
|
931
|
-
/**
|
|
932
|
-
* Whether this login should persist across browser restarts
|
|
933
|
-
*/
|
|
934
|
-
persistent_session?: boolean;
|
|
935
919
|
};
|
|
936
920
|
/**
|
|
937
921
|
* Typed error response for password login.
|
|
@@ -955,6 +939,18 @@ type PasswordLoginError = {
|
|
|
955
939
|
*/
|
|
956
940
|
retry_after?: number | null;
|
|
957
941
|
};
|
|
942
|
+
/**
|
|
943
|
+
* Validate email+password against live accounts only.
|
|
944
|
+
*
|
|
945
|
+
* Subclasses SimpleJWT so the field/validation contract stays theirs, but
|
|
946
|
+
* replaces ``validate()`` — the token pair itself is minted by the view via
|
|
947
|
+
* ``mint_tokens_for_request`` so the DPoP binding and token
|
|
948
|
+
* lifetime match OTP, OAuth and TOTP exactly.
|
|
949
|
+
*/
|
|
950
|
+
type PasswordLoginRequest = {
|
|
951
|
+
email: string;
|
|
952
|
+
password: string;
|
|
953
|
+
};
|
|
958
954
|
/**
|
|
959
955
|
* Password-login response.
|
|
960
956
|
*
|
|
@@ -986,10 +982,6 @@ type PasswordLoginResponse = {
|
|
|
986
982
|
* Whether user should be prompted to enable 2FA
|
|
987
983
|
*/
|
|
988
984
|
should_prompt_2fa?: boolean;
|
|
989
|
-
/**
|
|
990
|
-
* Whether this login should persist across browser restarts
|
|
991
|
-
*/
|
|
992
|
-
persistent_session?: boolean;
|
|
993
985
|
};
|
|
994
986
|
/**
|
|
995
987
|
* Serializer for updating user profile.
|
|
@@ -1179,10 +1171,6 @@ type VerifyResponse = {
|
|
|
1179
1171
|
* User profile data
|
|
1180
1172
|
*/
|
|
1181
1173
|
user: TotpVerifyUser;
|
|
1182
|
-
/**
|
|
1183
|
-
* Whether this login should persist across browser restarts
|
|
1184
|
-
*/
|
|
1185
|
-
persistent_session: boolean;
|
|
1186
1174
|
/**
|
|
1187
1175
|
* Number of remaining backup codes (if backup code was used)
|
|
1188
1176
|
*/
|
|
@@ -1323,22 +1311,6 @@ type CfgAccountsOauthDisconnectResponse200AutoRef = {
|
|
|
1323
1311
|
* 2FA disabled successfully
|
|
1324
1312
|
*/
|
|
1325
1313
|
type CfgTotpDisableResponse200AutoRef = unknown;
|
|
1326
|
-
/**
|
|
1327
|
-
* Validate email+password against live accounts only.
|
|
1328
|
-
*
|
|
1329
|
-
* Subclasses SimpleJWT so the field/validation contract stays theirs, but
|
|
1330
|
-
* replaces ``validate()`` — the token pair itself is minted by the view via
|
|
1331
|
-
* ``mint_tokens_for_request`` so the DPoP binding and remembered-session
|
|
1332
|
-
* lifetime match OTP, OAuth and TOTP exactly.
|
|
1333
|
-
*/
|
|
1334
|
-
type PasswordLoginRequestWritable = {
|
|
1335
|
-
/**
|
|
1336
|
-
* Keep this browser signed in for 30 days
|
|
1337
|
-
*/
|
|
1338
|
-
remember_me?: boolean;
|
|
1339
|
-
email: string;
|
|
1340
|
-
password: string;
|
|
1341
|
-
};
|
|
1342
1314
|
type CfgAccountsApiKeyRetrieveData = {
|
|
1343
1315
|
body?: never;
|
|
1344
1316
|
path?: never;
|
|
@@ -1619,7 +1591,7 @@ type CfgAccountsProfileUpdateUpdateResponses = {
|
|
|
1619
1591
|
200: User;
|
|
1620
1592
|
};
|
|
1621
1593
|
type CfgAccountsTokenCreateData = {
|
|
1622
|
-
body:
|
|
1594
|
+
body: PasswordLoginRequest;
|
|
1623
1595
|
path?: never;
|
|
1624
1596
|
query?: never;
|
|
1625
1597
|
url: '/cfg/accounts/token/';
|
package/dist/clients.mjs
CHANGED
|
@@ -66,77 +66,263 @@ var APIError = class extends Error {
|
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
// src/_api/generated/helpers/
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
// src/_api/generated/helpers/keys.ts
|
|
70
|
+
var k = /* @__PURE__ */ __name((key, store, personal) => ({ key, store, personal }), "k");
|
|
71
|
+
var f = /* @__PURE__ */ __name((prefix, store, personal) => ({ prefix, store, personal }), "f");
|
|
72
|
+
var CFG_KEYS = {
|
|
73
|
+
accessToken: k("cfg.auth.access_token", "local", true),
|
|
74
|
+
refreshToken: k("cfg.auth.refresh_token", "local", true),
|
|
75
|
+
apiKey: k("cfg.auth.api_key", "local", true),
|
|
76
|
+
email: k("cfg.auth.email", "local", false),
|
|
77
|
+
emailTs: k("cfg.auth.email_ts", "local", false),
|
|
78
|
+
redirectUrl: k("cfg.auth.redirect_url", "session", true),
|
|
79
|
+
redirectUrlTs: k("cfg.auth.redirect_url_ts", "session", true),
|
|
80
|
+
oauthState: k("cfg.auth.oauth_state", "session", true),
|
|
81
|
+
oauthProvider: k("cfg.auth.oauth_provider", "session", true),
|
|
82
|
+
profileCache: k("cfg.profile.cache", "local", true),
|
|
83
|
+
monitorSessionId: k("cfg.monitor.session_id", "local", false),
|
|
84
|
+
monitorSessionCookie: k("cfg.monitor.session_id", "cookie", false),
|
|
85
|
+
monitorDebug: k("cfg.monitor.debug", "local", false),
|
|
86
|
+
uiTabId: k("cfg.ui.tab_id", "session", false),
|
|
87
|
+
uiRouterSerial: k("cfg.ui.router_serial", "session", false),
|
|
88
|
+
uiState: k("cfg.ui.state", "local", false),
|
|
89
|
+
chatSpeechLanguage: k("cfg.chat.speech_language", "local", false),
|
|
90
|
+
chatRecentTools: k("cfg.chat.recent_tools", "local", false),
|
|
91
|
+
formsSpeechDebug: k("cfg.forms.speech_debug", "local", false),
|
|
92
|
+
formsSpeechPrefs: k("cfg.forms.speech_prefs", "local", false),
|
|
93
|
+
agentPlaygroundApiKeyId: k("cfg.agent.playground_api_key_id", "session", true),
|
|
94
|
+
agentPlaygroundBearer: k("cfg.agent.playground_bearer", "session", true),
|
|
95
|
+
agentEndpointDoc: k("cfg.agent.endpoint_doc", "session", false)
|
|
96
|
+
};
|
|
97
|
+
var CFG_FAMILIES = {
|
|
98
|
+
chatDraft: f("cfg.chat.draft.", "session", true),
|
|
99
|
+
dataTree: f("cfg.data.tree.", "local", false),
|
|
100
|
+
agentEndpointDraft: f("cfg.agent.endpoint_draft.", "local", false)
|
|
101
|
+
};
|
|
102
|
+
var OWNER_RE = /^[a-z][a-z0-9_]*$/;
|
|
103
|
+
function normalizeSegment(raw) {
|
|
104
|
+
return raw.trim().toLowerCase().replace(/[^a-z0-9_]+/g, "_").replace(/^_+|_+$/g, "");
|
|
105
|
+
}
|
|
106
|
+
__name(normalizeSegment, "normalizeSegment");
|
|
107
|
+
var hasWindow = /* @__PURE__ */ __name(() => typeof window !== "undefined", "hasWindow");
|
|
108
|
+
function nativeStorage(store) {
|
|
109
|
+
if (!hasWindow()) return null;
|
|
110
|
+
try {
|
|
111
|
+
return store === "session" ? window.sessionStorage : window.localStorage;
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
__name(nativeStorage, "nativeStorage");
|
|
117
|
+
function cookieNames() {
|
|
118
|
+
if (!hasWindow()) return [];
|
|
119
|
+
try {
|
|
120
|
+
return document.cookie.split("; ").map((part) => decodeURIComponent(part.split("=")[0] ?? "")).filter(Boolean);
|
|
121
|
+
} catch {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
__name(cookieNames, "cookieNames");
|
|
126
|
+
function createStorage(owner, options = {}) {
|
|
127
|
+
if (!OWNER_RE.test(owner)) {
|
|
128
|
+
throw new TypeError(`createStorage: owner "${owner}" must match ${OWNER_RE}`);
|
|
129
|
+
}
|
|
130
|
+
const prefix = `${owner}.`;
|
|
131
|
+
const pattern = owner === "cfg" ? /^cfg(\.[a-z0-9_]+)+$/ : new RegExp(`^(cfg|${owner})(\\.[a-z0-9_]+)+$`);
|
|
132
|
+
const cookieMaxAge = options.cookieMaxAgeSeconds ?? 60 * 60 * 24 * 30;
|
|
133
|
+
const specs = Object.values(options.keys ?? {});
|
|
134
|
+
const families = Object.values(options.families ?? {});
|
|
135
|
+
const specByKey = /* @__PURE__ */ new Map();
|
|
136
|
+
for (const spec of specs) specByKey.set(spec.key, [...specByKey.get(spec.key) ?? [], spec]);
|
|
137
|
+
const memory = {
|
|
138
|
+
local: /* @__PURE__ */ new Map(),
|
|
139
|
+
session: /* @__PURE__ */ new Map(),
|
|
140
|
+
cookie: /* @__PURE__ */ new Map()
|
|
141
|
+
};
|
|
142
|
+
const isValid = /* @__PURE__ */ __name((key) => pattern.test(key), "isValid");
|
|
143
|
+
const assertValid = /* @__PURE__ */ __name((key) => {
|
|
144
|
+
if (!isValid(key)) throw new TypeError(`storage key "${key}" must match ${pattern}`);
|
|
145
|
+
}, "assertValid");
|
|
146
|
+
const assertOwned = /* @__PURE__ */ __name((key) => {
|
|
147
|
+
assertValid(key);
|
|
148
|
+
if (!key.startsWith(prefix)) throw new TypeError(`storage key "${key}" is not owned by "${owner}"`);
|
|
149
|
+
}, "assertOwned");
|
|
150
|
+
function rawGet(store, key) {
|
|
151
|
+
if (!hasWindow()) return null;
|
|
152
|
+
if (store === "cookie") {
|
|
153
|
+
try {
|
|
154
|
+
const escaped = encodeURIComponent(key).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
155
|
+
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${escaped}=([^;]*)`));
|
|
156
|
+
if (match?.[1] !== void 0) return decodeURIComponent(match[1]);
|
|
157
|
+
} catch {
|
|
158
|
+
}
|
|
159
|
+
return memory.cookie.get(key) ?? null;
|
|
81
160
|
}
|
|
82
|
-
},
|
|
83
|
-
set(key, value) {
|
|
84
|
-
if (!isBrowser) return;
|
|
85
161
|
try {
|
|
86
|
-
|
|
87
|
-
|
|
162
|
+
const value = nativeStorage(store)?.getItem(key) ?? null;
|
|
163
|
+
if (value !== null) return value;
|
|
88
164
|
} catch {
|
|
89
165
|
}
|
|
166
|
+
return memory[store].get(key) ?? null;
|
|
90
167
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (!isBrowser) return null;
|
|
168
|
+
__name(rawGet, "rawGet");
|
|
169
|
+
function rawSet(store, key, value) {
|
|
170
|
+
if (!hasWindow()) return false;
|
|
95
171
|
try {
|
|
96
|
-
|
|
172
|
+
if (store === "cookie") {
|
|
173
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
174
|
+
document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}; Path=/; Max-Age=${cookieMaxAge}; SameSite=Lax${secure}`;
|
|
175
|
+
if (rawGet("cookie", key) === value && !memory.cookie.has(key)) return true;
|
|
176
|
+
memory.cookie.set(key, value);
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const native = nativeStorage(store);
|
|
180
|
+
if (!native) throw new Error("storage unavailable");
|
|
181
|
+
native.setItem(key, value);
|
|
182
|
+
memory[store].delete(key);
|
|
183
|
+
return true;
|
|
97
184
|
} catch {
|
|
98
|
-
|
|
185
|
+
memory[store].set(key, value);
|
|
186
|
+
return false;
|
|
99
187
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
188
|
+
}
|
|
189
|
+
__name(rawSet, "rawSet");
|
|
190
|
+
function rawRemove(store, key) {
|
|
191
|
+
memory[store].delete(key);
|
|
192
|
+
if (!hasWindow()) return;
|
|
103
193
|
try {
|
|
104
|
-
if (
|
|
105
|
-
|
|
194
|
+
if (store === "cookie") {
|
|
195
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
196
|
+
document.cookie = `${encodeURIComponent(key)}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
|
|
197
|
+
} else {
|
|
198
|
+
nativeStorage(store)?.removeItem(key);
|
|
199
|
+
}
|
|
106
200
|
} catch {
|
|
107
201
|
}
|
|
108
202
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
203
|
+
__name(rawRemove, "rawRemove");
|
|
204
|
+
function resolveStore(key, store) {
|
|
205
|
+
return store ?? specByKey.get(key)?.[0]?.store ?? "local";
|
|
206
|
+
}
|
|
207
|
+
__name(resolveStore, "resolveStore");
|
|
208
|
+
function listKeys(store, startsWith) {
|
|
209
|
+
const out = [];
|
|
114
210
|
try {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
211
|
+
const native = nativeStorage(store);
|
|
212
|
+
if (native) {
|
|
213
|
+
for (let i = 0; i < native.length; i += 1) {
|
|
214
|
+
const name = native.key(i);
|
|
215
|
+
if (name?.startsWith(startsWith)) out.push(name);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
119
218
|
} catch {
|
|
120
|
-
return null;
|
|
121
219
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
220
|
+
for (const name of memory[store].keys()) if (name.startsWith(startsWith) && !out.includes(name)) out.push(name);
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
__name(listKeys, "listKeys");
|
|
224
|
+
const familyKey = /* @__PURE__ */ __name((family, id) => {
|
|
225
|
+
const part = normalizeSegment(id);
|
|
226
|
+
if (!part) throw new TypeError("storage family id is empty after normalisation");
|
|
227
|
+
return family.prefix + part;
|
|
228
|
+
}, "familyKey");
|
|
229
|
+
const api = {
|
|
230
|
+
owner,
|
|
231
|
+
key(...parts) {
|
|
232
|
+
const segments = parts.map(normalizeSegment);
|
|
233
|
+
if (segments.length === 0 || segments.some((segment) => !segment)) {
|
|
234
|
+
throw new TypeError(`storage key parts must be non-empty: ${JSON.stringify(parts)}`);
|
|
133
235
|
}
|
|
134
|
-
|
|
236
|
+
return `${prefix}${segments.join(".")}`;
|
|
237
|
+
},
|
|
238
|
+
familyKey,
|
|
239
|
+
isValid,
|
|
240
|
+
read(key, store) {
|
|
241
|
+
assertValid(key);
|
|
242
|
+
const target = resolveStore(key, store);
|
|
243
|
+
return rawGet(target, key);
|
|
244
|
+
},
|
|
245
|
+
write(key, value, store) {
|
|
246
|
+
assertOwned(key);
|
|
247
|
+
const target = resolveStore(key, store);
|
|
248
|
+
return rawSet(target, key, value);
|
|
249
|
+
},
|
|
250
|
+
remove(key, store) {
|
|
251
|
+
assertOwned(key);
|
|
252
|
+
const target = resolveStore(key, store);
|
|
253
|
+
rawRemove(target, key);
|
|
254
|
+
},
|
|
255
|
+
readJSON(key, store) {
|
|
256
|
+
const raw = api.read(key, store);
|
|
257
|
+
if (raw === null) return null;
|
|
258
|
+
try {
|
|
259
|
+
return JSON.parse(raw);
|
|
260
|
+
} catch {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
writeJSON(key, value, store) {
|
|
265
|
+
return api.write(key, JSON.stringify(value), store);
|
|
266
|
+
},
|
|
267
|
+
keys(store = "local") {
|
|
268
|
+
return listKeys(store, prefix);
|
|
269
|
+
},
|
|
270
|
+
clearAll({ all = false } = {}) {
|
|
271
|
+
for (const spec of specs) {
|
|
272
|
+
if (!all && !spec.personal) continue;
|
|
273
|
+
rawRemove(spec.store, spec.key);
|
|
274
|
+
}
|
|
275
|
+
for (const family of families) {
|
|
276
|
+
if (!all && !family.personal) continue;
|
|
277
|
+
for (const name of listKeys(family.store, family.prefix)) rawRemove(family.store, name);
|
|
278
|
+
}
|
|
279
|
+
if (all) {
|
|
280
|
+
for (const store of ["local", "session"]) {
|
|
281
|
+
for (const name of listKeys(store, prefix)) rawRemove(store, name);
|
|
282
|
+
}
|
|
283
|
+
for (const name of cookieNames()) if (name.startsWith(prefix)) rawRemove("cookie", name);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
onChange(key, listener, store = "local") {
|
|
287
|
+
assertValid(key);
|
|
288
|
+
if (!hasWindow()) return () => {
|
|
289
|
+
};
|
|
290
|
+
const handler = /* @__PURE__ */ __name((event) => {
|
|
291
|
+
if (event.storageArea !== nativeStorage(store)) return;
|
|
292
|
+
if (event.key === null || event.key === key) listener(event.key === null ? null : event.newValue);
|
|
293
|
+
}, "handler");
|
|
294
|
+
window.addEventListener("storage", handler);
|
|
295
|
+
return () => window.removeEventListener("storage", handler);
|
|
135
296
|
}
|
|
136
|
-
}
|
|
297
|
+
};
|
|
298
|
+
return api;
|
|
299
|
+
}
|
|
300
|
+
__name(createStorage, "createStorage");
|
|
301
|
+
var cfgStorage = createStorage("cfg", {
|
|
302
|
+
keys: CFG_KEYS,
|
|
303
|
+
families: CFG_FAMILIES
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// src/_api/generated/helpers/auth.ts
|
|
307
|
+
var ACCESS_KEY = "cfg.auth.access_token";
|
|
308
|
+
var REFRESH_KEY = "cfg.auth.refresh_token";
|
|
309
|
+
var API_KEY_KEY = "cfg.auth.api_key";
|
|
310
|
+
var storage = true ? cfgStorage : createStorage2("cfg");
|
|
311
|
+
var isBrowser = typeof window !== "undefined";
|
|
312
|
+
var STORE_OF = {
|
|
313
|
+
localStorage: "local",
|
|
314
|
+
sessionStorage: "session",
|
|
315
|
+
cookie: "cookie"
|
|
137
316
|
};
|
|
138
317
|
function backendFor(mode) {
|
|
139
|
-
|
|
318
|
+
const store = STORE_OF[mode];
|
|
319
|
+
return {
|
|
320
|
+
get: /* @__PURE__ */ __name((key) => storage.read(key, store), "get"),
|
|
321
|
+
set(key, value) {
|
|
322
|
+
if (value === null) storage.remove(key, store);
|
|
323
|
+
else storage.write(key, value, store);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
140
326
|
}
|
|
141
327
|
__name(backendFor, "backendFor");
|
|
142
328
|
var _storageMode = "localStorage";
|
|
@@ -325,10 +511,12 @@ var auth = {
|
|
|
325
511
|
notifySessionChanged();
|
|
326
512
|
},
|
|
327
513
|
clearTokens() {
|
|
328
|
-
for (const
|
|
514
|
+
for (const mode of ["localStorage", "sessionStorage", "cookie"]) {
|
|
515
|
+
const backend = backendFor(mode);
|
|
329
516
|
backend.set(ACCESS_KEY, null);
|
|
330
517
|
backend.set(REFRESH_KEY, null);
|
|
331
518
|
}
|
|
519
|
+
storage.clearAll();
|
|
332
520
|
notifySessionChanged();
|
|
333
521
|
},
|
|
334
522
|
/** Session-aware: token PRESENT and not past its `exp` (or a live refresh
|
|
@@ -520,7 +708,7 @@ function dpopEnabled() {
|
|
|
520
708
|
}
|
|
521
709
|
}
|
|
522
710
|
__name(dpopEnabled, "dpopEnabled");
|
|
523
|
-
var _DPOP_DB = "cfg
|
|
711
|
+
var _DPOP_DB = "cfg.auth.dpop";
|
|
524
712
|
var _DPOP_STORE = "keys";
|
|
525
713
|
var _DPOP_KEY_ID = "dpop-ec-p256";
|
|
526
714
|
function _idbOpen() {
|