@djangocfg/api 2.1.541 → 2.1.543

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 (67) hide show
  1. package/README.md +1 -2
  2. package/dist/auth-server.cjs +1 -0
  3. package/dist/auth-server.cjs.map +1 -1
  4. package/dist/auth.cjs +156 -170
  5. package/dist/auth.cjs.map +1 -1
  6. package/dist/auth.d.cts +134 -29
  7. package/dist/auth.d.ts +134 -29
  8. package/dist/auth.mjs +168 -183
  9. package/dist/auth.mjs.map +1 -1
  10. package/dist/clients.cjs +4 -99
  11. package/dist/clients.cjs.map +1 -1
  12. package/dist/clients.d.cts +4 -136
  13. package/dist/clients.d.ts +4 -136
  14. package/dist/clients.mjs +3 -99
  15. package/dist/clients.mjs.map +1 -1
  16. package/dist/hooks.cjs +1 -0
  17. package/dist/hooks.cjs.map +1 -1
  18. package/dist/hooks.d.cts +2 -4
  19. package/dist/hooks.d.ts +2 -4
  20. package/dist/hooks.mjs.map +1 -1
  21. package/dist/index.cjs +4 -100
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +10 -340
  24. package/dist/index.d.ts +10 -340
  25. package/dist/index.mjs +3 -100
  26. package/dist/index.mjs.map +1 -1
  27. package/package.json +5 -4
  28. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRetrieve.ts +8 -2
  29. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthConnectionsList.ts +8 -2
  30. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthProvidersRetrieve.ts +8 -2
  31. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOtpConsentPolicyRetrieve.ts +8 -2
  32. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfileRetrieve.ts +8 -2
  33. package/src/_api/generated/_cfg_accounts/openapi.json +0 -45
  34. package/src/_api/generated/_cfg_accounts/schemas/User.ts +0 -2
  35. package/src/_api/generated/_cfg_accounts/schemas/index.ts +0 -1
  36. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpBackupCodesRetrieve.ts +8 -2
  37. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpDevicesRetrieve.ts +8 -2
  38. package/src/_api/generated/index.ts +1 -5
  39. package/src/_api/generated/openapi.json +0 -135
  40. package/src/_api/generated/sdk.gen.ts +1 -20
  41. package/src/_api/generated/types.gen.ts +0 -79
  42. package/src/_api/index.ts +1 -1
  43. package/src/auth/__tests__/useTwoFactorStatus.test.ts +2 -2
  44. package/src/auth/context/AccountsContext.tsx +15 -11
  45. package/src/auth/hooks/useAuthForm.ts +0 -1
  46. package/src/auth/hooks/useCfgRouter.ts +1 -4
  47. package/src/auth/hooks/useGithubAuth.ts +25 -3
  48. package/src/auth/hooks/useLocalStorage.ts +7 -30
  49. package/src/auth/hooks/useSessionStorage.ts +6 -29
  50. package/src/auth/hooks/useTwoFactorVerify.ts +5 -9
  51. package/src/auth/utils/analytics.ts +22 -2
  52. package/src/auth/utils/errors.ts +22 -11
  53. package/src/auth/utils/storage.ts +64 -0
  54. package/src/clients.ts +2 -4
  55. package/src/index.ts +0 -2
  56. package/src/log-control.ts +1 -1
  57. package/src/server.ts +0 -4
  58. package/src/_api/generated/_cfg_accounts/schemas/CentrifugoToken.ts +0 -14
  59. package/src/_api/generated/_cfg_centrifugo/api.ts +0 -87
  60. package/src/_api/generated/_cfg_centrifugo/hooks/index.ts +0 -4
  61. package/src/_api/generated/_cfg_centrifugo/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +0 -74
  62. package/src/_api/generated/_cfg_centrifugo/index.ts +0 -29
  63. package/src/_api/generated/_cfg_centrifugo/openapi.json +0 -136
  64. package/src/_api/generated/_cfg_centrifugo/schemas/ConnectionTokenResponse.ts +0 -14
  65. package/src/_api/generated/_cfg_centrifugo/schemas/index.ts +0 -4
  66. package/src/_api/generated/_cfg_centrifugo/sdk.gen.ts +0 -5
  67. package/src/_api/generated/_cfg_centrifugo/types.gen.ts +0 -5
@@ -1,14 +0,0 @@
1
- // AUTO-GENERATED by cmdop_server / devtools.generator.ts_extras
2
- // Source: OpenAPI 3.1 components.schemas
3
- // DO NOT EDIT — re-run `make gen-clients`.
4
-
5
- import { z } from "zod";
6
-
7
- export const CentrifugoTokenSchema = z.object({
8
- token: z.string(),
9
- centrifugo_url: z.string(),
10
- expires_at: z.string().datetime({ offset: true }),
11
- channels: z.array(z.string()),
12
- });
13
-
14
- export type CentrifugoToken = z.infer<typeof CentrifugoTokenSchema>;
@@ -1,87 +0,0 @@
1
- // AUTO-GENERATED by django_generator / ts_extras.wrapper
2
- // Thin per-group proxy over the global `auth` store. All actual auth
3
- // wiring lives in `helpers/auth.ts` (one interceptor, one source of
4
- // truth). DO NOT EDIT — re-run `make gen`.
5
-
6
- import { auth } from '../helpers/auth';
7
- import { APILogger, type LoggerConfig } from '../helpers/logger';
8
-
9
- import { CfgCentrifugo } from '../sdk.gen';
10
-
11
-
12
-
13
- export interface APIOptions {
14
- /** Logger config (defaults to dev-only). */
15
- logger?: Partial<LoggerConfig>;
16
- /** Locale for `Accept-Language`. If omitted, auto-detected from cookie/navigator. */
17
- locale?: string;
18
- /** API key sent as `X-API-Key`. Falls back to NEXT_PUBLIC_API_KEY. */
19
- apiKey?: string;
20
- /** Send Django session/CSRF cookies cross-origin. Defaults to true. */
21
- withCredentials?: boolean;
22
- }
23
-
24
- /**
25
- * Per-group ergonomic facade.
26
- *
27
- * Calling `setToken/setApiKey/setLocale/setBaseUrl` proxies to the
28
- * global `auth` store — the change applies to **every** group's API
29
- * instance because they share the same HTTP client and interceptor.
30
- *
31
- * Use the global `auth` object directly when you don't need a group
32
- * facade: `import { auth } from '@your/api'; auth.setToken(jwt);`
33
- */
34
- export class API {
35
- readonly logger: APILogger;
36
-
37
- readonly cfgCentrifugo = CfgCentrifugo;
38
-
39
- constructor(_baseUrl?: string, opts: APIOptions = {}) {
40
- this.logger = new APILogger(opts.logger);
41
- if (_baseUrl) auth.setBaseUrl(_baseUrl);
42
- if (opts.locale !== undefined) auth.setLocale(opts.locale);
43
- if (opts.apiKey !== undefined) auth.setApiKey(opts.apiKey);
44
- if (opts.withCredentials !== undefined) auth.setWithCredentials(opts.withCredentials);
45
- }
46
-
47
- // ── Base URL ────────────────────────────────────────────────────────────
48
- getBaseUrl(): string { return auth.getBaseUrl(); }
49
- setBaseUrl(url: string): void { auth.setBaseUrl(url); }
50
-
51
- // ── Tokens ──────────────────────────────────────────────────────────────
52
- getToken(): string | null { return auth.getToken(); }
53
- setToken(token: string | null): void { auth.setToken(token); }
54
- getRefreshToken(): string | null { return auth.getRefreshToken(); }
55
- setRefreshToken(token: string | null): void { auth.setRefreshToken(token); }
56
- clearToken(): void { auth.clearTokens(); }
57
- isAuthenticated(): boolean { return auth.isAuthenticated(); }
58
-
59
- // ── Locale / API key ────────────────────────────────────────────────────
60
- getLocale(): string | null { return auth.getLocale(); }
61
- setLocale(locale: string | null): void { auth.setLocale(locale); }
62
- getApiKey(): string | null { return auth.getApiKey(); }
63
- setApiKey(key: string | null): void { auth.setApiKey(key); }
64
-
65
- // ── 401 handling ────────────────────────────────────────────────────────
66
- /** Fired only on terminal 401 (after refresh+retry path is exhausted). */
67
- onUnauthorized(cb: ((response: Response) => void) | null): void {
68
- auth.onUnauthorized(cb);
69
- }
70
- /** Provide a refresh strategy. See `auth.setRefreshHandler` for the contract. */
71
- setRefreshHandler(
72
- fn: ((refreshToken: string) => Promise<{ access: string; refresh?: string } | null>) | null,
73
- ): void {
74
- auth.setRefreshHandler(fn);
75
- }
76
- /**
77
- * Proactively refresh now via the registered handler, sharing the single
78
- * 401-recovery flight (rotation + dedup + rotated-token persistence).
79
- * See `auth.refreshNow`.
80
- */
81
- refreshNow(): Promise<string | null> {
82
- return auth.refreshNow();
83
- }
84
- }
85
-
86
- export { CfgCentrifugo };
87
- export { auth };
@@ -1,4 +0,0 @@
1
- // AUTO-GENERATED — barrel for all hooks.
2
- // DO NOT EDIT.
3
-
4
- export { useCfgCentrifugoAuthTokenRetrieve } from "./useCfgCentrifugoAuthTokenRetrieve";
@@ -1,74 +0,0 @@
1
- 'use client';
2
-
3
- // AUTO-GENERATED by openapi_processor / ts.hooks
4
- // Get Centrifugo connection token
5
- // DO NOT EDIT — re-run `make gen`.
6
-
7
- import useSWR from "swr";
8
- import type { SWRConfiguration } from "swr";
9
- import { CfgCentrifugo } from "../../sdk.gen";
10
- import type { CfgCentrifugoAuthTokenRetrieveData, CfgCentrifugoAuthTokenRetrieveResponses } from "../../types.gen";
11
- import { ConnectionTokenResponseSchema } from "../schemas/ConnectionTokenResponse";
12
-
13
- type Result = CfgCentrifugoAuthTokenRetrieveResponses[keyof CfgCentrifugoAuthTokenRetrieveResponses];
14
-
15
- /**
16
- * Optional `enabled` flag — when `false`, the SWR key becomes `null` and
17
- * no request is made. Use for gated endpoints (auth-required, feature
18
- * flags, "fetch only when X is selected"). The flag is stripped before
19
- * being forwarded to `useSWR` so the underlying SWR config stays pristine.
20
- */
21
- type HookConfig = SWRConfiguration<Result> & { enabled?: boolean };
22
-
23
- export function useCfgCentrifugoAuthTokenRetrieve(
24
- args?: Omit<CfgCentrifugoAuthTokenRetrieveData, "url" | "body">,
25
- config?: HookConfig,
26
- ) {
27
- const { enabled = true, ...swrConfig } = config ?? {};
28
- const key = enabled ? ["cfg_centrifugo_auth_token_retrieve", args ?? {}] as const : null;
29
- return useSWR<Result>(
30
- key,
31
- async () => {
32
- const res = await CfgCentrifugo.cfgCentrifugoAuthTokenRetrieve({ ...(args ?? {}), throwOnError: true } as never);
33
- const data = res.data as Result;
34
- const parsed = ConnectionTokenResponseSchema.safeParse(data);
35
- if (!parsed.success) {
36
- // Log first so the failure is always visible, even if the
37
- // event handler swallows it.
38
- console.warn(
39
- "[zod] response did not match schema",
40
- {
41
- operation: "cfg_centrifugo_auth_token_retrieve",
42
- method: "GET",
43
- path: "/cfg/centrifugo/auth/token/",
44
- issues: parsed.error.issues,
45
- data,
46
- },
47
- );
48
- if (typeof window !== "undefined") {
49
- try {
50
- window.dispatchEvent(
51
- new CustomEvent("zod-validation-error", {
52
- detail: {
53
- operation: "cfg_centrifugo_auth_token_retrieve",
54
- method: "GET",
55
- path: "/cfg/centrifugo/auth/token/",
56
- issues: parsed.error.issues,
57
- data,
58
- timestamp: new Date(),
59
- },
60
- bubbles: true,
61
- cancelable: false,
62
- }),
63
- );
64
- } catch {
65
- // Event dispatch is best-effort.
66
- }
67
- }
68
- return data;
69
- }
70
- return parsed.data as unknown as Result;
71
- },
72
- swrConfig,
73
- );
74
- }
@@ -1,29 +0,0 @@
1
- // AUTO-GENERATED by django_generator / ts_extras.wrapper
2
- // Group barrel. DO NOT EDIT — re-run `make gen`.
3
-
4
- // Wrapper class + per-group SDK re-exports + global auth.
5
- export { API, type APIOptions, auth, CfgCentrifugo } from './api';
6
-
7
- // Shared utilities.
8
- export {
9
- type StorageAdapter,
10
- LocalStorageAdapter,
11
- MemoryStorageAdapter,
12
- CookieStorageAdapter,
13
- APIError,
14
- NetworkError,
15
- APILogger,
16
- defaultLogger,
17
- type LoggerConfig,
18
- type RequestLog,
19
- type ResponseLog,
20
- type ErrorLog,
21
- dispatchValidationError,
22
- onValidationError,
23
- formatZodError,
24
- type ValidationErrorDetail,
25
- type ValidationErrorEvent,
26
- } from '../helpers';
27
-
28
- // Generated artifacts (Hey API).
29
- export type * from '../types.gen';
@@ -1,136 +0,0 @@
1
- {
2
- "openapi": "3.1.0",
3
- "info": {
4
- "title": "Django CFG API",
5
- "version": "1.0.0",
6
- "description": "RESTful API with modern architecture"
7
- },
8
- "paths": {
9
- "/cfg/centrifugo/auth/token/": {
10
- "get": {
11
- "operationId": "cfg_centrifugo_auth_token_retrieve",
12
- "description": "Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.",
13
- "summary": "Get Centrifugo connection token",
14
- "tags": [
15
- "cfg_centrifugo"
16
- ],
17
- "security": [
18
- {
19
- "apiKeyAuth": []
20
- },
21
- {
22
- "jwtAuthWithLastLogin": []
23
- },
24
- {
25
- "tokenAuth": []
26
- }
27
- ],
28
- "responses": {
29
- "200": {
30
- "content": {
31
- "application/json": {
32
- "schema": {
33
- "$ref": "#/components/schemas/ConnectionTokenResponse"
34
- }
35
- }
36
- },
37
- "description": ""
38
- },
39
- "401": {
40
- "content": {
41
- "application/json": {
42
- "schema": {
43
- "description": "Unauthorized - authentication required"
44
- }
45
- }
46
- },
47
- "description": ""
48
- },
49
- "500": {
50
- "content": {
51
- "application/json": {
52
- "schema": {
53
- "description": "Server error"
54
- }
55
- }
56
- },
57
- "description": ""
58
- }
59
- },
60
- "x-async-capable": false
61
- }
62
- }
63
- },
64
- "components": {
65
- "schemas": {
66
- "ConnectionTokenResponse": {
67
- "description": "Response model for Centrifugo connection token.",
68
- "properties": {
69
- "token": {
70
- "description": "JWT token for Centrifugo connection",
71
- "title": "Token",
72
- "type": "string"
73
- },
74
- "centrifugo_url": {
75
- "description": "Centrifugo WebSocket URL",
76
- "title": "Centrifugo Url",
77
- "type": "string"
78
- },
79
- "expires_at": {
80
- "description": "Token expiration time (ISO 8601)",
81
- "title": "Expires At",
82
- "type": "string"
83
- },
84
- "channels": {
85
- "description": "List of allowed channels",
86
- "items": {
87
- "type": "string"
88
- },
89
- "title": "Channels",
90
- "type": "array"
91
- }
92
- },
93
- "required": [
94
- "token",
95
- "centrifugo_url",
96
- "expires_at",
97
- "channels"
98
- ],
99
- "title": "ConnectionTokenResponse",
100
- "type": "object"
101
- }
102
- },
103
- "securitySchemes": {
104
- "apiKeyAuth": {
105
- "type": "apiKey",
106
- "in": "header",
107
- "name": "X-API-Key"
108
- },
109
- "basicAuth": {
110
- "type": "http",
111
- "scheme": "basic"
112
- },
113
- "cookieAuth": {
114
- "type": "apiKey",
115
- "in": "cookie",
116
- "name": "sessionid"
117
- },
118
- "jwtAuthWithLastLogin": {
119
- "type": "http",
120
- "scheme": "bearer",
121
- "bearerFormat": "JWT"
122
- },
123
- "tokenAuth": {
124
- "type": "apiKey",
125
- "in": "header",
126
- "name": "Authorization",
127
- "description": "Token-based authentication with required prefix \"Token\""
128
- }
129
- }
130
- },
131
- "servers": [
132
- {
133
- "url": "http://localhost:8000"
134
- }
135
- ]
136
- }
@@ -1,14 +0,0 @@
1
- // AUTO-GENERATED by cmdop_server / devtools.generator.ts_extras
2
- // Source: OpenAPI 3.1 components.schemas
3
- // DO NOT EDIT — re-run `make gen-clients`.
4
-
5
- import { z } from "zod";
6
-
7
- export const ConnectionTokenResponseSchema = z.object({
8
- token: z.string(),
9
- centrifugo_url: z.string(),
10
- expires_at: z.string(),
11
- channels: z.array(z.string()),
12
- });
13
-
14
- export type ConnectionTokenResponse = z.infer<typeof ConnectionTokenResponseSchema>;
@@ -1,4 +0,0 @@
1
- // AUTO-GENERATED — barrel for zod schemas.
2
- // DO NOT EDIT.
3
-
4
- export * from "./ConnectionTokenResponse";
@@ -1,5 +0,0 @@
1
- // AUTO-GENERATED by openapi_processor / ts.tool
2
- // Re-exports the top-level Hey API SDK so group-scoped imports work:
3
- // import { Foo } from "@api/generated/_<group>/sdk.gen";
4
- // DO NOT EDIT — re-run `make gen`.
5
- export * from "../sdk.gen";
@@ -1,5 +0,0 @@
1
- // AUTO-GENERATED by openapi_processor / ts.tool
2
- // Re-exports the top-level Hey API types so group-scoped imports work:
3
- // import type { Foo } from "@api/generated/_<group>/types.gen";
4
- // DO NOT EDIT — re-run `make gen`.
5
- export * from "../types.gen";