Keep Studio business branding in verified client storage

This commit is contained in:
khondokartowsif171
2026-10-19 11:54:13 +06:00
parent 165320cc9f
commit 54091f4578
11 changed files with 151 additions and 38 deletions
+11 -2
View File
@@ -1,4 +1,5 @@
const { fail, requireProductWrite } = require('./workspace.cjs');
const { normalizeBrand } = require('./brand.cjs');
function sendJson(response, status, value) {
if (response.destroyed || response.writableEnded) return;
@@ -78,7 +79,7 @@ function createApiHandler({ resolveWorkspace, store, scrape, imageHandler, getCo
try {
const pathname = new URL(request.url, origin).pathname;
const routes = {
'/api/workspace': 'GET', '/api/catalog-image': 'GET',
'/api/workspace': 'GET', '/api/brand': 'POST', '/api/catalog-image': 'GET',
'/api/get-synced-stores': 'GET', '/api/sync-store': 'POST', '/api/delete-synced-store': 'POST'
};
if (!routes[pathname]) return sendJson(response, 404, { success: false, code: 'NOT_FOUND', error: 'API পাওয়া যায়নি।' });
@@ -86,7 +87,10 @@ function createApiHandler({ resolveWorkspace, store, scrape, imageHandler, getCo
if (request.method === 'POST') writeOrigin(request);
const workspace = await resolveWorkspace(request);
const publicWorkspace = { clientId: workspace.clientId, name: workspace.displayName, tenant: workspace.tenant, canWriteProducts: workspace.canWriteProducts };
if (pathname === '/api/workspace') return sendJson(response, 200, { success: true, workspace: publicWorkspace });
if (pathname === '/api/workspace') {
publicWorkspace.brand = normalizeBrand(await store.readBrand(workspace) || {}, workspace.displayName);
return sendJson(response, 200, { success: true, workspace: publicWorkspace });
}
if (pathname === '/api/catalog-image') {
if (!imageHandler) throw fail(503, 'IMAGE_UNAVAILABLE', 'Product image এখন পাওয়া যাচ্ছে না।');
return await imageHandler(request, response, workspace);
@@ -98,6 +102,11 @@ function createApiHandler({ resolveWorkspace, store, scrape, imageHandler, getCo
}
requireProductWrite(workspace);
const body = await readJson(request, maxBodyBytes);
if (pathname === '/api/brand') {
const brand = normalizeBrand(body, workspace.displayName);
await store.saveBrand(workspace, brand);
return sendJson(response, 200, { success: true, brand });
}
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 নির্বাচন করুন।');