@devrouter/cli 0.5.5 → 0.6.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/README.md +13 -2
- package/assets/preview/github-sweep.yml +23 -0
- package/assets/preview/github.yml +35 -0
- package/assets/preview/gitlab-template.yml +34 -0
- package/assets/preview/gitlab.yml +22 -0
- package/assets/preview/installation.json +54 -0
- package/bin/devrouter-process +29 -2
- package/dist/devrouter-lifecycle-worker.js +1554 -425
- package/dist/devrouter-preview-gitlab-ingress.js +182 -0
- package/dist/devrouter.js +9442 -2701
- package/package.json +11 -2
- package/upgrade-prompts/0.5.6.md +73 -0
- package/upgrade-prompts/0.6.0.md +57 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/core/preview/ingress/gitlab.ts
|
|
21
|
+
var gitlab_exports = {};
|
|
22
|
+
__export(gitlab_exports, {
|
|
23
|
+
createGitLabPreviewIngress: () => createGitLabPreviewIngress
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(gitlab_exports);
|
|
26
|
+
var import_node_crypto = require("crypto");
|
|
27
|
+
|
|
28
|
+
// src/core/preview/command.ts
|
|
29
|
+
var MAX_COMMAND_BYTES = 512;
|
|
30
|
+
var MAX_ALIAS_LENGTH = 63;
|
|
31
|
+
var ALIAS_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
32
|
+
function parsePreviewCommand(text) {
|
|
33
|
+
if (Buffer.byteLength(text, "utf8") > MAX_COMMAND_BYTES || /[\r\n]/u.test(text)) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const command = text.trim();
|
|
37
|
+
if (command === "/preview start") {
|
|
38
|
+
return { kind: "start", aliases: [] };
|
|
39
|
+
}
|
|
40
|
+
if (command.startsWith("/preview start ")) {
|
|
41
|
+
return parseStart(command.slice("/preview start ".length));
|
|
42
|
+
}
|
|
43
|
+
if (command === "/preview extend" || command === "/preview extend 1h") {
|
|
44
|
+
return { kind: "extend" };
|
|
45
|
+
}
|
|
46
|
+
if (command === "/preview stop") return { kind: "stop" };
|
|
47
|
+
if (command === "/preview status") return { kind: "status" };
|
|
48
|
+
if (command === "/preview profiles") return { kind: "profiles" };
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function isPreviewAlias(alias) {
|
|
52
|
+
return typeof alias === "string" && alias.length <= MAX_ALIAS_LENGTH && ALIAS_PATTERN.test(alias);
|
|
53
|
+
}
|
|
54
|
+
function parseStart(rawAliases) {
|
|
55
|
+
const aliases = rawAliases.split(",");
|
|
56
|
+
if (aliases.some((alias) => !isPreviewAlias(alias)) || new Set(aliases).size !== aliases.length) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return { kind: "start", aliases };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/core/preview/http.ts
|
|
63
|
+
var MAX_STATE_BYTES = 1024 * 1024;
|
|
64
|
+
async function readPreviewResponse(response, label, maxBytes = MAX_STATE_BYTES) {
|
|
65
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > 16 * MAX_STATE_BYTES)
|
|
66
|
+
throw new Error("Invalid response size bound.");
|
|
67
|
+
const length = response.headers.get("content-length");
|
|
68
|
+
if (length !== null && (!/^\d+$/.test(length) || Number(length) > maxBytes)) {
|
|
69
|
+
await response.body?.cancel();
|
|
70
|
+
throw new Error(`${label} response exceeds its size bound.`);
|
|
71
|
+
}
|
|
72
|
+
const reader = response.body?.getReader();
|
|
73
|
+
if (!reader) throw new Error(`${label} response is empty.`);
|
|
74
|
+
const chunks = [];
|
|
75
|
+
let size = 0;
|
|
76
|
+
try {
|
|
77
|
+
for (; ; ) {
|
|
78
|
+
const { done, value } = await reader.read();
|
|
79
|
+
if (done) break;
|
|
80
|
+
size += value.byteLength;
|
|
81
|
+
if (size > maxBytes) throw new Error(`${label} response exceeds its size bound.`);
|
|
82
|
+
chunks.push(value);
|
|
83
|
+
}
|
|
84
|
+
} finally {
|
|
85
|
+
await reader.cancel();
|
|
86
|
+
}
|
|
87
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/core/preview/forge/status.ts
|
|
91
|
+
function forgeObject(value) {
|
|
92
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
93
|
+
throw new Error("Invalid forge object.");
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
function forgeId(value) {
|
|
97
|
+
const id = typeof value === "number" && Number.isSafeInteger(value) ? String(value) : value;
|
|
98
|
+
if (typeof id !== "string" || !/^[1-9][0-9]{0,19}$/.test(id))
|
|
99
|
+
throw new Error("Invalid forge numeric identity.");
|
|
100
|
+
return id;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/core/preview/ingress/gitlab.ts
|
|
104
|
+
function createGitLabPreviewIngress(options) {
|
|
105
|
+
const base = new URL(options.apiUrl);
|
|
106
|
+
if (base.protocol !== "https:" || base.username || base.password || base.search || base.hash || base.port || base.pathname !== "/api/v4/" || !/^[A-Za-z0-9_./-]{1,128}$/.test(options.controllerRef) || options.controllerRef.includes("..") || !/^[a-z][a-z0-9-]{0,62}$/.test(options.installedProjectKey))
|
|
107
|
+
throw new Error("Invalid registered GitLab ingress policy.");
|
|
108
|
+
forgeId(options.controllerProjectId);
|
|
109
|
+
forgeId(options.candidateProjectId);
|
|
110
|
+
return async (request) => {
|
|
111
|
+
if (request.method !== "POST") return new Response(null, { status: 405 });
|
|
112
|
+
let secret;
|
|
113
|
+
try {
|
|
114
|
+
secret = await options.hookSecret();
|
|
115
|
+
} catch {
|
|
116
|
+
return new Response(null, { status: 503 });
|
|
117
|
+
}
|
|
118
|
+
const presented = request.headers.get("x-gitlab-token") ?? "";
|
|
119
|
+
if (secret.length < 32 || secret.length > 256 || presented.length > 256 || Buffer.byteLength(secret) !== Buffer.byteLength(presented) || !(0, import_node_crypto.timingSafeEqual)(Buffer.from(secret), Buffer.from(presented)))
|
|
120
|
+
return new Response(null, { status: 401 });
|
|
121
|
+
if (request.headers.get("content-type")?.split(";")[0] !== "application/json")
|
|
122
|
+
return new Response(null, { status: 415 });
|
|
123
|
+
if (request.headers.get("x-gitlab-event") !== "Note Hook" || !/^[a-f0-9-]{36}$/i.test(request.headers.get("x-gitlab-event-uuid") ?? ""))
|
|
124
|
+
return new Response(null, { status: 400 });
|
|
125
|
+
let payload;
|
|
126
|
+
try {
|
|
127
|
+
payload = forgeObject(
|
|
128
|
+
JSON.parse(await readPreviewResponse(new Response(request.body), "GitLab hook", 64 * 1024))
|
|
129
|
+
);
|
|
130
|
+
} catch {
|
|
131
|
+
return new Response(null, { status: 400 });
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
if (payload.object_kind !== "note") return new Response(null, { status: 204 });
|
|
135
|
+
const note = forgeObject(payload.object_attributes);
|
|
136
|
+
if (note.noteable_type !== "MergeRequest") return new Response(null, { status: 204 });
|
|
137
|
+
const merge = forgeObject(payload.merge_request), project = forgeObject(payload.project);
|
|
138
|
+
if (forgeId(project.id) !== options.candidateProjectId || forgeId(note.project_id) !== options.candidateProjectId || note.action !== "create" || note.system !== false || note.created_at !== note.updated_at || note.line_code || typeof note.note !== "string" || !parsePreviewCommand(note.note) || merge.target_project_id !== Number(options.candidateProjectId) || merge.source_project_id !== Number(options.candidateProjectId))
|
|
139
|
+
return new Response(null, { status: 204 });
|
|
140
|
+
const change = forgeId(merge.iid);
|
|
141
|
+
forgeId(note.id);
|
|
142
|
+
let token;
|
|
143
|
+
try {
|
|
144
|
+
token = await options.triggerToken();
|
|
145
|
+
} catch {
|
|
146
|
+
return new Response(null, { status: 503 });
|
|
147
|
+
}
|
|
148
|
+
if (!token || /\s/.test(token)) return new Response(null, { status: 503 });
|
|
149
|
+
let response;
|
|
150
|
+
try {
|
|
151
|
+
response = await (options.fetch ?? fetch)(
|
|
152
|
+
new URL(`projects/${options.controllerProjectId}/trigger/pipeline`, base),
|
|
153
|
+
{
|
|
154
|
+
method: "POST",
|
|
155
|
+
redirect: "error",
|
|
156
|
+
signal: AbortSignal.timeout(1e4),
|
|
157
|
+
headers: { "Content-Type": "application/json" },
|
|
158
|
+
body: JSON.stringify({
|
|
159
|
+
token,
|
|
160
|
+
ref: options.controllerRef,
|
|
161
|
+
inputs: {
|
|
162
|
+
preview_mode: "handle-event",
|
|
163
|
+
preview_project: options.installedProjectKey,
|
|
164
|
+
preview_change: change
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
} catch {
|
|
170
|
+
return new Response(null, { status: 503 });
|
|
171
|
+
}
|
|
172
|
+
await response.body?.cancel();
|
|
173
|
+
return new Response(null, { status: response.ok ? 202 : 503 });
|
|
174
|
+
} catch {
|
|
175
|
+
return new Response(null, { status: 400 });
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
180
|
+
0 && (module.exports = {
|
|
181
|
+
createGitLabPreviewIngress
|
|
182
|
+
});
|