@djangocfg/api 2.1.482 → 2.1.483

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 +64 -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 +64 -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 +1 -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
@@ -723,6 +723,10 @@ type OAuthCallbackRequestRequest = {
723
723
  * Same redirect_uri used in authorize request. If not provided, uses config's site_url + callback_path
724
724
  */
725
725
  redirect_uri?: string;
726
+ /**
727
+ * Keep this browser signed in for 30 days
728
+ */
729
+ remember_me?: boolean;
726
730
  };
727
731
  /**
728
732
  * Serializer for OAuth connection info (user-facing).
@@ -846,6 +850,10 @@ type OAuthTokenResponse = {
846
850
  * True if user should be prompted to enable 2FA
847
851
  */
848
852
  should_prompt_2fa?: boolean;
853
+ /**
854
+ * Whether this login should persist across browser restarts
855
+ */
856
+ persistent_session?: boolean;
849
857
  };
850
858
  /**
851
859
  * Typed error response for OTP operations.
@@ -921,6 +929,10 @@ type OtpVerifyRequest = {
921
929
  * Source URL for tracking login (e.g., https://my.djangocfg.com)
922
930
  */
923
931
  source_url?: string;
932
+ /**
933
+ * Keep this browser signed in for 30 days
934
+ */
935
+ remember_me?: boolean;
924
936
  };
925
937
  /**
926
938
  * OTP verification response.
@@ -960,6 +972,10 @@ type OtpVerifyResponse = {
960
972
  * Whether user should be prompted to enable 2FA
961
973
  */
962
974
  should_prompt_2fa?: boolean;
975
+ /**
976
+ * Whether this login should persist across browser restarts
977
+ */
978
+ persistent_session?: boolean;
963
979
  };
964
980
  /**
965
981
  * Serializer for updating user profile.
@@ -1150,6 +1166,10 @@ type VerifyResponse = {
1150
1166
  * User profile data
1151
1167
  */
1152
1168
  user: TotpVerifyUser;
1169
+ /**
1170
+ * Whether this login should persist across browser restarts
1171
+ */
1172
+ persistent_session: boolean;
1153
1173
  /**
1154
1174
  * Number of remaining backup codes (if backup code was used)
1155
1175
  */
@@ -1807,7 +1827,7 @@ declare class CfgAccountsOauth {
1807
1827
  */
1808
1828
  static cfgAccountsOauthProvidersRetrieve<ThrowOnError extends boolean = false>(options?: Options<CfgAccountsOauthProvidersRetrieveData, ThrowOnError>): RequestResult<CfgAccountsOauthProvidersRetrieveResponses, unknown, ThrowOnError>;
1809
1829
  }
1810
- declare class CfgAccounts {
1830
+ declare class CfgAccountsOtp {
1811
1831
  /**
1812
1832
  * Marketing-consent checkbox policy for the caller's jurisdiction.
1813
1833
  *
@@ -1998,7 +2018,7 @@ declare class API$2 {
1998
2018
  readonly logger: APILogger;
1999
2019
  readonly cfgAccountsApiKey: typeof CfgAccountsApiKey;
2000
2020
  readonly cfgAccountsOauth: typeof CfgAccountsOauth;
2001
- readonly cfgAccounts: typeof CfgAccounts;
2021
+ readonly cfgAccountsOtp: typeof CfgAccountsOtp;
2002
2022
  readonly cfgAccountsProfile: typeof CfgAccountsProfile;
2003
2023
  readonly cfgAccountsAuth: typeof CfgAccountsAuth;
2004
2024
  constructor(_baseUrl?: string, opts?: APIOptions$2);
package/dist/clients.d.ts CHANGED
@@ -723,6 +723,10 @@ type OAuthCallbackRequestRequest = {
723
723
  * Same redirect_uri used in authorize request. If not provided, uses config's site_url + callback_path
724
724
  */
725
725
  redirect_uri?: string;
726
+ /**
727
+ * Keep this browser signed in for 30 days
728
+ */
729
+ remember_me?: boolean;
726
730
  };
727
731
  /**
728
732
  * Serializer for OAuth connection info (user-facing).
@@ -846,6 +850,10 @@ type OAuthTokenResponse = {
846
850
  * True if user should be prompted to enable 2FA
847
851
  */
848
852
  should_prompt_2fa?: boolean;
853
+ /**
854
+ * Whether this login should persist across browser restarts
855
+ */
856
+ persistent_session?: boolean;
849
857
  };
850
858
  /**
851
859
  * Typed error response for OTP operations.
@@ -921,6 +929,10 @@ type OtpVerifyRequest = {
921
929
  * Source URL for tracking login (e.g., https://my.djangocfg.com)
922
930
  */
923
931
  source_url?: string;
932
+ /**
933
+ * Keep this browser signed in for 30 days
934
+ */
935
+ remember_me?: boolean;
924
936
  };
925
937
  /**
926
938
  * OTP verification response.
@@ -960,6 +972,10 @@ type OtpVerifyResponse = {
960
972
  * Whether user should be prompted to enable 2FA
961
973
  */
962
974
  should_prompt_2fa?: boolean;
975
+ /**
976
+ * Whether this login should persist across browser restarts
977
+ */
978
+ persistent_session?: boolean;
963
979
  };
964
980
  /**
965
981
  * Serializer for updating user profile.
@@ -1150,6 +1166,10 @@ type VerifyResponse = {
1150
1166
  * User profile data
1151
1167
  */
1152
1168
  user: TotpVerifyUser;
1169
+ /**
1170
+ * Whether this login should persist across browser restarts
1171
+ */
1172
+ persistent_session: boolean;
1153
1173
  /**
1154
1174
  * Number of remaining backup codes (if backup code was used)
1155
1175
  */
@@ -1807,7 +1827,7 @@ declare class CfgAccountsOauth {
1807
1827
  */
1808
1828
  static cfgAccountsOauthProvidersRetrieve<ThrowOnError extends boolean = false>(options?: Options<CfgAccountsOauthProvidersRetrieveData, ThrowOnError>): RequestResult<CfgAccountsOauthProvidersRetrieveResponses, unknown, ThrowOnError>;
1809
1829
  }
1810
- declare class CfgAccounts {
1830
+ declare class CfgAccountsOtp {
1811
1831
  /**
1812
1832
  * Marketing-consent checkbox policy for the caller's jurisdiction.
1813
1833
  *
@@ -1998,7 +2018,7 @@ declare class API$2 {
1998
2018
  readonly logger: APILogger;
1999
2019
  readonly cfgAccountsApiKey: typeof CfgAccountsApiKey;
2000
2020
  readonly cfgAccountsOauth: typeof CfgAccountsOauth;
2001
- readonly cfgAccounts: typeof CfgAccounts;
2021
+ readonly cfgAccountsOtp: typeof CfgAccountsOtp;
2002
2022
  readonly cfgAccountsProfile: typeof CfgAccountsProfile;
2003
2023
  readonly cfgAccountsAuth: typeof CfgAccountsAuth;
2004
2024
  constructor(_baseUrl?: string, opts?: APIOptions$2);
package/dist/clients.mjs CHANGED
@@ -89,6 +89,24 @@ var localStorageBackend = {
89
89
  }
90
90
  }
91
91
  };
92
+ var sessionStorageBackend = {
93
+ get(key) {
94
+ if (!isBrowser) return null;
95
+ try {
96
+ return window.sessionStorage.getItem(key);
97
+ } catch {
98
+ return null;
99
+ }
100
+ },
101
+ set(key, value) {
102
+ if (!isBrowser) return;
103
+ try {
104
+ if (value === null) window.sessionStorage.removeItem(key);
105
+ else window.sessionStorage.setItem(key, value);
106
+ } catch {
107
+ }
108
+ }
109
+ };
92
110
  var COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
93
111
  var cookieBackend = {
94
112
  get(key) {
@@ -96,7 +114,8 @@ var cookieBackend = {
96
114
  try {
97
115
  const re = new RegExp(`(?:^|;\\s*)${encodeURIComponent(key)}=([^;]*)`);
98
116
  const m = document.cookie.match(re);
99
- return m ? decodeURIComponent(m[1]) : null;
117
+ const value = m?.[1];
118
+ return value === void 0 ? null : decodeURIComponent(value);
100
119
  } catch {
101
120
  return null;
102
121
  }
@@ -122,7 +141,8 @@ function detectLocale() {
122
141
  try {
123
142
  if (typeof document !== "undefined") {
124
143
  const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
125
- if (m) return decodeURIComponent(m[1]);
144
+ const locale = m?.[1];
145
+ if (locale !== void 0) return decodeURIComponent(locale);
126
146
  }
127
147
  if (typeof navigator !== "undefined" && navigator.language) {
128
148
  return navigator.language;
@@ -272,7 +292,7 @@ var auth = {
272
292
  },
273
293
  setStorageMode(mode) {
274
294
  _storageMode = mode;
275
- _storage = mode === "cookie" ? cookieBackend : localStorageBackend;
295
+ _storage = mode === "cookie" ? cookieBackend : mode === "sessionStorage" ? sessionStorageBackend : localStorageBackend;
276
296
  notifySessionChanged();
277
297
  },
278
298
  // ── Bearer token ──────────────────────────────────────────────────
@@ -536,7 +556,7 @@ __name(_getDpopKeyPair, "_getDpopKeyPair");
536
556
  function _b64urlFromBytes(bytes) {
537
557
  const arr = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
538
558
  let s = "";
539
- for (let i = 0; i < arr.length; i++) s += String.fromCharCode(arr[i]);
559
+ for (let i = 0; i < arr.length; i++) s += String.fromCharCode(arr[i] ?? 0);
540
560
  return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
541
561
  }
542
562
  __name(_b64urlFromBytes, "_b64urlFromBytes");
@@ -554,7 +574,8 @@ async function _makeDpopProof(method, url) {
554
574
  const pair = await _getDpopKeyPair();
555
575
  const jwk = await _publicJwk(pair.publicKey);
556
576
  const header = { typ: "dpop+jwt", alg: "ES256", jwk };
557
- const htu = url.split("#")[0].split("?")[0];
577
+ const withoutFragment = url.split("#")[0] ?? url;
578
+ const htu = withoutFragment.split("?")[0] ?? withoutFragment;
558
579
  const jti = crypto.randomUUID && crypto.randomUUID() || _b64urlFromBytes(crypto.getRandomValues(new Uint8Array(16)));
559
580
  const payload = { htm: method.toUpperCase(), htu, iat: Math.floor(Date.now() / 1e3), jti };
560
581
  const signingInput = `${_b64urlFromString(JSON.stringify(header))}.${_b64urlFromString(JSON.stringify(payload))}`;
@@ -1744,9 +1765,9 @@ var CfgAccountsOauth = class {
1744
1765
  return (options?.client ?? client).get({ url: "/cfg/accounts/oauth/providers/", ...options });
1745
1766
  }
1746
1767
  };
1747
- var CfgAccounts = class {
1768
+ var CfgAccountsOtp = class {
1748
1769
  static {
1749
- __name(this, "CfgAccounts");
1770
+ __name(this, "CfgAccountsOtp");
1750
1771
  }
1751
1772
  /**
1752
1773
  * Marketing-consent checkbox policy for the caller's jurisdiction.
@@ -2214,7 +2235,7 @@ var API = class {
2214
2235
  logger;
2215
2236
  cfgAccountsApiKey = CfgAccountsApiKey;
2216
2237
  cfgAccountsOauth = CfgAccountsOauth;
2217
- cfgAccounts = CfgAccounts;
2238
+ cfgAccountsOtp = CfgAccountsOtp;
2218
2239
  cfgAccountsProfile = CfgAccountsProfile;
2219
2240
  cfgAccountsAuth = CfgAccountsAuth;
2220
2241
  constructor(_baseUrl, opts = {}) {