Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions scripts/lib/kyasi-library.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Client for the federated product library at kyasi.us
* Reads are public. Writes need KYASI_LIBRARY_TOKEN (ADMIN_API_TOKEN).
* Reads and writes require KYASI_LIBRARY_TOKEN (ADMIN_API_TOKEN on kyasi-net).
*/
const DEFAULT_BASE =
process.env.KYASI_LIBRARY_URL || "https://kyasi.us";
Expand All @@ -27,10 +27,11 @@ async function req(path, opts = {}) {
headers["Content-Type"] = "application/json";
}
const token = libraryToken();
if (opts.auth) {
// All library APIs are auth-gated (session or Bearer). Machine clients use Bearer.
if (opts.auth !== false) {
if (!token) {
throw new Error(
"KYASI_LIBRARY_TOKEN (or ADMIN_API_TOKEN) required for library writes",
"KYASI_LIBRARY_TOKEN (or ADMIN_API_TOKEN) required for library access",
);
}
headers.Authorization = `Bearer ${token}`;
Expand Down Expand Up @@ -138,5 +139,5 @@ export async function linkSiteItem(input) {
}

export async function health() {
return req("/api/health");
return req("/api/health", { auth: false });
}
7 changes: 6 additions & 1 deletion worker/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,14 @@ export async function handleAdmin(
// Always this site: admin panel is site-local (ibamboo), not a network hub.
const siteId = 'ibamboo'
try {
// Site-filtered list only — never call network-wide /api/stats here.
// Site-filtered list only. kyasi.us reads require Bearer or operator session.
const headers: Record<string, string> = { Accept: 'application/json' }
if (env.LIBRARY_TOKEN) {
headers.Authorization = `Bearer ${env.LIBRARY_TOKEN}`
}
const itemsRes = await fetch(
`${base}/api/library/items?site=${encodeURIComponent(siteId)}&limit=100`,
{ headers },
)
const itemsPayload = (await itemsRes.json()) as {
items?: unknown[]
Expand Down
Loading