| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import fs from 'node:fs';
- import path from 'node:path';
- import { request, invoke } from '../server/scripts/platform-client.mjs';
- const out = path.resolve('work/noodle-innovation-20261108-r1');
- const classes = ['KfCategory', 'KfCategoryRelation', 'KfProduct', 'KfSku', 'KfMaterial',
- 'KfProcess', 'KfProcessStep', 'KfStandard', 'KfSupplier', 'KfSupplyQuote', 'KfRetailPriceSnapshot'];
- const save = (name, data) => fs.writeFileSync(path.join(out, name), JSON.stringify(data, null, 2) + '\n');
- fs.mkdirSync(out, { recursive: true });
- try {
- const schema = await request('GET', '/schemas');
- const tables = schema.results.filter(t => classes.includes(t.className) || t.className === 'KfSource');
- save('live-schema.json', tables);
- const contract = await invoke('ksfGetIngestContract', { requestId: 'noodle-innovation-audit-20261108-r1' });
- if (contract.http !== 200 || !contract.body.result?.ok) throw Error('CONTRACT_READ_FAILED');
- save('ingest-contract.json', contract.body.result.data);
- const results = [];
- for (const name of classes) {
- let last, total, rows = [];
- for (let page = 0; page < 100; page++) {
- const where = { dataMode: { $ne: 'sample' }, ...(last ? { objectId: { $gt: last } } : {}) };
- const query = new URLSearchParams({ where: JSON.stringify(where), limit: '100', order: 'objectId', count: '1' });
- const batch = await request('GET', '/classes/' + name + '?' + query);
- if (total === undefined) total = batch.count;
- rows.push(...batch.results);
- if (batch.results.length < 100) break;
- last = batch.results.at(-1).objectId;
- }
- if (rows.length !== total || new Set(rows.map(r => r.objectId)).size !== total) throw Error('PAGINATION_MISMATCH');
- save(name + '.json', rows);
- results.push({ className: name, nonSampleRecords: total,
- modes: Object.fromEntries([...new Set(rows.map(r => r.dataMode || 'unspecified'))].map(m => [m, rows.filter(r => (r.dataMode || 'unspecified') === m).length])) });
- }
- const sourceIds = new Set(classes.flatMap(name => JSON.parse(fs.readFileSync(path.join(out, name + '.json'), 'utf8')).map(r => r.sourceRef?.objectId).filter(Boolean)));
- const sources = [];
- for (const id of sourceIds) sources.push(await request('GET', '/classes/KfSource/' + id));
- save('linked-sources.json', sources);
- const summary = { checkedAt: new Date().toISOString(), classes: results, linkedSources: sources.length, readOnly: true, databaseWrites: 0, paidCalls: 0 };
- save('parse-audit.json', summary);
- console.log(JSON.stringify(summary));
- } catch {
- console.error(JSON.stringify({ ok: false, code: 'NOODLE_AUDIT_FAILED', diagnostic: 'No credentials or raw exceptions printed.' }));
- process.exitCode = 1;
- }
|