@djangocfg/monitor 2.1.322 → 2.1.327
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.
- package/dist/client.cjs +956 -1126
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +25 -39
- package/dist/client.d.ts +25 -39
- package/dist/client.mjs +956 -1137
- package/dist/client.mjs.map +1 -1
- package/dist/index.cjs +934 -1092
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -39
- package/dist/index.d.ts +25 -39
- package/dist/index.mjs +927 -1096
- package/dist/index.mjs.map +1 -1
- package/dist/server.cjs +915 -1092
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +25 -39
- package/dist/server.d.ts +25 -39
- package/dist/server.mjs +907 -1095
- package/dist/server.mjs.map +1 -1
- package/package.json +7 -2
- package/src/_api/generated/_shared/errors.ts +70 -0
- package/src/_api/generated/_shared/index.ts +25 -0
- package/src/_api/generated/_shared/logger.ts +123 -0
- package/src/_api/generated/_shared/storage.ts +83 -0
- package/src/_api/generated/_shared/validation-events.ts +52 -0
- package/src/_api/generated/cfg_monitor/api.ts +122 -0
- package/src/_api/generated/cfg_monitor/client/client.gen.ts +280 -0
- package/src/_api/generated/cfg_monitor/client/index.ts +25 -0
- package/src/_api/generated/cfg_monitor/client/types.gen.ts +217 -0
- package/src/_api/generated/cfg_monitor/client/utils.gen.ts +318 -0
- package/src/_api/generated/cfg_monitor/client.gen.ts +16 -0
- package/src/_api/generated/cfg_monitor/core/auth.gen.ts +41 -0
- package/src/_api/generated/cfg_monitor/core/bodySerializer.gen.ts +82 -0
- package/src/_api/generated/cfg_monitor/core/params.gen.ts +169 -0
- package/src/_api/generated/cfg_monitor/core/pathSerializer.gen.ts +171 -0
- package/src/_api/generated/cfg_monitor/core/queryKeySerializer.gen.ts +117 -0
- package/src/_api/generated/cfg_monitor/core/serverSentEvents.gen.ts +242 -0
- package/src/_api/generated/cfg_monitor/core/types.gen.ts +104 -0
- package/src/_api/generated/cfg_monitor/core/utils.gen.ts +140 -0
- package/src/_api/generated/cfg_monitor/events.ts +198 -0
- package/src/_api/generated/cfg_monitor/hooks/index.ts +4 -0
- package/src/_api/generated/cfg_monitor/hooks/useCfgMonitorIngestCreate.ts +24 -0
- package/src/_api/generated/cfg_monitor/index.ts +26 -314
- package/src/_api/generated/cfg_monitor/schemas/EventTypeEnum.ts +9 -0
- package/src/_api/generated/cfg_monitor/{_utils/schemas/FrontendEventIngestRequest.schema.ts → schemas/FrontendEventIngestRequest.ts} +12 -19
- package/src/_api/generated/cfg_monitor/schemas/IngestBatchRequest.ts +12 -0
- package/src/_api/generated/cfg_monitor/schemas/LevelEnum.ts +9 -0
- package/src/_api/generated/cfg_monitor/schemas/index.ts +7 -0
- package/src/_api/generated/cfg_monitor/sdk.gen.ts +55 -0
- package/src/_api/generated/cfg_monitor/types.gen.ts +79 -0
- package/src/_api/generated/index.ts +22 -0
- package/src/_api/index.ts +2 -2
- package/src/client/capture/console.ts +2 -3
- package/src/client/transport/ingest.ts +21 -17
- package/src/server/index.ts +3 -2
- package/src/_api/generated/cfg_monitor/CLAUDE.md +0 -60
- package/src/_api/generated/cfg_monitor/_utils/fetchers/index.ts +0 -30
- package/src/_api/generated/cfg_monitor/_utils/fetchers/monitor.ts +0 -51
- package/src/_api/generated/cfg_monitor/_utils/hooks/index.ts +0 -30
- package/src/_api/generated/cfg_monitor/_utils/hooks/monitor.ts +0 -43
- package/src/_api/generated/cfg_monitor/_utils/schemas/IngestBatchRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_monitor/_utils/schemas/index.ts +0 -22
- package/src/_api/generated/cfg_monitor/api-instance.ts +0 -181
- package/src/_api/generated/cfg_monitor/client.ts +0 -330
- package/src/_api/generated/cfg_monitor/enums.ts +0 -34
- package/src/_api/generated/cfg_monitor/errors.ts +0 -123
- package/src/_api/generated/cfg_monitor/http.ts +0 -160
- package/src/_api/generated/cfg_monitor/logger.ts +0 -261
- package/src/_api/generated/cfg_monitor/monitor/client.ts +0 -26
- package/src/_api/generated/cfg_monitor/monitor/index.ts +0 -4
- package/src/_api/generated/cfg_monitor/monitor/models.ts +0 -47
- package/src/_api/generated/cfg_monitor/retry.ts +0 -177
- package/src/_api/generated/cfg_monitor/schema.json +0 -181
- package/src/_api/generated/cfg_monitor/storage.ts +0 -163
- package/src/_api/generated/cfg_monitor/validation-events.ts +0 -135
|
@@ -1,317 +1,29 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
/**
|
|
4
|
-
* Django CFG API - API Client with JWT Management
|
|
5
|
-
*
|
|
6
|
-
* Usage:
|
|
7
|
-
* ```typescript
|
|
8
|
-
* import { API } from './api';
|
|
9
|
-
*
|
|
10
|
-
* const api = new API('https://api.example.com');
|
|
11
|
-
*
|
|
12
|
-
* // Set JWT token
|
|
13
|
-
* api.setToken('your-jwt-token', 'refresh-token');
|
|
14
|
-
*
|
|
15
|
-
* // Use API
|
|
16
|
-
* const posts = await api.posts.list();
|
|
17
|
-
* const user = await api.users.retrieve(1);
|
|
18
|
-
*
|
|
19
|
-
* // Check authentication
|
|
20
|
-
* if (api.isAuthenticated()) {
|
|
21
|
-
* // ...
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* // Custom storage with logging (for Electron/Node.js)
|
|
25
|
-
* import { MemoryStorageAdapter, APILogger } from './storage';
|
|
26
|
-
* const logger = new APILogger({ enabled: true, logLevel: 'debug' });
|
|
27
|
-
* const api = new API('https://api.example.com', {
|
|
28
|
-
* storage: new MemoryStorageAdapter(logger),
|
|
29
|
-
* loggerConfig: { enabled: true, logLevel: 'debug' }
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* // Get OpenAPI schema
|
|
33
|
-
* const schema = api.getSchema();
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
1
|
+
// AUTO-GENERATED by django_generator / ts_extras.wrapper
|
|
2
|
+
// Group barrel. DO NOT EDIT — re-run `make gen`.
|
|
36
3
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
StorageAdapter,
|
|
40
|
-
LocalStorageAdapter,
|
|
41
|
-
CookieStorageAdapter,
|
|
42
|
-
MemoryStorageAdapter
|
|
43
|
-
} from "./storage";
|
|
44
|
-
import type { RetryConfig } from "./retry";
|
|
45
|
-
import type { LoggerConfig } from "./logger";
|
|
46
|
-
import { APILogger } from "./logger";
|
|
47
|
-
import { Monitor } from "./monitor/client";
|
|
48
|
-
export * as MonitorTypes from "./monitor/models";
|
|
49
|
-
// Note: Direct exports (export * from) are removed to avoid duplicate type conflicts
|
|
50
|
-
// Use namespace exports like CfgAccountsTypes.User or import from specific modules
|
|
51
|
-
export * as Enums from "./enums";
|
|
52
|
-
|
|
53
|
-
// Re-export Zod schemas for runtime validation
|
|
54
|
-
export * as Schemas from "./_utils/schemas";
|
|
55
|
-
// Also export all schemas directly for convenience
|
|
56
|
-
export * from "./_utils/schemas";
|
|
4
|
+
// Wrapper class + per-group SDK re-exports
|
|
5
|
+
export { API, type APIOptions, Cfg, Monitor } from './api';
|
|
57
6
|
|
|
58
|
-
//
|
|
59
|
-
export type { ValidationErrorDetail, ValidationErrorEvent } from "./validation-events";
|
|
60
|
-
export { dispatchValidationError, onValidationError, formatZodError } from "./validation-events";
|
|
61
|
-
|
|
62
|
-
// Re-export typed fetchers for universal usage
|
|
63
|
-
export * as Fetchers from "./_utils/fetchers";
|
|
64
|
-
export * from "./_utils/fetchers";
|
|
65
|
-
|
|
66
|
-
// Re-export API instance configuration functions
|
|
7
|
+
// Shared utilities (storage / errors / logger / validation events)
|
|
67
8
|
export {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
export
|
|
89
|
-
|
|
90
|
-
// Re-export HTTP adapters for custom implementations
|
|
91
|
-
export type { HttpClientAdapter, HttpRequest, HttpResponse } from "./http";
|
|
92
|
-
export { FetchAdapter, KeepAliveFetchAdapter } from "./http";
|
|
93
|
-
|
|
94
|
-
// Re-export logger types and classes
|
|
95
|
-
export type { LoggerConfig, RequestLog, ResponseLog, ErrorLog } from "./logger";
|
|
96
|
-
export { APILogger } from "./logger";
|
|
97
|
-
|
|
98
|
-
// Re-export retry configuration and utilities
|
|
99
|
-
export type { RetryConfig, FailedAttemptInfo } from "./retry";
|
|
100
|
-
export { withRetry, shouldRetry, DEFAULT_RETRY_CONFIG } from "./retry";
|
|
101
|
-
|
|
102
|
-
export const TOKEN_KEY = "auth_token";
|
|
103
|
-
export const REFRESH_TOKEN_KEY = "refresh_token";
|
|
104
|
-
|
|
105
|
-
/** Auto-detect locale from cookie NEXT_LOCALE or navigator.language */
|
|
106
|
-
function detectLocale(): string | null {
|
|
107
|
-
try {
|
|
108
|
-
if (typeof document !== 'undefined') {
|
|
109
|
-
const match = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
110
|
-
if (match) return match[1];
|
|
111
|
-
}
|
|
112
|
-
if (typeof navigator !== 'undefined' && navigator.language) {
|
|
113
|
-
return navigator.language;
|
|
114
|
-
}
|
|
115
|
-
} catch {}
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export interface APIOptions {
|
|
120
|
-
/** Custom storage adapter (defaults to LocalStorageAdapter) */
|
|
121
|
-
storage?: StorageAdapter;
|
|
122
|
-
/** Custom HTTP client adapter (defaults to FetchAdapter) */
|
|
123
|
-
httpClient?: HttpClientAdapter;
|
|
124
|
-
/** Retry configuration for failed requests */
|
|
125
|
-
retryConfig?: RetryConfig;
|
|
126
|
-
/** Logger configuration */
|
|
127
|
-
loggerConfig?: Partial<LoggerConfig>;
|
|
128
|
-
/** Locale for Accept-Language header (e.g. 'en', 'ko', 'ru') */
|
|
129
|
-
locale?: string;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export class API {
|
|
133
|
-
private baseUrl: string;
|
|
134
|
-
private _client: APIClient;
|
|
135
|
-
private _token: string | null = null;
|
|
136
|
-
private _refreshToken: string | null = null;
|
|
137
|
-
private _locale: string | null = null;
|
|
138
|
-
private storage: StorageAdapter;
|
|
139
|
-
private options?: APIOptions;
|
|
140
|
-
|
|
141
|
-
// Sub-clients
|
|
142
|
-
public monitor!: Monitor;
|
|
143
|
-
|
|
144
|
-
constructor(baseUrl: string, options?: APIOptions) {
|
|
145
|
-
this.baseUrl = baseUrl;
|
|
146
|
-
this.options = options;
|
|
147
|
-
|
|
148
|
-
// Create logger if config provided
|
|
149
|
-
const logger = options?.loggerConfig ? new APILogger(options.loggerConfig) : undefined;
|
|
150
|
-
|
|
151
|
-
// Initialize storage with logger
|
|
152
|
-
this.storage = options?.storage || new LocalStorageAdapter(logger);
|
|
153
|
-
|
|
154
|
-
this._locale = options?.locale || null;
|
|
155
|
-
|
|
156
|
-
this._loadTokensFromStorage();
|
|
157
|
-
|
|
158
|
-
// Initialize APIClient with token getter for URL authentication
|
|
159
|
-
this._client = new APIClient(this.baseUrl, {
|
|
160
|
-
httpClient: this.options?.httpClient,
|
|
161
|
-
retryConfig: this.options?.retryConfig,
|
|
162
|
-
loggerConfig: this.options?.loggerConfig,
|
|
163
|
-
tokenGetter: () => this.getToken(),
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// Always inject auth header wrapper (reads token dynamically from storage)
|
|
167
|
-
this._injectAuthHeader();
|
|
168
|
-
|
|
169
|
-
// Initialize sub-clients from APIClient
|
|
170
|
-
this.monitor = this._client.monitor;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private _loadTokensFromStorage(): void {
|
|
174
|
-
this._token = this.storage.getItem(TOKEN_KEY);
|
|
175
|
-
this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private _reinitClients(): void {
|
|
179
|
-
this._client = new APIClient(this.baseUrl, {
|
|
180
|
-
httpClient: this.options?.httpClient,
|
|
181
|
-
retryConfig: this.options?.retryConfig,
|
|
182
|
-
loggerConfig: this.options?.loggerConfig,
|
|
183
|
-
tokenGetter: () => this.getToken(),
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// Always inject auth header wrapper (reads token dynamically from storage)
|
|
187
|
-
this._injectAuthHeader();
|
|
188
|
-
|
|
189
|
-
// Reinitialize sub-clients
|
|
190
|
-
this.monitor = this._client.monitor;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
private _injectAuthHeader(): void {
|
|
194
|
-
// Override request method to inject auth header
|
|
195
|
-
const originalRequest = this._client.request.bind(this._client);
|
|
196
|
-
this._client.request = async <T>(
|
|
197
|
-
method: string,
|
|
198
|
-
path: string,
|
|
199
|
-
options?: { params?: Record<string, any>; body?: any; formData?: FormData; headers?: Record<string, string> }
|
|
200
|
-
): Promise<T> => {
|
|
201
|
-
// Read token from storage dynamically (supports JWT injection after instantiation)
|
|
202
|
-
const token = this.getToken();
|
|
203
|
-
const locale = this._locale || detectLocale();
|
|
204
|
-
const mergedOptions = {
|
|
205
|
-
...options,
|
|
206
|
-
headers: {
|
|
207
|
-
...(options?.headers || {}),
|
|
208
|
-
...(token ? { 'Authorization': `Bearer ${token}` } : {}),
|
|
209
|
-
...(locale ? { 'Accept-Language': locale } : {}),
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
return originalRequest(method, path, mergedOptions);
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Get current JWT token
|
|
219
|
-
*/
|
|
220
|
-
getToken(): string | null {
|
|
221
|
-
return this.storage.getItem(TOKEN_KEY);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Get current refresh token
|
|
226
|
-
*/
|
|
227
|
-
getRefreshToken(): string | null {
|
|
228
|
-
return this.storage.getItem(REFRESH_TOKEN_KEY);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Set JWT token and refresh token
|
|
233
|
-
* @param token - JWT access token
|
|
234
|
-
* @param refreshToken - JWT refresh token (optional)
|
|
235
|
-
*/
|
|
236
|
-
setToken(token: string, refreshToken?: string): void {
|
|
237
|
-
this._token = token;
|
|
238
|
-
this.storage.setItem(TOKEN_KEY, token);
|
|
239
|
-
|
|
240
|
-
if (refreshToken) {
|
|
241
|
-
this._refreshToken = refreshToken;
|
|
242
|
-
this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Reinitialize clients with new token
|
|
246
|
-
this._reinitClients();
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Clear all tokens
|
|
251
|
-
*/
|
|
252
|
-
clearTokens(): void {
|
|
253
|
-
this._token = null;
|
|
254
|
-
this._refreshToken = null;
|
|
255
|
-
this.storage.removeItem(TOKEN_KEY);
|
|
256
|
-
this.storage.removeItem(REFRESH_TOKEN_KEY);
|
|
257
|
-
|
|
258
|
-
// Reinitialize clients without token
|
|
259
|
-
this._reinitClients();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Check if user is authenticated
|
|
264
|
-
*/
|
|
265
|
-
isAuthenticated(): boolean {
|
|
266
|
-
return !!this.getToken();
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Update base URL and reinitialize clients
|
|
271
|
-
* @param url - New base URL
|
|
272
|
-
*/
|
|
273
|
-
setBaseUrl(url: string): void {
|
|
274
|
-
this.baseUrl = url;
|
|
275
|
-
this._reinitClients();
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Get current base URL
|
|
280
|
-
*/
|
|
281
|
-
getBaseUrl(): string {
|
|
282
|
-
return this.baseUrl;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Set locale for Accept-Language header
|
|
287
|
-
* @param locale - Locale string (e.g. 'en', 'ko', 'ru') or null to clear
|
|
288
|
-
*/
|
|
289
|
-
setLocale(locale: string | null): void {
|
|
290
|
-
this._locale = locale;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Get current locale
|
|
295
|
-
*/
|
|
296
|
-
getLocale(): string | null {
|
|
297
|
-
return this._locale;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Get OpenAPI schema path
|
|
302
|
-
* @returns Path to the OpenAPI schema JSON file
|
|
303
|
-
*
|
|
304
|
-
* Note: The OpenAPI schema is available in the schema.json file.
|
|
305
|
-
* You can load it dynamically using:
|
|
306
|
-
* ```typescript
|
|
307
|
-
* const schema = await fetch('./schema.json').then(r => r.json());
|
|
308
|
-
* // or using fs in Node.js:
|
|
309
|
-
* // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
|
|
310
|
-
* ```
|
|
311
|
-
*/
|
|
312
|
-
getSchemaPath(): string {
|
|
313
|
-
return './schema.json';
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export default API;
|
|
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 '../_shared';
|
|
27
|
+
|
|
28
|
+
// Generated artifacts (Hey API)
|
|
29
|
+
export type * from './types.gen';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// AUTO-GENERATED by django-cfg / django_generator.ts_extras
|
|
2
|
+
// Source: OpenAPI 3.1 components.schemas
|
|
3
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
4
|
+
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
export const EventTypeEnumSchema = z.enum(["JS_ERROR", "NETWORK_ERROR", "ERROR", "WARNING", "PAGE_VIEW", "PERFORMANCE", "CONSOLE"]);
|
|
8
|
+
|
|
9
|
+
export type EventTypeEnum = z.infer<typeof EventTypeEnumSchema>;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import * as Enums from '../../enums'
|
|
1
|
+
// AUTO-GENERATED by django-cfg / django_generator.ts_extras
|
|
2
|
+
// Source: OpenAPI 3.1 components.schemas
|
|
3
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
4
|
+
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { EventTypeEnumSchema } from "./EventTypeEnum";
|
|
7
|
+
import { LevelEnumSchema } from "./LevelEnum";
|
|
9
8
|
|
|
10
|
-
/**
|
|
11
|
-
* Single browser event payload.
|
|
12
|
-
*/
|
|
13
9
|
export const FrontendEventIngestRequestSchema = z.object({
|
|
14
|
-
event_type:
|
|
10
|
+
event_type: EventTypeEnumSchema,
|
|
15
11
|
message: z.string().min(1).max(5000),
|
|
16
|
-
level:
|
|
12
|
+
level: LevelEnumSchema.optional(),
|
|
17
13
|
stack_trace: z.string().max(10000).optional(),
|
|
18
14
|
url: z.string().max(2000).optional(),
|
|
19
15
|
fingerprint: z.string().max(64).optional(),
|
|
@@ -24,11 +20,8 @@ export const FrontendEventIngestRequestSchema = z.object({
|
|
|
24
20
|
user_agent: z.string().max(500).optional(),
|
|
25
21
|
build_id: z.string().max(100).optional(),
|
|
26
22
|
environment: z.string().max(20).optional(),
|
|
27
|
-
extra: z.
|
|
23
|
+
extra: z.unknown().optional(),
|
|
28
24
|
project_name: z.string().max(100).optional(),
|
|
29
|
-
})
|
|
25
|
+
});
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
* Infer TypeScript type from Zod schema
|
|
33
|
-
*/
|
|
34
|
-
export type FrontendEventIngestRequest = z.infer<typeof FrontendEventIngestRequestSchema>
|
|
27
|
+
export type FrontendEventIngestRequest = z.infer<typeof FrontendEventIngestRequestSchema>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// AUTO-GENERATED by django-cfg / django_generator.ts_extras
|
|
2
|
+
// Source: OpenAPI 3.1 components.schemas
|
|
3
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
4
|
+
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { FrontendEventIngestRequestSchema } from "./FrontendEventIngestRequest";
|
|
7
|
+
|
|
8
|
+
export const IngestBatchRequestSchema = z.object({
|
|
9
|
+
events: z.array(FrontendEventIngestRequestSchema),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export type IngestBatchRequest = z.infer<typeof IngestBatchRequestSchema>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// AUTO-GENERATED by django-cfg / django_generator.ts_extras
|
|
2
|
+
// Source: OpenAPI 3.1 components.schemas
|
|
3
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
4
|
+
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
export const LevelEnumSchema = z.enum(["error", "warning", "info", "debug"]);
|
|
8
|
+
|
|
9
|
+
export type LevelEnum = z.infer<typeof LevelEnumSchema>;
|
|
@@ -0,0 +1,55 @@
|
|
|
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 { CfgMonitorIngestCreateData, CfgMonitorIngestCreateResponses } 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
|
+
* Ingest browser events
|
|
24
|
+
*
|
|
25
|
+
* Accepts a batch of up to 50 frontend events. No authentication required — anonymous visitors can send events.
|
|
26
|
+
*/
|
|
27
|
+
public static cfgMonitorIngestCreate<ThrowOnError extends boolean = false>(options: Options<CfgMonitorIngestCreateData, ThrowOnError>) {
|
|
28
|
+
return (options.client ?? client).post<CfgMonitorIngestCreateResponses, unknown, ThrowOnError>({
|
|
29
|
+
url: '/cfg/monitor/ingest/',
|
|
30
|
+
...options,
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
...options.headers
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class Monitor {
|
|
40
|
+
/**
|
|
41
|
+
* Ingest browser events
|
|
42
|
+
*
|
|
43
|
+
* Accepts a batch of up to 50 frontend events. No authentication required — anonymous visitors can send events.
|
|
44
|
+
*/
|
|
45
|
+
public static cfgMonitorIngestCreate<ThrowOnError extends boolean = false>(options: Options<CfgMonitorIngestCreateData, ThrowOnError>) {
|
|
46
|
+
return (options.client ?? client).post<CfgMonitorIngestCreateResponses, unknown, ThrowOnError>({
|
|
47
|
+
url: '/cfg/monitor/ingest/',
|
|
48
|
+
...options,
|
|
49
|
+
headers: {
|
|
50
|
+
'Content-Type': 'application/json',
|
|
51
|
+
...options.headers
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
* * `JS_ERROR` - Js Error
|
|
9
|
+
* * `NETWORK_ERROR` - Network Error
|
|
10
|
+
* * `ERROR` - Error
|
|
11
|
+
* * `WARNING` - Warning
|
|
12
|
+
* * `PAGE_VIEW` - Page View
|
|
13
|
+
* * `PERFORMANCE` - Performance
|
|
14
|
+
* * `CONSOLE` - Console
|
|
15
|
+
*/
|
|
16
|
+
export enum EventTypeEnum {
|
|
17
|
+
JS_ERROR = 'JS_ERROR',
|
|
18
|
+
NETWORK_ERROR = 'NETWORK_ERROR',
|
|
19
|
+
ERROR = 'ERROR',
|
|
20
|
+
WARNING = 'WARNING',
|
|
21
|
+
PAGE_VIEW = 'PAGE_VIEW',
|
|
22
|
+
PERFORMANCE = 'PERFORMANCE',
|
|
23
|
+
CONSOLE = 'CONSOLE'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Single browser event payload.
|
|
28
|
+
*/
|
|
29
|
+
export type FrontendEventIngestRequest = {
|
|
30
|
+
event_type: EventTypeEnum;
|
|
31
|
+
message: string;
|
|
32
|
+
level?: LevelEnum;
|
|
33
|
+
stack_trace?: string;
|
|
34
|
+
url?: string;
|
|
35
|
+
fingerprint?: string;
|
|
36
|
+
http_status?: number | null;
|
|
37
|
+
http_method?: string;
|
|
38
|
+
http_url?: string;
|
|
39
|
+
session_id?: string;
|
|
40
|
+
user_agent?: string;
|
|
41
|
+
build_id?: string;
|
|
42
|
+
environment?: string;
|
|
43
|
+
extra?: unknown;
|
|
44
|
+
project_name?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Batch of up to 50 browser events.
|
|
49
|
+
*/
|
|
50
|
+
export type IngestBatchRequest = {
|
|
51
|
+
events: Array<FrontendEventIngestRequest>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* * `error` - Error
|
|
56
|
+
* * `warning` - Warning
|
|
57
|
+
* * `info` - Info
|
|
58
|
+
* * `debug` - Debug
|
|
59
|
+
*/
|
|
60
|
+
export enum LevelEnum {
|
|
61
|
+
ERROR = 'error',
|
|
62
|
+
WARNING = 'warning',
|
|
63
|
+
INFO = 'info',
|
|
64
|
+
DEBUG = 'debug'
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type CfgMonitorIngestCreateData = {
|
|
68
|
+
body: IngestBatchRequest;
|
|
69
|
+
path?: never;
|
|
70
|
+
query?: never;
|
|
71
|
+
url: '/cfg/monitor/ingest/';
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type CfgMonitorIngestCreateResponses = {
|
|
75
|
+
/**
|
|
76
|
+
* Accepted
|
|
77
|
+
*/
|
|
78
|
+
202: unknown;
|
|
79
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// AUTO-GENERATED by django_generator / ts_extras.wrapper
|
|
2
|
+
// Top-level barrel — one singleton API per group, baseUrl from Next.js env.
|
|
3
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
4
|
+
|
|
5
|
+
import { API as CfgMonitorAPI, LocalStorageAdapter as CfgMonitorStorage } from './cfg_monitor';
|
|
6
|
+
|
|
7
|
+
const isStaticBuild = process.env.NEXT_PUBLIC_STATIC_BUILD === 'true';
|
|
8
|
+
const baseUrl = isStaticBuild ? '' : process.env.NEXT_PUBLIC_API_URL || '';
|
|
9
|
+
|
|
10
|
+
export const cfgMonitorApi = new CfgMonitorAPI(baseUrl, { storage: new CfgMonitorStorage() });
|
|
11
|
+
|
|
12
|
+
// API wrapper classes — for users who need to construct their own
|
|
13
|
+
// instance (e.g. with MemoryStorageAdapter in SSR/tests).
|
|
14
|
+
export { API as CfgMonitorAPI } from './cfg_monitor';
|
|
15
|
+
|
|
16
|
+
// Hey API SDK classes — one per OpenAPI tag. Lets consumers call
|
|
17
|
+
// `Centrifugo.cfgCentrifugoAuthTokenRetrieve({...})` directly without
|
|
18
|
+
// going through the wrapper singleton.
|
|
19
|
+
export { Monitor } from './cfg_monitor';
|
|
20
|
+
|
|
21
|
+
// Shared utilities (errors, storage adapters, logger).
|
|
22
|
+
export * from './_shared';
|
package/src/_api/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { monitorApi, configureMonitorApi, BaseClient } from './BaseClient'
|
|
2
|
-
export type { FrontendEventIngestRequest, IngestBatchRequest } from './generated/cfg_monitor/
|
|
3
|
-
export {
|
|
2
|
+
export type { FrontendEventIngestRequest, IngestBatchRequest } from './generated/cfg_monitor/types.gen'
|
|
3
|
+
export { EventTypeEnum as EventType, LevelEnum as EventLevel } from './generated/cfg_monitor/types.gen'
|
|
4
4
|
|
|
5
5
|
/** Ingest path — matches the generated client. Single source of truth for sendBeacon fallback. */
|
|
6
6
|
export const INGEST_PATH = '/cfg/monitor/ingest/'
|
|
@@ -3,15 +3,14 @@ import { getSessionId } from './session'
|
|
|
3
3
|
import { monitorStore } from '../store'
|
|
4
4
|
import { MONITOR_INGEST_PATTERN, DEFAULT_DEDUPE_TTL } from '../constants'
|
|
5
5
|
import { EventType, EventLevel } from '../../_api'
|
|
6
|
-
import type { FrontendEventIngestRequestEventType, FrontendEventIngestRequestLevel } from '../../_api/generated/cfg_monitor/enums'
|
|
7
6
|
|
|
8
7
|
type ConsoleLevel = 'warn' | 'error'
|
|
9
8
|
|
|
10
|
-
const levelMap: Record<ConsoleLevel,
|
|
9
|
+
const levelMap: Record<ConsoleLevel, EventLevel> = {
|
|
11
10
|
warn: EventLevel.WARNING,
|
|
12
11
|
error: EventLevel.ERROR,
|
|
13
12
|
}
|
|
14
|
-
const typeMap: Record<ConsoleLevel,
|
|
13
|
+
const typeMap: Record<ConsoleLevel, EventType> = {
|
|
15
14
|
warn: EventType.WARNING,
|
|
16
15
|
error: EventType.ERROR,
|
|
17
16
|
}
|
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
import { monitorApi } from '../../_api'
|
|
2
|
-
import {
|
|
1
|
+
import { monitorApi, INGEST_PATH } from '../../_api'
|
|
2
|
+
import { Monitor } from '../../_api/generated/cfg_monitor'
|
|
3
3
|
import type { IngestBatchRequest } from '../../_api'
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
monitorApiBeacon.setBaseUrl(monitorApi.getBaseUrl())
|
|
13
|
-
}
|
|
14
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Send a batch of events to the ingest endpoint.
|
|
7
|
+
*
|
|
8
|
+
* `useBeacon=true` is for page-unload scenarios — `fetch` with `keepalive: true`
|
|
9
|
+
* lets the request survive after the document goes away (browser-supported
|
|
10
|
+
* replacement for navigator.sendBeacon when we need JSON + custom headers).
|
|
11
|
+
*/
|
|
15
12
|
export async function sendBatch(
|
|
16
13
|
batch: IngestBatchRequest,
|
|
17
14
|
useBeacon = false,
|
|
18
15
|
): Promise<void> {
|
|
19
16
|
if (batch.events.length === 0) return
|
|
20
17
|
|
|
21
|
-
if (useBeacon) {
|
|
22
|
-
|
|
23
|
-
await
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
if (useBeacon && typeof fetch !== 'undefined') {
|
|
19
|
+
const baseUrl = monitorApi.getBaseUrl()
|
|
20
|
+
await fetch(`${baseUrl}${INGEST_PATH}`, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: { 'Content-Type': 'application/json' },
|
|
23
|
+
body: JSON.stringify(batch),
|
|
24
|
+
keepalive: true,
|
|
25
|
+
credentials: 'include',
|
|
26
|
+
})
|
|
27
|
+
return
|
|
26
28
|
}
|
|
29
|
+
|
|
30
|
+
await Monitor.cfgMonitorIngestCreate({ body: batch, throwOnError: true })
|
|
27
31
|
}
|