@resolveio/server-lib 22.3.94 → 22.3.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "22.3.94",
3
+ "version": "22.3.95",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "package": "./build_package.sh",
@@ -1048,6 +1048,9 @@ function buildResolveIORunnerQaLiveDataSeederScript() {
1048
1048
  ' if (existing && extractBolIdentifiers().length && existing.selected && existing.selected.truck_treating_bol_context && !Object.prototype.hasOwnProperty.call(existing.selected.truck_treating_bol_context, "primary_bol_status")) {',
1049
1049
  ' return;',
1050
1050
  ' }',
1051
+ ' if (existing && shouldAutoDiscoverAssetContext() && !(existing.selected && existing.selected.qa_asset_context)) {',
1052
+ ' return;',
1053
+ ' }',
1051
1054
  ' if (["pass", "needs-data"].includes(status)) {',
1052
1055
  ' normalizeCoverageMatrixFromLiveSeed(existing);',
1053
1056
  ' const preserved = { ...existing, reused_existing: true, reuse_reason: reason, checked_at: new Date().toISOString() };',
@@ -1194,6 +1197,24 @@ function buildResolveIORunnerQaLiveDataSeederScript() {
1194
1197
  ' return /\\b(deliver(?:y|ed|ies)?|bol|bill\\s+of\\s+lading|truck\\s*treat(?:ing)?|flush(?:es)?|selected\\s+treatments?|chemical|red)\\b/i.test(text);',
1195
1198
  '}',
1196
1199
  '',
1200
+ 'function shouldAutoDiscoverAssetContext() {',
1201
+ ' const text = readSeedHintText();',
1202
+ ' return /\\b(asset|assets|unit|units|equipment|current\\s+location|location\\s+name|location\\s+names|default\\s+yard|yard)\\b/i.test(text);',
1203
+ '}',
1204
+ '',
1205
+ 'function extractAssetIdentifiers() {',
1206
+ ' const text = readSeedHintText();',
1207
+ ' const identifiers = new Set();',
1208
+ ' const explicit = /\\b(?:asset|unit|equipment)\\s*(?:#|no\\.?|number|num)?\\s*[:#-]?\\s*([A-Z0-9][A-Z0-9._-]{1,})\\b/gi;',
1209
+ ' let match;',
1210
+ ' while ((match = explicit.exec(text)) !== null) {',
1211
+ ' const value = String(match[1] || "").trim();',
1212
+ ' if (isUsefulSeedIdentifier(value)) identifiers.add(value);',
1213
+ ' }',
1214
+ ' if (shouldAutoDiscoverAssetContext()) extractSeedIdentifiers().forEach((value) => identifiers.add(value));',
1215
+ ' return Array.from(identifiers).slice(0, 20);',
1216
+ '}',
1217
+ '',
1197
1218
  'function extractRouteNameHints() {',
1198
1219
  ' const text = readSeedHintText();',
1199
1220
  ' const routes = new Set();',
@@ -1241,6 +1262,25 @@ function buildResolveIORunnerQaLiveDataSeederScript() {
1241
1262
  ' return ors.length ? { $or: ors } : null;',
1242
1263
  '}',
1243
1264
  '',
1265
+ 'function assetLookupQuery(identifiers) {',
1266
+ ' const ors = [];',
1267
+ ' const fields = ["_id", "asset_number", "asset_number_string", "asset_unit_number", "unit_number", "number", "serial_number", "name"];',
1268
+ ' for (const identifier of identifiers || []) {',
1269
+ ' const value = String(identifier || "").trim();',
1270
+ ' if (!value) continue;',
1271
+ ' const escaped = value.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\\\$&");',
1272
+ ' const exactText = new RegExp(`^${escaped}$`, "i");',
1273
+ ' const containsText = new RegExp(escaped, "i");',
1274
+ ' for (const field of fields) ors.push({ [field]: exactText });',
1275
+ ' for (const field of ["asset_number_string", "asset_unit_number", "unit_number", "number", "serial_number", "name"]) ors.push({ [field]: containsText });',
1276
+ ' if (/^\\d+$/.test(value)) {',
1277
+ ' const numericValue = Number(value);',
1278
+ ' for (const field of ["asset_number", "unit_number", "number"]) ors.push({ [field]: numericValue });',
1279
+ ' }',
1280
+ ' }',
1281
+ ' return ors.length ? { $or: ors } : null;',
1282
+ '}',
1283
+ '',
1244
1284
  'async function copyByIds(sourceDb, targetDb, collectionName, ids, summary, limit = 100) {',
1245
1285
  ' const cleanIds = unique(ids).slice(0, limit);',
1246
1286
  ' if (!cleanIds.length) return [];',
@@ -1417,6 +1457,45 @@ function buildResolveIORunnerQaLiveDataSeederScript() {
1417
1457
  ' return [...bols, ...productionRoutes, ...productionDeliveries, ...truckTreatingDeliveries, ...copiedTreatmentPlans];',
1418
1458
  '}',
1419
1459
  '',
1460
+ 'async function copyTicketAssetContext(sourceDb, targetDb, summary) {',
1461
+ ' if (!shouldAutoDiscoverAssetContext()) return [];',
1462
+ ' const assetIdentifiers = extractAssetIdentifiers();',
1463
+ ' summary.selected.asset_identifiers = assetIdentifiers;',
1464
+ ' const query = assetLookupQuery(assetIdentifiers);',
1465
+ ' if (!query) return [];',
1466
+ ' const assets = await copyQuery(sourceDb, targetDb, "assets", query, summary, 20, { updatedAt: -1, asset_number: 1 });',
1467
+ ' if (!assets.length) {',
1468
+ ' summary.notes.push(`No live assets matched ticket identifiers: ${assetIdentifiers.join(", ")}`);',
1469
+ ' return [];',
1470
+ ' }',
1471
+ ' const yardIds = unique([',
1472
+ ' ...idValues(assets, ["id_yard", "id_default_yard"]),',
1473
+ ' ...collectNestedStringValues(assets, ["id", "id_yard"])',
1474
+ ' ]);',
1475
+ ' const locationIds = unique([',
1476
+ ' ...idValues(assets, ["id_location", "id_current_location", "id_default_location"]),',
1477
+ ' ...collectNestedStringValues(assets, ["id_location"])',
1478
+ ' ]);',
1479
+ ' const userIds = unique([',
1480
+ ' ...idValues(assets, ["id_user", "id_driver", "id_created_by", "id_updated_by"]),',
1481
+ ' ...collectNestedStringValues(assets, ["id_user", "id_driver", "id_created_by", "id_updated_by"])',
1482
+ ' ]);',
1483
+ ' await copyByIds(sourceDb, targetDb, "yards", yardIds, summary, 100);',
1484
+ ' await copyByIds(sourceDb, targetDb, "production-locations", locationIds, summary, 100);',
1485
+ ' await copyByIds(sourceDb, targetDb, "users", userIds, summary, 100);',
1486
+ ' const assetIds = assets.map((doc) => doc._id).filter(Boolean);',
1487
+ ' const assetNumbers = assets.map((doc) => String(doc.asset_number || doc.asset_number_string || doc.asset_unit_number || doc.unit_number || "")).filter(Boolean);',
1488
+ ' summary.selected.qa_asset_context = {',
1489
+ ' asset_ids: assetIds,',
1490
+ ' asset_numbers: assetNumbers,',
1491
+ ' yard_ids: yardIds,',
1492
+ ' production_location_ids: locationIds,',
1493
+ ' browser_routes: assetIds[0] ? { list: "/asset/list", detail: `/asset/detail/${assetIds[0]}`, edit: `/asset/edit/${assetIds[0]}` } : { list: "/asset/list" }',
1494
+ ' };',
1495
+ ' summary.notes.push(`Seeded live asset context for ${assetIdentifiers.join(", ")}: ${assets.length} asset(s), ${yardIds.length} yard id(s), ${locationIds.length} production location id(s).`);',
1496
+ ' return assets;',
1497
+ '}',
1498
+ '',
1420
1499
  'async function ensureBillingSurchargePricingFixtures(targetDb, summary, serviceItems, customerIds) {',
1421
1500
  ' const now = new Date();',
1422
1501
  ' const activeServiceItems = (serviceItems || []).filter((doc) => {',
@@ -1581,6 +1660,7 @@ function buildResolveIORunnerQaLiveDataSeederScript() {
1581
1660
  ' const identifiers = extractSeedIdentifiers();',
1582
1661
  ' summary.selected.seed_identifiers = identifiers;',
1583
1662
  ' const truckTreatingBolContextDocs = await copyTruckTreatingBolContext(sourceDb, targetDb, summary);',
1663
+ ' const ticketAssetContextDocs = await copyTicketAssetContext(sourceDb, targetDb, summary);',
1584
1664
  ' if (!includeBillingFixtures) {',
1585
1665
  ' summary.notes.push("Using live-context seed profile: billing dashboard fixtures are disabled because ticket context does not mention billing, invoices, taxes, inventory, pricing, surcharges, checkout, or pick tickets.");',
1586
1666
  ' await cleanupSyntheticBillingDashboardQaFixtures(targetDb, summary);',
@@ -1619,7 +1699,7 @@ function buildResolveIORunnerQaLiveDataSeederScript() {
1619
1699
  ' summary.notes.push("No live billable delivery or truck-treatment records matched the Billing Dashboard awaiting-invoice filters.");',
1620
1700
  ' }',
1621
1701
  '',
1622
- ' const sourceDocs = [...truckTreatingBolContextDocs, ...productionDeliveries, ...truckTreatingDeliveries];',
1702
+ ' const sourceDocs = [...truckTreatingBolContextDocs, ...ticketAssetContextDocs, ...productionDeliveries, ...truckTreatingDeliveries];',
1623
1703
  ' const customerIds = idValues(sourceDocs, ["id_customer"]);',
1624
1704
  ' const locationIds = idValues(sourceDocs, ["id_location"]);',
1625
1705
  ' const wellGroupIds = idValues(sourceDocs, ["id_well_group"]);',
@@ -1675,7 +1755,7 @@ function buildResolveIORunnerQaLiveDataSeederScript() {
1675
1755
  ' ] }, summary, 120, { date: -1, updatedAt: -1 });',
1676
1756
  ' }',
1677
1757
  '',
1678
- ' summary.ready = truckTreatingBolContextDocs.length > 0 || productionDeliveries.length > 0 || truckTreatingDeliveries.length > 0;',
1758
+ ' summary.ready = truckTreatingBolContextDocs.length > 0 || ticketAssetContextDocs.length > 0 || productionDeliveries.length > 0 || truckTreatingDeliveries.length > 0;',
1679
1759
  ' return summary;',
1680
1760
  '}',
1681
1761
  '',