@djangocfg/api 2.1.327 → 2.1.332

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 (174) hide show
  1. package/dist/auth-server.cjs +328 -3553
  2. package/dist/auth-server.cjs.map +1 -1
  3. package/dist/auth-server.mjs +328 -3553
  4. package/dist/auth-server.mjs.map +1 -1
  5. package/dist/auth.cjs +744 -3036
  6. package/dist/auth.cjs.map +1 -1
  7. package/dist/auth.d.cts +35 -35
  8. package/dist/auth.d.ts +35 -35
  9. package/dist/auth.mjs +744 -3036
  10. package/dist/auth.mjs.map +1 -1
  11. package/dist/clients.cjs +303 -3548
  12. package/dist/clients.cjs.map +1 -1
  13. package/dist/clients.d.cts +28 -2557
  14. package/dist/clients.d.ts +28 -2557
  15. package/dist/clients.mjs +303 -3548
  16. package/dist/clients.mjs.map +1 -1
  17. package/dist/index.cjs +1130 -3099
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1807 -2165
  20. package/dist/index.d.ts +1807 -2165
  21. package/dist/index.mjs +1130 -3099
  22. package/dist/index.mjs.map +1 -1
  23. package/package.json +2 -2
  24. package/src/_api/generated/_cfg_accounts/api.ts +67 -0
  25. package/src/_api/generated/{cfg_totp → _cfg_accounts}/events.ts +3 -3
  26. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/index.ts +1 -1
  27. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOauthConnectionsList.ts +5 -6
  28. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOauthDisconnectCreate.ts +3 -3
  29. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOauthGithubAuthorizeCreate.ts +3 -3
  30. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOauthGithubCallbackCreate.ts +3 -3
  31. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOauthProvidersRetrieve.ts +5 -6
  32. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOtpRequestCreate.ts +3 -3
  33. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOtpVerifyCreate.ts +3 -3
  34. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfileAvatarCreate.ts +3 -3
  35. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfileDeleteCreate.ts +3 -3
  36. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfilePartialPartialUpdate.ts +3 -3
  37. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfilePartialUpdate.ts +3 -3
  38. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfileRetrieve.ts +5 -6
  39. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfileUpdatePartialUpdate.ts +3 -3
  40. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfileUpdateUpdate.ts +3 -3
  41. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsTokenRefreshCreate.ts +3 -3
  42. package/src/_api/generated/{cfg_centrifugo → _cfg_accounts}/index.ts +6 -6
  43. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/AccountDeleteResponse.ts +3 -3
  44. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/CentrifugoToken.ts +4 -4
  45. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/CfgUserUpdateRequest.ts +4 -4
  46. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthAuthorizeRequestRequest.ts +2 -2
  47. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthAuthorizeResponse.ts +2 -2
  48. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthCallbackRequestRequest.ts +3 -3
  49. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthConnection.ts +6 -6
  50. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthDisconnectRequestRequest.ts +2 -2
  51. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthError.ts +2 -2
  52. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthProvidersResponse.ts +3 -3
  53. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthTokenResponse.ts +7 -7
  54. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OTPErrorResponse.ts +2 -2
  55. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OTPRequestRequest.ts +2 -2
  56. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OTPRequestResponse.ts +2 -2
  57. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OTPVerifyRequest.ts +2 -2
  58. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OTPVerifyResponse.ts +6 -6
  59. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/PatchedCfgUserUpdateRequest.ts +4 -4
  60. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/ProviderEnum.ts +2 -2
  61. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/TokenRefresh.ts +2 -2
  62. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/TokenRefreshRequest.ts +2 -2
  63. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/User.ts +13 -13
  64. package/src/_api/generated/_cfg_accounts/sdk.gen.ts +5 -0
  65. package/src/_api/generated/_cfg_accounts/types.gen.ts +5 -0
  66. package/src/_api/generated/_cfg_centrifugo/api.ts +67 -0
  67. package/src/_api/generated/{cfg_centrifugo → _cfg_centrifugo}/events.ts +3 -3
  68. package/src/_api/generated/{cfg_centrifugo → _cfg_centrifugo}/hooks/index.ts +1 -1
  69. package/src/_api/generated/{cfg_centrifugo → _cfg_centrifugo}/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +5 -6
  70. package/src/_api/generated/{cfg_accounts → _cfg_centrifugo}/index.ts +6 -6
  71. package/src/_api/generated/{cfg_centrifugo → _cfg_centrifugo}/schemas/ConnectionTokenResponse.ts +4 -4
  72. package/src/_api/generated/_cfg_centrifugo/sdk.gen.ts +5 -0
  73. package/src/_api/generated/_cfg_centrifugo/types.gen.ts +5 -0
  74. package/src/_api/generated/_cfg_totp/api.ts +67 -0
  75. package/src/_api/generated/{cfg_accounts → _cfg_totp}/events.ts +3 -3
  76. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/index.ts +1 -1
  77. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpBackupCodesRegenerateCreate.ts +3 -3
  78. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpBackupCodesRetrieve.ts +5 -6
  79. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpDevicesDestroy.ts +3 -3
  80. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpDevicesRetrieve.ts +5 -6
  81. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpDisableCreate.ts +3 -3
  82. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpSetupConfirmCreate.ts +3 -3
  83. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpSetupCreate.ts +3 -3
  84. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpVerifyBackupCreate.ts +3 -3
  85. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpVerifyCreate.ts +3 -3
  86. package/src/_api/generated/{cfg_totp → _cfg_totp}/index.ts +6 -6
  87. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/BackupCodesRegenerateRequest.ts +2 -2
  88. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/BackupCodesRegenerateResponse.ts +2 -2
  89. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/BackupCodesStatus.ts +2 -2
  90. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/ConfirmSetupRequest.ts +3 -3
  91. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/ConfirmSetupResponse.ts +3 -3
  92. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/DeviceList.ts +6 -6
  93. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/DeviceListResponse.ts +2 -2
  94. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/DeviceListStatusEnum.ts +2 -2
  95. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/DisableRequest.ts +2 -2
  96. package/src/_api/generated/_cfg_totp/schemas/SetupRequest.ts +11 -0
  97. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/SetupResponse.ts +4 -4
  98. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/TotpVerifyUser.ts +12 -12
  99. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/VerifyBackupRequest.ts +3 -3
  100. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/VerifyRequest.ts +3 -3
  101. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/VerifyResponse.ts +4 -4
  102. package/src/_api/generated/_cfg_totp/sdk.gen.ts +5 -0
  103. package/src/_api/generated/_cfg_totp/types.gen.ts +5 -0
  104. package/src/_api/generated/{cfg_centrifugo/client.gen.ts → client.gen.ts} +3 -0
  105. package/src/_api/generated/helpers/auth.ts +223 -0
  106. package/src/_api/generated/{_shared → helpers}/index.ts +1 -0
  107. package/src/_api/generated/index.ts +22 -20
  108. package/src/_api/generated/{cfg_accounts/sdk.gen.ts → sdk.gen.ts} +455 -1
  109. package/src/_api/generated/{cfg_accounts/types.gen.ts → types.gen.ts} +607 -77
  110. package/src/auth/context/AccountsContext.tsx +10 -10
  111. package/src/auth/context/AuthContext.tsx +1 -1
  112. package/src/auth/hooks/useDeleteAccount.ts +2 -1
  113. package/src/auth/hooks/useGithubAuth.ts +3 -2
  114. package/src/auth/hooks/useTokenRefresh.ts +2 -1
  115. package/src/auth/hooks/useTwoFactor.ts +4 -3
  116. package/src/auth/hooks/useTwoFactorSetup.ts +3 -2
  117. package/src/auth/hooks/useTwoFactorStatus.ts +4 -3
  118. package/src/auth/middlewares/tokenRefresh.ts +2 -1
  119. package/src/clients.ts +3 -3
  120. package/src/index.ts +22 -5
  121. package/src/server.ts +9 -9
  122. package/src/_api/generated/cfg_accounts/api.ts +0 -187
  123. package/src/_api/generated/cfg_accounts/client.gen.ts +0 -16
  124. package/src/_api/generated/cfg_centrifugo/api.ts +0 -164
  125. package/src/_api/generated/cfg_centrifugo/client/client.gen.ts +0 -280
  126. package/src/_api/generated/cfg_centrifugo/client/index.ts +0 -25
  127. package/src/_api/generated/cfg_centrifugo/client/types.gen.ts +0 -217
  128. package/src/_api/generated/cfg_centrifugo/client/utils.gen.ts +0 -318
  129. package/src/_api/generated/cfg_centrifugo/core/auth.gen.ts +0 -41
  130. package/src/_api/generated/cfg_centrifugo/core/bodySerializer.gen.ts +0 -82
  131. package/src/_api/generated/cfg_centrifugo/core/params.gen.ts +0 -169
  132. package/src/_api/generated/cfg_centrifugo/core/pathSerializer.gen.ts +0 -171
  133. package/src/_api/generated/cfg_centrifugo/core/queryKeySerializer.gen.ts +0 -117
  134. package/src/_api/generated/cfg_centrifugo/core/serverSentEvents.gen.ts +0 -242
  135. package/src/_api/generated/cfg_centrifugo/core/types.gen.ts +0 -104
  136. package/src/_api/generated/cfg_centrifugo/core/utils.gen.ts +0 -140
  137. package/src/_api/generated/cfg_centrifugo/sdk.gen.ts +0 -64
  138. package/src/_api/generated/cfg_centrifugo/types.gen.ts +0 -61
  139. package/src/_api/generated/cfg_totp/api.ts +0 -181
  140. package/src/_api/generated/cfg_totp/client/client.gen.ts +0 -280
  141. package/src/_api/generated/cfg_totp/client/index.ts +0 -25
  142. package/src/_api/generated/cfg_totp/client/types.gen.ts +0 -217
  143. package/src/_api/generated/cfg_totp/client/utils.gen.ts +0 -318
  144. package/src/_api/generated/cfg_totp/client.gen.ts +0 -16
  145. package/src/_api/generated/cfg_totp/core/auth.gen.ts +0 -41
  146. package/src/_api/generated/cfg_totp/core/bodySerializer.gen.ts +0 -82
  147. package/src/_api/generated/cfg_totp/core/params.gen.ts +0 -169
  148. package/src/_api/generated/cfg_totp/core/pathSerializer.gen.ts +0 -171
  149. package/src/_api/generated/cfg_totp/core/queryKeySerializer.gen.ts +0 -117
  150. package/src/_api/generated/cfg_totp/core/serverSentEvents.gen.ts +0 -242
  151. package/src/_api/generated/cfg_totp/core/types.gen.ts +0 -104
  152. package/src/_api/generated/cfg_totp/core/utils.gen.ts +0 -140
  153. package/src/_api/generated/cfg_totp/schemas/SetupRequest.ts +0 -11
  154. package/src/_api/generated/cfg_totp/sdk.gen.ts +0 -432
  155. package/src/_api/generated/cfg_totp/types.gen.ts +0 -479
  156. /package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/index.ts +0 -0
  157. /package/src/_api/generated/{cfg_centrifugo → _cfg_centrifugo}/schemas/index.ts +0 -0
  158. /package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/index.ts +0 -0
  159. /package/src/_api/generated/{cfg_accounts/client → client}/client.gen.ts +0 -0
  160. /package/src/_api/generated/{cfg_accounts/client → client}/index.ts +0 -0
  161. /package/src/_api/generated/{cfg_accounts/client → client}/types.gen.ts +0 -0
  162. /package/src/_api/generated/{cfg_accounts/client → client}/utils.gen.ts +0 -0
  163. /package/src/_api/generated/{cfg_accounts/core → core}/auth.gen.ts +0 -0
  164. /package/src/_api/generated/{cfg_accounts/core → core}/bodySerializer.gen.ts +0 -0
  165. /package/src/_api/generated/{cfg_accounts/core → core}/params.gen.ts +0 -0
  166. /package/src/_api/generated/{cfg_accounts/core → core}/pathSerializer.gen.ts +0 -0
  167. /package/src/_api/generated/{cfg_accounts/core → core}/queryKeySerializer.gen.ts +0 -0
  168. /package/src/_api/generated/{cfg_accounts/core → core}/serverSentEvents.gen.ts +0 -0
  169. /package/src/_api/generated/{cfg_accounts/core → core}/types.gen.ts +0 -0
  170. /package/src/_api/generated/{cfg_accounts/core → core}/utils.gen.ts +0 -0
  171. /package/src/_api/generated/{_shared → helpers}/errors.ts +0 -0
  172. /package/src/_api/generated/{_shared → helpers}/logger.ts +0 -0
  173. /package/src/_api/generated/{_shared → helpers}/storage.ts +0 -0
  174. /package/src/_api/generated/{_shared → helpers}/validation-events.ts +0 -0
@@ -1,140 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- import type { BodySerializer, QuerySerializer } from './bodySerializer.gen';
4
- import {
5
- type ArraySeparatorStyle,
6
- serializeArrayParam,
7
- serializeObjectParam,
8
- serializePrimitiveParam,
9
- } from './pathSerializer.gen';
10
-
11
- export interface PathSerializer {
12
- path: Record<string, unknown>;
13
- url: string;
14
- }
15
-
16
- export const PATH_PARAM_RE = /\{[^{}]+\}/g;
17
-
18
- export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
19
- let url = _url;
20
- const matches = _url.match(PATH_PARAM_RE);
21
- if (matches) {
22
- for (const match of matches) {
23
- let explode = false;
24
- let name = match.substring(1, match.length - 1);
25
- let style: ArraySeparatorStyle = 'simple';
26
-
27
- if (name.endsWith('*')) {
28
- explode = true;
29
- name = name.substring(0, name.length - 1);
30
- }
31
-
32
- if (name.startsWith('.')) {
33
- name = name.substring(1);
34
- style = 'label';
35
- } else if (name.startsWith(';')) {
36
- name = name.substring(1);
37
- style = 'matrix';
38
- }
39
-
40
- const value = path[name];
41
-
42
- if (value === undefined || value === null) {
43
- continue;
44
- }
45
-
46
- if (Array.isArray(value)) {
47
- url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
48
- continue;
49
- }
50
-
51
- if (typeof value === 'object') {
52
- url = url.replace(
53
- match,
54
- serializeObjectParam({
55
- explode,
56
- name,
57
- style,
58
- value: value as Record<string, unknown>,
59
- valueOnly: true,
60
- }),
61
- );
62
- continue;
63
- }
64
-
65
- if (style === 'matrix') {
66
- url = url.replace(
67
- match,
68
- `;${serializePrimitiveParam({
69
- name,
70
- value: value as string,
71
- })}`,
72
- );
73
- continue;
74
- }
75
-
76
- const replaceValue = encodeURIComponent(
77
- style === 'label' ? `.${value as string}` : (value as string),
78
- );
79
- url = url.replace(match, replaceValue);
80
- }
81
- }
82
- return url;
83
- };
84
-
85
- export const getUrl = ({
86
- baseUrl,
87
- path,
88
- query,
89
- querySerializer,
90
- url: _url,
91
- }: {
92
- baseUrl?: string;
93
- path?: Record<string, unknown>;
94
- query?: Record<string, unknown>;
95
- querySerializer: QuerySerializer;
96
- url: string;
97
- }) => {
98
- const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
99
- let url = (baseUrl ?? '') + pathUrl;
100
- if (path) {
101
- url = defaultPathSerializer({ path, url });
102
- }
103
- let search = query ? querySerializer(query) : '';
104
- if (search.startsWith('?')) {
105
- search = search.substring(1);
106
- }
107
- if (search) {
108
- url += `?${search}`;
109
- }
110
- return url;
111
- };
112
-
113
- export function getValidRequestBody(options: {
114
- body?: unknown;
115
- bodySerializer?: BodySerializer | null;
116
- serializedBody?: unknown;
117
- }) {
118
- const hasBody = options.body !== undefined;
119
- const isSerializedBody = hasBody && options.bodySerializer;
120
-
121
- if (isSerializedBody) {
122
- if ('serializedBody' in options) {
123
- const hasSerializedBody =
124
- options.serializedBody !== undefined && options.serializedBody !== '';
125
-
126
- return hasSerializedBody ? options.serializedBody : null;
127
- }
128
-
129
- // not all clients implement a serializedBody property (i.e., client-axios)
130
- return options.body !== '' ? options.body : null;
131
- }
132
-
133
- // plain/text body
134
- if (hasBody) {
135
- return options.body;
136
- }
137
-
138
- // no body was provided
139
- return undefined;
140
- }
@@ -1,64 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- import type { Client, Options as Options2, TDataShape } from './client';
4
- import { client } from './client.gen';
5
- import type { CfgCentrifugoAuthTokenRetrieveData, CfgCentrifugoAuthTokenRetrieveErrors, CfgCentrifugoAuthTokenRetrieveResponses } from './types.gen';
6
-
7
- export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = Options2<TData, ThrowOnError, TResponse> & {
8
- /**
9
- * You can provide a client instance returned by `createClient()` instead of
10
- * individual options. This might be also useful if you want to implement a
11
- * custom client.
12
- */
13
- client?: Client;
14
- /**
15
- * You can pass arbitrary values through the `meta` object. This can be
16
- * used to access values that aren't defined as part of the SDK function.
17
- */
18
- meta?: Record<string, unknown>;
19
- };
20
-
21
- export class Cfg {
22
- /**
23
- * Get Centrifugo connection token
24
- *
25
- * Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.
26
- */
27
- public static cfgCentrifugoAuthTokenRetrieve<ThrowOnError extends boolean = false>(options?: Options<CfgCentrifugoAuthTokenRetrieveData, ThrowOnError>) {
28
- return (options?.client ?? client).get<CfgCentrifugoAuthTokenRetrieveResponses, CfgCentrifugoAuthTokenRetrieveErrors, ThrowOnError>({
29
- security: [{ scheme: 'bearer', type: 'http' }],
30
- url: '/cfg/centrifugo/auth/token/',
31
- ...options
32
- });
33
- }
34
- }
35
-
36
- export class Centrifugo {
37
- /**
38
- * Get Centrifugo connection token
39
- *
40
- * Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.
41
- */
42
- public static cfgCentrifugoAuthTokenRetrieve<ThrowOnError extends boolean = false>(options?: Options<CfgCentrifugoAuthTokenRetrieveData, ThrowOnError>) {
43
- return (options?.client ?? client).get<CfgCentrifugoAuthTokenRetrieveResponses, CfgCentrifugoAuthTokenRetrieveErrors, ThrowOnError>({
44
- security: [{ scheme: 'bearer', type: 'http' }],
45
- url: '/cfg/centrifugo/auth/token/',
46
- ...options
47
- });
48
- }
49
- }
50
-
51
- export class CentrifugoAuth {
52
- /**
53
- * Get Centrifugo connection token
54
- *
55
- * Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.
56
- */
57
- public static cfgCentrifugoAuthTokenRetrieve<ThrowOnError extends boolean = false>(options?: Options<CfgCentrifugoAuthTokenRetrieveData, ThrowOnError>) {
58
- return (options?.client ?? client).get<CfgCentrifugoAuthTokenRetrieveResponses, CfgCentrifugoAuthTokenRetrieveErrors, ThrowOnError>({
59
- security: [{ scheme: 'bearer', type: 'http' }],
60
- url: '/cfg/centrifugo/auth/token/',
61
- ...options
62
- });
63
- }
64
- }
@@ -1,61 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- export type ClientOptions = {
4
- baseUrl: 'http://localhost:8000' | (string & {});
5
- };
6
-
7
- /**
8
- * ConnectionTokenResponse
9
- *
10
- * Response model for Centrifugo connection token.
11
- */
12
- export type ConnectionTokenResponse = {
13
- /**
14
- * Token
15
- *
16
- * JWT token for Centrifugo connection
17
- */
18
- token: string;
19
- /**
20
- * Centrifugo Url
21
- *
22
- * Centrifugo WebSocket URL
23
- */
24
- centrifugo_url: string;
25
- /**
26
- * Expires At
27
- *
28
- * Token expiration time (ISO 8601)
29
- */
30
- expires_at: string;
31
- /**
32
- * Channels
33
- *
34
- * List of allowed channels
35
- */
36
- channels: Array<string>;
37
- };
38
-
39
- export type CfgCentrifugoAuthTokenRetrieveData = {
40
- body?: never;
41
- path?: never;
42
- query?: never;
43
- url: '/cfg/centrifugo/auth/token/';
44
- };
45
-
46
- export type CfgCentrifugoAuthTokenRetrieveErrors = {
47
- /**
48
- * Unauthorized - authentication required
49
- */
50
- 401: unknown;
51
- /**
52
- * Server error
53
- */
54
- 500: unknown;
55
- };
56
-
57
- export type CfgCentrifugoAuthTokenRetrieveResponses = {
58
- 200: ConnectionTokenResponse;
59
- };
60
-
61
- export type CfgCentrifugoAuthTokenRetrieveResponse = CfgCentrifugoAuthTokenRetrieveResponses[keyof CfgCentrifugoAuthTokenRetrieveResponses];
@@ -1,181 +0,0 @@
1
- // AUTO-GENERATED by django_generator / ts_extras.wrapper
2
- // Self-contained API wrapper for this group. DO NOT EDIT — re-run `make gen`.
3
-
4
- import { client } from './client.gen';
5
- import type { StorageAdapter } from '../_shared/storage';
6
- import { LocalStorageAdapter } from '../_shared/storage';
7
- import { APILogger, type LoggerConfig } from '../_shared/logger';
8
-
9
- import { Cfg } from './sdk.gen';
10
- import { Totp } from './sdk.gen';
11
- import { BackupCodes } from './sdk.gen';
12
- import { TotpManagement } from './sdk.gen';
13
- import { TotpSetup } from './sdk.gen';
14
- import { TotpVerification } from './sdk.gen';
15
- import type { ZodTypeAny } from 'zod';
16
- import {
17
- BackupCodesRegenerateResponseSchema,
18
- BackupCodesStatusSchema,
19
- ConfirmSetupResponseSchema,
20
- DeviceListResponseSchema,
21
- SetupResponseSchema,
22
- VerifyResponseSchema,
23
- } from './schemas';
24
- import { dispatchValidationError } from '../_shared/validation-events';
25
-
26
- const ACCESS_KEY = 'cfg.access_token';
27
- const REFRESH_KEY = 'cfg.refresh_token';
28
-
29
- interface ValidationRoute {
30
- method: string;
31
- re: RegExp;
32
- schema: ZodTypeAny;
33
- path: string;
34
- }
35
- const VALIDATION_ROUTES: ReadonlyArray<ValidationRoute> = [
36
- { method: 'GET', re: new RegExp('^/cfg/totp/backup\\-codes/?$'), schema: BackupCodesStatusSchema, path: '/cfg/totp/backup-codes/' },
37
- { method: 'POST', re: new RegExp('^/cfg/totp/backup\\-codes/regenerate/?$'), schema: BackupCodesRegenerateResponseSchema, path: '/cfg/totp/backup-codes/regenerate/' },
38
- { method: 'GET', re: new RegExp('^/cfg/totp/devices/?$'), schema: DeviceListResponseSchema, path: '/cfg/totp/devices/' },
39
- { method: 'POST', re: new RegExp('^/cfg/totp/setup/?$'), schema: SetupResponseSchema, path: '/cfg/totp/setup/' },
40
- { method: 'POST', re: new RegExp('^/cfg/totp/setup/confirm/?$'), schema: ConfirmSetupResponseSchema, path: '/cfg/totp/setup/confirm/' },
41
- { method: 'POST', re: new RegExp('^/cfg/totp/verify/?$'), schema: VerifyResponseSchema, path: '/cfg/totp/verify/' },
42
- { method: 'POST', re: new RegExp('^/cfg/totp/verify/backup/?$'), schema: VerifyResponseSchema, path: '/cfg/totp/verify/backup/' }
43
- ];
44
-
45
- /** Auto-detect locale from cookie NEXT_LOCALE or navigator.language. */
46
- function detectLocale(): string | null {
47
- try {
48
- if (typeof document !== 'undefined') {
49
- const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
50
- if (m) return decodeURIComponent(m[1]);
51
- }
52
- if (typeof navigator !== 'undefined' && navigator.language) {
53
- return navigator.language;
54
- }
55
- } catch {}
56
- return null;
57
- }
58
-
59
- export interface APIOptions {
60
- /** Override storage backend (LocalStorage by default; Memory for SSR/tests). */
61
- storage?: StorageAdapter;
62
- /** Logger config (defaults to dev-only). */
63
- logger?: Partial<LoggerConfig>;
64
- /** Locale for `Accept-Language`. If omitted, auto-detected from cookie/navigator. */
65
- locale?: string;
66
- /** API key sent as `X-API-Key`. Falls back to NEXT_PUBLIC_API_KEY. */
67
- apiKey?: string;
68
- /** Send Django session/CSRF cookies cross-origin. Defaults to true. */
69
- withCredentials?: boolean;
70
- }
71
-
72
- /**
73
- * Self-contained API wrapper for this group.
74
- *
75
- * Each group has its own client + interceptor + token store. The interceptor
76
- * automatically attaches:
77
- * - `Authorization: Bearer <jwt>` from storage
78
- * - `Accept-Language` from `opts.locale` or `NEXT_LOCALE` cookie
79
- * - `X-API-Key` from `opts.apiKey` or `NEXT_PUBLIC_API_KEY`
80
- * - `credentials: 'include'` for Django session/CSRF cookies (toggle via opts)
81
- */
82
- export class API {
83
- private baseUrl: string;
84
- private storage: StorageAdapter;
85
- private locale: string | null;
86
- private apiKey: string | null;
87
- readonly logger: APILogger;
88
-
89
- readonly cfg = Cfg;
90
- readonly totp = Totp;
91
- readonly backupCodes = BackupCodes;
92
- readonly totpManagement = TotpManagement;
93
- readonly totpSetup = TotpSetup;
94
- readonly totpVerification = TotpVerification;
95
-
96
- constructor(baseUrl: string, opts: APIOptions = {}) {
97
- this.baseUrl = baseUrl.replace(/\/$/, '');
98
- this.storage = opts.storage ?? new LocalStorageAdapter();
99
- this.logger = new APILogger(opts.logger);
100
- this.locale = opts.locale ?? null;
101
- this.apiKey = opts.apiKey ?? (typeof process !== 'undefined' ? (process.env?.NEXT_PUBLIC_API_KEY ?? null) : null);
102
-
103
- const credentials: RequestCredentials = (opts.withCredentials ?? true) ? 'include' : 'same-origin';
104
- client.setConfig({ baseUrl: this.baseUrl, credentials });
105
-
106
- client.interceptors.request.use((request) => {
107
- const access = this.getToken();
108
- if (access) request.headers.set('Authorization', `Bearer ${access}`);
109
-
110
- const locale = this.locale ?? detectLocale();
111
- if (locale) request.headers.set('Accept-Language', locale);
112
-
113
- if (this.apiKey) request.headers.set('X-API-Key', this.apiKey);
114
-
115
- return request;
116
- });
117
-
118
- client.interceptors.response.use(async (response, request) => {
119
- if (!response.ok) return response;
120
- const ct = response.headers.get('content-type') || '';
121
- if (!ct.includes('application/json')) return response;
122
- const url = new URL(request.url);
123
- const method = request.method.toUpperCase();
124
- const route = VALIDATION_ROUTES.find(
125
- (r) => r.method === method && r.re.test(url.pathname),
126
- );
127
- if (!route) return response;
128
- let payload: unknown;
129
- try {
130
- payload = await response.clone().json();
131
- } catch {
132
- return response;
133
- }
134
- const result = route.schema.safeParse(payload);
135
- if (!result.success) {
136
- dispatchValidationError({
137
- operation: `${method} ${route.path}`,
138
- path: route.path,
139
- method,
140
- error: result.error,
141
- response: payload,
142
- timestamp: new Date(),
143
- });
144
- }
145
- return response;
146
- });
147
- }
148
-
149
- // ── Base URL ────────────────────────────────────────────────────────────
150
- getBaseUrl(): string { return this.baseUrl; }
151
- setBaseUrl(url: string): void {
152
- this.baseUrl = url.replace(/\/$/, '');
153
- client.setConfig({ baseUrl: this.baseUrl });
154
- }
155
-
156
- // ── Tokens ──────────────────────────────────────────────────────────────
157
- getToken(): string | null { return this.storage.getItem(ACCESS_KEY); }
158
- setToken(token: string | null): void {
159
- if (token) this.storage.setItem(ACCESS_KEY, token);
160
- else this.storage.removeItem(ACCESS_KEY);
161
- }
162
- getRefreshToken(): string | null { return this.storage.getItem(REFRESH_KEY); }
163
- setRefreshToken(token: string | null): void {
164
- if (token) this.storage.setItem(REFRESH_KEY, token);
165
- else this.storage.removeItem(REFRESH_KEY);
166
- }
167
- clearToken(): void {
168
- this.storage.removeItem(ACCESS_KEY);
169
- this.storage.removeItem(REFRESH_KEY);
170
- }
171
- isAuthenticated(): boolean { return this.getToken() !== null; }
172
-
173
- // ── Locale / API key ────────────────────────────────────────────────────
174
- getLocale(): string | null { return this.locale ?? detectLocale(); }
175
- setLocale(locale: string | null): void { this.locale = locale; }
176
- getApiKey(): string | null { return this.apiKey; }
177
- setApiKey(key: string | null): void { this.apiKey = key; }
178
- }
179
-
180
- export { Cfg, Totp, BackupCodes, TotpManagement, TotpSetup, TotpVerification };
181
- export { client };