dsh-plugin-update 0.3.1 → 0.4.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/CHANGELOG.md +11 -0
- package/README.md +51 -8
- package/dist/client.d.ts +4 -4
- package/dist/client.js +2 -1
- package/dist/config.d.ts +4 -1
- package/dist/config.js +8 -1
- package/dist/entry.d.ts +6 -0
- package/dist/entry.js +36 -4
- package/dist/host.d.ts +4 -4
- package/dist/host.js +77 -6
- package/dist/http.d.ts +2 -2
- package/dist/http.js +3 -2
- package/dist/panel-batch.d.ts +9 -0
- package/dist/panel-batch.js +113 -7
- package/dist/panel.d.ts +14 -1
- package/dist/panel.js +141 -16
- package/dist/service.d.ts +14 -0
- package/dist/service.js +50 -0
- package/package.json +1 -1
package/dist/service.js
CHANGED
|
@@ -226,6 +226,55 @@ async function fetchNpmRelease(fetchImpl, timeoutMs = CHECK_TIMEOUT_MS, opts) {
|
|
|
226
226
|
throw checkFailedWithStatus(response);
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
+
async function fetchNpmVersionRelease(fetchImpl, timeoutMs = CHECK_TIMEOUT_MS, opts) {
|
|
230
|
+
const targetName = opts?.targetPackageName ?? PACKAGE_NAME;
|
|
231
|
+
const registry = opts?.registryUrl ?? NPM_REGISTRY;
|
|
232
|
+
const channel = opts?.releaseChannel === "prerelease" ? "prerelease" : "stable";
|
|
233
|
+
const version = opts?.version;
|
|
234
|
+
if (typeof version !== "string" || !validReleaseVersion(version) || !isVersionAllowedInChannel(version, channel)) {
|
|
235
|
+
throw updateError("invalid-release");
|
|
236
|
+
}
|
|
237
|
+
let response = null;
|
|
238
|
+
try {
|
|
239
|
+
response = await fetchImpl(`${registry}${encodeURIComponent(targetName)}/${encodeURIComponent(version)}`, {
|
|
240
|
+
headers: { accept: "application/json" },
|
|
241
|
+
redirect: "error",
|
|
242
|
+
signal: timeoutSignal(timeoutMs)
|
|
243
|
+
});
|
|
244
|
+
} catch {
|
|
245
|
+
throw updateError("check-failed");
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
if (!response.ok) throw checkFailedWithStatus(response);
|
|
249
|
+
const declared = Number(response.headers.get("content-length"));
|
|
250
|
+
if (Number.isFinite(declared) && declared > MAX_METADATA_BYTES) throw updateError("invalid-release");
|
|
251
|
+
const text = await response.text();
|
|
252
|
+
if (byteLength(text) > MAX_METADATA_BYTES) throw updateError("invalid-release");
|
|
253
|
+
const value = JSON.parse(text);
|
|
254
|
+
if (value.name !== targetName || value.version !== version || !isVersionAllowedInChannel(value.version, channel)) {
|
|
255
|
+
throw updateError("invalid-release");
|
|
256
|
+
}
|
|
257
|
+
const nodeRange = value.engines?.node;
|
|
258
|
+
if (nodeRange !== void 0 && typeof nodeRange !== "string") throw updateError("invalid-release");
|
|
259
|
+
const tarballText = value.dist?.tarball;
|
|
260
|
+
const integrity = value.dist?.integrity;
|
|
261
|
+
let tarball;
|
|
262
|
+
try {
|
|
263
|
+
tarball = new URL(String(tarballText));
|
|
264
|
+
} catch {
|
|
265
|
+
throw updateError("invalid-release");
|
|
266
|
+
}
|
|
267
|
+
const registryOrigin = new URL(registry).origin;
|
|
268
|
+
const shapeOk = tarball.origin === registryOrigin && !tarball.username && !tarball.password && !tarball.search && !tarball.hash && tarball.pathname === `/${targetName}/-/${targetName}-${version}.tgz` && typeof integrity === "string" && new RegExp(INTEGRITY_PATTERN).test(integrity);
|
|
269
|
+
if (!shapeOk) throw updateError("invalid-release");
|
|
270
|
+
return { version, nodeRange: typeof nodeRange === "string" ? nodeRange : "*", integrity, tarball: tarball.href };
|
|
271
|
+
} catch (error) {
|
|
272
|
+
if (error?.code === "check-failed") throw error;
|
|
273
|
+
if (error?.code === "invalid-release") throw error;
|
|
274
|
+
if (response !== null && response.ok) throw updateError("invalid-release");
|
|
275
|
+
throw checkFailedWithStatus(response);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
229
278
|
function createUpdateCore(ports) {
|
|
230
279
|
const checkTimeoutMs = ports.checkTimeoutMs ?? CHECK_TIMEOUT_MS;
|
|
231
280
|
const confirmationTtlMs = ports.confirmationTtlMs ?? CONFIRMATION_TTL_MS;
|
|
@@ -446,6 +495,7 @@ export {
|
|
|
446
495
|
compareVersions,
|
|
447
496
|
createUpdateCore,
|
|
448
497
|
fetchNpmRelease,
|
|
498
|
+
fetchNpmVersionRelease,
|
|
449
499
|
isPrereleaseVersion,
|
|
450
500
|
isVersionAllowedInChannel,
|
|
451
501
|
satisfiesNodeRange,
|