@djangocfg/monitor 2.1.322 → 2.1.331
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 +945 -1136
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +32 -46
- package/dist/client.d.ts +32 -46
- package/dist/client.mjs +945 -1147
- package/dist/client.mjs.map +1 -1
- package/dist/index.cjs +908 -1108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -46
- package/dist/index.d.ts +32 -46
- package/dist/index.mjs +901 -1112
- package/dist/index.mjs.map +1 -1
- package/dist/server.cjs +904 -1102
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +32 -46
- package/dist/server.d.ts +32 -46
- package/dist/server.mjs +896 -1105
- package/dist/server.mjs.map +1 -1
- package/package.json +7 -2
- package/src/_api/BaseClient.ts +1 -1
- package/src/_api/generated/_cfg_monitor/api.ts +120 -0
- package/src/_api/generated/_cfg_monitor/events.ts +198 -0
- package/src/_api/generated/_cfg_monitor/hooks/index.ts +4 -0
- package/src/_api/generated/_cfg_monitor/hooks/useCfgMonitorIngestCreate.ts +24 -0
- package/src/_api/generated/_cfg_monitor/index.ts +29 -0
- package/src/_api/generated/_cfg_monitor/schemas/EventTypeEnum.ts +9 -0
- package/src/_api/generated/_cfg_monitor/schemas/FrontendEventIngestRequest.ts +27 -0
- package/src/_api/generated/_cfg_monitor/schemas/IngestBatchRequest.ts +12 -0
- package/src/_api/generated/_cfg_monitor/schemas/LevelEnum.ts +9 -0
- package/src/_api/generated/_cfg_monitor/schemas/index.ts +7 -0
- package/src/_api/generated/_cfg_monitor/sdk.gen.ts +5 -0
- package/src/_api/generated/_cfg_monitor/types.gen.ts +5 -0
- package/src/_api/generated/client/client.gen.ts +280 -0
- package/src/_api/generated/client/index.ts +25 -0
- package/src/_api/generated/client/types.gen.ts +217 -0
- package/src/_api/generated/client/utils.gen.ts +318 -0
- package/src/_api/generated/client.gen.ts +16 -0
- package/src/_api/generated/core/auth.gen.ts +41 -0
- package/src/_api/generated/core/bodySerializer.gen.ts +82 -0
- package/src/_api/generated/core/params.gen.ts +169 -0
- package/src/_api/generated/core/pathSerializer.gen.ts +171 -0
- package/src/_api/generated/core/queryKeySerializer.gen.ts +117 -0
- package/src/_api/generated/core/serverSentEvents.gen.ts +242 -0
- package/src/_api/generated/core/types.gen.ts +104 -0
- package/src/_api/generated/core/utils.gen.ts +140 -0
- package/src/_api/generated/helpers/errors.ts +70 -0
- package/src/_api/generated/helpers/index.ts +25 -0
- package/src/_api/generated/helpers/logger.ts +123 -0
- package/src/_api/generated/helpers/storage.ts +83 -0
- package/src/_api/generated/helpers/validation-events.ts +52 -0
- package/src/_api/generated/index.ts +22 -0
- package/src/_api/generated/sdk.gen.ts +55 -0
- package/src/_api/generated/types.gen.ts +79 -0
- package/src/_api/index.ts +2 -2
- package/src/client/capture/console.ts +2 -3
- package/src/client/transport/ingest.ts +21 -17
- package/src/server/index.ts +3 -2
- package/src/_api/generated/cfg_monitor/CLAUDE.md +0 -60
- package/src/_api/generated/cfg_monitor/_utils/fetchers/index.ts +0 -30
- package/src/_api/generated/cfg_monitor/_utils/fetchers/monitor.ts +0 -51
- package/src/_api/generated/cfg_monitor/_utils/hooks/index.ts +0 -30
- package/src/_api/generated/cfg_monitor/_utils/hooks/monitor.ts +0 -43
- package/src/_api/generated/cfg_monitor/_utils/schemas/FrontendEventIngestRequest.schema.ts +0 -34
- package/src/_api/generated/cfg_monitor/_utils/schemas/IngestBatchRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_monitor/_utils/schemas/index.ts +0 -22
- package/src/_api/generated/cfg_monitor/api-instance.ts +0 -181
- package/src/_api/generated/cfg_monitor/client.ts +0 -330
- package/src/_api/generated/cfg_monitor/enums.ts +0 -34
- package/src/_api/generated/cfg_monitor/errors.ts +0 -123
- package/src/_api/generated/cfg_monitor/http.ts +0 -160
- package/src/_api/generated/cfg_monitor/index.ts +0 -317
- package/src/_api/generated/cfg_monitor/logger.ts +0 -261
- package/src/_api/generated/cfg_monitor/monitor/client.ts +0 -26
- package/src/_api/generated/cfg_monitor/monitor/index.ts +0 -4
- package/src/_api/generated/cfg_monitor/monitor/models.ts +0 -47
- package/src/_api/generated/cfg_monitor/retry.ts +0 -177
- package/src/_api/generated/cfg_monitor/schema.json +0 -181
- package/src/_api/generated/cfg_monitor/storage.ts +0 -163
- package/src/_api/generated/cfg_monitor/validation-events.ts +0 -135
package/dist/client.mjs
CHANGED
|
@@ -1,262 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
11
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
5
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
30
6
|
|
|
31
|
-
// ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
|
|
32
|
-
var require_retry_operation = __commonJS({
|
|
33
|
-
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module) {
|
|
34
|
-
function RetryOperation(timeouts, options) {
|
|
35
|
-
if (typeof options === "boolean") {
|
|
36
|
-
options = { forever: options };
|
|
37
|
-
}
|
|
38
|
-
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
39
|
-
this._timeouts = timeouts;
|
|
40
|
-
this._options = options || {};
|
|
41
|
-
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
42
|
-
this._fn = null;
|
|
43
|
-
this._errors = [];
|
|
44
|
-
this._attempts = 1;
|
|
45
|
-
this._operationTimeout = null;
|
|
46
|
-
this._operationTimeoutCb = null;
|
|
47
|
-
this._timeout = null;
|
|
48
|
-
this._operationStart = null;
|
|
49
|
-
this._timer = null;
|
|
50
|
-
if (this._options.forever) {
|
|
51
|
-
this._cachedTimeouts = this._timeouts.slice(0);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
__name(RetryOperation, "RetryOperation");
|
|
55
|
-
module.exports = RetryOperation;
|
|
56
|
-
RetryOperation.prototype.reset = function() {
|
|
57
|
-
this._attempts = 1;
|
|
58
|
-
this._timeouts = this._originalTimeouts.slice(0);
|
|
59
|
-
};
|
|
60
|
-
RetryOperation.prototype.stop = function() {
|
|
61
|
-
if (this._timeout) {
|
|
62
|
-
clearTimeout(this._timeout);
|
|
63
|
-
}
|
|
64
|
-
if (this._timer) {
|
|
65
|
-
clearTimeout(this._timer);
|
|
66
|
-
}
|
|
67
|
-
this._timeouts = [];
|
|
68
|
-
this._cachedTimeouts = null;
|
|
69
|
-
};
|
|
70
|
-
RetryOperation.prototype.retry = function(err) {
|
|
71
|
-
if (this._timeout) {
|
|
72
|
-
clearTimeout(this._timeout);
|
|
73
|
-
}
|
|
74
|
-
if (!err) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
78
|
-
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
79
|
-
this._errors.push(err);
|
|
80
|
-
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
this._errors.push(err);
|
|
84
|
-
var timeout = this._timeouts.shift();
|
|
85
|
-
if (timeout === void 0) {
|
|
86
|
-
if (this._cachedTimeouts) {
|
|
87
|
-
this._errors.splice(0, this._errors.length - 1);
|
|
88
|
-
timeout = this._cachedTimeouts.slice(-1);
|
|
89
|
-
} else {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
var self = this;
|
|
94
|
-
this._timer = setTimeout(function() {
|
|
95
|
-
self._attempts++;
|
|
96
|
-
if (self._operationTimeoutCb) {
|
|
97
|
-
self._timeout = setTimeout(function() {
|
|
98
|
-
self._operationTimeoutCb(self._attempts);
|
|
99
|
-
}, self._operationTimeout);
|
|
100
|
-
if (self._options.unref) {
|
|
101
|
-
self._timeout.unref();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
self._fn(self._attempts);
|
|
105
|
-
}, timeout);
|
|
106
|
-
if (this._options.unref) {
|
|
107
|
-
this._timer.unref();
|
|
108
|
-
}
|
|
109
|
-
return true;
|
|
110
|
-
};
|
|
111
|
-
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
112
|
-
this._fn = fn;
|
|
113
|
-
if (timeoutOps) {
|
|
114
|
-
if (timeoutOps.timeout) {
|
|
115
|
-
this._operationTimeout = timeoutOps.timeout;
|
|
116
|
-
}
|
|
117
|
-
if (timeoutOps.cb) {
|
|
118
|
-
this._operationTimeoutCb = timeoutOps.cb;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
var self = this;
|
|
122
|
-
if (this._operationTimeoutCb) {
|
|
123
|
-
this._timeout = setTimeout(function() {
|
|
124
|
-
self._operationTimeoutCb();
|
|
125
|
-
}, self._operationTimeout);
|
|
126
|
-
}
|
|
127
|
-
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
128
|
-
this._fn(this._attempts);
|
|
129
|
-
};
|
|
130
|
-
RetryOperation.prototype.try = function(fn) {
|
|
131
|
-
console.log("Using RetryOperation.try() is deprecated");
|
|
132
|
-
this.attempt(fn);
|
|
133
|
-
};
|
|
134
|
-
RetryOperation.prototype.start = function(fn) {
|
|
135
|
-
console.log("Using RetryOperation.start() is deprecated");
|
|
136
|
-
this.attempt(fn);
|
|
137
|
-
};
|
|
138
|
-
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
139
|
-
RetryOperation.prototype.errors = function() {
|
|
140
|
-
return this._errors;
|
|
141
|
-
};
|
|
142
|
-
RetryOperation.prototype.attempts = function() {
|
|
143
|
-
return this._attempts;
|
|
144
|
-
};
|
|
145
|
-
RetryOperation.prototype.mainError = function() {
|
|
146
|
-
if (this._errors.length === 0) {
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
var counts = {};
|
|
150
|
-
var mainError = null;
|
|
151
|
-
var mainErrorCount = 0;
|
|
152
|
-
for (var i = 0; i < this._errors.length; i++) {
|
|
153
|
-
var error = this._errors[i];
|
|
154
|
-
var message = error.message;
|
|
155
|
-
var count = (counts[message] || 0) + 1;
|
|
156
|
-
counts[message] = count;
|
|
157
|
-
if (count >= mainErrorCount) {
|
|
158
|
-
mainError = error;
|
|
159
|
-
mainErrorCount = count;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return mainError;
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js
|
|
168
|
-
var require_retry = __commonJS({
|
|
169
|
-
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports) {
|
|
170
|
-
var RetryOperation = require_retry_operation();
|
|
171
|
-
exports.operation = function(options) {
|
|
172
|
-
var timeouts = exports.timeouts(options);
|
|
173
|
-
return new RetryOperation(timeouts, {
|
|
174
|
-
forever: options && (options.forever || options.retries === Infinity),
|
|
175
|
-
unref: options && options.unref,
|
|
176
|
-
maxRetryTime: options && options.maxRetryTime
|
|
177
|
-
});
|
|
178
|
-
};
|
|
179
|
-
exports.timeouts = function(options) {
|
|
180
|
-
if (options instanceof Array) {
|
|
181
|
-
return [].concat(options);
|
|
182
|
-
}
|
|
183
|
-
var opts = {
|
|
184
|
-
retries: 10,
|
|
185
|
-
factor: 2,
|
|
186
|
-
minTimeout: 1 * 1e3,
|
|
187
|
-
maxTimeout: Infinity,
|
|
188
|
-
randomize: false
|
|
189
|
-
};
|
|
190
|
-
for (var key in options) {
|
|
191
|
-
opts[key] = options[key];
|
|
192
|
-
}
|
|
193
|
-
if (opts.minTimeout > opts.maxTimeout) {
|
|
194
|
-
throw new Error("minTimeout is greater than maxTimeout");
|
|
195
|
-
}
|
|
196
|
-
var timeouts = [];
|
|
197
|
-
for (var i = 0; i < opts.retries; i++) {
|
|
198
|
-
timeouts.push(this.createTimeout(i, opts));
|
|
199
|
-
}
|
|
200
|
-
if (options && options.forever && !timeouts.length) {
|
|
201
|
-
timeouts.push(this.createTimeout(i, opts));
|
|
202
|
-
}
|
|
203
|
-
timeouts.sort(function(a, b) {
|
|
204
|
-
return a - b;
|
|
205
|
-
});
|
|
206
|
-
return timeouts;
|
|
207
|
-
};
|
|
208
|
-
exports.createTimeout = function(attempt, opts) {
|
|
209
|
-
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
210
|
-
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
|
|
211
|
-
timeout = Math.min(timeout, opts.maxTimeout);
|
|
212
|
-
return timeout;
|
|
213
|
-
};
|
|
214
|
-
exports.wrap = function(obj, options, methods) {
|
|
215
|
-
if (options instanceof Array) {
|
|
216
|
-
methods = options;
|
|
217
|
-
options = null;
|
|
218
|
-
}
|
|
219
|
-
if (!methods) {
|
|
220
|
-
methods = [];
|
|
221
|
-
for (var key in obj) {
|
|
222
|
-
if (typeof obj[key] === "function") {
|
|
223
|
-
methods.push(key);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
for (var i = 0; i < methods.length; i++) {
|
|
228
|
-
var method = methods[i];
|
|
229
|
-
var original = obj[method];
|
|
230
|
-
obj[method] = (/* @__PURE__ */ __name(function retryWrapper(original2) {
|
|
231
|
-
var op = exports.operation(options);
|
|
232
|
-
var args = Array.prototype.slice.call(arguments, 1);
|
|
233
|
-
var callback = args.pop();
|
|
234
|
-
args.push(function(err) {
|
|
235
|
-
if (op.retry(err)) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
if (err) {
|
|
239
|
-
arguments[0] = op.mainError();
|
|
240
|
-
}
|
|
241
|
-
callback.apply(this, arguments);
|
|
242
|
-
});
|
|
243
|
-
op.attempt(function() {
|
|
244
|
-
original2.apply(obj, args);
|
|
245
|
-
});
|
|
246
|
-
}, "retryWrapper")).bind(obj, original);
|
|
247
|
-
obj[method].options = options;
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
// ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js
|
|
254
|
-
var require_retry2 = __commonJS({
|
|
255
|
-
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports, module) {
|
|
256
|
-
module.exports = require_retry();
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
|
|
260
7
|
// src/client/capture/fingerprint.ts
|
|
261
8
|
function simpleHash(str) {
|
|
262
9
|
let hash = 0;
|
|
@@ -319,200 +66,864 @@ __name(ensureSessionCookie, "ensureSessionCookie");
|
|
|
319
66
|
// src/client/store/index.ts
|
|
320
67
|
import { createStore } from "zustand/vanilla";
|
|
321
68
|
|
|
322
|
-
// src/_api/generated/
|
|
323
|
-
var
|
|
324
|
-
|
|
325
|
-
__publicField(this, "client");
|
|
326
|
-
this.client = client;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Ingest browser events
|
|
330
|
-
*
|
|
331
|
-
* Accepts a batch of up to 50 frontend events. No authentication required
|
|
332
|
-
* — anonymous visitors can send events.
|
|
333
|
-
*/
|
|
334
|
-
async ingestCreate(data) {
|
|
335
|
-
const response = await this.client.request("POST", "/cfg/monitor/ingest/", { body: data });
|
|
336
|
-
return response;
|
|
337
|
-
}
|
|
69
|
+
// src/_api/generated/core/bodySerializer.gen.ts
|
|
70
|
+
var jsonBodySerializer = {
|
|
71
|
+
bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
|
|
338
72
|
};
|
|
339
|
-
__name(_Monitor, "Monitor");
|
|
340
|
-
var Monitor = _Monitor;
|
|
341
73
|
|
|
342
|
-
// src/_api/generated/
|
|
343
|
-
var
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
74
|
+
// src/_api/generated/core/params.gen.ts
|
|
75
|
+
var extraPrefixesMap = {
|
|
76
|
+
$body_: "body",
|
|
77
|
+
$headers_: "headers",
|
|
78
|
+
$path_: "path",
|
|
79
|
+
$query_: "query"
|
|
80
|
+
};
|
|
81
|
+
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
82
|
+
|
|
83
|
+
// src/_api/generated/core/serverSentEvents.gen.ts
|
|
84
|
+
function createSseClient({
|
|
85
|
+
onRequest,
|
|
86
|
+
onSseError,
|
|
87
|
+
onSseEvent,
|
|
88
|
+
responseTransformer,
|
|
89
|
+
responseValidator,
|
|
90
|
+
sseDefaultRetryDelay,
|
|
91
|
+
sseMaxRetryAttempts,
|
|
92
|
+
sseMaxRetryDelay,
|
|
93
|
+
sseSleepFn,
|
|
94
|
+
url,
|
|
95
|
+
...options
|
|
96
|
+
}) {
|
|
97
|
+
let lastEventId;
|
|
98
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
99
|
+
const createStream = /* @__PURE__ */ __name(async function* () {
|
|
100
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
101
|
+
let attempt = 0;
|
|
102
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
103
|
+
while (true) {
|
|
104
|
+
if (signal.aborted) break;
|
|
105
|
+
attempt++;
|
|
106
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
107
|
+
if (lastEventId !== void 0) {
|
|
108
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const requestInit = {
|
|
112
|
+
redirect: "follow",
|
|
113
|
+
...options,
|
|
114
|
+
body: options.serializedBody,
|
|
115
|
+
headers,
|
|
116
|
+
signal
|
|
117
|
+
};
|
|
118
|
+
let request = new Request(url, requestInit);
|
|
119
|
+
if (onRequest) {
|
|
120
|
+
request = await onRequest(url, requestInit);
|
|
352
121
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
122
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
123
|
+
const response = await _fetch(request);
|
|
124
|
+
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
125
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
126
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
127
|
+
let buffer = "";
|
|
128
|
+
const abortHandler = /* @__PURE__ */ __name(() => {
|
|
129
|
+
try {
|
|
130
|
+
reader.cancel();
|
|
131
|
+
} catch {
|
|
132
|
+
}
|
|
133
|
+
}, "abortHandler");
|
|
134
|
+
signal.addEventListener("abort", abortHandler);
|
|
135
|
+
try {
|
|
136
|
+
while (true) {
|
|
137
|
+
const { done, value } = await reader.read();
|
|
138
|
+
if (done) break;
|
|
139
|
+
buffer += value;
|
|
140
|
+
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
141
|
+
const chunks = buffer.split("\n\n");
|
|
142
|
+
buffer = chunks.pop() ?? "";
|
|
143
|
+
for (const chunk of chunks) {
|
|
144
|
+
const lines = chunk.split("\n");
|
|
145
|
+
const dataLines = [];
|
|
146
|
+
let eventName;
|
|
147
|
+
for (const line of lines) {
|
|
148
|
+
if (line.startsWith("data:")) {
|
|
149
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
150
|
+
} else if (line.startsWith("event:")) {
|
|
151
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
152
|
+
} else if (line.startsWith("id:")) {
|
|
153
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
154
|
+
} else if (line.startsWith("retry:")) {
|
|
155
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
156
|
+
if (!Number.isNaN(parsed)) {
|
|
157
|
+
retryDelay = parsed;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let data;
|
|
162
|
+
let parsedJson = false;
|
|
163
|
+
if (dataLines.length) {
|
|
164
|
+
const rawData = dataLines.join("\n");
|
|
165
|
+
try {
|
|
166
|
+
data = JSON.parse(rawData);
|
|
167
|
+
parsedJson = true;
|
|
168
|
+
} catch {
|
|
169
|
+
data = rawData;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (parsedJson) {
|
|
173
|
+
if (responseValidator) {
|
|
174
|
+
await responseValidator(data);
|
|
175
|
+
}
|
|
176
|
+
if (responseTransformer) {
|
|
177
|
+
data = await responseTransformer(data);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
onSseEvent?.({
|
|
181
|
+
data,
|
|
182
|
+
event: eventName,
|
|
183
|
+
id: lastEventId,
|
|
184
|
+
retry: retryDelay
|
|
185
|
+
});
|
|
186
|
+
if (dataLines.length) {
|
|
187
|
+
yield data;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
} finally {
|
|
192
|
+
signal.removeEventListener("abort", abortHandler);
|
|
193
|
+
reader.releaseLock();
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
} catch (error) {
|
|
197
|
+
onSseError?.(error);
|
|
198
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
202
|
+
await sleep(backoff);
|
|
357
203
|
}
|
|
358
204
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
205
|
+
}, "createStream");
|
|
206
|
+
const stream = createStream();
|
|
207
|
+
return { stream };
|
|
208
|
+
}
|
|
209
|
+
__name(createSseClient, "createSseClient");
|
|
210
|
+
|
|
211
|
+
// src/_api/generated/core/pathSerializer.gen.ts
|
|
212
|
+
var separatorArrayExplode = /* @__PURE__ */ __name((style) => {
|
|
213
|
+
switch (style) {
|
|
214
|
+
case "label":
|
|
215
|
+
return ".";
|
|
216
|
+
case "matrix":
|
|
217
|
+
return ";";
|
|
218
|
+
case "simple":
|
|
219
|
+
return ",";
|
|
220
|
+
default:
|
|
221
|
+
return "&";
|
|
222
|
+
}
|
|
223
|
+
}, "separatorArrayExplode");
|
|
224
|
+
var separatorArrayNoExplode = /* @__PURE__ */ __name((style) => {
|
|
225
|
+
switch (style) {
|
|
226
|
+
case "form":
|
|
227
|
+
return ",";
|
|
228
|
+
case "pipeDelimited":
|
|
229
|
+
return "|";
|
|
230
|
+
case "spaceDelimited":
|
|
231
|
+
return "%20";
|
|
232
|
+
default:
|
|
233
|
+
return ",";
|
|
234
|
+
}
|
|
235
|
+
}, "separatorArrayNoExplode");
|
|
236
|
+
var separatorObjectExplode = /* @__PURE__ */ __name((style) => {
|
|
237
|
+
switch (style) {
|
|
238
|
+
case "label":
|
|
239
|
+
return ".";
|
|
240
|
+
case "matrix":
|
|
241
|
+
return ";";
|
|
242
|
+
case "simple":
|
|
243
|
+
return ",";
|
|
244
|
+
default:
|
|
245
|
+
return "&";
|
|
246
|
+
}
|
|
247
|
+
}, "separatorObjectExplode");
|
|
248
|
+
var serializeArrayParam = /* @__PURE__ */ __name(({
|
|
249
|
+
allowReserved,
|
|
250
|
+
explode,
|
|
251
|
+
name,
|
|
252
|
+
style,
|
|
253
|
+
value
|
|
254
|
+
}) => {
|
|
255
|
+
if (!explode) {
|
|
256
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
257
|
+
switch (style) {
|
|
258
|
+
case "label":
|
|
259
|
+
return `.${joinedValues2}`;
|
|
260
|
+
case "matrix":
|
|
261
|
+
return `;${name}=${joinedValues2}`;
|
|
262
|
+
case "simple":
|
|
263
|
+
return joinedValues2;
|
|
264
|
+
default:
|
|
265
|
+
return `${name}=${joinedValues2}`;
|
|
369
266
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
// Include Django session cookies
|
|
376
|
-
});
|
|
377
|
-
let data = null;
|
|
378
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
379
|
-
if (response.status !== 204) {
|
|
380
|
-
if (responseType === "blob") {
|
|
381
|
-
data = await response.blob();
|
|
382
|
-
} else if (responseType === "text") {
|
|
383
|
-
data = await response.text();
|
|
384
|
-
} else if (responseType === "json") {
|
|
385
|
-
data = await response.json();
|
|
386
|
-
} else if (contentType.includes("application/json")) {
|
|
387
|
-
data = await response.json();
|
|
388
|
-
} else if (contentType.startsWith("text/")) {
|
|
389
|
-
data = await response.text();
|
|
390
|
-
} else {
|
|
391
|
-
data = await response.blob();
|
|
392
|
-
}
|
|
267
|
+
}
|
|
268
|
+
const separator = separatorArrayExplode(style);
|
|
269
|
+
const joinedValues = value.map((v) => {
|
|
270
|
+
if (style === "label" || style === "simple") {
|
|
271
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
393
272
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
273
|
+
return serializePrimitiveParam({
|
|
274
|
+
allowReserved,
|
|
275
|
+
name,
|
|
276
|
+
value: v
|
|
397
277
|
});
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
278
|
+
}).join(separator);
|
|
279
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
280
|
+
}, "serializeArrayParam");
|
|
281
|
+
var serializePrimitiveParam = /* @__PURE__ */ __name(({
|
|
282
|
+
allowReserved,
|
|
283
|
+
name,
|
|
284
|
+
value
|
|
285
|
+
}) => {
|
|
286
|
+
if (value === void 0 || value === null) {
|
|
287
|
+
return "";
|
|
288
|
+
}
|
|
289
|
+
if (typeof value === "object") {
|
|
290
|
+
throw new Error(
|
|
291
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
292
|
+
);
|
|
404
293
|
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
var
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
294
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
295
|
+
}, "serializePrimitiveParam");
|
|
296
|
+
var serializeObjectParam = /* @__PURE__ */ __name(({
|
|
297
|
+
allowReserved,
|
|
298
|
+
explode,
|
|
299
|
+
name,
|
|
300
|
+
style,
|
|
301
|
+
value,
|
|
302
|
+
valueOnly
|
|
303
|
+
}) => {
|
|
304
|
+
if (value instanceof Date) {
|
|
305
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
306
|
+
}
|
|
307
|
+
if (style !== "deepObject" && !explode) {
|
|
308
|
+
let values = [];
|
|
309
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
310
|
+
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
311
|
+
});
|
|
312
|
+
const joinedValues2 = values.join(",");
|
|
313
|
+
switch (style) {
|
|
314
|
+
case "form":
|
|
315
|
+
return `${name}=${joinedValues2}`;
|
|
316
|
+
case "label":
|
|
317
|
+
return `.${joinedValues2}`;
|
|
318
|
+
case "matrix":
|
|
319
|
+
return `;${name}=${joinedValues2}`;
|
|
320
|
+
default:
|
|
321
|
+
return joinedValues2;
|
|
416
322
|
}
|
|
417
323
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
324
|
+
const separator = separatorObjectExplode(style);
|
|
325
|
+
const joinedValues = Object.entries(value).map(
|
|
326
|
+
([key, v]) => serializePrimitiveParam({
|
|
327
|
+
allowReserved,
|
|
328
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
329
|
+
value: v
|
|
330
|
+
})
|
|
331
|
+
).join(separator);
|
|
332
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
333
|
+
}, "serializeObjectParam");
|
|
421
334
|
|
|
422
|
-
// src/_api/generated/
|
|
423
|
-
var
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
335
|
+
// src/_api/generated/core/utils.gen.ts
|
|
336
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
337
|
+
var defaultPathSerializer = /* @__PURE__ */ __name(({ path, url: _url }) => {
|
|
338
|
+
let url = _url;
|
|
339
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
340
|
+
if (matches) {
|
|
341
|
+
for (const match of matches) {
|
|
342
|
+
let explode = false;
|
|
343
|
+
let name = match.substring(1, match.length - 1);
|
|
344
|
+
let style = "simple";
|
|
345
|
+
if (name.endsWith("*")) {
|
|
346
|
+
explode = true;
|
|
347
|
+
name = name.substring(0, name.length - 1);
|
|
348
|
+
}
|
|
349
|
+
if (name.startsWith(".")) {
|
|
350
|
+
name = name.substring(1);
|
|
351
|
+
style = "label";
|
|
352
|
+
} else if (name.startsWith(";")) {
|
|
353
|
+
name = name.substring(1);
|
|
354
|
+
style = "matrix";
|
|
355
|
+
}
|
|
356
|
+
const value = path[name];
|
|
357
|
+
if (value === void 0 || value === null) {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (Array.isArray(value)) {
|
|
361
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (typeof value === "object") {
|
|
365
|
+
url = url.replace(
|
|
366
|
+
match,
|
|
367
|
+
serializeObjectParam({
|
|
368
|
+
explode,
|
|
369
|
+
name,
|
|
370
|
+
style,
|
|
371
|
+
value,
|
|
372
|
+
valueOnly: true
|
|
373
|
+
})
|
|
374
|
+
);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (style === "matrix") {
|
|
378
|
+
url = url.replace(
|
|
379
|
+
match,
|
|
380
|
+
`;${serializePrimitiveParam({
|
|
381
|
+
name,
|
|
382
|
+
value
|
|
383
|
+
})}`
|
|
384
|
+
);
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const replaceValue = encodeURIComponent(
|
|
388
|
+
style === "label" ? `.${value}` : value
|
|
389
|
+
);
|
|
390
|
+
url = url.replace(match, replaceValue);
|
|
391
|
+
}
|
|
431
392
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
393
|
+
return url;
|
|
394
|
+
}, "defaultPathSerializer");
|
|
395
|
+
var getUrl = /* @__PURE__ */ __name(({
|
|
396
|
+
baseUrl,
|
|
397
|
+
path,
|
|
398
|
+
query,
|
|
399
|
+
querySerializer,
|
|
400
|
+
url: _url
|
|
401
|
+
}) => {
|
|
402
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
403
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
404
|
+
if (path) {
|
|
405
|
+
url = defaultPathSerializer({ path, url });
|
|
406
|
+
}
|
|
407
|
+
let search = query ? querySerializer(query) : "";
|
|
408
|
+
if (search.startsWith("?")) {
|
|
409
|
+
search = search.substring(1);
|
|
410
|
+
}
|
|
411
|
+
if (search) {
|
|
412
|
+
url += `?${search}`;
|
|
413
|
+
}
|
|
414
|
+
return url;
|
|
415
|
+
}, "getUrl");
|
|
416
|
+
function getValidRequestBody(options) {
|
|
417
|
+
const hasBody = options.body !== void 0;
|
|
418
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
419
|
+
if (isSerializedBody) {
|
|
420
|
+
if ("serializedBody" in options) {
|
|
421
|
+
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
422
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
439
423
|
}
|
|
440
|
-
return null;
|
|
424
|
+
return options.body !== "" ? options.body : null;
|
|
441
425
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
426
|
+
if (hasBody) {
|
|
427
|
+
return options.body;
|
|
428
|
+
}
|
|
429
|
+
return void 0;
|
|
430
|
+
}
|
|
431
|
+
__name(getValidRequestBody, "getValidRequestBody");
|
|
432
|
+
|
|
433
|
+
// src/_api/generated/core/auth.gen.ts
|
|
434
|
+
var getAuthToken = /* @__PURE__ */ __name(async (auth, callback) => {
|
|
435
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
436
|
+
if (!token) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (auth.scheme === "bearer") {
|
|
440
|
+
return `Bearer ${token}`;
|
|
441
|
+
}
|
|
442
|
+
if (auth.scheme === "basic") {
|
|
443
|
+
return `Basic ${btoa(token)}`;
|
|
444
|
+
}
|
|
445
|
+
return token;
|
|
446
|
+
}, "getAuthToken");
|
|
447
|
+
|
|
448
|
+
// src/_api/generated/client/utils.gen.ts
|
|
449
|
+
var createQuerySerializer = /* @__PURE__ */ __name(({
|
|
450
|
+
parameters = {},
|
|
451
|
+
...args
|
|
452
|
+
} = {}) => {
|
|
453
|
+
const querySerializer = /* @__PURE__ */ __name((queryParams) => {
|
|
454
|
+
const search = [];
|
|
455
|
+
if (queryParams && typeof queryParams === "object") {
|
|
456
|
+
for (const name in queryParams) {
|
|
457
|
+
const value = queryParams[name];
|
|
458
|
+
if (value === void 0 || value === null) {
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
const options = parameters[name] || args;
|
|
462
|
+
if (Array.isArray(value)) {
|
|
463
|
+
const serializedArray = serializeArrayParam({
|
|
464
|
+
allowReserved: options.allowReserved,
|
|
465
|
+
explode: true,
|
|
466
|
+
name,
|
|
467
|
+
style: "form",
|
|
468
|
+
value,
|
|
469
|
+
...options.array
|
|
470
|
+
});
|
|
471
|
+
if (serializedArray) search.push(serializedArray);
|
|
472
|
+
} else if (typeof value === "object") {
|
|
473
|
+
const serializedObject = serializeObjectParam({
|
|
474
|
+
allowReserved: options.allowReserved,
|
|
475
|
+
explode: true,
|
|
476
|
+
name,
|
|
477
|
+
style: "deepObject",
|
|
478
|
+
value,
|
|
479
|
+
...options.object
|
|
480
|
+
});
|
|
481
|
+
if (serializedObject) search.push(serializedObject);
|
|
482
|
+
} else {
|
|
483
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
484
|
+
allowReserved: options.allowReserved,
|
|
485
|
+
name,
|
|
486
|
+
value
|
|
487
|
+
});
|
|
488
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
489
|
+
}
|
|
453
490
|
}
|
|
454
491
|
}
|
|
455
|
-
return
|
|
492
|
+
return search.join("&");
|
|
493
|
+
}, "querySerializer");
|
|
494
|
+
return querySerializer;
|
|
495
|
+
}, "createQuerySerializer");
|
|
496
|
+
var getParseAs = /* @__PURE__ */ __name((contentType) => {
|
|
497
|
+
if (!contentType) {
|
|
498
|
+
return "stream";
|
|
499
|
+
}
|
|
500
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
501
|
+
if (!cleanContent) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
505
|
+
return "json";
|
|
506
|
+
}
|
|
507
|
+
if (cleanContent === "multipart/form-data") {
|
|
508
|
+
return "formData";
|
|
509
|
+
}
|
|
510
|
+
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
511
|
+
return "blob";
|
|
512
|
+
}
|
|
513
|
+
if (cleanContent.startsWith("text/")) {
|
|
514
|
+
return "text";
|
|
515
|
+
}
|
|
516
|
+
return;
|
|
517
|
+
}, "getParseAs");
|
|
518
|
+
var checkForExistence = /* @__PURE__ */ __name((options, name) => {
|
|
519
|
+
if (!name) {
|
|
520
|
+
return false;
|
|
456
521
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
522
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
523
|
+
return true;
|
|
524
|
+
}
|
|
525
|
+
return false;
|
|
526
|
+
}, "checkForExistence");
|
|
527
|
+
var setAuthParams = /* @__PURE__ */ __name(async ({
|
|
528
|
+
security,
|
|
529
|
+
...options
|
|
530
|
+
}) => {
|
|
531
|
+
for (const auth of security) {
|
|
532
|
+
if (checkForExistence(options, auth.name)) {
|
|
533
|
+
continue;
|
|
466
534
|
}
|
|
467
|
-
|
|
468
|
-
|
|
535
|
+
const token = await getAuthToken(auth, options.auth);
|
|
536
|
+
if (!token) {
|
|
537
|
+
continue;
|
|
469
538
|
}
|
|
470
|
-
|
|
471
|
-
|
|
539
|
+
const name = auth.name ?? "Authorization";
|
|
540
|
+
switch (auth.in) {
|
|
541
|
+
case "query":
|
|
542
|
+
if (!options.query) {
|
|
543
|
+
options.query = {};
|
|
544
|
+
}
|
|
545
|
+
options.query[name] = token;
|
|
546
|
+
break;
|
|
547
|
+
case "cookie":
|
|
548
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
549
|
+
break;
|
|
550
|
+
case "header":
|
|
551
|
+
default:
|
|
552
|
+
options.headers.set(name, token);
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}, "setAuthParams");
|
|
557
|
+
var buildUrl = /* @__PURE__ */ __name((options) => getUrl({
|
|
558
|
+
baseUrl: options.baseUrl,
|
|
559
|
+
path: options.path,
|
|
560
|
+
query: options.query,
|
|
561
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
562
|
+
url: options.url
|
|
563
|
+
}), "buildUrl");
|
|
564
|
+
var mergeConfigs = /* @__PURE__ */ __name((a, b) => {
|
|
565
|
+
const config = { ...a, ...b };
|
|
566
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
567
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
568
|
+
}
|
|
569
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
570
|
+
return config;
|
|
571
|
+
}, "mergeConfigs");
|
|
572
|
+
var headersEntries = /* @__PURE__ */ __name((headers) => {
|
|
573
|
+
const entries = [];
|
|
574
|
+
headers.forEach((value, key) => {
|
|
575
|
+
entries.push([key, value]);
|
|
576
|
+
});
|
|
577
|
+
return entries;
|
|
578
|
+
}, "headersEntries");
|
|
579
|
+
var mergeHeaders = /* @__PURE__ */ __name((...headers) => {
|
|
580
|
+
const mergedHeaders = new Headers();
|
|
581
|
+
for (const header of headers) {
|
|
582
|
+
if (!header) {
|
|
583
|
+
continue;
|
|
472
584
|
}
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
585
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
586
|
+
for (const [key, value] of iterator) {
|
|
587
|
+
if (value === null) {
|
|
588
|
+
mergedHeaders.delete(key);
|
|
589
|
+
} else if (Array.isArray(value)) {
|
|
590
|
+
for (const v of value) {
|
|
591
|
+
mergedHeaders.append(key, v);
|
|
592
|
+
}
|
|
593
|
+
} else if (value !== void 0) {
|
|
594
|
+
mergedHeaders.set(
|
|
595
|
+
key,
|
|
596
|
+
typeof value === "object" ? JSON.stringify(value) : value
|
|
597
|
+
);
|
|
478
598
|
}
|
|
479
599
|
}
|
|
480
|
-
return this.message;
|
|
481
600
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
601
|
+
return mergedHeaders;
|
|
602
|
+
}, "mergeHeaders");
|
|
603
|
+
var _Interceptors = class _Interceptors {
|
|
604
|
+
constructor() {
|
|
605
|
+
__publicField(this, "fns", []);
|
|
606
|
+
}
|
|
607
|
+
clear() {
|
|
608
|
+
this.fns = [];
|
|
609
|
+
}
|
|
610
|
+
eject(id) {
|
|
611
|
+
const index = this.getInterceptorIndex(id);
|
|
612
|
+
if (this.fns[index]) {
|
|
613
|
+
this.fns[index] = null;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
exists(id) {
|
|
617
|
+
const index = this.getInterceptorIndex(id);
|
|
618
|
+
return Boolean(this.fns[index]);
|
|
619
|
+
}
|
|
620
|
+
getInterceptorIndex(id) {
|
|
621
|
+
if (typeof id === "number") {
|
|
622
|
+
return this.fns[id] ? id : -1;
|
|
623
|
+
}
|
|
624
|
+
return this.fns.indexOf(id);
|
|
625
|
+
}
|
|
626
|
+
update(id, fn) {
|
|
627
|
+
const index = this.getInterceptorIndex(id);
|
|
628
|
+
if (this.fns[index]) {
|
|
629
|
+
this.fns[index] = fn;
|
|
630
|
+
return id;
|
|
631
|
+
}
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
634
|
+
use(fn) {
|
|
635
|
+
this.fns.push(fn);
|
|
636
|
+
return this.fns.length - 1;
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
__name(_Interceptors, "Interceptors");
|
|
640
|
+
var Interceptors = _Interceptors;
|
|
641
|
+
var createInterceptors = /* @__PURE__ */ __name(() => ({
|
|
642
|
+
error: new Interceptors(),
|
|
643
|
+
request: new Interceptors(),
|
|
644
|
+
response: new Interceptors()
|
|
645
|
+
}), "createInterceptors");
|
|
646
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
647
|
+
allowReserved: false,
|
|
648
|
+
array: {
|
|
649
|
+
explode: true,
|
|
650
|
+
style: "form"
|
|
651
|
+
},
|
|
652
|
+
object: {
|
|
653
|
+
explode: true,
|
|
654
|
+
style: "deepObject"
|
|
485
655
|
}
|
|
486
|
-
|
|
487
|
-
|
|
656
|
+
});
|
|
657
|
+
var defaultHeaders = {
|
|
658
|
+
"Content-Type": "application/json"
|
|
659
|
+
};
|
|
660
|
+
var createConfig = /* @__PURE__ */ __name((override = {}) => ({
|
|
661
|
+
...jsonBodySerializer,
|
|
662
|
+
headers: defaultHeaders,
|
|
663
|
+
parseAs: "auto",
|
|
664
|
+
querySerializer: defaultQuerySerializer,
|
|
665
|
+
...override
|
|
666
|
+
}), "createConfig");
|
|
667
|
+
|
|
668
|
+
// src/_api/generated/client/client.gen.ts
|
|
669
|
+
var createClient = /* @__PURE__ */ __name((config = {}) => {
|
|
670
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
671
|
+
const getConfig = /* @__PURE__ */ __name(() => ({ ..._config }), "getConfig");
|
|
672
|
+
const setConfig = /* @__PURE__ */ __name((config2) => {
|
|
673
|
+
_config = mergeConfigs(_config, config2);
|
|
674
|
+
return getConfig();
|
|
675
|
+
}, "setConfig");
|
|
676
|
+
const interceptors = createInterceptors();
|
|
677
|
+
const beforeRequest = /* @__PURE__ */ __name(async (options) => {
|
|
678
|
+
const opts = {
|
|
679
|
+
..._config,
|
|
680
|
+
...options,
|
|
681
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
682
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
683
|
+
serializedBody: void 0
|
|
684
|
+
};
|
|
685
|
+
if (opts.security) {
|
|
686
|
+
await setAuthParams({
|
|
687
|
+
...opts,
|
|
688
|
+
security: opts.security
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
if (opts.requestValidator) {
|
|
692
|
+
await opts.requestValidator(opts);
|
|
693
|
+
}
|
|
694
|
+
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
695
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
696
|
+
}
|
|
697
|
+
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
698
|
+
opts.headers.delete("Content-Type");
|
|
699
|
+
}
|
|
700
|
+
const resolvedOpts = opts;
|
|
701
|
+
const url = buildUrl(resolvedOpts);
|
|
702
|
+
return { opts: resolvedOpts, url };
|
|
703
|
+
}, "beforeRequest");
|
|
704
|
+
const request = /* @__PURE__ */ __name(async (options) => {
|
|
705
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
706
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
707
|
+
let request2;
|
|
708
|
+
let response;
|
|
709
|
+
try {
|
|
710
|
+
const { opts, url } = await beforeRequest(options);
|
|
711
|
+
const requestInit = {
|
|
712
|
+
redirect: "follow",
|
|
713
|
+
...opts,
|
|
714
|
+
body: getValidRequestBody(opts)
|
|
715
|
+
};
|
|
716
|
+
request2 = new Request(url, requestInit);
|
|
717
|
+
for (const fn of interceptors.request.fns) {
|
|
718
|
+
if (fn) {
|
|
719
|
+
request2 = await fn(request2, opts);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
const _fetch = opts.fetch;
|
|
723
|
+
response = await _fetch(request2);
|
|
724
|
+
for (const fn of interceptors.response.fns) {
|
|
725
|
+
if (fn) {
|
|
726
|
+
response = await fn(response, request2, opts);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
const result = {
|
|
730
|
+
request: request2,
|
|
731
|
+
response
|
|
732
|
+
};
|
|
733
|
+
if (response.ok) {
|
|
734
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
735
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
736
|
+
let emptyData;
|
|
737
|
+
switch (parseAs) {
|
|
738
|
+
case "arrayBuffer":
|
|
739
|
+
case "blob":
|
|
740
|
+
case "text":
|
|
741
|
+
emptyData = await response[parseAs]();
|
|
742
|
+
break;
|
|
743
|
+
case "formData":
|
|
744
|
+
emptyData = new FormData();
|
|
745
|
+
break;
|
|
746
|
+
case "stream":
|
|
747
|
+
emptyData = response.body;
|
|
748
|
+
break;
|
|
749
|
+
case "json":
|
|
750
|
+
default:
|
|
751
|
+
emptyData = {};
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
755
|
+
data: emptyData,
|
|
756
|
+
...result
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
let data;
|
|
760
|
+
switch (parseAs) {
|
|
761
|
+
case "arrayBuffer":
|
|
762
|
+
case "blob":
|
|
763
|
+
case "formData":
|
|
764
|
+
case "text":
|
|
765
|
+
data = await response[parseAs]();
|
|
766
|
+
break;
|
|
767
|
+
case "json": {
|
|
768
|
+
const text = await response.text();
|
|
769
|
+
data = text ? JSON.parse(text) : {};
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
case "stream":
|
|
773
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
774
|
+
data: response.body,
|
|
775
|
+
...result
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
if (parseAs === "json") {
|
|
779
|
+
if (opts.responseValidator) {
|
|
780
|
+
await opts.responseValidator(data);
|
|
781
|
+
}
|
|
782
|
+
if (opts.responseTransformer) {
|
|
783
|
+
data = await opts.responseTransformer(data);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return opts.responseStyle === "data" ? data : {
|
|
787
|
+
data,
|
|
788
|
+
...result
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
const textError = await response.text();
|
|
792
|
+
let jsonError;
|
|
793
|
+
try {
|
|
794
|
+
jsonError = JSON.parse(textError);
|
|
795
|
+
} catch {
|
|
796
|
+
}
|
|
797
|
+
throw jsonError ?? textError;
|
|
798
|
+
} catch (error) {
|
|
799
|
+
let finalError = error;
|
|
800
|
+
for (const fn of interceptors.error.fns) {
|
|
801
|
+
if (fn) {
|
|
802
|
+
finalError = await fn(finalError, response, request2, options);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
finalError = finalError || {};
|
|
806
|
+
if (throwOnError) {
|
|
807
|
+
throw finalError;
|
|
808
|
+
}
|
|
809
|
+
return responseStyle === "data" ? void 0 : {
|
|
810
|
+
error: finalError,
|
|
811
|
+
request: request2,
|
|
812
|
+
response
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
}, "request");
|
|
816
|
+
const makeMethodFn = /* @__PURE__ */ __name((method) => (options) => request({ ...options, method }), "makeMethodFn");
|
|
817
|
+
const makeSseFn = /* @__PURE__ */ __name((method) => async (options) => {
|
|
818
|
+
const { opts, url } = await beforeRequest(options);
|
|
819
|
+
return createSseClient({
|
|
820
|
+
...opts,
|
|
821
|
+
body: opts.body,
|
|
822
|
+
method,
|
|
823
|
+
onRequest: /* @__PURE__ */ __name(async (url2, init) => {
|
|
824
|
+
let request2 = new Request(url2, init);
|
|
825
|
+
for (const fn of interceptors.request.fns) {
|
|
826
|
+
if (fn) {
|
|
827
|
+
request2 = await fn(request2, opts);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
return request2;
|
|
831
|
+
}, "onRequest"),
|
|
832
|
+
serializedBody: getValidRequestBody(opts),
|
|
833
|
+
url
|
|
834
|
+
});
|
|
835
|
+
}, "makeSseFn");
|
|
836
|
+
const _buildUrl = /* @__PURE__ */ __name((options) => buildUrl({ ..._config, ...options }), "_buildUrl");
|
|
837
|
+
return {
|
|
838
|
+
buildUrl: _buildUrl,
|
|
839
|
+
connect: makeMethodFn("CONNECT"),
|
|
840
|
+
delete: makeMethodFn("DELETE"),
|
|
841
|
+
get: makeMethodFn("GET"),
|
|
842
|
+
getConfig,
|
|
843
|
+
head: makeMethodFn("HEAD"),
|
|
844
|
+
interceptors,
|
|
845
|
+
options: makeMethodFn("OPTIONS"),
|
|
846
|
+
patch: makeMethodFn("PATCH"),
|
|
847
|
+
post: makeMethodFn("POST"),
|
|
848
|
+
put: makeMethodFn("PUT"),
|
|
849
|
+
request,
|
|
850
|
+
setConfig,
|
|
851
|
+
sse: {
|
|
852
|
+
connect: makeSseFn("CONNECT"),
|
|
853
|
+
delete: makeSseFn("DELETE"),
|
|
854
|
+
get: makeSseFn("GET"),
|
|
855
|
+
head: makeSseFn("HEAD"),
|
|
856
|
+
options: makeSseFn("OPTIONS"),
|
|
857
|
+
patch: makeSseFn("PATCH"),
|
|
858
|
+
post: makeSseFn("POST"),
|
|
859
|
+
put: makeSseFn("PUT"),
|
|
860
|
+
trace: makeSseFn("TRACE")
|
|
861
|
+
},
|
|
862
|
+
trace: makeMethodFn("TRACE")
|
|
863
|
+
};
|
|
864
|
+
}, "createClient");
|
|
865
|
+
|
|
866
|
+
// src/_api/generated/client.gen.ts
|
|
867
|
+
var client = createClient(createConfig({ baseUrl: "http://localhost:8000" }));
|
|
868
|
+
|
|
869
|
+
// src/_api/generated/helpers/storage.ts
|
|
870
|
+
var _LocalStorageAdapter = class _LocalStorageAdapter {
|
|
871
|
+
getItem(key) {
|
|
872
|
+
if (typeof window === "undefined") return null;
|
|
873
|
+
try {
|
|
874
|
+
return window.localStorage.getItem(key);
|
|
875
|
+
} catch {
|
|
876
|
+
return null;
|
|
877
|
+
}
|
|
488
878
|
}
|
|
489
|
-
|
|
490
|
-
|
|
879
|
+
setItem(key, value) {
|
|
880
|
+
if (typeof window === "undefined") return;
|
|
881
|
+
try {
|
|
882
|
+
window.localStorage.setItem(key, value);
|
|
883
|
+
} catch {
|
|
884
|
+
}
|
|
491
885
|
}
|
|
492
|
-
|
|
493
|
-
|
|
886
|
+
removeItem(key) {
|
|
887
|
+
if (typeof window === "undefined") return;
|
|
888
|
+
try {
|
|
889
|
+
window.localStorage.removeItem(key);
|
|
890
|
+
} catch {
|
|
891
|
+
}
|
|
494
892
|
}
|
|
495
|
-
|
|
496
|
-
|
|
893
|
+
clear() {
|
|
894
|
+
if (typeof window === "undefined") return;
|
|
895
|
+
try {
|
|
896
|
+
window.localStorage.clear();
|
|
897
|
+
} catch {
|
|
898
|
+
}
|
|
497
899
|
}
|
|
498
900
|
};
|
|
499
|
-
__name(
|
|
500
|
-
var
|
|
501
|
-
var
|
|
502
|
-
constructor(
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
this.
|
|
901
|
+
__name(_LocalStorageAdapter, "LocalStorageAdapter");
|
|
902
|
+
var LocalStorageAdapter = _LocalStorageAdapter;
|
|
903
|
+
var _MemoryStorageAdapter = class _MemoryStorageAdapter {
|
|
904
|
+
constructor() {
|
|
905
|
+
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
906
|
+
}
|
|
907
|
+
getItem(key) {
|
|
908
|
+
return this.store.get(key) ?? null;
|
|
909
|
+
}
|
|
910
|
+
setItem(key, value) {
|
|
911
|
+
this.store.set(key, value);
|
|
912
|
+
}
|
|
913
|
+
removeItem(key) {
|
|
914
|
+
this.store.delete(key);
|
|
915
|
+
}
|
|
916
|
+
clear() {
|
|
917
|
+
this.store.clear();
|
|
507
918
|
}
|
|
508
919
|
};
|
|
509
|
-
__name(
|
|
510
|
-
var
|
|
920
|
+
__name(_MemoryStorageAdapter, "MemoryStorageAdapter");
|
|
921
|
+
var MemoryStorageAdapter = _MemoryStorageAdapter;
|
|
511
922
|
|
|
512
|
-
// src/_api/generated/
|
|
923
|
+
// src/_api/generated/helpers/logger.ts
|
|
513
924
|
import { createConsola } from "consola";
|
|
514
925
|
var DEFAULT_CONFIG = {
|
|
515
|
-
enabled: process.env.NODE_ENV !== "production",
|
|
926
|
+
enabled: typeof process !== "undefined" && process.env.NODE_ENV !== "production",
|
|
516
927
|
logRequests: true,
|
|
517
928
|
logResponses: true,
|
|
518
929
|
logErrors: true,
|
|
@@ -535,127 +946,65 @@ var _APILogger = class _APILogger {
|
|
|
535
946
|
level: this.config.enabled ? 4 : 0
|
|
536
947
|
});
|
|
537
948
|
}
|
|
538
|
-
/**
|
|
539
|
-
* Enable logging
|
|
540
|
-
*/
|
|
541
949
|
enable() {
|
|
542
950
|
this.config.enabled = true;
|
|
543
951
|
}
|
|
544
|
-
/**
|
|
545
|
-
* Disable logging
|
|
546
|
-
*/
|
|
547
952
|
disable() {
|
|
548
953
|
this.config.enabled = false;
|
|
549
954
|
}
|
|
550
|
-
/**
|
|
551
|
-
* Update configuration
|
|
552
|
-
*/
|
|
553
955
|
setConfig(config) {
|
|
554
956
|
this.config = { ...this.config, ...config };
|
|
555
957
|
}
|
|
556
|
-
/**
|
|
557
|
-
* Filter sensitive headers
|
|
558
|
-
*/
|
|
559
958
|
filterHeaders(headers) {
|
|
560
959
|
if (!headers) return {};
|
|
561
960
|
const filtered = {};
|
|
562
961
|
Object.keys(headers).forEach((key) => {
|
|
563
|
-
|
|
564
|
-
if (SENSITIVE_HEADERS.includes(lowerKey)) {
|
|
565
|
-
filtered[key] = "***";
|
|
566
|
-
} else {
|
|
567
|
-
filtered[key] = headers[key] || "";
|
|
568
|
-
}
|
|
962
|
+
filtered[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? "***" : headers[key] || "";
|
|
569
963
|
});
|
|
570
964
|
return filtered;
|
|
571
965
|
}
|
|
572
|
-
/**
|
|
573
|
-
* Log request
|
|
574
|
-
*/
|
|
575
966
|
logRequest(request) {
|
|
576
967
|
if (!this.config.enabled || !this.config.logRequests) return;
|
|
577
968
|
const { method, url, headers, body } = request;
|
|
578
969
|
this.consola.start(`${method} ${url}`);
|
|
579
|
-
if (this.config.logHeaders && headers)
|
|
580
|
-
|
|
581
|
-
}
|
|
582
|
-
if (this.config.logBodies && body) {
|
|
583
|
-
this.consola.debug("Body:", body);
|
|
584
|
-
}
|
|
970
|
+
if (this.config.logHeaders && headers) this.consola.debug("Headers:", this.filterHeaders(headers));
|
|
971
|
+
if (this.config.logBodies && body) this.consola.debug("Body:", body);
|
|
585
972
|
}
|
|
586
|
-
/**
|
|
587
|
-
* Log response
|
|
588
|
-
*/
|
|
589
973
|
logResponse(request, response) {
|
|
590
974
|
if (!this.config.enabled || !this.config.logResponses) return;
|
|
591
975
|
const { method, url } = request;
|
|
592
976
|
const { status, statusText, data, duration } = response;
|
|
593
|
-
|
|
594
|
-
this.consola.
|
|
595
|
-
`${method} ${url} ${status} ${statusText} (${duration}ms)`
|
|
596
|
-
);
|
|
597
|
-
if (this.config.logBodies && data) {
|
|
598
|
-
this.consola.debug("Response:", data);
|
|
599
|
-
}
|
|
977
|
+
this.consola.success(`${method} ${url} ${status} ${statusText} (${duration}ms)`);
|
|
978
|
+
if (this.config.logBodies && data) this.consola.debug("Response:", data);
|
|
600
979
|
}
|
|
601
|
-
/**
|
|
602
|
-
* Log error
|
|
603
|
-
*/
|
|
604
980
|
logError(request, error) {
|
|
605
981
|
if (!this.config.enabled || !this.config.logErrors) return;
|
|
606
982
|
const { method, url } = request;
|
|
607
983
|
const { message, statusCode, fieldErrors, duration } = error;
|
|
608
|
-
this.consola.error(
|
|
609
|
-
`${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`
|
|
610
|
-
);
|
|
984
|
+
this.consola.error(`${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`);
|
|
611
985
|
this.consola.error("Message:", message);
|
|
612
986
|
if (fieldErrors && Object.keys(fieldErrors).length > 0) {
|
|
613
987
|
this.consola.error("Field Errors:");
|
|
614
988
|
Object.entries(fieldErrors).forEach(([field, errors]) => {
|
|
615
|
-
errors.forEach((err) => {
|
|
616
|
-
this.consola.error(` \u2022 ${field}: ${err}`);
|
|
617
|
-
});
|
|
989
|
+
errors.forEach((err) => this.consola.error(` \u2022 ${field}: ${err}`));
|
|
618
990
|
});
|
|
619
991
|
}
|
|
620
992
|
}
|
|
621
|
-
/**
|
|
622
|
-
* Log general info
|
|
623
|
-
*/
|
|
624
993
|
info(message, ...args) {
|
|
625
|
-
if (
|
|
626
|
-
this.consola.info(message, ...args);
|
|
994
|
+
if (this.config.enabled) this.consola.info(message, ...args);
|
|
627
995
|
}
|
|
628
|
-
/**
|
|
629
|
-
* Log warning
|
|
630
|
-
*/
|
|
631
996
|
warn(message, ...args) {
|
|
632
|
-
if (
|
|
633
|
-
this.consola.warn(message, ...args);
|
|
997
|
+
if (this.config.enabled) this.consola.warn(message, ...args);
|
|
634
998
|
}
|
|
635
|
-
/**
|
|
636
|
-
* Log error
|
|
637
|
-
*/
|
|
638
999
|
error(message, ...args) {
|
|
639
|
-
if (
|
|
640
|
-
this.consola.error(message, ...args);
|
|
1000
|
+
if (this.config.enabled) this.consola.error(message, ...args);
|
|
641
1001
|
}
|
|
642
|
-
/**
|
|
643
|
-
* Log debug
|
|
644
|
-
*/
|
|
645
1002
|
debug(message, ...args) {
|
|
646
|
-
if (
|
|
647
|
-
this.consola.debug(message, ...args);
|
|
1003
|
+
if (this.config.enabled) this.consola.debug(message, ...args);
|
|
648
1004
|
}
|
|
649
|
-
/**
|
|
650
|
-
* Log success
|
|
651
|
-
*/
|
|
652
1005
|
success(message, ...args) {
|
|
653
|
-
if (
|
|
654
|
-
this.consola.success(message, ...args);
|
|
1006
|
+
if (this.config.enabled) this.consola.success(message, ...args);
|
|
655
1007
|
}
|
|
656
|
-
/**
|
|
657
|
-
* Create a sub-logger with prefix
|
|
658
|
-
*/
|
|
659
1008
|
withTag(tag) {
|
|
660
1009
|
return this.consola.withTag(tag);
|
|
661
1010
|
}
|
|
@@ -664,532 +1013,14 @@ __name(_APILogger, "APILogger");
|
|
|
664
1013
|
var APILogger = _APILogger;
|
|
665
1014
|
var defaultLogger = new APILogger();
|
|
666
1015
|
|
|
667
|
-
//
|
|
668
|
-
var
|
|
669
|
-
|
|
670
|
-
// ../../node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js
|
|
671
|
-
var objectToString = Object.prototype.toString;
|
|
672
|
-
var isError = /* @__PURE__ */ __name((value) => objectToString.call(value) === "[object Error]", "isError");
|
|
673
|
-
var errorMessages = /* @__PURE__ */ new Set([
|
|
674
|
-
"network error",
|
|
675
|
-
// Chrome
|
|
676
|
-
"Failed to fetch",
|
|
677
|
-
// Chrome
|
|
678
|
-
"NetworkError when attempting to fetch resource.",
|
|
679
|
-
// Firefox
|
|
680
|
-
"The Internet connection appears to be offline.",
|
|
681
|
-
// Safari 16
|
|
682
|
-
"Network request failed",
|
|
683
|
-
// `cross-fetch`
|
|
684
|
-
"fetch failed",
|
|
685
|
-
// Undici (Node.js)
|
|
686
|
-
"terminated",
|
|
687
|
-
// Undici (Node.js)
|
|
688
|
-
" A network error occurred.",
|
|
689
|
-
// Bun (WebKit)
|
|
690
|
-
"Network connection lost"
|
|
691
|
-
// Cloudflare Workers (fetch)
|
|
692
|
-
]);
|
|
693
|
-
function isNetworkError(error) {
|
|
694
|
-
const isValid = error && isError(error) && error.name === "TypeError" && typeof error.message === "string";
|
|
695
|
-
if (!isValid) {
|
|
696
|
-
return false;
|
|
697
|
-
}
|
|
698
|
-
const { message, stack } = error;
|
|
699
|
-
if (message === "Load failed") {
|
|
700
|
-
return stack === void 0 || "__sentry_captured__" in error;
|
|
701
|
-
}
|
|
702
|
-
if (message.startsWith("error sending request for url")) {
|
|
703
|
-
return true;
|
|
704
|
-
}
|
|
705
|
-
return errorMessages.has(message);
|
|
706
|
-
}
|
|
707
|
-
__name(isNetworkError, "isNetworkError");
|
|
708
|
-
|
|
709
|
-
// ../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
710
|
-
var _AbortError = class _AbortError extends Error {
|
|
711
|
-
constructor(message) {
|
|
712
|
-
super();
|
|
713
|
-
if (message instanceof Error) {
|
|
714
|
-
this.originalError = message;
|
|
715
|
-
({ message } = message);
|
|
716
|
-
} else {
|
|
717
|
-
this.originalError = new Error(message);
|
|
718
|
-
this.originalError.stack = this.stack;
|
|
719
|
-
}
|
|
720
|
-
this.name = "AbortError";
|
|
721
|
-
this.message = message;
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
__name(_AbortError, "AbortError");
|
|
725
|
-
var AbortError = _AbortError;
|
|
726
|
-
var decorateErrorWithCounts = /* @__PURE__ */ __name((error, attemptNumber, options) => {
|
|
727
|
-
const retriesLeft = options.retries - (attemptNumber - 1);
|
|
728
|
-
error.attemptNumber = attemptNumber;
|
|
729
|
-
error.retriesLeft = retriesLeft;
|
|
730
|
-
return error;
|
|
731
|
-
}, "decorateErrorWithCounts");
|
|
732
|
-
async function pRetry(input, options) {
|
|
733
|
-
return new Promise((resolve, reject) => {
|
|
734
|
-
options = { ...options };
|
|
735
|
-
options.onFailedAttempt ?? (options.onFailedAttempt = () => {
|
|
736
|
-
});
|
|
737
|
-
options.shouldRetry ?? (options.shouldRetry = () => true);
|
|
738
|
-
options.retries ?? (options.retries = 10);
|
|
739
|
-
const operation = import_retry.default.operation(options);
|
|
740
|
-
const abortHandler = /* @__PURE__ */ __name(() => {
|
|
741
|
-
operation.stop();
|
|
742
|
-
reject(options.signal?.reason);
|
|
743
|
-
}, "abortHandler");
|
|
744
|
-
if (options.signal && !options.signal.aborted) {
|
|
745
|
-
options.signal.addEventListener("abort", abortHandler, { once: true });
|
|
746
|
-
}
|
|
747
|
-
const cleanUp = /* @__PURE__ */ __name(() => {
|
|
748
|
-
options.signal?.removeEventListener("abort", abortHandler);
|
|
749
|
-
operation.stop();
|
|
750
|
-
}, "cleanUp");
|
|
751
|
-
operation.attempt(async (attemptNumber) => {
|
|
752
|
-
try {
|
|
753
|
-
const result = await input(attemptNumber);
|
|
754
|
-
cleanUp();
|
|
755
|
-
resolve(result);
|
|
756
|
-
} catch (error) {
|
|
757
|
-
try {
|
|
758
|
-
if (!(error instanceof Error)) {
|
|
759
|
-
throw new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
|
|
760
|
-
}
|
|
761
|
-
if (error instanceof AbortError) {
|
|
762
|
-
throw error.originalError;
|
|
763
|
-
}
|
|
764
|
-
if (error instanceof TypeError && !isNetworkError(error)) {
|
|
765
|
-
throw error;
|
|
766
|
-
}
|
|
767
|
-
decorateErrorWithCounts(error, attemptNumber, options);
|
|
768
|
-
if (!await options.shouldRetry(error)) {
|
|
769
|
-
operation.stop();
|
|
770
|
-
reject(error);
|
|
771
|
-
}
|
|
772
|
-
await options.onFailedAttempt(error);
|
|
773
|
-
if (!operation.retry(error)) {
|
|
774
|
-
throw operation.mainError();
|
|
775
|
-
}
|
|
776
|
-
} catch (finalError) {
|
|
777
|
-
decorateErrorWithCounts(finalError, attemptNumber, options);
|
|
778
|
-
cleanUp();
|
|
779
|
-
reject(finalError);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
});
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
__name(pRetry, "pRetry");
|
|
786
|
-
|
|
787
|
-
// src/_api/generated/cfg_monitor/retry.ts
|
|
788
|
-
var DEFAULT_RETRY_CONFIG = {
|
|
789
|
-
retries: 3,
|
|
790
|
-
factor: 2,
|
|
791
|
-
minTimeout: 1e3,
|
|
792
|
-
maxTimeout: 6e4,
|
|
793
|
-
randomize: true,
|
|
794
|
-
onFailedAttempt: /* @__PURE__ */ __name(() => {
|
|
795
|
-
}, "onFailedAttempt")
|
|
796
|
-
};
|
|
797
|
-
function shouldRetry(error) {
|
|
798
|
-
if (error instanceof NetworkError) {
|
|
799
|
-
return true;
|
|
800
|
-
}
|
|
801
|
-
if (error instanceof APIError) {
|
|
802
|
-
const status = error.statusCode;
|
|
803
|
-
if (status >= 500 && status < 600) {
|
|
804
|
-
return true;
|
|
805
|
-
}
|
|
806
|
-
if (status === 429) {
|
|
807
|
-
return true;
|
|
808
|
-
}
|
|
809
|
-
return false;
|
|
810
|
-
}
|
|
811
|
-
return true;
|
|
812
|
-
}
|
|
813
|
-
__name(shouldRetry, "shouldRetry");
|
|
814
|
-
async function withRetry(fn, config) {
|
|
815
|
-
const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
|
|
816
|
-
return pRetry(
|
|
817
|
-
async () => {
|
|
818
|
-
try {
|
|
819
|
-
return await fn();
|
|
820
|
-
} catch (error) {
|
|
821
|
-
if (!shouldRetry(error)) {
|
|
822
|
-
throw new AbortError(error);
|
|
823
|
-
}
|
|
824
|
-
throw error;
|
|
825
|
-
}
|
|
826
|
-
},
|
|
827
|
-
{
|
|
828
|
-
retries: finalConfig.retries,
|
|
829
|
-
factor: finalConfig.factor,
|
|
830
|
-
minTimeout: finalConfig.minTimeout,
|
|
831
|
-
maxTimeout: finalConfig.maxTimeout,
|
|
832
|
-
randomize: finalConfig.randomize,
|
|
833
|
-
onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
|
|
834
|
-
const pRetryError = error;
|
|
835
|
-
finalConfig.onFailedAttempt({
|
|
836
|
-
error: pRetryError,
|
|
837
|
-
attemptNumber: pRetryError.attemptNumber,
|
|
838
|
-
retriesLeft: pRetryError.retriesLeft
|
|
839
|
-
});
|
|
840
|
-
} : void 0
|
|
841
|
-
}
|
|
842
|
-
);
|
|
843
|
-
}
|
|
844
|
-
__name(withRetry, "withRetry");
|
|
845
|
-
|
|
846
|
-
// src/_api/generated/cfg_monitor/client.ts
|
|
847
|
-
var _APIClient = class _APIClient {
|
|
848
|
-
constructor(baseUrl, options) {
|
|
849
|
-
__publicField(this, "baseUrl");
|
|
850
|
-
__publicField(this, "httpClient");
|
|
851
|
-
__publicField(this, "logger", null);
|
|
852
|
-
__publicField(this, "retryConfig", null);
|
|
853
|
-
__publicField(this, "tokenGetter", null);
|
|
854
|
-
// Sub-clients
|
|
855
|
-
__publicField(this, "monitor");
|
|
856
|
-
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
857
|
-
this.httpClient = options?.httpClient || new FetchAdapter();
|
|
858
|
-
this.tokenGetter = options?.tokenGetter || null;
|
|
859
|
-
if (options?.loggerConfig !== void 0) {
|
|
860
|
-
this.logger = new APILogger(options.loggerConfig);
|
|
861
|
-
}
|
|
862
|
-
if (options?.retryConfig !== void 0) {
|
|
863
|
-
this.retryConfig = options.retryConfig;
|
|
864
|
-
}
|
|
865
|
-
this.monitor = new Monitor(this);
|
|
866
|
-
}
|
|
867
|
-
/**
|
|
868
|
-
* Get CSRF token from cookies (for SessionAuthentication).
|
|
869
|
-
*
|
|
870
|
-
* Returns null if cookie doesn't exist (JWT-only auth).
|
|
871
|
-
*/
|
|
872
|
-
getCsrfToken() {
|
|
873
|
-
const name = "csrftoken";
|
|
874
|
-
const value = `; ${document.cookie}`;
|
|
875
|
-
const parts = value.split(`; ${name}=`);
|
|
876
|
-
if (parts.length === 2) {
|
|
877
|
-
return parts.pop()?.split(";").shift() || null;
|
|
878
|
-
}
|
|
879
|
-
return null;
|
|
880
|
-
}
|
|
881
|
-
/**
|
|
882
|
-
* Get the base URL for building streaming/download URLs.
|
|
883
|
-
*/
|
|
884
|
-
getBaseUrl() {
|
|
885
|
-
return this.baseUrl;
|
|
886
|
-
}
|
|
887
|
-
/**
|
|
888
|
-
* Get JWT token for URL authentication (used in streaming endpoints).
|
|
889
|
-
* Returns null if no token getter is configured or no token is available.
|
|
890
|
-
*/
|
|
891
|
-
getToken() {
|
|
892
|
-
return this.tokenGetter ? this.tokenGetter() : null;
|
|
893
|
-
}
|
|
894
|
-
/**
|
|
895
|
-
* Make HTTP request with Django CSRF and session handling.
|
|
896
|
-
* Automatically retries on network errors and 5xx server errors.
|
|
897
|
-
*/
|
|
898
|
-
async request(method, path, options) {
|
|
899
|
-
if (this.retryConfig) {
|
|
900
|
-
return withRetry(() => this._makeRequest(method, path, options), {
|
|
901
|
-
...this.retryConfig,
|
|
902
|
-
onFailedAttempt: /* @__PURE__ */ __name((info) => {
|
|
903
|
-
if (this.logger) {
|
|
904
|
-
this.logger.warn(
|
|
905
|
-
`Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} for ${method} ${path}: ${info.error.message}`
|
|
906
|
-
);
|
|
907
|
-
}
|
|
908
|
-
this.retryConfig?.onFailedAttempt?.(info);
|
|
909
|
-
}, "onFailedAttempt")
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
return this._makeRequest(method, path, options);
|
|
913
|
-
}
|
|
914
|
-
/**
|
|
915
|
-
* Internal request method (without retry wrapper).
|
|
916
|
-
* Used by request() method with optional retry logic.
|
|
917
|
-
*/
|
|
918
|
-
async _makeRequest(method, path, options) {
|
|
919
|
-
const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
|
|
920
|
-
const startTime = Date.now();
|
|
921
|
-
const headers = {
|
|
922
|
-
...options?.headers || {}
|
|
923
|
-
};
|
|
924
|
-
if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
|
|
925
|
-
headers["Content-Type"] = "application/json";
|
|
926
|
-
}
|
|
927
|
-
if (!headers["Authorization"]) {
|
|
928
|
-
const token = this.getToken();
|
|
929
|
-
if (token) {
|
|
930
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
if (this.logger) {
|
|
934
|
-
this.logger.logRequest({
|
|
935
|
-
method,
|
|
936
|
-
url,
|
|
937
|
-
headers,
|
|
938
|
-
body: options?.formData || options?.body,
|
|
939
|
-
timestamp: startTime
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
|
-
try {
|
|
943
|
-
const response = await this.httpClient.request({
|
|
944
|
-
method,
|
|
945
|
-
url,
|
|
946
|
-
headers,
|
|
947
|
-
params: options?.params,
|
|
948
|
-
body: options?.body,
|
|
949
|
-
formData: options?.formData,
|
|
950
|
-
binaryBody: options?.binaryBody,
|
|
951
|
-
responseType: options?.responseType
|
|
952
|
-
});
|
|
953
|
-
const duration = Date.now() - startTime;
|
|
954
|
-
if (response.status >= 400) {
|
|
955
|
-
const error = new APIError(
|
|
956
|
-
response.status,
|
|
957
|
-
response.statusText,
|
|
958
|
-
response.data,
|
|
959
|
-
url
|
|
960
|
-
);
|
|
961
|
-
if (this.logger) {
|
|
962
|
-
this.logger.logError(
|
|
963
|
-
{
|
|
964
|
-
method,
|
|
965
|
-
url,
|
|
966
|
-
headers,
|
|
967
|
-
body: options?.formData || options?.body,
|
|
968
|
-
timestamp: startTime
|
|
969
|
-
},
|
|
970
|
-
{
|
|
971
|
-
message: error.message,
|
|
972
|
-
statusCode: response.status,
|
|
973
|
-
duration,
|
|
974
|
-
timestamp: Date.now()
|
|
975
|
-
}
|
|
976
|
-
);
|
|
977
|
-
}
|
|
978
|
-
throw error;
|
|
979
|
-
}
|
|
980
|
-
if (this.logger) {
|
|
981
|
-
this.logger.logResponse(
|
|
982
|
-
{
|
|
983
|
-
method,
|
|
984
|
-
url,
|
|
985
|
-
headers,
|
|
986
|
-
body: options?.formData || options?.body,
|
|
987
|
-
timestamp: startTime
|
|
988
|
-
},
|
|
989
|
-
{
|
|
990
|
-
status: response.status,
|
|
991
|
-
statusText: response.statusText,
|
|
992
|
-
data: response.data,
|
|
993
|
-
duration,
|
|
994
|
-
timestamp: Date.now()
|
|
995
|
-
}
|
|
996
|
-
);
|
|
997
|
-
}
|
|
998
|
-
return response.data;
|
|
999
|
-
} catch (error) {
|
|
1000
|
-
const duration = Date.now() - startTime;
|
|
1001
|
-
if (error instanceof APIError) {
|
|
1002
|
-
throw error;
|
|
1003
|
-
}
|
|
1004
|
-
let possiblyCors = false;
|
|
1005
|
-
if (error instanceof TypeError && typeof window !== "undefined") {
|
|
1006
|
-
try {
|
|
1007
|
-
const isCrossOrigin = (() => {
|
|
1008
|
-
try {
|
|
1009
|
-
return new URL(url).origin !== window.location.origin;
|
|
1010
|
-
} catch {
|
|
1011
|
-
return false;
|
|
1012
|
-
}
|
|
1013
|
-
})();
|
|
1014
|
-
if (isCrossOrigin) {
|
|
1015
|
-
const entries = performance.getEntriesByName(url, "resource");
|
|
1016
|
-
if (entries.length > 0) {
|
|
1017
|
-
const last = entries[entries.length - 1];
|
|
1018
|
-
possiblyCors = "responseStatus" in last && last.responseStatus === 0;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
} catch {
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
if (this.logger) {
|
|
1025
|
-
this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
|
|
1026
|
-
this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
|
|
1027
|
-
if (possiblyCors) {
|
|
1028
|
-
this.logger.error(` \u2192 Possibly blocked by CORS policy (configure CORS on the server)`);
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
if (typeof window !== "undefined") {
|
|
1032
|
-
try {
|
|
1033
|
-
window.dispatchEvent(new CustomEvent("network-error", {
|
|
1034
|
-
detail: {
|
|
1035
|
-
url,
|
|
1036
|
-
method,
|
|
1037
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1038
|
-
possibly_cors: possiblyCors,
|
|
1039
|
-
timestamp: /* @__PURE__ */ new Date()
|
|
1040
|
-
},
|
|
1041
|
-
bubbles: true,
|
|
1042
|
-
cancelable: false
|
|
1043
|
-
}));
|
|
1044
|
-
} catch {
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
|
|
1048
|
-
if (this.logger) {
|
|
1049
|
-
this.logger.logError(
|
|
1050
|
-
{
|
|
1051
|
-
method,
|
|
1052
|
-
url,
|
|
1053
|
-
headers,
|
|
1054
|
-
body: options?.formData || options?.body,
|
|
1055
|
-
timestamp: startTime
|
|
1056
|
-
},
|
|
1057
|
-
{
|
|
1058
|
-
message: networkError.message,
|
|
1059
|
-
duration,
|
|
1060
|
-
timestamp: Date.now()
|
|
1061
|
-
}
|
|
1062
|
-
);
|
|
1063
|
-
}
|
|
1064
|
-
throw networkError;
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
};
|
|
1068
|
-
__name(_APIClient, "APIClient");
|
|
1069
|
-
var APIClient = _APIClient;
|
|
1070
|
-
|
|
1071
|
-
// src/_api/generated/cfg_monitor/storage.ts
|
|
1072
|
-
var _LocalStorageAdapter = class _LocalStorageAdapter {
|
|
1073
|
-
constructor(logger) {
|
|
1074
|
-
__publicField(this, "logger");
|
|
1075
|
-
this.logger = logger;
|
|
1076
|
-
}
|
|
1077
|
-
getItem(key) {
|
|
1078
|
-
try {
|
|
1079
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
1080
|
-
const value = localStorage.getItem(key);
|
|
1081
|
-
this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
|
|
1082
|
-
return value;
|
|
1083
|
-
}
|
|
1084
|
-
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
1085
|
-
} catch (error) {
|
|
1086
|
-
this.logger?.error("LocalStorage.getItem failed:", error);
|
|
1087
|
-
}
|
|
1088
|
-
return null;
|
|
1089
|
-
}
|
|
1090
|
-
setItem(key, value) {
|
|
1091
|
-
try {
|
|
1092
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
1093
|
-
localStorage.setItem(key, value);
|
|
1094
|
-
this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
|
|
1095
|
-
} else {
|
|
1096
|
-
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
1097
|
-
}
|
|
1098
|
-
} catch (error) {
|
|
1099
|
-
this.logger?.error("LocalStorage.setItem failed:", error);
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
removeItem(key) {
|
|
1103
|
-
try {
|
|
1104
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
1105
|
-
localStorage.removeItem(key);
|
|
1106
|
-
this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
|
|
1107
|
-
} else {
|
|
1108
|
-
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
1109
|
-
}
|
|
1110
|
-
} catch (error) {
|
|
1111
|
-
this.logger?.error("LocalStorage.removeItem failed:", error);
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
};
|
|
1115
|
-
__name(_LocalStorageAdapter, "LocalStorageAdapter");
|
|
1116
|
-
var LocalStorageAdapter = _LocalStorageAdapter;
|
|
1117
|
-
var _MemoryStorageAdapter = class _MemoryStorageAdapter {
|
|
1118
|
-
constructor(logger) {
|
|
1119
|
-
__publicField(this, "storage", /* @__PURE__ */ new Map());
|
|
1120
|
-
__publicField(this, "logger");
|
|
1121
|
-
this.logger = logger;
|
|
1122
|
-
}
|
|
1123
|
-
getItem(key) {
|
|
1124
|
-
const value = this.storage.get(key) || null;
|
|
1125
|
-
this.logger?.debug(`MemoryStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
|
|
1126
|
-
return value;
|
|
1127
|
-
}
|
|
1128
|
-
setItem(key, value) {
|
|
1129
|
-
this.storage.set(key, value);
|
|
1130
|
-
this.logger?.debug(`MemoryStorage.setItem("${key}"): success`);
|
|
1131
|
-
}
|
|
1132
|
-
removeItem(key) {
|
|
1133
|
-
this.storage.delete(key);
|
|
1134
|
-
this.logger?.debug(`MemoryStorage.removeItem("${key}"): success`);
|
|
1135
|
-
}
|
|
1136
|
-
};
|
|
1137
|
-
__name(_MemoryStorageAdapter, "MemoryStorageAdapter");
|
|
1138
|
-
var MemoryStorageAdapter = _MemoryStorageAdapter;
|
|
1139
|
-
|
|
1140
|
-
// src/_api/generated/cfg_monitor/enums.ts
|
|
1141
|
-
var FrontendEventIngestRequestEventType = /* @__PURE__ */ ((FrontendEventIngestRequestEventType2) => {
|
|
1142
|
-
FrontendEventIngestRequestEventType2["JS_ERROR"] = "JS_ERROR";
|
|
1143
|
-
FrontendEventIngestRequestEventType2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
1144
|
-
FrontendEventIngestRequestEventType2["ERROR"] = "ERROR";
|
|
1145
|
-
FrontendEventIngestRequestEventType2["WARNING"] = "WARNING";
|
|
1146
|
-
FrontendEventIngestRequestEventType2["PAGE_VIEW"] = "PAGE_VIEW";
|
|
1147
|
-
FrontendEventIngestRequestEventType2["PERFORMANCE"] = "PERFORMANCE";
|
|
1148
|
-
FrontendEventIngestRequestEventType2["CONSOLE"] = "CONSOLE";
|
|
1149
|
-
return FrontendEventIngestRequestEventType2;
|
|
1150
|
-
})(FrontendEventIngestRequestEventType || {});
|
|
1151
|
-
var FrontendEventIngestRequestLevel = /* @__PURE__ */ ((FrontendEventIngestRequestLevel2) => {
|
|
1152
|
-
FrontendEventIngestRequestLevel2["ERROR"] = "error";
|
|
1153
|
-
FrontendEventIngestRequestLevel2["WARNING"] = "warning";
|
|
1154
|
-
FrontendEventIngestRequestLevel2["INFO"] = "info";
|
|
1155
|
-
FrontendEventIngestRequestLevel2["DEBUG"] = "debug";
|
|
1156
|
-
return FrontendEventIngestRequestLevel2;
|
|
1157
|
-
})(FrontendEventIngestRequestLevel || {});
|
|
1158
|
-
|
|
1159
|
-
// src/_api/generated/cfg_monitor/_utils/schemas/FrontendEventIngestRequest.schema.ts
|
|
1160
|
-
import { z } from "zod";
|
|
1161
|
-
var FrontendEventIngestRequestSchema = z.object({
|
|
1162
|
-
event_type: z.nativeEnum(FrontendEventIngestRequestEventType),
|
|
1163
|
-
message: z.string().min(1).max(5e3),
|
|
1164
|
-
level: z.nativeEnum(FrontendEventIngestRequestLevel).optional(),
|
|
1165
|
-
stack_trace: z.string().max(1e4).optional(),
|
|
1166
|
-
url: z.string().max(2e3).optional(),
|
|
1167
|
-
fingerprint: z.string().max(64).optional(),
|
|
1168
|
-
http_status: z.number().int().nullable().optional(),
|
|
1169
|
-
http_method: z.string().max(10).optional(),
|
|
1170
|
-
http_url: z.string().max(2e3).optional(),
|
|
1171
|
-
session_id: z.string().max(64).optional(),
|
|
1172
|
-
user_agent: z.string().max(500).optional(),
|
|
1173
|
-
build_id: z.string().max(100).optional(),
|
|
1174
|
-
environment: z.string().max(20).optional(),
|
|
1175
|
-
extra: z.record(z.string(), z.any()).optional(),
|
|
1176
|
-
project_name: z.string().max(100).optional()
|
|
1177
|
-
});
|
|
1178
|
-
|
|
1179
|
-
// src/_api/generated/cfg_monitor/_utils/schemas/IngestBatchRequest.schema.ts
|
|
1180
|
-
import { z as z2 } from "zod";
|
|
1181
|
-
var IngestBatchRequestSchema = z2.object({
|
|
1182
|
-
events: z2.array(FrontendEventIngestRequestSchema)
|
|
1183
|
-
});
|
|
1184
|
-
|
|
1185
|
-
// src/_api/generated/cfg_monitor/index.ts
|
|
1186
|
-
var TOKEN_KEY = "auth_token";
|
|
1187
|
-
var REFRESH_TOKEN_KEY = "refresh_token";
|
|
1016
|
+
// src/_api/generated/_cfg_monitor/api.ts
|
|
1017
|
+
var ACCESS_KEY = "cfg.access_token";
|
|
1018
|
+
var REFRESH_KEY = "cfg.refresh_token";
|
|
1188
1019
|
function detectLocale() {
|
|
1189
1020
|
try {
|
|
1190
1021
|
if (typeof document !== "undefined") {
|
|
1191
|
-
const
|
|
1192
|
-
if (
|
|
1022
|
+
const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
1023
|
+
if (m) return decodeURIComponent(m[1]);
|
|
1193
1024
|
}
|
|
1194
1025
|
if (typeof navigator !== "undefined" && navigator.language) {
|
|
1195
1026
|
return navigator.language;
|
|
@@ -1200,144 +1031,70 @@ function detectLocale() {
|
|
|
1200
1031
|
}
|
|
1201
1032
|
__name(detectLocale, "detectLocale");
|
|
1202
1033
|
var _API = class _API {
|
|
1203
|
-
constructor(baseUrl,
|
|
1034
|
+
constructor(baseUrl, opts = {}) {
|
|
1204
1035
|
__publicField(this, "baseUrl");
|
|
1205
|
-
__publicField(this, "_client");
|
|
1206
|
-
__publicField(this, "_token", null);
|
|
1207
|
-
__publicField(this, "_refreshToken", null);
|
|
1208
|
-
__publicField(this, "_locale", null);
|
|
1209
1036
|
__publicField(this, "storage");
|
|
1210
|
-
__publicField(this, "
|
|
1211
|
-
|
|
1212
|
-
__publicField(this, "
|
|
1213
|
-
this.baseUrl = baseUrl;
|
|
1214
|
-
this.
|
|
1215
|
-
|
|
1216
|
-
this.
|
|
1217
|
-
this.
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
}
|
|
1228
|
-
_loadTokensFromStorage() {
|
|
1229
|
-
this._token = this.storage.getItem(TOKEN_KEY);
|
|
1230
|
-
this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
|
|
1231
|
-
}
|
|
1232
|
-
_reinitClients() {
|
|
1233
|
-
this._client = new APIClient(this.baseUrl, {
|
|
1234
|
-
httpClient: this.options?.httpClient,
|
|
1235
|
-
retryConfig: this.options?.retryConfig,
|
|
1236
|
-
loggerConfig: this.options?.loggerConfig,
|
|
1237
|
-
tokenGetter: /* @__PURE__ */ __name(() => this.getToken(), "tokenGetter")
|
|
1037
|
+
__publicField(this, "locale");
|
|
1038
|
+
__publicField(this, "apiKey");
|
|
1039
|
+
__publicField(this, "logger");
|
|
1040
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
1041
|
+
this.storage = opts.storage ?? new LocalStorageAdapter();
|
|
1042
|
+
this.logger = new APILogger(opts.logger);
|
|
1043
|
+
this.locale = opts.locale ?? null;
|
|
1044
|
+
this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
|
|
1045
|
+
const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
|
|
1046
|
+
client.setConfig({ baseUrl: this.baseUrl, credentials });
|
|
1047
|
+
client.interceptors.request.use((request) => {
|
|
1048
|
+
const access = this.getToken();
|
|
1049
|
+
if (access) request.headers.set("Authorization", `Bearer ${access}`);
|
|
1050
|
+
const locale = this.locale ?? detectLocale();
|
|
1051
|
+
if (locale) request.headers.set("Accept-Language", locale);
|
|
1052
|
+
if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
|
|
1053
|
+
return request;
|
|
1238
1054
|
});
|
|
1239
|
-
this._injectAuthHeader();
|
|
1240
|
-
this.monitor = this._client.monitor;
|
|
1241
|
-
}
|
|
1242
|
-
_injectAuthHeader() {
|
|
1243
|
-
const originalRequest = this._client.request.bind(this._client);
|
|
1244
|
-
this._client.request = async (method, path, options) => {
|
|
1245
|
-
const token = this.getToken();
|
|
1246
|
-
const locale = this._locale || detectLocale();
|
|
1247
|
-
const mergedOptions = {
|
|
1248
|
-
...options,
|
|
1249
|
-
headers: {
|
|
1250
|
-
...options?.headers || {},
|
|
1251
|
-
...token ? { "Authorization": `Bearer ${token}` } : {},
|
|
1252
|
-
...locale ? { "Accept-Language": locale } : {}
|
|
1253
|
-
}
|
|
1254
|
-
};
|
|
1255
|
-
return originalRequest(method, path, mergedOptions);
|
|
1256
|
-
};
|
|
1257
1055
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1056
|
+
// ── Base URL ────────────────────────────────────────────────────────────
|
|
1057
|
+
getBaseUrl() {
|
|
1058
|
+
return this.baseUrl;
|
|
1059
|
+
}
|
|
1060
|
+
setBaseUrl(url) {
|
|
1061
|
+
this.baseUrl = url.replace(/\/$/, "");
|
|
1062
|
+
client.setConfig({ baseUrl: this.baseUrl });
|
|
1063
|
+
}
|
|
1064
|
+
// ── Tokens ──────────────────────────────────────────────────────────────
|
|
1261
1065
|
getToken() {
|
|
1262
|
-
return this.storage.getItem(
|
|
1066
|
+
return this.storage.getItem(ACCESS_KEY);
|
|
1067
|
+
}
|
|
1068
|
+
setToken(token) {
|
|
1069
|
+
if (token) this.storage.setItem(ACCESS_KEY, token);
|
|
1070
|
+
else this.storage.removeItem(ACCESS_KEY);
|
|
1263
1071
|
}
|
|
1264
|
-
/**
|
|
1265
|
-
* Get current refresh token
|
|
1266
|
-
*/
|
|
1267
1072
|
getRefreshToken() {
|
|
1268
|
-
return this.storage.getItem(
|
|
1073
|
+
return this.storage.getItem(REFRESH_KEY);
|
|
1269
1074
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
* @param refreshToken - JWT refresh token (optional)
|
|
1274
|
-
*/
|
|
1275
|
-
setToken(token, refreshToken) {
|
|
1276
|
-
this._token = token;
|
|
1277
|
-
this.storage.setItem(TOKEN_KEY, token);
|
|
1278
|
-
if (refreshToken) {
|
|
1279
|
-
this._refreshToken = refreshToken;
|
|
1280
|
-
this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
|
|
1281
|
-
}
|
|
1282
|
-
this._reinitClients();
|
|
1075
|
+
setRefreshToken(token) {
|
|
1076
|
+
if (token) this.storage.setItem(REFRESH_KEY, token);
|
|
1077
|
+
else this.storage.removeItem(REFRESH_KEY);
|
|
1283
1078
|
}
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
clearTokens() {
|
|
1288
|
-
this._token = null;
|
|
1289
|
-
this._refreshToken = null;
|
|
1290
|
-
this.storage.removeItem(TOKEN_KEY);
|
|
1291
|
-
this.storage.removeItem(REFRESH_TOKEN_KEY);
|
|
1292
|
-
this._reinitClients();
|
|
1079
|
+
clearToken() {
|
|
1080
|
+
this.storage.removeItem(ACCESS_KEY);
|
|
1081
|
+
this.storage.removeItem(REFRESH_KEY);
|
|
1293
1082
|
}
|
|
1294
|
-
/**
|
|
1295
|
-
* Check if user is authenticated
|
|
1296
|
-
*/
|
|
1297
1083
|
isAuthenticated() {
|
|
1298
|
-
return
|
|
1084
|
+
return this.getToken() !== null;
|
|
1299
1085
|
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
*/
|
|
1304
|
-
setBaseUrl(url) {
|
|
1305
|
-
this.baseUrl = url;
|
|
1306
|
-
this._reinitClients();
|
|
1307
|
-
}
|
|
1308
|
-
/**
|
|
1309
|
-
* Get current base URL
|
|
1310
|
-
*/
|
|
1311
|
-
getBaseUrl() {
|
|
1312
|
-
return this.baseUrl;
|
|
1086
|
+
// ── Locale / API key ────────────────────────────────────────────────────
|
|
1087
|
+
getLocale() {
|
|
1088
|
+
return this.locale ?? detectLocale();
|
|
1313
1089
|
}
|
|
1314
|
-
/**
|
|
1315
|
-
* Set locale for Accept-Language header
|
|
1316
|
-
* @param locale - Locale string (e.g. 'en', 'ko', 'ru') or null to clear
|
|
1317
|
-
*/
|
|
1318
1090
|
setLocale(locale) {
|
|
1319
|
-
this.
|
|
1091
|
+
this.locale = locale;
|
|
1320
1092
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
*/
|
|
1324
|
-
getLocale() {
|
|
1325
|
-
return this._locale;
|
|
1093
|
+
getApiKey() {
|
|
1094
|
+
return this.apiKey;
|
|
1326
1095
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
* @returns Path to the OpenAPI schema JSON file
|
|
1330
|
-
*
|
|
1331
|
-
* Note: The OpenAPI schema is available in the schema.json file.
|
|
1332
|
-
* You can load it dynamically using:
|
|
1333
|
-
* ```typescript
|
|
1334
|
-
* const schema = await fetch('./schema.json').then(r => r.json());
|
|
1335
|
-
* // or using fs in Node.js:
|
|
1336
|
-
* // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
|
|
1337
|
-
* ```
|
|
1338
|
-
*/
|
|
1339
|
-
getSchemaPath() {
|
|
1340
|
-
return "./schema.json";
|
|
1096
|
+
setApiKey(key) {
|
|
1097
|
+
this.apiKey = key;
|
|
1341
1098
|
}
|
|
1342
1099
|
};
|
|
1343
1100
|
__name(_API, "API");
|
|
@@ -1350,30 +1107,71 @@ function configureMonitorApi(baseUrl) {
|
|
|
1350
1107
|
}
|
|
1351
1108
|
__name(configureMonitorApi, "configureMonitorApi");
|
|
1352
1109
|
|
|
1110
|
+
// src/_api/generated/types.gen.ts
|
|
1111
|
+
var EventTypeEnum = /* @__PURE__ */ ((EventTypeEnum2) => {
|
|
1112
|
+
EventTypeEnum2["JS_ERROR"] = "JS_ERROR";
|
|
1113
|
+
EventTypeEnum2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
1114
|
+
EventTypeEnum2["ERROR"] = "ERROR";
|
|
1115
|
+
EventTypeEnum2["WARNING"] = "WARNING";
|
|
1116
|
+
EventTypeEnum2["PAGE_VIEW"] = "PAGE_VIEW";
|
|
1117
|
+
EventTypeEnum2["PERFORMANCE"] = "PERFORMANCE";
|
|
1118
|
+
EventTypeEnum2["CONSOLE"] = "CONSOLE";
|
|
1119
|
+
return EventTypeEnum2;
|
|
1120
|
+
})(EventTypeEnum || {});
|
|
1121
|
+
var LevelEnum = /* @__PURE__ */ ((LevelEnum2) => {
|
|
1122
|
+
LevelEnum2["ERROR"] = "error";
|
|
1123
|
+
LevelEnum2["WARNING"] = "warning";
|
|
1124
|
+
LevelEnum2["INFO"] = "info";
|
|
1125
|
+
LevelEnum2["DEBUG"] = "debug";
|
|
1126
|
+
return LevelEnum2;
|
|
1127
|
+
})(LevelEnum || {});
|
|
1128
|
+
|
|
1129
|
+
// src/_api/index.ts
|
|
1130
|
+
var INGEST_PATH = "/cfg/monitor/ingest/";
|
|
1131
|
+
|
|
1132
|
+
// src/_api/generated/sdk.gen.ts
|
|
1133
|
+
var _Monitor = class _Monitor {
|
|
1134
|
+
/**
|
|
1135
|
+
* Ingest browser events
|
|
1136
|
+
*
|
|
1137
|
+
* Accepts a batch of up to 50 frontend events. No authentication required — anonymous visitors can send events.
|
|
1138
|
+
*/
|
|
1139
|
+
static cfgMonitorIngestCreate(options) {
|
|
1140
|
+
return (options.client ?? client).post({
|
|
1141
|
+
url: "/cfg/monitor/ingest/",
|
|
1142
|
+
...options,
|
|
1143
|
+
headers: {
|
|
1144
|
+
"Content-Type": "application/json",
|
|
1145
|
+
...options.headers
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
__name(_Monitor, "Monitor");
|
|
1151
|
+
var Monitor = _Monitor;
|
|
1152
|
+
|
|
1353
1153
|
// src/client/transport/ingest.ts
|
|
1354
|
-
var monitorApiBeacon = new API("", {
|
|
1355
|
-
storage: new MemoryStorageAdapter(),
|
|
1356
|
-
httpClient: new KeepAliveFetchAdapter()
|
|
1357
|
-
});
|
|
1358
|
-
function syncBeaconBaseUrl() {
|
|
1359
|
-
monitorApiBeacon.setBaseUrl(monitorApi.getBaseUrl());
|
|
1360
|
-
}
|
|
1361
|
-
__name(syncBeaconBaseUrl, "syncBeaconBaseUrl");
|
|
1362
1154
|
async function sendBatch(batch, useBeacon = false) {
|
|
1363
1155
|
if (batch.events.length === 0) return;
|
|
1364
|
-
if (useBeacon) {
|
|
1365
|
-
|
|
1366
|
-
await
|
|
1367
|
-
|
|
1368
|
-
|
|
1156
|
+
if (useBeacon && typeof fetch !== "undefined") {
|
|
1157
|
+
const baseUrl = monitorApi.getBaseUrl();
|
|
1158
|
+
await fetch(`${baseUrl}${INGEST_PATH}`, {
|
|
1159
|
+
method: "POST",
|
|
1160
|
+
headers: { "Content-Type": "application/json" },
|
|
1161
|
+
body: JSON.stringify(batch),
|
|
1162
|
+
keepalive: true,
|
|
1163
|
+
credentials: "include"
|
|
1164
|
+
});
|
|
1165
|
+
return;
|
|
1369
1166
|
}
|
|
1167
|
+
await Monitor.cfgMonitorIngestCreate({ body: batch, throwOnError: true });
|
|
1370
1168
|
}
|
|
1371
1169
|
__name(sendBatch, "sendBatch");
|
|
1372
1170
|
|
|
1373
1171
|
// src/client/utils/env.ts
|
|
1374
1172
|
var isDevelopment = process.env.NODE_ENV === "development";
|
|
1375
1173
|
var isProduction = !isDevelopment;
|
|
1376
|
-
var MONITOR_VERSION = "2.1.
|
|
1174
|
+
var MONITOR_VERSION = "2.1.331";
|
|
1377
1175
|
|
|
1378
1176
|
// src/client/constants.ts
|
|
1379
1177
|
var MONITOR_INGEST_PATTERN = /cfg\/monitor\/ingest/;
|
|
@@ -1946,8 +1744,8 @@ var FrontendMonitor = {
|
|
|
1946
1744
|
}
|
|
1947
1745
|
};
|
|
1948
1746
|
export {
|
|
1949
|
-
|
|
1950
|
-
|
|
1747
|
+
LevelEnum as EventLevel,
|
|
1748
|
+
EventTypeEnum as EventType,
|
|
1951
1749
|
FrontendMonitor,
|
|
1952
1750
|
MONITOR_VERSION,
|
|
1953
1751
|
MonitorProvider,
|