@objectstack/lint 12.6.0 → 14.3.0

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/dist/index.cjs CHANGED
@@ -20,6 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ APPROVAL_APPROVER_TYPE_UNKNOWN: () => APPROVAL_APPROVER_TYPE_UNKNOWN,
24
+ APPROVAL_ESCALATION_REASSIGN_NO_TARGET: () => APPROVAL_ESCALATION_REASSIGN_NO_TARGET,
25
+ APPROVAL_ROLE_NOT_MEMBERSHIP_TIER: () => APPROVAL_ROLE_NOT_MEMBERSHIP_TIER,
26
+ CAPABILITY_REFERENCE_UNKNOWN: () => CAPABILITY_REFERENCE_UNKNOWN,
23
27
  CHART_CONFIG_MISSING: () => CHART_CONFIG_MISSING,
24
28
  CHART_FIELD_UNKNOWN: () => CHART_FIELD_UNKNOWN,
25
29
  FIELD_GROUP_EMPTY: () => FIELD_GROUP_EMPTY,
@@ -29,6 +33,14 @@ __export(index_exports, {
29
33
  LIST_VIEW_FILTERS_IN_VIEWS_MODE: () => LIST_VIEW_FILTERS_IN_VIEWS_MODE,
30
34
  MEASURE_AGGREGATE_INCOHERENT: () => MEASURE_AGGREGATE_INCOHERENT,
31
35
  PAGE_SOURCE_CLASSNAME: () => PAGE_SOURCE_CLASSNAME,
36
+ SECURITY_ANCHOR_HIGH_PRIVILEGE: () => SECURITY_ANCHOR_HIGH_PRIVILEGE,
37
+ SECURITY_BOOK_AUDIENCE_UNKNOWN_SET: () => SECURITY_BOOK_AUDIENCE_UNKNOWN_SET,
38
+ SECURITY_EXTERNAL_WIDER: () => SECURITY_EXTERNAL_WIDER,
39
+ SECURITY_OWD_ALIAS: () => SECURITY_OWD_ALIAS,
40
+ SECURITY_OWD_UNSET: () => SECURITY_OWD_UNSET,
41
+ SECURITY_PRIVATE_NO_READSCOPE: () => SECURITY_PRIVATE_NO_READSCOPE,
42
+ SECURITY_ROLE_WORD: () => SECURITY_ROLE_WORD,
43
+ SECURITY_WILDCARD_VAMA: () => SECURITY_WILDCARD_VAMA,
32
44
  SEMANTIC_ROLE_FIELD_UNKNOWN: () => SEMANTIC_ROLE_FIELD_UNKNOWN,
33
45
  STYLE_CLASSNAME_TAILWIND: () => STYLE_CLASSNAME_TAILWIND,
34
46
  STYLE_NODE_MISSING_ID: () => STYLE_NODE_MISSING_ID,
@@ -41,6 +53,10 @@ __export(index_exports, {
41
53
  WIDGET_DATASET_UNKNOWN: () => WIDGET_DATASET_UNKNOWN,
42
54
  WIDGET_DIMENSION_UNKNOWN: () => WIDGET_DIMENSION_UNKNOWN,
43
55
  WIDGET_MEASURE_UNKNOWN: () => WIDGET_MEASURE_UNKNOWN,
56
+ buildAccessMatrix: () => buildAccessMatrix,
57
+ diffAccessMatrix: () => diffAccessMatrix,
58
+ validateApprovalApprovers: () => validateApprovalApprovers,
59
+ validateCapabilityReferences: () => validateCapabilityReferences,
44
60
  validateFormLayout: () => validateFormLayout,
45
61
  validateJsxPages: () => validateJsxPages,
46
62
  validateListViewMode: () => validateListViewMode,
@@ -49,6 +65,7 @@ __export(index_exports, {
49
65
  validateReactPages: () => validateReactPages,
50
66
  validateRecordTitle: () => validateRecordTitle,
51
67
  validateResponsiveStyles: () => validateResponsiveStyles,
68
+ validateSecurityPosture: () => validateSecurityPosture,
52
69
  validateSemanticRoles: () => validateSemanticRoles,
53
70
  validateStackExpressions: () => validateStackExpressions,
54
71
  validateWidgetBindings: () => validateWidgetBindings
@@ -1251,8 +1268,571 @@ function validateFormLayout(stack) {
1251
1268
  }
1252
1269
  return findings;
1253
1270
  }
1271
+
1272
+ // src/validate-capability-references.ts
1273
+ var import_security = require("@objectstack/spec/security");
1274
+ var CAPABILITY_REFERENCE_UNKNOWN = "capability-reference-unknown";
1275
+ function asArray12(v) {
1276
+ if (Array.isArray(v)) return v;
1277
+ if (v && typeof v === "object") {
1278
+ return Object.entries(v).map(([name, def]) => ({ name, ...def }));
1279
+ }
1280
+ return [];
1281
+ }
1282
+ function asCapArray(v) {
1283
+ return Array.isArray(v) ? v.filter((s) => typeof s === "string" && s.length > 0) : [];
1284
+ }
1285
+ function flattenObjectRequired(v) {
1286
+ if (Array.isArray(v)) return asCapArray(v).map((cap) => ({ cap }));
1287
+ if (v && typeof v === "object") {
1288
+ const out = [];
1289
+ for (const [key, val] of Object.entries(v)) {
1290
+ for (const cap of asCapArray(val)) out.push({ cap, key });
1291
+ }
1292
+ return out;
1293
+ }
1294
+ return [];
1295
+ }
1296
+ function validateCapabilityReferences(stack) {
1297
+ const findings = [];
1298
+ if (!stack || typeof stack !== "object") return findings;
1299
+ const known = new Set(import_security.PLATFORM_CAPABILITY_NAMES);
1300
+ for (const ps of asArray12(stack.permissions)) {
1301
+ for (const cap of asCapArray(ps.systemPermissions)) known.add(cap);
1302
+ }
1303
+ for (const seed of asArray12(stack.data)) {
1304
+ if (seed.object !== "sys_capability") continue;
1305
+ for (const rec of Array.isArray(seed.records) ? seed.records : []) {
1306
+ const name = rec?.name;
1307
+ if (typeof name === "string" && name.length > 0) known.add(name);
1308
+ }
1309
+ }
1310
+ const hint = "Fix the capability name, declare it on a permission set\u2019s systemPermissions, ship a sys_capability seed row, or ignore this if the capability is provided by another installed package (references fail closed at runtime).";
1311
+ const flag = (cap, where, path) => {
1312
+ if (known.has(cap)) return;
1313
+ findings.push({
1314
+ severity: "warning",
1315
+ rule: CAPABILITY_REFERENCE_UNKNOWN,
1316
+ where,
1317
+ path,
1318
+ message: `requiredPermissions references capability "${cap}" which is registered nowhere \u2014 no built-in capability, no permission set in this package grants it via systemPermissions, and no sys_capability seed declares it`,
1319
+ hint
1320
+ });
1321
+ };
1322
+ const objects = asArray12(stack.objects);
1323
+ for (let i = 0; i < objects.length; i++) {
1324
+ const obj = objects[i];
1325
+ if (!obj || typeof obj !== "object") continue;
1326
+ const objName = typeof obj.name === "string" ? obj.name : `(object ${i})`;
1327
+ const objPath = `objects[${i}]`;
1328
+ for (const { cap, key } of flattenObjectRequired(obj.requiredPermissions)) {
1329
+ flag(cap, `object "${objName}"`, `${objPath}.requiredPermissions${key ? `.${key}` : ""}`);
1330
+ }
1331
+ const fields = asArray12(obj.fields);
1332
+ for (const f of fields) {
1333
+ const fname = typeof f.name === "string" ? f.name : "(field)";
1334
+ for (const cap of asCapArray(f.requiredPermissions)) {
1335
+ flag(cap, `field "${objName}.${fname}"`, `${objPath}.fields.${fname}.requiredPermissions`);
1336
+ }
1337
+ }
1338
+ for (const [ai, action] of asArray12(obj.actions).entries()) {
1339
+ const aName = typeof action.name === "string" ? action.name : `(action ${ai})`;
1340
+ for (const cap of asCapArray(action.requiredPermissions)) {
1341
+ flag(cap, `action "${objName}.${aName}"`, `${objPath}.actions[${ai}].requiredPermissions`);
1342
+ }
1343
+ }
1344
+ }
1345
+ for (const [i, action] of asArray12(stack.actions).entries()) {
1346
+ const aName = typeof action.name === "string" ? action.name : `(action ${i})`;
1347
+ for (const cap of asCapArray(action.requiredPermissions)) {
1348
+ flag(cap, `action "${aName}"`, `actions[${i}].requiredPermissions`);
1349
+ }
1350
+ }
1351
+ const apps = asArray12(stack.apps);
1352
+ for (let i = 0; i < apps.length; i++) {
1353
+ const app = apps[i];
1354
+ if (!app || typeof app !== "object") continue;
1355
+ const appName = typeof app.name === "string" ? app.name : `(app ${i})`;
1356
+ const walk = (node, path) => {
1357
+ if (!node || typeof node !== "object") return;
1358
+ if (Array.isArray(node)) {
1359
+ node.forEach((child, ci) => walk(child, `${path}[${ci}]`));
1360
+ return;
1361
+ }
1362
+ const rec = node;
1363
+ for (const cap of asCapArray(rec.requiredPermissions)) {
1364
+ flag(cap, `app "${appName}"`, `${path}.requiredPermissions`);
1365
+ }
1366
+ if (rec.navigation) walk(rec.navigation, `${path}.navigation`);
1367
+ if (rec.areas) walk(rec.areas, `${path}.areas`);
1368
+ if (rec.tabs) walk(rec.tabs, `${path}.tabs`);
1369
+ if (rec.children) walk(rec.children, `${path}.children`);
1370
+ if (rec.items) walk(rec.items, `${path}.items`);
1371
+ };
1372
+ walk(app, `apps[${i}]`);
1373
+ }
1374
+ return findings;
1375
+ }
1376
+
1377
+ // src/validate-approval-approvers.ts
1378
+ var import_automation = require("@objectstack/spec/automation");
1379
+ var APPROVAL_ROLE_NOT_MEMBERSHIP_TIER = "approval-role-not-membership-tier";
1380
+ var APPROVAL_APPROVER_TYPE_UNKNOWN = "approval-approver-type-unknown";
1381
+ var APPROVAL_ESCALATION_REASSIGN_NO_TARGET = "approval-escalation-reassign-no-target";
1382
+ var MEMBERSHIP_TIERS = /* @__PURE__ */ new Set(["owner", "admin", "member", "guest"]);
1383
+ var TYPE_FIX = {
1384
+ business_unit: "department",
1385
+ bu: "department"
1386
+ };
1387
+ function asArray13(v) {
1388
+ if (Array.isArray(v)) return v;
1389
+ if (v && typeof v === "object") {
1390
+ return Object.entries(v).map(([name, def]) => ({ name, ...def }));
1391
+ }
1392
+ return [];
1393
+ }
1394
+ function validateApprovalApprovers(stack) {
1395
+ const findings = [];
1396
+ if (!stack || typeof stack !== "object") return findings;
1397
+ const flows = asArray13(stack.flows);
1398
+ const validTypes = new Set(import_automation.ApproverType.options);
1399
+ for (let fi = 0; fi < flows.length; fi++) {
1400
+ const flow = flows[fi];
1401
+ if (!flow || typeof flow !== "object") continue;
1402
+ const flowName = typeof flow.name === "string" ? flow.name : `(flow ${fi})`;
1403
+ const nodes = Array.isArray(flow.nodes) ? flow.nodes : [];
1404
+ for (let ni = 0; ni < nodes.length; ni++) {
1405
+ const node = nodes[ni];
1406
+ if (!node || node.type !== import_automation.APPROVAL_NODE_TYPE) continue;
1407
+ const nodeId = typeof node.id === "string" ? node.id : `(node ${ni})`;
1408
+ const cfg = node.config ?? {};
1409
+ const approvers = Array.isArray(cfg.approvers) ? cfg.approvers : [];
1410
+ const where = `flow "${flowName}" \xB7 node "${nodeId}"`;
1411
+ for (let ai = 0; ai < approvers.length; ai++) {
1412
+ const a = approvers[ai];
1413
+ if (!a || typeof a !== "object") continue;
1414
+ const type = typeof a.type === "string" ? a.type : "";
1415
+ const value = typeof a.value === "string" ? a.value : "";
1416
+ const path = `flows[${fi}].nodes[${ni}].config.approvers[${ai}]`;
1417
+ if (type && !validTypes.has(type)) {
1418
+ const fix = TYPE_FIX[type];
1419
+ findings.push({
1420
+ severity: "warning",
1421
+ rule: APPROVAL_APPROVER_TYPE_UNKNOWN,
1422
+ where,
1423
+ path: `${path}.type`,
1424
+ message: `approver type '${type}' is not an ApproverType (${import_automation.ApproverType.options.join(" | ")}).`,
1425
+ hint: fix ? `Use the spec value: { type: '${fix}', value: '${value}' }.` : `Pick one of the spec values; unmapped types degrade to an inert '${type}:${value}' literal at runtime.`
1426
+ });
1427
+ continue;
1428
+ }
1429
+ if (type === "role" && value && !MEMBERSHIP_TIERS.has(value.toLowerCase())) {
1430
+ findings.push({
1431
+ severity: "warning",
1432
+ rule: APPROVAL_ROLE_NOT_MEMBERSHIP_TIER,
1433
+ where,
1434
+ path: `${path}.value`,
1435
+ message: `approver { type: 'role', value: '${value}' } resolves against the better-auth org-membership tier (sys_member.role: owner/admin/member) \u2014 '${value}' is not a membership tier, so this approver matches nobody and the request stalls.`,
1436
+ hint: `If '${value}' is an org position, author { type: 'position', value: '${value}' } (resolved via sys_user_position, ADR-0090 D3). Keep type 'role' only for membership tiers (owner/admin/member).`
1437
+ });
1438
+ }
1439
+ }
1440
+ const escalation = cfg.escalation ?? null;
1441
+ if (escalation && typeof escalation === "object" && escalation.action === "reassign") {
1442
+ const target = typeof escalation.escalateTo === "string" ? escalation.escalateTo.trim() : "";
1443
+ if (!target) {
1444
+ findings.push({
1445
+ severity: "warning",
1446
+ rule: APPROVAL_ESCALATION_REASSIGN_NO_TARGET,
1447
+ where,
1448
+ path: `flows[${fi}].nodes[${ni}].config.escalation.escalateTo`,
1449
+ message: `escalation.action is 'reassign' but escalateTo is empty \u2014 at runtime the escalation degrades to a notify and the request stays with the original approvers.`,
1450
+ hint: `Set escalateTo to a position machine name (expanded via sys_user_position, ADR-0090 D3) or a specific user id, or change action to 'notify'.`
1451
+ });
1452
+ }
1453
+ }
1454
+ }
1455
+ }
1456
+ return findings;
1457
+ }
1458
+
1459
+ // src/validate-security-posture.ts
1460
+ var import_security2 = require("@objectstack/spec/security");
1461
+ var SECURITY_OWD_UNSET = "security-owd-unset";
1462
+ var SECURITY_OWD_ALIAS = "security-owd-alias";
1463
+ var SECURITY_EXTERNAL_WIDER = "security-external-wider-than-internal";
1464
+ var SECURITY_WILDCARD_VAMA = "security-wildcard-vama";
1465
+ var SECURITY_ANCHOR_HIGH_PRIVILEGE = "security-anchor-high-privilege";
1466
+ var SECURITY_ROLE_WORD = "security-role-word";
1467
+ var SECURITY_BOOK_AUDIENCE_UNKNOWN_SET = "security-book-audience-unknown-set";
1468
+ var SECURITY_PRIVATE_NO_READSCOPE = "security-private-no-readscope";
1469
+ var SECURITY_MASTER_DETAIL_UNGRANTED = "security-master-detail-ungranted";
1470
+ var CANONICAL_OWD = ["private", "public_read", "public_read_write", "controlled_by_parent"];
1471
+ var OWD_ALIAS_FIX = {
1472
+ read: "public_read",
1473
+ read_write: "public_read_write",
1474
+ full: "public_read_write",
1475
+ public: "public_read_write"
1476
+ };
1477
+ var OWD_WIDTH = {
1478
+ private: 0,
1479
+ public_read: 1,
1480
+ public_read_write: 2
1481
+ };
1482
+ function asArray14(v) {
1483
+ if (Array.isArray(v)) return v;
1484
+ if (v && typeof v === "object") {
1485
+ return Object.entries(v).map(([name, def]) => ({ name, ...def }));
1486
+ }
1487
+ return [];
1488
+ }
1489
+ function owdOf(obj) {
1490
+ return obj.sharingModel ?? obj.security?.sharingModel;
1491
+ }
1492
+ function isSystemObject(obj) {
1493
+ return obj.isSystem === true || String(obj.name ?? "").startsWith("sys_");
1494
+ }
1495
+ function identifierHasRoleToken(name) {
1496
+ if (typeof name !== "string") return false;
1497
+ return name.toLowerCase().split(/[^a-z0-9]+/).some((tok) => tok === "role" || tok === "roles");
1498
+ }
1499
+ function labelHasRoleWord(label) {
1500
+ if (typeof label !== "string") return false;
1501
+ return /\brole(s)?\b/i.test(label);
1502
+ }
1503
+ function refOf(def) {
1504
+ const r = def.reference ?? def.reference_to;
1505
+ return typeof r === "string" && r ? r : void 0;
1506
+ }
1507
+ function firstMasterDetailField(obj) {
1508
+ for (const f of asArray14(obj.fields)) {
1509
+ if (f.type === "master_detail") {
1510
+ return { name: String(f.name ?? "?"), parent: refOf(f) };
1511
+ }
1512
+ }
1513
+ return void 0;
1514
+ }
1515
+ function grantsObjectAccess(p) {
1516
+ return p.allowRead === true || p.allowCreate === true || p.allowEdit === true || p.allowDelete === true || p.viewAllRecords === true || p.modifyAllRecords === true;
1517
+ }
1518
+ function validateSecurityPosture(stack) {
1519
+ const findings = [];
1520
+ if (!stack || typeof stack !== "object") return findings;
1521
+ const objects = asArray14(stack.objects);
1522
+ const permissionSets = asArray14(stack.permissions);
1523
+ for (let i = 0; i < objects.length; i++) {
1524
+ const obj = objects[i];
1525
+ if (!obj || typeof obj !== "object") continue;
1526
+ const objName = typeof obj.name === "string" ? obj.name : `(object ${i})`;
1527
+ const objPath = `objects[${i}]`;
1528
+ const owd = owdOf(obj);
1529
+ const external = obj.externalSharingModel;
1530
+ if (!isSystemObject(obj)) {
1531
+ if (owd == null) {
1532
+ findings.push({
1533
+ severity: "error",
1534
+ rule: SECURITY_OWD_UNSET,
1535
+ where: `object "${objName}"`,
1536
+ path: `${objPath}.sharingModel`,
1537
+ message: `custom object "${objName}" declares no sharingModel (OWD). The runtime fails CLOSED to 'private' (ADR-0090 D1), but the baseline must be an authored decision, not an accident \u2014 this is the exact shape of the leave_request incident (objectui#2348).`,
1538
+ hint: `Declare sharingModel explicitly: 'private' (owner + shares; recommended default), 'public_read', 'public_read_write', or 'controlled_by_parent' (master-detail children).`
1539
+ });
1540
+ } else if (typeof owd === "string" && OWD_ALIAS_FIX[owd]) {
1541
+ findings.push({
1542
+ severity: "error",
1543
+ rule: SECURITY_OWD_ALIAS,
1544
+ where: `object "${objName}"`,
1545
+ path: `${objPath}.sharingModel`,
1546
+ message: `sharingModel '${owd}' is a retired alias (ADR-0090 D4). The runtime fails CLOSED to 'private' on unknown values, so this object is NOT ${owd === "read" ? "readable" : "writable"} org-wide.`,
1547
+ hint: `Replace with the canonical value: sharingModel: '${OWD_ALIAS_FIX[owd]}'.`
1548
+ });
1549
+ } else if (typeof owd === "string" && !CANONICAL_OWD.includes(owd)) {
1550
+ findings.push({
1551
+ severity: "error",
1552
+ rule: SECURITY_OWD_ALIAS,
1553
+ where: `object "${objName}"`,
1554
+ path: `${objPath}.sharingModel`,
1555
+ message: `sharingModel '${owd}' is not a canonical OWD value; the runtime fails CLOSED to 'private'.`,
1556
+ hint: `Use one of: ${CANONICAL_OWD.join(", ")}.`
1557
+ });
1558
+ }
1559
+ }
1560
+ if (typeof external === "string") {
1561
+ if (OWD_ALIAS_FIX[external]) {
1562
+ findings.push({
1563
+ severity: "error",
1564
+ rule: SECURITY_OWD_ALIAS,
1565
+ where: `object "${objName}"`,
1566
+ path: `${objPath}.externalSharingModel`,
1567
+ message: `externalSharingModel '${external}' is a retired alias (ADR-0090 D4).`,
1568
+ hint: `Replace with the canonical value: externalSharingModel: '${OWD_ALIAS_FIX[external]}'.`
1569
+ });
1570
+ } else if (typeof owd === "string" && external in OWD_WIDTH && owd in OWD_WIDTH && OWD_WIDTH[external] > OWD_WIDTH[owd]) {
1571
+ findings.push({
1572
+ severity: "error",
1573
+ rule: SECURITY_EXTERNAL_WIDER,
1574
+ where: `object "${objName}"`,
1575
+ path: `${objPath}.externalSharingModel`,
1576
+ message: `externalSharingModel '${external}' is WIDER than the internal sharingModel '${owd}' \u2014 the external baseline must never exceed the internal one (ADR-0090 D11).`,
1577
+ hint: `Narrow externalSharingModel to '${owd}' or below (ordering: private < public_read < public_read_write).`
1578
+ });
1579
+ }
1580
+ }
1581
+ }
1582
+ for (let i = 0; i < permissionSets.length; i++) {
1583
+ const ps = permissionSets[i];
1584
+ if (!ps || typeof ps !== "object") continue;
1585
+ const psName = typeof ps.name === "string" ? ps.name : `(permission set ${i})`;
1586
+ const psPath = `permissions[${i}]`;
1587
+ const objectsMap = ps.objects && typeof ps.objects === "object" ? ps.objects : {};
1588
+ const wildcard = objectsMap["*"];
1589
+ if (wildcard && (wildcard.viewAllRecords === true || wildcard.modifyAllRecords === true)) {
1590
+ findings.push({
1591
+ severity: "error",
1592
+ rule: SECURITY_WILDCARD_VAMA,
1593
+ where: `permission set "${psName}"`,
1594
+ path: `${psPath}.objects.*`,
1595
+ message: `'*' wildcard carrying View All / Modify All Data \u2014 a package-authored superuser. Only the platform's own admin set may combine the wildcard with VAMA (ADR-0066).`,
1596
+ hint: `Enumerate the objects this set really needs, or drop viewAllRecords/modifyAllRecords from the wildcard entry. App-level admins belong in an ordinary set the customer binds to a position of their choosing (ADR-0090 D9).`
1597
+ });
1598
+ }
1599
+ if (ps.isDefault === true) {
1600
+ const offending = (0, import_security2.describeAnchorForbiddenBits)(ps, "everyone");
1601
+ if (offending) {
1602
+ findings.push({
1603
+ severity: "error",
1604
+ rule: SECURITY_ANCHOR_HIGH_PRIVILEGE,
1605
+ where: `permission set "${psName}"`,
1606
+ path: `${psPath}.isDefault`,
1607
+ message: `isDefault:true suggests binding this set to the 'everyone' audience anchor, but it carries ${offending} \u2014 the runtime will refuse the binding (ADR-0090 D5/D9).`,
1608
+ hint: `Split the powerful bits into a separate set granted through ordinary positions, and keep the everyone-suggested set low-privilege.`
1609
+ });
1610
+ }
1611
+ }
1612
+ }
1613
+ const flagRole = (kind, name, label, where, path) => {
1614
+ if (identifierHasRoleToken(name)) {
1615
+ findings.push({
1616
+ severity: "error",
1617
+ rule: SECURITY_ROLE_WORD,
1618
+ where,
1619
+ path,
1620
+ message: `${kind} name "${String(name)}" uses the reserved word "role" \u2014 the platform vocabulary is permission_set (capability), position (distribution), business_unit (hierarchy) (ADR-0090 D3).`,
1621
+ hint: `Rename using 'position' for distribution groups or a domain word (e.g. 'function', 'duty').`
1622
+ });
1623
+ } else if (labelHasRoleWord(label)) {
1624
+ findings.push({
1625
+ severity: "error",
1626
+ rule: SECURITY_ROLE_WORD,
1627
+ where,
1628
+ path: `${path.replace(/\.name$/, "")}.label`,
1629
+ message: `${kind} label "${String(label)}" uses the reserved word "role" (ADR-0090 D3).`,
1630
+ hint: `Relabel with 'Position' (distribution) or a domain word \u2014 admins must meet ONE vocabulary.`
1631
+ });
1632
+ }
1633
+ };
1634
+ for (let i = 0; i < objects.length; i++) {
1635
+ const obj = objects[i];
1636
+ if (!obj || typeof obj !== "object" || isSystemObject(obj)) continue;
1637
+ const objName = typeof obj.name === "string" ? obj.name : `(object ${i})`;
1638
+ flagRole("object", obj.name, obj.label, `object "${objName}"`, `objects[${i}].name`);
1639
+ for (const f of asArray14(obj.fields)) {
1640
+ flagRole("field", f.name, f.label, `field "${objName}.${String(f.name ?? "?")}"`, `objects[${i}].fields.${String(f.name ?? "?")}.name`);
1641
+ }
1642
+ for (const [ai, action] of asArray14(obj.actions).entries()) {
1643
+ flagRole("action", action.name, action.label, `action "${objName}.${String(action.name ?? "?")}"`, `objects[${i}].actions[${ai}].name`);
1644
+ }
1645
+ }
1646
+ for (let i = 0; i < permissionSets.length; i++) {
1647
+ const ps = permissionSets[i];
1648
+ if (!ps || typeof ps !== "object") continue;
1649
+ flagRole("permission set", ps.name, ps.label, `permission set "${String(ps.name ?? i)}"`, `permissions[${i}].name`);
1650
+ }
1651
+ for (const [i, pos] of asArray14(stack.positions).entries()) {
1652
+ flagRole("position", pos.name, pos.label, `position "${String(pos.name ?? i)}"`, `positions[${i}].name`);
1653
+ }
1654
+ for (const [i, app] of asArray14(stack.apps).entries()) {
1655
+ flagRole("app", app.name, app.label, `app "${String(app.name ?? i)}"`, `apps[${i}].name`);
1656
+ }
1657
+ for (const [i, book] of asArray14(stack.books).entries()) {
1658
+ flagRole("book", book.name, book.label, `book "${String(book.name ?? i)}"`, `books[${i}].name`);
1659
+ }
1660
+ const stackSetNames = new Set(
1661
+ permissionSets.map((ps) => typeof ps.name === "string" ? ps.name : void 0).filter((n) => !!n)
1662
+ );
1663
+ for (const [i, book] of asArray14(stack.books).entries()) {
1664
+ const audience = book.audience;
1665
+ if (!audience || typeof audience !== "object") continue;
1666
+ const setName = audience.permissionSet;
1667
+ if (typeof setName !== "string" || setName.length === 0) continue;
1668
+ if (!stackSetNames.has(setName)) {
1669
+ findings.push({
1670
+ severity: "warning",
1671
+ rule: SECURITY_BOOK_AUDIENCE_UNKNOWN_SET,
1672
+ where: `book "${String(book.name ?? i)}"`,
1673
+ path: `books[${i}].audience.permissionSet`,
1674
+ message: `book audience references permission set "${setName}", which this stack does not declare. The runtime fails closed \u2014 no holder means NO reader can open the book.`,
1675
+ hint: `Gate the book on one of this package's own permission sets (ADR-0090 D9, e.g. its admin set), or fix the typo. Ignore if the set is intentionally provided by another installed package.`
1676
+ });
1677
+ }
1678
+ }
1679
+ const privateObjects = new Set(
1680
+ objects.filter((o) => o && typeof o === "object" && !isSystemObject(o)).filter((o) => {
1681
+ const owd = owdOf(o);
1682
+ return owd == null || owd === "private";
1683
+ }).map((o) => String(o.name ?? ""))
1684
+ );
1685
+ if (privateObjects.size > 0) {
1686
+ for (let i = 0; i < permissionSets.length; i++) {
1687
+ const ps = permissionSets[i];
1688
+ if (!ps || typeof ps !== "object") continue;
1689
+ const psName = typeof ps.name === "string" ? ps.name : `(permission set ${i})`;
1690
+ const objectsMap = ps.objects && typeof ps.objects === "object" ? ps.objects : {};
1691
+ for (const [objName, rawPerm] of Object.entries(objectsMap)) {
1692
+ if (!privateObjects.has(objName)) continue;
1693
+ const p = rawPerm ?? {};
1694
+ if (p.allowRead === true && p.readScope == null && p.viewAllRecords !== true) {
1695
+ findings.push({
1696
+ severity: "info",
1697
+ rule: SECURITY_PRIVATE_NO_READSCOPE,
1698
+ where: `permission set "${psName}"`,
1699
+ path: `permissions[${i}].objects.${objName}.readScope`,
1700
+ message: `"${objName}" is private (OWD) and this set grants allowRead without a readScope \u2014 holders see ONLY records they own (plus explicit shares).`,
1701
+ hint: `If that is intended (personal data), ignore this. Otherwise add readScope: 'own_and_reports' | 'unit' | 'unit_and_below' | 'org', or widen the object's sharingModel.`
1702
+ });
1703
+ }
1704
+ }
1705
+ }
1706
+ }
1707
+ if (permissionSets.length > 0) {
1708
+ const wildcardGrantsAll = permissionSets.some(
1709
+ (ps) => grantsObjectAccess(ps.objects?.["*"] ?? {})
1710
+ );
1711
+ if (!wildcardGrantsAll) {
1712
+ const grantedObjects = /* @__PURE__ */ new Set();
1713
+ for (const ps of permissionSets) {
1714
+ const objectsMap = ps.objects && typeof ps.objects === "object" ? ps.objects : {};
1715
+ for (const [objName, rawPerm] of Object.entries(objectsMap)) {
1716
+ if (objName === "*") continue;
1717
+ if (grantsObjectAccess(rawPerm ?? {})) grantedObjects.add(objName);
1718
+ }
1719
+ }
1720
+ for (let i = 0; i < objects.length; i++) {
1721
+ const obj = objects[i];
1722
+ if (!obj || typeof obj !== "object" || isSystemObject(obj)) continue;
1723
+ const objName = typeof obj.name === "string" ? obj.name : "";
1724
+ if (!objName || grantedObjects.has(objName)) continue;
1725
+ const md = firstMasterDetailField(obj);
1726
+ if (!md) continue;
1727
+ const parentText = md.parent ? ` \u2192 "${md.parent}"` : "";
1728
+ findings.push({
1729
+ severity: "warning",
1730
+ rule: SECURITY_MASTER_DETAIL_UNGRANTED,
1731
+ where: `object "${objName}"`,
1732
+ path: `objects[${i}].fields.${md.name}`,
1733
+ message: `detail object "${objName}" (master_detail "${md.name}"${parentText}) has no object-level CRUD grant in any permission set. A master-detail child derives its RECORD-level access from the master (ADR-0055 controlled_by_parent), but object-level CRUD is a SEPARATE gate that is never derived \u2014 role-bound non-admin users are denied (403) before the parent-derived access is ever consulted (the silent "can't submit the subtable" trap).`,
1734
+ hint: `Grant "${objName}" in at least one permission set that already grants its master${md.parent ? ` "${md.parent}"` : ""} \u2014 e.g. permissions[i].objects.${objName} = { allowRead: true, allowCreate: true, allowEdit: true }. If no role should ever touch it (a pure system/internal table), name it sys_* or set isSystem: true.`
1735
+ });
1736
+ }
1737
+ }
1738
+ }
1739
+ return findings;
1740
+ }
1741
+
1742
+ // src/build-access-matrix.ts
1743
+ function asArray15(v) {
1744
+ if (Array.isArray(v)) return v;
1745
+ if (v && typeof v === "object") {
1746
+ return Object.entries(v).map(([name, def]) => ({ name, ...def }));
1747
+ }
1748
+ return [];
1749
+ }
1750
+ function buildAccessMatrix(stack) {
1751
+ const entries = [];
1752
+ if (!stack || typeof stack !== "object") return { version: 1, entries };
1753
+ const owdByObject = /* @__PURE__ */ new Map();
1754
+ for (const obj of asArray15(stack.objects)) {
1755
+ const name = typeof obj.name === "string" ? obj.name : "";
1756
+ if (!name) continue;
1757
+ const owd = obj.sharingModel ?? obj.security?.sharingModel;
1758
+ if (typeof owd === "string") owdByObject.set(name, owd);
1759
+ }
1760
+ for (const ps of asArray15(stack.permissions)) {
1761
+ const psName = typeof ps.name === "string" ? ps.name : "";
1762
+ if (!psName) continue;
1763
+ const objects = ps.objects && typeof ps.objects === "object" ? ps.objects : {};
1764
+ for (const [objName, rawPerm] of Object.entries(objects)) {
1765
+ const p = rawPerm ?? {};
1766
+ const entry = {
1767
+ permissionSet: psName,
1768
+ object: objName,
1769
+ create: p.allowCreate === true,
1770
+ read: p.allowRead === true || p.viewAllRecords === true || p.modifyAllRecords === true,
1771
+ edit: p.allowEdit === true || p.modifyAllRecords === true,
1772
+ delete: p.allowDelete === true || p.modifyAllRecords === true,
1773
+ viewAllRecords: p.viewAllRecords === true,
1774
+ modifyAllRecords: p.modifyAllRecords === true
1775
+ };
1776
+ if (typeof p.readScope === "string") entry.readScope = p.readScope;
1777
+ if (typeof p.writeScope === "string") entry.writeScope = p.writeScope;
1778
+ const owd = owdByObject.get(objName);
1779
+ if (owd) entry.sharingModel = owd;
1780
+ entries.push(entry);
1781
+ }
1782
+ }
1783
+ entries.sort(
1784
+ (a, b) => a.permissionSet === b.permissionSet ? a.object.localeCompare(b.object) : a.permissionSet.localeCompare(b.permissionSet)
1785
+ );
1786
+ return { version: 1, entries };
1787
+ }
1788
+ var BIT_LABELS = [
1789
+ ["create", "create"],
1790
+ ["read", "read"],
1791
+ ["edit", "edit"],
1792
+ ["delete", "delete"],
1793
+ ["viewAllRecords", "View All Data"],
1794
+ ["modifyAllRecords", "Modify All Data"]
1795
+ ];
1796
+ function diffAccessMatrix(before, after) {
1797
+ const lines = [];
1798
+ const key = (e) => `${e.permissionSet}\0${e.object}`;
1799
+ const beforeMap = new Map((before?.entries ?? []).map((e) => [key(e), e]));
1800
+ const afterMap = new Map((after?.entries ?? []).map((e) => [key(e), e]));
1801
+ for (const [k, b] of beforeMap) {
1802
+ if (!afterMap.has(k)) {
1803
+ lines.push(`'${b.permissionSet}' loses ALL access to '${b.object}' (entry removed)`);
1804
+ }
1805
+ }
1806
+ for (const [k, a] of afterMap) {
1807
+ const b = beforeMap.get(k);
1808
+ if (!b) {
1809
+ const grants = BIT_LABELS.filter(([bit]) => a[bit] === true).map(([, label]) => label);
1810
+ lines.push(`'${a.permissionSet}' gains access to '${a.object}' (${grants.join(", ") || "no bits set"})`);
1811
+ continue;
1812
+ }
1813
+ for (const [bit, label] of BIT_LABELS) {
1814
+ if (b[bit] !== a[bit]) {
1815
+ lines.push(`'${a.permissionSet}' ${a[bit] ? "gains" : "loses"} ${label} on '${a.object}'`);
1816
+ }
1817
+ }
1818
+ if ((b.readScope ?? "own") !== (a.readScope ?? "own")) {
1819
+ lines.push(`'${a.permissionSet}' read depth on '${a.object}': ${b.readScope ?? "own"} \u2192 ${a.readScope ?? "own"}`);
1820
+ }
1821
+ if ((b.writeScope ?? "own") !== (a.writeScope ?? "own")) {
1822
+ lines.push(`'${a.permissionSet}' write depth on '${a.object}': ${b.writeScope ?? "own"} \u2192 ${a.writeScope ?? "own"}`);
1823
+ }
1824
+ if ((b.sharingModel ?? "") !== (a.sharingModel ?? "")) {
1825
+ lines.push(`'${a.object}' record baseline (OWD): ${b.sharingModel ?? "(unset)"} \u2192 ${a.sharingModel ?? "(unset)"} (affects every principal)`);
1826
+ }
1827
+ }
1828
+ return lines;
1829
+ }
1254
1830
  // Annotate the CommonJS export names for ESM import in node:
1255
1831
  0 && (module.exports = {
1832
+ APPROVAL_APPROVER_TYPE_UNKNOWN,
1833
+ APPROVAL_ESCALATION_REASSIGN_NO_TARGET,
1834
+ APPROVAL_ROLE_NOT_MEMBERSHIP_TIER,
1835
+ CAPABILITY_REFERENCE_UNKNOWN,
1256
1836
  CHART_CONFIG_MISSING,
1257
1837
  CHART_FIELD_UNKNOWN,
1258
1838
  FIELD_GROUP_EMPTY,
@@ -1262,6 +1842,14 @@ function validateFormLayout(stack) {
1262
1842
  LIST_VIEW_FILTERS_IN_VIEWS_MODE,
1263
1843
  MEASURE_AGGREGATE_INCOHERENT,
1264
1844
  PAGE_SOURCE_CLASSNAME,
1845
+ SECURITY_ANCHOR_HIGH_PRIVILEGE,
1846
+ SECURITY_BOOK_AUDIENCE_UNKNOWN_SET,
1847
+ SECURITY_EXTERNAL_WIDER,
1848
+ SECURITY_OWD_ALIAS,
1849
+ SECURITY_OWD_UNSET,
1850
+ SECURITY_PRIVATE_NO_READSCOPE,
1851
+ SECURITY_ROLE_WORD,
1852
+ SECURITY_WILDCARD_VAMA,
1265
1853
  SEMANTIC_ROLE_FIELD_UNKNOWN,
1266
1854
  STYLE_CLASSNAME_TAILWIND,
1267
1855
  STYLE_NODE_MISSING_ID,
@@ -1274,6 +1862,10 @@ function validateFormLayout(stack) {
1274
1862
  WIDGET_DATASET_UNKNOWN,
1275
1863
  WIDGET_DIMENSION_UNKNOWN,
1276
1864
  WIDGET_MEASURE_UNKNOWN,
1865
+ buildAccessMatrix,
1866
+ diffAccessMatrix,
1867
+ validateApprovalApprovers,
1868
+ validateCapabilityReferences,
1277
1869
  validateFormLayout,
1278
1870
  validateJsxPages,
1279
1871
  validateListViewMode,
@@ -1282,6 +1874,7 @@ function validateFormLayout(stack) {
1282
1874
  validateReactPages,
1283
1875
  validateRecordTitle,
1284
1876
  validateResponsiveStyles,
1877
+ validateSecurityPosture,
1285
1878
  validateSemanticRoles,
1286
1879
  validateStackExpressions,
1287
1880
  validateWidgetBindings