@djangocfg/api 2.1.540 → 2.1.542

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 (53) hide show
  1. package/README.md +1 -2
  2. package/dist/auth.cjs +99 -111
  3. package/dist/auth.cjs.map +1 -1
  4. package/dist/auth.d.cts +0 -22
  5. package/dist/auth.d.ts +0 -22
  6. package/dist/auth.mjs +99 -111
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/clients.cjs +3 -99
  9. package/dist/clients.cjs.map +1 -1
  10. package/dist/clients.d.cts +4 -136
  11. package/dist/clients.d.ts +4 -136
  12. package/dist/clients.mjs +3 -99
  13. package/dist/clients.mjs.map +1 -1
  14. package/dist/hooks.cjs.map +1 -1
  15. package/dist/hooks.d.cts +2 -4
  16. package/dist/hooks.d.ts +2 -4
  17. package/dist/hooks.mjs.map +1 -1
  18. package/dist/index.cjs +3 -100
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +8 -338
  21. package/dist/index.d.ts +8 -338
  22. package/dist/index.mjs +3 -100
  23. package/dist/index.mjs.map +1 -1
  24. package/package.json +4 -4
  25. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRetrieve.ts +8 -2
  26. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthConnectionsList.ts +8 -2
  27. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthProvidersRetrieve.ts +8 -2
  28. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOtpConsentPolicyRetrieve.ts +8 -2
  29. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfileRetrieve.ts +8 -2
  30. package/src/_api/generated/_cfg_accounts/openapi.json +0 -45
  31. package/src/_api/generated/_cfg_accounts/schemas/User.ts +0 -2
  32. package/src/_api/generated/_cfg_accounts/schemas/index.ts +0 -1
  33. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpBackupCodesRetrieve.ts +8 -2
  34. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpDevicesRetrieve.ts +8 -2
  35. package/src/_api/generated/index.ts +1 -5
  36. package/src/_api/generated/openapi.json +0 -135
  37. package/src/_api/generated/sdk.gen.ts +1 -20
  38. package/src/_api/generated/types.gen.ts +0 -79
  39. package/src/_api/index.ts +1 -1
  40. package/src/clients.ts +2 -4
  41. package/src/index.ts +0 -2
  42. package/src/log-control.ts +1 -1
  43. package/src/server.ts +0 -4
  44. package/src/_api/generated/_cfg_accounts/schemas/CentrifugoToken.ts +0 -14
  45. package/src/_api/generated/_cfg_centrifugo/api.ts +0 -87
  46. package/src/_api/generated/_cfg_centrifugo/hooks/index.ts +0 -4
  47. package/src/_api/generated/_cfg_centrifugo/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +0 -74
  48. package/src/_api/generated/_cfg_centrifugo/index.ts +0 -29
  49. package/src/_api/generated/_cfg_centrifugo/openapi.json +0 -136
  50. package/src/_api/generated/_cfg_centrifugo/schemas/ConnectionTokenResponse.ts +0 -14
  51. package/src/_api/generated/_cfg_centrifugo/schemas/index.ts +0 -4
  52. package/src/_api/generated/_cfg_centrifugo/sdk.gen.ts +0 -5
  53. package/src/_api/generated/_cfg_centrifugo/types.gen.ts +0 -5
package/src/_api/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Re-export the generated barrel directly. Per-group API singletons,
2
- // API classes (AccountsAPI/TotpAPI/CentrifugoAPI), and shared utilities
2
+ // API classes (AccountsAPI/TotpAPI), and shared utilities
3
3
  // (LocalStorageAdapter / MemoryStorageAdapter / APIError / ...) all come
4
4
  // from `_api/generated/index.ts`.
5
5
  export * from './generated';
package/src/clients.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @djangocfg/api/clients — pre-configured per-group API singletons.
3
3
  *
4
- * Singletons (`cfgAccountsApi`, `cfgTotpApi`, `cfgCentrifugoApi`) live in the
4
+ * Singletons (`cfgAccountsApi`, `cfgTotpApi`) live in the
5
5
  * generated barrel. This file just re-exports them with the legacy-friendly
6
- * `apiAccounts` / `apiTotp` / `apiCentrifugo` aliases.
6
+ * `apiAccounts` / `apiTotp` aliases.
7
7
  *
8
8
  * Usage:
9
9
  * import { apiAccounts } from '@djangocfg/api/clients';
@@ -13,8 +13,6 @@
13
13
  export {
14
14
  CfgAccountsApi as apiAccounts,
15
15
  CfgTotpApi as apiTotp,
16
- CfgCentrifugoApi as apiCentrifugo,
17
16
  CfgAccountsAPI as AccountsAPI,
18
17
  CfgTotpAPI as TotpAPI,
19
- CfgCentrifugoAPI as CentrifugoAPI,
20
18
  } from './_api/generated';
package/src/index.ts CHANGED
@@ -21,7 +21,6 @@ export {
21
21
  CfgAccountsOtp,
22
22
  CfgAccountsProfile,
23
23
  CfgAccountsAuth,
24
- CfgCentrifugo,
25
24
  CfgTotpBackupCodes,
26
25
  CfgTotp,
27
26
  CfgTotpSetup,
@@ -31,7 +30,6 @@ export {
31
30
  // Type namespaces (one per group) for code that needs `AccountsTypes.User`.
32
31
  export type * as AccountsTypes from './_api/generated/_cfg_accounts/types.gen';
33
32
  export type * as TotpTypes from './_api/generated/_cfg_totp/types.gen';
34
- export type * as CentrifugoTypes from './_api/generated/_cfg_centrifugo/types.gen';
35
33
 
36
34
  // Convenience top-level type re-exports.
37
35
  export type { User } from './_api/generated/_cfg_accounts/types.gen';
@@ -7,7 +7,7 @@
7
7
  * hardcoding `isDev ? 4 : 1`.
8
8
  *
9
9
  * Lives in `@djangocfg/api` because it's the lowest shared package — api,
10
- * layouts, centrifugo, ui-core consumers can all import it without a cycle.
10
+ * layouts, ui-core consumers can all import it without a cycle.
11
11
  *
12
12
  * consola levels: 0 silent · 1 error · 2 warn · 3 info · 4 debug · 5 trace.
13
13
  *
package/src/server.ts CHANGED
@@ -8,7 +8,6 @@
8
8
  export {
9
9
  CfgAccountsAPI as AccountsAPI,
10
10
  CfgTotpAPI as TotpAPI,
11
- CfgCentrifugoAPI as CentrifugoAPI,
12
11
  MemoryStorageAdapter,
13
12
  LocalStorageAdapter,
14
13
  type StorageAdapter,
@@ -19,14 +18,11 @@ export {
19
18
  // SDK fetchers (Hey API SDK classes — re-export as namespace modules).
20
19
  export * as AccountsFetchers from './_api/generated/_cfg_accounts/sdk.gen';
21
20
  export * as TotpFetchers from './_api/generated/_cfg_totp/sdk.gen';
22
- export * as CentrifugoFetchers from './_api/generated/_cfg_centrifugo/sdk.gen';
23
21
 
24
22
  // Zod schemas.
25
23
  export * as AccountsSchemas from './_api/generated/_cfg_accounts/schemas';
26
24
  export * as TotpSchemas from './_api/generated/_cfg_totp/schemas';
27
- export * as CentrifugoSchemas from './_api/generated/_cfg_centrifugo/schemas';
28
25
 
29
26
  // Types.
30
27
  export type * as AccountsTypes from './_api/generated/_cfg_accounts/types.gen';
31
28
  export type * as TotpTypes from './_api/generated/_cfg_totp/types.gen';
32
- export type * as CentrifugoTypes from './_api/generated/_cfg_centrifugo/types.gen';
@@ -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";