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