Read existing Client catalogs through verified workspace context

This commit is contained in:
khondokartowsif171
2026-10-19 01:34:52 +06:00
parent 6db99f96df
commit 165320cc9f
10 changed files with 189 additions and 17 deletions
+5 -2
View File
@@ -42,7 +42,7 @@ function readJson(request, maxBytes) {
});
}
function createApiHandler({ resolveWorkspace, store, scrape, imageHandler, publicOrigin, maxBodyBytes = 32768, maxConcurrentImports = 1, maxImportsPerMinute = 5 }) {
function createApiHandler({ resolveWorkspace, store, scrape, imageHandler, getConnected, publicOrigin, maxBodyBytes = 32768, maxConcurrentImports = 1, maxImportsPerMinute = 5 }) {
const configured = new URL(publicOrigin);
if (!['http:', 'https:'].includes(configured.protocol) || configured.pathname !== '/' || configured.search || configured.hash || configured.username || configured.password) {
throw new Error('A public Studio origin without path or credentials is required');
@@ -92,11 +92,14 @@ function createApiHandler({ resolveWorkspace, store, scrape, imageHandler, publi
return await imageHandler(request, response, workspace);
}
if (request.method === 'GET') {
return sendJson(response, 200, { success: true, stores: (await store.read(workspace)).map(record => browserStore(record, workspace)), workspace: publicWorkspace });
const records = await store.read(workspace);
if (getConnected) records.unshift(await getConnected(workspace));
return sendJson(response, 200, { success: true, stores: records.map(record => browserStore(record, workspace)), workspace: publicWorkspace });
}
requireProductWrite(workspace);
const body = await readJson(request, maxBodyBytes);
if (pathname === '/api/delete-synced-store') {
if (typeof body.storeId === 'string' && body.storeId.startsWith('connected:')) throw fail(403, 'CONNECTED_CATALOG_READ_ONLY', 'Connected catalog মূল Client dashboard থেকে পরিচালনা করুন।');
if (typeof body.storeId !== 'string' || !body.storeId || body.storeId.length > 160) throw fail(400, 'INVALID_STORE_ID', 'সঠিক store নির্বাচন করুন।');
return sendJson(response, 200, { success: true, stores: (await store.remove(workspace, body.storeId)).map(record => browserStore(record, workspace)) });
}