import { readFileSync } from 'node:fs';import { dirname,join,resolve } from 'node:path';import { fileURLToPath } from 'node:url';
const root=resolve(dirname(fileURLToPath(import.meta.url)),'..');const read=r=>readFileSync(join(root,r),'utf8');const failures=[];const assert=(c,m)=>{if(!c)failures.push(m)};
const pkg=JSON.parse(read('package.json'));assert(pkg.version==='1.39.0',`Paketversion ist ${pkg.version}`);const server=read('server.mjs');const catalog=read('app/modules/catalog.mjs');const kernel=read('app/kernel/platform-kernel.mjs');const frontend=read('public/app.js');assert(!frontend.includes('...state.currentListing,\n          ...payload'),'Frontend sendet unkontrolliertes Listing-Objekt an die native Allowlist');
for(const marker of ['registerListingsRoutes','registerInventoryRoutes','registerMediaRoutes','configureMediaModule'])assert(server.includes(marker),`Serverregistrierung fehlt: ${marker}`);
for(const legacy of ["app.post('/api/listings'","app.get('/api/listings'","app.get('/api/media-library'","app.get('/api/inventory/locations'","app.get('/api/trash'"])assert(!server.includes(legacy),`Legacy-Route verblieben: ${legacy}`);
for(const id of ['listings','inventory','media']){const manifest=JSON.parse(read(`app/modules/${id}/module.json`));assert(manifest.status==='native',`${id} ist nicht nativ`);assert(read(`app/modules/${id}/routes.mjs`).includes("owner:'vendoo."+id)||read(`app/modules/${id}/routes.mjs`).includes("owner: 'vendoo."+id),`${id}-Routenbesitzer fehlt`)}
for(const marker of ['createListingsModule','createInventoryModule','createMediaModule'])assert(catalog.includes(marker),`Katalog fehlt: ${marker}`);assert(!catalog.includes("'media', 'listings'"),'Media/Listings stehen noch in Legacy-Liste');
const listingService=read('app/modules/listings/service.mjs'),listingRoutes=read('app/modules/listings/routes.mjs'),inventoryService=read('app/modules/inventory/service.mjs'),mediaService=read('app/modules/media/service.mjs');
for(const marker of ['ALLOWED_FIELDS','Unbekanntes Artikelfeld','LISTING_TRASH_NOT_FOUND','sanitizeRichHtml'])assert(listingService.includes(marker),`Listing-Schutz fehlt: ${marker}`);for(const marker of ['validateResourceLock','listings.permanent-delete','listing.soft_deleted'])assert(listingRoutes.includes(marker),`Listing-Route fehlt: ${marker}`);for(const marker of ['Maximal 500 Artikel','Unbekanntes Lagerfeld','INVENTORY_LOCATION_INVALID'])assert(inventoryService.includes(marker),`Inventory-Schutz fehlt: ${marker}`);for(const marker of ['normalizePath','p.includes(\'..\')','referenced','protectedPaths','validateFavorite','validateDelete'])assert(mediaService.includes(marker),`Media-Schutz fehlt: ${marker}`);
for(const marker of ["policies.register('listings.permanent-delete'","policies.register('inventory.manage'","policies.register('media.delete'"])assert(kernel.includes(marker),`Policy fehlt: ${marker}`);
if(failures.length){console.error(`Catalog-&-Media-Gate 1.39.0 fehlgeschlagen (${failures.length}):`);failures.forEach(x=>console.error(`- ${x}`));process.exit(1)}console.log('Catalog-&-Media-Gate 1.39.0 erfolgreich: native Listings-, Inventory- und Media-Routen, Payload-Allowlist, Locking, Papierkorbgrenzen, Bulk-Limits und Medien-Referenzschutz geprüft.');
