@djangocfg/api 2.1.482 → 2.1.484

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 (51) hide show
  1. package/README.md +1 -1
  2. package/dist/auth.cjs +79 -25
  3. package/dist/auth.cjs.map +1 -1
  4. package/dist/auth.d.cts +14 -1
  5. package/dist/auth.d.ts +14 -1
  6. package/dist/auth.mjs +79 -25
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/clients.cjs +29 -8
  9. package/dist/clients.cjs.map +1 -1
  10. package/dist/clients.d.cts +22 -2
  11. package/dist/clients.d.ts +22 -2
  12. package/dist/clients.mjs +29 -8
  13. package/dist/clients.mjs.map +1 -1
  14. package/dist/hooks.cjs +29 -8
  15. package/dist/hooks.cjs.map +1 -1
  16. package/dist/hooks.mjs +29 -8
  17. package/dist/hooks.mjs.map +1 -1
  18. package/dist/index.cjs +31 -9
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +32 -4
  21. package/dist/index.d.ts +32 -4
  22. package/dist/index.mjs +31 -9
  23. package/dist/index.mjs.map +1 -1
  24. package/package.json +2 -2
  25. package/src/_api/generated/_cfg_accounts/api.ts +3 -3
  26. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOtpConsentPolicyRetrieve.ts +2 -2
  27. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOtpRequestCreate.ts +2 -2
  28. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOtpVerifyCreate.ts +2 -2
  29. package/src/_api/generated/_cfg_accounts/index.ts +1 -1
  30. package/src/_api/generated/_cfg_accounts/openapi.json +21 -43
  31. package/src/_api/generated/_cfg_accounts/schemas/OAuthCallbackRequestRequest.ts +1 -0
  32. package/src/_api/generated/_cfg_accounts/schemas/OAuthTokenResponse.ts +1 -0
  33. package/src/_api/generated/_cfg_accounts/schemas/OTPVerifyRequest.ts +1 -0
  34. package/src/_api/generated/_cfg_accounts/schemas/OTPVerifyResponse.ts +1 -0
  35. package/src/_api/generated/_cfg_totp/openapi.json +5 -0
  36. package/src/_api/generated/_cfg_totp/schemas/VerifyResponse.ts +1 -0
  37. package/src/_api/generated/helpers/auth.ts +27 -6
  38. package/src/_api/generated/index.ts +1 -1
  39. package/src/_api/generated/openapi.json +26 -43
  40. package/src/_api/generated/sdk.gen.ts +1 -1
  41. package/src/_api/generated/types.gen.ts +28 -0
  42. package/src/auth/context/AccountsContext.tsx +29 -0
  43. package/src/auth/context/AuthContext.tsx +3 -2
  44. package/src/auth/context/types.ts +1 -1
  45. package/src/auth/hooks/useAuthForm.ts +3 -2
  46. package/src/auth/hooks/useAuthFormState.ts +3 -0
  47. package/src/auth/hooks/useAuthRedirect.ts +2 -2
  48. package/src/auth/hooks/useGithubAuth.ts +34 -21
  49. package/src/auth/hooks/useTwoFactorVerify.ts +5 -3
  50. package/src/auth/types/form.ts +3 -1
  51. package/src/index.ts +5 -1
package/dist/index.cjs CHANGED
@@ -22,12 +22,13 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  APIError: () => APIError,
24
24
  APILogger: () => APILogger,
25
- CfgAccounts: () => CfgAccounts,
25
+ CfgAccounts: () => CfgAccountsOtp,
26
26
  CfgAccountsAPI: () => API,
27
27
  CfgAccountsApi: () => CfgAccountsApi,
28
28
  CfgAccountsApiKey: () => CfgAccountsApiKey,
29
29
  CfgAccountsAuth: () => CfgAccountsAuth,
30
30
  CfgAccountsOauth: () => CfgAccountsOauth,
31
+ CfgAccountsOtp: () => CfgAccountsOtp,
31
32
  CfgAccountsProfile: () => CfgAccountsProfile,
32
33
  CfgCentrifugo: () => CfgCentrifugo,
33
34
  CfgCentrifugoAPI: () => API2,
@@ -160,6 +161,24 @@ var localStorageBackend = {
160
161
  }
161
162
  }
162
163
  };
164
+ var sessionStorageBackend = {
165
+ get(key) {
166
+ if (!isBrowser) return null;
167
+ try {
168
+ return window.sessionStorage.getItem(key);
169
+ } catch {
170
+ return null;
171
+ }
172
+ },
173
+ set(key, value) {
174
+ if (!isBrowser) return;
175
+ try {
176
+ if (value === null) window.sessionStorage.removeItem(key);
177
+ else window.sessionStorage.setItem(key, value);
178
+ } catch {
179
+ }
180
+ }
181
+ };
163
182
  var COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
164
183
  var cookieBackend = {
165
184
  get(key) {
@@ -167,7 +186,8 @@ var cookieBackend = {
167
186
  try {
168
187
  const re = new RegExp(`(?:^|;\\s*)${encodeURIComponent(key)}=([^;]*)`);
169
188
  const m = document.cookie.match(re);
170
- return m ? decodeURIComponent(m[1]) : null;
189
+ const value = m?.[1];
190
+ return value === void 0 ? null : decodeURIComponent(value);
171
191
  } catch {
172
192
  return null;
173
193
  }
@@ -193,7 +213,8 @@ function detectLocale() {
193
213
  try {
194
214
  if (typeof document !== "undefined") {
195
215
  const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
196
- if (m) return decodeURIComponent(m[1]);
216
+ const locale = m?.[1];
217
+ if (locale !== void 0) return decodeURIComponent(locale);
197
218
  }
198
219
  if (typeof navigator !== "undefined" && navigator.language) {
199
220
  return navigator.language;
@@ -343,7 +364,7 @@ var auth = {
343
364
  },
344
365
  setStorageMode(mode) {
345
366
  _storageMode = mode;
346
- _storage = mode === "cookie" ? cookieBackend : localStorageBackend;
367
+ _storage = mode === "cookie" ? cookieBackend : mode === "sessionStorage" ? sessionStorageBackend : localStorageBackend;
347
368
  notifySessionChanged();
348
369
  },
349
370
  // ── Bearer token ──────────────────────────────────────────────────
@@ -607,7 +628,7 @@ __name(_getDpopKeyPair, "_getDpopKeyPair");
607
628
  function _b64urlFromBytes(bytes) {
608
629
  const arr = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
609
630
  let s = "";
610
- for (let i = 0; i < arr.length; i++) s += String.fromCharCode(arr[i]);
631
+ for (let i = 0; i < arr.length; i++) s += String.fromCharCode(arr[i] ?? 0);
611
632
  return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
612
633
  }
613
634
  __name(_b64urlFromBytes, "_b64urlFromBytes");
@@ -625,7 +646,8 @@ async function _makeDpopProof(method, url) {
625
646
  const pair = await _getDpopKeyPair();
626
647
  const jwk = await _publicJwk(pair.publicKey);
627
648
  const header = { typ: "dpop+jwt", alg: "ES256", jwk };
628
- const htu = url.split("#")[0].split("?")[0];
649
+ const withoutFragment = url.split("#")[0] ?? url;
650
+ const htu = withoutFragment.split("?")[0] ?? withoutFragment;
629
651
  const jti = crypto.randomUUID && crypto.randomUUID() || _b64urlFromBytes(crypto.getRandomValues(new Uint8Array(16)));
630
652
  const payload = { htm: method.toUpperCase(), htu, iat: Math.floor(Date.now() / 1e3), jti };
631
653
  const signingInput = `${_b64urlFromString(JSON.stringify(header))}.${_b64urlFromString(JSON.stringify(payload))}`;
@@ -1815,9 +1837,9 @@ var CfgAccountsOauth = class {
1815
1837
  return (options?.client ?? client).get({ url: "/cfg/accounts/oauth/providers/", ...options });
1816
1838
  }
1817
1839
  };
1818
- var CfgAccounts = class {
1840
+ var CfgAccountsOtp = class {
1819
1841
  static {
1820
- __name(this, "CfgAccounts");
1842
+ __name(this, "CfgAccountsOtp");
1821
1843
  }
1822
1844
  /**
1823
1845
  * Marketing-consent checkbox policy for the caller's jurisdiction.
@@ -2285,7 +2307,7 @@ var API = class {
2285
2307
  logger;
2286
2308
  cfgAccountsApiKey = CfgAccountsApiKey;
2287
2309
  cfgAccountsOauth = CfgAccountsOauth;
2288
- cfgAccounts = CfgAccounts;
2310
+ cfgAccountsOtp = CfgAccountsOtp;
2289
2311
  cfgAccountsProfile = CfgAccountsProfile;
2290
2312
  cfgAccountsAuth = CfgAccountsAuth;
2291
2313
  constructor(_baseUrl, opts = {}) {