Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(plugins): check updates without GitHub REST quota

tianma-if2b3646f6093c
diff --git a/apps/api/src/plugin-distribution-routes.test.mjs b/apps/api/src/plugin-distribution-routes.test.mjs
index a8921dbd..d6673f7f 100644
--- a/apps/api/src/plugin-distribution-routes.test.mjs
+++ b/apps/api/src/plugin-distribution-routes.test.mjs
@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test";
import {
downloadGithubReleaseAsset,
downloadGithubReleaseAssetByTag,
+ readGithubLatestReleaseManifestText,
readGithubReleaseByTag,
readGithubRepositoryManifestText,
} from "./plugin-distribution-routes.ts";
@@ -107,6 +108,92 @@ describe("GitHub plugin release asset proxy", () => {
})).rejects.toThrow("Invalid GitHub release coordinates");
});
+ test("falls back to raw.githubusercontent.com when the GitHub REST API rate-limits the instance", async () => {
+ const calls = [];
+ const text = await readGithubRepositoryManifestText({
+ owner: "example",
+ repository: "edgeever-plugin",
+ request: async (input) => {
+ const url = String(input);
+ calls.push(url);
+ if (url.includes("api.github.com")) return new Response("rate limited", { status: 403 });
+ if (url === "https://raw.githubusercontent.com/example/edgeever-plugin/HEAD/manifest.json") {
+ return new Response("{\"version\":\"0.4.1\"}");
+ }
+ return new Response("missing", { status: 404 });
+ },
+ });
+ expect(text).toBe("{\"version\":\"0.4.1\"}");
+ expect(calls[0]).toContain("/contents/manifest.json");
+ expect(calls).toContain("https://raw.githubusercontent.com/example/edgeever-plugin/HEAD/manifest.json");
+ });
+
+ test("reads the latest GitHub Release manifest without using the REST API", async () => {
+ const calls = [];
+ const text = await readGithubLatestReleaseManifestText({
+ owner: "example",
+ repository: "edgeever-plugin",
+ request: async (input) => {
+ calls.push(String(input));
+ if (String(input).endsWith("/releases/latest/download/manifest.json")) {
+ return new Response("{\"version\":\"0.4.1\"}");
+ }
+ throw new Error(String(input));
+ },
+ });
+ expect(text).toBe("{\"version\":\"0.4.1\"}");
+ expect(calls).toEqual([
+ "https://github.com/example/edgeever-plugin/releases/latest/download/manifest.json",
+ ]);
+ });
+
+ test("falls back to the latest-release API when the public download URL fails", async () => {
+ const calls = [];
+ const text = await readGithubLatestReleaseManifestText({
+ owner: "example",
+ repository: "edgeever-plugin",
+ request: async (input) => {
+ const url = String(input);
+ calls.push(url);
+ if (url.endsWith("/releases/latest/download/manifest.json")) {
+ return new Response("missing", { status: 404 });
+ }
+ if (url.endsWith("/releases/latest")) {
+ return Response.json({ tag_name: "v0.4.1" });
+ }
+ if (url.endsWith("/releases/download/v0.4.1/manifest.json")) {
+ return new Response("{\"version\":\"0.4.1\"}", { headers: { "content-length": "19" } });
+ }
+ throw new Error(url);
+ },
+ });
+ expect(text).toBe("{\"version\":\"0.4.1\"}");
+ expect(calls[0]).toBe("https://github.com/example/edgeever-plugin/releases/latest/download/manifest.json");
+ expect(calls).toContain("https://api.github.com/repos/example/edgeever-plugin/releases/latest");
+ });
+
+ test("falls back to raw.githubusercontent.com when latest-release lookup is rate-limited", async () => {
+ const calls = [];
+ const text = await readGithubLatestReleaseManifestText({
+ owner: "example",
+ repository: "edgeever-plugin",
+ request: async (input) => {
+ const url = String(input);
+ calls.push(url);
+ if (url.includes("api.github.com") || url.includes("/releases/latest/download/")) {
+ return new Response("rate limited", { status: 403 });
+ }
+ if (url === "https://raw.githubusercontent.com/example/edgeever-plugin/HEAD/manifest.json") {
+ return new Response("{\"version\":\"0.4.1\"}");
+ }
+ return new Response("missing", { status: 404 });
+ },
+ });
+ expect(text).toBe("{\"version\":\"0.4.1\"}");
+ expect(calls[0]).toBe("https://github.com/example/edgeever-plugin/releases/latest/download/manifest.json");
+ expect(calls).toContain("https://raw.githubusercontent.com/example/edgeever-plugin/HEAD/manifest.json");
+ });
+
test("reads the raw repository manifest for live official plugin resolution", async () => {
const text = await readGithubRepositoryManifestText({
owner: "example",
diff --git a/apps/api/src/plugin-distribution-routes.ts b/apps/api/src/plugin-distribution-routes.ts
index da5c9719..b1891a02 100644
--- a/apps/api/src/plugin-distribution-routes.ts
+++ b/apps/api/src/plugin-distribution-routes.ts
@@ -82,7 +82,23 @@ export const readGithubRepositoryManifestText = async ({
},
});
if (response.status === 404) throw new GithubUpstreamError("Repository manifest was not found.", 404);
- if (!response.ok) throw new Error(`Repository manifest request failed with HTTP ${response.status}.`);
+ if (!response.ok) {
+ if (response.status === 403 || response.status === 429) {
+ for (const ref of ["HEAD", "main", "master"] as const) {
+ const raw = await request(`https://raw.githubusercontent.com/${owner}/${repository}/${ref}/manifest.json`, {
+ headers: { "User-Agent": "EdgeEver" },
+ });
+ if (raw.ok) {
+ const text = await raw.text();
+ if (new TextEncoder().encode(text).byteLength > ASSET_LIMITS["manifest.json"]) {
+ throw new Error("manifest.json exceeds the allowed package size.");
+ }
+ return text;
+ }
+ }
+ }
+ throw new Error(`Repository manifest request failed with HTTP ${response.status}.`);
+ }
const text = await response.text();
if (new TextEncoder().encode(text).byteLength > ASSET_LIMITS["manifest.json"]) {
throw new Error("manifest.json exceeds the allowed package size.");
@@ -90,6 +106,69 @@ export const readGithubRepositoryManifestText = async ({
return text;
};
+const assertManifestSize = (text: string) => {
+ if (new TextEncoder().encode(text).byteLength > ASSET_LIMITS["manifest.json"]) {
+ throw new Error("manifest.json exceeds the allowed package size.");
+ }
+ return text;
+};
+
+const isRetriableGithubLookupError = (error: unknown) => {
+ if (error instanceof GithubUpstreamError) return false;
+ return error instanceof Error && !error.message.includes("exceeds the allowed package size");
+};
+
+export const readGithubLatestReleaseManifestText = async ({
+ owner,
+ repository,
+ request = fetch,
+}: {
+ owner: string;
+ repository: string;
+ request?: typeof fetch;
+}) => {
+ if (!hasValidRepositoryCoordinates(owner, repository)) throw new Error("Invalid GitHub repository coordinates.");
+ try {
+ const response = await request(
+ `https://github.com/${owner}/${repository}/releases/latest/download/manifest.json`,
+ {
+ redirect: "follow",
+ headers: { "User-Agent": "EdgeEver" },
+ },
+ );
+ if (response.ok) return assertManifestSize(await response.text());
+ } catch (error) {
+ if (!isRetriableGithubLookupError(error)) throw error;
+ }
+
+ try {
+ const response = await request(`https://api.github.com/repos/${owner}/${repository}/releases/latest`, {
+ headers: {
+ Accept: "application/vnd.github+json",
+ "User-Agent": "EdgeEver",
+ "X-GitHub-Api-Version": GITHUB_API_VERSION,
+ },
+ });
+ if (response.ok) {
+ const release = await response.json() as { tag_name?: unknown };
+ if (typeof release.tag_name === "string" && RELEASE_TAG_PATTERN.test(release.tag_name)) {
+ const buffer = await downloadGithubReleaseAssetByTag({
+ owner,
+ repository,
+ releaseTag: release.tag_name,
+ assetName: "manifest.json",
+ request,
+ });
+ return assertManifestSize(new TextDecoder().decode(buffer));
+ }
+ }
+ } catch (error) {
+ if (!isRetriableGithubLookupError(error)) throw error;
+ }
+
+ return readGithubRepositoryManifestText({ owner, repository, request });
+};
+
export const readGithubReleaseByTag = async ({
owner,
repository,
@@ -195,19 +274,68 @@ export const downloadGithubReleaseAssetByTag = async ({
}
};
+const PLUGIN_MANIFEST_CACHE_TTL_MS = 300_000;
+const PLUGIN_MANIFEST_CACHE_LIMIT = 64;
+const pluginManifestMemoryCache = new Map<string, { text: string; expiresAt: number }>();
+
+const readCachedPluginManifest = (key: string) => {
+ const entry = pluginManifestMemoryCache.get(key);
+ if (!entry) return null;
+ if (entry.expiresAt <= Date.now()) {
+ pluginManifestMemoryCache.delete(key);
+ return null;
+ }
+ return entry.text;
+};
+
+const writeCachedPluginManifest = (key: string, text: string) => {
+ if (pluginManifestMemoryCache.size >= PLUGIN_MANIFEST_CACHE_LIMIT) {
+ const oldest = pluginManifestMemoryCache.keys().next().value;
+ if (typeof oldest === "string") pluginManifestMemoryCache.delete(oldest);
+ }
+ pluginManifestMemoryCache.set(key, { text, expiresAt: Date.now() + PLUGIN_MANIFEST_CACHE_TTL_MS });
+};
+
+const respondWithGithubManifestText = (
+ context: { text: (body: string, status: number, headers: Record<string, string>) => Response },
+ text: string,
+) => context.text(text, 200, {
+ "Cache-Control": "private, max-age=300",
+ "Content-Type": "application/json; charset=utf-8",
+});
+
export const registerPluginDistributionRoutes = (app: Hono<AppEnv>) => {
+ app.get("/api/v1/plugins/github/:owner/:repository/latest-manifest", async (context) => {
+ const owner = context.req.param("owner");
+ const repository = context.req.param("repository");
+ if (!hasValidRepositoryCoordinates(owner, repository)) {
+ return badRequest(context, "Invalid GitHub repository coordinates.");
+ }
+ const cacheKey = `latest:${owner}/${repository}`;
+ const cached = readCachedPluginManifest(cacheKey);
+ if (cached) return respondWithGithubManifestText(context, cached);
+ try {
+ const text = await readGithubLatestReleaseManifestText({ owner, repository });
+ writeCachedPluginManifest(cacheKey, text);
+ return respondWithGithubManifestText(context, text);
+ } catch (error) {
+ return githubUpstreamError(context, error);
+ }
+ });
+
app.get("/api/v1/plugins/github/:owner/:repository/manifest", async (context) => {
const owner = context.req.param("owner");
const repository = context.req.param("repository");
if (!hasValidRepositoryCoordinates(owner, repository)) {
return badRequest(context, "Invalid GitHub repository coordinates.");
}
+ const cacheKey = `branch:${owner}/${repository}`;
+ const cached = readCachedPluginManifest(cacheKey);
+ if (cached) return respondWithGithubManifestText(context, cached);
try {
const text = await readGithubRepositoryManifestText({ owner, repository });
- return context.text(text, 200, {
- "Cache-Control": "private, max-age=60",
- "Content-Type": "application/json; charset=utf-8",
- });
+ writeCachedPluginManifest(cacheKey, text);
+ return respondWithGithubManifestText(context, text);
} catch (error) {
return githubUpstreamError(context, error);
}
diff --git a/apps/web/src/components/settings/PluginManagerCard.test.mjs b/apps/web/src/components/settings/PluginManagerCard.test.mjs
index 35057855..530903c3 100644
--- a/apps/web/src/components/settings/PluginManagerCard.test.mjs
+++ b/apps/web/src/components/settings/PluginManagerCard.test.mjs
@@ -24,6 +24,11 @@ describe("plugin manager card layout", () => {
expect(source).not.toContain("{snapshot.extensions.length > 0 ? (\n <Button");
});
+ test("does not treat a single plugin update error as a total check failure", () => {
+ expect(source).toContain("checkErrors.length === snapshot.extensions.length");
+ expect(source).not.toContain("refreshedMarketplace.data?.resolutionErrors ?? {}");
+ });
+
test("shows a retryable error instead of silently hiding a failed marketplace", () => {
expect(source).toContain("marketplaceQuery.isError");
expect(source).toContain('t("plugins.marketplace.loadFailed"');
diff --git a/apps/web/src/components/settings/PluginManagerCard.tsx b/apps/web/src/components/settings/PluginManagerCard.tsx
index 7c8f13be..c64c1f4f 100644
--- a/apps/web/src/components/settings/PluginManagerCard.tsx
+++ b/apps/web/src/components/settings/PluginManagerCard.tsx
@@ -377,12 +377,11 @@ export const PluginManagerCard = ({
["plugin-updates", extensionVersionKey, refreshedMarketplace.data?.updatedAt ?? "unavailable"],
result,
);
- const firstCheckError = Object.values({
- ...(refreshedMarketplace.data?.resolutionErrors ?? {}),
- ...result.errors,
- })[0];
- setLastManualCheckCount(firstCheckError ? null : result.updates.length);
- if (firstCheckError) setError(t("plugins.updates.checkFailed", { message: firstCheckError }));
+ setLastManualCheckCount(result.updates.length);
+ const checkErrors = Object.values(result.errors);
+ if (checkErrors.length > 0 && checkErrors.length === snapshot.extensions.length) {
+ setError(t("plugins.updates.checkFailed", { message: checkErrors[0] }));
+ }
} catch (checkError) {
setError(checkError instanceof Error ? checkError.message : String(checkError));
} finally {
diff --git a/apps/web/src/lib/plugins/github-plugin-distribution.test.mjs b/apps/web/src/lib/plugins/github-plugin-distribution.test.mjs
index 5fd48ba2..5d202fe2 100644
--- a/apps/web/src/lib/plugins/github-plugin-distribution.test.mjs
+++ b/apps/web/src/lib/plugins/github-plugin-distribution.test.mjs
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
-import { downloadGithubExtension, downloadPinnedGithubExtension, parseGithubRepositoryUrl } from "./github-plugin-distribution.ts";
+import { downloadGithubExtension, downloadPinnedGithubExtension, loadGithubInstallableManifest, loadGithubRepositoryManifest, parseGithubRepositoryUrl } from "./github-plugin-distribution.ts";
const manifest = {
type: "plugin",
@@ -102,6 +102,66 @@ describe("GitHub plugin distribution", () => {
.rejects.toThrow("does not match the repository manifest");
});
+ test("reads an installable plugin from the latest GitHub Release without using the REST API", async () => {
+ const calls = [];
+ const request = async (input) => {
+ const url = String(input);
+ calls.push(url);
+ if (url.includes("api.github.com")) throw new Error(`should not use GitHub REST: ${url}`);
+ if (url === "https://github.com/example/edgeever-plugin/releases/latest/download/manifest.json") {
+ return new Response(JSON.stringify(manifest));
+ }
+ throw new Error(`Unexpected request: ${url}`);
+ };
+
+ const loaded = await loadGithubInstallableManifest("https://github.com/example/edgeever-plugin", request);
+
+ expect(loaded.manifest.version).toBe("1.2.3");
+ expect(calls).toEqual([
+ "https://github.com/example/edgeever-plugin/releases/latest/download/manifest.json",
+ ]);
+ });
+
+ test("falls back to raw GitHub when the latest Release download is rate-limited", async () => {
+ const calls = [];
+ const request = async (input) => {
+ const url = String(input);
+ calls.push(url);
+ if (url.includes("api.github.com")) throw new Error(`should not use GitHub REST: ${url}`);
+ if (url.includes("/releases/latest/download/manifest.json")) {
+ return new Response("rate limited", { status: 403 });
+ }
+ if (url === "https://raw.githubusercontent.com/example/edgeever-plugin/HEAD/manifest.json") {
+ return new Response(JSON.stringify(manifest));
+ }
+ throw new Error(`Unexpected request: ${url}`);
+ };
+
+ const loaded = await loadGithubInstallableManifest("https://github.com/example/edgeever-plugin", request);
+
+ expect(loaded.manifest.version).toBe("1.2.3");
+ expect(calls).toContain("https://raw.githubusercontent.com/example/edgeever-plugin/HEAD/manifest.json");
+ expect(calls.some((url) => url.includes("api.github.com"))).toBe(false);
+ });
+
+ test("reads the repository manifest from raw GitHub when the REST API rate-limits the browser", async () => {
+ const calls = [];
+ const request = async (input) => {
+ const url = String(input);
+ calls.push(url);
+ if (url.includes("/contents/manifest.json")) return new Response("rate limited", { status: 403 });
+ if (url === "https://raw.githubusercontent.com/example/edgeever-plugin/HEAD/manifest.json") {
+ return new Response(JSON.stringify(manifest));
+ }
+ throw new Error(`Unexpected request: ${url}`);
+ };
+
+ const loaded = await loadGithubRepositoryManifest("https://github.com/example/edgeever-plugin", request);
+
+ expect(loaded.manifest.version).toBe("1.2.3");
+ expect(calls).toContain("https://raw.githubusercontent.com/example/edgeever-plugin/HEAD/manifest.json");
+ });
+
test("explains a renderer network failure instead of showing Failed to fetch", async () => {
const request = async () => {
throw new TypeError("Failed to fetch");
diff --git a/apps/web/src/lib/plugins/github-plugin-distribution.ts b/apps/web/src/lib/plugins/github-plugin-distribution.ts
index 0e2668d9..249e7162 100644
--- a/apps/web/src/lib/plugins/github-plugin-distribution.ts
+++ b/apps/web/src/lib/plugins/github-plugin-distribution.ts
@@ -73,6 +73,8 @@ const isGithubUnreachableError = (error: unknown) => {
return error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
};
+const isGithubRateLimitedStatus = (status: number) => status === 403 || status === 429;
+
const isMissingGithubAssetError = (error: unknown) => {
const message = error instanceof Error ? error.message : String(error);
return /HTTP 404/i.test(message);
@@ -109,21 +111,50 @@ const readGithubApi = async (
url: string,
headers: Record<string, string>,
) => {
+ const throughInstance = async () => {
+ try {
+ return await fetchGithubMetadataThroughInstance(url);
+ } catch {
+ throw new Error(GITHUB_UNREACHABLE_MESSAGE);
+ }
+ };
try {
- return await request(url, {
+ const response = await request(url, {
cache: "no-store",
credentials: "omit",
headers,
signal: AbortSignal.timeout(GITHUB_API_TIMEOUT_MS),
});
+ if (isGithubRateLimitedStatus(response.status) || response.status === 401) {
+ try {
+ return await throughInstance();
+ } catch {
+ return response;
+ }
+ }
+ return response;
} catch (error) {
if (!isGithubUnreachableError(error)) throw error;
+ return throughInstance();
+ }
+};
+
+const readRawGithubManifest = async (
+ request: typeof fetch,
+ coordinates: GithubRepositoryCoordinates,
+) => {
+ for (const ref of ["HEAD", "main", "master"]) {
try {
- return await fetchGithubMetadataThroughInstance(url);
- } catch {
- throw new Error(GITHUB_UNREACHABLE_MESSAGE);
+ const response = await request(
+ `https://raw.githubusercontent.com/${coordinates.owner}/${coordinates.repository}/${ref}/manifest.json`,
+ { cache: "no-store", credentials: "omit", signal: AbortSignal.timeout(GITHUB_API_TIMEOUT_MS) },
+ );
+ if (response.ok) return response;
+ } catch (error) {
+ if (!isGithubUnreachableError(error)) throw error;
}
}
+ return null;
};
const namedReleaseAsset = (name: string): GithubReleaseAsset => ({
@@ -238,6 +269,17 @@ const assertBundledEntry = (manifest: PluginManifest) => {
if (entryPath !== "main.js") throw new Error("GitHub plugins must use ./main.js as the bundled entry.");
};
+const parseGithubManifestText = (
+ coordinates: GithubRepositoryCoordinates,
+ manifestText: string,
+ manifestUrl: string,
+): GithubRepositoryManifest => ({
+ manifest: parseExtensionManifest(JSON.parse(manifestText) as unknown),
+ manifestText,
+ manifestUrl,
+ repositoryUrl: coordinates.repositoryUrl,
+});
+
export const loadGithubRepositoryManifest = async (
input: string,
request: typeof fetch = window.fetch.bind(window),
@@ -245,19 +287,75 @@ export const loadGithubRepositoryManifest = async (
const coordinates = parseGithubRepositoryUrl(input);
if (!coordinates) throw new Error("Enter a public GitHub repository URL such as https://github.com/owner/repository.");
const manifestUrl = `https://api.github.com/repos/${coordinates.owner}/${coordinates.repository}/contents/manifest.json`;
- const manifestResponse = await readGithubApi(
+ let manifestResponse = await readGithubApi(
request,
manifestUrl,
{ Accept: "application/vnd.github.raw+json", "X-GitHub-Api-Version": GITHUB_API_VERSION },
);
+ if (!manifestResponse.ok) {
+ manifestResponse = await readRawGithubManifest(request, coordinates)
+ ?? (isGithubRateLimitedStatus(manifestResponse.status)
+ ? await fetchGithubMetadataThroughInstance(manifestUrl).catch(() => manifestResponse)
+ : manifestResponse);
+ }
if (!manifestResponse.ok) throw new Error(`Repository manifest request failed with HTTP ${manifestResponse.status}.`);
- const manifestText = await manifestResponse.text();
- return {
- manifest: parseExtensionManifest(JSON.parse(manifestText) as unknown),
- manifestText,
- manifestUrl,
- repositoryUrl: coordinates.repositoryUrl,
- };
+ return parseGithubManifestText(coordinates, await manifestResponse.text(), manifestUrl);
+};
+
+export const loadGithubInstallableManifest = async (
+ input: string,
+ request: typeof fetch = window.fetch.bind(window),
+): Promise<GithubRepositoryManifest> => {
+ const coordinates = parseGithubRepositoryUrl(input);
+ if (!coordinates) throw new Error("Enter a public GitHub repository URL such as https://github.com/owner/repository.");
+ const latestUrl = `https://github.com/${coordinates.owner}/${coordinates.repository}/releases/latest/download/manifest.json`;
+ let lastStatus: number | null = null;
+
+ try {
+ const manifestText = await api.getGithubPluginLatestManifest(coordinates.owner, coordinates.repository);
+ if (manifestText.trim().length > 0) {
+ return parseGithubManifestText(coordinates, manifestText, latestUrl);
+ }
+ } catch {
+ // Instance may be down, unauthenticated in tests, or itself rate-limited by GitHub.
+ }
+
+ try {
+ const response = await request(latestUrl, {
+ cache: "no-store",
+ credentials: "omit",
+ redirect: "follow",
+ signal: AbortSignal.timeout(GITHUB_API_TIMEOUT_MS),
+ });
+ lastStatus = response.status;
+ if (response.ok) {
+ const manifestText = await response.text();
+ if (manifestText.trim().length > 0) {
+ return parseGithubManifestText(coordinates, manifestText, latestUrl);
+ }
+ }
+ } catch (error) {
+ if (!isGithubUnreachableError(error)) throw error;
+ }
+
+ const rawResponse = await readRawGithubManifest(request, coordinates);
+ if (rawResponse?.ok) {
+ const manifestText = await rawResponse.text();
+ if (manifestText.trim().length > 0) {
+ return parseGithubManifestText(
+ coordinates,
+ manifestText,
+ rawResponse.url || `https://raw.githubusercontent.com/${coordinates.owner}/${coordinates.repository}/HEAD/manifest.json`,
+ );
+ }
+ }
+ lastStatus = rawResponse?.status ?? lastStatus;
+
+ throw new Error(
+ lastStatus
+ ? `Latest GitHub plugin release request failed with HTTP ${lastStatus}.`
+ : "Could not read the latest GitHub plugin release from this device or your EdgeEver instance.",
+ );
};
export const downloadGithubExtension = async (
diff --git a/apps/web/src/lib/plugins/plugin-marketplace.test.mjs b/apps/web/src/lib/plugins/plugin-marketplace.test.mjs
index 25832076..d58e9e75 100644
--- a/apps/web/src/lib/plugins/plugin-marketplace.test.mjs
+++ b/apps/web/src/lib/plugins/plugin-marketplace.test.mjs
@@ -90,7 +90,9 @@ describe("bundled plugin marketplace", () => {
};
const request = async (input) => {
const url = String(input);
- if (url.includes("/contents/manifest.json")) return new Response(manifestText);
+ if (url.includes("/releases/latest/download/manifest.json") || url.includes("/contents/manifest.json")) {
+ return new Response(manifestText);
+ }
if (url.includes("/releases/tags/")) return Response.json({
tag_name: "v0.5.3",
draft: false,
@@ -138,7 +140,7 @@ describe("bundled plugin marketplace", () => {
const calls = [];
const request = async (input) => {
calls.push(String(input));
- if (String(input).includes("/contents/manifest.json")) {
+ if (String(input).includes("/releases/latest/download/manifest.json")) {
return new Response(JSON.stringify({
type: "plugin",
id: "org.edgeever.plugins.ai-rss",
diff --git a/apps/web/src/lib/plugins/plugin-marketplace.ts b/apps/web/src/lib/plugins/plugin-marketplace.ts
index a9b2ba11..4a58abf6 100644
--- a/apps/web/src/lib/plugins/plugin-marketplace.ts
+++ b/apps/web/src/lib/plugins/plugin-marketplace.ts
@@ -1,7 +1,7 @@
import { parseMarketplaceRegistry, type MarketplaceEntry, type MarketplaceRegistry } from "@edgeever/plugin-api";
import {
downloadGithubExtension,
- loadGithubRepositoryManifest,
+ loadGithubInstallableManifest,
type GithubAssetDownloader,
} from "@/lib/plugins/github-plugin-distribution";
import { isVersionOutdated } from "@/lib/version-check";
@@ -31,7 +31,7 @@ const resolveOfficialGithubEntry = async (
downloadAssetBytes?: GithubAssetDownloader,
): Promise<MarketplaceEntry> => {
if (entry.publisher !== "edgeever" || entry.distribution.type !== "github") return entry;
- const live = await loadGithubRepositoryManifest(entry.distribution.repositoryUrl, request);
+ const live = await loadGithubInstallableManifest(entry.distribution.repositoryUrl, request);
if (live.manifest.id !== entry.id) {
throw new Error("Official repository manifest id does not match the marketplace entry.");
}
diff --git a/apps/web/src/lib/plugins/plugin-updates.test.mjs b/apps/web/src/lib/plugins/plugin-updates.test.mjs
index 7eca61b4..ce3b1c50 100644
--- a/apps/web/src/lib/plugins/plugin-updates.test.mjs
+++ b/apps/web/src/lib/plugins/plugin-updates.test.mjs
@@ -58,6 +58,30 @@ describe("plugin update checks", () => {
expect(update?.marketplaceEntry).toEqual(entry);
});
+ test("checks GitHub-installed plugins from the latest Release without using the REST API", async () => {
+ const calls = [];
+ const request = async (input) => {
+ const url = String(input);
+ calls.push(url);
+ if (url.includes("api.github.com")) throw new Error(`should not use GitHub REST: ${url}`);
+ if (url.endsWith("/releases/latest/download/manifest.json")) {
+ return new Response(JSON.stringify({ ...pluginManifest, version: "1.2.0" }));
+ }
+ throw new Error(`Unexpected request: ${url}`);
+ };
+
+ const update = await checkInstalledExtensionUpdate(
+ installed({
+ source: { kind: "github", verified: false, repositoryUrl: "https://github.com/example/plugin" },
+ }),
+ [],
+ request,
+ );
+
+ expect(update?.latestVersion).toBe("1.2.0");
+ expect(calls.some((url) => url.includes("api.github.com"))).toBe(false);
+ });
+
test("does not offer the same or an older version", async () => {
const request = async () => Response.json(pluginManifest);
expect(await checkInstalledExtensionUpdate(installed(), [], request)).toBeNull();
diff --git a/apps/web/src/lib/plugins/plugin-updates.ts b/apps/web/src/lib/plugins/plugin-updates.ts
index e72696f6..cf3fec07 100644
--- a/apps/web/src/lib/plugins/plugin-updates.ts
+++ b/apps/web/src/lib/plugins/plugin-updates.ts
@@ -1,6 +1,6 @@
import { parseExtensionManifest, type ExtensionManifest, type MarketplaceEntry, type PluginPermission } from "@edgeever/plugin-api";
import type { InstalledExtension } from "@/lib/plugins/plugin-host";
-import { loadGithubRepositoryManifest } from "@/lib/plugins/github-plugin-distribution";
+import { loadGithubInstallableManifest } from "@/lib/plugins/github-plugin-distribution";
import { isVersionOutdated } from "@/lib/version-check";
export interface PluginUpdateInfo {
@@ -31,7 +31,7 @@ const fetchManifest = async (url: string, request: typeof fetch) => {
const loadMarketplaceManifest = async (entry: MarketplaceEntry, request: typeof fetch) => {
if (entry.distribution.type === "github") {
- return (await loadGithubRepositoryManifest(entry.distribution.repositoryUrl, request)).manifest;
+ return (await loadGithubInstallableManifest(entry.distribution.repositoryUrl, request)).manifest;
}
return fetchManifest(entry.distribution.manifestUrl, request);
};
@@ -64,7 +64,7 @@ export const checkInstalledExtensionUpdate = async (
}
} else if (extension.source.kind === "github") {
if (!extension.source.repositoryUrl) throw new Error("Installed GitHub extension is missing its repository URL.");
- latestManifest = (await loadGithubRepositoryManifest(extension.source.repositoryUrl, request)).manifest;
+ latestManifest = (await loadGithubInstallableManifest(extension.source.repositoryUrl, request)).manifest;
} else {
latestManifest = await fetchManifest(extension.manifestUrl, request);
}
diff --git a/packages/client/src/index.test.mjs b/packages/client/src/index.test.mjs
index 51c6791b..2f544630 100644
--- a/packages/client/src/index.test.mjs
+++ b/packages/client/src/index.test.mjs
@@ -199,12 +199,14 @@ describe("EdgeEver client HTTP contract", () => {
fetch: async (input) => {
const url = String(input);
calls.push(url);
+ if (url.endsWith("/latest-manifest")) return new Response("{\"id\":\"plugin\",\"version\":\"1.2.3\"}");
if (url.endsWith("/manifest")) return new Response("{\"id\":\"plugin\"}");
if (url.includes("/releases/tags/missing")) return new Response(null, { status: 404 });
return Response.json({ tag_name: "v1.2.3", draft: false, assets: [] });
},
});
+ expect(await client.getGithubPluginLatestManifest("example-owner", "example-plugin")).toBe("{\"id\":\"plugin\",\"version\":\"1.2.3\"}");
expect(await client.getGithubPluginRepositoryManifest("example-owner", "example-plugin")).toBe("{\"id\":\"plugin\"}");
expect(await client.getGithubPluginRelease("example-owner", "example-plugin", "missing")).toBeNull();
expect(await client.getGithubPluginRelease("example-owner", "example-plugin", "v1.2.3")).toEqual({
@@ -213,6 +215,7 @@ describe("EdgeEver client HTTP contract", () => {
assets: [],
});
expect(calls).toEqual([
+ "/api/v1/plugins/github/example-owner/example-plugin/latest-manifest",
"/api/v1/plugins/github/example-owner/example-plugin/manifest",
"/api/v1/plugins/github/example-owner/example-plugin/releases/tags/missing",
"/api/v1/plugins/github/example-owner/example-plugin/releases/tags/v1.2.3",
diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts
index 01a66673..66332b06 100644
--- a/packages/client/src/index.ts
+++ b/packages/client/src/index.ts
@@ -1254,6 +1254,13 @@ export const createEdgeEverClient = (options: EdgeEverClientOptions = {}) => {
return response.text();
},
+ getGithubPluginLatestManifest: async (owner: string, repository: string) => {
+ const path = `/api/v1/plugins/github/${encodeURIComponent(owner)}/${encodeURIComponent(repository)}/latest-manifest`;
+ const { context, response } = await send(path, undefined, { setJsonContentType: false });
+ if (!response.ok) await throwRequestError(context, response, "GitHub plugin latest-release manifest request failed");
+ return response.text();
+ },
+
getGithubPluginRelease: async (owner: string, repository: string, releaseTag: string) => {
const path = `/api/v1/plugins/github/${encodeURIComponent(owner)}/${encodeURIComponent(repository)}/releases/tags/${encodeURIComponent(releaseTag)}`;
const { context, response } = await send(path, undefined, { setJsonContentType: false });