@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.cjs
CHANGED
|
@@ -999,77 +999,263 @@ var APIError = class extends Error {
|
|
|
999
999
|
}
|
|
1000
1000
|
};
|
|
1001
1001
|
|
|
1002
|
-
// src/_api/generated/helpers/
|
|
1003
|
-
var
|
|
1004
|
-
var
|
|
1005
|
-
var
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1002
|
+
// src/_api/generated/helpers/keys.ts
|
|
1003
|
+
var k = /* @__PURE__ */ __name((key, store, personal) => ({ key, store, personal }), "k");
|
|
1004
|
+
var f = /* @__PURE__ */ __name((prefix, store, personal) => ({ prefix, store, personal }), "f");
|
|
1005
|
+
var CFG_KEYS = {
|
|
1006
|
+
accessToken: k("cfg.auth.access_token", "local", true),
|
|
1007
|
+
refreshToken: k("cfg.auth.refresh_token", "local", true),
|
|
1008
|
+
apiKey: k("cfg.auth.api_key", "local", true),
|
|
1009
|
+
email: k("cfg.auth.email", "local", false),
|
|
1010
|
+
emailTs: k("cfg.auth.email_ts", "local", false),
|
|
1011
|
+
redirectUrl: k("cfg.auth.redirect_url", "session", true),
|
|
1012
|
+
redirectUrlTs: k("cfg.auth.redirect_url_ts", "session", true),
|
|
1013
|
+
oauthState: k("cfg.auth.oauth_state", "session", true),
|
|
1014
|
+
oauthProvider: k("cfg.auth.oauth_provider", "session", true),
|
|
1015
|
+
profileCache: k("cfg.profile.cache", "local", true),
|
|
1016
|
+
monitorSessionId: k("cfg.monitor.session_id", "local", false),
|
|
1017
|
+
monitorSessionCookie: k("cfg.monitor.session_id", "cookie", false),
|
|
1018
|
+
monitorDebug: k("cfg.monitor.debug", "local", false),
|
|
1019
|
+
uiTabId: k("cfg.ui.tab_id", "session", false),
|
|
1020
|
+
uiRouterSerial: k("cfg.ui.router_serial", "session", false),
|
|
1021
|
+
uiState: k("cfg.ui.state", "local", false),
|
|
1022
|
+
chatSpeechLanguage: k("cfg.chat.speech_language", "local", false),
|
|
1023
|
+
chatRecentTools: k("cfg.chat.recent_tools", "local", false),
|
|
1024
|
+
formsSpeechDebug: k("cfg.forms.speech_debug", "local", false),
|
|
1025
|
+
formsSpeechPrefs: k("cfg.forms.speech_prefs", "local", false),
|
|
1026
|
+
agentPlaygroundApiKeyId: k("cfg.agent.playground_api_key_id", "session", true),
|
|
1027
|
+
agentPlaygroundBearer: k("cfg.agent.playground_bearer", "session", true),
|
|
1028
|
+
agentEndpointDoc: k("cfg.agent.endpoint_doc", "session", false)
|
|
1029
|
+
};
|
|
1030
|
+
var CFG_FAMILIES = {
|
|
1031
|
+
chatDraft: f("cfg.chat.draft.", "session", true),
|
|
1032
|
+
dataTree: f("cfg.data.tree.", "local", false),
|
|
1033
|
+
agentEndpointDraft: f("cfg.agent.endpoint_draft.", "local", false)
|
|
1034
|
+
};
|
|
1035
|
+
var OWNER_RE = /^[a-z][a-z0-9_]*$/;
|
|
1036
|
+
function normalizeSegment(raw) {
|
|
1037
|
+
return raw.trim().toLowerCase().replace(/[^a-z0-9_]+/g, "_").replace(/^_+|_+$/g, "");
|
|
1038
|
+
}
|
|
1039
|
+
__name(normalizeSegment, "normalizeSegment");
|
|
1040
|
+
var hasWindow = /* @__PURE__ */ __name(() => typeof window !== "undefined", "hasWindow");
|
|
1041
|
+
function nativeStorage(store) {
|
|
1042
|
+
if (!hasWindow()) return null;
|
|
1043
|
+
try {
|
|
1044
|
+
return store === "session" ? window.sessionStorage : window.localStorage;
|
|
1045
|
+
} catch {
|
|
1046
|
+
return null;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
__name(nativeStorage, "nativeStorage");
|
|
1050
|
+
function cookieNames() {
|
|
1051
|
+
if (!hasWindow()) return [];
|
|
1052
|
+
try {
|
|
1053
|
+
return document.cookie.split("; ").map((part) => decodeURIComponent(part.split("=")[0] ?? "")).filter(Boolean);
|
|
1054
|
+
} catch {
|
|
1055
|
+
return [];
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
__name(cookieNames, "cookieNames");
|
|
1059
|
+
function createStorage(owner, options = {}) {
|
|
1060
|
+
if (!OWNER_RE.test(owner)) {
|
|
1061
|
+
throw new TypeError(`createStorage: owner "${owner}" must match ${OWNER_RE}`);
|
|
1062
|
+
}
|
|
1063
|
+
const prefix = `${owner}.`;
|
|
1064
|
+
const pattern = owner === "cfg" ? /^cfg(\.[a-z0-9_]+)+$/ : new RegExp(`^(cfg|${owner})(\\.[a-z0-9_]+)+$`);
|
|
1065
|
+
const cookieMaxAge = options.cookieMaxAgeSeconds ?? 60 * 60 * 24 * 30;
|
|
1066
|
+
const specs = Object.values(options.keys ?? {});
|
|
1067
|
+
const families = Object.values(options.families ?? {});
|
|
1068
|
+
const specByKey = /* @__PURE__ */ new Map();
|
|
1069
|
+
for (const spec of specs) specByKey.set(spec.key, [...specByKey.get(spec.key) ?? [], spec]);
|
|
1070
|
+
const memory = {
|
|
1071
|
+
local: /* @__PURE__ */ new Map(),
|
|
1072
|
+
session: /* @__PURE__ */ new Map(),
|
|
1073
|
+
cookie: /* @__PURE__ */ new Map()
|
|
1074
|
+
};
|
|
1075
|
+
const isValid = /* @__PURE__ */ __name((key) => pattern.test(key), "isValid");
|
|
1076
|
+
const assertValid = /* @__PURE__ */ __name((key) => {
|
|
1077
|
+
if (!isValid(key)) throw new TypeError(`storage key "${key}" must match ${pattern}`);
|
|
1078
|
+
}, "assertValid");
|
|
1079
|
+
const assertOwned = /* @__PURE__ */ __name((key) => {
|
|
1080
|
+
assertValid(key);
|
|
1081
|
+
if (!key.startsWith(prefix)) throw new TypeError(`storage key "${key}" is not owned by "${owner}"`);
|
|
1082
|
+
}, "assertOwned");
|
|
1083
|
+
function rawGet(store, key) {
|
|
1084
|
+
if (!hasWindow()) return null;
|
|
1085
|
+
if (store === "cookie") {
|
|
1086
|
+
try {
|
|
1087
|
+
const escaped = encodeURIComponent(key).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1088
|
+
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${escaped}=([^;]*)`));
|
|
1089
|
+
if (match?.[1] !== void 0) return decodeURIComponent(match[1]);
|
|
1090
|
+
} catch {
|
|
1091
|
+
}
|
|
1092
|
+
return memory.cookie.get(key) ?? null;
|
|
1014
1093
|
}
|
|
1015
|
-
},
|
|
1016
|
-
set(key, value) {
|
|
1017
|
-
if (!isBrowser) return;
|
|
1018
1094
|
try {
|
|
1019
|
-
|
|
1020
|
-
|
|
1095
|
+
const value = nativeStorage(store)?.getItem(key) ?? null;
|
|
1096
|
+
if (value !== null) return value;
|
|
1021
1097
|
} catch {
|
|
1022
1098
|
}
|
|
1099
|
+
return memory[store].get(key) ?? null;
|
|
1023
1100
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
if (!isBrowser) return null;
|
|
1101
|
+
__name(rawGet, "rawGet");
|
|
1102
|
+
function rawSet(store, key, value) {
|
|
1103
|
+
if (!hasWindow()) return false;
|
|
1028
1104
|
try {
|
|
1029
|
-
|
|
1105
|
+
if (store === "cookie") {
|
|
1106
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
1107
|
+
document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}; Path=/; Max-Age=${cookieMaxAge}; SameSite=Lax${secure}`;
|
|
1108
|
+
if (rawGet("cookie", key) === value && !memory.cookie.has(key)) return true;
|
|
1109
|
+
memory.cookie.set(key, value);
|
|
1110
|
+
return false;
|
|
1111
|
+
}
|
|
1112
|
+
const native = nativeStorage(store);
|
|
1113
|
+
if (!native) throw new Error("storage unavailable");
|
|
1114
|
+
native.setItem(key, value);
|
|
1115
|
+
memory[store].delete(key);
|
|
1116
|
+
return true;
|
|
1030
1117
|
} catch {
|
|
1031
|
-
|
|
1118
|
+
memory[store].set(key, value);
|
|
1119
|
+
return false;
|
|
1032
1120
|
}
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1121
|
+
}
|
|
1122
|
+
__name(rawSet, "rawSet");
|
|
1123
|
+
function rawRemove(store, key) {
|
|
1124
|
+
memory[store].delete(key);
|
|
1125
|
+
if (!hasWindow()) return;
|
|
1036
1126
|
try {
|
|
1037
|
-
if (
|
|
1038
|
-
|
|
1127
|
+
if (store === "cookie") {
|
|
1128
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
1129
|
+
document.cookie = `${encodeURIComponent(key)}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
|
|
1130
|
+
} else {
|
|
1131
|
+
nativeStorage(store)?.removeItem(key);
|
|
1132
|
+
}
|
|
1039
1133
|
} catch {
|
|
1040
1134
|
}
|
|
1041
1135
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1136
|
+
__name(rawRemove, "rawRemove");
|
|
1137
|
+
function resolveStore(key, store) {
|
|
1138
|
+
return store ?? specByKey.get(key)?.[0]?.store ?? "local";
|
|
1139
|
+
}
|
|
1140
|
+
__name(resolveStore, "resolveStore");
|
|
1141
|
+
function listKeys(store, startsWith) {
|
|
1142
|
+
const out = [];
|
|
1047
1143
|
try {
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1144
|
+
const native = nativeStorage(store);
|
|
1145
|
+
if (native) {
|
|
1146
|
+
for (let i = 0; i < native.length; i += 1) {
|
|
1147
|
+
const name = native.key(i);
|
|
1148
|
+
if (name?.startsWith(startsWith)) out.push(name);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1052
1151
|
} catch {
|
|
1053
|
-
return null;
|
|
1054
1152
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1153
|
+
for (const name of memory[store].keys()) if (name.startsWith(startsWith) && !out.includes(name)) out.push(name);
|
|
1154
|
+
return out;
|
|
1155
|
+
}
|
|
1156
|
+
__name(listKeys, "listKeys");
|
|
1157
|
+
const familyKey = /* @__PURE__ */ __name((family, id) => {
|
|
1158
|
+
const part = normalizeSegment(id);
|
|
1159
|
+
if (!part) throw new TypeError("storage family id is empty after normalisation");
|
|
1160
|
+
return family.prefix + part;
|
|
1161
|
+
}, "familyKey");
|
|
1162
|
+
const api = {
|
|
1163
|
+
owner,
|
|
1164
|
+
key(...parts) {
|
|
1165
|
+
const segments = parts.map(normalizeSegment);
|
|
1166
|
+
if (segments.length === 0 || segments.some((segment) => !segment)) {
|
|
1167
|
+
throw new TypeError(`storage key parts must be non-empty: ${JSON.stringify(parts)}`);
|
|
1066
1168
|
}
|
|
1067
|
-
|
|
1169
|
+
return `${prefix}${segments.join(".")}`;
|
|
1170
|
+
},
|
|
1171
|
+
familyKey,
|
|
1172
|
+
isValid,
|
|
1173
|
+
read(key, store) {
|
|
1174
|
+
assertValid(key);
|
|
1175
|
+
const target = resolveStore(key, store);
|
|
1176
|
+
return rawGet(target, key);
|
|
1177
|
+
},
|
|
1178
|
+
write(key, value, store) {
|
|
1179
|
+
assertOwned(key);
|
|
1180
|
+
const target = resolveStore(key, store);
|
|
1181
|
+
return rawSet(target, key, value);
|
|
1182
|
+
},
|
|
1183
|
+
remove(key, store) {
|
|
1184
|
+
assertOwned(key);
|
|
1185
|
+
const target = resolveStore(key, store);
|
|
1186
|
+
rawRemove(target, key);
|
|
1187
|
+
},
|
|
1188
|
+
readJSON(key, store) {
|
|
1189
|
+
const raw = api.read(key, store);
|
|
1190
|
+
if (raw === null) return null;
|
|
1191
|
+
try {
|
|
1192
|
+
return JSON.parse(raw);
|
|
1193
|
+
} catch {
|
|
1194
|
+
return null;
|
|
1195
|
+
}
|
|
1196
|
+
},
|
|
1197
|
+
writeJSON(key, value, store) {
|
|
1198
|
+
return api.write(key, JSON.stringify(value), store);
|
|
1199
|
+
},
|
|
1200
|
+
keys(store = "local") {
|
|
1201
|
+
return listKeys(store, prefix);
|
|
1202
|
+
},
|
|
1203
|
+
clearAll({ all = false } = {}) {
|
|
1204
|
+
for (const spec of specs) {
|
|
1205
|
+
if (!all && !spec.personal) continue;
|
|
1206
|
+
rawRemove(spec.store, spec.key);
|
|
1207
|
+
}
|
|
1208
|
+
for (const family of families) {
|
|
1209
|
+
if (!all && !family.personal) continue;
|
|
1210
|
+
for (const name of listKeys(family.store, family.prefix)) rawRemove(family.store, name);
|
|
1211
|
+
}
|
|
1212
|
+
if (all) {
|
|
1213
|
+
for (const store of ["local", "session"]) {
|
|
1214
|
+
for (const name of listKeys(store, prefix)) rawRemove(store, name);
|
|
1215
|
+
}
|
|
1216
|
+
for (const name of cookieNames()) if (name.startsWith(prefix)) rawRemove("cookie", name);
|
|
1217
|
+
}
|
|
1218
|
+
},
|
|
1219
|
+
onChange(key, listener, store = "local") {
|
|
1220
|
+
assertValid(key);
|
|
1221
|
+
if (!hasWindow()) return () => {
|
|
1222
|
+
};
|
|
1223
|
+
const handler = /* @__PURE__ */ __name((event) => {
|
|
1224
|
+
if (event.storageArea !== nativeStorage(store)) return;
|
|
1225
|
+
if (event.key === null || event.key === key) listener(event.key === null ? null : event.newValue);
|
|
1226
|
+
}, "handler");
|
|
1227
|
+
window.addEventListener("storage", handler);
|
|
1228
|
+
return () => window.removeEventListener("storage", handler);
|
|
1068
1229
|
}
|
|
1069
|
-
}
|
|
1230
|
+
};
|
|
1231
|
+
return api;
|
|
1232
|
+
}
|
|
1233
|
+
__name(createStorage, "createStorage");
|
|
1234
|
+
var cfgStorage = createStorage("cfg", {
|
|
1235
|
+
keys: CFG_KEYS,
|
|
1236
|
+
families: CFG_FAMILIES
|
|
1237
|
+
});
|
|
1238
|
+
|
|
1239
|
+
// src/_api/generated/helpers/auth.ts
|
|
1240
|
+
var ACCESS_KEY = "cfg.auth.access_token";
|
|
1241
|
+
var REFRESH_KEY = "cfg.auth.refresh_token";
|
|
1242
|
+
var API_KEY_KEY = "cfg.auth.api_key";
|
|
1243
|
+
var storage = true ? cfgStorage : createStorage2("cfg");
|
|
1244
|
+
var isBrowser = typeof window !== "undefined";
|
|
1245
|
+
var STORE_OF = {
|
|
1246
|
+
localStorage: "local",
|
|
1247
|
+
sessionStorage: "session",
|
|
1248
|
+
cookie: "cookie"
|
|
1070
1249
|
};
|
|
1071
1250
|
function backendFor(mode) {
|
|
1072
|
-
|
|
1251
|
+
const store = STORE_OF[mode];
|
|
1252
|
+
return {
|
|
1253
|
+
get: /* @__PURE__ */ __name((key) => storage.read(key, store), "get"),
|
|
1254
|
+
set(key, value) {
|
|
1255
|
+
if (value === null) storage.remove(key, store);
|
|
1256
|
+
else storage.write(key, value, store);
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1073
1259
|
}
|
|
1074
1260
|
__name(backendFor, "backendFor");
|
|
1075
1261
|
var _storageMode = "localStorage";
|
|
@@ -1258,10 +1444,12 @@ var auth = {
|
|
|
1258
1444
|
notifySessionChanged();
|
|
1259
1445
|
},
|
|
1260
1446
|
clearTokens() {
|
|
1261
|
-
for (const
|
|
1447
|
+
for (const mode of ["localStorage", "sessionStorage", "cookie"]) {
|
|
1448
|
+
const backend = backendFor(mode);
|
|
1262
1449
|
backend.set(ACCESS_KEY, null);
|
|
1263
1450
|
backend.set(REFRESH_KEY, null);
|
|
1264
1451
|
}
|
|
1452
|
+
storage.clearAll();
|
|
1265
1453
|
notifySessionChanged();
|
|
1266
1454
|
},
|
|
1267
1455
|
/** Session-aware: token PRESENT and not past its `exp` (or a live refresh
|
|
@@ -1453,7 +1641,7 @@ function dpopEnabled() {
|
|
|
1453
1641
|
}
|
|
1454
1642
|
}
|
|
1455
1643
|
__name(dpopEnabled, "dpopEnabled");
|
|
1456
|
-
var _DPOP_DB = "cfg
|
|
1644
|
+
var _DPOP_DB = "cfg.auth.dpop";
|
|
1457
1645
|
var _DPOP_STORE = "keys";
|
|
1458
1646
|
var _DPOP_KEY_ID = "dpop-ec-p256";
|
|
1459
1647
|
function _idbOpen() {
|