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