@djangocfg/monitor 2.1.332 → 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 +1100 -1098
- package/dist/client.cjs.map +1 -1
- package/dist/client.mjs +1100 -1098
- package/dist/client.mjs.map +1 -1
- package/dist/index.cjs +12 -838
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +12 -838
- package/dist/index.mjs.map +1 -1
- package/dist/server.cjs +1067 -1065
- package/dist/server.cjs.map +1 -1
- package/dist/server.mjs +1067 -1065
- package/dist/server.mjs.map +1 -1
- package/package.json +2 -2
- package/src/_api/generated/client.gen.ts +3 -2
- package/src/_api/generated/helpers/auth.ts +64 -47
package/dist/index.cjs
CHANGED
|
@@ -27,806 +27,6 @@ __export(index_exports, {
|
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(index_exports);
|
|
29
29
|
|
|
30
|
-
// src/_api/generated/core/bodySerializer.gen.ts
|
|
31
|
-
var jsonBodySerializer = {
|
|
32
|
-
bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// src/_api/generated/core/params.gen.ts
|
|
36
|
-
var extraPrefixesMap = {
|
|
37
|
-
$body_: "body",
|
|
38
|
-
$headers_: "headers",
|
|
39
|
-
$path_: "path",
|
|
40
|
-
$query_: "query"
|
|
41
|
-
};
|
|
42
|
-
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
43
|
-
|
|
44
|
-
// src/_api/generated/core/serverSentEvents.gen.ts
|
|
45
|
-
function createSseClient({
|
|
46
|
-
onRequest,
|
|
47
|
-
onSseError,
|
|
48
|
-
onSseEvent,
|
|
49
|
-
responseTransformer,
|
|
50
|
-
responseValidator,
|
|
51
|
-
sseDefaultRetryDelay,
|
|
52
|
-
sseMaxRetryAttempts,
|
|
53
|
-
sseMaxRetryDelay,
|
|
54
|
-
sseSleepFn,
|
|
55
|
-
url,
|
|
56
|
-
...options
|
|
57
|
-
}) {
|
|
58
|
-
let lastEventId;
|
|
59
|
-
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
60
|
-
const createStream = /* @__PURE__ */ __name(async function* () {
|
|
61
|
-
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
62
|
-
let attempt = 0;
|
|
63
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
64
|
-
while (true) {
|
|
65
|
-
if (signal.aborted) break;
|
|
66
|
-
attempt++;
|
|
67
|
-
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
68
|
-
if (lastEventId !== void 0) {
|
|
69
|
-
headers.set("Last-Event-ID", lastEventId);
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
const requestInit = {
|
|
73
|
-
redirect: "follow",
|
|
74
|
-
...options,
|
|
75
|
-
body: options.serializedBody,
|
|
76
|
-
headers,
|
|
77
|
-
signal
|
|
78
|
-
};
|
|
79
|
-
let request = new Request(url, requestInit);
|
|
80
|
-
if (onRequest) {
|
|
81
|
-
request = await onRequest(url, requestInit);
|
|
82
|
-
}
|
|
83
|
-
const _fetch = options.fetch ?? globalThis.fetch;
|
|
84
|
-
const response = await _fetch(request);
|
|
85
|
-
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
86
|
-
if (!response.body) throw new Error("No body in SSE response");
|
|
87
|
-
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
88
|
-
let buffer = "";
|
|
89
|
-
const abortHandler = /* @__PURE__ */ __name(() => {
|
|
90
|
-
try {
|
|
91
|
-
reader.cancel();
|
|
92
|
-
} catch {
|
|
93
|
-
}
|
|
94
|
-
}, "abortHandler");
|
|
95
|
-
signal.addEventListener("abort", abortHandler);
|
|
96
|
-
try {
|
|
97
|
-
while (true) {
|
|
98
|
-
const { done, value } = await reader.read();
|
|
99
|
-
if (done) break;
|
|
100
|
-
buffer += value;
|
|
101
|
-
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
102
|
-
const chunks = buffer.split("\n\n");
|
|
103
|
-
buffer = chunks.pop() ?? "";
|
|
104
|
-
for (const chunk of chunks) {
|
|
105
|
-
const lines = chunk.split("\n");
|
|
106
|
-
const dataLines = [];
|
|
107
|
-
let eventName;
|
|
108
|
-
for (const line of lines) {
|
|
109
|
-
if (line.startsWith("data:")) {
|
|
110
|
-
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
111
|
-
} else if (line.startsWith("event:")) {
|
|
112
|
-
eventName = line.replace(/^event:\s*/, "");
|
|
113
|
-
} else if (line.startsWith("id:")) {
|
|
114
|
-
lastEventId = line.replace(/^id:\s*/, "");
|
|
115
|
-
} else if (line.startsWith("retry:")) {
|
|
116
|
-
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
117
|
-
if (!Number.isNaN(parsed)) {
|
|
118
|
-
retryDelay = parsed;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
let data;
|
|
123
|
-
let parsedJson = false;
|
|
124
|
-
if (dataLines.length) {
|
|
125
|
-
const rawData = dataLines.join("\n");
|
|
126
|
-
try {
|
|
127
|
-
data = JSON.parse(rawData);
|
|
128
|
-
parsedJson = true;
|
|
129
|
-
} catch {
|
|
130
|
-
data = rawData;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (parsedJson) {
|
|
134
|
-
if (responseValidator) {
|
|
135
|
-
await responseValidator(data);
|
|
136
|
-
}
|
|
137
|
-
if (responseTransformer) {
|
|
138
|
-
data = await responseTransformer(data);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
onSseEvent?.({
|
|
142
|
-
data,
|
|
143
|
-
event: eventName,
|
|
144
|
-
id: lastEventId,
|
|
145
|
-
retry: retryDelay
|
|
146
|
-
});
|
|
147
|
-
if (dataLines.length) {
|
|
148
|
-
yield data;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
} finally {
|
|
153
|
-
signal.removeEventListener("abort", abortHandler);
|
|
154
|
-
reader.releaseLock();
|
|
155
|
-
}
|
|
156
|
-
break;
|
|
157
|
-
} catch (error) {
|
|
158
|
-
onSseError?.(error);
|
|
159
|
-
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
163
|
-
await sleep(backoff);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}, "createStream");
|
|
167
|
-
const stream = createStream();
|
|
168
|
-
return { stream };
|
|
169
|
-
}
|
|
170
|
-
__name(createSseClient, "createSseClient");
|
|
171
|
-
|
|
172
|
-
// src/_api/generated/core/pathSerializer.gen.ts
|
|
173
|
-
var separatorArrayExplode = /* @__PURE__ */ __name((style) => {
|
|
174
|
-
switch (style) {
|
|
175
|
-
case "label":
|
|
176
|
-
return ".";
|
|
177
|
-
case "matrix":
|
|
178
|
-
return ";";
|
|
179
|
-
case "simple":
|
|
180
|
-
return ",";
|
|
181
|
-
default:
|
|
182
|
-
return "&";
|
|
183
|
-
}
|
|
184
|
-
}, "separatorArrayExplode");
|
|
185
|
-
var separatorArrayNoExplode = /* @__PURE__ */ __name((style) => {
|
|
186
|
-
switch (style) {
|
|
187
|
-
case "form":
|
|
188
|
-
return ",";
|
|
189
|
-
case "pipeDelimited":
|
|
190
|
-
return "|";
|
|
191
|
-
case "spaceDelimited":
|
|
192
|
-
return "%20";
|
|
193
|
-
default:
|
|
194
|
-
return ",";
|
|
195
|
-
}
|
|
196
|
-
}, "separatorArrayNoExplode");
|
|
197
|
-
var separatorObjectExplode = /* @__PURE__ */ __name((style) => {
|
|
198
|
-
switch (style) {
|
|
199
|
-
case "label":
|
|
200
|
-
return ".";
|
|
201
|
-
case "matrix":
|
|
202
|
-
return ";";
|
|
203
|
-
case "simple":
|
|
204
|
-
return ",";
|
|
205
|
-
default:
|
|
206
|
-
return "&";
|
|
207
|
-
}
|
|
208
|
-
}, "separatorObjectExplode");
|
|
209
|
-
var serializeArrayParam = /* @__PURE__ */ __name(({
|
|
210
|
-
allowReserved,
|
|
211
|
-
explode,
|
|
212
|
-
name,
|
|
213
|
-
style,
|
|
214
|
-
value
|
|
215
|
-
}) => {
|
|
216
|
-
if (!explode) {
|
|
217
|
-
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
218
|
-
switch (style) {
|
|
219
|
-
case "label":
|
|
220
|
-
return `.${joinedValues2}`;
|
|
221
|
-
case "matrix":
|
|
222
|
-
return `;${name}=${joinedValues2}`;
|
|
223
|
-
case "simple":
|
|
224
|
-
return joinedValues2;
|
|
225
|
-
default:
|
|
226
|
-
return `${name}=${joinedValues2}`;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
const separator = separatorArrayExplode(style);
|
|
230
|
-
const joinedValues = value.map((v) => {
|
|
231
|
-
if (style === "label" || style === "simple") {
|
|
232
|
-
return allowReserved ? v : encodeURIComponent(v);
|
|
233
|
-
}
|
|
234
|
-
return serializePrimitiveParam({
|
|
235
|
-
allowReserved,
|
|
236
|
-
name,
|
|
237
|
-
value: v
|
|
238
|
-
});
|
|
239
|
-
}).join(separator);
|
|
240
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
241
|
-
}, "serializeArrayParam");
|
|
242
|
-
var serializePrimitiveParam = /* @__PURE__ */ __name(({
|
|
243
|
-
allowReserved,
|
|
244
|
-
name,
|
|
245
|
-
value
|
|
246
|
-
}) => {
|
|
247
|
-
if (value === void 0 || value === null) {
|
|
248
|
-
return "";
|
|
249
|
-
}
|
|
250
|
-
if (typeof value === "object") {
|
|
251
|
-
throw new Error(
|
|
252
|
-
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
256
|
-
}, "serializePrimitiveParam");
|
|
257
|
-
var serializeObjectParam = /* @__PURE__ */ __name(({
|
|
258
|
-
allowReserved,
|
|
259
|
-
explode,
|
|
260
|
-
name,
|
|
261
|
-
style,
|
|
262
|
-
value,
|
|
263
|
-
valueOnly
|
|
264
|
-
}) => {
|
|
265
|
-
if (value instanceof Date) {
|
|
266
|
-
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
267
|
-
}
|
|
268
|
-
if (style !== "deepObject" && !explode) {
|
|
269
|
-
let values = [];
|
|
270
|
-
Object.entries(value).forEach(([key, v]) => {
|
|
271
|
-
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
272
|
-
});
|
|
273
|
-
const joinedValues2 = values.join(",");
|
|
274
|
-
switch (style) {
|
|
275
|
-
case "form":
|
|
276
|
-
return `${name}=${joinedValues2}`;
|
|
277
|
-
case "label":
|
|
278
|
-
return `.${joinedValues2}`;
|
|
279
|
-
case "matrix":
|
|
280
|
-
return `;${name}=${joinedValues2}`;
|
|
281
|
-
default:
|
|
282
|
-
return joinedValues2;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
const separator = separatorObjectExplode(style);
|
|
286
|
-
const joinedValues = Object.entries(value).map(
|
|
287
|
-
([key, v]) => serializePrimitiveParam({
|
|
288
|
-
allowReserved,
|
|
289
|
-
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
290
|
-
value: v
|
|
291
|
-
})
|
|
292
|
-
).join(separator);
|
|
293
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
294
|
-
}, "serializeObjectParam");
|
|
295
|
-
|
|
296
|
-
// src/_api/generated/core/utils.gen.ts
|
|
297
|
-
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
298
|
-
var defaultPathSerializer = /* @__PURE__ */ __name(({ path, url: _url }) => {
|
|
299
|
-
let url = _url;
|
|
300
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
301
|
-
if (matches) {
|
|
302
|
-
for (const match of matches) {
|
|
303
|
-
let explode = false;
|
|
304
|
-
let name = match.substring(1, match.length - 1);
|
|
305
|
-
let style = "simple";
|
|
306
|
-
if (name.endsWith("*")) {
|
|
307
|
-
explode = true;
|
|
308
|
-
name = name.substring(0, name.length - 1);
|
|
309
|
-
}
|
|
310
|
-
if (name.startsWith(".")) {
|
|
311
|
-
name = name.substring(1);
|
|
312
|
-
style = "label";
|
|
313
|
-
} else if (name.startsWith(";")) {
|
|
314
|
-
name = name.substring(1);
|
|
315
|
-
style = "matrix";
|
|
316
|
-
}
|
|
317
|
-
const value = path[name];
|
|
318
|
-
if (value === void 0 || value === null) {
|
|
319
|
-
continue;
|
|
320
|
-
}
|
|
321
|
-
if (Array.isArray(value)) {
|
|
322
|
-
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
if (typeof value === "object") {
|
|
326
|
-
url = url.replace(
|
|
327
|
-
match,
|
|
328
|
-
serializeObjectParam({
|
|
329
|
-
explode,
|
|
330
|
-
name,
|
|
331
|
-
style,
|
|
332
|
-
value,
|
|
333
|
-
valueOnly: true
|
|
334
|
-
})
|
|
335
|
-
);
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
if (style === "matrix") {
|
|
339
|
-
url = url.replace(
|
|
340
|
-
match,
|
|
341
|
-
`;${serializePrimitiveParam({
|
|
342
|
-
name,
|
|
343
|
-
value
|
|
344
|
-
})}`
|
|
345
|
-
);
|
|
346
|
-
continue;
|
|
347
|
-
}
|
|
348
|
-
const replaceValue = encodeURIComponent(
|
|
349
|
-
style === "label" ? `.${value}` : value
|
|
350
|
-
);
|
|
351
|
-
url = url.replace(match, replaceValue);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return url;
|
|
355
|
-
}, "defaultPathSerializer");
|
|
356
|
-
var getUrl = /* @__PURE__ */ __name(({
|
|
357
|
-
baseUrl,
|
|
358
|
-
path,
|
|
359
|
-
query,
|
|
360
|
-
querySerializer,
|
|
361
|
-
url: _url
|
|
362
|
-
}) => {
|
|
363
|
-
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
364
|
-
let url = (baseUrl ?? "") + pathUrl;
|
|
365
|
-
if (path) {
|
|
366
|
-
url = defaultPathSerializer({ path, url });
|
|
367
|
-
}
|
|
368
|
-
let search = query ? querySerializer(query) : "";
|
|
369
|
-
if (search.startsWith("?")) {
|
|
370
|
-
search = search.substring(1);
|
|
371
|
-
}
|
|
372
|
-
if (search) {
|
|
373
|
-
url += `?${search}`;
|
|
374
|
-
}
|
|
375
|
-
return url;
|
|
376
|
-
}, "getUrl");
|
|
377
|
-
function getValidRequestBody(options) {
|
|
378
|
-
const hasBody = options.body !== void 0;
|
|
379
|
-
const isSerializedBody = hasBody && options.bodySerializer;
|
|
380
|
-
if (isSerializedBody) {
|
|
381
|
-
if ("serializedBody" in options) {
|
|
382
|
-
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
383
|
-
return hasSerializedBody ? options.serializedBody : null;
|
|
384
|
-
}
|
|
385
|
-
return options.body !== "" ? options.body : null;
|
|
386
|
-
}
|
|
387
|
-
if (hasBody) {
|
|
388
|
-
return options.body;
|
|
389
|
-
}
|
|
390
|
-
return void 0;
|
|
391
|
-
}
|
|
392
|
-
__name(getValidRequestBody, "getValidRequestBody");
|
|
393
|
-
|
|
394
|
-
// src/_api/generated/core/auth.gen.ts
|
|
395
|
-
var getAuthToken = /* @__PURE__ */ __name(async (auth2, callback) => {
|
|
396
|
-
const token = typeof callback === "function" ? await callback(auth2) : callback;
|
|
397
|
-
if (!token) {
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
if (auth2.scheme === "bearer") {
|
|
401
|
-
return `Bearer ${token}`;
|
|
402
|
-
}
|
|
403
|
-
if (auth2.scheme === "basic") {
|
|
404
|
-
return `Basic ${btoa(token)}`;
|
|
405
|
-
}
|
|
406
|
-
return token;
|
|
407
|
-
}, "getAuthToken");
|
|
408
|
-
|
|
409
|
-
// src/_api/generated/client/utils.gen.ts
|
|
410
|
-
var createQuerySerializer = /* @__PURE__ */ __name(({
|
|
411
|
-
parameters = {},
|
|
412
|
-
...args
|
|
413
|
-
} = {}) => {
|
|
414
|
-
const querySerializer = /* @__PURE__ */ __name((queryParams) => {
|
|
415
|
-
const search = [];
|
|
416
|
-
if (queryParams && typeof queryParams === "object") {
|
|
417
|
-
for (const name in queryParams) {
|
|
418
|
-
const value = queryParams[name];
|
|
419
|
-
if (value === void 0 || value === null) {
|
|
420
|
-
continue;
|
|
421
|
-
}
|
|
422
|
-
const options = parameters[name] || args;
|
|
423
|
-
if (Array.isArray(value)) {
|
|
424
|
-
const serializedArray = serializeArrayParam({
|
|
425
|
-
allowReserved: options.allowReserved,
|
|
426
|
-
explode: true,
|
|
427
|
-
name,
|
|
428
|
-
style: "form",
|
|
429
|
-
value,
|
|
430
|
-
...options.array
|
|
431
|
-
});
|
|
432
|
-
if (serializedArray) search.push(serializedArray);
|
|
433
|
-
} else if (typeof value === "object") {
|
|
434
|
-
const serializedObject = serializeObjectParam({
|
|
435
|
-
allowReserved: options.allowReserved,
|
|
436
|
-
explode: true,
|
|
437
|
-
name,
|
|
438
|
-
style: "deepObject",
|
|
439
|
-
value,
|
|
440
|
-
...options.object
|
|
441
|
-
});
|
|
442
|
-
if (serializedObject) search.push(serializedObject);
|
|
443
|
-
} else {
|
|
444
|
-
const serializedPrimitive = serializePrimitiveParam({
|
|
445
|
-
allowReserved: options.allowReserved,
|
|
446
|
-
name,
|
|
447
|
-
value
|
|
448
|
-
});
|
|
449
|
-
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return search.join("&");
|
|
454
|
-
}, "querySerializer");
|
|
455
|
-
return querySerializer;
|
|
456
|
-
}, "createQuerySerializer");
|
|
457
|
-
var getParseAs = /* @__PURE__ */ __name((contentType) => {
|
|
458
|
-
if (!contentType) {
|
|
459
|
-
return "stream";
|
|
460
|
-
}
|
|
461
|
-
const cleanContent = contentType.split(";")[0]?.trim();
|
|
462
|
-
if (!cleanContent) {
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
466
|
-
return "json";
|
|
467
|
-
}
|
|
468
|
-
if (cleanContent === "multipart/form-data") {
|
|
469
|
-
return "formData";
|
|
470
|
-
}
|
|
471
|
-
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
472
|
-
return "blob";
|
|
473
|
-
}
|
|
474
|
-
if (cleanContent.startsWith("text/")) {
|
|
475
|
-
return "text";
|
|
476
|
-
}
|
|
477
|
-
return;
|
|
478
|
-
}, "getParseAs");
|
|
479
|
-
var checkForExistence = /* @__PURE__ */ __name((options, name) => {
|
|
480
|
-
if (!name) {
|
|
481
|
-
return false;
|
|
482
|
-
}
|
|
483
|
-
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
484
|
-
return true;
|
|
485
|
-
}
|
|
486
|
-
return false;
|
|
487
|
-
}, "checkForExistence");
|
|
488
|
-
var setAuthParams = /* @__PURE__ */ __name(async ({
|
|
489
|
-
security,
|
|
490
|
-
...options
|
|
491
|
-
}) => {
|
|
492
|
-
for (const auth2 of security) {
|
|
493
|
-
if (checkForExistence(options, auth2.name)) {
|
|
494
|
-
continue;
|
|
495
|
-
}
|
|
496
|
-
const token = await getAuthToken(auth2, options.auth);
|
|
497
|
-
if (!token) {
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
const name = auth2.name ?? "Authorization";
|
|
501
|
-
switch (auth2.in) {
|
|
502
|
-
case "query":
|
|
503
|
-
if (!options.query) {
|
|
504
|
-
options.query = {};
|
|
505
|
-
}
|
|
506
|
-
options.query[name] = token;
|
|
507
|
-
break;
|
|
508
|
-
case "cookie":
|
|
509
|
-
options.headers.append("Cookie", `${name}=${token}`);
|
|
510
|
-
break;
|
|
511
|
-
case "header":
|
|
512
|
-
default:
|
|
513
|
-
options.headers.set(name, token);
|
|
514
|
-
break;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
}, "setAuthParams");
|
|
518
|
-
var buildUrl = /* @__PURE__ */ __name((options) => getUrl({
|
|
519
|
-
baseUrl: options.baseUrl,
|
|
520
|
-
path: options.path,
|
|
521
|
-
query: options.query,
|
|
522
|
-
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
523
|
-
url: options.url
|
|
524
|
-
}), "buildUrl");
|
|
525
|
-
var mergeConfigs = /* @__PURE__ */ __name((a, b) => {
|
|
526
|
-
const config = { ...a, ...b };
|
|
527
|
-
if (config.baseUrl?.endsWith("/")) {
|
|
528
|
-
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
529
|
-
}
|
|
530
|
-
config.headers = mergeHeaders(a.headers, b.headers);
|
|
531
|
-
return config;
|
|
532
|
-
}, "mergeConfigs");
|
|
533
|
-
var headersEntries = /* @__PURE__ */ __name((headers) => {
|
|
534
|
-
const entries = [];
|
|
535
|
-
headers.forEach((value, key) => {
|
|
536
|
-
entries.push([key, value]);
|
|
537
|
-
});
|
|
538
|
-
return entries;
|
|
539
|
-
}, "headersEntries");
|
|
540
|
-
var mergeHeaders = /* @__PURE__ */ __name((...headers) => {
|
|
541
|
-
const mergedHeaders = new Headers();
|
|
542
|
-
for (const header of headers) {
|
|
543
|
-
if (!header) {
|
|
544
|
-
continue;
|
|
545
|
-
}
|
|
546
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
547
|
-
for (const [key, value] of iterator) {
|
|
548
|
-
if (value === null) {
|
|
549
|
-
mergedHeaders.delete(key);
|
|
550
|
-
} else if (Array.isArray(value)) {
|
|
551
|
-
for (const v of value) {
|
|
552
|
-
mergedHeaders.append(key, v);
|
|
553
|
-
}
|
|
554
|
-
} else if (value !== void 0) {
|
|
555
|
-
mergedHeaders.set(
|
|
556
|
-
key,
|
|
557
|
-
typeof value === "object" ? JSON.stringify(value) : value
|
|
558
|
-
);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
return mergedHeaders;
|
|
563
|
-
}, "mergeHeaders");
|
|
564
|
-
var _Interceptors = class _Interceptors {
|
|
565
|
-
constructor() {
|
|
566
|
-
__publicField(this, "fns", []);
|
|
567
|
-
}
|
|
568
|
-
clear() {
|
|
569
|
-
this.fns = [];
|
|
570
|
-
}
|
|
571
|
-
eject(id) {
|
|
572
|
-
const index = this.getInterceptorIndex(id);
|
|
573
|
-
if (this.fns[index]) {
|
|
574
|
-
this.fns[index] = null;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
exists(id) {
|
|
578
|
-
const index = this.getInterceptorIndex(id);
|
|
579
|
-
return Boolean(this.fns[index]);
|
|
580
|
-
}
|
|
581
|
-
getInterceptorIndex(id) {
|
|
582
|
-
if (typeof id === "number") {
|
|
583
|
-
return this.fns[id] ? id : -1;
|
|
584
|
-
}
|
|
585
|
-
return this.fns.indexOf(id);
|
|
586
|
-
}
|
|
587
|
-
update(id, fn) {
|
|
588
|
-
const index = this.getInterceptorIndex(id);
|
|
589
|
-
if (this.fns[index]) {
|
|
590
|
-
this.fns[index] = fn;
|
|
591
|
-
return id;
|
|
592
|
-
}
|
|
593
|
-
return false;
|
|
594
|
-
}
|
|
595
|
-
use(fn) {
|
|
596
|
-
this.fns.push(fn);
|
|
597
|
-
return this.fns.length - 1;
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
__name(_Interceptors, "Interceptors");
|
|
601
|
-
var Interceptors = _Interceptors;
|
|
602
|
-
var createInterceptors = /* @__PURE__ */ __name(() => ({
|
|
603
|
-
error: new Interceptors(),
|
|
604
|
-
request: new Interceptors(),
|
|
605
|
-
response: new Interceptors()
|
|
606
|
-
}), "createInterceptors");
|
|
607
|
-
var defaultQuerySerializer = createQuerySerializer({
|
|
608
|
-
allowReserved: false,
|
|
609
|
-
array: {
|
|
610
|
-
explode: true,
|
|
611
|
-
style: "form"
|
|
612
|
-
},
|
|
613
|
-
object: {
|
|
614
|
-
explode: true,
|
|
615
|
-
style: "deepObject"
|
|
616
|
-
}
|
|
617
|
-
});
|
|
618
|
-
var defaultHeaders = {
|
|
619
|
-
"Content-Type": "application/json"
|
|
620
|
-
};
|
|
621
|
-
var createConfig = /* @__PURE__ */ __name((override = {}) => ({
|
|
622
|
-
...jsonBodySerializer,
|
|
623
|
-
headers: defaultHeaders,
|
|
624
|
-
parseAs: "auto",
|
|
625
|
-
querySerializer: defaultQuerySerializer,
|
|
626
|
-
...override
|
|
627
|
-
}), "createConfig");
|
|
628
|
-
|
|
629
|
-
// src/_api/generated/client/client.gen.ts
|
|
630
|
-
var createClient = /* @__PURE__ */ __name((config = {}) => {
|
|
631
|
-
let _config = mergeConfigs(createConfig(), config);
|
|
632
|
-
const getConfig = /* @__PURE__ */ __name(() => ({ ..._config }), "getConfig");
|
|
633
|
-
const setConfig = /* @__PURE__ */ __name((config2) => {
|
|
634
|
-
_config = mergeConfigs(_config, config2);
|
|
635
|
-
return getConfig();
|
|
636
|
-
}, "setConfig");
|
|
637
|
-
const interceptors = createInterceptors();
|
|
638
|
-
const beforeRequest = /* @__PURE__ */ __name(async (options) => {
|
|
639
|
-
const opts = {
|
|
640
|
-
..._config,
|
|
641
|
-
...options,
|
|
642
|
-
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
643
|
-
headers: mergeHeaders(_config.headers, options.headers),
|
|
644
|
-
serializedBody: void 0
|
|
645
|
-
};
|
|
646
|
-
if (opts.security) {
|
|
647
|
-
await setAuthParams({
|
|
648
|
-
...opts,
|
|
649
|
-
security: opts.security
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
if (opts.requestValidator) {
|
|
653
|
-
await opts.requestValidator(opts);
|
|
654
|
-
}
|
|
655
|
-
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
656
|
-
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
657
|
-
}
|
|
658
|
-
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
659
|
-
opts.headers.delete("Content-Type");
|
|
660
|
-
}
|
|
661
|
-
const resolvedOpts = opts;
|
|
662
|
-
const url = buildUrl(resolvedOpts);
|
|
663
|
-
return { opts: resolvedOpts, url };
|
|
664
|
-
}, "beforeRequest");
|
|
665
|
-
const request = /* @__PURE__ */ __name(async (options) => {
|
|
666
|
-
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
667
|
-
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
668
|
-
let request2;
|
|
669
|
-
let response;
|
|
670
|
-
try {
|
|
671
|
-
const { opts, url } = await beforeRequest(options);
|
|
672
|
-
const requestInit = {
|
|
673
|
-
redirect: "follow",
|
|
674
|
-
...opts,
|
|
675
|
-
body: getValidRequestBody(opts)
|
|
676
|
-
};
|
|
677
|
-
request2 = new Request(url, requestInit);
|
|
678
|
-
for (const fn of interceptors.request.fns) {
|
|
679
|
-
if (fn) {
|
|
680
|
-
request2 = await fn(request2, opts);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
const _fetch = opts.fetch;
|
|
684
|
-
response = await _fetch(request2);
|
|
685
|
-
for (const fn of interceptors.response.fns) {
|
|
686
|
-
if (fn) {
|
|
687
|
-
response = await fn(response, request2, opts);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
const result = {
|
|
691
|
-
request: request2,
|
|
692
|
-
response
|
|
693
|
-
};
|
|
694
|
-
if (response.ok) {
|
|
695
|
-
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
696
|
-
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
697
|
-
let emptyData;
|
|
698
|
-
switch (parseAs) {
|
|
699
|
-
case "arrayBuffer":
|
|
700
|
-
case "blob":
|
|
701
|
-
case "text":
|
|
702
|
-
emptyData = await response[parseAs]();
|
|
703
|
-
break;
|
|
704
|
-
case "formData":
|
|
705
|
-
emptyData = new FormData();
|
|
706
|
-
break;
|
|
707
|
-
case "stream":
|
|
708
|
-
emptyData = response.body;
|
|
709
|
-
break;
|
|
710
|
-
case "json":
|
|
711
|
-
default:
|
|
712
|
-
emptyData = {};
|
|
713
|
-
break;
|
|
714
|
-
}
|
|
715
|
-
return opts.responseStyle === "data" ? emptyData : {
|
|
716
|
-
data: emptyData,
|
|
717
|
-
...result
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
let data;
|
|
721
|
-
switch (parseAs) {
|
|
722
|
-
case "arrayBuffer":
|
|
723
|
-
case "blob":
|
|
724
|
-
case "formData":
|
|
725
|
-
case "text":
|
|
726
|
-
data = await response[parseAs]();
|
|
727
|
-
break;
|
|
728
|
-
case "json": {
|
|
729
|
-
const text = await response.text();
|
|
730
|
-
data = text ? JSON.parse(text) : {};
|
|
731
|
-
break;
|
|
732
|
-
}
|
|
733
|
-
case "stream":
|
|
734
|
-
return opts.responseStyle === "data" ? response.body : {
|
|
735
|
-
data: response.body,
|
|
736
|
-
...result
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
if (parseAs === "json") {
|
|
740
|
-
if (opts.responseValidator) {
|
|
741
|
-
await opts.responseValidator(data);
|
|
742
|
-
}
|
|
743
|
-
if (opts.responseTransformer) {
|
|
744
|
-
data = await opts.responseTransformer(data);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
return opts.responseStyle === "data" ? data : {
|
|
748
|
-
data,
|
|
749
|
-
...result
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
const textError = await response.text();
|
|
753
|
-
let jsonError;
|
|
754
|
-
try {
|
|
755
|
-
jsonError = JSON.parse(textError);
|
|
756
|
-
} catch {
|
|
757
|
-
}
|
|
758
|
-
throw jsonError ?? textError;
|
|
759
|
-
} catch (error) {
|
|
760
|
-
let finalError = error;
|
|
761
|
-
for (const fn of interceptors.error.fns) {
|
|
762
|
-
if (fn) {
|
|
763
|
-
finalError = await fn(finalError, response, request2, options);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
finalError = finalError || {};
|
|
767
|
-
if (throwOnError) {
|
|
768
|
-
throw finalError;
|
|
769
|
-
}
|
|
770
|
-
return responseStyle === "data" ? void 0 : {
|
|
771
|
-
error: finalError,
|
|
772
|
-
request: request2,
|
|
773
|
-
response
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
}, "request");
|
|
777
|
-
const makeMethodFn = /* @__PURE__ */ __name((method) => (options) => request({ ...options, method }), "makeMethodFn");
|
|
778
|
-
const makeSseFn = /* @__PURE__ */ __name((method) => async (options) => {
|
|
779
|
-
const { opts, url } = await beforeRequest(options);
|
|
780
|
-
return createSseClient({
|
|
781
|
-
...opts,
|
|
782
|
-
body: opts.body,
|
|
783
|
-
method,
|
|
784
|
-
onRequest: /* @__PURE__ */ __name(async (url2, init) => {
|
|
785
|
-
let request2 = new Request(url2, init);
|
|
786
|
-
for (const fn of interceptors.request.fns) {
|
|
787
|
-
if (fn) {
|
|
788
|
-
request2 = await fn(request2, opts);
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
return request2;
|
|
792
|
-
}, "onRequest"),
|
|
793
|
-
serializedBody: getValidRequestBody(opts),
|
|
794
|
-
url
|
|
795
|
-
});
|
|
796
|
-
}, "makeSseFn");
|
|
797
|
-
const _buildUrl = /* @__PURE__ */ __name((options) => buildUrl({ ..._config, ...options }), "_buildUrl");
|
|
798
|
-
return {
|
|
799
|
-
buildUrl: _buildUrl,
|
|
800
|
-
connect: makeMethodFn("CONNECT"),
|
|
801
|
-
delete: makeMethodFn("DELETE"),
|
|
802
|
-
get: makeMethodFn("GET"),
|
|
803
|
-
getConfig,
|
|
804
|
-
head: makeMethodFn("HEAD"),
|
|
805
|
-
interceptors,
|
|
806
|
-
options: makeMethodFn("OPTIONS"),
|
|
807
|
-
patch: makeMethodFn("PATCH"),
|
|
808
|
-
post: makeMethodFn("POST"),
|
|
809
|
-
put: makeMethodFn("PUT"),
|
|
810
|
-
request,
|
|
811
|
-
setConfig,
|
|
812
|
-
sse: {
|
|
813
|
-
connect: makeSseFn("CONNECT"),
|
|
814
|
-
delete: makeSseFn("DELETE"),
|
|
815
|
-
get: makeSseFn("GET"),
|
|
816
|
-
head: makeSseFn("HEAD"),
|
|
817
|
-
options: makeSseFn("OPTIONS"),
|
|
818
|
-
patch: makeSseFn("PATCH"),
|
|
819
|
-
post: makeSseFn("POST"),
|
|
820
|
-
put: makeSseFn("PUT"),
|
|
821
|
-
trace: makeSseFn("TRACE")
|
|
822
|
-
},
|
|
823
|
-
trace: makeMethodFn("TRACE")
|
|
824
|
-
};
|
|
825
|
-
}, "createClient");
|
|
826
|
-
|
|
827
|
-
// src/_api/generated/client.gen.ts
|
|
828
|
-
var client = createClient(createConfig({ baseUrl: "http://localhost:8000" }));
|
|
829
|
-
|
|
830
30
|
// src/_api/generated/helpers/auth.ts
|
|
831
31
|
var ACCESS_KEY = "cfg.access_token";
|
|
832
32
|
var REFRESH_KEY = "cfg.refresh_token";
|
|
@@ -919,15 +119,20 @@ var _apiKeyOverride = null;
|
|
|
919
119
|
var _baseUrlOverride = null;
|
|
920
120
|
var _withCredentials = true;
|
|
921
121
|
var _onUnauthorized = null;
|
|
122
|
+
var _client = null;
|
|
123
|
+
function pushClientConfig() {
|
|
124
|
+
if (!_client) return;
|
|
125
|
+
_client.setConfig({
|
|
126
|
+
baseUrl: auth.getBaseUrl(),
|
|
127
|
+
credentials: _withCredentials ? "include" : "same-origin"
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
__name(pushClientConfig, "pushClientConfig");
|
|
922
131
|
var auth = {
|
|
923
132
|
// ── Storage mode ──────────────────────────────────────────────────
|
|
924
133
|
getStorageMode() {
|
|
925
134
|
return _storageMode;
|
|
926
135
|
},
|
|
927
|
-
/**
|
|
928
|
-
* Switch the storage backend. Existing values in the *previous*
|
|
929
|
-
* backend are NOT migrated — set fresh values after switching.
|
|
930
|
-
*/
|
|
931
136
|
setStorageMode(mode) {
|
|
932
137
|
_storageMode = mode;
|
|
933
138
|
_storage = mode === "cookie" ? cookieBackend : localStorageBackend;
|
|
@@ -953,15 +158,12 @@ var auth = {
|
|
|
953
158
|
return _storage.get(ACCESS_KEY) !== null;
|
|
954
159
|
},
|
|
955
160
|
// ── API key ───────────────────────────────────────────────────────
|
|
956
|
-
/** In-memory API key. Falls back to storage, then NEXT_PUBLIC_API_KEY. */
|
|
957
161
|
getApiKey() {
|
|
958
162
|
return _apiKeyOverride ?? _storage.get(API_KEY_KEY) ?? defaultApiKey();
|
|
959
163
|
},
|
|
960
|
-
/** In-memory only (cleared on reload). */
|
|
961
164
|
setApiKey(key) {
|
|
962
165
|
_apiKeyOverride = key;
|
|
963
166
|
},
|
|
964
|
-
/** Persist to active storage backend (localStorage or cookie). */
|
|
965
167
|
setApiKeyPersist(key) {
|
|
966
168
|
_apiKeyOverride = key;
|
|
967
169
|
_storage.set(API_KEY_KEY, key);
|
|
@@ -971,7 +173,6 @@ var auth = {
|
|
|
971
173
|
_storage.set(API_KEY_KEY, null);
|
|
972
174
|
},
|
|
973
175
|
// ── Locale ────────────────────────────────────────────────────────
|
|
974
|
-
/** Override locale → falls back to NEXT_LOCALE cookie / navigator.language. */
|
|
975
176
|
getLocale() {
|
|
976
177
|
return _localeOverride ?? detectLocale();
|
|
977
178
|
},
|
|
@@ -985,48 +186,21 @@ var auth = {
|
|
|
985
186
|
},
|
|
986
187
|
setBaseUrl(url) {
|
|
987
188
|
_baseUrlOverride = url ? url.replace(/\/$/, "") : null;
|
|
988
|
-
|
|
189
|
+
pushClientConfig();
|
|
989
190
|
},
|
|
990
|
-
// ── Credentials toggle
|
|
191
|
+
// ── Credentials toggle ────────────────────────────────────────────
|
|
991
192
|
getWithCredentials() {
|
|
992
193
|
return _withCredentials;
|
|
993
194
|
},
|
|
994
195
|
setWithCredentials(value) {
|
|
995
196
|
_withCredentials = value;
|
|
996
|
-
|
|
197
|
+
pushClientConfig();
|
|
997
198
|
},
|
|
998
199
|
// ── 401 handler ───────────────────────────────────────────────────
|
|
999
|
-
/**
|
|
1000
|
-
* Register a callback fired on every 401 response. Use this to wire
|
|
1001
|
-
* a token-refresh flow or a forced logout. Setting `null` removes
|
|
1002
|
-
* the handler.
|
|
1003
|
-
*/
|
|
1004
200
|
onUnauthorized(cb) {
|
|
1005
201
|
_onUnauthorized = cb;
|
|
1006
202
|
}
|
|
1007
203
|
};
|
|
1008
|
-
client.setConfig({
|
|
1009
|
-
baseUrl: auth.getBaseUrl(),
|
|
1010
|
-
credentials: _withCredentials ? "include" : "same-origin"
|
|
1011
|
-
});
|
|
1012
|
-
client.interceptors.request.use((request) => {
|
|
1013
|
-
const token = auth.getToken();
|
|
1014
|
-
if (token) request.headers.set("Authorization", `Bearer ${token}`);
|
|
1015
|
-
const locale = auth.getLocale();
|
|
1016
|
-
if (locale) request.headers.set("Accept-Language", locale);
|
|
1017
|
-
const apiKey = auth.getApiKey();
|
|
1018
|
-
if (apiKey) request.headers.set("X-API-Key", apiKey);
|
|
1019
|
-
return request;
|
|
1020
|
-
});
|
|
1021
|
-
client.interceptors.response.use((response) => {
|
|
1022
|
-
if (response.status === 401 && _onUnauthorized) {
|
|
1023
|
-
try {
|
|
1024
|
-
_onUnauthorized(response);
|
|
1025
|
-
} catch {
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
return response;
|
|
1029
|
-
});
|
|
1030
204
|
|
|
1031
205
|
// src/_api/generated/helpers/logger.ts
|
|
1032
206
|
var import_consola = require("consola");
|