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