fixes
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/**
|
||||
* Admin orgs UI client — users + companies directory, staff roles, plan assign.
|
||||
* Admin orgs UI client — users + companies directory, staff roles, plan assign,
|
||||
* clone-catalog, and Fix A1 (`POST …/fix-catalog`).
|
||||
* Flash Fix A1: result.prompts / hashes / categories → flash.admin.fixA1Success.
|
||||
* Contract: docs/admin-roles-support/04-contract.md · Docs: 10-admin-orgs-ui.md
|
||||
*/
|
||||
import { api, ApiError } from "$lib/api";
|
||||
@@ -18,6 +20,8 @@ export const ADMIN_USERS_PATH = "/api/admin/users";
|
||||
export const ADMIN_COMPANIES_PATH = "/api/admin/companies";
|
||||
export const ADMIN_CLONE_CATALOG_PATH = (companyId: string) =>
|
||||
`${ADMIN_COMPANIES_PATH}/${encodeURIComponent(companyId)}/clone-catalog`;
|
||||
export const ADMIN_FIX_CATALOG_PATH = (companyId: string) =>
|
||||
`${ADMIN_COMPANIES_PATH}/${encodeURIComponent(companyId)}/fix-catalog`;
|
||||
export const ADMIN_STAFF_ROLE_PATH = (userId: string) =>
|
||||
`/api/admin/users/${encodeURIComponent(userId)}/staff-role`;
|
||||
|
||||
@@ -226,6 +230,56 @@ export async function cloneAdminCompanyCatalog(
|
||||
});
|
||||
}
|
||||
|
||||
export type FixCatalogResult = {
|
||||
company_id: string;
|
||||
company_name: string;
|
||||
a1_cohort?: boolean;
|
||||
category_attribute_orphans_removed?: number;
|
||||
category_attribute_links?: number;
|
||||
/** Alias of category_prompts_updated for flash.admin.fixA1Success {prompts}. */
|
||||
prompts?: number;
|
||||
category_prompts_updated?: number;
|
||||
product_enhance_languages?: number;
|
||||
/** Alias of weak_hashes_cleared for flash {hashes}. */
|
||||
hashes?: number;
|
||||
weak_hashes_cleared?: number;
|
||||
/** Alias of categories_backfilled for flash {categories}. */
|
||||
categories?: number;
|
||||
categories_backfilled?: number;
|
||||
attributes_sanitized?: number;
|
||||
products_scanned?: number;
|
||||
reprocess_needed_count?: number;
|
||||
reprocess_sample_raw_product_ids?: string[];
|
||||
};
|
||||
|
||||
export type FixCatalogResponse = {
|
||||
status: string;
|
||||
result: FixCatalogResult;
|
||||
note?: string;
|
||||
};
|
||||
|
||||
/** In-place Fix A1 / catalog hygiene. Never clears catalog; no mass reprocess. */
|
||||
export async function fixAdminCompanyCatalog(
|
||||
companyId: string,
|
||||
opts?: { backfillCategories?: boolean; reprocessSampleLimit?: number }
|
||||
): Promise<FixCatalogResponse> {
|
||||
const body: {
|
||||
confirm: true;
|
||||
backfill_categories?: boolean;
|
||||
reprocess_sample_limit?: number;
|
||||
} = { confirm: true };
|
||||
if (opts?.backfillCategories === false) {
|
||||
body.backfill_categories = false;
|
||||
}
|
||||
if (typeof opts?.reprocessSampleLimit === "number") {
|
||||
body.reprocess_sample_limit = opts.reprocessSampleLimit;
|
||||
}
|
||||
return api<FixCatalogResponse>(ADMIN_FIX_CATALOG_PATH(companyId), {
|
||||
method: "POST",
|
||||
body
|
||||
});
|
||||
}
|
||||
|
||||
export function isStaffRoleApiUnavailable(err: unknown): boolean {
|
||||
return err instanceof ApiError && (err.status === 404 || err.status === 501);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user