@dotcms/create-app 26.9.3-1-next.2649 → 26.9.9-1
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/index.js +164 -113
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -9,6 +9,170 @@ import fs6 from "fs-extra";
|
|
|
9
9
|
import ora from "ora";
|
|
10
10
|
import path8 from "path";
|
|
11
11
|
|
|
12
|
+
// libs/http/src/lib/fetch-retry.ts
|
|
13
|
+
function isSuccessStatus(status) {
|
|
14
|
+
return status >= 200 && status < 300;
|
|
15
|
+
}
|
|
16
|
+
function describeRequestFailure(error) {
|
|
17
|
+
if (isHttpError(error)) {
|
|
18
|
+
if (error.code === "ECONNREFUSED") {
|
|
19
|
+
return "Connection refused - service not accepting connections yet";
|
|
20
|
+
}
|
|
21
|
+
if (error.code === "ETIMEDOUT") {
|
|
22
|
+
return "Connection timeout - service too slow or not responding";
|
|
23
|
+
}
|
|
24
|
+
if (error.code === "ENOTFOUND") {
|
|
25
|
+
return "Host not found (DNS lookup failed)";
|
|
26
|
+
}
|
|
27
|
+
if (error.code === "ECONNRESET") {
|
|
28
|
+
return "Connection reset by the server";
|
|
29
|
+
}
|
|
30
|
+
if (error.code === "CERT_HAS_EXPIRED") {
|
|
31
|
+
return "TLS certificate has expired";
|
|
32
|
+
}
|
|
33
|
+
if (error.code === "DEPTH_ZERO_SELF_SIGNED_CERT" || error.code === "SELF_SIGNED_CERT_IN_CHAIN") {
|
|
34
|
+
return "TLS certificate is self-signed and not trusted";
|
|
35
|
+
}
|
|
36
|
+
if (error.response) {
|
|
37
|
+
return `HTTP ${error.response.status}: ${error.response.statusText}`;
|
|
38
|
+
}
|
|
39
|
+
return error.code || error.message;
|
|
40
|
+
}
|
|
41
|
+
if (error instanceof Error) {
|
|
42
|
+
return error.message;
|
|
43
|
+
}
|
|
44
|
+
return String(error);
|
|
45
|
+
}
|
|
46
|
+
function formatRetryReport({
|
|
47
|
+
attempt,
|
|
48
|
+
totalAttempts,
|
|
49
|
+
reason,
|
|
50
|
+
nextDelayMs
|
|
51
|
+
}) {
|
|
52
|
+
return `dotCMS not ready (attempt ${attempt}/${totalAttempts}) - ${reason} - retrying in ${Math.round(nextDelayMs / 1e3)}s`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// libs/http/src/lib/http.ts
|
|
56
|
+
var HttpError = class extends Error {
|
|
57
|
+
constructor(message, init) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.name = "HttpError";
|
|
60
|
+
this.status = init.status ?? null;
|
|
61
|
+
this.code = init.code;
|
|
62
|
+
if (typeof init.status === "number") {
|
|
63
|
+
this.response = { status: init.status, statusText: init.statusText ?? "" };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
function isHttpError(error) {
|
|
68
|
+
return error instanceof HttpError;
|
|
69
|
+
}
|
|
70
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
71
|
+
var MAX_BODY_BYTES = 10 * 1024 * 1024;
|
|
72
|
+
async function readBody(response, url) {
|
|
73
|
+
const tooLarge = () => new HttpError(`Response from ${url} is too large (over ${MAX_BODY_BYTES} bytes)`, {
|
|
74
|
+
status: response.status,
|
|
75
|
+
code: "EBODYTOOLARGE"
|
|
76
|
+
});
|
|
77
|
+
const declared = Number(response.headers.get("content-length"));
|
|
78
|
+
if (Number.isFinite(declared) && declared > MAX_BODY_BYTES)
|
|
79
|
+
throw tooLarge();
|
|
80
|
+
let text = "";
|
|
81
|
+
if (!response.body) {
|
|
82
|
+
text = await response.text().catch(() => "");
|
|
83
|
+
} else {
|
|
84
|
+
const reader = response.body.getReader();
|
|
85
|
+
const decoder = new TextDecoder();
|
|
86
|
+
let size = 0;
|
|
87
|
+
for (; ; ) {
|
|
88
|
+
const { done, value } = await reader.read();
|
|
89
|
+
if (done)
|
|
90
|
+
break;
|
|
91
|
+
if (!value)
|
|
92
|
+
continue;
|
|
93
|
+
size += value.byteLength;
|
|
94
|
+
if (size > MAX_BODY_BYTES) {
|
|
95
|
+
await reader.cancel().catch(() => void 0);
|
|
96
|
+
throw tooLarge();
|
|
97
|
+
}
|
|
98
|
+
text += decoder.decode(value, { stream: true });
|
|
99
|
+
}
|
|
100
|
+
text += decoder.decode();
|
|
101
|
+
}
|
|
102
|
+
if (!text) {
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
return JSON.parse(text);
|
|
107
|
+
} catch {
|
|
108
|
+
return text;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function request(url, init, { token, timeoutMs = DEFAULT_TIMEOUT_MS, acceptAnyStatus = false }) {
|
|
112
|
+
const controller = new AbortController();
|
|
113
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
114
|
+
const headers = new Headers(init.headers);
|
|
115
|
+
if (token) {
|
|
116
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
117
|
+
}
|
|
118
|
+
let response;
|
|
119
|
+
try {
|
|
120
|
+
try {
|
|
121
|
+
response = await fetch(url, { ...init, headers, signal: controller.signal });
|
|
122
|
+
} catch (error) {
|
|
123
|
+
const aborted = error?.name === "AbortError";
|
|
124
|
+
const cause = error?.cause;
|
|
125
|
+
throw new HttpError(
|
|
126
|
+
aborted ? `Request to ${url} timed out after ${timeoutMs}ms` : `Request to ${url} failed: ${error?.message ?? String(error)}`,
|
|
127
|
+
{ status: null, code: aborted ? "ETIMEDOUT" : cause?.code }
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
let data;
|
|
131
|
+
try {
|
|
132
|
+
data = await readBody(response, url);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (isHttpError(error))
|
|
135
|
+
throw error;
|
|
136
|
+
const aborted = error?.name === "AbortError";
|
|
137
|
+
throw new HttpError(
|
|
138
|
+
aborted ? `Request to ${url} timed out after ${timeoutMs}ms while reading the response` : `Reading the response from ${url} failed: ${error?.message ?? String(error)}`,
|
|
139
|
+
{ status: response.status, code: aborted ? "ETIMEDOUT" : void 0 }
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
if (!isSuccessStatus(response.status) && !acceptAnyStatus) {
|
|
143
|
+
throw new HttpError(`Request failed with status code ${response.status}`, {
|
|
144
|
+
status: response.status,
|
|
145
|
+
statusText: response.statusText
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return { status: response.status, data };
|
|
149
|
+
} finally {
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function httpGet(url, options = {}) {
|
|
154
|
+
return request(url, { method: "GET" }, options);
|
|
155
|
+
}
|
|
156
|
+
function httpPost(url, body, options = {}) {
|
|
157
|
+
return request(
|
|
158
|
+
url,
|
|
159
|
+
{
|
|
160
|
+
method: "POST",
|
|
161
|
+
body: JSON.stringify(body),
|
|
162
|
+
headers: { "Content-Type": "application/json" }
|
|
163
|
+
},
|
|
164
|
+
options
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// libs/http/src/lib/result.ts
|
|
169
|
+
function Ok(val) {
|
|
170
|
+
return { ok: true, val };
|
|
171
|
+
}
|
|
172
|
+
function Err(val) {
|
|
173
|
+
return { ok: false, val };
|
|
174
|
+
}
|
|
175
|
+
|
|
12
176
|
// libs/sdk/create-app/src/api/index.ts
|
|
13
177
|
import chalk from "chalk";
|
|
14
178
|
|
|
@@ -175,88 +339,6 @@ var FailedToGetDefaultSiteError = class extends Error {
|
|
|
175
339
|
}
|
|
176
340
|
};
|
|
177
341
|
|
|
178
|
-
// libs/sdk/create-app/src/result.ts
|
|
179
|
-
function Ok(val) {
|
|
180
|
-
return { ok: true, val };
|
|
181
|
-
}
|
|
182
|
-
function Err(val) {
|
|
183
|
-
return { ok: false, val };
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// libs/sdk/create-app/src/utils/http.ts
|
|
187
|
-
var HttpError = class extends Error {
|
|
188
|
-
constructor(message, init) {
|
|
189
|
-
super(message);
|
|
190
|
-
this.name = "HttpError";
|
|
191
|
-
this.status = init.status ?? null;
|
|
192
|
-
this.code = init.code;
|
|
193
|
-
if (typeof init.status === "number") {
|
|
194
|
-
this.response = { status: init.status, statusText: init.statusText ?? "" };
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
function isHttpError(error) {
|
|
199
|
-
return error instanceof HttpError;
|
|
200
|
-
}
|
|
201
|
-
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
202
|
-
function isSuccess(status) {
|
|
203
|
-
return status >= 200 && status < 300;
|
|
204
|
-
}
|
|
205
|
-
async function readBody(response) {
|
|
206
|
-
const text = await response.text().catch(() => "");
|
|
207
|
-
if (!text) {
|
|
208
|
-
return void 0;
|
|
209
|
-
}
|
|
210
|
-
try {
|
|
211
|
-
return JSON.parse(text);
|
|
212
|
-
} catch {
|
|
213
|
-
return text;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
async function request(url, init, { token, timeoutMs = DEFAULT_TIMEOUT_MS, acceptAnyStatus = false }) {
|
|
217
|
-
const controller = new AbortController();
|
|
218
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
219
|
-
const headers = new Headers(init.headers);
|
|
220
|
-
if (token) {
|
|
221
|
-
headers.set("Authorization", `Bearer ${token}`);
|
|
222
|
-
}
|
|
223
|
-
let response;
|
|
224
|
-
try {
|
|
225
|
-
response = await fetch(url, { ...init, headers, signal: controller.signal });
|
|
226
|
-
} catch (error) {
|
|
227
|
-
const aborted = error?.name === "AbortError";
|
|
228
|
-
const cause = error?.cause;
|
|
229
|
-
throw new HttpError(
|
|
230
|
-
aborted ? `Request to ${url} timed out after ${timeoutMs}ms` : `Request to ${url} failed: ${error?.message ?? String(error)}`,
|
|
231
|
-
{ status: null, code: aborted ? "ETIMEDOUT" : cause?.code }
|
|
232
|
-
);
|
|
233
|
-
} finally {
|
|
234
|
-
clearTimeout(timer);
|
|
235
|
-
}
|
|
236
|
-
const data = await readBody(response);
|
|
237
|
-
if (!isSuccess(response.status) && !acceptAnyStatus) {
|
|
238
|
-
throw new HttpError(`Request failed with status code ${response.status}`, {
|
|
239
|
-
status: response.status,
|
|
240
|
-
statusText: response.statusText
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
return { status: response.status, data };
|
|
244
|
-
}
|
|
245
|
-
function httpGet(url, options = {}) {
|
|
246
|
-
return request(url, { method: "GET" }, options);
|
|
247
|
-
}
|
|
248
|
-
function httpPost(url, body, options = {}) {
|
|
249
|
-
return request(
|
|
250
|
-
url,
|
|
251
|
-
{
|
|
252
|
-
method: "POST",
|
|
253
|
-
body: JSON.stringify(body),
|
|
254
|
-
headers: { "Content-Type": "application/json" }
|
|
255
|
-
},
|
|
256
|
-
options
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
342
|
// libs/sdk/create-app/src/api/index.ts
|
|
261
343
|
function getSafeErrorDetails(err) {
|
|
262
344
|
if (isHttpError(err)) {
|
|
@@ -708,37 +790,6 @@ import { execa } from "execa";
|
|
|
708
790
|
import net from "net";
|
|
709
791
|
import path3 from "path";
|
|
710
792
|
|
|
711
|
-
// libs/sdk/create-app/src/utils/fetch-retry.ts
|
|
712
|
-
function isSuccessStatus(status) {
|
|
713
|
-
return status >= 200 && status < 300;
|
|
714
|
-
}
|
|
715
|
-
function describeRequestFailure(error) {
|
|
716
|
-
if (isHttpError(error)) {
|
|
717
|
-
if (error.code === "ECONNREFUSED") {
|
|
718
|
-
return "Connection refused - service not accepting connections yet";
|
|
719
|
-
}
|
|
720
|
-
if (error.code === "ETIMEDOUT") {
|
|
721
|
-
return "Connection timeout - service too slow or not responding";
|
|
722
|
-
}
|
|
723
|
-
if (error.response) {
|
|
724
|
-
return `HTTP ${error.response.status}: ${error.response.statusText}`;
|
|
725
|
-
}
|
|
726
|
-
return error.code || error.message;
|
|
727
|
-
}
|
|
728
|
-
if (error instanceof Error) {
|
|
729
|
-
return error.message;
|
|
730
|
-
}
|
|
731
|
-
return String(error);
|
|
732
|
-
}
|
|
733
|
-
function formatRetryReport({
|
|
734
|
-
attempt,
|
|
735
|
-
totalAttempts,
|
|
736
|
-
reason,
|
|
737
|
-
nextDelayMs
|
|
738
|
-
}) {
|
|
739
|
-
return `dotCMS not ready (attempt ${attempt}/${totalAttempts}) - ${reason} - retrying in ${Math.round(nextDelayMs / 1e3)}s`;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
793
|
// libs/sdk/create-app/src/utils/ports.ts
|
|
743
794
|
var DOTCMS_HTTP_PORT = 8082;
|
|
744
795
|
var REQUIRED_PORTS = [
|