@djangocfg/api 2.1.420 → 2.1.422

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 (45) hide show
  1. package/dist/auth-server.cjs +45 -27
  2. package/dist/auth-server.cjs.map +1 -1
  3. package/dist/auth-server.mjs +45 -27
  4. package/dist/auth-server.mjs.map +1 -1
  5. package/dist/auth.cjs +61 -33
  6. package/dist/auth.cjs.map +1 -1
  7. package/dist/auth.d.cts +2 -1
  8. package/dist/auth.d.ts +2 -1
  9. package/dist/auth.mjs +61 -33
  10. package/dist/auth.mjs.map +1 -1
  11. package/dist/clients.cjs +45 -27
  12. package/dist/clients.cjs.map +1 -1
  13. package/dist/clients.d.cts +1 -1
  14. package/dist/clients.d.ts +1 -1
  15. package/dist/clients.mjs +45 -27
  16. package/dist/clients.mjs.map +1 -1
  17. package/dist/hooks.cjs +48 -29
  18. package/dist/hooks.cjs.map +1 -1
  19. package/dist/hooks.mjs +48 -29
  20. package/dist/hooks.mjs.map +1 -1
  21. package/dist/index.cjs +45 -27
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +2 -2
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.mjs +45 -27
  26. package/dist/index.mjs.map +1 -1
  27. package/package.json +2 -2
  28. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRetrieve.ts +12 -3
  29. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthConnectionsList.ts +12 -3
  30. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthProvidersRetrieve.ts +12 -3
  31. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfileRetrieve.ts +12 -3
  32. package/src/_api/generated/_cfg_accounts/openapi.json +9 -0
  33. package/src/_api/generated/_cfg_centrifugo/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +12 -3
  34. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpBackupCodesRetrieve.ts +12 -3
  35. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpDevicesRetrieve.ts +12 -3
  36. package/src/_api/generated/client/client.gen.ts +1 -4
  37. package/src/_api/generated/client/types.gen.ts +3 -2
  38. package/src/_api/generated/client/utils.gen.ts +6 -8
  39. package/src/_api/generated/core/params.gen.ts +4 -4
  40. package/src/_api/generated/helpers/auth.ts +58 -9
  41. package/src/_api/generated/index.ts +6 -0
  42. package/src/_api/generated/openapi.json +9 -0
  43. package/src/_api/generated/sdk.gen.ts +18 -6
  44. package/src/auth/hooks/useAuthForm.ts +5 -4
  45. package/src/auth/hooks/useAutoAuth.ts +23 -4
package/dist/auth.d.cts CHANGED
@@ -500,7 +500,8 @@ declare const validateIdentifier: (id: string) => boolean;
500
500
  declare const useAuthForm: (options: UseAuthFormOptions) => AuthFormReturn;
501
501
 
502
502
  interface UseAutoAuthOptions {
503
- onOTPDetected?: (otp: string) => void;
503
+ /** Called with the OTP from the URL, plus the optional `email` query param if present. */
504
+ onOTPDetected?: (otp: string, email?: string) => void;
504
505
  cleanupUrl?: boolean;
505
506
  /** Paths where auto-auth should be active. Default: ['/auth'] */
506
507
  allowedPaths?: string[];
package/dist/auth.d.ts CHANGED
@@ -500,7 +500,8 @@ declare const validateIdentifier: (id: string) => boolean;
500
500
  declare const useAuthForm: (options: UseAuthFormOptions) => AuthFormReturn;
501
501
 
502
502
  interface UseAutoAuthOptions {
503
- onOTPDetected?: (otp: string) => void;
503
+ /** Called with the OTP from the URL, plus the optional `email` query param if present. */
504
+ onOTPDetected?: (otp: string, email?: string) => void;
504
505
  cleanupUrl?: boolean;
505
506
  /** Paths where auto-auth should be active. Default: ['/auth'] */
506
507
  allowedPaths?: string[];
package/dist/auth.mjs CHANGED
@@ -229,24 +229,35 @@ var authLogger = logger.withTag("auth");
229
229
  // src/auth/hooks/useAutoAuth.ts
230
230
  import { usePathname as usePathname2 } from "next/navigation";
231
231
  import { useEffect as useEffect3 } from "react";
232
+ var normalizePath = /* @__PURE__ */ __name((path) => {
233
+ if (!path) return "";
234
+ const withoutLocale = path.replace(/^\/[a-z]{2}(?=\/|$)/, "");
235
+ const trimmed = withoutLocale.replace(/\/+$/, "");
236
+ return trimmed || "/";
237
+ }, "normalizePath");
232
238
  var useAutoAuth = /* @__PURE__ */ __name((options = {}) => {
233
239
  const { onOTPDetected, cleanupUrl = true, allowedPaths = ["/auth"] } = options;
234
240
  const queryParams = useQueryParams();
235
241
  const pathname = usePathname2();
236
242
  const router = useCfgRouter();
237
- const isAllowedPath = allowedPaths.some((path) => pathname === path || pathname?.startsWith(path + "/"));
243
+ const normalizedPath = normalizePath(pathname);
244
+ const isAllowedPath = allowedPaths.some(
245
+ (path) => normalizedPath === path || normalizedPath.startsWith(path + "/")
246
+ );
238
247
  const hasOTP = !!queryParams.get("otp");
239
248
  const isReady = !!pathname && hasOTP && isAllowedPath;
240
249
  useEffect3(() => {
241
250
  if (!isReady) return;
242
251
  const queryOtp = queryParams.get("otp");
252
+ const queryEmail = queryParams.get("email") || void 0;
243
253
  if (queryOtp && typeof queryOtp === "string" && queryOtp.length === AUTH_CONSTANTS.EMAIL_OTP_LENGTH) {
244
254
  authLogger.info("OTP detected in URL on auth page:", queryOtp);
245
- onOTPDetected?.(queryOtp);
255
+ onOTPDetected?.(queryOtp, queryEmail);
246
256
  }
247
257
  if (cleanupUrl && queryOtp) {
248
258
  const cleanQuery = Object.fromEntries(queryParams.entries());
249
259
  delete cleanQuery.otp;
260
+ delete cleanQuery.email;
250
261
  const queryString = new URLSearchParams(cleanQuery).toString();
251
262
  const realPathname = typeof window !== "undefined" ? window.location.pathname : pathname;
252
263
  router.replace(queryString ? `${realPathname}?${queryString}` : realPathname);
@@ -389,6 +400,18 @@ function detectLocale() {
389
400
  }
390
401
  __name(detectLocale, "detectLocale");
391
402
  function defaultBaseUrl() {
403
+ if (typeof window !== "undefined") {
404
+ try {
405
+ if (typeof process !== "undefined" && process.env) {
406
+ if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
407
+ if (process.env.NEXT_PUBLIC_API_PROXY_URL !== void 0)
408
+ return process.env.NEXT_PUBLIC_API_PROXY_URL;
409
+ return process.env.NEXT_PUBLIC_API_URL || "";
410
+ }
411
+ } catch {
412
+ }
413
+ return "";
414
+ }
392
415
  try {
393
416
  if (typeof process !== "undefined" && process.env) {
394
417
  if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
@@ -400,7 +423,6 @@ function defaultBaseUrl() {
400
423
  }
401
424
  __name(defaultBaseUrl, "defaultBaseUrl");
402
425
  function defaultApiKey() {
403
- if (isBrowser2) return null;
404
426
  try {
405
427
  if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_KEY) {
406
428
  return process.env.NEXT_PUBLIC_API_KEY;
@@ -556,7 +578,7 @@ function installAuthOnClient(client2) {
556
578
  const locale = auth.getLocale();
557
579
  if (locale) request.headers.set("Accept-Language", locale);
558
580
  const apiKey = auth.getApiKey();
559
- if (apiKey) request.headers.set("X-API-Key", apiKey);
581
+ if (apiKey && !request.headers.has("X-API-Key")) request.headers.set("X-API-Key", apiKey);
560
582
  try {
561
583
  const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
562
584
  if (tz) request.headers.set("X-Timezone", tz);
@@ -1195,11 +1217,8 @@ var checkForExistence = /* @__PURE__ */ __name((options, name) => {
1195
1217
  }
1196
1218
  return false;
1197
1219
  }, "checkForExistence");
1198
- var setAuthParams = /* @__PURE__ */ __name(async ({
1199
- security,
1200
- ...options
1201
- }) => {
1202
- for (const auth2 of security) {
1220
+ async function setAuthParams(options) {
1221
+ for (const auth2 of options.security ?? []) {
1203
1222
  if (checkForExistence(options, auth2.name)) {
1204
1223
  continue;
1205
1224
  }
@@ -1224,7 +1243,8 @@ var setAuthParams = /* @__PURE__ */ __name(async ({
1224
1243
  break;
1225
1244
  }
1226
1245
  }
1227
- }, "setAuthParams");
1246
+ }
1247
+ __name(setAuthParams, "setAuthParams");
1228
1248
  var buildUrl = /* @__PURE__ */ __name((options) => getUrl({
1229
1249
  baseUrl: options.baseUrl,
1230
1250
  path: options.path,
@@ -1353,10 +1373,7 @@ var createClient = /* @__PURE__ */ __name((config = {}) => {
1353
1373
  serializedBody: void 0
1354
1374
  };
1355
1375
  if (opts.security) {
1356
- await setAuthParams({
1357
- ...opts,
1358
- security: opts.security
1359
- });
1376
+ await setAuthParams(opts);
1360
1377
  }
1361
1378
  if (opts.requestValidator) {
1362
1379
  await opts.requestValidator(opts);
@@ -1549,11 +1566,15 @@ var CfgAccountsApiKey = class {
1549
1566
  */
1550
1567
  static cfgAccountsApiKeyRetrieve(options) {
1551
1568
  return (options?.client ?? client).get({
1552
- security: [{ scheme: "bearer", type: "http" }, {
1553
- in: "cookie",
1554
- name: "sessionid",
1555
- type: "apiKey"
1556
- }],
1569
+ security: [
1570
+ { scheme: "bearer", type: "http" },
1571
+ {
1572
+ in: "cookie",
1573
+ name: "sessionid",
1574
+ type: "apiKey"
1575
+ },
1576
+ { name: "X-API-Key", type: "apiKey" }
1577
+ ],
1557
1578
  url: "/cfg/accounts/api-key/",
1558
1579
  ...options
1559
1580
  });
@@ -1565,11 +1586,15 @@ var CfgAccountsApiKey = class {
1565
1586
  */
1566
1587
  static cfgAccountsApiKeyRegenerateCreate(options) {
1567
1588
  return (options.client ?? client).post({
1568
- security: [{ scheme: "bearer", type: "http" }, {
1569
- in: "cookie",
1570
- name: "sessionid",
1571
- type: "apiKey"
1572
- }],
1589
+ security: [
1590
+ { scheme: "bearer", type: "http" },
1591
+ {
1592
+ in: "cookie",
1593
+ name: "sessionid",
1594
+ type: "apiKey"
1595
+ },
1596
+ { name: "X-API-Key", type: "apiKey" }
1597
+ ],
1573
1598
  url: "/cfg/accounts/api-key/regenerate/",
1574
1599
  ...options,
1575
1600
  headers: {
@@ -1585,11 +1610,15 @@ var CfgAccountsApiKey = class {
1585
1610
  */
1586
1611
  static cfgAccountsApiKeyTestCreate(options) {
1587
1612
  return (options.client ?? client).post({
1588
- security: [{ scheme: "bearer", type: "http" }, {
1589
- in: "cookie",
1590
- name: "sessionid",
1591
- type: "apiKey"
1592
- }],
1613
+ security: [
1614
+ { scheme: "bearer", type: "http" },
1615
+ {
1616
+ in: "cookie",
1617
+ name: "sessionid",
1618
+ type: "apiKey"
1619
+ },
1620
+ { name: "X-API-Key", type: "apiKey" }
1621
+ ],
1593
1622
  url: "/cfg/accounts/api-key/test/",
1594
1623
  ...options,
1595
1624
  headers: {
@@ -2655,14 +2684,13 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
2655
2684
  }, [setUseBackupCode, setTwoFactorCode, clearError]);
2656
2685
  useAutoAuth({
2657
2686
  allowedPaths: [authPath],
2658
- onOTPDetected: /* @__PURE__ */ __name((detectedOtp) => {
2687
+ onOTPDetected: /* @__PURE__ */ __name((detectedOtp, detectedEmail) => {
2659
2688
  if (isAutoSubmitFromUrlRef.current || isLoading) return;
2660
2689
  isAutoSubmitFromUrlRef.current = true;
2661
2690
  authLogger.info("OTP detected from URL, auto-submitting");
2662
- const savedEmail = getSavedEmail();
2663
- const autoIdentifier = savedEmail || "";
2691
+ const autoIdentifier = detectedEmail || getSavedEmail() || "";
2664
2692
  if (!autoIdentifier) {
2665
- authLogger.warn("No saved identifier found for auto-submit");
2693
+ authLogger.warn("No identifier found for auto-submit (no email in URL or storage)");
2666
2694
  isAutoSubmitFromUrlRef.current = false;
2667
2695
  return;
2668
2696
  }