@cloudflare/vite-plugin 1.28.0 → 1.29.0
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/index.mjs
CHANGED
|
@@ -21610,8 +21610,13 @@ function createHotChannel(webSocketContainer) {
|
|
|
21610
21610
|
return {
|
|
21611
21611
|
send(payload) {
|
|
21612
21612
|
const webSocket = webSocketContainer.webSocket;
|
|
21613
|
-
|
|
21614
|
-
webSocket
|
|
21613
|
+
const message = JSON.stringify(payload);
|
|
21614
|
+
if (!webSocket) {
|
|
21615
|
+
webSocketContainer.messageBuffers ??= [];
|
|
21616
|
+
webSocketContainer.messageBuffers.push(message);
|
|
21617
|
+
return;
|
|
21618
|
+
}
|
|
21619
|
+
webSocket.send(message);
|
|
21615
21620
|
},
|
|
21616
21621
|
on(event, listener) {
|
|
21617
21622
|
const listeners = listenersMap.get(event) ?? /* @__PURE__ */ new Set();
|
|
@@ -21657,6 +21662,10 @@ var CloudflareDevEnvironment = class extends vite.DevEnvironment {
|
|
|
21657
21662
|
assert(webSocket, "Failed to establish WebSocket");
|
|
21658
21663
|
webSocket.accept();
|
|
21659
21664
|
this.#webSocketContainer.webSocket = webSocket;
|
|
21665
|
+
if (this.#webSocketContainer.messageBuffers) {
|
|
21666
|
+
for (const bufferedMessage of this.#webSocketContainer.messageBuffers) webSocket.send(bufferedMessage);
|
|
21667
|
+
delete this.#webSocketContainer.messageBuffers;
|
|
21668
|
+
}
|
|
21660
21669
|
}
|
|
21661
21670
|
async fetchWorkerExportTypes(miniflare, workerConfig) {
|
|
21662
21671
|
await this.depsOptimizer?.init();
|
|
@@ -22287,6 +22296,229 @@ const OpenAPI = {
|
|
|
22287
22296
|
LOGGER: void 0
|
|
22288
22297
|
};
|
|
22289
22298
|
|
|
22299
|
+
//#endregion
|
|
22300
|
+
//#region ../containers-shared/src/client/core/request.ts
|
|
22301
|
+
/* istanbul ignore file */
|
|
22302
|
+
const isDefined = (value) => {
|
|
22303
|
+
return value !== void 0 && value !== null;
|
|
22304
|
+
};
|
|
22305
|
+
const isString = (value) => {
|
|
22306
|
+
return typeof value === "string";
|
|
22307
|
+
};
|
|
22308
|
+
const isStringWithValue = (value) => {
|
|
22309
|
+
return isString(value) && value !== "";
|
|
22310
|
+
};
|
|
22311
|
+
const isBlob = (value) => {
|
|
22312
|
+
return typeof value === "object" && typeof value.type === "string" && typeof value.stream === "function" && typeof value.arrayBuffer === "function" && typeof value.constructor === "function" && typeof value.constructor.name === "string" && /^(Blob|File)$/.test(value.constructor.name) && /^(Blob|File)$/.test(value[Symbol.toStringTag]);
|
|
22313
|
+
};
|
|
22314
|
+
const base64 = (str) => {
|
|
22315
|
+
try {
|
|
22316
|
+
return btoa(str);
|
|
22317
|
+
} catch (err) {
|
|
22318
|
+
return Buffer.from(str).toString("base64");
|
|
22319
|
+
}
|
|
22320
|
+
};
|
|
22321
|
+
const getQueryString = (params) => {
|
|
22322
|
+
const qs = [];
|
|
22323
|
+
const append = (key, value) => {
|
|
22324
|
+
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
22325
|
+
};
|
|
22326
|
+
const process$2 = (key, value) => {
|
|
22327
|
+
if (isDefined(value)) if (Array.isArray(value)) value.forEach((v) => {
|
|
22328
|
+
process$2(key, v);
|
|
22329
|
+
});
|
|
22330
|
+
else if (typeof value === "object") Object.entries(value).forEach(([k, v]) => {
|
|
22331
|
+
process$2(`${key}[${k}]`, v);
|
|
22332
|
+
});
|
|
22333
|
+
else append(key, value);
|
|
22334
|
+
};
|
|
22335
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
22336
|
+
process$2(key, value);
|
|
22337
|
+
});
|
|
22338
|
+
if (qs.length > 0) return `?${qs.join("&")}`;
|
|
22339
|
+
return "";
|
|
22340
|
+
};
|
|
22341
|
+
const getUrl = (config, options) => {
|
|
22342
|
+
const encoder = config.ENCODE_PATH || encodeURI;
|
|
22343
|
+
const path$1 = options.url.replace("{api-version}", config.VERSION).replace(/{(.*?)}/g, (substring, group) => {
|
|
22344
|
+
if (options.path?.hasOwnProperty(group)) return encoder(String(options.path[group]));
|
|
22345
|
+
return substring;
|
|
22346
|
+
});
|
|
22347
|
+
const url = `${config.BASE}${path$1}`;
|
|
22348
|
+
if (options.query) return `${url}${getQueryString(options.query)}`;
|
|
22349
|
+
return url;
|
|
22350
|
+
};
|
|
22351
|
+
const getFormData = (options) => {
|
|
22352
|
+
if (options.formData) {
|
|
22353
|
+
const formData = new FormData();
|
|
22354
|
+
const process$2 = async (key, value) => {
|
|
22355
|
+
if (isString(value)) formData.append(key, value);
|
|
22356
|
+
else formData.append(key, JSON.stringify(value));
|
|
22357
|
+
};
|
|
22358
|
+
Object.entries(options.formData).filter(([_, value]) => isDefined(value)).forEach(([key, value]) => {
|
|
22359
|
+
if (Array.isArray(value)) value.forEach((v) => process$2(key, v));
|
|
22360
|
+
else process$2(key, value);
|
|
22361
|
+
});
|
|
22362
|
+
return formData;
|
|
22363
|
+
}
|
|
22364
|
+
};
|
|
22365
|
+
const resolve$1 = async (options, resolver) => {
|
|
22366
|
+
if (typeof resolver === "function") return resolver(options);
|
|
22367
|
+
return resolver;
|
|
22368
|
+
};
|
|
22369
|
+
const getHeaders = async (config, options) => {
|
|
22370
|
+
const token = await resolve$1(options, config.TOKEN);
|
|
22371
|
+
const username = await resolve$1(options, config.USERNAME);
|
|
22372
|
+
const password = await resolve$1(options, config.PASSWORD);
|
|
22373
|
+
const additionalHeaders = await resolve$1(options, config.HEADERS);
|
|
22374
|
+
const headers = Object.entries({
|
|
22375
|
+
Accept: "application/json",
|
|
22376
|
+
...additionalHeaders,
|
|
22377
|
+
...options.headers
|
|
22378
|
+
}).filter(([_, value]) => isDefined(value)).reduce((headers$1, [key, value]) => ({
|
|
22379
|
+
...headers$1,
|
|
22380
|
+
[key]: String(value)
|
|
22381
|
+
}), {});
|
|
22382
|
+
if (isStringWithValue(token)) headers["Authorization"] = `Bearer ${token}`;
|
|
22383
|
+
if (isStringWithValue(username) && isStringWithValue(password)) headers["Authorization"] = `Basic ${base64(`${username}:${password}`)}`;
|
|
22384
|
+
if (options.body) if (options.mediaType) headers["Content-Type"] = options.mediaType;
|
|
22385
|
+
else if (isBlob(options.body)) headers["Content-Type"] = options.body.type || "application/octet-stream";
|
|
22386
|
+
else if (isString(options.body)) headers["Content-Type"] = "text/plain";
|
|
22387
|
+
else headers["Content-Type"] = "application/json";
|
|
22388
|
+
return new Headers(headers);
|
|
22389
|
+
};
|
|
22390
|
+
const getRequestBody = (options) => {
|
|
22391
|
+
if (options.body !== void 0) if (options.mediaType?.includes("/json")) return JSON.stringify(options.body);
|
|
22392
|
+
else if (isString(options.body) || isBlob(options.body)) return options.body;
|
|
22393
|
+
else return JSON.stringify(options.body);
|
|
22394
|
+
};
|
|
22395
|
+
const isResponseSchemaV4 = (config, _options) => {
|
|
22396
|
+
return config.BASE.endsWith("/containers");
|
|
22397
|
+
};
|
|
22398
|
+
const parseResponseSchemaV4 = (url, response, responseHeader, responseBody) => {
|
|
22399
|
+
const fetchResult = typeof responseBody === "object" ? responseBody : JSON.parse(responseBody);
|
|
22400
|
+
const ok = response.ok && fetchResult.success;
|
|
22401
|
+
let result;
|
|
22402
|
+
if (ok) if (fetchResult.result !== void 0) result = fetchResult.result;
|
|
22403
|
+
else result = {};
|
|
22404
|
+
else result = { error: fetchResult.errors?.[0]?.message };
|
|
22405
|
+
return {
|
|
22406
|
+
url,
|
|
22407
|
+
ok,
|
|
22408
|
+
status: response.status,
|
|
22409
|
+
statusText: response.statusText,
|
|
22410
|
+
body: responseHeader ?? result
|
|
22411
|
+
};
|
|
22412
|
+
};
|
|
22413
|
+
const sendRequest = async (config, options, url, body, formData, headers, onCancel) => {
|
|
22414
|
+
const controller = new AbortController();
|
|
22415
|
+
const request$1 = {
|
|
22416
|
+
headers,
|
|
22417
|
+
body: body ?? formData,
|
|
22418
|
+
method: options.method,
|
|
22419
|
+
signal: controller.signal
|
|
22420
|
+
};
|
|
22421
|
+
if (config.WITH_CREDENTIALS) request$1.credentials = config.CREDENTIALS;
|
|
22422
|
+
onCancel(() => controller.abort());
|
|
22423
|
+
return await fetch(url, request$1);
|
|
22424
|
+
};
|
|
22425
|
+
const getResponseHeader = (response, responseHeader) => {
|
|
22426
|
+
if (responseHeader) {
|
|
22427
|
+
const content = response.headers.get(responseHeader);
|
|
22428
|
+
if (isString(content)) return content;
|
|
22429
|
+
}
|
|
22430
|
+
};
|
|
22431
|
+
const getResponseBody = async (response) => {
|
|
22432
|
+
if (response.status !== 204) try {
|
|
22433
|
+
const contentType = response.headers.get("Content-Type");
|
|
22434
|
+
if (contentType) if (["application/json", "application/problem+json"].some((type) => contentType.toLowerCase().startsWith(type))) return await response.json();
|
|
22435
|
+
else return await response.text();
|
|
22436
|
+
} catch (error) {
|
|
22437
|
+
console.error(error);
|
|
22438
|
+
}
|
|
22439
|
+
};
|
|
22440
|
+
const catchErrorCodes = (options, result) => {
|
|
22441
|
+
const error = {
|
|
22442
|
+
400: "Bad Request",
|
|
22443
|
+
401: "Unauthorized",
|
|
22444
|
+
403: "Forbidden",
|
|
22445
|
+
404: "Not Found",
|
|
22446
|
+
500: "Internal Server Error",
|
|
22447
|
+
502: "Bad Gateway",
|
|
22448
|
+
503: "Service Unavailable",
|
|
22449
|
+
...options.errors
|
|
22450
|
+
}[result.status];
|
|
22451
|
+
if (error) throw new ApiError(options, result, error);
|
|
22452
|
+
if (!result.ok) throw new ApiError(options, result, "Generic Error");
|
|
22453
|
+
};
|
|
22454
|
+
/**
|
|
22455
|
+
* Shared HTTP execution: builds URL, headers, body, sends the request,
|
|
22456
|
+
* and returns the raw response components for further processing.
|
|
22457
|
+
* Returns null if the request was cancelled before sending.
|
|
22458
|
+
*/
|
|
22459
|
+
const executeRequest = async (config, options, onCancel) => {
|
|
22460
|
+
const url = getUrl(config, options);
|
|
22461
|
+
const formData = getFormData(options);
|
|
22462
|
+
const body = getRequestBody(options);
|
|
22463
|
+
const headers = await getHeaders(config, options);
|
|
22464
|
+
debugLogRequest(config, url, headers, formData ?? body ?? {});
|
|
22465
|
+
if (onCancel.isCancelled) return null;
|
|
22466
|
+
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
|
|
22467
|
+
return {
|
|
22468
|
+
url,
|
|
22469
|
+
response,
|
|
22470
|
+
responseBody: await getResponseBody(response),
|
|
22471
|
+
responseHeader: getResponseHeader(response, options.responseHeader)
|
|
22472
|
+
};
|
|
22473
|
+
};
|
|
22474
|
+
/**
|
|
22475
|
+
* Build an ApiResult from the raw response, handling V4 schema parsing.
|
|
22476
|
+
*/
|
|
22477
|
+
const buildApiResult = (config, options, req) => {
|
|
22478
|
+
if (isResponseSchemaV4(config, options)) return parseResponseSchemaV4(req.url, req.response, req.responseHeader, req.responseBody);
|
|
22479
|
+
return {
|
|
22480
|
+
url: req.url,
|
|
22481
|
+
ok: req.response.ok,
|
|
22482
|
+
status: req.response.status,
|
|
22483
|
+
statusText: req.response.statusText,
|
|
22484
|
+
body: req.responseHeader ?? req.responseBody
|
|
22485
|
+
};
|
|
22486
|
+
};
|
|
22487
|
+
/**
|
|
22488
|
+
* Request method
|
|
22489
|
+
* @param config The OpenAPI configuration object
|
|
22490
|
+
* @param options The request options from the service
|
|
22491
|
+
* @returns CancelablePromise<T>
|
|
22492
|
+
* @throws ApiError
|
|
22493
|
+
*/
|
|
22494
|
+
const request = (config, options) => {
|
|
22495
|
+
return new CancelablePromise(async (resolve$2, reject, onCancel) => {
|
|
22496
|
+
try {
|
|
22497
|
+
const req = await executeRequest(config, options, onCancel);
|
|
22498
|
+
if (!req) return;
|
|
22499
|
+
const result = buildApiResult(config, options, req);
|
|
22500
|
+
debugLogResponse(config, result);
|
|
22501
|
+
catchErrorCodes(options, result);
|
|
22502
|
+
resolve$2(result.body);
|
|
22503
|
+
} catch (error) {
|
|
22504
|
+
reject(error);
|
|
22505
|
+
}
|
|
22506
|
+
});
|
|
22507
|
+
};
|
|
22508
|
+
const debugLogRequest = async (config, url, headers, body) => {
|
|
22509
|
+
config.LOGGER?.debug(`-- START CF API REQUEST: ${url}`);
|
|
22510
|
+
const logHeaders = new Headers(headers);
|
|
22511
|
+
logHeaders.delete("Authorization");
|
|
22512
|
+
config.LOGGER?.debugWithSanitization("HEADERS:", JSON.stringify(logHeaders, null, 2));
|
|
22513
|
+
config.LOGGER?.debugWithSanitization("BODY:", JSON.stringify(body instanceof FormData ? await new Response(body).text() : body, null, 2));
|
|
22514
|
+
config.LOGGER?.debug("-- END CF API REQUEST");
|
|
22515
|
+
};
|
|
22516
|
+
const debugLogResponse = (config, response) => {
|
|
22517
|
+
config.LOGGER?.debug("-- START CF API RESPONSE:", response.statusText, response.status);
|
|
22518
|
+
config.LOGGER?.debugWithSanitization("RESPONSE:", response.body);
|
|
22519
|
+
config.LOGGER?.debug("-- END CF API RESPONSE");
|
|
22520
|
+
};
|
|
22521
|
+
|
|
22290
22522
|
//#endregion
|
|
22291
22523
|
//#region ../containers-shared/src/client/models/ApplicationRollout.ts
|
|
22292
22524
|
let ApplicationRollout;
|
|
@@ -22513,212 +22745,6 @@ let UpdateApplicationRolloutRequest;
|
|
|
22513
22745
|
}({});
|
|
22514
22746
|
})(UpdateApplicationRolloutRequest || (UpdateApplicationRolloutRequest = {}));
|
|
22515
22747
|
|
|
22516
|
-
//#endregion
|
|
22517
|
-
//#region ../containers-shared/src/client/core/request.ts
|
|
22518
|
-
/* istanbul ignore file */
|
|
22519
|
-
const isDefined = (value) => {
|
|
22520
|
-
return value !== void 0 && value !== null;
|
|
22521
|
-
};
|
|
22522
|
-
const isString = (value) => {
|
|
22523
|
-
return typeof value === "string";
|
|
22524
|
-
};
|
|
22525
|
-
const isStringWithValue = (value) => {
|
|
22526
|
-
return isString(value) && value !== "";
|
|
22527
|
-
};
|
|
22528
|
-
const isBlob = (value) => {
|
|
22529
|
-
return typeof value === "object" && typeof value.type === "string" && typeof value.stream === "function" && typeof value.arrayBuffer === "function" && typeof value.constructor === "function" && typeof value.constructor.name === "string" && /^(Blob|File)$/.test(value.constructor.name) && /^(Blob|File)$/.test(value[Symbol.toStringTag]);
|
|
22530
|
-
};
|
|
22531
|
-
const base64 = (str) => {
|
|
22532
|
-
try {
|
|
22533
|
-
return btoa(str);
|
|
22534
|
-
} catch (err) {
|
|
22535
|
-
return Buffer.from(str).toString("base64");
|
|
22536
|
-
}
|
|
22537
|
-
};
|
|
22538
|
-
const getQueryString = (params) => {
|
|
22539
|
-
const qs = [];
|
|
22540
|
-
const append = (key, value) => {
|
|
22541
|
-
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
22542
|
-
};
|
|
22543
|
-
const process$2 = (key, value) => {
|
|
22544
|
-
if (isDefined(value)) if (Array.isArray(value)) value.forEach((v) => {
|
|
22545
|
-
process$2(key, v);
|
|
22546
|
-
});
|
|
22547
|
-
else if (typeof value === "object") Object.entries(value).forEach(([k, v]) => {
|
|
22548
|
-
process$2(`${key}[${k}]`, v);
|
|
22549
|
-
});
|
|
22550
|
-
else append(key, value);
|
|
22551
|
-
};
|
|
22552
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
22553
|
-
process$2(key, value);
|
|
22554
|
-
});
|
|
22555
|
-
if (qs.length > 0) return `?${qs.join("&")}`;
|
|
22556
|
-
return "";
|
|
22557
|
-
};
|
|
22558
|
-
const getUrl = (config, options) => {
|
|
22559
|
-
const encoder = config.ENCODE_PATH || encodeURI;
|
|
22560
|
-
const path$1 = options.url.replace("{api-version}", config.VERSION).replace(/{(.*?)}/g, (substring, group) => {
|
|
22561
|
-
if (options.path?.hasOwnProperty(group)) return encoder(String(options.path[group]));
|
|
22562
|
-
return substring;
|
|
22563
|
-
});
|
|
22564
|
-
const url = `${config.BASE}${path$1}`;
|
|
22565
|
-
if (options.query) return `${url}${getQueryString(options.query)}`;
|
|
22566
|
-
return url;
|
|
22567
|
-
};
|
|
22568
|
-
const getFormData = (options) => {
|
|
22569
|
-
if (options.formData) {
|
|
22570
|
-
const formData = new FormData();
|
|
22571
|
-
const process$2 = async (key, value) => {
|
|
22572
|
-
if (isString(value)) formData.append(key, value);
|
|
22573
|
-
else formData.append(key, JSON.stringify(value));
|
|
22574
|
-
};
|
|
22575
|
-
Object.entries(options.formData).filter(([_, value]) => isDefined(value)).forEach(([key, value]) => {
|
|
22576
|
-
if (Array.isArray(value)) value.forEach((v) => process$2(key, v));
|
|
22577
|
-
else process$2(key, value);
|
|
22578
|
-
});
|
|
22579
|
-
return formData;
|
|
22580
|
-
}
|
|
22581
|
-
};
|
|
22582
|
-
const resolve$1 = async (options, resolver) => {
|
|
22583
|
-
if (typeof resolver === "function") return resolver(options);
|
|
22584
|
-
return resolver;
|
|
22585
|
-
};
|
|
22586
|
-
const getHeaders = async (config, options) => {
|
|
22587
|
-
const token = await resolve$1(options, config.TOKEN);
|
|
22588
|
-
const username = await resolve$1(options, config.USERNAME);
|
|
22589
|
-
const password = await resolve$1(options, config.PASSWORD);
|
|
22590
|
-
const additionalHeaders = await resolve$1(options, config.HEADERS);
|
|
22591
|
-
const headers = Object.entries({
|
|
22592
|
-
Accept: "application/json",
|
|
22593
|
-
...additionalHeaders,
|
|
22594
|
-
...options.headers
|
|
22595
|
-
}).filter(([_, value]) => isDefined(value)).reduce((headers$1, [key, value]) => ({
|
|
22596
|
-
...headers$1,
|
|
22597
|
-
[key]: String(value)
|
|
22598
|
-
}), {});
|
|
22599
|
-
if (isStringWithValue(token)) headers["Authorization"] = `Bearer ${token}`;
|
|
22600
|
-
if (isStringWithValue(username) && isStringWithValue(password)) headers["Authorization"] = `Basic ${base64(`${username}:${password}`)}`;
|
|
22601
|
-
if (options.body) if (options.mediaType) headers["Content-Type"] = options.mediaType;
|
|
22602
|
-
else if (isBlob(options.body)) headers["Content-Type"] = options.body.type || "application/octet-stream";
|
|
22603
|
-
else if (isString(options.body)) headers["Content-Type"] = "text/plain";
|
|
22604
|
-
else headers["Content-Type"] = "application/json";
|
|
22605
|
-
return new Headers(headers);
|
|
22606
|
-
};
|
|
22607
|
-
const getRequestBody = (options) => {
|
|
22608
|
-
if (options.body !== void 0) if (options.mediaType?.includes("/json")) return JSON.stringify(options.body);
|
|
22609
|
-
else if (isString(options.body) || isBlob(options.body)) return options.body;
|
|
22610
|
-
else return JSON.stringify(options.body);
|
|
22611
|
-
};
|
|
22612
|
-
const isResponseSchemaV4 = (config, _options) => {
|
|
22613
|
-
return config.BASE.endsWith("/containers");
|
|
22614
|
-
};
|
|
22615
|
-
const parseResponseSchemaV4 = (url, response, responseHeader, responseBody) => {
|
|
22616
|
-
const fetchResult = typeof responseBody === "object" ? responseBody : JSON.parse(responseBody);
|
|
22617
|
-
const ok = response.ok && fetchResult.success;
|
|
22618
|
-
let result;
|
|
22619
|
-
if (ok) if (fetchResult.result !== void 0) result = fetchResult.result;
|
|
22620
|
-
else result = {};
|
|
22621
|
-
else result = { error: fetchResult.errors?.[0]?.message };
|
|
22622
|
-
return {
|
|
22623
|
-
url,
|
|
22624
|
-
ok,
|
|
22625
|
-
status: response.status,
|
|
22626
|
-
statusText: response.statusText,
|
|
22627
|
-
body: responseHeader ?? result
|
|
22628
|
-
};
|
|
22629
|
-
};
|
|
22630
|
-
const sendRequest = async (config, options, url, body, formData, headers, onCancel) => {
|
|
22631
|
-
const controller = new AbortController();
|
|
22632
|
-
const request$1 = {
|
|
22633
|
-
headers,
|
|
22634
|
-
body: body ?? formData,
|
|
22635
|
-
method: options.method,
|
|
22636
|
-
signal: controller.signal
|
|
22637
|
-
};
|
|
22638
|
-
if (config.WITH_CREDENTIALS) request$1.credentials = config.CREDENTIALS;
|
|
22639
|
-
onCancel(() => controller.abort());
|
|
22640
|
-
return await fetch(url, request$1);
|
|
22641
|
-
};
|
|
22642
|
-
const getResponseHeader = (response, responseHeader) => {
|
|
22643
|
-
if (responseHeader) {
|
|
22644
|
-
const content = response.headers.get(responseHeader);
|
|
22645
|
-
if (isString(content)) return content;
|
|
22646
|
-
}
|
|
22647
|
-
};
|
|
22648
|
-
const getResponseBody = async (response) => {
|
|
22649
|
-
if (response.status !== 204) try {
|
|
22650
|
-
const contentType = response.headers.get("Content-Type");
|
|
22651
|
-
if (contentType) if (["application/json", "application/problem+json"].some((type) => contentType.toLowerCase().startsWith(type))) return await response.json();
|
|
22652
|
-
else return await response.text();
|
|
22653
|
-
} catch (error) {
|
|
22654
|
-
console.error(error);
|
|
22655
|
-
}
|
|
22656
|
-
};
|
|
22657
|
-
const catchErrorCodes = (options, result) => {
|
|
22658
|
-
const error = {
|
|
22659
|
-
400: "Bad Request",
|
|
22660
|
-
401: "Unauthorized",
|
|
22661
|
-
403: "Forbidden",
|
|
22662
|
-
404: "Not Found",
|
|
22663
|
-
500: "Internal Server Error",
|
|
22664
|
-
502: "Bad Gateway",
|
|
22665
|
-
503: "Service Unavailable",
|
|
22666
|
-
...options.errors
|
|
22667
|
-
}[result.status];
|
|
22668
|
-
if (error) throw new ApiError(options, result, error);
|
|
22669
|
-
if (!result.ok) throw new ApiError(options, result, "Generic Error");
|
|
22670
|
-
};
|
|
22671
|
-
/**
|
|
22672
|
-
* Request method
|
|
22673
|
-
* @param config The OpenAPI configuration object
|
|
22674
|
-
* @param options The request options from the service
|
|
22675
|
-
* @returns CancelablePromise<T>
|
|
22676
|
-
* @throws ApiError
|
|
22677
|
-
*/
|
|
22678
|
-
const request = (config, options) => {
|
|
22679
|
-
return new CancelablePromise(async (resolve$2, reject, onCancel) => {
|
|
22680
|
-
try {
|
|
22681
|
-
const url = getUrl(config, options);
|
|
22682
|
-
const formData = getFormData(options);
|
|
22683
|
-
const body = getRequestBody(options);
|
|
22684
|
-
const headers = await getHeaders(config, options);
|
|
22685
|
-
debugLogRequest(config, url, headers, formData ?? body ?? {});
|
|
22686
|
-
if (!onCancel.isCancelled) {
|
|
22687
|
-
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
|
|
22688
|
-
const responseBody = await getResponseBody(response);
|
|
22689
|
-
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
22690
|
-
let result;
|
|
22691
|
-
if (isResponseSchemaV4(config, options)) result = parseResponseSchemaV4(url, response, responseHeader, responseBody);
|
|
22692
|
-
else result = {
|
|
22693
|
-
url,
|
|
22694
|
-
ok: response.ok,
|
|
22695
|
-
status: response.status,
|
|
22696
|
-
statusText: response.statusText,
|
|
22697
|
-
body: responseHeader ?? responseBody
|
|
22698
|
-
};
|
|
22699
|
-
debugLogResponse(config, result);
|
|
22700
|
-
catchErrorCodes(options, result);
|
|
22701
|
-
resolve$2(result.body);
|
|
22702
|
-
}
|
|
22703
|
-
} catch (error) {
|
|
22704
|
-
reject(error);
|
|
22705
|
-
}
|
|
22706
|
-
});
|
|
22707
|
-
};
|
|
22708
|
-
const debugLogRequest = async (config, url, headers, body) => {
|
|
22709
|
-
config.LOGGER?.debug(`-- START CF API REQUEST: ${url}`);
|
|
22710
|
-
const logHeaders = new Headers(headers);
|
|
22711
|
-
logHeaders.delete("Authorization");
|
|
22712
|
-
config.LOGGER?.debugWithSanitization("HEADERS:", JSON.stringify(logHeaders, null, 2));
|
|
22713
|
-
config.LOGGER?.debugWithSanitization("BODY:", JSON.stringify(body instanceof FormData ? await new Response(body).text() : body, null, 2));
|
|
22714
|
-
config.LOGGER?.debug("-- END CF API REQUEST");
|
|
22715
|
-
};
|
|
22716
|
-
const debugLogResponse = (config, response) => {
|
|
22717
|
-
config.LOGGER?.debug("-- START CF API RESPONSE:", response.statusText, response.status);
|
|
22718
|
-
config.LOGGER?.debugWithSanitization("RESPONSE:", response.body);
|
|
22719
|
-
config.LOGGER?.debug("-- END CF API RESPONSE");
|
|
22720
|
-
};
|
|
22721
|
-
|
|
22722
22748
|
//#endregion
|
|
22723
22749
|
//#region ../containers-shared/src/client/services/ImageRegistriesService.ts
|
|
22724
22750
|
/* istanbul ignore file */
|