@fluid-app/fluid-cli-widget 0.1.28 → 0.1.30
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-JKSTx5pZ.d.mts +199 -0
- package/dist/index-JKSTx5pZ.d.mts.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +767 -239
- package/dist/index.mjs.map +1 -1
- package/dist/{src-CVadzcYM.mjs → src-_wfDoBLp.mjs} +357 -30
- package/dist/src-_wfDoBLp.mjs.map +1 -0
- package/dist/vite/plugin.d.mts +2 -86
- package/dist/vite/plugin.mjs +1 -191
- package/package.json +1 -1
- package/templates/default/AGENTS.md +15 -0
- package/templates/default/styles.css +47 -15
- package/dist/index-BYRGkNyt.d.mts +0 -91
- package/dist/index-BYRGkNyt.d.mts.map +0 -1
- package/dist/src-CVadzcYM.mjs.map +0 -1
- package/dist/vite/plugin.d.mts.map +0 -1
- package/dist/vite/plugin.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,243 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as fluidOsV0WidgetPackageGitCredentialCreate, l as WidgetToolingError, n as loadAndValidateWidgetPackage, r as publishWidgetPackage$1, t as buildWidgetPackage$1 } from "./src-_wfDoBLp.mjs";
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { execa } from "execa";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { findProjectConfig, readConfig } from "@fluid-app/fluid-cli";
|
|
8
|
-
import chalk from "chalk";
|
|
9
|
-
import ora from "ora";
|
|
10
8
|
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
11
9
|
import { cp, mkdir, mkdtemp, readFile, readdir, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
10
|
+
import chalk from "chalk";
|
|
11
|
+
import ora from "ora";
|
|
12
12
|
import { spawn, spawnSync } from "node:child_process";
|
|
13
13
|
import os from "node:os";
|
|
14
14
|
import prompts from "prompts";
|
|
15
|
-
//#region ../../platform/api-client-core/src/fetch-client.ts
|
|
16
|
-
/**
|
|
17
|
-
* API Error class compatible with fluid-admin's ApiError
|
|
18
|
-
*/
|
|
19
|
-
var ApiError = class ApiError extends Error {
|
|
20
|
-
status;
|
|
21
|
-
data;
|
|
22
|
-
requestId;
|
|
23
|
-
constructor(message, status, data, requestId) {
|
|
24
|
-
super(message);
|
|
25
|
-
this.name = "ApiError";
|
|
26
|
-
this.status = status;
|
|
27
|
-
this.data = data;
|
|
28
|
-
this.requestId = requestId;
|
|
29
|
-
if ("captureStackTrace" in Error) Error.captureStackTrace(this, ApiError);
|
|
30
|
-
}
|
|
31
|
-
toJSON() {
|
|
32
|
-
return {
|
|
33
|
-
name: this.name,
|
|
34
|
-
message: this.message,
|
|
35
|
-
status: this.status,
|
|
36
|
-
data: this.data,
|
|
37
|
-
requestId: this.requestId
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
function getStringRequestId(value) {
|
|
42
|
-
if (typeof value !== "string") return;
|
|
43
|
-
const trimmed = value.trim();
|
|
44
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
45
|
-
}
|
|
46
|
-
function getRequestIdFromHeaders(headers) {
|
|
47
|
-
return getStringRequestId(headers.get("x-request-id")) ?? getStringRequestId(headers.get("request-id")) ?? getStringRequestId(headers.get("X-Request-ID"));
|
|
48
|
-
}
|
|
49
|
-
function getRequestIdFromJsonBody(body) {
|
|
50
|
-
if (!body || typeof body !== "object" || Array.isArray(body)) return;
|
|
51
|
-
const record = body;
|
|
52
|
-
const meta = record.meta;
|
|
53
|
-
return getStringRequestId(record.request_id) ?? getStringRequestId(record.requestId) ?? (meta && typeof meta === "object" && !Array.isArray(meta) ? getStringRequestId(meta.request_id) ?? getStringRequestId(meta.requestId) : void 0);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Creates a configured fetch client instance
|
|
57
|
-
*/
|
|
58
|
-
function createFetchClient(config) {
|
|
59
|
-
const { baseUrl, getAuthToken, onAuthError, defaultHeaders = {}, credentials, cache, networkRetry, throwOnInvalidJson = false } = config;
|
|
60
|
-
const maxNetworkRetries = Math.max(0, networkRetry?.maxRetries ?? 0);
|
|
61
|
-
const baseNetworkRetryDelayMs = Math.max(0, networkRetry?.baseDelayMs ?? 0);
|
|
62
|
-
/**
|
|
63
|
-
* Build headers for a request
|
|
64
|
-
*/
|
|
65
|
-
async function buildHeaders(customHeaders) {
|
|
66
|
-
const headers = {
|
|
67
|
-
Accept: "application/json",
|
|
68
|
-
"Content-Type": "application/json",
|
|
69
|
-
...defaultHeaders,
|
|
70
|
-
...customHeaders
|
|
71
|
-
};
|
|
72
|
-
if (getAuthToken) {
|
|
73
|
-
const token = await getAuthToken();
|
|
74
|
-
if (token) headers.Authorization = `Bearer ${token}`;
|
|
75
|
-
}
|
|
76
|
-
return headers;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Join baseUrl + endpoint via string concatenation (matches fetchApi).
|
|
80
|
-
* Using `new URL(endpoint, baseUrl)` would strip any path prefix from
|
|
81
|
-
* baseUrl (e.g. "/api") when the endpoint starts with "/".
|
|
82
|
-
*/
|
|
83
|
-
function joinUrl(endpoint) {
|
|
84
|
-
return `${baseUrl}${endpoint}`;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Build URL with query parameters for GET requests
|
|
88
|
-
* Compatible with fluid-admin's query param handling
|
|
89
|
-
*/
|
|
90
|
-
function buildUrl(endpoint, params) {
|
|
91
|
-
const fullUrl = joinUrl(endpoint);
|
|
92
|
-
if (!params || Object.keys(params).length === 0) return fullUrl;
|
|
93
|
-
const queryString = new URLSearchParams();
|
|
94
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
95
|
-
if (value === void 0 || value === null) return;
|
|
96
|
-
if (Array.isArray(value)) value.forEach((item) => queryString.append(`${key}[]`, String(item)));
|
|
97
|
-
else if (typeof value === "object") Object.entries(value).forEach(([subKey, subValue]) => {
|
|
98
|
-
if (subValue === void 0 || subValue === null) return;
|
|
99
|
-
if (Array.isArray(subValue)) subValue.forEach((item) => queryString.append(`${key}[${subKey}][]`, String(item)));
|
|
100
|
-
else queryString.append(`${key}[${subKey}]`, String(subValue));
|
|
101
|
-
});
|
|
102
|
-
else queryString.append(key, String(value));
|
|
103
|
-
});
|
|
104
|
-
const qs = queryString.toString();
|
|
105
|
-
return qs ? `${fullUrl}?${qs}` : fullUrl;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Shared response handler for both JSON and FormData requests.
|
|
109
|
-
* Handles auth errors, non-OK responses, 204 No Content, and JSON parsing.
|
|
110
|
-
*/
|
|
111
|
-
async function handleResponse(response, method, _url) {
|
|
112
|
-
const headerRequestId = getRequestIdFromHeaders(response.headers);
|
|
113
|
-
if (response.status === 401 && onAuthError) onAuthError();
|
|
114
|
-
if (!response.ok) {
|
|
115
|
-
const errorText = await response.text().catch(() => "");
|
|
116
|
-
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
117
|
-
let data;
|
|
118
|
-
try {
|
|
119
|
-
data = JSON.parse(errorText);
|
|
120
|
-
} catch {
|
|
121
|
-
throw new ApiError(errorText.slice(0, 200) || `${method} request failed with status ${response.status}`, response.status, null, headerRequestId);
|
|
122
|
-
}
|
|
123
|
-
const nestedError = typeof data.error === "object" && data.error !== null ? data.error.message : void 0;
|
|
124
|
-
const directError = typeof data.error === "string" ? data.error : void 0;
|
|
125
|
-
const message = typeof data.message === "string" ? data.message : void 0;
|
|
126
|
-
const errorMessage = typeof data.error_message === "string" ? data.error_message : void 0;
|
|
127
|
-
throw new ApiError(message || errorMessage || directError || (typeof nestedError === "string" ? nestedError : void 0) || `${method} request failed with status ${response.status}`, response.status, data.errors || data, headerRequestId ?? getRequestIdFromJsonBody(data));
|
|
128
|
-
} else throw new ApiError(`${method} request failed with status ${response.status}`, response.status, null, headerRequestId);
|
|
129
|
-
}
|
|
130
|
-
if (response.status === 204 || response.headers.get("content-length") === "0") return null;
|
|
131
|
-
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
132
|
-
const responseText = await response.text();
|
|
133
|
-
try {
|
|
134
|
-
return JSON.parse(responseText);
|
|
135
|
-
} catch {
|
|
136
|
-
if (throwOnInvalidJson) throw new ApiError("Failed to parse response as JSON", response.status, null, headerRequestId);
|
|
137
|
-
return responseText ? responseText : null;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
function getNetworkRetryDelayMs(retryAttempt) {
|
|
143
|
-
return baseNetworkRetryDelayMs * 2 ** (retryAttempt - 1);
|
|
144
|
-
}
|
|
145
|
-
async function waitForNetworkRetry(retryAttempt) {
|
|
146
|
-
const delayMs = getNetworkRetryDelayMs(retryAttempt);
|
|
147
|
-
if (delayMs <= 0) return;
|
|
148
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
149
|
-
}
|
|
150
|
-
async function fetchWithNetworkRetry(url, fetchOptions, signal) {
|
|
151
|
-
let retryCount = 0;
|
|
152
|
-
while (true) try {
|
|
153
|
-
return await fetch(url, fetchOptions);
|
|
154
|
-
} catch (networkError) {
|
|
155
|
-
if (signal?.aborted || retryCount >= maxNetworkRetries) throw networkError;
|
|
156
|
-
retryCount += 1;
|
|
157
|
-
await waitForNetworkRetry(retryCount);
|
|
158
|
-
if (signal?.aborted) throw networkError;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Main request function
|
|
163
|
-
*/
|
|
164
|
-
async function request(endpoint, options = {}) {
|
|
165
|
-
const { method = "GET", headers: customHeaders, params, body, signal, priority } = options;
|
|
166
|
-
const url = params ? buildUrl(endpoint, params) : joinUrl(endpoint);
|
|
167
|
-
const headers = await buildHeaders(customHeaders);
|
|
168
|
-
let response;
|
|
169
|
-
try {
|
|
170
|
-
const fetchOptions = {
|
|
171
|
-
method,
|
|
172
|
-
headers
|
|
173
|
-
};
|
|
174
|
-
if (credentials) fetchOptions.credentials = credentials;
|
|
175
|
-
if (cache) fetchOptions.cache = cache;
|
|
176
|
-
if (priority) fetchOptions.priority = priority;
|
|
177
|
-
const serializedBody = body && method !== "GET" ? JSON.stringify(body) : null;
|
|
178
|
-
if (serializedBody) fetchOptions.body = serializedBody;
|
|
179
|
-
if (signal) fetchOptions.signal = signal;
|
|
180
|
-
response = await fetchWithNetworkRetry(url, fetchOptions, signal);
|
|
181
|
-
} catch (networkError) {
|
|
182
|
-
throw new ApiError(`Network error: ${networkError instanceof Error ? networkError.message : "Unknown network error"}`, 0, null);
|
|
183
|
-
}
|
|
184
|
-
return handleResponse(response, method, url);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Request with FormData (for file uploads)
|
|
188
|
-
*/
|
|
189
|
-
async function requestWithFormData(endpoint, formData, options = {}) {
|
|
190
|
-
const { method = "POST", headers: customHeaders, signal, priority } = options;
|
|
191
|
-
const url = joinUrl(endpoint);
|
|
192
|
-
const headers = await buildHeaders(customHeaders);
|
|
193
|
-
delete headers["Content-Type"];
|
|
194
|
-
let response;
|
|
195
|
-
try {
|
|
196
|
-
const fetchOptions = {
|
|
197
|
-
method,
|
|
198
|
-
headers,
|
|
199
|
-
body: formData
|
|
200
|
-
};
|
|
201
|
-
if (credentials) fetchOptions.credentials = credentials;
|
|
202
|
-
if (cache) fetchOptions.cache = cache;
|
|
203
|
-
if (priority) fetchOptions.priority = priority;
|
|
204
|
-
if (signal) fetchOptions.signal = signal;
|
|
205
|
-
response = await fetchWithNetworkRetry(url, fetchOptions, signal);
|
|
206
|
-
} catch (networkError) {
|
|
207
|
-
throw new ApiError(`Network error: ${networkError instanceof Error ? networkError.message : "Unknown network error"}`, 0, null);
|
|
208
|
-
}
|
|
209
|
-
return handleResponse(response, method, url);
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
request,
|
|
213
|
-
requestWithFormData,
|
|
214
|
-
get: (endpoint, params, options) => request(endpoint, {
|
|
215
|
-
...options,
|
|
216
|
-
method: "GET",
|
|
217
|
-
...params && { params }
|
|
218
|
-
}),
|
|
219
|
-
post: (endpoint, body, options) => request(endpoint, {
|
|
220
|
-
...options,
|
|
221
|
-
method: "POST",
|
|
222
|
-
body
|
|
223
|
-
}),
|
|
224
|
-
put: (endpoint, body, options) => request(endpoint, {
|
|
225
|
-
...options,
|
|
226
|
-
method: "PUT",
|
|
227
|
-
body
|
|
228
|
-
}),
|
|
229
|
-
patch: (endpoint, body, options) => request(endpoint, {
|
|
230
|
-
...options,
|
|
231
|
-
method: "PATCH",
|
|
232
|
-
body
|
|
233
|
-
}),
|
|
234
|
-
delete: (endpoint, options) => request(endpoint, {
|
|
235
|
-
...options,
|
|
236
|
-
method: "DELETE"
|
|
237
|
-
})
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
//#endregion
|
|
241
15
|
//#region src/utils/config.ts
|
|
242
16
|
const WIDGET_CONFIG_FILE = "fluid.widget.config.ts";
|
|
243
17
|
var WidgetConfigParseError = class extends Error {
|
|
@@ -800,9 +574,9 @@ function isRecord$3(value) {
|
|
|
800
574
|
}
|
|
801
575
|
//#endregion
|
|
802
576
|
//#region src/utils/template.ts
|
|
803
|
-
const EMBEDDED_PORTAL_SDK_VERSION = "0.1.
|
|
577
|
+
const EMBEDDED_PORTAL_SDK_VERSION = "0.1.464";
|
|
804
578
|
const EMBEDDED_CLI_CORE_VERSION = "0.1.14";
|
|
805
|
-
const EMBEDDED_CLI_WIDGET_VERSION = "0.1.
|
|
579
|
+
const EMBEDDED_CLI_WIDGET_VERSION = "0.1.30";
|
|
806
580
|
function getDefaultTemplatePath() {
|
|
807
581
|
return path.join(findPackageRoot(), "templates", "default");
|
|
808
582
|
}
|
|
@@ -976,6 +750,733 @@ const buildCommand = new Command("build").description("Validate and build the cu
|
|
|
976
750
|
});
|
|
977
751
|
});
|
|
978
752
|
//#endregion
|
|
753
|
+
//#region ../../platform/api-client-core/src/api-error-shape.ts
|
|
754
|
+
/**
|
|
755
|
+
* Narrows a parsed JSON error payload to the envelope contract. Arrays and
|
|
756
|
+
* primitives are not envelopes, so they resolve to `null` — their content is
|
|
757
|
+
* still reachable through `ApiError.data`.
|
|
758
|
+
*/
|
|
759
|
+
function toApiErrorBody(value) {
|
|
760
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
761
|
+
return value;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* The single unwrap rule, shared by every producer of `ApiError`.
|
|
765
|
+
*
|
|
766
|
+
* `??` rather than `||` so an explicitly empty `errors` (`""`, `0`, `false`)
|
|
767
|
+
* is preserved instead of silently falling back to the whole envelope.
|
|
768
|
+
*/
|
|
769
|
+
function toApiErrorData(body) {
|
|
770
|
+
if (!body) return null;
|
|
771
|
+
return body.errors ?? body;
|
|
772
|
+
}
|
|
773
|
+
//#endregion
|
|
774
|
+
//#region ../../platform/api-client-core/src/fetch-client.ts
|
|
775
|
+
/**
|
|
776
|
+
* API Error class compatible with fluid-admin's ApiError
|
|
777
|
+
*/
|
|
778
|
+
var ApiError = class ApiError extends Error {
|
|
779
|
+
status;
|
|
780
|
+
/**
|
|
781
|
+
* The unwrapped field-error bag. See `ApiErrorData`; the contract is
|
|
782
|
+
* documented in `docs/api-error-data-contract.md`.
|
|
783
|
+
*/
|
|
784
|
+
data;
|
|
785
|
+
/**
|
|
786
|
+
* The full error response envelope. Read `error_message`, `error`, `status`
|
|
787
|
+
* and nested `errors` from here — `data` has already unwrapped one level.
|
|
788
|
+
*/
|
|
789
|
+
body;
|
|
790
|
+
requestId;
|
|
791
|
+
constructor(message, status, data, requestId, body) {
|
|
792
|
+
super(message);
|
|
793
|
+
this.name = "ApiError";
|
|
794
|
+
this.status = status;
|
|
795
|
+
this.data = data ?? null;
|
|
796
|
+
this.body = body ?? null;
|
|
797
|
+
this.requestId = requestId;
|
|
798
|
+
if ("captureStackTrace" in Error) Error.captureStackTrace(this, ApiError);
|
|
799
|
+
}
|
|
800
|
+
toJSON() {
|
|
801
|
+
return {
|
|
802
|
+
name: this.name,
|
|
803
|
+
message: this.message,
|
|
804
|
+
status: this.status,
|
|
805
|
+
data: this.data,
|
|
806
|
+
body: this.body,
|
|
807
|
+
requestId: this.requestId
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region ../../platform/api-client-core/src/hey-api-error-policy.ts
|
|
813
|
+
function getNonEmptyString(value) {
|
|
814
|
+
if (typeof value !== "string") return;
|
|
815
|
+
const trimmed = value.trim();
|
|
816
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
817
|
+
}
|
|
818
|
+
function getRequestId(response, error) {
|
|
819
|
+
const meta = toApiErrorBody(error?.meta);
|
|
820
|
+
return getNonEmptyString(response.headers.get("x-request-id")) ?? getNonEmptyString(response.headers.get("request-id")) ?? getNonEmptyString(error?.request_id) ?? getNonEmptyString(error?.requestId) ?? getNonEmptyString(meta?.request_id) ?? getNonEmptyString(meta?.requestId);
|
|
821
|
+
}
|
|
822
|
+
function getErrorMessage(error, fallback) {
|
|
823
|
+
const nestedError = toApiErrorBody(error.error);
|
|
824
|
+
return getNonEmptyString(error.message) ?? getNonEmptyString(error.error_message) ?? getNonEmptyString(nestedError?.message) ?? fallback;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Creates an error interceptor compatible with generated Hey API fetch clients.
|
|
828
|
+
* Consumer-specific auth and cancellation policy is supplied through callbacks,
|
|
829
|
+
* keeping this package independent from generated client types.
|
|
830
|
+
*/
|
|
831
|
+
function createHeyApiErrorInterceptor(options = {}) {
|
|
832
|
+
return (error, response, request, requestOptions) => {
|
|
833
|
+
if (!response) {
|
|
834
|
+
if (error instanceof ApiError) return error;
|
|
835
|
+
if (options.shouldPassThroughTransportError?.(error)) return error;
|
|
836
|
+
if (!request) return error;
|
|
837
|
+
return new ApiError(`Network error: ${error instanceof Error ? error.message : "Unknown network error"}`, 0, null);
|
|
838
|
+
}
|
|
839
|
+
if (response.ok && error instanceof SyntaxError) return new ApiError("Failed to parse response as JSON", response.status, null, getRequestId(response, null));
|
|
840
|
+
options.onResponseError?.(response);
|
|
841
|
+
const method = request?.method ?? requestOptions.method ?? "GET";
|
|
842
|
+
const errorRecord = toApiErrorBody(error);
|
|
843
|
+
const requestId = getRequestId(response, errorRecord);
|
|
844
|
+
if (errorRecord) return new ApiError(getErrorMessage(errorRecord, `${method} request failed`), response.status, toApiErrorData(errorRecord), requestId, errorRecord);
|
|
845
|
+
const isJson = response.headers.get("content-type")?.includes("application/json");
|
|
846
|
+
const text = getNonEmptyString(error);
|
|
847
|
+
return new ApiError(isJson && text ? text.slice(0, 200) : `${method} request failed with status ${response.status}`, response.status, isJson ? error : null, requestId, null);
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
//#endregion
|
|
851
|
+
//#region ../../api-clients/hey-api-fetch-runtime/src/generated/core/bodySerializer.gen.ts
|
|
852
|
+
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
853
|
+
Object.entries({
|
|
854
|
+
$body_: "body",
|
|
855
|
+
$headers_: "headers",
|
|
856
|
+
$path_: "path",
|
|
857
|
+
$query_: "query"
|
|
858
|
+
});
|
|
859
|
+
//#endregion
|
|
860
|
+
//#region ../../api-clients/hey-api-fetch-runtime/src/generated/core/serverSentEvents.gen.ts
|
|
861
|
+
function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
|
|
862
|
+
let lastEventId;
|
|
863
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
864
|
+
const createStream = async function* () {
|
|
865
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
866
|
+
let attempt = 0;
|
|
867
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
868
|
+
while (true) {
|
|
869
|
+
if (signal.aborted) break;
|
|
870
|
+
attempt++;
|
|
871
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
872
|
+
if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
|
|
873
|
+
try {
|
|
874
|
+
const requestInit = {
|
|
875
|
+
redirect: "follow",
|
|
876
|
+
...options,
|
|
877
|
+
body: options.serializedBody,
|
|
878
|
+
headers,
|
|
879
|
+
signal
|
|
880
|
+
};
|
|
881
|
+
let request = new Request(url, requestInit);
|
|
882
|
+
if (onRequest) request = await onRequest(url, requestInit);
|
|
883
|
+
const response = await (options.fetch ?? globalThis.fetch)(request);
|
|
884
|
+
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
885
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
886
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
887
|
+
let buffer = "";
|
|
888
|
+
const abortHandler = () => {
|
|
889
|
+
try {
|
|
890
|
+
reader.cancel();
|
|
891
|
+
} catch {}
|
|
892
|
+
};
|
|
893
|
+
signal.addEventListener("abort", abortHandler);
|
|
894
|
+
try {
|
|
895
|
+
while (true) {
|
|
896
|
+
const { done, value } = await reader.read();
|
|
897
|
+
if (done) break;
|
|
898
|
+
buffer += value;
|
|
899
|
+
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
900
|
+
const chunks = buffer.split("\n\n");
|
|
901
|
+
buffer = chunks.pop() ?? "";
|
|
902
|
+
for (const chunk of chunks) {
|
|
903
|
+
const lines = chunk.split("\n");
|
|
904
|
+
const dataLines = [];
|
|
905
|
+
let eventName;
|
|
906
|
+
for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
|
|
907
|
+
else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
|
|
908
|
+
else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
|
|
909
|
+
else if (line.startsWith("retry:")) {
|
|
910
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
911
|
+
if (!Number.isNaN(parsed)) retryDelay = parsed;
|
|
912
|
+
}
|
|
913
|
+
let data;
|
|
914
|
+
let parsedJson = false;
|
|
915
|
+
if (dataLines.length) {
|
|
916
|
+
const rawData = dataLines.join("\n");
|
|
917
|
+
try {
|
|
918
|
+
data = JSON.parse(rawData);
|
|
919
|
+
parsedJson = true;
|
|
920
|
+
} catch {
|
|
921
|
+
data = rawData;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
if (parsedJson) {
|
|
925
|
+
if (responseValidator) await responseValidator(data);
|
|
926
|
+
if (responseTransformer) data = await responseTransformer(data);
|
|
927
|
+
}
|
|
928
|
+
onSseEvent?.({
|
|
929
|
+
data,
|
|
930
|
+
event: eventName,
|
|
931
|
+
id: lastEventId,
|
|
932
|
+
retry: retryDelay
|
|
933
|
+
});
|
|
934
|
+
if (dataLines.length) yield data;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
} finally {
|
|
938
|
+
signal.removeEventListener("abort", abortHandler);
|
|
939
|
+
reader.releaseLock();
|
|
940
|
+
}
|
|
941
|
+
break;
|
|
942
|
+
} catch (error) {
|
|
943
|
+
onSseError?.(error);
|
|
944
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
|
|
945
|
+
await sleep(Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4));
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
return { stream: createStream() };
|
|
950
|
+
}
|
|
951
|
+
//#endregion
|
|
952
|
+
//#region ../../api-clients/hey-api-fetch-runtime/src/generated/core/pathSerializer.gen.ts
|
|
953
|
+
const separatorArrayExplode = (style) => {
|
|
954
|
+
switch (style) {
|
|
955
|
+
case "label": return ".";
|
|
956
|
+
case "matrix": return ";";
|
|
957
|
+
case "simple": return ",";
|
|
958
|
+
default: return "&";
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
const separatorArrayNoExplode = (style) => {
|
|
962
|
+
switch (style) {
|
|
963
|
+
case "form": return ",";
|
|
964
|
+
case "pipeDelimited": return "|";
|
|
965
|
+
case "spaceDelimited": return "%20";
|
|
966
|
+
default: return ",";
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
const separatorObjectExplode = (style) => {
|
|
970
|
+
switch (style) {
|
|
971
|
+
case "label": return ".";
|
|
972
|
+
case "matrix": return ";";
|
|
973
|
+
case "simple": return ",";
|
|
974
|
+
default: return "&";
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
|
|
978
|
+
if (!explode) {
|
|
979
|
+
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
980
|
+
switch (style) {
|
|
981
|
+
case "label": return `.${joinedValues}`;
|
|
982
|
+
case "matrix": return `;${name}=${joinedValues}`;
|
|
983
|
+
case "simple": return joinedValues;
|
|
984
|
+
default: return `${name}=${joinedValues}`;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
const separator = separatorArrayExplode(style);
|
|
988
|
+
const joinedValues = value.map((v) => {
|
|
989
|
+
if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
|
|
990
|
+
return serializePrimitiveParam({
|
|
991
|
+
allowReserved,
|
|
992
|
+
name,
|
|
993
|
+
value: v
|
|
994
|
+
});
|
|
995
|
+
}).join(separator);
|
|
996
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
997
|
+
};
|
|
998
|
+
const serializePrimitiveParam = ({ allowReserved, name, value }) => {
|
|
999
|
+
if (value === void 0 || value === null) return "";
|
|
1000
|
+
if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
1001
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
1002
|
+
};
|
|
1003
|
+
const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
|
|
1004
|
+
if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
1005
|
+
if (style !== "deepObject" && !explode) {
|
|
1006
|
+
let values = [];
|
|
1007
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
1008
|
+
values = [
|
|
1009
|
+
...values,
|
|
1010
|
+
key,
|
|
1011
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
1012
|
+
];
|
|
1013
|
+
});
|
|
1014
|
+
const joinedValues = values.join(",");
|
|
1015
|
+
switch (style) {
|
|
1016
|
+
case "form": return `${name}=${joinedValues}`;
|
|
1017
|
+
case "label": return `.${joinedValues}`;
|
|
1018
|
+
case "matrix": return `;${name}=${joinedValues}`;
|
|
1019
|
+
default: return joinedValues;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
const separator = separatorObjectExplode(style);
|
|
1023
|
+
const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
|
|
1024
|
+
allowReserved,
|
|
1025
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
1026
|
+
value: v
|
|
1027
|
+
})).join(separator);
|
|
1028
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
1029
|
+
};
|
|
1030
|
+
//#endregion
|
|
1031
|
+
//#region ../../api-clients/hey-api-fetch-runtime/src/generated/core/utils.gen.ts
|
|
1032
|
+
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
1033
|
+
const defaultPathSerializer = ({ path, url: _url }) => {
|
|
1034
|
+
let url = _url;
|
|
1035
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
1036
|
+
if (matches) for (const match of matches) {
|
|
1037
|
+
let explode = false;
|
|
1038
|
+
let name = match.substring(1, match.length - 1);
|
|
1039
|
+
let style = "simple";
|
|
1040
|
+
if (name.endsWith("*")) {
|
|
1041
|
+
explode = true;
|
|
1042
|
+
name = name.substring(0, name.length - 1);
|
|
1043
|
+
}
|
|
1044
|
+
if (name.startsWith(".")) {
|
|
1045
|
+
name = name.substring(1);
|
|
1046
|
+
style = "label";
|
|
1047
|
+
} else if (name.startsWith(";")) {
|
|
1048
|
+
name = name.substring(1);
|
|
1049
|
+
style = "matrix";
|
|
1050
|
+
}
|
|
1051
|
+
const value = path[name];
|
|
1052
|
+
if (value === void 0 || value === null) continue;
|
|
1053
|
+
if (Array.isArray(value)) {
|
|
1054
|
+
url = url.replace(match, serializeArrayParam({
|
|
1055
|
+
explode,
|
|
1056
|
+
name,
|
|
1057
|
+
style,
|
|
1058
|
+
value
|
|
1059
|
+
}));
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
if (typeof value === "object") {
|
|
1063
|
+
url = url.replace(match, serializeObjectParam({
|
|
1064
|
+
explode,
|
|
1065
|
+
name,
|
|
1066
|
+
style,
|
|
1067
|
+
value,
|
|
1068
|
+
valueOnly: true
|
|
1069
|
+
}));
|
|
1070
|
+
continue;
|
|
1071
|
+
}
|
|
1072
|
+
if (style === "matrix") {
|
|
1073
|
+
url = url.replace(match, `;${serializePrimitiveParam({
|
|
1074
|
+
name,
|
|
1075
|
+
value
|
|
1076
|
+
})}`);
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
1080
|
+
url = url.replace(match, replaceValue);
|
|
1081
|
+
}
|
|
1082
|
+
return url;
|
|
1083
|
+
};
|
|
1084
|
+
const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
1085
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
1086
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
1087
|
+
if (path) url = defaultPathSerializer({
|
|
1088
|
+
path,
|
|
1089
|
+
url
|
|
1090
|
+
});
|
|
1091
|
+
let search = query ? querySerializer(query) : "";
|
|
1092
|
+
if (search.startsWith("?")) search = search.substring(1);
|
|
1093
|
+
if (search) url += `?${search}`;
|
|
1094
|
+
return url;
|
|
1095
|
+
};
|
|
1096
|
+
function getValidRequestBody(options) {
|
|
1097
|
+
const hasBody = options.body !== void 0;
|
|
1098
|
+
if (hasBody && options.bodySerializer) {
|
|
1099
|
+
if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
|
|
1100
|
+
return options.body !== "" ? options.body : null;
|
|
1101
|
+
}
|
|
1102
|
+
if (hasBody) return options.body;
|
|
1103
|
+
}
|
|
1104
|
+
//#endregion
|
|
1105
|
+
//#region ../../api-clients/hey-api-fetch-runtime/src/generated/core/auth.gen.ts
|
|
1106
|
+
const getAuthToken = async (auth, callback) => {
|
|
1107
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
1108
|
+
if (!token) return;
|
|
1109
|
+
if (auth.scheme === "bearer") return `Bearer ${token}`;
|
|
1110
|
+
if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
|
|
1111
|
+
return token;
|
|
1112
|
+
};
|
|
1113
|
+
//#endregion
|
|
1114
|
+
//#region ../../api-clients/hey-api-fetch-runtime/src/generated/client/utils.gen.ts
|
|
1115
|
+
const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
1116
|
+
const querySerializer = (queryParams) => {
|
|
1117
|
+
const search = [];
|
|
1118
|
+
if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
|
|
1119
|
+
const value = queryParams[name];
|
|
1120
|
+
if (value === void 0 || value === null) continue;
|
|
1121
|
+
const options = parameters[name] || args;
|
|
1122
|
+
if (Array.isArray(value)) {
|
|
1123
|
+
const serializedArray = serializeArrayParam({
|
|
1124
|
+
allowReserved: options.allowReserved,
|
|
1125
|
+
explode: true,
|
|
1126
|
+
name,
|
|
1127
|
+
style: "form",
|
|
1128
|
+
value,
|
|
1129
|
+
...options.array
|
|
1130
|
+
});
|
|
1131
|
+
if (serializedArray) search.push(serializedArray);
|
|
1132
|
+
} else if (typeof value === "object") {
|
|
1133
|
+
const serializedObject = serializeObjectParam({
|
|
1134
|
+
allowReserved: options.allowReserved,
|
|
1135
|
+
explode: true,
|
|
1136
|
+
name,
|
|
1137
|
+
style: "deepObject",
|
|
1138
|
+
value,
|
|
1139
|
+
...options.object
|
|
1140
|
+
});
|
|
1141
|
+
if (serializedObject) search.push(serializedObject);
|
|
1142
|
+
} else {
|
|
1143
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
1144
|
+
allowReserved: options.allowReserved,
|
|
1145
|
+
name,
|
|
1146
|
+
value
|
|
1147
|
+
});
|
|
1148
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
return search.join("&");
|
|
1152
|
+
};
|
|
1153
|
+
return querySerializer;
|
|
1154
|
+
};
|
|
1155
|
+
/**
|
|
1156
|
+
* Infers parseAs value from provided Content-Type header.
|
|
1157
|
+
*/
|
|
1158
|
+
const getParseAs = (contentType) => {
|
|
1159
|
+
if (!contentType) return "stream";
|
|
1160
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
1161
|
+
if (!cleanContent) return;
|
|
1162
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
|
|
1163
|
+
if (cleanContent === "multipart/form-data") return "formData";
|
|
1164
|
+
if ([
|
|
1165
|
+
"application/",
|
|
1166
|
+
"audio/",
|
|
1167
|
+
"image/",
|
|
1168
|
+
"video/"
|
|
1169
|
+
].some((type) => cleanContent.startsWith(type))) return "blob";
|
|
1170
|
+
if (cleanContent.startsWith("text/")) return "text";
|
|
1171
|
+
};
|
|
1172
|
+
const checkForExistence = (options, name) => {
|
|
1173
|
+
if (!name) return false;
|
|
1174
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
|
|
1175
|
+
return false;
|
|
1176
|
+
};
|
|
1177
|
+
async function setAuthParams(options) {
|
|
1178
|
+
for (const auth of options.security ?? []) {
|
|
1179
|
+
if (checkForExistence(options, auth.name)) continue;
|
|
1180
|
+
const token = await getAuthToken(auth, options.auth);
|
|
1181
|
+
if (!token) continue;
|
|
1182
|
+
const name = auth.name ?? "Authorization";
|
|
1183
|
+
switch (auth.in) {
|
|
1184
|
+
case "query":
|
|
1185
|
+
if (!options.query) options.query = {};
|
|
1186
|
+
options.query[name] = token;
|
|
1187
|
+
break;
|
|
1188
|
+
case "cookie":
|
|
1189
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
1190
|
+
break;
|
|
1191
|
+
default:
|
|
1192
|
+
options.headers.set(name, token);
|
|
1193
|
+
break;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
const buildUrl = (options) => getUrl({
|
|
1198
|
+
baseUrl: options.baseUrl,
|
|
1199
|
+
path: options.path,
|
|
1200
|
+
query: options.query,
|
|
1201
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
1202
|
+
url: options.url
|
|
1203
|
+
});
|
|
1204
|
+
const mergeConfigs = (a, b) => {
|
|
1205
|
+
const config = {
|
|
1206
|
+
...a,
|
|
1207
|
+
...b
|
|
1208
|
+
};
|
|
1209
|
+
if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
1210
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
1211
|
+
return config;
|
|
1212
|
+
};
|
|
1213
|
+
const headersEntries = (headers) => {
|
|
1214
|
+
const entries = [];
|
|
1215
|
+
headers.forEach((value, key) => {
|
|
1216
|
+
entries.push([key, value]);
|
|
1217
|
+
});
|
|
1218
|
+
return entries;
|
|
1219
|
+
};
|
|
1220
|
+
const mergeHeaders = (...headers) => {
|
|
1221
|
+
const mergedHeaders = new Headers();
|
|
1222
|
+
for (const header of headers) {
|
|
1223
|
+
if (!header) continue;
|
|
1224
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
1225
|
+
for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
|
|
1226
|
+
else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
|
|
1227
|
+
else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
1228
|
+
}
|
|
1229
|
+
return mergedHeaders;
|
|
1230
|
+
};
|
|
1231
|
+
var Interceptors = class {
|
|
1232
|
+
fns = [];
|
|
1233
|
+
clear() {
|
|
1234
|
+
this.fns = [];
|
|
1235
|
+
}
|
|
1236
|
+
eject(id) {
|
|
1237
|
+
const index = this.getInterceptorIndex(id);
|
|
1238
|
+
if (this.fns[index]) this.fns[index] = null;
|
|
1239
|
+
}
|
|
1240
|
+
exists(id) {
|
|
1241
|
+
const index = this.getInterceptorIndex(id);
|
|
1242
|
+
return Boolean(this.fns[index]);
|
|
1243
|
+
}
|
|
1244
|
+
getInterceptorIndex(id) {
|
|
1245
|
+
if (typeof id === "number") return this.fns[id] ? id : -1;
|
|
1246
|
+
return this.fns.indexOf(id);
|
|
1247
|
+
}
|
|
1248
|
+
update(id, fn) {
|
|
1249
|
+
const index = this.getInterceptorIndex(id);
|
|
1250
|
+
if (this.fns[index]) {
|
|
1251
|
+
this.fns[index] = fn;
|
|
1252
|
+
return id;
|
|
1253
|
+
}
|
|
1254
|
+
return false;
|
|
1255
|
+
}
|
|
1256
|
+
use(fn) {
|
|
1257
|
+
this.fns.push(fn);
|
|
1258
|
+
return this.fns.length - 1;
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
const createInterceptors = () => ({
|
|
1262
|
+
error: new Interceptors(),
|
|
1263
|
+
request: new Interceptors(),
|
|
1264
|
+
response: new Interceptors()
|
|
1265
|
+
});
|
|
1266
|
+
const defaultQuerySerializer = createQuerySerializer({
|
|
1267
|
+
allowReserved: false,
|
|
1268
|
+
array: {
|
|
1269
|
+
explode: true,
|
|
1270
|
+
style: "form"
|
|
1271
|
+
},
|
|
1272
|
+
object: {
|
|
1273
|
+
explode: true,
|
|
1274
|
+
style: "deepObject"
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
const defaultHeaders = { "Content-Type": "application/json" };
|
|
1278
|
+
const createConfig = (override = {}) => ({
|
|
1279
|
+
...jsonBodySerializer,
|
|
1280
|
+
headers: defaultHeaders,
|
|
1281
|
+
parseAs: "auto",
|
|
1282
|
+
querySerializer: defaultQuerySerializer,
|
|
1283
|
+
...override
|
|
1284
|
+
});
|
|
1285
|
+
//#endregion
|
|
1286
|
+
//#region ../../api-clients/hey-api-fetch-runtime/src/generated/client/client.gen.ts
|
|
1287
|
+
const createClient = (config = {}) => {
|
|
1288
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
1289
|
+
const getConfig = () => ({ ..._config });
|
|
1290
|
+
const setConfig = (config) => {
|
|
1291
|
+
_config = mergeConfigs(_config, config);
|
|
1292
|
+
return getConfig();
|
|
1293
|
+
};
|
|
1294
|
+
const interceptors = createInterceptors();
|
|
1295
|
+
const beforeRequest = async (options) => {
|
|
1296
|
+
const opts = {
|
|
1297
|
+
..._config,
|
|
1298
|
+
...options,
|
|
1299
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
1300
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
1301
|
+
serializedBody: void 0
|
|
1302
|
+
};
|
|
1303
|
+
if (opts.security) await setAuthParams(opts);
|
|
1304
|
+
if (opts.requestValidator) await opts.requestValidator(opts);
|
|
1305
|
+
if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
|
|
1306
|
+
if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
|
|
1307
|
+
const resolvedOpts = opts;
|
|
1308
|
+
return {
|
|
1309
|
+
opts: resolvedOpts,
|
|
1310
|
+
url: buildUrl(resolvedOpts)
|
|
1311
|
+
};
|
|
1312
|
+
};
|
|
1313
|
+
const request = async (options) => {
|
|
1314
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
1315
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
1316
|
+
let request;
|
|
1317
|
+
let response;
|
|
1318
|
+
try {
|
|
1319
|
+
const { opts, url } = await beforeRequest(options);
|
|
1320
|
+
const requestInit = {
|
|
1321
|
+
redirect: "follow",
|
|
1322
|
+
...opts,
|
|
1323
|
+
body: getValidRequestBody(opts)
|
|
1324
|
+
};
|
|
1325
|
+
request = new Request(url, requestInit);
|
|
1326
|
+
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
1327
|
+
const _fetch = opts.fetch;
|
|
1328
|
+
response = await _fetch(request);
|
|
1329
|
+
for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request, opts);
|
|
1330
|
+
const result = {
|
|
1331
|
+
request,
|
|
1332
|
+
response
|
|
1333
|
+
};
|
|
1334
|
+
if (response.ok) {
|
|
1335
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
1336
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
1337
|
+
let emptyData;
|
|
1338
|
+
switch (parseAs) {
|
|
1339
|
+
case "arrayBuffer":
|
|
1340
|
+
case "blob":
|
|
1341
|
+
case "text":
|
|
1342
|
+
emptyData = await response[parseAs]();
|
|
1343
|
+
break;
|
|
1344
|
+
case "formData":
|
|
1345
|
+
emptyData = new FormData();
|
|
1346
|
+
break;
|
|
1347
|
+
case "stream":
|
|
1348
|
+
emptyData = response.body;
|
|
1349
|
+
break;
|
|
1350
|
+
default:
|
|
1351
|
+
emptyData = {};
|
|
1352
|
+
break;
|
|
1353
|
+
}
|
|
1354
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
1355
|
+
data: emptyData,
|
|
1356
|
+
...result
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
let data;
|
|
1360
|
+
switch (parseAs) {
|
|
1361
|
+
case "arrayBuffer":
|
|
1362
|
+
case "blob":
|
|
1363
|
+
case "formData":
|
|
1364
|
+
case "text":
|
|
1365
|
+
data = await response[parseAs]();
|
|
1366
|
+
break;
|
|
1367
|
+
case "json": {
|
|
1368
|
+
const text = await response.text();
|
|
1369
|
+
data = text ? JSON.parse(text) : {};
|
|
1370
|
+
break;
|
|
1371
|
+
}
|
|
1372
|
+
case "stream": return opts.responseStyle === "data" ? response.body : {
|
|
1373
|
+
data: response.body,
|
|
1374
|
+
...result
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
if (parseAs === "json") {
|
|
1378
|
+
if (opts.responseValidator) await opts.responseValidator(data);
|
|
1379
|
+
if (opts.responseTransformer) data = await opts.responseTransformer(data);
|
|
1380
|
+
}
|
|
1381
|
+
return opts.responseStyle === "data" ? data : {
|
|
1382
|
+
data,
|
|
1383
|
+
...result
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
const textError = await response.text();
|
|
1387
|
+
let jsonError;
|
|
1388
|
+
try {
|
|
1389
|
+
jsonError = JSON.parse(textError);
|
|
1390
|
+
} catch {}
|
|
1391
|
+
throw jsonError ?? textError;
|
|
1392
|
+
} catch (error) {
|
|
1393
|
+
let finalError = error;
|
|
1394
|
+
for (const fn of interceptors.error.fns) if (fn) finalError = await fn(finalError, response, request, options);
|
|
1395
|
+
finalError = finalError || {};
|
|
1396
|
+
if (throwOnError) throw finalError;
|
|
1397
|
+
return responseStyle === "data" ? void 0 : {
|
|
1398
|
+
error: finalError,
|
|
1399
|
+
request,
|
|
1400
|
+
response
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
const makeMethodFn = (method) => (options) => request({
|
|
1405
|
+
...options,
|
|
1406
|
+
method
|
|
1407
|
+
});
|
|
1408
|
+
const makeSseFn = (method) => async (options) => {
|
|
1409
|
+
const { opts, url } = await beforeRequest(options);
|
|
1410
|
+
return createSseClient({
|
|
1411
|
+
...opts,
|
|
1412
|
+
body: opts.body,
|
|
1413
|
+
method,
|
|
1414
|
+
onRequest: async (url, init) => {
|
|
1415
|
+
let request = new Request(url, init);
|
|
1416
|
+
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
1417
|
+
return request;
|
|
1418
|
+
},
|
|
1419
|
+
serializedBody: getValidRequestBody(opts),
|
|
1420
|
+
url
|
|
1421
|
+
});
|
|
1422
|
+
};
|
|
1423
|
+
const _buildUrl = (options) => buildUrl({
|
|
1424
|
+
..._config,
|
|
1425
|
+
...options
|
|
1426
|
+
});
|
|
1427
|
+
return {
|
|
1428
|
+
buildUrl: _buildUrl,
|
|
1429
|
+
connect: makeMethodFn("CONNECT"),
|
|
1430
|
+
delete: makeMethodFn("DELETE"),
|
|
1431
|
+
get: makeMethodFn("GET"),
|
|
1432
|
+
getConfig,
|
|
1433
|
+
head: makeMethodFn("HEAD"),
|
|
1434
|
+
interceptors,
|
|
1435
|
+
options: makeMethodFn("OPTIONS"),
|
|
1436
|
+
patch: makeMethodFn("PATCH"),
|
|
1437
|
+
post: makeMethodFn("POST"),
|
|
1438
|
+
put: makeMethodFn("PUT"),
|
|
1439
|
+
request,
|
|
1440
|
+
setConfig,
|
|
1441
|
+
sse: {
|
|
1442
|
+
connect: makeSseFn("CONNECT"),
|
|
1443
|
+
delete: makeSseFn("DELETE"),
|
|
1444
|
+
get: makeSseFn("GET"),
|
|
1445
|
+
head: makeSseFn("HEAD"),
|
|
1446
|
+
options: makeSseFn("OPTIONS"),
|
|
1447
|
+
patch: makeSseFn("PATCH"),
|
|
1448
|
+
post: makeSseFn("POST"),
|
|
1449
|
+
put: makeSseFn("PUT"),
|
|
1450
|
+
trace: makeSseFn("TRACE")
|
|
1451
|
+
},
|
|
1452
|
+
trace: makeMethodFn("TRACE")
|
|
1453
|
+
};
|
|
1454
|
+
};
|
|
1455
|
+
//#endregion
|
|
1456
|
+
//#region ../../api-clients/fluidos/src/hey-api-client.ts
|
|
1457
|
+
function isAbortError(error) {
|
|
1458
|
+
return error instanceof DOMException && error.name === "AbortError" || error instanceof Error && error.name === "AbortError";
|
|
1459
|
+
}
|
|
1460
|
+
function createFluidOsHeyApiClient(config) {
|
|
1461
|
+
const client = createClient({
|
|
1462
|
+
auth: async () => await config.getAuthToken?.() ?? void 0,
|
|
1463
|
+
baseUrl: config.baseUrl,
|
|
1464
|
+
fetch: config.fetch,
|
|
1465
|
+
headers: {
|
|
1466
|
+
Accept: "application/json",
|
|
1467
|
+
...config.defaultHeaders
|
|
1468
|
+
},
|
|
1469
|
+
throwOnError: true
|
|
1470
|
+
});
|
|
1471
|
+
client.interceptors.error.use(createHeyApiErrorInterceptor({
|
|
1472
|
+
onResponseError: (response) => {
|
|
1473
|
+
if (response.status === 401) config.onAuthError?.();
|
|
1474
|
+
},
|
|
1475
|
+
shouldPassThroughTransportError: isAbortError
|
|
1476
|
+
}));
|
|
1477
|
+
return client;
|
|
1478
|
+
}
|
|
1479
|
+
//#endregion
|
|
979
1480
|
//#region src/utils/auth-client.ts
|
|
980
1481
|
function createAuthenticatedClient() {
|
|
981
1482
|
return { client: createAuthenticatedWidgetPackageClient() };
|
|
@@ -986,7 +1487,7 @@ function createAuthenticatedWidgetPackageClient() {
|
|
|
986
1487
|
if (!profileName) throw new Error("Not logged in. Run " + chalk.cyan("fluid login") + " first.");
|
|
987
1488
|
throw new Error("No auth token found for profile " + chalk.cyan(profileName) + ". Run " + chalk.cyan("fluid login") + " to re-authenticate.");
|
|
988
1489
|
}
|
|
989
|
-
return
|
|
1490
|
+
return createFluidOsHeyApiClient({
|
|
990
1491
|
baseUrl: profile?.baseUrl ?? process.env["FLUID_API_BASE"] ?? "https://api.fluid.app",
|
|
991
1492
|
getAuthToken: () => token
|
|
992
1493
|
});
|
|
@@ -1678,6 +2179,10 @@ async function gitAutoCommit(cwd, message, identity = DEFAULT_COMMIT_IDENTITY) {
|
|
|
1678
2179
|
}
|
|
1679
2180
|
//#endregion
|
|
1680
2181
|
//#region src/utils/git-credential.ts
|
|
2182
|
+
function unwrapResponseData(response) {
|
|
2183
|
+
if (response !== null && typeof response === "object" && "data" in response && !("git_credential" in response)) return response.data;
|
|
2184
|
+
return response;
|
|
2185
|
+
}
|
|
1681
2186
|
/**
|
|
1682
2187
|
* Mint a git credential for a widget package.
|
|
1683
2188
|
*
|
|
@@ -1690,8 +2195,13 @@ async function gitAutoCommit(cwd, message, identity = DEFAULT_COMMIT_IDENTITY) {
|
|
|
1690
2195
|
* decide whether to degrade gracefully (see `isGitSyncUnavailable`).
|
|
1691
2196
|
*/
|
|
1692
2197
|
async function mintWidgetGitCredential(options) {
|
|
1693
|
-
const
|
|
1694
|
-
|
|
2198
|
+
const response = unwrapResponseData(options.droplet ? await options.client.post({
|
|
2199
|
+
responseStyle: "data",
|
|
2200
|
+
url: `/api/droplets/${encodeURIComponent(options.droplet)}/widget_package/git_credential`
|
|
2201
|
+
}) : await fluidOsV0WidgetPackageGitCredentialCreate({
|
|
2202
|
+
client: options.client,
|
|
2203
|
+
responseStyle: "data"
|
|
2204
|
+
}));
|
|
1695
2205
|
const remoteUrl = response?.git_credential?.remote_url;
|
|
1696
2206
|
if (typeof remoteUrl !== "string" || remoteUrl.length === 0) throw new Error("The git credential response did not include a remote URL. Update the Fluid CLI, or contact support if this persists.");
|
|
1697
2207
|
const expiresAtRaw = response.git_credential?.expires_at;
|
|
@@ -2170,10 +2680,18 @@ async function promptForDroplet(client) {
|
|
|
2170
2680
|
}
|
|
2171
2681
|
async function listDroplets(client) {
|
|
2172
2682
|
try {
|
|
2173
|
-
const firstResponse = await client.get(
|
|
2683
|
+
const firstResponse = await client.get({
|
|
2684
|
+
query: { page: 1 },
|
|
2685
|
+
responseStyle: "data",
|
|
2686
|
+
url: "/api/droplets"
|
|
2687
|
+
});
|
|
2174
2688
|
const totalPages = Math.min(readTotalPages(firstResponse) ?? 1, MAX_DROPLET_PAGES);
|
|
2175
2689
|
const responses = [firstResponse];
|
|
2176
|
-
for (let page = 2; page <= totalPages; page += 1) responses.push(await client.get(
|
|
2690
|
+
for (let page = 2; page <= totalPages; page += 1) responses.push(await client.get({
|
|
2691
|
+
query: { page },
|
|
2692
|
+
responseStyle: "data",
|
|
2693
|
+
url: "/api/droplets"
|
|
2694
|
+
}));
|
|
2177
2695
|
return responses.flatMap(normalizeDropletsResponse);
|
|
2178
2696
|
} catch (err) {
|
|
2179
2697
|
if (isApiLikeError(err)) {
|
|
@@ -2270,10 +2788,17 @@ const linkCommand = new Command("link").description("Link this widget project to
|
|
|
2270
2788
|
//#endregion
|
|
2271
2789
|
//#region src/utils/droplet-api.ts
|
|
2272
2790
|
async function fetchDropletWidgetStatus(options) {
|
|
2273
|
-
return extractArray(await options.client.get(
|
|
2791
|
+
return extractArray(await options.client.get({
|
|
2792
|
+
responseStyle: "data",
|
|
2793
|
+
url: `/api/droplets/${encodeURIComponent(options.droplet)}/widget_package_versions`
|
|
2794
|
+
})).map(normalizeVersionSummary);
|
|
2274
2795
|
}
|
|
2275
2796
|
async function fetchDropletWidgetLogs(options) {
|
|
2276
|
-
return extractArray(await options.client.get(
|
|
2797
|
+
return extractArray(await options.client.get({
|
|
2798
|
+
query: options.limit ? { limit: options.limit } : void 0,
|
|
2799
|
+
responseStyle: "data",
|
|
2800
|
+
url: `/api/droplets/${encodeURIComponent(options.droplet)}/widget_package_versions/logs`
|
|
2801
|
+
})).map(normalizeLogEntry);
|
|
2277
2802
|
}
|
|
2278
2803
|
function formatStatusRows(versions) {
|
|
2279
2804
|
if (versions.length === 0) return "No widget package versions found.";
|
|
@@ -2530,7 +3055,10 @@ function str(value) {
|
|
|
2530
3055
|
return null;
|
|
2531
3056
|
}
|
|
2532
3057
|
async function fetchCurrentUser(client) {
|
|
2533
|
-
const raw = await client.get(
|
|
3058
|
+
const raw = await client.get({
|
|
3059
|
+
responseStyle: "data",
|
|
3060
|
+
url: "/api/me"
|
|
3061
|
+
});
|
|
2534
3062
|
const composed = [str(raw.first_name), str(raw.last_name)].filter((part) => part !== null).join(" ").trim();
|
|
2535
3063
|
const idValue = str(raw.public_id) ?? (typeof raw.id === "number" && Number.isFinite(raw.id) ? String(raw.id) : null);
|
|
2536
3064
|
return {
|