@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/server.cjs
CHANGED
|
@@ -26,6 +26,361 @@ __export(server_exports, {
|
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(server_exports);
|
|
28
28
|
|
|
29
|
+
// src/_api/generated/helpers/auth.ts
|
|
30
|
+
var ACCESS_KEY = "cfg.access_token";
|
|
31
|
+
var REFRESH_KEY = "cfg.refresh_token";
|
|
32
|
+
var API_KEY_KEY = "cfg.api_key";
|
|
33
|
+
var isBrowser = typeof window !== "undefined";
|
|
34
|
+
var localStorageBackend = {
|
|
35
|
+
get(key) {
|
|
36
|
+
if (!isBrowser) return null;
|
|
37
|
+
try {
|
|
38
|
+
return window.localStorage.getItem(key);
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
set(key, value) {
|
|
44
|
+
if (!isBrowser) return;
|
|
45
|
+
try {
|
|
46
|
+
if (value === null) window.localStorage.removeItem(key);
|
|
47
|
+
else window.localStorage.setItem(key, value);
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
|
|
53
|
+
var cookieBackend = {
|
|
54
|
+
get(key) {
|
|
55
|
+
if (!isBrowser) return null;
|
|
56
|
+
try {
|
|
57
|
+
const re = new RegExp(`(?:^|;\\s*)${encodeURIComponent(key)}=([^;]*)`);
|
|
58
|
+
const m = document.cookie.match(re);
|
|
59
|
+
return m ? decodeURIComponent(m[1]) : null;
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
set(key, value) {
|
|
65
|
+
if (!isBrowser) return;
|
|
66
|
+
try {
|
|
67
|
+
const k = encodeURIComponent(key);
|
|
68
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
69
|
+
if (value === null) {
|
|
70
|
+
document.cookie = `${k}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
|
|
71
|
+
} else {
|
|
72
|
+
const v = encodeURIComponent(value);
|
|
73
|
+
document.cookie = `${k}=${v}; Path=/; Max-Age=${COOKIE_MAX_AGE}; SameSite=Lax${secure}`;
|
|
74
|
+
}
|
|
75
|
+
} catch {
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var _storage = localStorageBackend;
|
|
80
|
+
var _storageMode = "localStorage";
|
|
81
|
+
function detectLocale() {
|
|
82
|
+
try {
|
|
83
|
+
if (typeof document !== "undefined") {
|
|
84
|
+
const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
85
|
+
if (m) return decodeURIComponent(m[1]);
|
|
86
|
+
}
|
|
87
|
+
if (typeof navigator !== "undefined" && navigator.language) {
|
|
88
|
+
return navigator.language;
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
__name(detectLocale, "detectLocale");
|
|
95
|
+
function defaultBaseUrl() {
|
|
96
|
+
try {
|
|
97
|
+
if (typeof process !== "undefined" && process.env) {
|
|
98
|
+
if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
|
|
99
|
+
return process.env.NEXT_PUBLIC_API_URL || "";
|
|
100
|
+
}
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
return "";
|
|
104
|
+
}
|
|
105
|
+
__name(defaultBaseUrl, "defaultBaseUrl");
|
|
106
|
+
function defaultApiKey() {
|
|
107
|
+
try {
|
|
108
|
+
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_KEY) {
|
|
109
|
+
return process.env.NEXT_PUBLIC_API_KEY;
|
|
110
|
+
}
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
__name(defaultApiKey, "defaultApiKey");
|
|
116
|
+
var _localeOverride = null;
|
|
117
|
+
var _apiKeyOverride = null;
|
|
118
|
+
var _baseUrlOverride = null;
|
|
119
|
+
var _withCredentials = true;
|
|
120
|
+
var _onUnauthorized = null;
|
|
121
|
+
var _client = null;
|
|
122
|
+
function pushClientConfig() {
|
|
123
|
+
if (!_client) return;
|
|
124
|
+
_client.setConfig({
|
|
125
|
+
baseUrl: auth.getBaseUrl(),
|
|
126
|
+
credentials: _withCredentials ? "include" : "same-origin"
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
__name(pushClientConfig, "pushClientConfig");
|
|
130
|
+
var auth = {
|
|
131
|
+
// ── Storage mode ──────────────────────────────────────────────────
|
|
132
|
+
getStorageMode() {
|
|
133
|
+
return _storageMode;
|
|
134
|
+
},
|
|
135
|
+
setStorageMode(mode) {
|
|
136
|
+
_storageMode = mode;
|
|
137
|
+
_storage = mode === "cookie" ? cookieBackend : localStorageBackend;
|
|
138
|
+
},
|
|
139
|
+
// ── Bearer token ──────────────────────────────────────────────────
|
|
140
|
+
getToken() {
|
|
141
|
+
return _storage.get(ACCESS_KEY);
|
|
142
|
+
},
|
|
143
|
+
setToken(token) {
|
|
144
|
+
_storage.set(ACCESS_KEY, token);
|
|
145
|
+
},
|
|
146
|
+
getRefreshToken() {
|
|
147
|
+
return _storage.get(REFRESH_KEY);
|
|
148
|
+
},
|
|
149
|
+
setRefreshToken(token) {
|
|
150
|
+
_storage.set(REFRESH_KEY, token);
|
|
151
|
+
},
|
|
152
|
+
clearTokens() {
|
|
153
|
+
_storage.set(ACCESS_KEY, null);
|
|
154
|
+
_storage.set(REFRESH_KEY, null);
|
|
155
|
+
},
|
|
156
|
+
isAuthenticated() {
|
|
157
|
+
return _storage.get(ACCESS_KEY) !== null;
|
|
158
|
+
},
|
|
159
|
+
// ── API key ───────────────────────────────────────────────────────
|
|
160
|
+
getApiKey() {
|
|
161
|
+
return _apiKeyOverride ?? _storage.get(API_KEY_KEY) ?? defaultApiKey();
|
|
162
|
+
},
|
|
163
|
+
setApiKey(key) {
|
|
164
|
+
_apiKeyOverride = key;
|
|
165
|
+
},
|
|
166
|
+
setApiKeyPersist(key) {
|
|
167
|
+
_apiKeyOverride = key;
|
|
168
|
+
_storage.set(API_KEY_KEY, key);
|
|
169
|
+
},
|
|
170
|
+
clearApiKey() {
|
|
171
|
+
_apiKeyOverride = null;
|
|
172
|
+
_storage.set(API_KEY_KEY, null);
|
|
173
|
+
},
|
|
174
|
+
// ── Locale ────────────────────────────────────────────────────────
|
|
175
|
+
getLocale() {
|
|
176
|
+
return _localeOverride ?? detectLocale();
|
|
177
|
+
},
|
|
178
|
+
setLocale(locale) {
|
|
179
|
+
_localeOverride = locale;
|
|
180
|
+
},
|
|
181
|
+
// ── Base URL ──────────────────────────────────────────────────────
|
|
182
|
+
getBaseUrl() {
|
|
183
|
+
const url = _baseUrlOverride ?? defaultBaseUrl();
|
|
184
|
+
return url.replace(/\/$/, "");
|
|
185
|
+
},
|
|
186
|
+
setBaseUrl(url) {
|
|
187
|
+
_baseUrlOverride = url ? url.replace(/\/$/, "") : null;
|
|
188
|
+
pushClientConfig();
|
|
189
|
+
},
|
|
190
|
+
// ── Credentials toggle ────────────────────────────────────────────
|
|
191
|
+
getWithCredentials() {
|
|
192
|
+
return _withCredentials;
|
|
193
|
+
},
|
|
194
|
+
setWithCredentials(value) {
|
|
195
|
+
_withCredentials = value;
|
|
196
|
+
pushClientConfig();
|
|
197
|
+
},
|
|
198
|
+
// ── 401 handler ───────────────────────────────────────────────────
|
|
199
|
+
onUnauthorized(cb) {
|
|
200
|
+
_onUnauthorized = cb;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
function installAuthOnClient(client2) {
|
|
204
|
+
if (_client) return;
|
|
205
|
+
_client = client2;
|
|
206
|
+
client2.setConfig({
|
|
207
|
+
baseUrl: auth.getBaseUrl(),
|
|
208
|
+
credentials: _withCredentials ? "include" : "same-origin"
|
|
209
|
+
});
|
|
210
|
+
client2.interceptors.request.use((request) => {
|
|
211
|
+
const token = auth.getToken();
|
|
212
|
+
if (token) request.headers.set("Authorization", `Bearer ${token}`);
|
|
213
|
+
const locale = auth.getLocale();
|
|
214
|
+
if (locale) request.headers.set("Accept-Language", locale);
|
|
215
|
+
const apiKey = auth.getApiKey();
|
|
216
|
+
if (apiKey) request.headers.set("X-API-Key", apiKey);
|
|
217
|
+
return request;
|
|
218
|
+
});
|
|
219
|
+
client2.interceptors.response.use((response) => {
|
|
220
|
+
if (response.status === 401 && _onUnauthorized) {
|
|
221
|
+
try {
|
|
222
|
+
_onUnauthorized(response);
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return response;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
__name(installAuthOnClient, "installAuthOnClient");
|
|
230
|
+
|
|
231
|
+
// src/_api/generated/helpers/logger.ts
|
|
232
|
+
var import_consola = require("consola");
|
|
233
|
+
var DEFAULT_CONFIG = {
|
|
234
|
+
enabled: typeof process !== "undefined" && process.env.NODE_ENV !== "production",
|
|
235
|
+
logRequests: true,
|
|
236
|
+
logResponses: true,
|
|
237
|
+
logErrors: true,
|
|
238
|
+
logBodies: true,
|
|
239
|
+
logHeaders: false
|
|
240
|
+
};
|
|
241
|
+
var SENSITIVE_HEADERS = [
|
|
242
|
+
"authorization",
|
|
243
|
+
"cookie",
|
|
244
|
+
"set-cookie",
|
|
245
|
+
"x-api-key",
|
|
246
|
+
"x-csrf-token"
|
|
247
|
+
];
|
|
248
|
+
var _APILogger = class _APILogger {
|
|
249
|
+
constructor(config = {}) {
|
|
250
|
+
__publicField(this, "config");
|
|
251
|
+
__publicField(this, "consola");
|
|
252
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
253
|
+
this.consola = config.consola || (0, import_consola.createConsola)({
|
|
254
|
+
level: this.config.enabled ? 4 : 0
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
enable() {
|
|
258
|
+
this.config.enabled = true;
|
|
259
|
+
}
|
|
260
|
+
disable() {
|
|
261
|
+
this.config.enabled = false;
|
|
262
|
+
}
|
|
263
|
+
setConfig(config) {
|
|
264
|
+
this.config = { ...this.config, ...config };
|
|
265
|
+
}
|
|
266
|
+
filterHeaders(headers) {
|
|
267
|
+
if (!headers) return {};
|
|
268
|
+
const filtered = {};
|
|
269
|
+
Object.keys(headers).forEach((key) => {
|
|
270
|
+
filtered[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? "***" : headers[key] || "";
|
|
271
|
+
});
|
|
272
|
+
return filtered;
|
|
273
|
+
}
|
|
274
|
+
logRequest(request) {
|
|
275
|
+
if (!this.config.enabled || !this.config.logRequests) return;
|
|
276
|
+
const { method, url, headers, body } = request;
|
|
277
|
+
this.consola.start(`${method} ${url}`);
|
|
278
|
+
if (this.config.logHeaders && headers) this.consola.debug("Headers:", this.filterHeaders(headers));
|
|
279
|
+
if (this.config.logBodies && body) this.consola.debug("Body:", body);
|
|
280
|
+
}
|
|
281
|
+
logResponse(request, response) {
|
|
282
|
+
if (!this.config.enabled || !this.config.logResponses) return;
|
|
283
|
+
const { method, url } = request;
|
|
284
|
+
const { status, statusText, data, duration } = response;
|
|
285
|
+
this.consola.success(`${method} ${url} ${status} ${statusText} (${duration}ms)`);
|
|
286
|
+
if (this.config.logBodies && data) this.consola.debug("Response:", data);
|
|
287
|
+
}
|
|
288
|
+
logError(request, error) {
|
|
289
|
+
if (!this.config.enabled || !this.config.logErrors) return;
|
|
290
|
+
const { method, url } = request;
|
|
291
|
+
const { message, statusCode, fieldErrors, duration } = error;
|
|
292
|
+
this.consola.error(`${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`);
|
|
293
|
+
this.consola.error("Message:", message);
|
|
294
|
+
if (fieldErrors && Object.keys(fieldErrors).length > 0) {
|
|
295
|
+
this.consola.error("Field Errors:");
|
|
296
|
+
Object.entries(fieldErrors).forEach(([field, errors]) => {
|
|
297
|
+
errors.forEach((err) => this.consola.error(` \u2022 ${field}: ${err}`));
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
info(message, ...args) {
|
|
302
|
+
if (this.config.enabled) this.consola.info(message, ...args);
|
|
303
|
+
}
|
|
304
|
+
warn(message, ...args) {
|
|
305
|
+
if (this.config.enabled) this.consola.warn(message, ...args);
|
|
306
|
+
}
|
|
307
|
+
error(message, ...args) {
|
|
308
|
+
if (this.config.enabled) this.consola.error(message, ...args);
|
|
309
|
+
}
|
|
310
|
+
debug(message, ...args) {
|
|
311
|
+
if (this.config.enabled) this.consola.debug(message, ...args);
|
|
312
|
+
}
|
|
313
|
+
success(message, ...args) {
|
|
314
|
+
if (this.config.enabled) this.consola.success(message, ...args);
|
|
315
|
+
}
|
|
316
|
+
withTag(tag) {
|
|
317
|
+
return this.consola.withTag(tag);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
__name(_APILogger, "APILogger");
|
|
321
|
+
var APILogger = _APILogger;
|
|
322
|
+
var defaultLogger = new APILogger();
|
|
323
|
+
|
|
324
|
+
// src/_api/generated/_cfg_monitor/api.ts
|
|
325
|
+
var _API = class _API {
|
|
326
|
+
constructor(_baseUrl, opts = {}) {
|
|
327
|
+
__publicField(this, "logger");
|
|
328
|
+
this.logger = new APILogger(opts.logger);
|
|
329
|
+
if (_baseUrl) auth.setBaseUrl(_baseUrl);
|
|
330
|
+
if (opts.locale !== void 0) auth.setLocale(opts.locale);
|
|
331
|
+
if (opts.apiKey !== void 0) auth.setApiKey(opts.apiKey);
|
|
332
|
+
if (opts.withCredentials !== void 0) auth.setWithCredentials(opts.withCredentials);
|
|
333
|
+
}
|
|
334
|
+
// ── Base URL ────────────────────────────────────────────────────────────
|
|
335
|
+
getBaseUrl() {
|
|
336
|
+
return auth.getBaseUrl();
|
|
337
|
+
}
|
|
338
|
+
setBaseUrl(url) {
|
|
339
|
+
auth.setBaseUrl(url);
|
|
340
|
+
}
|
|
341
|
+
// ── Tokens ──────────────────────────────────────────────────────────────
|
|
342
|
+
getToken() {
|
|
343
|
+
return auth.getToken();
|
|
344
|
+
}
|
|
345
|
+
setToken(token) {
|
|
346
|
+
auth.setToken(token);
|
|
347
|
+
}
|
|
348
|
+
getRefreshToken() {
|
|
349
|
+
return auth.getRefreshToken();
|
|
350
|
+
}
|
|
351
|
+
setRefreshToken(token) {
|
|
352
|
+
auth.setRefreshToken(token);
|
|
353
|
+
}
|
|
354
|
+
clearToken() {
|
|
355
|
+
auth.clearTokens();
|
|
356
|
+
}
|
|
357
|
+
isAuthenticated() {
|
|
358
|
+
return auth.isAuthenticated();
|
|
359
|
+
}
|
|
360
|
+
// ── Locale / API key ────────────────────────────────────────────────────
|
|
361
|
+
getLocale() {
|
|
362
|
+
return auth.getLocale();
|
|
363
|
+
}
|
|
364
|
+
setLocale(locale) {
|
|
365
|
+
auth.setLocale(locale);
|
|
366
|
+
}
|
|
367
|
+
getApiKey() {
|
|
368
|
+
return auth.getApiKey();
|
|
369
|
+
}
|
|
370
|
+
setApiKey(key) {
|
|
371
|
+
auth.setApiKey(key);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
__name(_API, "API");
|
|
375
|
+
var API = _API;
|
|
376
|
+
|
|
377
|
+
// src/_api/BaseClient.ts
|
|
378
|
+
var monitorApi = new API("");
|
|
379
|
+
function configureMonitorApi(baseUrl) {
|
|
380
|
+
monitorApi.setBaseUrl(baseUrl);
|
|
381
|
+
}
|
|
382
|
+
__name(configureMonitorApi, "configureMonitorApi");
|
|
383
|
+
|
|
29
384
|
// src/_api/generated/core/bodySerializer.gen.ts
|
|
30
385
|
var jsonBodySerializer = {
|
|
31
386
|
bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
|
|
@@ -391,15 +746,15 @@ function getValidRequestBody(options) {
|
|
|
391
746
|
__name(getValidRequestBody, "getValidRequestBody");
|
|
392
747
|
|
|
393
748
|
// src/_api/generated/core/auth.gen.ts
|
|
394
|
-
var getAuthToken = /* @__PURE__ */ __name(async (
|
|
395
|
-
const token = typeof callback === "function" ? await callback(
|
|
749
|
+
var getAuthToken = /* @__PURE__ */ __name(async (auth2, callback) => {
|
|
750
|
+
const token = typeof callback === "function" ? await callback(auth2) : callback;
|
|
396
751
|
if (!token) {
|
|
397
752
|
return;
|
|
398
753
|
}
|
|
399
|
-
if (
|
|
754
|
+
if (auth2.scheme === "bearer") {
|
|
400
755
|
return `Bearer ${token}`;
|
|
401
756
|
}
|
|
402
|
-
if (
|
|
757
|
+
if (auth2.scheme === "basic") {
|
|
403
758
|
return `Basic ${btoa(token)}`;
|
|
404
759
|
}
|
|
405
760
|
return token;
|
|
@@ -488,16 +843,16 @@ var setAuthParams = /* @__PURE__ */ __name(async ({
|
|
|
488
843
|
security,
|
|
489
844
|
...options
|
|
490
845
|
}) => {
|
|
491
|
-
for (const
|
|
492
|
-
if (checkForExistence(options,
|
|
846
|
+
for (const auth2 of security) {
|
|
847
|
+
if (checkForExistence(options, auth2.name)) {
|
|
493
848
|
continue;
|
|
494
849
|
}
|
|
495
|
-
const token = await getAuthToken(
|
|
850
|
+
const token = await getAuthToken(auth2, options.auth);
|
|
496
851
|
if (!token) {
|
|
497
852
|
continue;
|
|
498
853
|
}
|
|
499
|
-
const name =
|
|
500
|
-
switch (
|
|
854
|
+
const name = auth2.name ?? "Authorization";
|
|
855
|
+
switch (auth2.in) {
|
|
501
856
|
case "query":
|
|
502
857
|
if (!options.query) {
|
|
503
858
|
options.query = {};
|
|
@@ -825,247 +1180,7 @@ var createClient = /* @__PURE__ */ __name((config = {}) => {
|
|
|
825
1180
|
|
|
826
1181
|
// src/_api/generated/client.gen.ts
|
|
827
1182
|
var client = createClient(createConfig({ baseUrl: "http://localhost:8000" }));
|
|
828
|
-
|
|
829
|
-
// src/_api/generated/helpers/storage.ts
|
|
830
|
-
var _LocalStorageAdapter = class _LocalStorageAdapter {
|
|
831
|
-
getItem(key) {
|
|
832
|
-
if (typeof window === "undefined") return null;
|
|
833
|
-
try {
|
|
834
|
-
return window.localStorage.getItem(key);
|
|
835
|
-
} catch {
|
|
836
|
-
return null;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
setItem(key, value) {
|
|
840
|
-
if (typeof window === "undefined") return;
|
|
841
|
-
try {
|
|
842
|
-
window.localStorage.setItem(key, value);
|
|
843
|
-
} catch {
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
removeItem(key) {
|
|
847
|
-
if (typeof window === "undefined") return;
|
|
848
|
-
try {
|
|
849
|
-
window.localStorage.removeItem(key);
|
|
850
|
-
} catch {
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
clear() {
|
|
854
|
-
if (typeof window === "undefined") return;
|
|
855
|
-
try {
|
|
856
|
-
window.localStorage.clear();
|
|
857
|
-
} catch {
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
__name(_LocalStorageAdapter, "LocalStorageAdapter");
|
|
862
|
-
var LocalStorageAdapter = _LocalStorageAdapter;
|
|
863
|
-
var _MemoryStorageAdapter = class _MemoryStorageAdapter {
|
|
864
|
-
constructor() {
|
|
865
|
-
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
866
|
-
}
|
|
867
|
-
getItem(key) {
|
|
868
|
-
return this.store.get(key) ?? null;
|
|
869
|
-
}
|
|
870
|
-
setItem(key, value) {
|
|
871
|
-
this.store.set(key, value);
|
|
872
|
-
}
|
|
873
|
-
removeItem(key) {
|
|
874
|
-
this.store.delete(key);
|
|
875
|
-
}
|
|
876
|
-
clear() {
|
|
877
|
-
this.store.clear();
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
__name(_MemoryStorageAdapter, "MemoryStorageAdapter");
|
|
881
|
-
var MemoryStorageAdapter = _MemoryStorageAdapter;
|
|
882
|
-
|
|
883
|
-
// src/_api/generated/helpers/logger.ts
|
|
884
|
-
var import_consola = require("consola");
|
|
885
|
-
var DEFAULT_CONFIG = {
|
|
886
|
-
enabled: typeof process !== "undefined" && process.env.NODE_ENV !== "production",
|
|
887
|
-
logRequests: true,
|
|
888
|
-
logResponses: true,
|
|
889
|
-
logErrors: true,
|
|
890
|
-
logBodies: true,
|
|
891
|
-
logHeaders: false
|
|
892
|
-
};
|
|
893
|
-
var SENSITIVE_HEADERS = [
|
|
894
|
-
"authorization",
|
|
895
|
-
"cookie",
|
|
896
|
-
"set-cookie",
|
|
897
|
-
"x-api-key",
|
|
898
|
-
"x-csrf-token"
|
|
899
|
-
];
|
|
900
|
-
var _APILogger = class _APILogger {
|
|
901
|
-
constructor(config = {}) {
|
|
902
|
-
__publicField(this, "config");
|
|
903
|
-
__publicField(this, "consola");
|
|
904
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
905
|
-
this.consola = config.consola || (0, import_consola.createConsola)({
|
|
906
|
-
level: this.config.enabled ? 4 : 0
|
|
907
|
-
});
|
|
908
|
-
}
|
|
909
|
-
enable() {
|
|
910
|
-
this.config.enabled = true;
|
|
911
|
-
}
|
|
912
|
-
disable() {
|
|
913
|
-
this.config.enabled = false;
|
|
914
|
-
}
|
|
915
|
-
setConfig(config) {
|
|
916
|
-
this.config = { ...this.config, ...config };
|
|
917
|
-
}
|
|
918
|
-
filterHeaders(headers) {
|
|
919
|
-
if (!headers) return {};
|
|
920
|
-
const filtered = {};
|
|
921
|
-
Object.keys(headers).forEach((key) => {
|
|
922
|
-
filtered[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? "***" : headers[key] || "";
|
|
923
|
-
});
|
|
924
|
-
return filtered;
|
|
925
|
-
}
|
|
926
|
-
logRequest(request) {
|
|
927
|
-
if (!this.config.enabled || !this.config.logRequests) return;
|
|
928
|
-
const { method, url, headers, body } = request;
|
|
929
|
-
this.consola.start(`${method} ${url}`);
|
|
930
|
-
if (this.config.logHeaders && headers) this.consola.debug("Headers:", this.filterHeaders(headers));
|
|
931
|
-
if (this.config.logBodies && body) this.consola.debug("Body:", body);
|
|
932
|
-
}
|
|
933
|
-
logResponse(request, response) {
|
|
934
|
-
if (!this.config.enabled || !this.config.logResponses) return;
|
|
935
|
-
const { method, url } = request;
|
|
936
|
-
const { status, statusText, data, duration } = response;
|
|
937
|
-
this.consola.success(`${method} ${url} ${status} ${statusText} (${duration}ms)`);
|
|
938
|
-
if (this.config.logBodies && data) this.consola.debug("Response:", data);
|
|
939
|
-
}
|
|
940
|
-
logError(request, error) {
|
|
941
|
-
if (!this.config.enabled || !this.config.logErrors) return;
|
|
942
|
-
const { method, url } = request;
|
|
943
|
-
const { message, statusCode, fieldErrors, duration } = error;
|
|
944
|
-
this.consola.error(`${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`);
|
|
945
|
-
this.consola.error("Message:", message);
|
|
946
|
-
if (fieldErrors && Object.keys(fieldErrors).length > 0) {
|
|
947
|
-
this.consola.error("Field Errors:");
|
|
948
|
-
Object.entries(fieldErrors).forEach(([field, errors]) => {
|
|
949
|
-
errors.forEach((err) => this.consola.error(` \u2022 ${field}: ${err}`));
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
info(message, ...args) {
|
|
954
|
-
if (this.config.enabled) this.consola.info(message, ...args);
|
|
955
|
-
}
|
|
956
|
-
warn(message, ...args) {
|
|
957
|
-
if (this.config.enabled) this.consola.warn(message, ...args);
|
|
958
|
-
}
|
|
959
|
-
error(message, ...args) {
|
|
960
|
-
if (this.config.enabled) this.consola.error(message, ...args);
|
|
961
|
-
}
|
|
962
|
-
debug(message, ...args) {
|
|
963
|
-
if (this.config.enabled) this.consola.debug(message, ...args);
|
|
964
|
-
}
|
|
965
|
-
success(message, ...args) {
|
|
966
|
-
if (this.config.enabled) this.consola.success(message, ...args);
|
|
967
|
-
}
|
|
968
|
-
withTag(tag) {
|
|
969
|
-
return this.consola.withTag(tag);
|
|
970
|
-
}
|
|
971
|
-
};
|
|
972
|
-
__name(_APILogger, "APILogger");
|
|
973
|
-
var APILogger = _APILogger;
|
|
974
|
-
var defaultLogger = new APILogger();
|
|
975
|
-
|
|
976
|
-
// src/_api/generated/_cfg_monitor/api.ts
|
|
977
|
-
var ACCESS_KEY = "cfg.access_token";
|
|
978
|
-
var REFRESH_KEY = "cfg.refresh_token";
|
|
979
|
-
function detectLocale() {
|
|
980
|
-
try {
|
|
981
|
-
if (typeof document !== "undefined") {
|
|
982
|
-
const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
983
|
-
if (m) return decodeURIComponent(m[1]);
|
|
984
|
-
}
|
|
985
|
-
if (typeof navigator !== "undefined" && navigator.language) {
|
|
986
|
-
return navigator.language;
|
|
987
|
-
}
|
|
988
|
-
} catch {
|
|
989
|
-
}
|
|
990
|
-
return null;
|
|
991
|
-
}
|
|
992
|
-
__name(detectLocale, "detectLocale");
|
|
993
|
-
var _API = class _API {
|
|
994
|
-
constructor(baseUrl, opts = {}) {
|
|
995
|
-
__publicField(this, "baseUrl");
|
|
996
|
-
__publicField(this, "storage");
|
|
997
|
-
__publicField(this, "locale");
|
|
998
|
-
__publicField(this, "apiKey");
|
|
999
|
-
__publicField(this, "logger");
|
|
1000
|
-
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
1001
|
-
this.storage = opts.storage ?? new LocalStorageAdapter();
|
|
1002
|
-
this.logger = new APILogger(opts.logger);
|
|
1003
|
-
this.locale = opts.locale ?? null;
|
|
1004
|
-
this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
|
|
1005
|
-
const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
|
|
1006
|
-
client.setConfig({ baseUrl: this.baseUrl, credentials });
|
|
1007
|
-
client.interceptors.request.use((request) => {
|
|
1008
|
-
const access = this.getToken();
|
|
1009
|
-
if (access) request.headers.set("Authorization", `Bearer ${access}`);
|
|
1010
|
-
const locale = this.locale ?? detectLocale();
|
|
1011
|
-
if (locale) request.headers.set("Accept-Language", locale);
|
|
1012
|
-
if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
|
|
1013
|
-
return request;
|
|
1014
|
-
});
|
|
1015
|
-
}
|
|
1016
|
-
// ── Base URL ────────────────────────────────────────────────────────────
|
|
1017
|
-
getBaseUrl() {
|
|
1018
|
-
return this.baseUrl;
|
|
1019
|
-
}
|
|
1020
|
-
setBaseUrl(url) {
|
|
1021
|
-
this.baseUrl = url.replace(/\/$/, "");
|
|
1022
|
-
client.setConfig({ baseUrl: this.baseUrl });
|
|
1023
|
-
}
|
|
1024
|
-
// ── Tokens ──────────────────────────────────────────────────────────────
|
|
1025
|
-
getToken() {
|
|
1026
|
-
return this.storage.getItem(ACCESS_KEY);
|
|
1027
|
-
}
|
|
1028
|
-
setToken(token) {
|
|
1029
|
-
if (token) this.storage.setItem(ACCESS_KEY, token);
|
|
1030
|
-
else this.storage.removeItem(ACCESS_KEY);
|
|
1031
|
-
}
|
|
1032
|
-
getRefreshToken() {
|
|
1033
|
-
return this.storage.getItem(REFRESH_KEY);
|
|
1034
|
-
}
|
|
1035
|
-
setRefreshToken(token) {
|
|
1036
|
-
if (token) this.storage.setItem(REFRESH_KEY, token);
|
|
1037
|
-
else this.storage.removeItem(REFRESH_KEY);
|
|
1038
|
-
}
|
|
1039
|
-
clearToken() {
|
|
1040
|
-
this.storage.removeItem(ACCESS_KEY);
|
|
1041
|
-
this.storage.removeItem(REFRESH_KEY);
|
|
1042
|
-
}
|
|
1043
|
-
isAuthenticated() {
|
|
1044
|
-
return this.getToken() !== null;
|
|
1045
|
-
}
|
|
1046
|
-
// ── Locale / API key ────────────────────────────────────────────────────
|
|
1047
|
-
getLocale() {
|
|
1048
|
-
return this.locale ?? detectLocale();
|
|
1049
|
-
}
|
|
1050
|
-
setLocale(locale) {
|
|
1051
|
-
this.locale = locale;
|
|
1052
|
-
}
|
|
1053
|
-
getApiKey() {
|
|
1054
|
-
return this.apiKey;
|
|
1055
|
-
}
|
|
1056
|
-
setApiKey(key) {
|
|
1057
|
-
this.apiKey = key;
|
|
1058
|
-
}
|
|
1059
|
-
};
|
|
1060
|
-
__name(_API, "API");
|
|
1061
|
-
var API = _API;
|
|
1062
|
-
|
|
1063
|
-
// src/_api/BaseClient.ts
|
|
1064
|
-
var monitorApi = new API("", { storage: new MemoryStorageAdapter() });
|
|
1065
|
-
function configureMonitorApi(baseUrl) {
|
|
1066
|
-
monitorApi.setBaseUrl(baseUrl);
|
|
1067
|
-
}
|
|
1068
|
-
__name(configureMonitorApi, "configureMonitorApi");
|
|
1183
|
+
installAuthOnClient(client);
|
|
1069
1184
|
|
|
1070
1185
|
// src/_api/generated/sdk.gen.ts
|
|
1071
1186
|
var _Monitor = class _Monitor {
|