@djangocfg/api 2.1.56 → 2.1.58

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 (75) hide show
  1. package/README.md +125 -9
  2. package/dist/auth.cjs +1865 -402
  3. package/dist/auth.cjs.map +1 -1
  4. package/dist/auth.d.cts +352 -76
  5. package/dist/auth.d.ts +352 -76
  6. package/dist/auth.mjs +1867 -404
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/clients.cjs +1637 -137
  9. package/dist/clients.cjs.map +1 -1
  10. package/dist/clients.d.cts +1394 -282
  11. package/dist/clients.d.ts +1394 -282
  12. package/dist/clients.mjs +1637 -137
  13. package/dist/clients.mjs.map +1 -1
  14. package/dist/hooks.cjs +24 -11
  15. package/dist/hooks.cjs.map +1 -1
  16. package/dist/hooks.d.cts +88 -21
  17. package/dist/hooks.d.ts +88 -21
  18. package/dist/hooks.mjs +24 -11
  19. package/dist/hooks.mjs.map +1 -1
  20. package/dist/index.cjs +38 -17
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +94 -21
  23. package/dist/index.d.ts +94 -21
  24. package/dist/index.mjs +38 -17
  25. package/dist/index.mjs.map +1 -1
  26. package/package.json +3 -3
  27. package/src/auth/context/AccountsContext.tsx +8 -1
  28. package/src/auth/context/AuthContext.tsx +31 -8
  29. package/src/auth/context/types.ts +8 -1
  30. package/src/auth/hooks/index.ts +29 -5
  31. package/src/auth/hooks/useAuthForm.ts +292 -226
  32. package/src/auth/hooks/useAuthFormState.ts +60 -0
  33. package/src/auth/hooks/useAuthValidation.ts +77 -0
  34. package/src/auth/hooks/useGithubAuth.ts +26 -5
  35. package/src/auth/hooks/useTwoFactor.ts +239 -0
  36. package/src/auth/hooks/useTwoFactorSetup.ts +213 -0
  37. package/src/auth/index.ts +3 -0
  38. package/src/auth/types/form.ts +194 -0
  39. package/src/auth/types/index.ts +28 -0
  40. package/src/clients.ts +10 -0
  41. package/src/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts +26 -3
  42. package/src/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts +26 -3
  43. package/src/generated/cfg_accounts/accounts/client.ts +4 -1
  44. package/src/generated/cfg_accounts/accounts/models.ts +15 -6
  45. package/src/generated/cfg_accounts/accounts__oauth/models.ts +16 -7
  46. package/src/generated/cfg_accounts/client.ts +5 -2
  47. package/src/generated/cfg_accounts/http.ts +8 -2
  48. package/src/generated/cfg_accounts/schema.json +47 -19
  49. package/src/generated/cfg_centrifugo/client.ts +5 -2
  50. package/src/generated/cfg_centrifugo/http.ts +8 -2
  51. package/src/generated/cfg_totp/CLAUDE.md +12 -12
  52. package/src/generated/cfg_totp/_utils/fetchers/index.ts +3 -3
  53. package/src/generated/cfg_totp/_utils/fetchers/{totp__2fa_management.ts → totp__totp_management.ts} +3 -3
  54. package/src/generated/cfg_totp/_utils/fetchers/{totp__2fa_setup.ts → totp__totp_setup.ts} +3 -3
  55. package/src/generated/cfg_totp/_utils/fetchers/{totp__2fa_verification.ts → totp__totp_verification.ts} +3 -3
  56. package/src/generated/cfg_totp/_utils/hooks/index.ts +3 -3
  57. package/src/generated/cfg_totp/_utils/hooks/{totp__2fa_management.ts → totp__totp_management.ts} +2 -2
  58. package/src/generated/cfg_totp/_utils/hooks/{totp__2fa_setup.ts → totp__totp_setup.ts} +2 -2
  59. package/src/generated/cfg_totp/_utils/hooks/{totp__2fa_verification.ts → totp__totp_verification.ts} +2 -2
  60. package/src/generated/cfg_totp/_utils/schemas/DeviceList.schema.ts +1 -1
  61. package/src/generated/cfg_totp/client.ts +14 -11
  62. package/src/generated/cfg_totp/http.ts +8 -2
  63. package/src/generated/cfg_totp/index.ts +16 -16
  64. package/src/generated/cfg_totp/schema.json +8 -7
  65. package/src/generated/cfg_totp/{totp__2fa_management → totp__totp_management}/client.ts +2 -2
  66. package/src/generated/cfg_totp/{totp__2fa_management → totp__totp_management}/models.ts +1 -1
  67. package/src/generated/cfg_totp/{totp__2fa_setup → totp__totp_setup}/client.ts +4 -4
  68. package/src/generated/cfg_totp/{totp__2fa_verification → totp__totp_verification}/client.ts +2 -2
  69. package/src/generated/cfg_webpush/client.ts +5 -2
  70. package/src/generated/cfg_webpush/http.ts +8 -2
  71. /package/src/generated/cfg_totp/{totp__2fa_management → totp__totp_management}/index.ts +0 -0
  72. /package/src/generated/cfg_totp/{totp__2fa_setup → totp__totp_setup}/index.ts +0 -0
  73. /package/src/generated/cfg_totp/{totp__2fa_setup → totp__totp_setup}/models.ts +0 -0
  74. /package/src/generated/cfg_totp/{totp__2fa_verification → totp__totp_verification}/index.ts +0 -0
  75. /package/src/generated/cfg_totp/{totp__2fa_verification → totp__totp_verification}/models.ts +0 -0
package/dist/index.cjs CHANGED
@@ -337,7 +337,10 @@ var Accounts = class {
337
337
  return response;
338
338
  }
339
339
  /**
340
- * Verify OTP code and return JWT tokens.
340
+ * Verify OTP code and return JWT tokens or 2FA session. If user has 2FA
341
+ * enabled: - Returns requires_2fa=True with session_id - Client must
342
+ * complete 2FA verification at /cfg/totp/verify/ If user has no 2FA: -
343
+ * Returns JWT tokens and user data directly
341
344
  */
342
345
  async otpVerifyCreate(data) {
343
346
  const response = await this.client.request("POST", "/cfg/accounts/otp/verify/", { body: data });
@@ -354,7 +357,7 @@ var FetchAdapter = class {
354
357
  __name(this, "FetchAdapter");
355
358
  }
356
359
  async request(request) {
357
- const { method, url, headers, body, params, formData } = request;
360
+ const { method, url, headers, body, params, formData, binaryBody } = request;
358
361
  let finalUrl = url;
359
362
  if (params) {
360
363
  const searchParams = new URLSearchParams();
@@ -372,6 +375,9 @@ var FetchAdapter = class {
372
375
  let requestBody;
373
376
  if (formData) {
374
377
  requestBody = formData;
378
+ } else if (binaryBody) {
379
+ finalHeaders["Content-Type"] = "application/octet-stream";
380
+ requestBody = binaryBody;
375
381
  } else if (body) {
376
382
  finalHeaders["Content-Type"] = "application/json";
377
383
  requestBody = JSON.stringify(body);
@@ -771,7 +777,7 @@ var APIClient = class {
771
777
  const headers = {
772
778
  ...options?.headers || {}
773
779
  };
774
- if (!options?.formData && !headers["Content-Type"]) {
780
+ if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
775
781
  headers["Content-Type"] = "application/json";
776
782
  }
777
783
  if (this.logger) {
@@ -790,7 +796,8 @@ var APIClient = class {
790
796
  headers,
791
797
  params: options?.params,
792
798
  body: options?.body,
793
- formData: options?.formData
799
+ formData: options?.formData,
800
+ binaryBody: options?.binaryBody
794
801
  });
795
802
  const duration = Date.now() - startTime;
796
803
  if (response.status >= 400) {
@@ -1141,11 +1148,14 @@ var OAuthProvidersResponseSchema = import_zod8.z.object({
1141
1148
  // src/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts
1142
1149
  var import_zod9 = require("zod");
1143
1150
  var OAuthTokenResponseSchema = import_zod9.z.object({
1144
- access: import_zod9.z.string(),
1145
- refresh: import_zod9.z.string(),
1146
- user: import_zod9.z.record(import_zod9.z.string(), import_zod9.z.any()),
1151
+ requires_2fa: import_zod9.z.boolean().optional(),
1152
+ session_id: import_zod9.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable().optional(),
1153
+ access: import_zod9.z.string().nullable().optional(),
1154
+ refresh: import_zod9.z.string().nullable().optional(),
1155
+ user: import_zod9.z.record(import_zod9.z.string(), import_zod9.z.any()).nullable().optional(),
1147
1156
  is_new_user: import_zod9.z.boolean(),
1148
- is_new_connection: import_zod9.z.boolean()
1157
+ is_new_connection: import_zod9.z.boolean(),
1158
+ should_prompt_2fa: import_zod9.z.boolean().optional()
1149
1159
  });
1150
1160
 
1151
1161
  // src/generated/cfg_accounts/_utils/schemas/OTPErrorResponse.schema.ts
@@ -1204,9 +1214,12 @@ var UserSchema = import_zod14.z.object({
1204
1214
 
1205
1215
  // src/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts
1206
1216
  var OTPVerifyResponseSchema = import_zod15.z.object({
1207
- refresh: import_zod15.z.string(),
1208
- access: import_zod15.z.string(),
1209
- user: UserSchema
1217
+ requires_2fa: import_zod15.z.boolean().optional(),
1218
+ session_id: import_zod15.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable().optional(),
1219
+ refresh: import_zod15.z.string().nullable().optional(),
1220
+ access: import_zod15.z.string().nullable().optional(),
1221
+ user: UserSchema.nullable().optional(),
1222
+ should_prompt_2fa: import_zod15.z.boolean().optional()
1210
1223
  });
1211
1224
 
1212
1225
  // src/generated/cfg_accounts/_utils/schemas/PatchedUserProfileUpdateRequest.schema.ts
@@ -2257,7 +2270,7 @@ var FetchAdapter2 = class {
2257
2270
  __name(this, "FetchAdapter");
2258
2271
  }
2259
2272
  async request(request) {
2260
- const { method, url, headers, body, params, formData } = request;
2273
+ const { method, url, headers, body, params, formData, binaryBody } = request;
2261
2274
  let finalUrl = url;
2262
2275
  if (params) {
2263
2276
  const searchParams = new URLSearchParams();
@@ -2275,6 +2288,9 @@ var FetchAdapter2 = class {
2275
2288
  let requestBody;
2276
2289
  if (formData) {
2277
2290
  requestBody = formData;
2291
+ } else if (binaryBody) {
2292
+ finalHeaders["Content-Type"] = "application/octet-stream";
2293
+ requestBody = binaryBody;
2278
2294
  } else if (body) {
2279
2295
  finalHeaders["Content-Type"] = "application/json";
2280
2296
  requestBody = JSON.stringify(body);
@@ -2674,7 +2690,7 @@ var APIClient2 = class {
2674
2690
  const headers = {
2675
2691
  ...options?.headers || {}
2676
2692
  };
2677
- if (!options?.formData && !headers["Content-Type"]) {
2693
+ if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
2678
2694
  headers["Content-Type"] = "application/json";
2679
2695
  }
2680
2696
  if (this.logger) {
@@ -2693,7 +2709,8 @@ var APIClient2 = class {
2693
2709
  headers,
2694
2710
  params: options?.params,
2695
2711
  body: options?.body,
2696
- formData: options?.formData
2712
+ formData: options?.formData,
2713
+ binaryBody: options?.binaryBody
2697
2714
  });
2698
2715
  const duration = Date.now() - startTime;
2699
2716
  if (response.status >= 400) {
@@ -3465,7 +3482,7 @@ var FetchAdapter3 = class {
3465
3482
  __name(this, "FetchAdapter");
3466
3483
  }
3467
3484
  async request(request) {
3468
- const { method, url, headers, body, params, formData } = request;
3485
+ const { method, url, headers, body, params, formData, binaryBody } = request;
3469
3486
  let finalUrl = url;
3470
3487
  if (params) {
3471
3488
  const searchParams = new URLSearchParams();
@@ -3483,6 +3500,9 @@ var FetchAdapter3 = class {
3483
3500
  let requestBody;
3484
3501
  if (formData) {
3485
3502
  requestBody = formData;
3503
+ } else if (binaryBody) {
3504
+ finalHeaders["Content-Type"] = "application/octet-stream";
3505
+ requestBody = binaryBody;
3486
3506
  } else if (body) {
3487
3507
  finalHeaders["Content-Type"] = "application/json";
3488
3508
  requestBody = JSON.stringify(body);
@@ -3879,7 +3899,7 @@ var APIClient3 = class {
3879
3899
  const headers = {
3880
3900
  ...options?.headers || {}
3881
3901
  };
3882
- if (!options?.formData && !headers["Content-Type"]) {
3902
+ if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
3883
3903
  headers["Content-Type"] = "application/json";
3884
3904
  }
3885
3905
  if (this.logger) {
@@ -3898,7 +3918,8 @@ var APIClient3 = class {
3898
3918
  headers,
3899
3919
  params: options?.params,
3900
3920
  body: options?.body,
3901
- formData: options?.formData
3921
+ formData: options?.formData,
3922
+ binaryBody: options?.binaryBody
3902
3923
  });
3903
3924
  const duration = Date.now() - startTime;
3904
3925
  if (response.status >= 400) {