@djangocfg/monitor 2.1.331 → 2.1.333
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 +388 -273
- package/dist/client.cjs.map +1 -1
- package/dist/client.mjs +388 -273
- package/dist/client.mjs.map +1 -1
- package/dist/index.cjs +170 -883
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +170 -883
- package/dist/index.mjs.map +1 -1
- package/dist/server.cjs +365 -250
- package/dist/server.cjs.map +1 -1
- package/dist/server.mjs +365 -250
- package/dist/server.mjs.map +1 -1
- package/package.json +2 -2
- package/src/_api/BaseClient.ts +2 -2
- package/src/_api/generated/_cfg_monitor/api.ts +29 -82
- package/src/_api/generated/_cfg_monitor/index.ts +4 -4
- package/src/_api/generated/client.gen.ts +4 -0
- package/src/_api/generated/helpers/auth.ts +240 -0
- package/src/_api/generated/helpers/index.ts +1 -0
- package/src/_api/generated/index.ts +13 -9
package/dist/client.cjs
CHANGED
|
@@ -100,6 +100,383 @@ __name(ensureSessionCookie, "ensureSessionCookie");
|
|
|
100
100
|
// src/client/store/index.ts
|
|
101
101
|
var import_vanilla = require("zustand/vanilla");
|
|
102
102
|
|
|
103
|
+
// src/_api/generated/helpers/auth.ts
|
|
104
|
+
var ACCESS_KEY = "cfg.access_token";
|
|
105
|
+
var REFRESH_KEY = "cfg.refresh_token";
|
|
106
|
+
var API_KEY_KEY = "cfg.api_key";
|
|
107
|
+
var isBrowser = typeof window !== "undefined";
|
|
108
|
+
var localStorageBackend = {
|
|
109
|
+
get(key) {
|
|
110
|
+
if (!isBrowser) return null;
|
|
111
|
+
try {
|
|
112
|
+
return window.localStorage.getItem(key);
|
|
113
|
+
} catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
set(key, value) {
|
|
118
|
+
if (!isBrowser) return;
|
|
119
|
+
try {
|
|
120
|
+
if (value === null) window.localStorage.removeItem(key);
|
|
121
|
+
else window.localStorage.setItem(key, value);
|
|
122
|
+
} catch {
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var COOKIE_MAX_AGE2 = 60 * 60 * 24 * 30;
|
|
127
|
+
var cookieBackend = {
|
|
128
|
+
get(key) {
|
|
129
|
+
if (!isBrowser) return null;
|
|
130
|
+
try {
|
|
131
|
+
const re = new RegExp(`(?:^|;\\s*)${encodeURIComponent(key)}=([^;]*)`);
|
|
132
|
+
const m = document.cookie.match(re);
|
|
133
|
+
return m ? decodeURIComponent(m[1]) : null;
|
|
134
|
+
} catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
set(key, value) {
|
|
139
|
+
if (!isBrowser) return;
|
|
140
|
+
try {
|
|
141
|
+
const k = encodeURIComponent(key);
|
|
142
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
143
|
+
if (value === null) {
|
|
144
|
+
document.cookie = `${k}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
|
|
145
|
+
} else {
|
|
146
|
+
const v = encodeURIComponent(value);
|
|
147
|
+
document.cookie = `${k}=${v}; Path=/; Max-Age=${COOKIE_MAX_AGE2}; SameSite=Lax${secure}`;
|
|
148
|
+
}
|
|
149
|
+
} catch {
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var _storage = localStorageBackend;
|
|
154
|
+
var _storageMode = "localStorage";
|
|
155
|
+
function detectLocale() {
|
|
156
|
+
try {
|
|
157
|
+
if (typeof document !== "undefined") {
|
|
158
|
+
const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
159
|
+
if (m) return decodeURIComponent(m[1]);
|
|
160
|
+
}
|
|
161
|
+
if (typeof navigator !== "undefined" && navigator.language) {
|
|
162
|
+
return navigator.language;
|
|
163
|
+
}
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
__name(detectLocale, "detectLocale");
|
|
169
|
+
function defaultBaseUrl() {
|
|
170
|
+
try {
|
|
171
|
+
if (typeof process !== "undefined" && process.env) {
|
|
172
|
+
if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
|
|
173
|
+
return process.env.NEXT_PUBLIC_API_URL || "";
|
|
174
|
+
}
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
return "";
|
|
178
|
+
}
|
|
179
|
+
__name(defaultBaseUrl, "defaultBaseUrl");
|
|
180
|
+
function defaultApiKey() {
|
|
181
|
+
try {
|
|
182
|
+
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_KEY) {
|
|
183
|
+
return process.env.NEXT_PUBLIC_API_KEY;
|
|
184
|
+
}
|
|
185
|
+
} catch {
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
__name(defaultApiKey, "defaultApiKey");
|
|
190
|
+
var _localeOverride = null;
|
|
191
|
+
var _apiKeyOverride = null;
|
|
192
|
+
var _baseUrlOverride = null;
|
|
193
|
+
var _withCredentials = true;
|
|
194
|
+
var _onUnauthorized = null;
|
|
195
|
+
var _client = null;
|
|
196
|
+
function pushClientConfig() {
|
|
197
|
+
if (!_client) return;
|
|
198
|
+
_client.setConfig({
|
|
199
|
+
baseUrl: auth.getBaseUrl(),
|
|
200
|
+
credentials: _withCredentials ? "include" : "same-origin"
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
__name(pushClientConfig, "pushClientConfig");
|
|
204
|
+
var auth = {
|
|
205
|
+
// ── Storage mode ──────────────────────────────────────────────────
|
|
206
|
+
getStorageMode() {
|
|
207
|
+
return _storageMode;
|
|
208
|
+
},
|
|
209
|
+
setStorageMode(mode) {
|
|
210
|
+
_storageMode = mode;
|
|
211
|
+
_storage = mode === "cookie" ? cookieBackend : localStorageBackend;
|
|
212
|
+
},
|
|
213
|
+
// ── Bearer token ──────────────────────────────────────────────────
|
|
214
|
+
getToken() {
|
|
215
|
+
return _storage.get(ACCESS_KEY);
|
|
216
|
+
},
|
|
217
|
+
setToken(token) {
|
|
218
|
+
_storage.set(ACCESS_KEY, token);
|
|
219
|
+
},
|
|
220
|
+
getRefreshToken() {
|
|
221
|
+
return _storage.get(REFRESH_KEY);
|
|
222
|
+
},
|
|
223
|
+
setRefreshToken(token) {
|
|
224
|
+
_storage.set(REFRESH_KEY, token);
|
|
225
|
+
},
|
|
226
|
+
clearTokens() {
|
|
227
|
+
_storage.set(ACCESS_KEY, null);
|
|
228
|
+
_storage.set(REFRESH_KEY, null);
|
|
229
|
+
},
|
|
230
|
+
isAuthenticated() {
|
|
231
|
+
return _storage.get(ACCESS_KEY) !== null;
|
|
232
|
+
},
|
|
233
|
+
// ── API key ───────────────────────────────────────────────────────
|
|
234
|
+
getApiKey() {
|
|
235
|
+
return _apiKeyOverride ?? _storage.get(API_KEY_KEY) ?? defaultApiKey();
|
|
236
|
+
},
|
|
237
|
+
setApiKey(key) {
|
|
238
|
+
_apiKeyOverride = key;
|
|
239
|
+
},
|
|
240
|
+
setApiKeyPersist(key) {
|
|
241
|
+
_apiKeyOverride = key;
|
|
242
|
+
_storage.set(API_KEY_KEY, key);
|
|
243
|
+
},
|
|
244
|
+
clearApiKey() {
|
|
245
|
+
_apiKeyOverride = null;
|
|
246
|
+
_storage.set(API_KEY_KEY, null);
|
|
247
|
+
},
|
|
248
|
+
// ── Locale ────────────────────────────────────────────────────────
|
|
249
|
+
getLocale() {
|
|
250
|
+
return _localeOverride ?? detectLocale();
|
|
251
|
+
},
|
|
252
|
+
setLocale(locale) {
|
|
253
|
+
_localeOverride = locale;
|
|
254
|
+
},
|
|
255
|
+
// ── Base URL ──────────────────────────────────────────────────────
|
|
256
|
+
getBaseUrl() {
|
|
257
|
+
const url = _baseUrlOverride ?? defaultBaseUrl();
|
|
258
|
+
return url.replace(/\/$/, "");
|
|
259
|
+
},
|
|
260
|
+
setBaseUrl(url) {
|
|
261
|
+
_baseUrlOverride = url ? url.replace(/\/$/, "") : null;
|
|
262
|
+
pushClientConfig();
|
|
263
|
+
},
|
|
264
|
+
// ── Credentials toggle ────────────────────────────────────────────
|
|
265
|
+
getWithCredentials() {
|
|
266
|
+
return _withCredentials;
|
|
267
|
+
},
|
|
268
|
+
setWithCredentials(value) {
|
|
269
|
+
_withCredentials = value;
|
|
270
|
+
pushClientConfig();
|
|
271
|
+
},
|
|
272
|
+
// ── 401 handler ───────────────────────────────────────────────────
|
|
273
|
+
onUnauthorized(cb) {
|
|
274
|
+
_onUnauthorized = cb;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
function installAuthOnClient(client2) {
|
|
278
|
+
if (_client) return;
|
|
279
|
+
_client = client2;
|
|
280
|
+
client2.setConfig({
|
|
281
|
+
baseUrl: auth.getBaseUrl(),
|
|
282
|
+
credentials: _withCredentials ? "include" : "same-origin"
|
|
283
|
+
});
|
|
284
|
+
client2.interceptors.request.use((request) => {
|
|
285
|
+
const token = auth.getToken();
|
|
286
|
+
if (token) request.headers.set("Authorization", `Bearer ${token}`);
|
|
287
|
+
const locale = auth.getLocale();
|
|
288
|
+
if (locale) request.headers.set("Accept-Language", locale);
|
|
289
|
+
const apiKey = auth.getApiKey();
|
|
290
|
+
if (apiKey) request.headers.set("X-API-Key", apiKey);
|
|
291
|
+
return request;
|
|
292
|
+
});
|
|
293
|
+
client2.interceptors.response.use((response) => {
|
|
294
|
+
if (response.status === 401 && _onUnauthorized) {
|
|
295
|
+
try {
|
|
296
|
+
_onUnauthorized(response);
|
|
297
|
+
} catch {
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return response;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
__name(installAuthOnClient, "installAuthOnClient");
|
|
304
|
+
|
|
305
|
+
// src/_api/generated/helpers/logger.ts
|
|
306
|
+
var import_consola = require("consola");
|
|
307
|
+
var DEFAULT_CONFIG = {
|
|
308
|
+
enabled: typeof process !== "undefined" && process.env.NODE_ENV !== "production",
|
|
309
|
+
logRequests: true,
|
|
310
|
+
logResponses: true,
|
|
311
|
+
logErrors: true,
|
|
312
|
+
logBodies: true,
|
|
313
|
+
logHeaders: false
|
|
314
|
+
};
|
|
315
|
+
var SENSITIVE_HEADERS = [
|
|
316
|
+
"authorization",
|
|
317
|
+
"cookie",
|
|
318
|
+
"set-cookie",
|
|
319
|
+
"x-api-key",
|
|
320
|
+
"x-csrf-token"
|
|
321
|
+
];
|
|
322
|
+
var _APILogger = class _APILogger {
|
|
323
|
+
constructor(config = {}) {
|
|
324
|
+
__publicField(this, "config");
|
|
325
|
+
__publicField(this, "consola");
|
|
326
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
327
|
+
this.consola = config.consola || (0, import_consola.createConsola)({
|
|
328
|
+
level: this.config.enabled ? 4 : 0
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
enable() {
|
|
332
|
+
this.config.enabled = true;
|
|
333
|
+
}
|
|
334
|
+
disable() {
|
|
335
|
+
this.config.enabled = false;
|
|
336
|
+
}
|
|
337
|
+
setConfig(config) {
|
|
338
|
+
this.config = { ...this.config, ...config };
|
|
339
|
+
}
|
|
340
|
+
filterHeaders(headers) {
|
|
341
|
+
if (!headers) return {};
|
|
342
|
+
const filtered = {};
|
|
343
|
+
Object.keys(headers).forEach((key) => {
|
|
344
|
+
filtered[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? "***" : headers[key] || "";
|
|
345
|
+
});
|
|
346
|
+
return filtered;
|
|
347
|
+
}
|
|
348
|
+
logRequest(request) {
|
|
349
|
+
if (!this.config.enabled || !this.config.logRequests) return;
|
|
350
|
+
const { method, url, headers, body } = request;
|
|
351
|
+
this.consola.start(`${method} ${url}`);
|
|
352
|
+
if (this.config.logHeaders && headers) this.consola.debug("Headers:", this.filterHeaders(headers));
|
|
353
|
+
if (this.config.logBodies && body) this.consola.debug("Body:", body);
|
|
354
|
+
}
|
|
355
|
+
logResponse(request, response) {
|
|
356
|
+
if (!this.config.enabled || !this.config.logResponses) return;
|
|
357
|
+
const { method, url } = request;
|
|
358
|
+
const { status, statusText, data, duration } = response;
|
|
359
|
+
this.consola.success(`${method} ${url} ${status} ${statusText} (${duration}ms)`);
|
|
360
|
+
if (this.config.logBodies && data) this.consola.debug("Response:", data);
|
|
361
|
+
}
|
|
362
|
+
logError(request, error) {
|
|
363
|
+
if (!this.config.enabled || !this.config.logErrors) return;
|
|
364
|
+
const { method, url } = request;
|
|
365
|
+
const { message, statusCode, fieldErrors, duration } = error;
|
|
366
|
+
this.consola.error(`${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`);
|
|
367
|
+
this.consola.error("Message:", message);
|
|
368
|
+
if (fieldErrors && Object.keys(fieldErrors).length > 0) {
|
|
369
|
+
this.consola.error("Field Errors:");
|
|
370
|
+
Object.entries(fieldErrors).forEach(([field, errors]) => {
|
|
371
|
+
errors.forEach((err) => this.consola.error(` \u2022 ${field}: ${err}`));
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
info(message, ...args) {
|
|
376
|
+
if (this.config.enabled) this.consola.info(message, ...args);
|
|
377
|
+
}
|
|
378
|
+
warn(message, ...args) {
|
|
379
|
+
if (this.config.enabled) this.consola.warn(message, ...args);
|
|
380
|
+
}
|
|
381
|
+
error(message, ...args) {
|
|
382
|
+
if (this.config.enabled) this.consola.error(message, ...args);
|
|
383
|
+
}
|
|
384
|
+
debug(message, ...args) {
|
|
385
|
+
if (this.config.enabled) this.consola.debug(message, ...args);
|
|
386
|
+
}
|
|
387
|
+
success(message, ...args) {
|
|
388
|
+
if (this.config.enabled) this.consola.success(message, ...args);
|
|
389
|
+
}
|
|
390
|
+
withTag(tag) {
|
|
391
|
+
return this.consola.withTag(tag);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
__name(_APILogger, "APILogger");
|
|
395
|
+
var APILogger = _APILogger;
|
|
396
|
+
var defaultLogger = new APILogger();
|
|
397
|
+
|
|
398
|
+
// src/_api/generated/_cfg_monitor/api.ts
|
|
399
|
+
var _API = class _API {
|
|
400
|
+
constructor(_baseUrl, opts = {}) {
|
|
401
|
+
__publicField(this, "logger");
|
|
402
|
+
this.logger = new APILogger(opts.logger);
|
|
403
|
+
if (_baseUrl) auth.setBaseUrl(_baseUrl);
|
|
404
|
+
if (opts.locale !== void 0) auth.setLocale(opts.locale);
|
|
405
|
+
if (opts.apiKey !== void 0) auth.setApiKey(opts.apiKey);
|
|
406
|
+
if (opts.withCredentials !== void 0) auth.setWithCredentials(opts.withCredentials);
|
|
407
|
+
}
|
|
408
|
+
// ── Base URL ────────────────────────────────────────────────────────────
|
|
409
|
+
getBaseUrl() {
|
|
410
|
+
return auth.getBaseUrl();
|
|
411
|
+
}
|
|
412
|
+
setBaseUrl(url) {
|
|
413
|
+
auth.setBaseUrl(url);
|
|
414
|
+
}
|
|
415
|
+
// ── Tokens ──────────────────────────────────────────────────────────────
|
|
416
|
+
getToken() {
|
|
417
|
+
return auth.getToken();
|
|
418
|
+
}
|
|
419
|
+
setToken(token) {
|
|
420
|
+
auth.setToken(token);
|
|
421
|
+
}
|
|
422
|
+
getRefreshToken() {
|
|
423
|
+
return auth.getRefreshToken();
|
|
424
|
+
}
|
|
425
|
+
setRefreshToken(token) {
|
|
426
|
+
auth.setRefreshToken(token);
|
|
427
|
+
}
|
|
428
|
+
clearToken() {
|
|
429
|
+
auth.clearTokens();
|
|
430
|
+
}
|
|
431
|
+
isAuthenticated() {
|
|
432
|
+
return auth.isAuthenticated();
|
|
433
|
+
}
|
|
434
|
+
// ── Locale / API key ────────────────────────────────────────────────────
|
|
435
|
+
getLocale() {
|
|
436
|
+
return auth.getLocale();
|
|
437
|
+
}
|
|
438
|
+
setLocale(locale) {
|
|
439
|
+
auth.setLocale(locale);
|
|
440
|
+
}
|
|
441
|
+
getApiKey() {
|
|
442
|
+
return auth.getApiKey();
|
|
443
|
+
}
|
|
444
|
+
setApiKey(key) {
|
|
445
|
+
auth.setApiKey(key);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
__name(_API, "API");
|
|
449
|
+
var API = _API;
|
|
450
|
+
|
|
451
|
+
// src/_api/BaseClient.ts
|
|
452
|
+
var monitorApi = new API("");
|
|
453
|
+
function configureMonitorApi(baseUrl) {
|
|
454
|
+
monitorApi.setBaseUrl(baseUrl);
|
|
455
|
+
}
|
|
456
|
+
__name(configureMonitorApi, "configureMonitorApi");
|
|
457
|
+
|
|
458
|
+
// src/_api/generated/types.gen.ts
|
|
459
|
+
var EventTypeEnum = /* @__PURE__ */ ((EventTypeEnum2) => {
|
|
460
|
+
EventTypeEnum2["JS_ERROR"] = "JS_ERROR";
|
|
461
|
+
EventTypeEnum2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
462
|
+
EventTypeEnum2["ERROR"] = "ERROR";
|
|
463
|
+
EventTypeEnum2["WARNING"] = "WARNING";
|
|
464
|
+
EventTypeEnum2["PAGE_VIEW"] = "PAGE_VIEW";
|
|
465
|
+
EventTypeEnum2["PERFORMANCE"] = "PERFORMANCE";
|
|
466
|
+
EventTypeEnum2["CONSOLE"] = "CONSOLE";
|
|
467
|
+
return EventTypeEnum2;
|
|
468
|
+
})(EventTypeEnum || {});
|
|
469
|
+
var LevelEnum = /* @__PURE__ */ ((LevelEnum2) => {
|
|
470
|
+
LevelEnum2["ERROR"] = "error";
|
|
471
|
+
LevelEnum2["WARNING"] = "warning";
|
|
472
|
+
LevelEnum2["INFO"] = "info";
|
|
473
|
+
LevelEnum2["DEBUG"] = "debug";
|
|
474
|
+
return LevelEnum2;
|
|
475
|
+
})(LevelEnum || {});
|
|
476
|
+
|
|
477
|
+
// src/_api/index.ts
|
|
478
|
+
var INGEST_PATH = "/cfg/monitor/ingest/";
|
|
479
|
+
|
|
103
480
|
// src/_api/generated/core/bodySerializer.gen.ts
|
|
104
481
|
var jsonBodySerializer = {
|
|
105
482
|
bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
|
|
@@ -465,15 +842,15 @@ function getValidRequestBody(options) {
|
|
|
465
842
|
__name(getValidRequestBody, "getValidRequestBody");
|
|
466
843
|
|
|
467
844
|
// src/_api/generated/core/auth.gen.ts
|
|
468
|
-
var getAuthToken = /* @__PURE__ */ __name(async (
|
|
469
|
-
const token = typeof callback === "function" ? await callback(
|
|
845
|
+
var getAuthToken = /* @__PURE__ */ __name(async (auth2, callback) => {
|
|
846
|
+
const token = typeof callback === "function" ? await callback(auth2) : callback;
|
|
470
847
|
if (!token) {
|
|
471
848
|
return;
|
|
472
849
|
}
|
|
473
|
-
if (
|
|
850
|
+
if (auth2.scheme === "bearer") {
|
|
474
851
|
return `Bearer ${token}`;
|
|
475
852
|
}
|
|
476
|
-
if (
|
|
853
|
+
if (auth2.scheme === "basic") {
|
|
477
854
|
return `Basic ${btoa(token)}`;
|
|
478
855
|
}
|
|
479
856
|
return token;
|
|
@@ -562,16 +939,16 @@ var setAuthParams = /* @__PURE__ */ __name(async ({
|
|
|
562
939
|
security,
|
|
563
940
|
...options
|
|
564
941
|
}) => {
|
|
565
|
-
for (const
|
|
566
|
-
if (checkForExistence(options,
|
|
942
|
+
for (const auth2 of security) {
|
|
943
|
+
if (checkForExistence(options, auth2.name)) {
|
|
567
944
|
continue;
|
|
568
945
|
}
|
|
569
|
-
const token = await getAuthToken(
|
|
946
|
+
const token = await getAuthToken(auth2, options.auth);
|
|
570
947
|
if (!token) {
|
|
571
948
|
continue;
|
|
572
949
|
}
|
|
573
|
-
const name =
|
|
574
|
-
switch (
|
|
950
|
+
const name = auth2.name ?? "Authorization";
|
|
951
|
+
switch (auth2.in) {
|
|
575
952
|
case "query":
|
|
576
953
|
if (!options.query) {
|
|
577
954
|
options.query = {};
|
|
@@ -899,269 +1276,7 @@ var createClient = /* @__PURE__ */ __name((config = {}) => {
|
|
|
899
1276
|
|
|
900
1277
|
// src/_api/generated/client.gen.ts
|
|
901
1278
|
var client = createClient(createConfig({ baseUrl: "http://localhost:8000" }));
|
|
902
|
-
|
|
903
|
-
// src/_api/generated/helpers/storage.ts
|
|
904
|
-
var _LocalStorageAdapter = class _LocalStorageAdapter {
|
|
905
|
-
getItem(key) {
|
|
906
|
-
if (typeof window === "undefined") return null;
|
|
907
|
-
try {
|
|
908
|
-
return window.localStorage.getItem(key);
|
|
909
|
-
} catch {
|
|
910
|
-
return null;
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
setItem(key, value) {
|
|
914
|
-
if (typeof window === "undefined") return;
|
|
915
|
-
try {
|
|
916
|
-
window.localStorage.setItem(key, value);
|
|
917
|
-
} catch {
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
removeItem(key) {
|
|
921
|
-
if (typeof window === "undefined") return;
|
|
922
|
-
try {
|
|
923
|
-
window.localStorage.removeItem(key);
|
|
924
|
-
} catch {
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
clear() {
|
|
928
|
-
if (typeof window === "undefined") return;
|
|
929
|
-
try {
|
|
930
|
-
window.localStorage.clear();
|
|
931
|
-
} catch {
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
__name(_LocalStorageAdapter, "LocalStorageAdapter");
|
|
936
|
-
var LocalStorageAdapter = _LocalStorageAdapter;
|
|
937
|
-
var _MemoryStorageAdapter = class _MemoryStorageAdapter {
|
|
938
|
-
constructor() {
|
|
939
|
-
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
940
|
-
}
|
|
941
|
-
getItem(key) {
|
|
942
|
-
return this.store.get(key) ?? null;
|
|
943
|
-
}
|
|
944
|
-
setItem(key, value) {
|
|
945
|
-
this.store.set(key, value);
|
|
946
|
-
}
|
|
947
|
-
removeItem(key) {
|
|
948
|
-
this.store.delete(key);
|
|
949
|
-
}
|
|
950
|
-
clear() {
|
|
951
|
-
this.store.clear();
|
|
952
|
-
}
|
|
953
|
-
};
|
|
954
|
-
__name(_MemoryStorageAdapter, "MemoryStorageAdapter");
|
|
955
|
-
var MemoryStorageAdapter = _MemoryStorageAdapter;
|
|
956
|
-
|
|
957
|
-
// src/_api/generated/helpers/logger.ts
|
|
958
|
-
var import_consola = require("consola");
|
|
959
|
-
var DEFAULT_CONFIG = {
|
|
960
|
-
enabled: typeof process !== "undefined" && process.env.NODE_ENV !== "production",
|
|
961
|
-
logRequests: true,
|
|
962
|
-
logResponses: true,
|
|
963
|
-
logErrors: true,
|
|
964
|
-
logBodies: true,
|
|
965
|
-
logHeaders: false
|
|
966
|
-
};
|
|
967
|
-
var SENSITIVE_HEADERS = [
|
|
968
|
-
"authorization",
|
|
969
|
-
"cookie",
|
|
970
|
-
"set-cookie",
|
|
971
|
-
"x-api-key",
|
|
972
|
-
"x-csrf-token"
|
|
973
|
-
];
|
|
974
|
-
var _APILogger = class _APILogger {
|
|
975
|
-
constructor(config = {}) {
|
|
976
|
-
__publicField(this, "config");
|
|
977
|
-
__publicField(this, "consola");
|
|
978
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
979
|
-
this.consola = config.consola || (0, import_consola.createConsola)({
|
|
980
|
-
level: this.config.enabled ? 4 : 0
|
|
981
|
-
});
|
|
982
|
-
}
|
|
983
|
-
enable() {
|
|
984
|
-
this.config.enabled = true;
|
|
985
|
-
}
|
|
986
|
-
disable() {
|
|
987
|
-
this.config.enabled = false;
|
|
988
|
-
}
|
|
989
|
-
setConfig(config) {
|
|
990
|
-
this.config = { ...this.config, ...config };
|
|
991
|
-
}
|
|
992
|
-
filterHeaders(headers) {
|
|
993
|
-
if (!headers) return {};
|
|
994
|
-
const filtered = {};
|
|
995
|
-
Object.keys(headers).forEach((key) => {
|
|
996
|
-
filtered[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? "***" : headers[key] || "";
|
|
997
|
-
});
|
|
998
|
-
return filtered;
|
|
999
|
-
}
|
|
1000
|
-
logRequest(request) {
|
|
1001
|
-
if (!this.config.enabled || !this.config.logRequests) return;
|
|
1002
|
-
const { method, url, headers, body } = request;
|
|
1003
|
-
this.consola.start(`${method} ${url}`);
|
|
1004
|
-
if (this.config.logHeaders && headers) this.consola.debug("Headers:", this.filterHeaders(headers));
|
|
1005
|
-
if (this.config.logBodies && body) this.consola.debug("Body:", body);
|
|
1006
|
-
}
|
|
1007
|
-
logResponse(request, response) {
|
|
1008
|
-
if (!this.config.enabled || !this.config.logResponses) return;
|
|
1009
|
-
const { method, url } = request;
|
|
1010
|
-
const { status, statusText, data, duration } = response;
|
|
1011
|
-
this.consola.success(`${method} ${url} ${status} ${statusText} (${duration}ms)`);
|
|
1012
|
-
if (this.config.logBodies && data) this.consola.debug("Response:", data);
|
|
1013
|
-
}
|
|
1014
|
-
logError(request, error) {
|
|
1015
|
-
if (!this.config.enabled || !this.config.logErrors) return;
|
|
1016
|
-
const { method, url } = request;
|
|
1017
|
-
const { message, statusCode, fieldErrors, duration } = error;
|
|
1018
|
-
this.consola.error(`${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`);
|
|
1019
|
-
this.consola.error("Message:", message);
|
|
1020
|
-
if (fieldErrors && Object.keys(fieldErrors).length > 0) {
|
|
1021
|
-
this.consola.error("Field Errors:");
|
|
1022
|
-
Object.entries(fieldErrors).forEach(([field, errors]) => {
|
|
1023
|
-
errors.forEach((err) => this.consola.error(` \u2022 ${field}: ${err}`));
|
|
1024
|
-
});
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
info(message, ...args) {
|
|
1028
|
-
if (this.config.enabled) this.consola.info(message, ...args);
|
|
1029
|
-
}
|
|
1030
|
-
warn(message, ...args) {
|
|
1031
|
-
if (this.config.enabled) this.consola.warn(message, ...args);
|
|
1032
|
-
}
|
|
1033
|
-
error(message, ...args) {
|
|
1034
|
-
if (this.config.enabled) this.consola.error(message, ...args);
|
|
1035
|
-
}
|
|
1036
|
-
debug(message, ...args) {
|
|
1037
|
-
if (this.config.enabled) this.consola.debug(message, ...args);
|
|
1038
|
-
}
|
|
1039
|
-
success(message, ...args) {
|
|
1040
|
-
if (this.config.enabled) this.consola.success(message, ...args);
|
|
1041
|
-
}
|
|
1042
|
-
withTag(tag) {
|
|
1043
|
-
return this.consola.withTag(tag);
|
|
1044
|
-
}
|
|
1045
|
-
};
|
|
1046
|
-
__name(_APILogger, "APILogger");
|
|
1047
|
-
var APILogger = _APILogger;
|
|
1048
|
-
var defaultLogger = new APILogger();
|
|
1049
|
-
|
|
1050
|
-
// src/_api/generated/_cfg_monitor/api.ts
|
|
1051
|
-
var ACCESS_KEY = "cfg.access_token";
|
|
1052
|
-
var REFRESH_KEY = "cfg.refresh_token";
|
|
1053
|
-
function detectLocale() {
|
|
1054
|
-
try {
|
|
1055
|
-
if (typeof document !== "undefined") {
|
|
1056
|
-
const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
1057
|
-
if (m) return decodeURIComponent(m[1]);
|
|
1058
|
-
}
|
|
1059
|
-
if (typeof navigator !== "undefined" && navigator.language) {
|
|
1060
|
-
return navigator.language;
|
|
1061
|
-
}
|
|
1062
|
-
} catch {
|
|
1063
|
-
}
|
|
1064
|
-
return null;
|
|
1065
|
-
}
|
|
1066
|
-
__name(detectLocale, "detectLocale");
|
|
1067
|
-
var _API = class _API {
|
|
1068
|
-
constructor(baseUrl, opts = {}) {
|
|
1069
|
-
__publicField(this, "baseUrl");
|
|
1070
|
-
__publicField(this, "storage");
|
|
1071
|
-
__publicField(this, "locale");
|
|
1072
|
-
__publicField(this, "apiKey");
|
|
1073
|
-
__publicField(this, "logger");
|
|
1074
|
-
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
1075
|
-
this.storage = opts.storage ?? new LocalStorageAdapter();
|
|
1076
|
-
this.logger = new APILogger(opts.logger);
|
|
1077
|
-
this.locale = opts.locale ?? null;
|
|
1078
|
-
this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
|
|
1079
|
-
const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
|
|
1080
|
-
client.setConfig({ baseUrl: this.baseUrl, credentials });
|
|
1081
|
-
client.interceptors.request.use((request) => {
|
|
1082
|
-
const access = this.getToken();
|
|
1083
|
-
if (access) request.headers.set("Authorization", `Bearer ${access}`);
|
|
1084
|
-
const locale = this.locale ?? detectLocale();
|
|
1085
|
-
if (locale) request.headers.set("Accept-Language", locale);
|
|
1086
|
-
if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
|
|
1087
|
-
return request;
|
|
1088
|
-
});
|
|
1089
|
-
}
|
|
1090
|
-
// ── Base URL ────────────────────────────────────────────────────────────
|
|
1091
|
-
getBaseUrl() {
|
|
1092
|
-
return this.baseUrl;
|
|
1093
|
-
}
|
|
1094
|
-
setBaseUrl(url) {
|
|
1095
|
-
this.baseUrl = url.replace(/\/$/, "");
|
|
1096
|
-
client.setConfig({ baseUrl: this.baseUrl });
|
|
1097
|
-
}
|
|
1098
|
-
// ── Tokens ──────────────────────────────────────────────────────────────
|
|
1099
|
-
getToken() {
|
|
1100
|
-
return this.storage.getItem(ACCESS_KEY);
|
|
1101
|
-
}
|
|
1102
|
-
setToken(token) {
|
|
1103
|
-
if (token) this.storage.setItem(ACCESS_KEY, token);
|
|
1104
|
-
else this.storage.removeItem(ACCESS_KEY);
|
|
1105
|
-
}
|
|
1106
|
-
getRefreshToken() {
|
|
1107
|
-
return this.storage.getItem(REFRESH_KEY);
|
|
1108
|
-
}
|
|
1109
|
-
setRefreshToken(token) {
|
|
1110
|
-
if (token) this.storage.setItem(REFRESH_KEY, token);
|
|
1111
|
-
else this.storage.removeItem(REFRESH_KEY);
|
|
1112
|
-
}
|
|
1113
|
-
clearToken() {
|
|
1114
|
-
this.storage.removeItem(ACCESS_KEY);
|
|
1115
|
-
this.storage.removeItem(REFRESH_KEY);
|
|
1116
|
-
}
|
|
1117
|
-
isAuthenticated() {
|
|
1118
|
-
return this.getToken() !== null;
|
|
1119
|
-
}
|
|
1120
|
-
// ── Locale / API key ────────────────────────────────────────────────────
|
|
1121
|
-
getLocale() {
|
|
1122
|
-
return this.locale ?? detectLocale();
|
|
1123
|
-
}
|
|
1124
|
-
setLocale(locale) {
|
|
1125
|
-
this.locale = locale;
|
|
1126
|
-
}
|
|
1127
|
-
getApiKey() {
|
|
1128
|
-
return this.apiKey;
|
|
1129
|
-
}
|
|
1130
|
-
setApiKey(key) {
|
|
1131
|
-
this.apiKey = key;
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
__name(_API, "API");
|
|
1135
|
-
var API = _API;
|
|
1136
|
-
|
|
1137
|
-
// src/_api/BaseClient.ts
|
|
1138
|
-
var monitorApi = new API("", { storage: new MemoryStorageAdapter() });
|
|
1139
|
-
function configureMonitorApi(baseUrl) {
|
|
1140
|
-
monitorApi.setBaseUrl(baseUrl);
|
|
1141
|
-
}
|
|
1142
|
-
__name(configureMonitorApi, "configureMonitorApi");
|
|
1143
|
-
|
|
1144
|
-
// src/_api/generated/types.gen.ts
|
|
1145
|
-
var EventTypeEnum = /* @__PURE__ */ ((EventTypeEnum2) => {
|
|
1146
|
-
EventTypeEnum2["JS_ERROR"] = "JS_ERROR";
|
|
1147
|
-
EventTypeEnum2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
1148
|
-
EventTypeEnum2["ERROR"] = "ERROR";
|
|
1149
|
-
EventTypeEnum2["WARNING"] = "WARNING";
|
|
1150
|
-
EventTypeEnum2["PAGE_VIEW"] = "PAGE_VIEW";
|
|
1151
|
-
EventTypeEnum2["PERFORMANCE"] = "PERFORMANCE";
|
|
1152
|
-
EventTypeEnum2["CONSOLE"] = "CONSOLE";
|
|
1153
|
-
return EventTypeEnum2;
|
|
1154
|
-
})(EventTypeEnum || {});
|
|
1155
|
-
var LevelEnum = /* @__PURE__ */ ((LevelEnum2) => {
|
|
1156
|
-
LevelEnum2["ERROR"] = "error";
|
|
1157
|
-
LevelEnum2["WARNING"] = "warning";
|
|
1158
|
-
LevelEnum2["INFO"] = "info";
|
|
1159
|
-
LevelEnum2["DEBUG"] = "debug";
|
|
1160
|
-
return LevelEnum2;
|
|
1161
|
-
})(LevelEnum || {});
|
|
1162
|
-
|
|
1163
|
-
// src/_api/index.ts
|
|
1164
|
-
var INGEST_PATH = "/cfg/monitor/ingest/";
|
|
1279
|
+
installAuthOnClient(client);
|
|
1165
1280
|
|
|
1166
1281
|
// src/_api/generated/sdk.gen.ts
|
|
1167
1282
|
var _Monitor = class _Monitor {
|
|
@@ -1205,7 +1320,7 @@ __name(sendBatch, "sendBatch");
|
|
|
1205
1320
|
// src/client/utils/env.ts
|
|
1206
1321
|
var isDevelopment = process.env.NODE_ENV === "development";
|
|
1207
1322
|
var isProduction = !isDevelopment;
|
|
1208
|
-
var MONITOR_VERSION = "2.1.
|
|
1323
|
+
var MONITOR_VERSION = "2.1.333";
|
|
1209
1324
|
|
|
1210
1325
|
// src/client/constants.ts
|
|
1211
1326
|
var MONITOR_INGEST_PATTERN = /cfg\/monitor\/ingest/;
|