@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/hooks.mjs
CHANGED
|
@@ -864,77 +864,263 @@ var APIError = class extends Error {
|
|
|
864
864
|
}
|
|
865
865
|
};
|
|
866
866
|
|
|
867
|
-
// src/_api/generated/helpers/
|
|
868
|
-
var
|
|
869
|
-
var
|
|
870
|
-
var
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
867
|
+
// src/_api/generated/helpers/keys.ts
|
|
868
|
+
var k = /* @__PURE__ */ __name((key, store, personal) => ({ key, store, personal }), "k");
|
|
869
|
+
var f = /* @__PURE__ */ __name((prefix, store, personal) => ({ prefix, store, personal }), "f");
|
|
870
|
+
var CFG_KEYS = {
|
|
871
|
+
accessToken: k("cfg.auth.access_token", "local", true),
|
|
872
|
+
refreshToken: k("cfg.auth.refresh_token", "local", true),
|
|
873
|
+
apiKey: k("cfg.auth.api_key", "local", true),
|
|
874
|
+
email: k("cfg.auth.email", "local", false),
|
|
875
|
+
emailTs: k("cfg.auth.email_ts", "local", false),
|
|
876
|
+
redirectUrl: k("cfg.auth.redirect_url", "session", true),
|
|
877
|
+
redirectUrlTs: k("cfg.auth.redirect_url_ts", "session", true),
|
|
878
|
+
oauthState: k("cfg.auth.oauth_state", "session", true),
|
|
879
|
+
oauthProvider: k("cfg.auth.oauth_provider", "session", true),
|
|
880
|
+
profileCache: k("cfg.profile.cache", "local", true),
|
|
881
|
+
monitorSessionId: k("cfg.monitor.session_id", "local", false),
|
|
882
|
+
monitorSessionCookie: k("cfg.monitor.session_id", "cookie", false),
|
|
883
|
+
monitorDebug: k("cfg.monitor.debug", "local", false),
|
|
884
|
+
uiTabId: k("cfg.ui.tab_id", "session", false),
|
|
885
|
+
uiRouterSerial: k("cfg.ui.router_serial", "session", false),
|
|
886
|
+
uiState: k("cfg.ui.state", "local", false),
|
|
887
|
+
chatSpeechLanguage: k("cfg.chat.speech_language", "local", false),
|
|
888
|
+
chatRecentTools: k("cfg.chat.recent_tools", "local", false),
|
|
889
|
+
formsSpeechDebug: k("cfg.forms.speech_debug", "local", false),
|
|
890
|
+
formsSpeechPrefs: k("cfg.forms.speech_prefs", "local", false),
|
|
891
|
+
agentPlaygroundApiKeyId: k("cfg.agent.playground_api_key_id", "session", true),
|
|
892
|
+
agentPlaygroundBearer: k("cfg.agent.playground_bearer", "session", true),
|
|
893
|
+
agentEndpointDoc: k("cfg.agent.endpoint_doc", "session", false)
|
|
894
|
+
};
|
|
895
|
+
var CFG_FAMILIES = {
|
|
896
|
+
chatDraft: f("cfg.chat.draft.", "session", true),
|
|
897
|
+
dataTree: f("cfg.data.tree.", "local", false),
|
|
898
|
+
agentEndpointDraft: f("cfg.agent.endpoint_draft.", "local", false)
|
|
899
|
+
};
|
|
900
|
+
var OWNER_RE = /^[a-z][a-z0-9_]*$/;
|
|
901
|
+
function normalizeSegment(raw) {
|
|
902
|
+
return raw.trim().toLowerCase().replace(/[^a-z0-9_]+/g, "_").replace(/^_+|_+$/g, "");
|
|
903
|
+
}
|
|
904
|
+
__name(normalizeSegment, "normalizeSegment");
|
|
905
|
+
var hasWindow = /* @__PURE__ */ __name(() => typeof window !== "undefined", "hasWindow");
|
|
906
|
+
function nativeStorage(store) {
|
|
907
|
+
if (!hasWindow()) return null;
|
|
908
|
+
try {
|
|
909
|
+
return store === "session" ? window.sessionStorage : window.localStorage;
|
|
910
|
+
} catch {
|
|
911
|
+
return null;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
__name(nativeStorage, "nativeStorage");
|
|
915
|
+
function cookieNames() {
|
|
916
|
+
if (!hasWindow()) return [];
|
|
917
|
+
try {
|
|
918
|
+
return document.cookie.split("; ").map((part) => decodeURIComponent(part.split("=")[0] ?? "")).filter(Boolean);
|
|
919
|
+
} catch {
|
|
920
|
+
return [];
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
__name(cookieNames, "cookieNames");
|
|
924
|
+
function createStorage(owner, options = {}) {
|
|
925
|
+
if (!OWNER_RE.test(owner)) {
|
|
926
|
+
throw new TypeError(`createStorage: owner "${owner}" must match ${OWNER_RE}`);
|
|
927
|
+
}
|
|
928
|
+
const prefix = `${owner}.`;
|
|
929
|
+
const pattern = owner === "cfg" ? /^cfg(\.[a-z0-9_]+)+$/ : new RegExp(`^(cfg|${owner})(\\.[a-z0-9_]+)+$`);
|
|
930
|
+
const cookieMaxAge = options.cookieMaxAgeSeconds ?? 60 * 60 * 24 * 30;
|
|
931
|
+
const specs = Object.values(options.keys ?? {});
|
|
932
|
+
const families = Object.values(options.families ?? {});
|
|
933
|
+
const specByKey = /* @__PURE__ */ new Map();
|
|
934
|
+
for (const spec of specs) specByKey.set(spec.key, [...specByKey.get(spec.key) ?? [], spec]);
|
|
935
|
+
const memory = {
|
|
936
|
+
local: /* @__PURE__ */ new Map(),
|
|
937
|
+
session: /* @__PURE__ */ new Map(),
|
|
938
|
+
cookie: /* @__PURE__ */ new Map()
|
|
939
|
+
};
|
|
940
|
+
const isValid = /* @__PURE__ */ __name((key) => pattern.test(key), "isValid");
|
|
941
|
+
const assertValid = /* @__PURE__ */ __name((key) => {
|
|
942
|
+
if (!isValid(key)) throw new TypeError(`storage key "${key}" must match ${pattern}`);
|
|
943
|
+
}, "assertValid");
|
|
944
|
+
const assertOwned = /* @__PURE__ */ __name((key) => {
|
|
945
|
+
assertValid(key);
|
|
946
|
+
if (!key.startsWith(prefix)) throw new TypeError(`storage key "${key}" is not owned by "${owner}"`);
|
|
947
|
+
}, "assertOwned");
|
|
948
|
+
function rawGet(store, key) {
|
|
949
|
+
if (!hasWindow()) return null;
|
|
950
|
+
if (store === "cookie") {
|
|
951
|
+
try {
|
|
952
|
+
const escaped = encodeURIComponent(key).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
953
|
+
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${escaped}=([^;]*)`));
|
|
954
|
+
if (match?.[1] !== void 0) return decodeURIComponent(match[1]);
|
|
955
|
+
} catch {
|
|
956
|
+
}
|
|
957
|
+
return memory.cookie.get(key) ?? null;
|
|
879
958
|
}
|
|
880
|
-
},
|
|
881
|
-
set(key, value) {
|
|
882
|
-
if (!isBrowser) return;
|
|
883
959
|
try {
|
|
884
|
-
|
|
885
|
-
|
|
960
|
+
const value = nativeStorage(store)?.getItem(key) ?? null;
|
|
961
|
+
if (value !== null) return value;
|
|
886
962
|
} catch {
|
|
887
963
|
}
|
|
964
|
+
return memory[store].get(key) ?? null;
|
|
888
965
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
if (!isBrowser) return null;
|
|
966
|
+
__name(rawGet, "rawGet");
|
|
967
|
+
function rawSet(store, key, value) {
|
|
968
|
+
if (!hasWindow()) return false;
|
|
893
969
|
try {
|
|
894
|
-
|
|
970
|
+
if (store === "cookie") {
|
|
971
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
972
|
+
document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}; Path=/; Max-Age=${cookieMaxAge}; SameSite=Lax${secure}`;
|
|
973
|
+
if (rawGet("cookie", key) === value && !memory.cookie.has(key)) return true;
|
|
974
|
+
memory.cookie.set(key, value);
|
|
975
|
+
return false;
|
|
976
|
+
}
|
|
977
|
+
const native = nativeStorage(store);
|
|
978
|
+
if (!native) throw new Error("storage unavailable");
|
|
979
|
+
native.setItem(key, value);
|
|
980
|
+
memory[store].delete(key);
|
|
981
|
+
return true;
|
|
895
982
|
} catch {
|
|
896
|
-
|
|
983
|
+
memory[store].set(key, value);
|
|
984
|
+
return false;
|
|
897
985
|
}
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
|
|
986
|
+
}
|
|
987
|
+
__name(rawSet, "rawSet");
|
|
988
|
+
function rawRemove(store, key) {
|
|
989
|
+
memory[store].delete(key);
|
|
990
|
+
if (!hasWindow()) return;
|
|
901
991
|
try {
|
|
902
|
-
if (
|
|
903
|
-
|
|
992
|
+
if (store === "cookie") {
|
|
993
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
994
|
+
document.cookie = `${encodeURIComponent(key)}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
|
|
995
|
+
} else {
|
|
996
|
+
nativeStorage(store)?.removeItem(key);
|
|
997
|
+
}
|
|
904
998
|
} catch {
|
|
905
999
|
}
|
|
906
1000
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1001
|
+
__name(rawRemove, "rawRemove");
|
|
1002
|
+
function resolveStore(key, store) {
|
|
1003
|
+
return store ?? specByKey.get(key)?.[0]?.store ?? "local";
|
|
1004
|
+
}
|
|
1005
|
+
__name(resolveStore, "resolveStore");
|
|
1006
|
+
function listKeys(store, startsWith) {
|
|
1007
|
+
const out = [];
|
|
912
1008
|
try {
|
|
913
|
-
const
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
1009
|
+
const native = nativeStorage(store);
|
|
1010
|
+
if (native) {
|
|
1011
|
+
for (let i = 0; i < native.length; i += 1) {
|
|
1012
|
+
const name = native.key(i);
|
|
1013
|
+
if (name?.startsWith(startsWith)) out.push(name);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
917
1016
|
} catch {
|
|
918
|
-
return null;
|
|
919
1017
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1018
|
+
for (const name of memory[store].keys()) if (name.startsWith(startsWith) && !out.includes(name)) out.push(name);
|
|
1019
|
+
return out;
|
|
1020
|
+
}
|
|
1021
|
+
__name(listKeys, "listKeys");
|
|
1022
|
+
const familyKey = /* @__PURE__ */ __name((family, id) => {
|
|
1023
|
+
const part = normalizeSegment(id);
|
|
1024
|
+
if (!part) throw new TypeError("storage family id is empty after normalisation");
|
|
1025
|
+
return family.prefix + part;
|
|
1026
|
+
}, "familyKey");
|
|
1027
|
+
const api = {
|
|
1028
|
+
owner,
|
|
1029
|
+
key(...parts) {
|
|
1030
|
+
const segments = parts.map(normalizeSegment);
|
|
1031
|
+
if (segments.length === 0 || segments.some((segment) => !segment)) {
|
|
1032
|
+
throw new TypeError(`storage key parts must be non-empty: ${JSON.stringify(parts)}`);
|
|
931
1033
|
}
|
|
932
|
-
|
|
1034
|
+
return `${prefix}${segments.join(".")}`;
|
|
1035
|
+
},
|
|
1036
|
+
familyKey,
|
|
1037
|
+
isValid,
|
|
1038
|
+
read(key, store) {
|
|
1039
|
+
assertValid(key);
|
|
1040
|
+
const target = resolveStore(key, store);
|
|
1041
|
+
return rawGet(target, key);
|
|
1042
|
+
},
|
|
1043
|
+
write(key, value, store) {
|
|
1044
|
+
assertOwned(key);
|
|
1045
|
+
const target = resolveStore(key, store);
|
|
1046
|
+
return rawSet(target, key, value);
|
|
1047
|
+
},
|
|
1048
|
+
remove(key, store) {
|
|
1049
|
+
assertOwned(key);
|
|
1050
|
+
const target = resolveStore(key, store);
|
|
1051
|
+
rawRemove(target, key);
|
|
1052
|
+
},
|
|
1053
|
+
readJSON(key, store) {
|
|
1054
|
+
const raw = api.read(key, store);
|
|
1055
|
+
if (raw === null) return null;
|
|
1056
|
+
try {
|
|
1057
|
+
return JSON.parse(raw);
|
|
1058
|
+
} catch {
|
|
1059
|
+
return null;
|
|
1060
|
+
}
|
|
1061
|
+
},
|
|
1062
|
+
writeJSON(key, value, store) {
|
|
1063
|
+
return api.write(key, JSON.stringify(value), store);
|
|
1064
|
+
},
|
|
1065
|
+
keys(store = "local") {
|
|
1066
|
+
return listKeys(store, prefix);
|
|
1067
|
+
},
|
|
1068
|
+
clearAll({ all = false } = {}) {
|
|
1069
|
+
for (const spec of specs) {
|
|
1070
|
+
if (!all && !spec.personal) continue;
|
|
1071
|
+
rawRemove(spec.store, spec.key);
|
|
1072
|
+
}
|
|
1073
|
+
for (const family of families) {
|
|
1074
|
+
if (!all && !family.personal) continue;
|
|
1075
|
+
for (const name of listKeys(family.store, family.prefix)) rawRemove(family.store, name);
|
|
1076
|
+
}
|
|
1077
|
+
if (all) {
|
|
1078
|
+
for (const store of ["local", "session"]) {
|
|
1079
|
+
for (const name of listKeys(store, prefix)) rawRemove(store, name);
|
|
1080
|
+
}
|
|
1081
|
+
for (const name of cookieNames()) if (name.startsWith(prefix)) rawRemove("cookie", name);
|
|
1082
|
+
}
|
|
1083
|
+
},
|
|
1084
|
+
onChange(key, listener, store = "local") {
|
|
1085
|
+
assertValid(key);
|
|
1086
|
+
if (!hasWindow()) return () => {
|
|
1087
|
+
};
|
|
1088
|
+
const handler = /* @__PURE__ */ __name((event) => {
|
|
1089
|
+
if (event.storageArea !== nativeStorage(store)) return;
|
|
1090
|
+
if (event.key === null || event.key === key) listener(event.key === null ? null : event.newValue);
|
|
1091
|
+
}, "handler");
|
|
1092
|
+
window.addEventListener("storage", handler);
|
|
1093
|
+
return () => window.removeEventListener("storage", handler);
|
|
933
1094
|
}
|
|
934
|
-
}
|
|
1095
|
+
};
|
|
1096
|
+
return api;
|
|
1097
|
+
}
|
|
1098
|
+
__name(createStorage, "createStorage");
|
|
1099
|
+
var cfgStorage = createStorage("cfg", {
|
|
1100
|
+
keys: CFG_KEYS,
|
|
1101
|
+
families: CFG_FAMILIES
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
// src/_api/generated/helpers/auth.ts
|
|
1105
|
+
var ACCESS_KEY = "cfg.auth.access_token";
|
|
1106
|
+
var REFRESH_KEY = "cfg.auth.refresh_token";
|
|
1107
|
+
var API_KEY_KEY = "cfg.auth.api_key";
|
|
1108
|
+
var storage = true ? cfgStorage : createStorage2("cfg");
|
|
1109
|
+
var isBrowser = typeof window !== "undefined";
|
|
1110
|
+
var STORE_OF = {
|
|
1111
|
+
localStorage: "local",
|
|
1112
|
+
sessionStorage: "session",
|
|
1113
|
+
cookie: "cookie"
|
|
935
1114
|
};
|
|
936
1115
|
function backendFor(mode) {
|
|
937
|
-
|
|
1116
|
+
const store = STORE_OF[mode];
|
|
1117
|
+
return {
|
|
1118
|
+
get: /* @__PURE__ */ __name((key) => storage.read(key, store), "get"),
|
|
1119
|
+
set(key, value) {
|
|
1120
|
+
if (value === null) storage.remove(key, store);
|
|
1121
|
+
else storage.write(key, value, store);
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
938
1124
|
}
|
|
939
1125
|
__name(backendFor, "backendFor");
|
|
940
1126
|
var _storageMode = "localStorage";
|
|
@@ -1123,10 +1309,12 @@ var auth = {
|
|
|
1123
1309
|
notifySessionChanged();
|
|
1124
1310
|
},
|
|
1125
1311
|
clearTokens() {
|
|
1126
|
-
for (const
|
|
1312
|
+
for (const mode of ["localStorage", "sessionStorage", "cookie"]) {
|
|
1313
|
+
const backend = backendFor(mode);
|
|
1127
1314
|
backend.set(ACCESS_KEY, null);
|
|
1128
1315
|
backend.set(REFRESH_KEY, null);
|
|
1129
1316
|
}
|
|
1317
|
+
storage.clearAll();
|
|
1130
1318
|
notifySessionChanged();
|
|
1131
1319
|
},
|
|
1132
1320
|
/** Session-aware: token PRESENT and not past its `exp` (or a live refresh
|
|
@@ -1318,7 +1506,7 @@ function dpopEnabled() {
|
|
|
1318
1506
|
}
|
|
1319
1507
|
}
|
|
1320
1508
|
__name(dpopEnabled, "dpopEnabled");
|
|
1321
|
-
var _DPOP_DB = "cfg
|
|
1509
|
+
var _DPOP_DB = "cfg.auth.dpop";
|
|
1322
1510
|
var _DPOP_STORE = "keys";
|
|
1323
1511
|
var _DPOP_KEY_ID = "dpop-ec-p256";
|
|
1324
1512
|
function _idbOpen() {
|