@objectstack/lint 16.0.0 → 17.0.0-rc.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/README.md +5 -2
- package/dist/index.cjs +2925 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +755 -33
- package/dist/index.d.ts +755 -33
- package/dist/index.js +2882 -77
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var TABLE_COUNT_ONLY = "table-count-only";
|
|
|
9
9
|
var MEASURE_AGGREGATE_INCOHERENT = "measure-aggregate-incoherent";
|
|
10
10
|
var WIDGET_LEGACY_ANALYTICS_SHAPE = "widget-legacy-analytics-shape";
|
|
11
11
|
var WIDGET_LEGACY_ANALYTICS_UNRENDERABLE = "widget-legacy-analytics-unrenderable";
|
|
12
|
+
var DASHBOARD_FILTER_FIELD_UNKNOWN = "dashboard-filter-field-unknown";
|
|
12
13
|
var LEGACY_ANALYTICS_KEYS = [
|
|
13
14
|
"categoryField",
|
|
14
15
|
"valueField",
|
|
@@ -86,6 +87,47 @@ function list(names) {
|
|
|
86
87
|
const arr = [...names];
|
|
87
88
|
return arr.length > 0 ? arr.join(", ") : "(none)";
|
|
88
89
|
}
|
|
90
|
+
var DATE_RANGE_FILTER_NAME = "dateRange";
|
|
91
|
+
var DATE_RANGE_DEFAULT_FIELD = "created_at";
|
|
92
|
+
var SYSTEM_FIELDS = /* @__PURE__ */ new Set([
|
|
93
|
+
"id",
|
|
94
|
+
"created_at",
|
|
95
|
+
"created_by",
|
|
96
|
+
"updated_at",
|
|
97
|
+
"updated_by",
|
|
98
|
+
"owner_id",
|
|
99
|
+
"organization_id",
|
|
100
|
+
"tenant_id",
|
|
101
|
+
"user_id",
|
|
102
|
+
"deleted_at"
|
|
103
|
+
]);
|
|
104
|
+
function dashboardFilterDefs(dash) {
|
|
105
|
+
const byName = /* @__PURE__ */ new Map();
|
|
106
|
+
const dateRange = dash.dateRange;
|
|
107
|
+
if (dateRange && typeof dateRange === "object") {
|
|
108
|
+
const declared = dateRange.field;
|
|
109
|
+
const field = typeof declared === "string" && declared ? declared : DATE_RANGE_DEFAULT_FIELD;
|
|
110
|
+
byName.set(DATE_RANGE_FILTER_NAME, { name: DATE_RANGE_FILTER_NAME, field });
|
|
111
|
+
}
|
|
112
|
+
for (const f of asArray(dash.globalFilters)) {
|
|
113
|
+
if (typeof f.field !== "string" || !f.field) continue;
|
|
114
|
+
const name = typeof f.name === "string" && f.name ? f.name : f.field;
|
|
115
|
+
const targetWidgets = Array.isArray(f.targetWidgets) ? f.targetWidgets.filter((w) => typeof w === "string") : void 0;
|
|
116
|
+
byName.set(name, { name, field: f.field, targetWidgets });
|
|
117
|
+
}
|
|
118
|
+
return [...byName.values()];
|
|
119
|
+
}
|
|
120
|
+
function effectiveFilterField(widget, def) {
|
|
121
|
+
const bindings = widget.filterBindings;
|
|
122
|
+
const binding = bindings && typeof bindings === "object" ? bindings[def.name] : void 0;
|
|
123
|
+
if (binding === false) return void 0;
|
|
124
|
+
if (typeof binding === "string" && binding) return { field: binding, explicit: true };
|
|
125
|
+
if (def.targetWidgets && def.targetWidgets.length > 0) {
|
|
126
|
+
const id = typeof widget.id === "string" ? widget.id : void 0;
|
|
127
|
+
if (!id || !def.targetWidgets.includes(id)) return void 0;
|
|
128
|
+
}
|
|
129
|
+
return { field: def.field, explicit: false };
|
|
130
|
+
}
|
|
89
131
|
function validateWidgetBindings(stack) {
|
|
90
132
|
const findings = [];
|
|
91
133
|
const datasets = /* @__PURE__ */ new Map();
|
|
@@ -130,6 +172,7 @@ function validateWidgetBindings(stack) {
|
|
|
130
172
|
const dash = dashboards[i];
|
|
131
173
|
const dashName = typeof dash.name === "string" ? dash.name : `(dashboard ${i})`;
|
|
132
174
|
const widgets = Array.isArray(dash.widgets) ? dash.widgets : [];
|
|
175
|
+
const dashFilterDefs = dashboardFilterDefs(dash);
|
|
133
176
|
for (let j = 0; j < widgets.length; j++) {
|
|
134
177
|
const w = widgets[j];
|
|
135
178
|
const widgetId = typeof w.id === "string" ? w.id : `(widget ${j})`;
|
|
@@ -173,7 +216,35 @@ function validateWidgetBindings(stack) {
|
|
|
173
216
|
hint: `Declared datasets: ${list(datasets.keys())}.${suggest(dsName, datasets.keys())} Define the dataset with defineDataset() or fix the reference (ADR-0021).`
|
|
174
217
|
});
|
|
175
218
|
}
|
|
219
|
+
if (!dsName) {
|
|
220
|
+
push({
|
|
221
|
+
severity: "error",
|
|
222
|
+
rule: WIDGET_DATASET_UNKNOWN,
|
|
223
|
+
message: `binds no \`dataset\` \u2014 the ADR-0021 widget shape requires one, so this widget resolves no data and renders empty.`,
|
|
224
|
+
hint: `Set \`dataset: '<name>'\` (plus \`values\`, and \`dimensions\` where the chart family needs them). Declared datasets: ${list(datasets.keys())}.`
|
|
225
|
+
});
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
176
228
|
if (!dataset) continue;
|
|
229
|
+
if (dashFilterDefs.length > 0) {
|
|
230
|
+
const datasetObject = typeof dataset.object === "string" ? dataset.object : void 0;
|
|
231
|
+
const objectFields = datasetObject ? objectFieldTypes.get(datasetObject) : void 0;
|
|
232
|
+
if (objectFields) {
|
|
233
|
+
for (const def of dashFilterDefs) {
|
|
234
|
+
const eff = effectiveFilterField(w, def);
|
|
235
|
+
if (!eff) continue;
|
|
236
|
+
const field = eff.field;
|
|
237
|
+
if (field.includes(".")) continue;
|
|
238
|
+
if (objectFields.has(field) || SYSTEM_FIELDS.has(field)) continue;
|
|
239
|
+
push({
|
|
240
|
+
severity: "error",
|
|
241
|
+
rule: DASHBOARD_FILTER_FIELD_UNKNOWN,
|
|
242
|
+
message: eff.explicit ? `binds dashboard filter \`${def.name}\` to field \`${field}\` (via filterBindings), but object \`${datasetObject}\` (dataset "${dsName}") has no field \`${field}\`.` : `inherits dashboard filter \`${def.name}(${field})\`, but object \`${datasetObject}\` (dataset "${dsName}") has no field \`${field}\`.`,
|
|
243
|
+
hint: eff.explicit ? `Point filterBindings: { ${def.name}: '<field>' } at a field that exists on \`${datasetObject}\`, or opt out with filterBindings: { ${def.name}: false }.${suggest(field, objectFields.keys())} Object fields: ${list(objectFields.keys())}.` : `Set filterBindings: { ${def.name}: false } on this widget to opt out, or re-target to an existing field with filterBindings: { ${def.name}: '<field>' }.${suggest(field, objectFields.keys())} Object fields: ${list(objectFields.keys())}.`
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
177
248
|
const dimensionNames = /* @__PURE__ */ new Set();
|
|
178
249
|
for (const d of asArray(dataset.dimensions)) {
|
|
179
250
|
if (typeof d.name === "string") dimensionNames.add(d.name);
|
|
@@ -215,13 +286,13 @@ function validateWidgetBindings(stack) {
|
|
|
215
286
|
hint: `Point xAxis.field at a dataset dimension name.${suggest(xAxis.field, dimensionNames)}`
|
|
216
287
|
});
|
|
217
288
|
}
|
|
218
|
-
const measureField = (
|
|
289
|
+
const measureField = (label2, field) => {
|
|
219
290
|
if (values.includes(field)) return;
|
|
220
291
|
const declaredButUnselected = measures.has(field);
|
|
221
292
|
push({
|
|
222
293
|
severity: "error",
|
|
223
294
|
rule: CHART_FIELD_UNKNOWN,
|
|
224
|
-
message: declaredButUnselected ? `chartConfig.${
|
|
295
|
+
message: declaredButUnselected ? `chartConfig.${label2} "${field}" is a measure of dataset "${dsName}" but is not selected in the widget's values (${list(values)}), so the query result will not contain it.` : `chartConfig.${label2} "${field}" does not resolve to a measure of dataset "${dsName}" (declared measures: ${list(measures.keys())}).`,
|
|
225
296
|
hint: declaredButUnselected ? `Add "${field}" to the widget's values, or bind the chart to a selected measure.` : `Post-cutover data is keyed by the dataset's measure NAME, not the base column.${suggest(field, selectedValues.size > 0 ? selectedValues : measures.keys())}`
|
|
226
297
|
});
|
|
227
298
|
};
|
|
@@ -412,8 +483,33 @@ function validateStackExpressions(stack) {
|
|
|
412
483
|
check(where, rule.condition ?? rule.criteria ?? rule.predicate, ruleObj, "record");
|
|
413
484
|
}
|
|
414
485
|
for (const hook of asArray2(stack.hooks)) {
|
|
415
|
-
const
|
|
416
|
-
|
|
486
|
+
const hookName = hook.name ?? "?";
|
|
487
|
+
if (typeof hook.object === "string") {
|
|
488
|
+
check(`hook '${hookName}' (${hook.object}) condition`, hook.condition, hook.object, "record");
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
const targets = Array.isArray(hook.object) ? hook.object.filter((o) => typeof o === "string" && o !== "*") : [];
|
|
492
|
+
if (targets.length === 0) {
|
|
493
|
+
check(`hook '${hookName}' condition`, hook.condition, void 0, "record");
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
const before = issues.length;
|
|
497
|
+
const seen = /* @__PURE__ */ new Set();
|
|
498
|
+
const kept = [];
|
|
499
|
+
for (const target of targets) {
|
|
500
|
+
const mark = issues.length;
|
|
501
|
+
check(`hook '${hookName}' (${target}) condition`, hook.condition, target, "record");
|
|
502
|
+
for (let i = mark; i < issues.length; i++) {
|
|
503
|
+
const issue = issues[i];
|
|
504
|
+
const key = `${issue.message}\0${issue.source ?? ""}`;
|
|
505
|
+
if (!seen.has(key)) {
|
|
506
|
+
seen.add(key);
|
|
507
|
+
kept.push(issue);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
issues.length = before;
|
|
512
|
+
issues.push(...kept);
|
|
417
513
|
}
|
|
418
514
|
return issues;
|
|
419
515
|
}
|
|
@@ -472,14 +568,14 @@ function scanListViews(listViews, wherePrefix, pathPrefix, out) {
|
|
|
472
568
|
function validateListViewMode(stack) {
|
|
473
569
|
const out = [];
|
|
474
570
|
asArray3(stack.objects).forEach((obj, i) => {
|
|
475
|
-
const
|
|
476
|
-
scanListViews(obj.listViews,
|
|
571
|
+
const label2 = typeof obj.name === "string" ? `object "${obj.name}"` : `objects[${i}]`;
|
|
572
|
+
scanListViews(obj.listViews, label2, `objects[${i}]`, out);
|
|
477
573
|
});
|
|
478
574
|
asArray3(stack.views).forEach((view, i) => {
|
|
479
575
|
const named = typeof view.objectName === "string" ? view.objectName : typeof view.name === "string" ? view.name : void 0;
|
|
480
|
-
const
|
|
481
|
-
scanView(view.list, `${
|
|
482
|
-
scanListViews(view.listViews,
|
|
576
|
+
const label2 = named ? `view "${named}"` : `views[${i}]`;
|
|
577
|
+
scanView(view.list, `${label2} \u203A list`, `views[${i}].list`, out);
|
|
578
|
+
scanListViews(view.listViews, label2, `views[${i}]`, out);
|
|
483
579
|
});
|
|
484
580
|
return out;
|
|
485
581
|
}
|
|
@@ -487,6 +583,8 @@ function validateListViewMode(stack) {
|
|
|
487
583
|
// src/validate-flow-trigger-readiness.ts
|
|
488
584
|
var FLOW_TRIGGER_UNKNOWN_OBJECT = "flow-trigger-unknown-object";
|
|
489
585
|
var FLOW_DRAFT_STATUS_AMBIGUOUS = "flow-draft-status-ambiguous";
|
|
586
|
+
var FLOW_TRIGGER_UNKNOWN_EVENT = "flow-trigger-unknown-event";
|
|
587
|
+
var VALID_RECORD_TRIGGER = /^record-(?:before|after)-(?:create|insert|update|delete|write)$/;
|
|
490
588
|
function asArray4(v) {
|
|
491
589
|
if (Array.isArray(v)) return v;
|
|
492
590
|
if (v && typeof v === "object") {
|
|
@@ -514,10 +612,11 @@ function validateFlowTriggerReadiness(stack) {
|
|
|
514
612
|
const start = startNodeOf(flow);
|
|
515
613
|
const config = start?.node.config ?? {};
|
|
516
614
|
const triggerType = typeof config.triggerType === "string" ? config.triggerType : void 0;
|
|
517
|
-
const
|
|
615
|
+
const isRecordTriggered2 = !!triggerType && triggerType.startsWith("record-");
|
|
616
|
+
const isArrayRecordTriggered = Array.isArray(config.triggerType) && config.triggerType.some((t) => typeof t === "string" && t.startsWith("record-"));
|
|
518
617
|
const isTimeRelative = config.timeRelative != null && typeof config.timeRelative === "object";
|
|
519
|
-
const isAutoTriggered =
|
|
520
|
-
if (
|
|
618
|
+
const isAutoTriggered = isRecordTriggered2 || triggerType === "api" || config.schedule != null || isTimeRelative || flow.type === "schedule" || flow.type === "api";
|
|
619
|
+
if (isRecordTriggered2 && start) {
|
|
521
620
|
const objectName = typeof config.objectName === "string" ? config.objectName : void 0;
|
|
522
621
|
if (objectName && !objectNames.has(objectName) && !objectName.startsWith("sys_")) {
|
|
523
622
|
findings.push({
|
|
@@ -544,6 +643,26 @@ function validateFlowTriggerReadiness(stack) {
|
|
|
544
643
|
});
|
|
545
644
|
}
|
|
546
645
|
}
|
|
646
|
+
if (start && isRecordTriggered2 && !VALID_RECORD_TRIGGER.test((triggerType ?? "").trim())) {
|
|
647
|
+
findings.push({
|
|
648
|
+
severity: "warning",
|
|
649
|
+
rule: FLOW_TRIGGER_UNKNOWN_EVENT,
|
|
650
|
+
where: `flow "${flowName}" \u203A start node`,
|
|
651
|
+
path: `flows[${flowIndex}].nodes[${start.index}].config.triggerType`,
|
|
652
|
+
message: `triggerType '${triggerType}' is not a recognized record trigger \u2014 the flow binds to the record-change trigger but never fires (the runtime stays silent about it).`,
|
|
653
|
+
hint: `Use record-{before,after}-{create,update,delete,write}. 'write' fires on create OR update in one flow (#3427); create/insert are synonyms. There is no "any change" token \u2014 pick the specific event(s).`
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
if (start && isArrayRecordTriggered) {
|
|
657
|
+
findings.push({
|
|
658
|
+
severity: "warning",
|
|
659
|
+
rule: FLOW_TRIGGER_UNKNOWN_EVENT,
|
|
660
|
+
where: `flow "${flowName}" \u203A start node`,
|
|
661
|
+
path: `flows[${flowIndex}].nodes[${start.index}].config.triggerType`,
|
|
662
|
+
message: `triggerType is an array (${JSON.stringify(config.triggerType)}), which is not supported \u2014 a start node takes a single trigger event, so the flow binds to nothing and never fires (the runtime stays silent about it).`,
|
|
663
|
+
hint: `Use one triggerType string. For "created or updated" use record-after-write (one flow, both events, #3427). For any other combination, author one flow per event \u2014 multi-event arrays are deferred (#3457).`
|
|
664
|
+
});
|
|
665
|
+
}
|
|
547
666
|
if (isAutoTriggered && (flow.status == null || flow.status === "draft")) {
|
|
548
667
|
findings.push({
|
|
549
668
|
severity: "warning",
|
|
@@ -558,6 +677,303 @@ function validateFlowTriggerReadiness(stack) {
|
|
|
558
677
|
return findings;
|
|
559
678
|
}
|
|
560
679
|
|
|
680
|
+
// src/validate-flow-template-paths.ts
|
|
681
|
+
var FLOW_TEMPLATE_UNKNOWN_FIELD = "flow-template-unknown-field";
|
|
682
|
+
var FLOW_TEMPLATE_LOOKUP_TRAVERSAL = "flow-template-lookup-traversal";
|
|
683
|
+
function asArray5(v) {
|
|
684
|
+
if (Array.isArray(v)) return v;
|
|
685
|
+
if (v && typeof v === "object") {
|
|
686
|
+
return Object.entries(v).map(([name, def]) => ({
|
|
687
|
+
name,
|
|
688
|
+
...def
|
|
689
|
+
}));
|
|
690
|
+
}
|
|
691
|
+
return [];
|
|
692
|
+
}
|
|
693
|
+
var SYSTEM_FIELDS2 = /* @__PURE__ */ new Set([
|
|
694
|
+
"id",
|
|
695
|
+
"name",
|
|
696
|
+
"owner",
|
|
697
|
+
"owner_id",
|
|
698
|
+
"created_at",
|
|
699
|
+
"created_by",
|
|
700
|
+
"updated_at",
|
|
701
|
+
"updated_by",
|
|
702
|
+
"organization_id",
|
|
703
|
+
"tenant_id",
|
|
704
|
+
"is_deleted",
|
|
705
|
+
"deleted_at",
|
|
706
|
+
"record_type"
|
|
707
|
+
]);
|
|
708
|
+
var RELATION_TYPES = /* @__PURE__ */ new Set([
|
|
709
|
+
"lookup",
|
|
710
|
+
"master_detail",
|
|
711
|
+
"user",
|
|
712
|
+
"tree"
|
|
713
|
+
]);
|
|
714
|
+
var FILTER_GUARDED_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
715
|
+
"get_record",
|
|
716
|
+
"update_record",
|
|
717
|
+
"delete_record"
|
|
718
|
+
]);
|
|
719
|
+
function fieldTypesOf(obj) {
|
|
720
|
+
const types = /* @__PURE__ */ new Map();
|
|
721
|
+
for (const f of asArray5(obj.fields)) {
|
|
722
|
+
if (typeof f.name === "string") {
|
|
723
|
+
types.set(f.name, typeof f.type === "string" ? f.type : "");
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return types;
|
|
727
|
+
}
|
|
728
|
+
function recordRefsIn(text) {
|
|
729
|
+
const refs = [];
|
|
730
|
+
const tokenRe = /\{([^{}]+)\}/g;
|
|
731
|
+
let m;
|
|
732
|
+
while ((m = tokenRe.exec(text)) !== null) {
|
|
733
|
+
const body = m[1].trim();
|
|
734
|
+
if (!/^[A-Za-z_$][\w$]*(?:\.(?:[A-Za-z_$][\w$]*|\d+))*$/.test(body)) continue;
|
|
735
|
+
const segments = body.split(".");
|
|
736
|
+
if (segments[0] !== "record") continue;
|
|
737
|
+
const rest = segments.slice(1);
|
|
738
|
+
if (rest.length > 0) refs.push(rest);
|
|
739
|
+
}
|
|
740
|
+
return refs;
|
|
741
|
+
}
|
|
742
|
+
function stringLeaves(value, out) {
|
|
743
|
+
if (typeof value === "string") {
|
|
744
|
+
if (value.includes("{")) out.push(value);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
if (Array.isArray(value)) {
|
|
748
|
+
for (const v of value) stringLeaves(v, out);
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
if (value && typeof value === "object") {
|
|
752
|
+
for (const v of Object.values(value)) stringLeaves(v, out);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
var NODE_CONFIG_KEYS = [
|
|
756
|
+
"config",
|
|
757
|
+
"notify",
|
|
758
|
+
"update_record",
|
|
759
|
+
"create_record",
|
|
760
|
+
"http",
|
|
761
|
+
"script",
|
|
762
|
+
"screen",
|
|
763
|
+
"wait",
|
|
764
|
+
"approval",
|
|
765
|
+
"connector_action",
|
|
766
|
+
"subflow",
|
|
767
|
+
"decision",
|
|
768
|
+
"start"
|
|
769
|
+
];
|
|
770
|
+
function collectNodeLeaves(node, guarded) {
|
|
771
|
+
const filterLeaves = [];
|
|
772
|
+
const otherLeaves = [];
|
|
773
|
+
for (const key of NODE_CONFIG_KEYS) {
|
|
774
|
+
if (!(key in node)) continue;
|
|
775
|
+
const block = node[key];
|
|
776
|
+
const splitFilter = guarded && !!block && typeof block === "object" && !Array.isArray(block);
|
|
777
|
+
if (splitFilter) {
|
|
778
|
+
const { filter, ...rest } = block;
|
|
779
|
+
const inFilter = [];
|
|
780
|
+
stringLeaves(filter, inFilter);
|
|
781
|
+
for (const text of inFilter) filterLeaves.push({ text, inFilter: true });
|
|
782
|
+
const outside = [];
|
|
783
|
+
stringLeaves(rest, outside);
|
|
784
|
+
for (const text of outside) otherLeaves.push({ text, inFilter: false });
|
|
785
|
+
continue;
|
|
786
|
+
}
|
|
787
|
+
const plain = [];
|
|
788
|
+
stringLeaves(block, plain);
|
|
789
|
+
for (const text of plain) otherLeaves.push({ text, inFilter: false });
|
|
790
|
+
}
|
|
791
|
+
return [...filterLeaves, ...otherLeaves];
|
|
792
|
+
}
|
|
793
|
+
function isRecordTriggered(flow, startConfig) {
|
|
794
|
+
if (flow.type === "record_change") return true;
|
|
795
|
+
const triggerType = typeof startConfig.triggerType === "string" ? startConfig.triggerType : void 0;
|
|
796
|
+
return !!triggerType && triggerType.startsWith("record-");
|
|
797
|
+
}
|
|
798
|
+
function boundObjectOf(flow) {
|
|
799
|
+
const nodes = Array.isArray(flow.nodes) ? flow.nodes : [];
|
|
800
|
+
const start = nodes.find((n) => n?.type === "start");
|
|
801
|
+
if (!start) return void 0;
|
|
802
|
+
const config = start.config ?? {};
|
|
803
|
+
const typed = start.start ?? {};
|
|
804
|
+
const fromConfig = typeof config.objectName === "string" ? config.objectName : void 0;
|
|
805
|
+
const fromTyped = typeof typed.objectName === "string" ? typed.objectName : void 0;
|
|
806
|
+
return fromConfig ?? fromTyped;
|
|
807
|
+
}
|
|
808
|
+
function declaredExpandOf(flow) {
|
|
809
|
+
const nodes = Array.isArray(flow.nodes) ? flow.nodes : [];
|
|
810
|
+
const start = nodes.find((n) => n?.type === "start");
|
|
811
|
+
const raw = (start?.config ?? {}).expand;
|
|
812
|
+
if (typeof raw === "string") return new Set(raw ? [raw] : []);
|
|
813
|
+
if (Array.isArray(raw)) return new Set(raw.filter((r) => typeof r === "string" && r.length > 0));
|
|
814
|
+
return /* @__PURE__ */ new Set();
|
|
815
|
+
}
|
|
816
|
+
function validateFlowTemplatePaths(stack) {
|
|
817
|
+
const findings = [];
|
|
818
|
+
const flows = asArray5(stack.flows);
|
|
819
|
+
if (flows.length === 0) return findings;
|
|
820
|
+
const objectsByName = /* @__PURE__ */ new Map();
|
|
821
|
+
for (const obj of asArray5(stack.objects)) {
|
|
822
|
+
if (typeof obj.name === "string") objectsByName.set(obj.name, obj);
|
|
823
|
+
}
|
|
824
|
+
flows.forEach((flow, flowIndex) => {
|
|
825
|
+
const flowName = typeof flow.name === "string" ? flow.name : `#${flowIndex}`;
|
|
826
|
+
const nodes = Array.isArray(flow.nodes) ? flow.nodes : [];
|
|
827
|
+
const start = nodes.find((n) => n?.type === "start")?.config ?? {};
|
|
828
|
+
if (!isRecordTriggered(flow, start)) return;
|
|
829
|
+
const objectName = boundObjectOf(flow);
|
|
830
|
+
if (!objectName) return;
|
|
831
|
+
const obj = objectsByName.get(objectName);
|
|
832
|
+
if (!obj) return;
|
|
833
|
+
const fieldTypes = fieldTypesOf(obj);
|
|
834
|
+
const expandSet = declaredExpandOf(flow);
|
|
835
|
+
nodes.forEach((node, nodeIndex) => {
|
|
836
|
+
if (typeof node !== "object" || !node) return;
|
|
837
|
+
const nodeLabel = typeof node.type === "string" ? node.type : typeof node.id === "string" ? node.id : `#${nodeIndex}`;
|
|
838
|
+
const nodeType = typeof node.type === "string" ? node.type : "";
|
|
839
|
+
const guarded = FILTER_GUARDED_NODE_TYPES.has(nodeType);
|
|
840
|
+
const leaves = collectNodeLeaves(node, guarded);
|
|
841
|
+
if (leaves.length === 0) return;
|
|
842
|
+
const seenUnknown = /* @__PURE__ */ new Set();
|
|
843
|
+
const seenTraversal = /* @__PURE__ */ new Set();
|
|
844
|
+
for (const leaf of leaves) {
|
|
845
|
+
const inFilter = leaf.inFilter;
|
|
846
|
+
for (const rest of recordRefsIn(leaf.text)) {
|
|
847
|
+
const head = rest[0];
|
|
848
|
+
const hasSubPath = rest.length > 1;
|
|
849
|
+
const nextIsIdentifier = hasSubPath && !/^\d+$/.test(rest[1]);
|
|
850
|
+
const isKnown = fieldTypes.has(head) || SYSTEM_FIELDS2.has(head);
|
|
851
|
+
if (!isKnown) {
|
|
852
|
+
if (seenUnknown.has(head)) continue;
|
|
853
|
+
seenUnknown.add(head);
|
|
854
|
+
findings.push({
|
|
855
|
+
severity: inFilter ? "error" : "warning",
|
|
856
|
+
rule: FLOW_TEMPLATE_UNKNOWN_FIELD,
|
|
857
|
+
where: `flow "${flowName}" node "${nodeLabel}"`,
|
|
858
|
+
path: `flows[${flowIndex}].nodes[${nodeIndex}]`,
|
|
859
|
+
message: inFilter ? `${nodeType} filter references '{record.${rest.join(".")}}', but '${head}' is not a field on object '${objectName}' \u2014 the token resolves to nothing, which DROPS the condition from the query instead of narrowing it. The node refuses to run at execution time (#3810).` : `template references '{record.${rest.join(".")}}', but '${head}' is not a field on object '${objectName}' \u2014 it resolves to an empty string at runtime (silently).`,
|
|
860
|
+
hint: inFilter ? `Check the field name against the object's field definitions (e.g. '{record.full_name}', not '{record.full_naem}'); system columns like id/created_at/owner are also addressable. This gates the build rather than warning: an absent condition WIDENS the query, so the runtime has already decided to refuse this node.` : `Check the field name against the object's field definitions (e.g. '{record.full_name}', not '{record.full_naem}'). System columns like id/created_at/owner are also addressable.`
|
|
861
|
+
});
|
|
862
|
+
continue;
|
|
863
|
+
}
|
|
864
|
+
if (nextIsIdentifier) {
|
|
865
|
+
const headType = fieldTypes.get(head) ?? "";
|
|
866
|
+
if (RELATION_TYPES.has(headType) && !expandSet.has(head)) {
|
|
867
|
+
const key = rest.join(".");
|
|
868
|
+
if (seenTraversal.has(key)) continue;
|
|
869
|
+
seenTraversal.add(key);
|
|
870
|
+
findings.push({
|
|
871
|
+
severity: inFilter ? "error" : "warning",
|
|
872
|
+
rule: FLOW_TEMPLATE_LOOKUP_TRAVERSAL,
|
|
873
|
+
where: `flow "${flowName}" node "${nodeLabel}"`,
|
|
874
|
+
path: `flows[${flowIndex}].nodes[${nodeIndex}]`,
|
|
875
|
+
message: inFilter ? `${nodeType} filter references '{record.${key}}', a cross-object hop through the ${headType} field '${head}' \u2014 the flow record carries '${head}' as a scalar id, not an expanded object, so the token resolves to nothing and the condition is DROPPED from the query instead of narrowing it. The node refuses to run at execution time (#3810).` : `template references '{record.${key}}', a cross-object hop through the ${headType} field '${head}' \u2014 the flow record carries '${head}' as a scalar id, not an expanded object, so this resolves to an empty string at runtime (silently).`,
|
|
876
|
+
hint: inFilter ? `Opt in to resolve it: add '${head}' to the start node's config.expand (#3475) and the engine re-reads it as the run's identity. Otherwise filter on the foreign-key id directly ('{record.${head}}'), or project the value via a formula field on '${objectName}'. This gates the build rather than warning: an absent condition WIDENS the query.` : `Opt in to resolve it: add '${head}' to the start node's config.expand (#3475) and the engine re-reads it as the run's identity. Otherwise reference the foreign-key id directly ('{record.${head}}'), or project the value via a formula field on '${objectName}'.`
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
return findings;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// src/validate-readonly-flow-writes.ts
|
|
888
|
+
var FLOW_UPDATE_READONLY_FIELD = "flow-update-readonly-field";
|
|
889
|
+
var FLOW_UPDATE_READONLY_WHEN_FIELD = "flow-update-readonly-when-field";
|
|
890
|
+
function asArray6(v) {
|
|
891
|
+
if (Array.isArray(v)) return v;
|
|
892
|
+
if (v && typeof v === "object") {
|
|
893
|
+
return Object.entries(v).map(([name, def]) => ({
|
|
894
|
+
name,
|
|
895
|
+
...def
|
|
896
|
+
}));
|
|
897
|
+
}
|
|
898
|
+
return [];
|
|
899
|
+
}
|
|
900
|
+
function buildReadonlyIndex(objects) {
|
|
901
|
+
const idx = /* @__PURE__ */ new Map();
|
|
902
|
+
for (const obj of objects) {
|
|
903
|
+
const name = typeof obj.name === "string" ? obj.name : void 0;
|
|
904
|
+
if (!name) continue;
|
|
905
|
+
const fieldMap = /* @__PURE__ */ new Map();
|
|
906
|
+
const collect = (fieldName, def) => {
|
|
907
|
+
const rw = def?.readonlyWhen;
|
|
908
|
+
const readonlyWhen = rw != null && !(typeof rw === "string" && rw.trim() === "");
|
|
909
|
+
fieldMap.set(fieldName, { readonly: def?.readonly === true, readonlyWhen });
|
|
910
|
+
};
|
|
911
|
+
const fields = obj.fields;
|
|
912
|
+
if (Array.isArray(fields)) {
|
|
913
|
+
for (const f of fields) {
|
|
914
|
+
const fn = f?.name;
|
|
915
|
+
if (typeof fn === "string") collect(fn, f);
|
|
916
|
+
}
|
|
917
|
+
} else if (fields && typeof fields === "object") {
|
|
918
|
+
for (const [fn, def] of Object.entries(fields)) collect(fn, def);
|
|
919
|
+
}
|
|
920
|
+
idx.set(name, fieldMap);
|
|
921
|
+
}
|
|
922
|
+
return idx;
|
|
923
|
+
}
|
|
924
|
+
function readLiteralObjectName(config) {
|
|
925
|
+
const raw = config.objectName ?? config.object;
|
|
926
|
+
if (typeof raw !== "string" || raw.includes("{")) return void 0;
|
|
927
|
+
return raw || void 0;
|
|
928
|
+
}
|
|
929
|
+
function validateReadonlyFlowWrites(stack) {
|
|
930
|
+
const findings = [];
|
|
931
|
+
const flows = asArray6(stack.flows);
|
|
932
|
+
if (flows.length === 0) return findings;
|
|
933
|
+
const roIndex = buildReadonlyIndex(asArray6(stack.objects));
|
|
934
|
+
flows.forEach((flow, flowIndex) => {
|
|
935
|
+
if (flow.runAs === "system") return;
|
|
936
|
+
const runAs = flow.runAs === "user" || flow.runAs === "system" ? flow.runAs : "user";
|
|
937
|
+
const flowName = typeof flow.name === "string" ? flow.name : `#${flowIndex}`;
|
|
938
|
+
const nodes = Array.isArray(flow.nodes) ? flow.nodes : [];
|
|
939
|
+
nodes.forEach((node, nodeIndex) => {
|
|
940
|
+
if (node?.type !== "update_record") return;
|
|
941
|
+
const config = node.config ?? {};
|
|
942
|
+
const objectName = readLiteralObjectName(config);
|
|
943
|
+
if (!objectName) return;
|
|
944
|
+
const fieldMap = roIndex.get(objectName);
|
|
945
|
+
if (!fieldMap) return;
|
|
946
|
+
const fields = config.fields;
|
|
947
|
+
if (!fields || typeof fields !== "object" || Array.isArray(fields)) return;
|
|
948
|
+
const nodeName = typeof node.label === "string" && node.label ? node.label : typeof node.id === "string" && node.id ? node.id : `#${nodeIndex}`;
|
|
949
|
+
for (const fieldName of Object.keys(fields)) {
|
|
950
|
+
const meta = fieldMap.get(fieldName);
|
|
951
|
+
if (!meta) continue;
|
|
952
|
+
if (meta.readonly) {
|
|
953
|
+
findings.push({
|
|
954
|
+
severity: "error",
|
|
955
|
+
rule: FLOW_UPDATE_READONLY_FIELD,
|
|
956
|
+
where: `flow "${flowName}" \u203A node "${nodeName}"`,
|
|
957
|
+
path: `flows[${flowIndex}].nodes[${nodeIndex}].config.fields.${fieldName}`,
|
|
958
|
+
message: `writes field '${fieldName}', which object '${objectName}' declares readonly:true. Under runAs:'${runAs}' the engine silently strips readonly fields from the UPDATE payload (#2948), so this write never lands \u2014 while the step still reports success.`,
|
|
959
|
+
hint: `If automation is meant to maintain this field, declare the flow runAs:'system' (the intended channel \u2014 readonly governs the end-user/API surface, not trusted system writers). Otherwise remove '${fieldName}' from this update_record node.`
|
|
960
|
+
});
|
|
961
|
+
} else if (meta.readonlyWhen) {
|
|
962
|
+
findings.push({
|
|
963
|
+
severity: "warning",
|
|
964
|
+
rule: FLOW_UPDATE_READONLY_WHEN_FIELD,
|
|
965
|
+
where: `flow "${flowName}" \u203A node "${nodeName}"`,
|
|
966
|
+
path: `flows[${flowIndex}].nodes[${nodeIndex}].config.fields.${fieldName}`,
|
|
967
|
+
message: `writes field '${fieldName}', which object '${objectName}' declares readonlyWhen. On records where that predicate is TRUE, a runAs:'${runAs}' UPDATE strips the field (#3042), so this write may silently not land depending on the record's state.`,
|
|
968
|
+
hint: `If automation must maintain this field regardless of record state, run the flow runAs:'system'. Otherwise confirm this node only targets records whose readonlyWhen predicate is FALSE.`
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
});
|
|
974
|
+
return findings;
|
|
975
|
+
}
|
|
976
|
+
|
|
561
977
|
// src/validate-view-containers.ts
|
|
562
978
|
var VIEW_CONTAINER_SHAPE = "view-container-shape";
|
|
563
979
|
var CONTAINER_SLOT_KEYS = ["list", "form", "listViews", "formViews"];
|
|
@@ -580,13 +996,13 @@ function validateViewContainers(stack) {
|
|
|
580
996
|
const rec = value;
|
|
581
997
|
if (rec.viewKind != null) continue;
|
|
582
998
|
if (containerViewCount(rec) > 0) continue;
|
|
583
|
-
const
|
|
999
|
+
const label2 = typeof rec.name === "string" ? ` ("${rec.name}")` : "";
|
|
584
1000
|
const hasContainerSlot = CONTAINER_SLOT_KEYS.some((k) => k in rec);
|
|
585
1001
|
const looksFlat = !hasContainerSlot && ["type", "columns", "data", "filter", "sort"].some((k) => k in rec);
|
|
586
1002
|
out.push({
|
|
587
1003
|
severity: "error",
|
|
588
1004
|
rule: VIEW_CONTAINER_SHAPE,
|
|
589
|
-
where: `views${key}${
|
|
1005
|
+
where: `views${key}${label2}`,
|
|
590
1006
|
path: `views${key}`,
|
|
591
1007
|
message: looksFlat ? "Flat list-view object is not a view container: `ViewSchema` strips its keys, so it parses to an EMPTY container \u2014 zero views register and the Console renders no view for it." : "View container defines no views \u2014 all of `list` / `form` / `listViews` / `formViews` are absent or empty, so nothing registers.",
|
|
592
1008
|
hint: "Wrap every view in a defineView container: defineView({ list: { type, data, columns, ... }, listViews: { ... }, formViews: { ... } }). See examples/app-showcase/src/ui/views/task.view.ts."
|
|
@@ -798,7 +1214,7 @@ function looksLikeTailwind(className) {
|
|
|
798
1214
|
return false;
|
|
799
1215
|
});
|
|
800
1216
|
}
|
|
801
|
-
function
|
|
1217
|
+
function asArray7(v) {
|
|
802
1218
|
if (Array.isArray(v)) return v;
|
|
803
1219
|
if (v && typeof v === "object") {
|
|
804
1220
|
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
@@ -891,13 +1307,13 @@ function checkNode(node, pageName, path, findings) {
|
|
|
891
1307
|
}
|
|
892
1308
|
function validateResponsiveStyles(stack) {
|
|
893
1309
|
const findings = [];
|
|
894
|
-
const pages =
|
|
1310
|
+
const pages = asArray7(stack.pages);
|
|
895
1311
|
for (let p = 0; p < pages.length; p++) {
|
|
896
1312
|
const page = pages[p];
|
|
897
1313
|
const pageName = typeof page.name === "string" ? page.name : `pages[${p}]`;
|
|
898
|
-
const regions =
|
|
1314
|
+
const regions = asArray7(page.regions);
|
|
899
1315
|
for (let r = 0; r < regions.length; r++) {
|
|
900
|
-
const components =
|
|
1316
|
+
const components = asArray7(regions[r].components);
|
|
901
1317
|
for (let c = 0; c < components.length; c++) {
|
|
902
1318
|
checkNode(components[c], pageName, `pages[${p}].regions[${r}].components[${c}]`, findings);
|
|
903
1319
|
}
|
|
@@ -908,10 +1324,10 @@ function validateResponsiveStyles(stack) {
|
|
|
908
1324
|
|
|
909
1325
|
// src/validate-jsx-pages.ts
|
|
910
1326
|
import { parseJsx, compile } from "@objectstack/sdui-parser";
|
|
911
|
-
var
|
|
1327
|
+
var asArray8 = (v) => Array.isArray(v) ? v : [];
|
|
912
1328
|
function validateJsxPages(stack, opts = {}) {
|
|
913
1329
|
const findings = [];
|
|
914
|
-
const pages =
|
|
1330
|
+
const pages = asArray8(stack.pages);
|
|
915
1331
|
for (let p = 0; p < pages.length; p++) {
|
|
916
1332
|
const page = pages[p];
|
|
917
1333
|
if (!page || page.kind !== "html" && page.kind !== "jsx") continue;
|
|
@@ -958,10 +1374,10 @@ function loadSucraseTransform() {
|
|
|
958
1374
|
}
|
|
959
1375
|
return cachedTransform;
|
|
960
1376
|
}
|
|
961
|
-
var
|
|
1377
|
+
var asArray9 = (v) => Array.isArray(v) ? v : [];
|
|
962
1378
|
function validateReactPages(stack) {
|
|
963
1379
|
const findings = [];
|
|
964
|
-
const pages =
|
|
1380
|
+
const pages = asArray9(stack.pages);
|
|
965
1381
|
for (let p = 0; p < pages.length; p++) {
|
|
966
1382
|
const page = pages[p];
|
|
967
1383
|
if (!page || page.kind !== "react") continue;
|
|
@@ -998,7 +1414,7 @@ function validateReactPages(stack) {
|
|
|
998
1414
|
|
|
999
1415
|
// src/validate-react-page-props.ts
|
|
1000
1416
|
import { createRequire as createRequire2 } from "module";
|
|
1001
|
-
import { REACT_BLOCKS } from "@objectstack/spec/ui";
|
|
1417
|
+
import { REACT_BLOCKS, chartAggregateResultKeys } from "@objectstack/spec/ui";
|
|
1002
1418
|
var cachedTs = null;
|
|
1003
1419
|
function loadTypeScript() {
|
|
1004
1420
|
if (cachedTs) return cachedTs;
|
|
@@ -1012,7 +1428,7 @@ function loadTypeScript() {
|
|
|
1012
1428
|
}
|
|
1013
1429
|
return cachedTs;
|
|
1014
1430
|
}
|
|
1015
|
-
var
|
|
1431
|
+
var asArray10 = (v) => Array.isArray(v) ? v : [];
|
|
1016
1432
|
var BLOCKS = new Map(
|
|
1017
1433
|
REACT_BLOCKS.map((b) => [
|
|
1018
1434
|
b.tag,
|
|
@@ -1049,9 +1465,173 @@ function nearestKnown(prop, known) {
|
|
|
1049
1465
|
}
|
|
1050
1466
|
return bestD <= 2 ? best : null;
|
|
1051
1467
|
}
|
|
1468
|
+
var NOT_STATIC = /* @__PURE__ */ Symbol("not-static");
|
|
1469
|
+
function staticValue(tsc, sf, node) {
|
|
1470
|
+
if (!node) return NOT_STATIC;
|
|
1471
|
+
if (tsc.isParenthesizedExpression(node)) return staticValue(tsc, sf, node.expression);
|
|
1472
|
+
if (tsc.isStringLiteral(node) || tsc.isNoSubstitutionTemplateLiteral(node)) return node.text;
|
|
1473
|
+
if (tsc.isNumericLiteral(node)) return Number(node.text);
|
|
1474
|
+
if (node.kind === tsc.SyntaxKind.TrueKeyword) return true;
|
|
1475
|
+
if (node.kind === tsc.SyntaxKind.FalseKeyword) return false;
|
|
1476
|
+
if (node.kind === tsc.SyntaxKind.NullKeyword) return null;
|
|
1477
|
+
if (tsc.isArrayLiteralExpression(node)) {
|
|
1478
|
+
const out = [];
|
|
1479
|
+
for (const el of node.elements) {
|
|
1480
|
+
const v = staticValue(tsc, sf, el);
|
|
1481
|
+
if (v === NOT_STATIC) return NOT_STATIC;
|
|
1482
|
+
out.push(v);
|
|
1483
|
+
}
|
|
1484
|
+
return out;
|
|
1485
|
+
}
|
|
1486
|
+
if (tsc.isObjectLiteralExpression(node)) {
|
|
1487
|
+
const out = {};
|
|
1488
|
+
for (const p of node.properties) {
|
|
1489
|
+
if (!tsc.isPropertyAssignment(p)) return NOT_STATIC;
|
|
1490
|
+
const key = tsc.isIdentifier(p.name) || tsc.isStringLiteral(p.name) ? p.name.text : null;
|
|
1491
|
+
if (key === null) return NOT_STATIC;
|
|
1492
|
+
const v = staticValue(tsc, sf, p.initializer);
|
|
1493
|
+
if (v === NOT_STATIC) return NOT_STATIC;
|
|
1494
|
+
out[key] = v;
|
|
1495
|
+
}
|
|
1496
|
+
return out;
|
|
1497
|
+
}
|
|
1498
|
+
return NOT_STATIC;
|
|
1499
|
+
}
|
|
1500
|
+
function attrValue(tsc, sf, attr) {
|
|
1501
|
+
const init = attr.initializer;
|
|
1502
|
+
if (!init) return true;
|
|
1503
|
+
if (tsc.isStringLiteral(init)) return init.text;
|
|
1504
|
+
if (tsc.isJsxExpression(init)) return staticValue(tsc, sf, init.expression);
|
|
1505
|
+
return NOT_STATIC;
|
|
1506
|
+
}
|
|
1507
|
+
var REACT_CHART_FIELD_UNKNOWN = "react-chart-field-unknown";
|
|
1508
|
+
var REACT_CHART_AGGREGATE_INVALID = "react-chart-aggregate-invalid";
|
|
1509
|
+
var REACT_CHART_AXIS_UNKNOWN = "react-chart-axis-unknown";
|
|
1510
|
+
var CHART_FUNCTIONS = ["count", "sum", "avg", "min", "max"];
|
|
1511
|
+
var SYSTEM_FIELDS3 = /* @__PURE__ */ new Set([
|
|
1512
|
+
"id",
|
|
1513
|
+
"created_at",
|
|
1514
|
+
"created_by",
|
|
1515
|
+
"updated_at",
|
|
1516
|
+
"updated_by",
|
|
1517
|
+
"owner_id",
|
|
1518
|
+
"organization_id",
|
|
1519
|
+
"tenant_id",
|
|
1520
|
+
"user_id",
|
|
1521
|
+
"deleted_at"
|
|
1522
|
+
]);
|
|
1523
|
+
function namedArray(v) {
|
|
1524
|
+
if (Array.isArray(v)) return v.filter((x) => !!x && typeof x === "object");
|
|
1525
|
+
if (v && typeof v === "object") {
|
|
1526
|
+
return Object.entries(v).map(([name, def]) => ({
|
|
1527
|
+
name,
|
|
1528
|
+
...def && typeof def === "object" ? def : {}
|
|
1529
|
+
}));
|
|
1530
|
+
}
|
|
1531
|
+
return [];
|
|
1532
|
+
}
|
|
1533
|
+
function indexObjectFields(stack) {
|
|
1534
|
+
const out = /* @__PURE__ */ new Map();
|
|
1535
|
+
for (const obj of namedArray(stack.objects)) {
|
|
1536
|
+
const name = typeof obj.name === "string" ? obj.name : void 0;
|
|
1537
|
+
if (!name) continue;
|
|
1538
|
+
const names = /* @__PURE__ */ new Set();
|
|
1539
|
+
for (const f of namedArray(obj.fields)) {
|
|
1540
|
+
if (typeof f.name === "string" && f.name) names.add(f.name);
|
|
1541
|
+
}
|
|
1542
|
+
out.set(name, names);
|
|
1543
|
+
}
|
|
1544
|
+
return out;
|
|
1545
|
+
}
|
|
1546
|
+
var isRec = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
1547
|
+
var strOf = (v) => typeof v === "string" && v.length > 0 ? v : void 0;
|
|
1548
|
+
function checkObjectChart(attrs, objectFields, findings) {
|
|
1549
|
+
const { values, where, path } = attrs;
|
|
1550
|
+
const push = (severity, rule, message, hint) => findings.push({ severity, rule, where, path, message, hint });
|
|
1551
|
+
if (values.has("data")) return;
|
|
1552
|
+
const aggregate = values.get("aggregate");
|
|
1553
|
+
if (aggregate === void 0 || aggregate === NOT_STATIC) return;
|
|
1554
|
+
if (!isRec(aggregate)) return;
|
|
1555
|
+
const fn = strOf(aggregate.function);
|
|
1556
|
+
const field = strOf(aggregate.field);
|
|
1557
|
+
const groupBy = aggregate.groupBy;
|
|
1558
|
+
const groupByField = strOf(groupBy) ?? (isRec(groupBy) ? strOf(groupBy.field) : void 0);
|
|
1559
|
+
if (fn && !CHART_FUNCTIONS.includes(fn)) {
|
|
1560
|
+
push(
|
|
1561
|
+
"error",
|
|
1562
|
+
REACT_CHART_AGGREGATE_INVALID,
|
|
1563
|
+
`aggregate.function "${fn}" is not an aggregation this chart can run.`,
|
|
1564
|
+
`Use one of: ${CHART_FUNCTIONS.join(", ")}.`
|
|
1565
|
+
);
|
|
1566
|
+
} else if (fn && fn !== "count" && !field) {
|
|
1567
|
+
push(
|
|
1568
|
+
"error",
|
|
1569
|
+
REACT_CHART_AGGREGATE_INVALID,
|
|
1570
|
+
`aggregate.function "${fn}" has no "field" to aggregate.`,
|
|
1571
|
+
'Add aggregate.field, or use function "count" (the only one that may omit it).'
|
|
1572
|
+
);
|
|
1573
|
+
}
|
|
1574
|
+
const objectName = strOf(values.get("objectName"));
|
|
1575
|
+
const known = objectName ? objectFields.get(objectName) : void 0;
|
|
1576
|
+
if (objectName && known) {
|
|
1577
|
+
const fieldRef = (name, prop) => {
|
|
1578
|
+
if (!name) return;
|
|
1579
|
+
if (name.includes(".")) return;
|
|
1580
|
+
if (known.has(name) || SYSTEM_FIELDS3.has(name)) return;
|
|
1581
|
+
push(
|
|
1582
|
+
"error",
|
|
1583
|
+
REACT_CHART_FIELD_UNKNOWN,
|
|
1584
|
+
`aggregate.${prop} "${name}" is not a field on object "${objectName}" \u2014 the aggregate query has nothing to ${prop === "groupBy" ? "group by" : "aggregate"}, so the chart comes back empty.`,
|
|
1585
|
+
`Fix the field name, or add "${name}" to ${objectName}.` + (known.size > 0 ? ` Object fields: ${[...known].sort().join(", ")}.` : "")
|
|
1586
|
+
);
|
|
1587
|
+
};
|
|
1588
|
+
fieldRef(field, "field");
|
|
1589
|
+
fieldRef(groupByField, "groupBy");
|
|
1590
|
+
}
|
|
1591
|
+
const keys = chartAggregateResultKeys({ field, function: fn, groupBy });
|
|
1592
|
+
const columns = [keys.category, keys.value].filter((k) => !!k);
|
|
1593
|
+
if (columns.length === 0) return;
|
|
1594
|
+
const axisRef = (name, prop) => {
|
|
1595
|
+
if (!name) return;
|
|
1596
|
+
if (columns.includes(name)) return;
|
|
1597
|
+
if (keys.comparison && name === keys.comparison) return;
|
|
1598
|
+
push(
|
|
1599
|
+
"error",
|
|
1600
|
+
REACT_CHART_AXIS_UNKNOWN,
|
|
1601
|
+
`"${name}" is not a column this aggregate returns, so the axis plots nothing. Object-bound aggregate rows are keyed by the RAW FIELD NAMES (unlike a dataset, whose rows are keyed by measure name).`,
|
|
1602
|
+
`Result columns: ${columns.join(", ")}` + (keys.comparison ? ` (plus "${keys.comparison}" with a comparison overlay)` : "") + `. Bind ${prop} to one of them.`
|
|
1603
|
+
);
|
|
1604
|
+
};
|
|
1605
|
+
const xAxisRaw = values.get("xAxis");
|
|
1606
|
+
const categoryAxis = strOf(values.get("xAxisKey")) ?? strOf(xAxisRaw) ?? (isRec(xAxisRaw) ? strOf(xAxisRaw.field) : void 0);
|
|
1607
|
+
const categoryProp = values.has("xAxisKey") ? "xAxisKey" : "xAxis.field";
|
|
1608
|
+
axisRef(categoryAxis, categoryProp);
|
|
1609
|
+
const yAxisRaw = values.get("yAxis");
|
|
1610
|
+
const yAxisList = Array.isArray(yAxisRaw) ? yAxisRaw : yAxisRaw !== void 0 ? [yAxisRaw] : [];
|
|
1611
|
+
for (const a of yAxisList) {
|
|
1612
|
+
axisRef(strOf(a) ?? (isRec(a) ? strOf(a.field) : void 0), "yAxis[].field");
|
|
1613
|
+
}
|
|
1614
|
+
const series = values.get("series");
|
|
1615
|
+
if (Array.isArray(series)) {
|
|
1616
|
+
for (const s of series) {
|
|
1617
|
+
if (!isRec(s)) continue;
|
|
1618
|
+
const dataKey = strOf(s.dataKey);
|
|
1619
|
+
axisRef(dataKey ?? strOf(s.name), dataKey ? "series[].dataKey" : "series[].name");
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
if (categoryAxis && keys.category && categoryAxis !== keys.category && categoryAxis === keys.value) {
|
|
1623
|
+
push(
|
|
1624
|
+
"error",
|
|
1625
|
+
REACT_CHART_AXIS_UNKNOWN,
|
|
1626
|
+
`${categoryProp} "${categoryAxis}" is the aggregate's VALUE column, not its category column.`,
|
|
1627
|
+
`The category axis is keyed by groupBy \u2014 bind it to "${keys.category}".`
|
|
1628
|
+
);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1052
1631
|
function validateReactPageProps(stack) {
|
|
1053
1632
|
const findings = [];
|
|
1054
|
-
const
|
|
1633
|
+
const objectFields = indexObjectFields(stack);
|
|
1634
|
+
const pages = asArray10(stack.pages);
|
|
1055
1635
|
for (let p = 0; p < pages.length; p++) {
|
|
1056
1636
|
const page = pages[p];
|
|
1057
1637
|
if (!page || page.kind !== "react") continue;
|
|
@@ -1072,12 +1652,17 @@ function validateReactPageProps(stack) {
|
|
|
1072
1652
|
if (block) {
|
|
1073
1653
|
let hasSpread = false;
|
|
1074
1654
|
const used = /* @__PURE__ */ new Set();
|
|
1655
|
+
const values = /* @__PURE__ */ new Map();
|
|
1075
1656
|
for (const a of node.attributes.properties) {
|
|
1076
1657
|
if (tsc.isJsxSpreadAttribute(a)) {
|
|
1077
1658
|
hasSpread = true;
|
|
1078
1659
|
continue;
|
|
1079
1660
|
}
|
|
1080
|
-
if (tsc.isJsxAttribute(a))
|
|
1661
|
+
if (tsc.isJsxAttribute(a)) {
|
|
1662
|
+
const propName = a.name.getText(sf);
|
|
1663
|
+
used.add(propName);
|
|
1664
|
+
values.set(propName, attrValue(tsc, sf, a));
|
|
1665
|
+
}
|
|
1081
1666
|
}
|
|
1082
1667
|
const where = `page "${name}" \u203A <${tag}>`;
|
|
1083
1668
|
const path = `pages[${p}].source`;
|
|
@@ -1108,6 +1693,9 @@ function validateReactPageProps(stack) {
|
|
|
1108
1693
|
});
|
|
1109
1694
|
}
|
|
1110
1695
|
}
|
|
1696
|
+
if (tag === "ObjectChart" && !hasSpread) {
|
|
1697
|
+
checkObjectChart({ values, where, path }, objectFields, findings);
|
|
1698
|
+
}
|
|
1111
1699
|
}
|
|
1112
1700
|
}
|
|
1113
1701
|
tsc.forEachChild(node, visit);
|
|
@@ -1119,11 +1707,11 @@ function validateReactPageProps(stack) {
|
|
|
1119
1707
|
|
|
1120
1708
|
// src/validate-page-source-styling.ts
|
|
1121
1709
|
var PAGE_SOURCE_CLASSNAME = "page-source-className-tailwind";
|
|
1122
|
-
var
|
|
1710
|
+
var asArray11 = (v) => Array.isArray(v) ? v : [];
|
|
1123
1711
|
var CLASSNAME_ATTR = /\bclassName\s*=\s*["'{]/g;
|
|
1124
1712
|
function validatePageSourceStyling(stack) {
|
|
1125
1713
|
const findings = [];
|
|
1126
|
-
const pages =
|
|
1714
|
+
const pages = asArray11(stack.pages);
|
|
1127
1715
|
for (let p = 0; p < pages.length; p++) {
|
|
1128
1716
|
const page = pages[p];
|
|
1129
1717
|
if (!page) continue;
|
|
@@ -1152,7 +1740,7 @@ function validatePageSourceStyling(stack) {
|
|
|
1152
1740
|
import { objectTitleCompleteness } from "@objectstack/spec/data";
|
|
1153
1741
|
var TITLE_FORMAT_RETIRED = "title-format-retired";
|
|
1154
1742
|
var TITLE_UNRESOLVABLE = "title-unresolvable";
|
|
1155
|
-
function
|
|
1743
|
+
function asArray12(v) {
|
|
1156
1744
|
if (Array.isArray(v)) return v;
|
|
1157
1745
|
if (v && typeof v === "object") {
|
|
1158
1746
|
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
@@ -1161,7 +1749,7 @@ function asArray10(v) {
|
|
|
1161
1749
|
}
|
|
1162
1750
|
function validateRecordTitle(stack) {
|
|
1163
1751
|
const findings = [];
|
|
1164
|
-
const objects =
|
|
1752
|
+
const objects = asArray12(stack.objects);
|
|
1165
1753
|
for (let i = 0; i < objects.length; i++) {
|
|
1166
1754
|
const obj = objects[i];
|
|
1167
1755
|
const objName = typeof obj.name === "string" ? obj.name : `(object ${i})`;
|
|
@@ -1197,7 +1785,7 @@ var FIELD_GROUP_UNDECLARED = "field-group-undeclared";
|
|
|
1197
1785
|
var FIELD_GROUP_EMPTY = "field-group-empty";
|
|
1198
1786
|
var FIELD_GROUP_SHADOWED = "field-group-shadowed";
|
|
1199
1787
|
var SEMANTIC_ROLE_FIELD_UNKNOWN = "semantic-role-field-unknown";
|
|
1200
|
-
function
|
|
1788
|
+
function asArray13(v) {
|
|
1201
1789
|
if (Array.isArray(v)) return v;
|
|
1202
1790
|
if (v && typeof v === "object") {
|
|
1203
1791
|
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
@@ -1206,7 +1794,7 @@ function asArray11(v) {
|
|
|
1206
1794
|
}
|
|
1207
1795
|
function validateSemanticRoles(stack) {
|
|
1208
1796
|
const findings = [];
|
|
1209
|
-
const objects =
|
|
1797
|
+
const objects = asArray13(stack.objects);
|
|
1210
1798
|
for (let i = 0; i < objects.length; i++) {
|
|
1211
1799
|
const obj = objects[i];
|
|
1212
1800
|
if (!obj || typeof obj !== "object") continue;
|
|
@@ -1301,7 +1889,7 @@ function validateSemanticRoles(stack) {
|
|
|
1301
1889
|
// src/validate-form-layout.ts
|
|
1302
1890
|
var FORM_FIELD_UNKNOWN = "form-field-unknown";
|
|
1303
1891
|
var FORM_COLSPAN_ABSOLUTE = "absolute-colspan-discouraged";
|
|
1304
|
-
function
|
|
1892
|
+
function asArray14(v) {
|
|
1305
1893
|
if (Array.isArray(v)) return v;
|
|
1306
1894
|
if (v && typeof v === "object") {
|
|
1307
1895
|
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
@@ -1326,13 +1914,13 @@ function boundObject(view) {
|
|
|
1326
1914
|
function validateFormLayout(stack) {
|
|
1327
1915
|
const findings = [];
|
|
1328
1916
|
const objectFields = /* @__PURE__ */ new Map();
|
|
1329
|
-
for (const obj of
|
|
1917
|
+
for (const obj of asArray14(stack.objects)) {
|
|
1330
1918
|
const name = typeof obj.name === "string" ? obj.name : void 0;
|
|
1331
1919
|
if (!name) continue;
|
|
1332
1920
|
const fields = obj.fields && typeof obj.fields === "object" && !Array.isArray(obj.fields) ? Object.keys(obj.fields) : [];
|
|
1333
1921
|
objectFields.set(name, new Set(fields));
|
|
1334
1922
|
}
|
|
1335
|
-
const views =
|
|
1923
|
+
const views = asArray14(stack.views);
|
|
1336
1924
|
for (let i = 0; i < views.length; i++) {
|
|
1337
1925
|
const view = views[i];
|
|
1338
1926
|
if (!view || typeof view !== "object") continue;
|
|
@@ -1382,7 +1970,7 @@ var VISIBILITY_ALIAS_DEPRECATED = "visibility-alias-deprecated";
|
|
|
1382
1970
|
var VISIBILITY_ROOT_MISLAYERED = "visibility-root-mislayered";
|
|
1383
1971
|
var CANONICAL = "visibleWhen";
|
|
1384
1972
|
var ALIASES = ["visibleOn", "visibility"];
|
|
1385
|
-
function
|
|
1973
|
+
function asArray15(v) {
|
|
1386
1974
|
if (Array.isArray(v)) return v;
|
|
1387
1975
|
if (v && typeof v === "object") {
|
|
1388
1976
|
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
@@ -1444,7 +2032,7 @@ function isFieldObject(entry) {
|
|
|
1444
2032
|
function validateVisibilityPredicates(stack, opts = {}) {
|
|
1445
2033
|
const layer = opts.layer ?? "runtime";
|
|
1446
2034
|
const findings = [];
|
|
1447
|
-
const views =
|
|
2035
|
+
const views = asArray15(stack.views);
|
|
1448
2036
|
for (let i = 0; i < views.length; i++) {
|
|
1449
2037
|
const view = views[i];
|
|
1450
2038
|
if (!view || typeof view !== "object") continue;
|
|
@@ -1467,7 +2055,7 @@ function validateVisibilityPredicates(stack, opts = {}) {
|
|
|
1467
2055
|
}
|
|
1468
2056
|
}
|
|
1469
2057
|
}
|
|
1470
|
-
const pages =
|
|
2058
|
+
const pages = asArray15(stack.pages);
|
|
1471
2059
|
for (let i = 0; i < pages.length; i++) {
|
|
1472
2060
|
const page = pages[i];
|
|
1473
2061
|
if (!page || typeof page !== "object") continue;
|
|
@@ -1491,7 +2079,7 @@ function validateVisibilityPredicates(stack, opts = {}) {
|
|
|
1491
2079
|
// src/validate-capability-references.ts
|
|
1492
2080
|
import { PLATFORM_CAPABILITY_NAMES } from "@objectstack/spec/security";
|
|
1493
2081
|
var CAPABILITY_REFERENCE_UNKNOWN = "capability-reference-unknown";
|
|
1494
|
-
function
|
|
2082
|
+
function asArray16(v) {
|
|
1495
2083
|
if (Array.isArray(v)) return v;
|
|
1496
2084
|
if (v && typeof v === "object") {
|
|
1497
2085
|
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
@@ -1516,13 +2104,13 @@ function validateCapabilityReferences(stack) {
|
|
|
1516
2104
|
const findings = [];
|
|
1517
2105
|
if (!stack || typeof stack !== "object") return findings;
|
|
1518
2106
|
const known = new Set(PLATFORM_CAPABILITY_NAMES);
|
|
1519
|
-
for (const cap of
|
|
2107
|
+
for (const cap of asArray16(stack.capabilities)) {
|
|
1520
2108
|
if (typeof cap.name === "string" && cap.name.length > 0) known.add(cap.name);
|
|
1521
2109
|
}
|
|
1522
|
-
for (const ps of
|
|
2110
|
+
for (const ps of asArray16(stack.permissions)) {
|
|
1523
2111
|
for (const cap of asCapArray(ps.systemPermissions)) known.add(cap);
|
|
1524
2112
|
}
|
|
1525
|
-
for (const seed of
|
|
2113
|
+
for (const seed of asArray16(stack.data)) {
|
|
1526
2114
|
if (seed.object !== "sys_capability") continue;
|
|
1527
2115
|
for (const rec of Array.isArray(seed.records) ? seed.records : []) {
|
|
1528
2116
|
const name = rec?.name;
|
|
@@ -1541,7 +2129,7 @@ function validateCapabilityReferences(stack) {
|
|
|
1541
2129
|
hint
|
|
1542
2130
|
});
|
|
1543
2131
|
};
|
|
1544
|
-
const objects =
|
|
2132
|
+
const objects = asArray16(stack.objects);
|
|
1545
2133
|
for (let i = 0; i < objects.length; i++) {
|
|
1546
2134
|
const obj = objects[i];
|
|
1547
2135
|
if (!obj || typeof obj !== "object") continue;
|
|
@@ -1550,27 +2138,27 @@ function validateCapabilityReferences(stack) {
|
|
|
1550
2138
|
for (const { cap, key } of flattenObjectRequired(obj.requiredPermissions)) {
|
|
1551
2139
|
flag(cap, `object "${objName}"`, `${objPath}.requiredPermissions${key ? `.${key}` : ""}`);
|
|
1552
2140
|
}
|
|
1553
|
-
const fields =
|
|
2141
|
+
const fields = asArray16(obj.fields);
|
|
1554
2142
|
for (const f of fields) {
|
|
1555
2143
|
const fname = typeof f.name === "string" ? f.name : "(field)";
|
|
1556
2144
|
for (const cap of asCapArray(f.requiredPermissions)) {
|
|
1557
2145
|
flag(cap, `field "${objName}.${fname}"`, `${objPath}.fields.${fname}.requiredPermissions`);
|
|
1558
2146
|
}
|
|
1559
2147
|
}
|
|
1560
|
-
for (const [ai, action] of
|
|
2148
|
+
for (const [ai, action] of asArray16(obj.actions).entries()) {
|
|
1561
2149
|
const aName = typeof action.name === "string" ? action.name : `(action ${ai})`;
|
|
1562
2150
|
for (const cap of asCapArray(action.requiredPermissions)) {
|
|
1563
2151
|
flag(cap, `action "${objName}.${aName}"`, `${objPath}.actions[${ai}].requiredPermissions`);
|
|
1564
2152
|
}
|
|
1565
2153
|
}
|
|
1566
2154
|
}
|
|
1567
|
-
for (const [i, action] of
|
|
2155
|
+
for (const [i, action] of asArray16(stack.actions).entries()) {
|
|
1568
2156
|
const aName = typeof action.name === "string" ? action.name : `(action ${i})`;
|
|
1569
2157
|
for (const cap of asCapArray(action.requiredPermissions)) {
|
|
1570
2158
|
flag(cap, `action "${aName}"`, `actions[${i}].requiredPermissions`);
|
|
1571
2159
|
}
|
|
1572
2160
|
}
|
|
1573
|
-
const apps =
|
|
2161
|
+
const apps = asArray16(stack.apps);
|
|
1574
2162
|
for (let i = 0; i < apps.length; i++) {
|
|
1575
2163
|
const app = apps[i];
|
|
1576
2164
|
if (!app || typeof app !== "object") continue;
|
|
@@ -1601,18 +2189,33 @@ import {
|
|
|
1601
2189
|
ApproverType,
|
|
1602
2190
|
APPROVAL_NODE_TYPE,
|
|
1603
2191
|
DEPRECATED_APPROVER_TYPES,
|
|
1604
|
-
|
|
2192
|
+
APPROVER_VALUE_BINDINGS,
|
|
2193
|
+
approverTypeIsOrgScoped,
|
|
2194
|
+
canonicalApproverType,
|
|
2195
|
+
normalizeDecisionOutputs
|
|
1605
2196
|
} from "@objectstack/spec/automation";
|
|
2197
|
+
import { BUILTIN_MEMBERSHIP_ROLES } from "@objectstack/spec";
|
|
2198
|
+
import { collectCelRootIdentifiers } from "@objectstack/formula";
|
|
1606
2199
|
var APPROVAL_APPROVER_NOT_MEMBERSHIP_TIER = "approval-approver-not-membership-tier";
|
|
1607
2200
|
var APPROVAL_APPROVER_TYPE_DEPRECATED = "approval-approver-type-deprecated";
|
|
1608
2201
|
var APPROVAL_APPROVER_TYPE_UNKNOWN = "approval-approver-type-unknown";
|
|
2202
|
+
var APPROVAL_APPROVER_TYPE_UNSUPPORTED = "approval-approver-type-unsupported";
|
|
1609
2203
|
var APPROVAL_ESCALATION_REASSIGN_NO_TARGET = "approval-escalation-reassign-no-target";
|
|
1610
|
-
var
|
|
2204
|
+
var APPROVAL_APPROVERS_MAY_RESOLVE_EMPTY = "approval-approvers-may-resolve-empty";
|
|
2205
|
+
var APPROVAL_EXPRESSION_INVALID = "approval-expression-invalid";
|
|
2206
|
+
var APPROVAL_EXPRESSION_NO_EMPTY_POLICY = "approval-expression-no-empty-policy";
|
|
2207
|
+
var APPROVAL_DECISION_OUTPUTS_RESERVED = "approval-decision-outputs-reserved";
|
|
2208
|
+
var APPROVAL_APPROVER_CROSS_ORG_UNSUPPORTED = "approval-approver-cross-org-unsupported";
|
|
2209
|
+
var EXPRESSION_ROOTS = /* @__PURE__ */ new Set(["current", "trigger", "vars"]);
|
|
2210
|
+
var RESERVED_OUTPUT_KEYS = /* @__PURE__ */ new Set(["decision", "requestId"]);
|
|
2211
|
+
var GROUP_ROUTED_TYPES = /* @__PURE__ */ new Set(["position", "team", "department"]);
|
|
2212
|
+
var MEMBERSHIP_TIERS = new Set(BUILTIN_MEMBERSHIP_ROLES);
|
|
2213
|
+
var MEMBERSHIP_TIER_LIST = BUILTIN_MEMBERSHIP_ROLES.join("/");
|
|
1611
2214
|
var TYPE_FIX = {
|
|
1612
2215
|
business_unit: "department",
|
|
1613
2216
|
bu: "department"
|
|
1614
2217
|
};
|
|
1615
|
-
function
|
|
2218
|
+
function asArray17(v) {
|
|
1616
2219
|
if (Array.isArray(v)) return v;
|
|
1617
2220
|
if (v && typeof v === "object") {
|
|
1618
2221
|
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
@@ -1622,7 +2225,7 @@ function asArray15(v) {
|
|
|
1622
2225
|
function validateApprovalApprovers(stack) {
|
|
1623
2226
|
const findings = [];
|
|
1624
2227
|
if (!stack || typeof stack !== "object") return findings;
|
|
1625
|
-
const flows =
|
|
2228
|
+
const flows = asArray17(stack.flows);
|
|
1626
2229
|
const validTypes = new Set(ApproverType.options);
|
|
1627
2230
|
for (let fi = 0; fi < flows.length; fi++) {
|
|
1628
2231
|
const flow = flows[fi];
|
|
@@ -1655,14 +2258,61 @@ function validateApprovalApprovers(stack) {
|
|
|
1655
2258
|
continue;
|
|
1656
2259
|
}
|
|
1657
2260
|
const canonical = canonicalApproverType(type);
|
|
2261
|
+
if (canonical === "expression") {
|
|
2262
|
+
const source = value.trim();
|
|
2263
|
+
if (!source) {
|
|
2264
|
+
findings.push({
|
|
2265
|
+
severity: "error",
|
|
2266
|
+
rule: APPROVAL_EXPRESSION_INVALID,
|
|
2267
|
+
where,
|
|
2268
|
+
path: `${path}.value`,
|
|
2269
|
+
message: `expression approver has an empty expression \u2014 the node fails at entry.`,
|
|
2270
|
+
hint: `Write a CEL expression over current.* (the record's live state at node entry), trigger.* (the submit-time snapshot) or vars.* (flow variables), e.g. current.approvers_dynamic or vars.approval_lead.picked_departments.`
|
|
2271
|
+
});
|
|
2272
|
+
} else {
|
|
2273
|
+
const parsed = collectCelRootIdentifiers(source);
|
|
2274
|
+
if (!parsed.ok) {
|
|
2275
|
+
findings.push({
|
|
2276
|
+
severity: "error",
|
|
2277
|
+
rule: APPROVAL_EXPRESSION_INVALID,
|
|
2278
|
+
where,
|
|
2279
|
+
path: `${path}.value`,
|
|
2280
|
+
message: `expression approver does not parse as CEL: ${parsed.error}.`,
|
|
2281
|
+
hint: `Approver expressions are bare CEL (no {\u2026} template braces), e.g. current.approvers_dynamic or vars.get_reviewers.record.owner_id.`
|
|
2282
|
+
});
|
|
2283
|
+
} else {
|
|
2284
|
+
const illegal = parsed.roots.filter((r) => !EXPRESSION_ROOTS.has(r));
|
|
2285
|
+
if (illegal.length) {
|
|
2286
|
+
const wantsRecord = illegal.includes("record") || illegal.includes("previous");
|
|
2287
|
+
findings.push({
|
|
2288
|
+
severity: "error",
|
|
2289
|
+
rule: APPROVAL_EXPRESSION_INVALID,
|
|
2290
|
+
where,
|
|
2291
|
+
path: `${path}.value`,
|
|
2292
|
+
message: `expression approver references \`${illegal.join("`, `")}\` \u2014 only current.*, trigger.* and vars.* are available, and the node fails at entry on any other root.`,
|
|
2293
|
+
hint: wantsRecord ? `\`record\`/\`previous\` are not bound here (on this platform \`record\` always means "the record at event time", which is ambiguous at an approval node). Write current.<field> for the live value at node entry, trigger.<field> for the submit-time snapshot (vars.previous carries the pre-update row).` : `Did you mean current.<field> (live record), trigger.<field> (submit snapshot), or vars.<name> (flow variable)?`
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
} else if (a.resolveAs != null) {
|
|
2299
|
+
findings.push({
|
|
2300
|
+
severity: "info",
|
|
2301
|
+
rule: APPROVAL_EXPRESSION_INVALID,
|
|
2302
|
+
where,
|
|
2303
|
+
path: `${path}.resolveAs`,
|
|
2304
|
+
message: `resolveAs has no effect on a '${type}' approver \u2014 it only applies to type 'expression'.`,
|
|
2305
|
+
hint: `Remove it, or switch this approver to { type: 'expression', value: '<CEL>', resolveAs: '${String(a.resolveAs)}' }.`
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
1658
2308
|
if (canonical === "org_membership_level" && value && !MEMBERSHIP_TIERS.has(value.toLowerCase())) {
|
|
1659
2309
|
findings.push({
|
|
1660
2310
|
severity: "warning",
|
|
1661
2311
|
rule: APPROVAL_APPROVER_NOT_MEMBERSHIP_TIER,
|
|
1662
2312
|
where,
|
|
1663
2313
|
path: `${path}.value`,
|
|
1664
|
-
message: `approver { type: '${type}', value: '${value}' } resolves against the better-auth org-membership tier (sys_member.role:
|
|
1665
|
-
hint: `If '${value}' is an org position, author { type: 'position', value: '${value}' } (resolved via sys_user_position, ADR-0090 D3). Keep type 'org_membership_level' only for membership tiers (
|
|
2314
|
+
message: `approver { type: '${type}', value: '${value}' } resolves against the better-auth org-membership tier (sys_member.role: ${MEMBERSHIP_TIER_LIST}) \u2014 '${value}' is not a membership tier, so this approver matches nobody and the request stalls.`,
|
|
2315
|
+
hint: `If '${value}' is an org position, author { type: 'position', value: '${value}' } (resolved via sys_user_position, ADR-0090 D3). Keep type 'org_membership_level' only for membership tiers (${MEMBERSHIP_TIER_LIST}) \u2014 the vocabulary is closed (ADR-0108), so a business role is always a position.`
|
|
1666
2316
|
});
|
|
1667
2317
|
} else if (type in DEPRECATED_APPROVER_TYPES) {
|
|
1668
2318
|
const fix = canonicalApproverType(type);
|
|
@@ -1674,8 +2324,67 @@ function validateApprovalApprovers(stack) {
|
|
|
1674
2324
|
message: `approver type '${type}' is the deprecated spelling of '${fix}' (ADR-0090 D3) and is removed in the next major.`,
|
|
1675
2325
|
hint: `Author { type: '${fix}', value: '${value}' }. It resolves identically today.`
|
|
1676
2326
|
});
|
|
2327
|
+
} else if (APPROVER_VALUE_BINDINGS[canonical]?.source === "unsupported") {
|
|
2328
|
+
findings.push({
|
|
2329
|
+
severity: "warning",
|
|
2330
|
+
rule: APPROVAL_APPROVER_TYPE_UNSUPPORTED,
|
|
2331
|
+
where,
|
|
2332
|
+
path: `${path}.type`,
|
|
2333
|
+
message: `approver type '${type}' is declared but not implemented by the runtime (#3508) \u2014 the slot resolves to nobody and the request stalls.`,
|
|
2334
|
+
hint: `Route to people the engine can expand: { type: 'team' | 'department' | 'position', ... }. Queue approvers need a real ownership-queue implementation before they take effect.`
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2337
|
+
const declaredOrg = a.organization;
|
|
2338
|
+
if (typeof declaredOrg === "string" && declaredOrg.trim() !== "" && ApproverType.options.includes(canonical) && !approverTypeIsOrgScoped(canonical)) {
|
|
2339
|
+
findings.push({
|
|
2340
|
+
severity: "error",
|
|
2341
|
+
rule: APPROVAL_APPROVER_CROSS_ORG_UNSUPPORTED,
|
|
2342
|
+
where,
|
|
2343
|
+
path: `${path}.organization`,
|
|
2344
|
+
message: `approver type '${type}' does not resolve through an organization directory, so 'organization: ${declaredOrg}' has no effect (ADR-0105 D9) \u2014 the runtime refuses it.`,
|
|
2345
|
+
hint: `Drop 'organization' here. Cross-organization targeting applies to 'position', 'org_membership_level', 'department' and 'expression' approvers.`
|
|
2346
|
+
});
|
|
1677
2347
|
}
|
|
1678
2348
|
}
|
|
2349
|
+
const routable = approvers.filter(
|
|
2350
|
+
(a) => a && typeof a === "object" && typeof a.type === "string"
|
|
2351
|
+
);
|
|
2352
|
+
if (routable.length > 0 && routable.every((a) => GROUP_ROUTED_TYPES.has(canonicalApproverType(String(a.type))))) {
|
|
2353
|
+
const locks = cfg.lockRecord !== false;
|
|
2354
|
+
findings.push({
|
|
2355
|
+
severity: "info",
|
|
2356
|
+
rule: APPROVAL_APPROVERS_MAY_RESOLVE_EMPTY,
|
|
2357
|
+
where,
|
|
2358
|
+
path: `flows[${fi}].nodes[${ni}].config.approvers`,
|
|
2359
|
+
message: `every approver on this node routes to a group (position/team/department) whose members are runtime data \u2014 if none is staffed, the request resolves to an empty slate and waits forever` + (locks ? `, and (lockRecord) the record stays locked with no in-product recovery.` : `.`),
|
|
2360
|
+
hint: `Make sure at least one target is always staffed, or add a guaranteed-staffed fallback approver, e.g. { type: 'org_membership_level', value: 'owner' }. A request that still lands empty is recoverable only by a platform/tenant admin override (#3424).`
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2363
|
+
const hasExpression = approvers.some(
|
|
2364
|
+
(a) => a && typeof a === "object" && canonicalApproverType(String(a.type ?? "")) === "expression"
|
|
2365
|
+
);
|
|
2366
|
+
if (hasExpression && cfg.onEmptyApprovers == null) {
|
|
2367
|
+
findings.push({
|
|
2368
|
+
severity: "info",
|
|
2369
|
+
rule: APPROVAL_EXPRESSION_NO_EMPTY_POLICY,
|
|
2370
|
+
where,
|
|
2371
|
+
path: `flows[${fi}].nodes[${ni}].config`,
|
|
2372
|
+
message: `this node resolves approvers from an expression but declares no onEmptyApprovers \u2014 an empty result falls back to the default ('admin_rescue': request opens, only a privileged admin can act).`,
|
|
2373
|
+
hint: `Declare the empty-slate policy explicitly: onEmptyApprovers: 'admin_rescue' (hold for admin takeover), 'fail' (fail the node \u2014 config bug), or 'auto_approve' (wave through, output.autoApproved = true).`
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
const declaredOutputs = normalizeDecisionOutputs(cfg.decisionOutputs).map((d) => d.key);
|
|
2377
|
+
const reserved = declaredOutputs.filter((k) => RESERVED_OUTPUT_KEYS.has(k));
|
|
2378
|
+
if (reserved.length) {
|
|
2379
|
+
findings.push({
|
|
2380
|
+
severity: "error",
|
|
2381
|
+
rule: APPROVAL_DECISION_OUTPUTS_RESERVED,
|
|
2382
|
+
where,
|
|
2383
|
+
path: `flows[${fi}].nodes[${ni}].config.decisionOutputs`,
|
|
2384
|
+
message: `decisionOutputs declares reserved key(s) \`${reserved.join("`, `")}\` \u2014 the resume envelope owns them, so every decide carrying them is rejected.`,
|
|
2385
|
+
hint: `Rename the output key(s); any name other than 'decision'/'requestId' works.`
|
|
2386
|
+
});
|
|
2387
|
+
}
|
|
1679
2388
|
const escalation = cfg.escalation ?? null;
|
|
1680
2389
|
if (escalation && typeof escalation === "object" && escalation.action === "reassign") {
|
|
1681
2390
|
const target = typeof escalation.escalateTo === "string" ? escalation.escalateTo.trim() : "";
|
|
@@ -1695,6 +2404,96 @@ function validateApprovalApprovers(stack) {
|
|
|
1695
2404
|
return findings;
|
|
1696
2405
|
}
|
|
1697
2406
|
|
|
2407
|
+
// src/validate-seed-replay-safety.ts
|
|
2408
|
+
var SEED_INSERT_MODE_DUPLICATES_ON_REPLAY = "seed-insert-mode-duplicates-on-replay";
|
|
2409
|
+
function validateSeedReplaySafety(stack) {
|
|
2410
|
+
const out = [];
|
|
2411
|
+
const seeds = Array.isArray(stack.data) ? stack.data : [];
|
|
2412
|
+
seeds.forEach((seed, i) => {
|
|
2413
|
+
if (!seed || typeof seed !== "object") return;
|
|
2414
|
+
if (seed.mode !== "insert") return;
|
|
2415
|
+
const object = typeof seed.object === "string" ? seed.object : void 0;
|
|
2416
|
+
const where = object ? `seed "${object}"` : `data[${i}]`;
|
|
2417
|
+
out.push({
|
|
2418
|
+
severity: "warning",
|
|
2419
|
+
rule: SEED_INSERT_MODE_DUPLICATES_ON_REPLAY,
|
|
2420
|
+
where,
|
|
2421
|
+
path: `data[${i}].mode`,
|
|
2422
|
+
message: "`mode: 'insert'` re-inserts every record on each replay boot (dev-server restart, package re-publish) with no existing-row check, so the dataset duplicates the table on every restart \u2014 seeds are replayed, not applied once.",
|
|
2423
|
+
hint: "Use `mode: 'ignore'` (skip rows that already exist) or `'upsert'` (create-or-update), and declare an `externalId` to match on: a single natural-key field (e.g. `externalId: 'code'`), or a COMPOSITE list of fields for a join / junction table with no single natural key (e.g. `externalId: ['team', 'project']`)."
|
|
2424
|
+
});
|
|
2425
|
+
});
|
|
2426
|
+
return out;
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
// src/validate-seed-state-machine.ts
|
|
2430
|
+
var SEED_VALUE_OUTSIDE_STATE_MACHINE = "seed-value-outside-state-machine";
|
|
2431
|
+
function fsmRulesByObject(objects) {
|
|
2432
|
+
const map = /* @__PURE__ */ new Map();
|
|
2433
|
+
for (const obj of objects) {
|
|
2434
|
+
if (!obj || typeof obj !== "object") continue;
|
|
2435
|
+
const name = typeof obj.name === "string" ? obj.name : void 0;
|
|
2436
|
+
if (!name) continue;
|
|
2437
|
+
const validations = Array.isArray(obj.validations) ? obj.validations : [];
|
|
2438
|
+
const rules = [];
|
|
2439
|
+
for (const v of validations) {
|
|
2440
|
+
if (!v || typeof v !== "object" || v.type !== "state_machine") continue;
|
|
2441
|
+
const field = typeof v.field === "string" ? v.field : void 0;
|
|
2442
|
+
if (!field) continue;
|
|
2443
|
+
const transitions = v.transitions && typeof v.transitions === "object" ? v.transitions : {};
|
|
2444
|
+
const states = /* @__PURE__ */ new Set();
|
|
2445
|
+
for (const s of Array.isArray(v.initialStates) ? v.initialStates : []) states.add(String(s));
|
|
2446
|
+
for (const from of Object.keys(transitions)) {
|
|
2447
|
+
states.add(String(from));
|
|
2448
|
+
const targets = transitions[from];
|
|
2449
|
+
for (const to of Array.isArray(targets) ? targets : []) states.add(String(to));
|
|
2450
|
+
}
|
|
2451
|
+
if (states.size > 0) rules.push({ field, states });
|
|
2452
|
+
}
|
|
2453
|
+
if (rules.length > 0) map.set(name, rules);
|
|
2454
|
+
}
|
|
2455
|
+
return map;
|
|
2456
|
+
}
|
|
2457
|
+
function recordLabel(record, externalId, index) {
|
|
2458
|
+
const keys = Array.isArray(externalId) ? externalId.map(String) : typeof externalId === "string" ? [externalId] : ["name"];
|
|
2459
|
+
const parts = keys.map((k) => record[k]).filter((v) => v != null && v !== "");
|
|
2460
|
+
return parts.length > 0 ? parts.map(String).join(" \xB7 ") : `#${index}`;
|
|
2461
|
+
}
|
|
2462
|
+
function validateSeedStateMachine(stack) {
|
|
2463
|
+
const out = [];
|
|
2464
|
+
const objects = Array.isArray(stack.objects) ? stack.objects : [];
|
|
2465
|
+
const seeds = Array.isArray(stack.data) ? stack.data : [];
|
|
2466
|
+
if (objects.length === 0 || seeds.length === 0) return out;
|
|
2467
|
+
const rulesByObject = fsmRulesByObject(objects);
|
|
2468
|
+
if (rulesByObject.size === 0) return out;
|
|
2469
|
+
seeds.forEach((seed, i) => {
|
|
2470
|
+
if (!seed || typeof seed !== "object") return;
|
|
2471
|
+
const objectName = typeof seed.object === "string" ? seed.object : void 0;
|
|
2472
|
+
if (!objectName) return;
|
|
2473
|
+
const rules = rulesByObject.get(objectName);
|
|
2474
|
+
if (!rules) return;
|
|
2475
|
+
const records = Array.isArray(seed.records) ? seed.records : [];
|
|
2476
|
+
records.forEach((record, j) => {
|
|
2477
|
+
if (!record || typeof record !== "object") return;
|
|
2478
|
+
for (const rule of rules) {
|
|
2479
|
+
const value = record[rule.field];
|
|
2480
|
+
if (value == null || value === "") continue;
|
|
2481
|
+
if (typeof value !== "string") continue;
|
|
2482
|
+
if (rule.states.has(value)) continue;
|
|
2483
|
+
out.push({
|
|
2484
|
+
severity: "warning",
|
|
2485
|
+
rule: SEED_VALUE_OUTSIDE_STATE_MACHINE,
|
|
2486
|
+
where: `seed "${objectName}" (${recordLabel(record, seed.externalId, j)})`,
|
|
2487
|
+
path: `data[${i}].records[${j}].${rule.field}`,
|
|
2488
|
+
message: `seeds '${rule.field}=${value}', which the '${objectName}' state machine does not declare (known states: ${[...rule.states].sort().join(", ")}). Seed writes are exempt from the state_machine rule (#3433), so this is NOT rejected at write time \u2014 a typo lands silently.`,
|
|
2489
|
+
hint: `If '${value}' is a real state, add it to the state machine (as an initial state or a transition endpoint). If it is a typo, correct it to a declared state. The exemption lets a seed be born mid-lifecycle; it is not a licence to write an unknown state.`
|
|
2490
|
+
});
|
|
2491
|
+
}
|
|
2492
|
+
});
|
|
2493
|
+
});
|
|
2494
|
+
return out;
|
|
2495
|
+
}
|
|
2496
|
+
|
|
1698
2497
|
// src/validate-security-posture.ts
|
|
1699
2498
|
import { describeAnchorForbiddenBits } from "@objectstack/spec/security";
|
|
1700
2499
|
var SECURITY_OWD_UNSET = "security-owd-unset";
|
|
@@ -1721,7 +2520,7 @@ var OWD_WIDTH = {
|
|
|
1721
2520
|
public_read: 1,
|
|
1722
2521
|
public_read_write: 2
|
|
1723
2522
|
};
|
|
1724
|
-
function
|
|
2523
|
+
function asArray18(v) {
|
|
1725
2524
|
if (Array.isArray(v)) return v;
|
|
1726
2525
|
if (v && typeof v === "object") {
|
|
1727
2526
|
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
@@ -1738,16 +2537,16 @@ function identifierHasRoleToken(name) {
|
|
|
1738
2537
|
if (typeof name !== "string") return false;
|
|
1739
2538
|
return name.toLowerCase().split(/[^a-z0-9]+/).some((tok) => tok === "role" || tok === "roles");
|
|
1740
2539
|
}
|
|
1741
|
-
function labelHasRoleWord(
|
|
1742
|
-
if (typeof
|
|
1743
|
-
return /\brole(s)?\b/i.test(
|
|
2540
|
+
function labelHasRoleWord(label2) {
|
|
2541
|
+
if (typeof label2 !== "string") return false;
|
|
2542
|
+
return /\brole(s)?\b/i.test(label2);
|
|
1744
2543
|
}
|
|
1745
2544
|
function refOf(def) {
|
|
1746
2545
|
const r = def.reference ?? def.reference_to;
|
|
1747
2546
|
return typeof r === "string" && r ? r : void 0;
|
|
1748
2547
|
}
|
|
1749
2548
|
function firstMasterDetailField(obj) {
|
|
1750
|
-
for (const f of
|
|
2549
|
+
for (const f of asArray18(obj.fields)) {
|
|
1751
2550
|
if (f.type === "master_detail") {
|
|
1752
2551
|
return { name: String(f.name ?? "?"), parent: refOf(f) };
|
|
1753
2552
|
}
|
|
@@ -1760,8 +2559,8 @@ function grantsObjectAccess(p) {
|
|
|
1760
2559
|
function validateSecurityPosture(stack, opts) {
|
|
1761
2560
|
const findings = [];
|
|
1762
2561
|
if (!stack || typeof stack !== "object") return findings;
|
|
1763
|
-
const objects =
|
|
1764
|
-
const permissionSets =
|
|
2562
|
+
const objects = asArray18(stack.objects);
|
|
2563
|
+
const permissionSets = asArray18(stack.permissions);
|
|
1765
2564
|
for (let i = 0; i < objects.length; i++) {
|
|
1766
2565
|
const obj = objects[i];
|
|
1767
2566
|
if (!obj || typeof obj !== "object") continue;
|
|
@@ -1864,7 +2663,7 @@ function validateSecurityPosture(stack, opts) {
|
|
|
1864
2663
|
}
|
|
1865
2664
|
}
|
|
1866
2665
|
}
|
|
1867
|
-
const flagRole = (kind, name,
|
|
2666
|
+
const flagRole = (kind, name, label2, where, path) => {
|
|
1868
2667
|
if (identifierHasRoleToken(name)) {
|
|
1869
2668
|
findings.push({
|
|
1870
2669
|
severity: "error",
|
|
@@ -1874,13 +2673,13 @@ function validateSecurityPosture(stack, opts) {
|
|
|
1874
2673
|
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).`,
|
|
1875
2674
|
hint: `Rename using 'position' for distribution groups or a domain word (e.g. 'function', 'duty').`
|
|
1876
2675
|
});
|
|
1877
|
-
} else if (labelHasRoleWord(
|
|
2676
|
+
} else if (labelHasRoleWord(label2)) {
|
|
1878
2677
|
findings.push({
|
|
1879
2678
|
severity: "error",
|
|
1880
2679
|
rule: SECURITY_ROLE_WORD,
|
|
1881
2680
|
where,
|
|
1882
2681
|
path: `${path.replace(/\.name$/, "")}.label`,
|
|
1883
|
-
message: `${kind} label "${String(
|
|
2682
|
+
message: `${kind} label "${String(label2)}" uses the reserved word "role" (ADR-0090 D3).`,
|
|
1884
2683
|
hint: `Relabel with 'Position' (distribution) or a domain word \u2014 admins must meet ONE vocabulary.`
|
|
1885
2684
|
});
|
|
1886
2685
|
}
|
|
@@ -1890,10 +2689,10 @@ function validateSecurityPosture(stack, opts) {
|
|
|
1890
2689
|
if (!obj || typeof obj !== "object" || isSystemObject(obj)) continue;
|
|
1891
2690
|
const objName = typeof obj.name === "string" ? obj.name : `(object ${i})`;
|
|
1892
2691
|
flagRole("object", obj.name, obj.label, `object "${objName}"`, `objects[${i}].name`);
|
|
1893
|
-
for (const f of
|
|
2692
|
+
for (const f of asArray18(obj.fields)) {
|
|
1894
2693
|
flagRole("field", f.name, f.label, `field "${objName}.${String(f.name ?? "?")}"`, `objects[${i}].fields.${String(f.name ?? "?")}.name`);
|
|
1895
2694
|
}
|
|
1896
|
-
for (const [ai, action] of
|
|
2695
|
+
for (const [ai, action] of asArray18(obj.actions).entries()) {
|
|
1897
2696
|
flagRole("action", action.name, action.label, `action "${objName}.${String(action.name ?? "?")}"`, `objects[${i}].actions[${ai}].name`);
|
|
1898
2697
|
}
|
|
1899
2698
|
}
|
|
@@ -1902,19 +2701,19 @@ function validateSecurityPosture(stack, opts) {
|
|
|
1902
2701
|
if (!ps || typeof ps !== "object") continue;
|
|
1903
2702
|
flagRole("permission set", ps.name, ps.label, `permission set "${String(ps.name ?? i)}"`, `permissions[${i}].name`);
|
|
1904
2703
|
}
|
|
1905
|
-
for (const [i, pos] of
|
|
2704
|
+
for (const [i, pos] of asArray18(stack.positions).entries()) {
|
|
1906
2705
|
flagRole("position", pos.name, pos.label, `position "${String(pos.name ?? i)}"`, `positions[${i}].name`);
|
|
1907
2706
|
}
|
|
1908
|
-
for (const [i, app] of
|
|
2707
|
+
for (const [i, app] of asArray18(stack.apps).entries()) {
|
|
1909
2708
|
flagRole("app", app.name, app.label, `app "${String(app.name ?? i)}"`, `apps[${i}].name`);
|
|
1910
2709
|
}
|
|
1911
|
-
for (const [i, book] of
|
|
2710
|
+
for (const [i, book] of asArray18(stack.books).entries()) {
|
|
1912
2711
|
flagRole("book", book.name, book.label, `book "${String(book.name ?? i)}"`, `books[${i}].name`);
|
|
1913
2712
|
}
|
|
1914
2713
|
const stackSetNames = new Set(
|
|
1915
2714
|
permissionSets.map((ps) => typeof ps.name === "string" ? ps.name : void 0).filter((n) => !!n)
|
|
1916
2715
|
);
|
|
1917
|
-
for (const [i, book] of
|
|
2716
|
+
for (const [i, book] of asArray18(stack.books).entries()) {
|
|
1918
2717
|
const audience = book.audience;
|
|
1919
2718
|
if (!audience || typeof audience !== "object") continue;
|
|
1920
2719
|
const setName = audience.permissionSet;
|
|
@@ -1992,7 +2791,7 @@ function validateSecurityPosture(stack, opts) {
|
|
|
1992
2791
|
}
|
|
1993
2792
|
const GRANT_SEED_OBJECTS = /* @__PURE__ */ new Set(["sys_user_position", "sys_user_permission_set"]);
|
|
1994
2793
|
const nowMs = opts?.nowMs ?? Date.now();
|
|
1995
|
-
for (const [i, seed] of
|
|
2794
|
+
for (const [i, seed] of asArray18(stack.data).entries()) {
|
|
1996
2795
|
const seedObject = typeof seed.object === "string" ? seed.object : "";
|
|
1997
2796
|
if (!GRANT_SEED_OBJECTS.has(seedObject)) continue;
|
|
1998
2797
|
const records = Array.isArray(seed.records) ? seed.records : [];
|
|
@@ -2032,8 +2831,1182 @@ function validateSecurityPosture(stack, opts) {
|
|
|
2032
2831
|
return findings;
|
|
2033
2832
|
}
|
|
2034
2833
|
|
|
2035
|
-
// src/
|
|
2036
|
-
|
|
2834
|
+
// src/validate-org-axis-red-lines.ts
|
|
2835
|
+
var ORG_AXIS_PERMISSION_INHERITANCE = "org-axis-permission-inheritance";
|
|
2836
|
+
var ORG_AXIS_CROSS_ORG_BU_GRANT = "org-axis-cross-org-bu-grant";
|
|
2837
|
+
var ORG_PARENT_FIELD = "parent_organization_id";
|
|
2838
|
+
function asArray19(v) {
|
|
2839
|
+
if (Array.isArray(v)) return v;
|
|
2840
|
+
if (v && typeof v === "object") {
|
|
2841
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
2842
|
+
}
|
|
2843
|
+
return [];
|
|
2844
|
+
}
|
|
2845
|
+
function str(v) {
|
|
2846
|
+
return typeof v === "string" ? v : "";
|
|
2847
|
+
}
|
|
2848
|
+
function isTenancyDisabled(object) {
|
|
2849
|
+
const tenancy = object.tenancy;
|
|
2850
|
+
if (tenancy && typeof tenancy === "object" && tenancy.enabled === false) return true;
|
|
2851
|
+
const systemFields = object.systemFields;
|
|
2852
|
+
if (systemFields && typeof systemFields === "object" && systemFields.tenant === false) return true;
|
|
2853
|
+
return false;
|
|
2854
|
+
}
|
|
2855
|
+
var INHERITANCE_HINT = `Remove the ${ORG_PARENT_FIELD} reference. Cross-organization visibility comes from MEMBERSHIP: under the \`group\` tenancy posture the engine's Layer 0 wall is \`organization_id IN accessible_org_ids\`, so a user who should see several organizations is made a member of them (ADR-0105 D2). A Layer-1 policy cannot widen Layer 0 anyway, so this rule would not grant the access it appears to. For a hierarchy INSIDE one organization, use the business-unit tree (\`unit_and_subordinates\` sharing, or a depth scope anchored on \`sys_user_position\`).`;
|
|
2856
|
+
function validateOrgAxisRedLines(stack) {
|
|
2857
|
+
const findings = [];
|
|
2858
|
+
const cfg = stack ?? {};
|
|
2859
|
+
const permissionSets = asArray19(cfg.permissions ?? cfg.permissionSets);
|
|
2860
|
+
permissionSets.forEach((ps, psIndex) => {
|
|
2861
|
+
asArray19(ps.rowLevelSecurity).forEach((policy, pIndex) => {
|
|
2862
|
+
for (const clause of ["using", "check"]) {
|
|
2863
|
+
if (!str(policy[clause]).includes(ORG_PARENT_FIELD)) continue;
|
|
2864
|
+
findings.push({
|
|
2865
|
+
severity: "error",
|
|
2866
|
+
rule: ORG_AXIS_PERMISSION_INHERITANCE,
|
|
2867
|
+
where: `permission set "${str(ps.name) || psIndex}" policy "${str(policy.name) || pIndex}"`,
|
|
2868
|
+
path: `permissions[${psIndex}].rowLevelSecurity[${pIndex}].${clause}`,
|
|
2869
|
+
message: `RLS ${clause} reads \`${ORG_PARENT_FIELD}\`, which builds a permission hierarchy along the organization axis. ADR-0105 D6 forbids it: the org tree is a REPORTING dimension only.`,
|
|
2870
|
+
hint: INHERITANCE_HINT
|
|
2871
|
+
});
|
|
2872
|
+
}
|
|
2873
|
+
});
|
|
2874
|
+
});
|
|
2875
|
+
const objects = asArray19(cfg.objects);
|
|
2876
|
+
objects.forEach((object, oIndex) => {
|
|
2877
|
+
const objectName = str(object.name) || String(oIndex);
|
|
2878
|
+
asArray19(object.rowLevelSecurity ?? object.rls).forEach((policy, pIndex) => {
|
|
2879
|
+
for (const clause of ["using", "check"]) {
|
|
2880
|
+
if (!str(policy[clause]).includes(ORG_PARENT_FIELD)) continue;
|
|
2881
|
+
findings.push({
|
|
2882
|
+
severity: "error",
|
|
2883
|
+
rule: ORG_AXIS_PERMISSION_INHERITANCE,
|
|
2884
|
+
where: `object "${objectName}" policy "${str(policy.name) || pIndex}"`,
|
|
2885
|
+
path: `objects[${oIndex}].rowLevelSecurity[${pIndex}].${clause}`,
|
|
2886
|
+
message: `RLS ${clause} reads \`${ORG_PARENT_FIELD}\`, which builds a permission hierarchy along the organization axis. ADR-0105 D6 forbids it: the org tree is a REPORTING dimension only.`,
|
|
2887
|
+
hint: INHERITANCE_HINT
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2890
|
+
});
|
|
2891
|
+
});
|
|
2892
|
+
asArray19(cfg.sharingRules ?? cfg.sharing).forEach((rule, rIndex) => {
|
|
2893
|
+
const criteria = JSON.stringify(rule.criteria ?? rule.filter ?? "");
|
|
2894
|
+
const sharedTo = JSON.stringify(rule.sharedTo ?? rule.recipient ?? "");
|
|
2895
|
+
if (criteria.includes(ORG_PARENT_FIELD) || sharedTo.includes(ORG_PARENT_FIELD)) {
|
|
2896
|
+
findings.push({
|
|
2897
|
+
severity: "error",
|
|
2898
|
+
rule: ORG_AXIS_PERMISSION_INHERITANCE,
|
|
2899
|
+
where: `sharing rule "${str(rule.name) || rIndex}"`,
|
|
2900
|
+
path: `sharingRules[${rIndex}]`,
|
|
2901
|
+
message: `Sharing rule reads \`${ORG_PARENT_FIELD}\`, granting access by walking the organization tree. ADR-0105 D6 forbids permission inheritance along the org axis.`,
|
|
2902
|
+
hint: INHERITANCE_HINT
|
|
2903
|
+
});
|
|
2904
|
+
}
|
|
2905
|
+
});
|
|
2906
|
+
const tenancyDisabledObjects = new Set(
|
|
2907
|
+
objects.filter((o) => isTenancyDisabled(o)).map((o) => str(o.name)).filter(Boolean)
|
|
2908
|
+
);
|
|
2909
|
+
asArray19(cfg.sharingRules ?? cfg.sharing).forEach((rule, rIndex) => {
|
|
2910
|
+
const target = str(rule.object ?? rule.objectName);
|
|
2911
|
+
if (!target || !tenancyDisabledObjects.has(target)) return;
|
|
2912
|
+
const sharedTo = rule.sharedTo ?? rule.recipient;
|
|
2913
|
+
const recipientType = str(sharedTo?.type);
|
|
2914
|
+
if (recipientType !== "business_unit") return;
|
|
2915
|
+
findings.push({
|
|
2916
|
+
severity: "error",
|
|
2917
|
+
rule: ORG_AXIS_CROSS_ORG_BU_GRANT,
|
|
2918
|
+
where: `sharing rule "${str(rule.name) || rIndex}" on object "${target}"`,
|
|
2919
|
+
path: `sharingRules[${rIndex}].sharedTo`,
|
|
2920
|
+
message: `A business-unit sharing rule targets "${target}", which opted out of tenancy (\`tenancy.enabled: false\`). Platform-global objects carry no organization column, so this grant spans EVERY organization \u2014 a cross-organization business-unit grant, which ADR-0105 D6 forbids (BU trees are org-internal).`,
|
|
2921
|
+
hint: `Either scope the object to organizations (drop \`tenancy.enabled: false\` so Layer 0 walls it), or share it to a position / permission-set audience instead of a business unit. A platform-global catalog that everyone should read wants an OWD of \`public_read\`, not a BU grant.`
|
|
2922
|
+
});
|
|
2923
|
+
});
|
|
2924
|
+
return findings;
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
// src/validate-dashboard-action-refs.ts
|
|
2928
|
+
var DASHBOARD_ACTION_TARGET_UNDEFINED = "dashboard-action-target-undefined";
|
|
2929
|
+
var DASHBOARD_ACTION_ROUTE_UNRESOLVED = "dashboard-action-route-unresolved";
|
|
2930
|
+
function asArray20(v) {
|
|
2931
|
+
if (Array.isArray(v)) return v;
|
|
2932
|
+
if (v && typeof v === "object") {
|
|
2933
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
2934
|
+
}
|
|
2935
|
+
return [];
|
|
2936
|
+
}
|
|
2937
|
+
function strName(v) {
|
|
2938
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
2939
|
+
}
|
|
2940
|
+
var MODAL_VERB_RE = /^(?:create|new|add|edit|update)_(.+)$/;
|
|
2941
|
+
var URL_COLLECTION_TO_STACK_KEY = {
|
|
2942
|
+
object: "objects",
|
|
2943
|
+
objects: "objects",
|
|
2944
|
+
report: "reports",
|
|
2945
|
+
reports: "reports",
|
|
2946
|
+
dashboard: "dashboards",
|
|
2947
|
+
dashboards: "dashboards",
|
|
2948
|
+
page: "pages",
|
|
2949
|
+
pages: "pages",
|
|
2950
|
+
view: "views",
|
|
2951
|
+
views: "views"
|
|
2952
|
+
};
|
|
2953
|
+
function viewContainerName(item) {
|
|
2954
|
+
return strName(item.name) ?? strName(item.id) ?? strName(item.object) ?? strName(item.list?.data && item.list.data.object) ?? strName(item.form?.data && item.form.data.object);
|
|
2955
|
+
}
|
|
2956
|
+
function collectKnownTargets(stack) {
|
|
2957
|
+
const actions = /* @__PURE__ */ new Set();
|
|
2958
|
+
const objects = /* @__PURE__ */ new Set();
|
|
2959
|
+
const reports = /* @__PURE__ */ new Set();
|
|
2960
|
+
const dashboards = /* @__PURE__ */ new Set();
|
|
2961
|
+
const pages = /* @__PURE__ */ new Set();
|
|
2962
|
+
const views = /* @__PURE__ */ new Set();
|
|
2963
|
+
const collectNames = (v, into, name) => {
|
|
2964
|
+
for (const item of asArray20(v)) {
|
|
2965
|
+
if (!item || typeof item !== "object") continue;
|
|
2966
|
+
const n = name(item);
|
|
2967
|
+
if (n) into.add(n);
|
|
2968
|
+
}
|
|
2969
|
+
};
|
|
2970
|
+
collectNames(stack.actions, actions, (a) => strName(a.name));
|
|
2971
|
+
for (const obj of asArray20(stack.objects)) {
|
|
2972
|
+
if (!obj || typeof obj !== "object") continue;
|
|
2973
|
+
const n = strName(obj.name);
|
|
2974
|
+
if (n) objects.add(n);
|
|
2975
|
+
collectNames(obj.actions, actions, (a) => strName(a.name));
|
|
2976
|
+
}
|
|
2977
|
+
collectNames(stack.reports, reports, (r) => strName(r.name));
|
|
2978
|
+
collectNames(stack.dashboards, dashboards, (d) => strName(d.name));
|
|
2979
|
+
collectNames(stack.pages, pages, (p) => strName(p.name));
|
|
2980
|
+
collectNames(stack.views, views, viewContainerName);
|
|
2981
|
+
for (const o of objects) views.add(o);
|
|
2982
|
+
return { actions, objects, reports, dashboards, pages, views };
|
|
2983
|
+
}
|
|
2984
|
+
function resolveActionTarget(actionType, target, known) {
|
|
2985
|
+
if (known.actions.has(target)) return true;
|
|
2986
|
+
if (actionType === "modal") {
|
|
2987
|
+
if (known.objects.has(target)) return true;
|
|
2988
|
+
const m = MODAL_VERB_RE.exec(target);
|
|
2989
|
+
if (m && known.objects.has(m[1])) return true;
|
|
2990
|
+
}
|
|
2991
|
+
return false;
|
|
2992
|
+
}
|
|
2993
|
+
function resolveUrlRoute(target, known) {
|
|
2994
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(target) || target.startsWith("//")) return null;
|
|
2995
|
+
if (target.includes("${")) return null;
|
|
2996
|
+
if (!target.startsWith("/")) return null;
|
|
2997
|
+
const pathPart = target.split(/[?#]/, 1)[0];
|
|
2998
|
+
const segments = pathPart.split("/").filter(Boolean);
|
|
2999
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
3000
|
+
const stackKey = URL_COLLECTION_TO_STACK_KEY[segments[i]];
|
|
3001
|
+
if (!stackKey) continue;
|
|
3002
|
+
const name = segments[i + 1];
|
|
3003
|
+
if (known[stackKey].has(name)) return void 0;
|
|
3004
|
+
return { collection: segments[i], name };
|
|
3005
|
+
}
|
|
3006
|
+
return null;
|
|
3007
|
+
}
|
|
3008
|
+
function validateDashboardActionRefs(stack) {
|
|
3009
|
+
const findings = [];
|
|
3010
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
3011
|
+
const dashboards = asArray20(stack.dashboards);
|
|
3012
|
+
if (dashboards.length === 0) return findings;
|
|
3013
|
+
const known = collectKnownTargets(stack);
|
|
3014
|
+
const checkOne = (action, where, path) => {
|
|
3015
|
+
const target = strName(action.actionUrl);
|
|
3016
|
+
if (!target) return;
|
|
3017
|
+
if (target.includes("${")) return;
|
|
3018
|
+
const actionType = strName(action.actionType) ?? "url";
|
|
3019
|
+
if (actionType === "script" || actionType === "modal") {
|
|
3020
|
+
if (resolveActionTarget(actionType, target, known)) return;
|
|
3021
|
+
const kindWord = actionType === "script" ? "script" : "modal";
|
|
3022
|
+
findings.push({
|
|
3023
|
+
severity: "error",
|
|
3024
|
+
rule: DASHBOARD_ACTION_TARGET_UNDEFINED,
|
|
3025
|
+
where,
|
|
3026
|
+
path,
|
|
3027
|
+
message: `${kindWord} action target "${target}" resolves to no defined action` + (actionType === "modal" ? " or object" : "") + `. The button renders but does nothing when clicked \u2014 a dangling reference the runtime cannot dispatch (ADR-0049: a declared reference must resolve).`,
|
|
3028
|
+
hint: actionType === "modal" ? `Define an action named "${target}" (stack.actions or the object's actions), use the "<verb>_<object>" convention against a real object (e.g. "create_<object>"), point actionUrl at an existing object, or remove the button.` : `Define a script action named "${target}" (stack.actions or the object's actions) with an inline body or a registered handler, or remove the button.`
|
|
3029
|
+
});
|
|
3030
|
+
return;
|
|
3031
|
+
}
|
|
3032
|
+
if (actionType === "url") {
|
|
3033
|
+
const route = resolveUrlRoute(target, known);
|
|
3034
|
+
if (!route) return;
|
|
3035
|
+
findings.push({
|
|
3036
|
+
severity: "warning",
|
|
3037
|
+
rule: DASHBOARD_ACTION_ROUTE_UNRESOLVED,
|
|
3038
|
+
where,
|
|
3039
|
+
path,
|
|
3040
|
+
message: `url action target "${target}" points at ${route.collection}/${route.name}, but no ${route.collection.replace(/s$/, "")} named "${route.name}" is registered in this stack \u2014 the button likely navigates to a dead route.`,
|
|
3041
|
+
hint: `Check the path for a typo, define the referenced ${route.collection.replace(/s$/, "")}, or ignore this if the route is served by another installed package or a host/console route.`
|
|
3042
|
+
});
|
|
3043
|
+
return;
|
|
3044
|
+
}
|
|
3045
|
+
};
|
|
3046
|
+
for (let di = 0; di < dashboards.length; di++) {
|
|
3047
|
+
const dash = dashboards[di];
|
|
3048
|
+
if (!dash || typeof dash !== "object") continue;
|
|
3049
|
+
const dashName = strName(dash.name) ?? `(dashboard ${di})`;
|
|
3050
|
+
const dashPath = `dashboards[${di}]`;
|
|
3051
|
+
const headerActions = asArray20(dash.header?.actions);
|
|
3052
|
+
for (let ai = 0; ai < headerActions.length; ai++) {
|
|
3053
|
+
const action = headerActions[ai];
|
|
3054
|
+
if (!action || typeof action !== "object") continue;
|
|
3055
|
+
const label2 = strName(action.label) ?? strName(action.actionUrl) ?? `#${ai}`;
|
|
3056
|
+
checkOne(
|
|
3057
|
+
action,
|
|
3058
|
+
`dashboard "${dashName}" \xB7 header action "${label2}"`,
|
|
3059
|
+
`${dashPath}.header.actions[${ai}].actionUrl`
|
|
3060
|
+
);
|
|
3061
|
+
}
|
|
3062
|
+
const widgets = asArray20(dash.widgets);
|
|
3063
|
+
for (let wi = 0; wi < widgets.length; wi++) {
|
|
3064
|
+
const widget = widgets[wi];
|
|
3065
|
+
if (!widget || typeof widget !== "object") continue;
|
|
3066
|
+
if (!strName(widget.actionUrl)) continue;
|
|
3067
|
+
const widgetId = strName(widget.id) ?? `#${wi}`;
|
|
3068
|
+
checkOne(
|
|
3069
|
+
{ actionType: widget.actionType, actionUrl: widget.actionUrl },
|
|
3070
|
+
`dashboard "${dashName}" \xB7 widget "${widgetId}" action`,
|
|
3071
|
+
`${dashPath}.widgets[${wi}].actionUrl`
|
|
3072
|
+
);
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
return findings;
|
|
3076
|
+
}
|
|
3077
|
+
|
|
3078
|
+
// src/validate-filter-tokens.ts
|
|
3079
|
+
import { classifyFilterToken, CONTEXT_TOKENS } from "@objectstack/spec/data";
|
|
3080
|
+
var FILTER_TOKEN_UNKNOWN = "filter-token-unknown";
|
|
3081
|
+
var FILTER_KEYS = /* @__PURE__ */ new Set(["filter", "filters", "runtimeFilter"]);
|
|
3082
|
+
function asArray21(v) {
|
|
3083
|
+
if (Array.isArray(v)) return v;
|
|
3084
|
+
if (v && typeof v === "object") {
|
|
3085
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
3086
|
+
}
|
|
3087
|
+
return [];
|
|
3088
|
+
}
|
|
3089
|
+
function label(v, fallback) {
|
|
3090
|
+
return typeof v === "string" && v.length > 0 ? v : fallback;
|
|
3091
|
+
}
|
|
3092
|
+
var KNOWN_LIST = CONTEXT_TOKENS.join("}, {");
|
|
3093
|
+
function walkFilterValues(node, path, where, out, seen) {
|
|
3094
|
+
if (node === null || node === void 0) return;
|
|
3095
|
+
if (typeof node === "string") {
|
|
3096
|
+
const cls = classifyFilterToken(node);
|
|
3097
|
+
if (cls?.kind === "unknown") {
|
|
3098
|
+
const suggestion = cls.suggestion;
|
|
3099
|
+
out.push({
|
|
3100
|
+
severity: "error",
|
|
3101
|
+
rule: FILTER_TOKEN_UNKNOWN,
|
|
3102
|
+
where,
|
|
3103
|
+
path,
|
|
3104
|
+
message: `Filter value "${node}" is not a resolvable placeholder. It is sent to the data engine as a literal string, matches no record, and the surface renders empty.`,
|
|
3105
|
+
hint: suggestion ? `Did you mean "{${suggestion}}"? Context tokens are {${KNOWN_LIST}}; time-based values use date macros such as {today} or {30_days_ago}.` : `Resolvable placeholders are the context tokens {${KNOWN_LIST}} and the date macros (e.g. {today}, {week_start}, {30_days_ago}). To filter on a literal value that happens to look like a placeholder, this is not supported \u2014 rename the value.`
|
|
3106
|
+
});
|
|
3107
|
+
}
|
|
3108
|
+
return;
|
|
3109
|
+
}
|
|
3110
|
+
if (typeof node !== "object") return;
|
|
3111
|
+
if (seen.has(node)) return;
|
|
3112
|
+
seen.add(node);
|
|
3113
|
+
if (Array.isArray(node)) {
|
|
3114
|
+
node.forEach((v, i) => walkFilterValues(v, `${path}[${i}]`, where, out, seen));
|
|
3115
|
+
return;
|
|
3116
|
+
}
|
|
3117
|
+
for (const [k, v] of Object.entries(node)) {
|
|
3118
|
+
walkFilterValues(v, `${path}.${k}`, where, out, seen);
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
function scanForFilters(node, path, where, out, seen) {
|
|
3122
|
+
if (!node || typeof node !== "object") return;
|
|
3123
|
+
if (seen.has(node)) return;
|
|
3124
|
+
seen.add(node);
|
|
3125
|
+
if (Array.isArray(node)) {
|
|
3126
|
+
node.forEach((v, i) => scanForFilters(v, `${path}[${i}]`, where, out, seen));
|
|
3127
|
+
return;
|
|
3128
|
+
}
|
|
3129
|
+
for (const [k, v] of Object.entries(node)) {
|
|
3130
|
+
const childPath = `${path}.${k}`;
|
|
3131
|
+
if (FILTER_KEYS.has(k)) {
|
|
3132
|
+
walkFilterValues(v, childPath, where, out, /* @__PURE__ */ new Set());
|
|
3133
|
+
continue;
|
|
3134
|
+
}
|
|
3135
|
+
scanForFilters(v, childPath, where, out, seen);
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
function validateFilterTokens(stack) {
|
|
3139
|
+
if (!stack || typeof stack !== "object") return [];
|
|
3140
|
+
const out = [];
|
|
3141
|
+
const surfaces = [
|
|
3142
|
+
["dashboards", "dashboard"],
|
|
3143
|
+
["objects", "object"],
|
|
3144
|
+
["views", "view"],
|
|
3145
|
+
["reports", "report"],
|
|
3146
|
+
["datasets", "dataset"],
|
|
3147
|
+
["pages", "page"],
|
|
3148
|
+
["apps", "app"]
|
|
3149
|
+
];
|
|
3150
|
+
for (const [key, kind] of surfaces) {
|
|
3151
|
+
const items = asArray21(stack[key]);
|
|
3152
|
+
items.forEach((item, i) => {
|
|
3153
|
+
const name = label(item.name ?? item.id, `#${i}`);
|
|
3154
|
+
if (kind === "dashboard") {
|
|
3155
|
+
const widgets = Array.isArray(item.widgets) ? item.widgets : [];
|
|
3156
|
+
widgets.forEach((w, wi) => {
|
|
3157
|
+
const wName = label(w.id ?? w.title, `#${wi}`);
|
|
3158
|
+
scanForFilters(
|
|
3159
|
+
w,
|
|
3160
|
+
`${key}[${i}].widgets[${wi}]`,
|
|
3161
|
+
`dashboard "${name}" \xB7 widget "${wName}"`,
|
|
3162
|
+
out,
|
|
3163
|
+
/* @__PURE__ */ new Set()
|
|
3164
|
+
);
|
|
3165
|
+
});
|
|
3166
|
+
const { widgets: _skip, ...rest } = item;
|
|
3167
|
+
scanForFilters(rest, `${key}[${i}]`, `dashboard "${name}"`, out, /* @__PURE__ */ new Set());
|
|
3168
|
+
return;
|
|
3169
|
+
}
|
|
3170
|
+
scanForFilters(item, `${key}[${i}]`, `${kind} "${name}"`, out, /* @__PURE__ */ new Set());
|
|
3171
|
+
});
|
|
3172
|
+
}
|
|
3173
|
+
return out;
|
|
3174
|
+
}
|
|
3175
|
+
|
|
3176
|
+
// src/validate-object-references.ts
|
|
3177
|
+
import {
|
|
3178
|
+
hasPlatformObjectPrefix,
|
|
3179
|
+
isPlatformProvidedObjectName,
|
|
3180
|
+
PLATFORM_PROVIDED_OBJECT_NAMES
|
|
3181
|
+
} from "@objectstack/spec/system";
|
|
3182
|
+
var PLATFORM_NAMES = [...PLATFORM_PROVIDED_OBJECT_NAMES];
|
|
3183
|
+
var OBJECT_REFERENCE_UNKNOWN = "object-reference-unknown";
|
|
3184
|
+
var OBJECT_REFERENCE_UNREGISTERED_PLATFORM = "object-reference-unregistered-platform";
|
|
3185
|
+
function asArray22(v) {
|
|
3186
|
+
if (Array.isArray(v)) return v;
|
|
3187
|
+
if (v && typeof v === "object") {
|
|
3188
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
3189
|
+
}
|
|
3190
|
+
return [];
|
|
3191
|
+
}
|
|
3192
|
+
function strName2(v) {
|
|
3193
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
3194
|
+
}
|
|
3195
|
+
function isInterpolated(target) {
|
|
3196
|
+
if (target.includes("${")) return true;
|
|
3197
|
+
const open = target.indexOf("{");
|
|
3198
|
+
return open !== -1 && target.indexOf("}", open + 2) !== -1;
|
|
3199
|
+
}
|
|
3200
|
+
function suggest2(target, known) {
|
|
3201
|
+
let best;
|
|
3202
|
+
let bestScore = Infinity;
|
|
3203
|
+
for (const candidate of known) {
|
|
3204
|
+
const d = distance(target, candidate);
|
|
3205
|
+
if (d < bestScore) {
|
|
3206
|
+
bestScore = d;
|
|
3207
|
+
best = candidate;
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
const limit = Math.max(2, Math.floor(target.length / 3));
|
|
3211
|
+
return best && bestScore <= limit ? ` Did you mean "${best}"?` : "";
|
|
3212
|
+
}
|
|
3213
|
+
function distance(a, b) {
|
|
3214
|
+
const m = a.length;
|
|
3215
|
+
const n = b.length;
|
|
3216
|
+
if (m === 0) return n;
|
|
3217
|
+
if (n === 0) return m;
|
|
3218
|
+
let prev = Array.from({ length: n + 1 }, (_, j) => j);
|
|
3219
|
+
for (let i = 1; i <= m; i++) {
|
|
3220
|
+
const curr = [i, ...new Array(n).fill(0)];
|
|
3221
|
+
for (let j = 1; j <= n; j++) {
|
|
3222
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
3223
|
+
curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);
|
|
3224
|
+
}
|
|
3225
|
+
prev = curr;
|
|
3226
|
+
}
|
|
3227
|
+
return prev[n];
|
|
3228
|
+
}
|
|
3229
|
+
function validateObjectReferences(stack) {
|
|
3230
|
+
const findings = [];
|
|
3231
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
3232
|
+
const objects = asArray22(stack.objects);
|
|
3233
|
+
const ownObjects = /* @__PURE__ */ new Set();
|
|
3234
|
+
for (const obj of objects) {
|
|
3235
|
+
const n = strName2(obj.name);
|
|
3236
|
+
if (n) ownObjects.add(n);
|
|
3237
|
+
}
|
|
3238
|
+
const check = (target, where, path, subject, fix) => {
|
|
3239
|
+
const name = strName2(target);
|
|
3240
|
+
if (!name) return;
|
|
3241
|
+
if (isInterpolated(name)) return;
|
|
3242
|
+
if (ownObjects.has(name)) return;
|
|
3243
|
+
if (isPlatformProvidedObjectName(name)) return;
|
|
3244
|
+
if (hasPlatformObjectPrefix(name)) {
|
|
3245
|
+
findings.push({
|
|
3246
|
+
severity: "warning",
|
|
3247
|
+
rule: OBJECT_REFERENCE_UNREGISTERED_PLATFORM,
|
|
3248
|
+
where,
|
|
3249
|
+
path,
|
|
3250
|
+
message: `${subject} "${name}" carries a platform namespace prefix, but no platform package, official plugin, or cloud runtime object registers that name \u2014 and this stack does not define it either. If nothing provides it at runtime the reference resolves to nothing and fails silently.` + suggest2(name, PLATFORM_NAMES),
|
|
3251
|
+
hint: `Check the spelling against the object the providing package actually registers (e.g. "sys_approval_request", not "sys_approval_process" \u2014 the process object was removed when approval became a flow node, ADR-0019). If a third-party package genuinely provides it, this warning is expected. ${fix}`
|
|
3252
|
+
});
|
|
3253
|
+
return;
|
|
3254
|
+
}
|
|
3255
|
+
findings.push({
|
|
3256
|
+
severity: "error",
|
|
3257
|
+
rule: OBJECT_REFERENCE_UNKNOWN,
|
|
3258
|
+
where,
|
|
3259
|
+
path,
|
|
3260
|
+
message: `${subject} "${name}" resolves to no object defined in this stack. The reference is inert at runtime \u2014 nothing reports the miss.` + suggest2(name, ownObjects),
|
|
3261
|
+
hint: `Point it at one of this stack's objects, or at a platform object by its full name (the platform user object is "sys_user", not "user"). ${fix}` + (ownObjects.size > 0 ? ` Defined objects: ${[...ownObjects].sort().join(", ")}.` : "")
|
|
3262
|
+
});
|
|
3263
|
+
};
|
|
3264
|
+
const checkActionParams2 = (action, actionPath, actionLabel) => {
|
|
3265
|
+
const params = asArray22(action.params);
|
|
3266
|
+
for (let pi = 0; pi < params.length; pi++) {
|
|
3267
|
+
const param = params[pi];
|
|
3268
|
+
if (!param || typeof param !== "object") continue;
|
|
3269
|
+
const paramLabel = strName2(param.name) ?? strName2(param.field) ?? `#${pi}`;
|
|
3270
|
+
const where = `${actionLabel} \xB7 param "${paramLabel}"`;
|
|
3271
|
+
check(
|
|
3272
|
+
strName2(param.reference),
|
|
3273
|
+
where,
|
|
3274
|
+
`${actionPath}.params[${pi}].reference`,
|
|
3275
|
+
"record-picker target",
|
|
3276
|
+
"Without a resolvable target the picker degrades to a raw record-id text input."
|
|
3277
|
+
);
|
|
3278
|
+
check(
|
|
3279
|
+
strName2(param.objectOverride),
|
|
3280
|
+
where,
|
|
3281
|
+
`${actionPath}.params[${pi}].objectOverride`,
|
|
3282
|
+
"field-backed param object",
|
|
3283
|
+
"The param inherits type/options from a field on this object, so an unknown object leaves it untyped."
|
|
3284
|
+
);
|
|
3285
|
+
}
|
|
3286
|
+
};
|
|
3287
|
+
const globalActions = asArray22(stack.actions);
|
|
3288
|
+
for (let ai = 0; ai < globalActions.length; ai++) {
|
|
3289
|
+
const action = globalActions[ai];
|
|
3290
|
+
if (!action || typeof action !== "object") continue;
|
|
3291
|
+
checkActionParams2(action, `actions[${ai}]`, `action "${strName2(action.name) ?? `#${ai}`}"`);
|
|
3292
|
+
}
|
|
3293
|
+
for (let oi = 0; oi < objects.length; oi++) {
|
|
3294
|
+
const obj = objects[oi];
|
|
3295
|
+
if (!obj || typeof obj !== "object") continue;
|
|
3296
|
+
const objName = strName2(obj.name) ?? `#${oi}`;
|
|
3297
|
+
const objActions = asArray22(obj.actions);
|
|
3298
|
+
for (let ai = 0; ai < objActions.length; ai++) {
|
|
3299
|
+
const action = objActions[ai];
|
|
3300
|
+
if (!action || typeof action !== "object") continue;
|
|
3301
|
+
checkActionParams2(
|
|
3302
|
+
action,
|
|
3303
|
+
`objects[${oi}].actions[${ai}]`,
|
|
3304
|
+
`object "${objName}" \xB7 action "${strName2(action.name) ?? `#${ai}`}"`
|
|
3305
|
+
);
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
const dashboards = asArray22(stack.dashboards);
|
|
3309
|
+
for (let di = 0; di < dashboards.length; di++) {
|
|
3310
|
+
const dash = dashboards[di];
|
|
3311
|
+
if (!dash || typeof dash !== "object") continue;
|
|
3312
|
+
const dashName = strName2(dash.name) ?? `#${di}`;
|
|
3313
|
+
const filters = asArray22(dash.globalFilters);
|
|
3314
|
+
for (let fi = 0; fi < filters.length; fi++) {
|
|
3315
|
+
const filter = filters[fi];
|
|
3316
|
+
if (!filter || typeof filter !== "object") continue;
|
|
3317
|
+
const optionsFrom = filter.optionsFrom;
|
|
3318
|
+
if (!optionsFrom || typeof optionsFrom !== "object") continue;
|
|
3319
|
+
check(
|
|
3320
|
+
strName2(optionsFrom.object),
|
|
3321
|
+
`dashboard "${dashName}" \xB7 filter "${strName2(filter.name) ?? `#${fi}`}"`,
|
|
3322
|
+
`dashboards[${di}].globalFilters[${fi}].optionsFrom.object`,
|
|
3323
|
+
"filter options source",
|
|
3324
|
+
"The dropdown fetches its options from this object; an unknown one renders an always-empty filter."
|
|
3325
|
+
);
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
const apps = asArray22(stack.apps);
|
|
3329
|
+
for (let ai = 0; ai < apps.length; ai++) {
|
|
3330
|
+
const app = apps[ai];
|
|
3331
|
+
if (!app || typeof app !== "object") continue;
|
|
3332
|
+
const appName = strName2(app.name) ?? `#${ai}`;
|
|
3333
|
+
const walkNav = (items, basePath) => {
|
|
3334
|
+
const navItems = asArray22(items);
|
|
3335
|
+
for (let ni = 0; ni < navItems.length; ni++) {
|
|
3336
|
+
const nav = navItems[ni];
|
|
3337
|
+
if (!nav || typeof nav !== "object") continue;
|
|
3338
|
+
const navId = strName2(nav.id) ?? `#${ni}`;
|
|
3339
|
+
const where = `app "${appName}" \xB7 nav "${navId}"`;
|
|
3340
|
+
const navPath = `${basePath}[${ni}]`;
|
|
3341
|
+
check(
|
|
3342
|
+
strName2(nav.requiresObject),
|
|
3343
|
+
where,
|
|
3344
|
+
`${navPath}.requiresObject`,
|
|
3345
|
+
"capability gate object",
|
|
3346
|
+
"The entry is hidden unless this object is registered, so a typo hides it permanently \u2014 and it suppresses the nav cross-reference check that would have caught the target."
|
|
3347
|
+
);
|
|
3348
|
+
if (nav.requiresObject && strName2(nav.objectName)) {
|
|
3349
|
+
check(
|
|
3350
|
+
strName2(nav.objectName),
|
|
3351
|
+
where,
|
|
3352
|
+
`${navPath}.objectName`,
|
|
3353
|
+
"navigation target",
|
|
3354
|
+
"Declaring `requiresObject` exempts this target from the build-time check, so it is only verified here."
|
|
3355
|
+
);
|
|
3356
|
+
}
|
|
3357
|
+
if (Array.isArray(nav.children)) walkNav(nav.children, `${navPath}.children`);
|
|
3358
|
+
}
|
|
3359
|
+
};
|
|
3360
|
+
walkNav(app.navigation, `apps[${ai}].navigation`);
|
|
3361
|
+
const areas = asArray22(app.areas);
|
|
3362
|
+
for (let ri = 0; ri < areas.length; ri++) {
|
|
3363
|
+
walkNav(areas[ri]?.navigation, `apps[${ai}].areas[${ri}].navigation`);
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
return findings;
|
|
3367
|
+
}
|
|
3368
|
+
|
|
3369
|
+
// src/page-walk.ts
|
|
3370
|
+
function isRec2(v) {
|
|
3371
|
+
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
3372
|
+
}
|
|
3373
|
+
function strName3(v) {
|
|
3374
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
3375
|
+
}
|
|
3376
|
+
var SOURCE_AUTHORED_KINDS = /* @__PURE__ */ new Set(["html", "react", "jsx"]);
|
|
3377
|
+
function isSourceAuthoredPage(page) {
|
|
3378
|
+
const kind = strName3(page.kind);
|
|
3379
|
+
return kind !== void 0 && SOURCE_AUTHORED_KINDS.has(kind);
|
|
3380
|
+
}
|
|
3381
|
+
function walkPageComponents(page, pagePath) {
|
|
3382
|
+
const out = [];
|
|
3383
|
+
if (!isRec2(page) || isSourceAuthoredPage(page)) return out;
|
|
3384
|
+
const pageObject = strName3(page.object);
|
|
3385
|
+
const visit = (node, path, inheritedObject) => {
|
|
3386
|
+
if (!isRec2(node)) return;
|
|
3387
|
+
const props = isRec2(node.properties) ? node.properties : void 0;
|
|
3388
|
+
const dataSource = isRec2(node.dataSource) ? node.dataSource : void 0;
|
|
3389
|
+
const objectName = strName3(dataSource?.object) ?? strName3(props?.object) ?? inheritedObject;
|
|
3390
|
+
out.push({ component: node, path, objectName });
|
|
3391
|
+
if (!props) return;
|
|
3392
|
+
if (Array.isArray(props.items)) {
|
|
3393
|
+
for (let i = 0; i < props.items.length; i++) {
|
|
3394
|
+
const item = props.items[i];
|
|
3395
|
+
if (!isRec2(item) || !Array.isArray(item.children)) continue;
|
|
3396
|
+
for (let c = 0; c < item.children.length; c++) {
|
|
3397
|
+
visit(item.children[c], `${path}.properties.items[${i}].children[${c}]`, objectName);
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3401
|
+
if (Array.isArray(props.children)) {
|
|
3402
|
+
for (let i = 0; i < props.children.length; i++) {
|
|
3403
|
+
visit(props.children[i], `${path}.properties.children[${i}]`, objectName);
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
for (const key of ["body", "footer"]) {
|
|
3407
|
+
const slotList = props[key];
|
|
3408
|
+
if (!Array.isArray(slotList)) continue;
|
|
3409
|
+
for (let i = 0; i < slotList.length; i++) {
|
|
3410
|
+
visit(slotList[i], `${path}.properties.${key}[${i}]`, objectName);
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
};
|
|
3414
|
+
const regions = Array.isArray(page.regions) ? page.regions : [];
|
|
3415
|
+
for (let r = 0; r < regions.length; r++) {
|
|
3416
|
+
const region = regions[r];
|
|
3417
|
+
if (!isRec2(region) || !Array.isArray(region.components)) continue;
|
|
3418
|
+
for (let c = 0; c < region.components.length; c++) {
|
|
3419
|
+
visit(region.components[c], `${pagePath}.regions[${r}].components[${c}]`, pageObject);
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
const slots = isRec2(page.slots) ? page.slots : void 0;
|
|
3423
|
+
if (slots) {
|
|
3424
|
+
for (const [slot, value] of Object.entries(slots)) {
|
|
3425
|
+
const list3 = Array.isArray(value) ? value : [value];
|
|
3426
|
+
const indexed = Array.isArray(value);
|
|
3427
|
+
for (let i = 0; i < list3.length; i++) {
|
|
3428
|
+
visit(list3[i], `${pagePath}.slots.${slot}${indexed ? `[${i}]` : ""}`, pageObject);
|
|
3429
|
+
}
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
return out;
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3435
|
+
// src/validate-action-name-refs.ts
|
|
3436
|
+
var ACTION_NAME_UNDEFINED = "action-name-undefined";
|
|
3437
|
+
function asArray23(v) {
|
|
3438
|
+
if (Array.isArray(v)) return v;
|
|
3439
|
+
if (v && typeof v === "object") {
|
|
3440
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
3441
|
+
}
|
|
3442
|
+
return [];
|
|
3443
|
+
}
|
|
3444
|
+
function strName4(v) {
|
|
3445
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
3446
|
+
}
|
|
3447
|
+
function strList(v) {
|
|
3448
|
+
return Array.isArray(v) ? v.filter((x) => typeof x === "string" && x.length > 0) : [];
|
|
3449
|
+
}
|
|
3450
|
+
function distance2(a, b) {
|
|
3451
|
+
const m = a.length;
|
|
3452
|
+
const n = b.length;
|
|
3453
|
+
if (m === 0) return n;
|
|
3454
|
+
if (n === 0) return m;
|
|
3455
|
+
let prev = Array.from({ length: n + 1 }, (_, j) => j);
|
|
3456
|
+
for (let i = 1; i <= m; i++) {
|
|
3457
|
+
const curr = [i, ...new Array(n).fill(0)];
|
|
3458
|
+
for (let j = 1; j <= n; j++) {
|
|
3459
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
3460
|
+
curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);
|
|
3461
|
+
}
|
|
3462
|
+
prev = curr;
|
|
3463
|
+
}
|
|
3464
|
+
return prev[n];
|
|
3465
|
+
}
|
|
3466
|
+
function suggest3(target, known) {
|
|
3467
|
+
let best;
|
|
3468
|
+
let bestScore = Infinity;
|
|
3469
|
+
for (const candidate of known) {
|
|
3470
|
+
const d = distance2(target, candidate);
|
|
3471
|
+
if (d < bestScore) {
|
|
3472
|
+
bestScore = d;
|
|
3473
|
+
best = candidate;
|
|
3474
|
+
}
|
|
3475
|
+
}
|
|
3476
|
+
const limit = Math.max(2, Math.floor(target.length / 3));
|
|
3477
|
+
return best && bestScore <= limit ? ` Did you mean "${best}"?` : "";
|
|
3478
|
+
}
|
|
3479
|
+
function collectActionNames(stack) {
|
|
3480
|
+
const names = /* @__PURE__ */ new Set();
|
|
3481
|
+
for (const action of asArray23(stack.actions)) {
|
|
3482
|
+
const n = strName4(action?.name);
|
|
3483
|
+
if (n) names.add(n);
|
|
3484
|
+
}
|
|
3485
|
+
for (const obj of asArray23(stack.objects)) {
|
|
3486
|
+
if (!obj || typeof obj !== "object") continue;
|
|
3487
|
+
for (const action of asArray23(obj.actions)) {
|
|
3488
|
+
const n = strName4(action?.name);
|
|
3489
|
+
if (n) names.add(n);
|
|
3490
|
+
}
|
|
3491
|
+
}
|
|
3492
|
+
return names;
|
|
3493
|
+
}
|
|
3494
|
+
function validateActionNameRefs(stack) {
|
|
3495
|
+
const findings = [];
|
|
3496
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
3497
|
+
const known = collectActionNames(stack);
|
|
3498
|
+
const check = (name, where, path, surface) => {
|
|
3499
|
+
if (known.has(name)) return;
|
|
3500
|
+
findings.push({
|
|
3501
|
+
severity: "error",
|
|
3502
|
+
rule: ACTION_NAME_UNDEFINED,
|
|
3503
|
+
where,
|
|
3504
|
+
path,
|
|
3505
|
+
message: `${surface} names action "${name}", which is defined by no action in this stack (neither \`stack.actions\` nor any object's \`actions\`). The button renders and does nothing when clicked \u2014 a dead affordance the runtime cannot dispatch.` + suggest3(name, known),
|
|
3506
|
+
hint: `Define an action named "${name}" (in \`stack.actions\` or the object's \`actions\`) with the location this surface needs, remove the reference, or ignore this if the action is contributed by another installed package.` + (known.size > 0 ? ` Defined actions: ${[...known].sort().join(", ")}.` : "")
|
|
3507
|
+
});
|
|
3508
|
+
};
|
|
3509
|
+
const views = asArray23(stack.views);
|
|
3510
|
+
for (let vi = 0; vi < views.length; vi++) {
|
|
3511
|
+
const view = views[vi];
|
|
3512
|
+
if (!view || typeof view !== "object") continue;
|
|
3513
|
+
const viewName = strName4(view.name) ?? strName4(view.object) ?? `#${vi}`;
|
|
3514
|
+
const checkListContainer = (container, label2, path) => {
|
|
3515
|
+
if (!container || typeof container !== "object") return;
|
|
3516
|
+
const list3 = container;
|
|
3517
|
+
for (const key of ["rowActions", "bulkActions"]) {
|
|
3518
|
+
const names = strList(list3[key]);
|
|
3519
|
+
for (let ai = 0; ai < names.length; ai++) {
|
|
3520
|
+
check(
|
|
3521
|
+
names[ai],
|
|
3522
|
+
`view "${viewName}" \xB7 ${label2} \xB7 ${key}`,
|
|
3523
|
+
`${path}.${key}[${ai}]`,
|
|
3524
|
+
key === "bulkActions" ? "Bulk-action menu" : "Row-action menu"
|
|
3525
|
+
);
|
|
3526
|
+
}
|
|
3527
|
+
}
|
|
3528
|
+
};
|
|
3529
|
+
checkListContainer(view.list, "list", `views[${vi}].list`);
|
|
3530
|
+
const listViews = view.listViews;
|
|
3531
|
+
if (listViews && typeof listViews === "object" && !Array.isArray(listViews)) {
|
|
3532
|
+
for (const [key, lv] of Object.entries(listViews)) {
|
|
3533
|
+
checkListContainer(lv, `listViews.${key}`, `views[${vi}].listViews.${key}`);
|
|
3534
|
+
}
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
const pages = asArray23(stack.pages);
|
|
3538
|
+
for (let pi = 0; pi < pages.length; pi++) {
|
|
3539
|
+
const page = pages[pi];
|
|
3540
|
+
if (!page || typeof page !== "object") continue;
|
|
3541
|
+
const pageName = strName4(page.name) ?? `#${pi}`;
|
|
3542
|
+
for (const { component, path } of walkPageComponents(page, `pages[${pi}]`)) {
|
|
3543
|
+
const props = component.properties;
|
|
3544
|
+
if (!props || typeof props !== "object") continue;
|
|
3545
|
+
const names = strList(props.actionNames);
|
|
3546
|
+
for (let ai = 0; ai < names.length; ai++) {
|
|
3547
|
+
check(
|
|
3548
|
+
names[ai],
|
|
3549
|
+
`page "${pageName}" \xB7 component "${strName4(component.type) ?? "?"}"`,
|
|
3550
|
+
`${path}.properties.actionNames[${ai}]`,
|
|
3551
|
+
"Quick-actions bar"
|
|
3552
|
+
);
|
|
3553
|
+
}
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
const apps = asArray23(stack.apps);
|
|
3557
|
+
for (let ai = 0; ai < apps.length; ai++) {
|
|
3558
|
+
const app = apps[ai];
|
|
3559
|
+
if (!app || typeof app !== "object") continue;
|
|
3560
|
+
const appName = strName4(app.name) ?? `#${ai}`;
|
|
3561
|
+
const walkNav = (items, basePath) => {
|
|
3562
|
+
const navItems = asArray23(items);
|
|
3563
|
+
for (let ni = 0; ni < navItems.length; ni++) {
|
|
3564
|
+
const nav = navItems[ni];
|
|
3565
|
+
if (!nav || typeof nav !== "object") continue;
|
|
3566
|
+
const navPath = `${basePath}[${ni}]`;
|
|
3567
|
+
const actionDef = nav.actionDef;
|
|
3568
|
+
const actionName = strName4(actionDef?.actionName);
|
|
3569
|
+
if (nav.type === "action" && actionName) {
|
|
3570
|
+
check(
|
|
3571
|
+
actionName,
|
|
3572
|
+
`app "${appName}" \xB7 nav "${strName4(nav.id) ?? `#${ni}`}"`,
|
|
3573
|
+
`${navPath}.actionDef.actionName`,
|
|
3574
|
+
"Navigation action item"
|
|
3575
|
+
);
|
|
3576
|
+
}
|
|
3577
|
+
if (Array.isArray(nav.children)) walkNav(nav.children, `${navPath}.children`);
|
|
3578
|
+
}
|
|
3579
|
+
};
|
|
3580
|
+
walkNav(app.navigation, `apps[${ai}].navigation`);
|
|
3581
|
+
const areas = asArray23(app.areas);
|
|
3582
|
+
for (let ri = 0; ri < areas.length; ri++) {
|
|
3583
|
+
walkNav(areas[ri]?.navigation, `apps[${ai}].areas[${ri}].navigation`);
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
return findings;
|
|
3587
|
+
}
|
|
3588
|
+
|
|
3589
|
+
// src/validate-page-field-bindings.ts
|
|
3590
|
+
var PAGE_FIELD_UNKNOWN = "page-field-unknown";
|
|
3591
|
+
var SYSTEM_FIELDS4 = /* @__PURE__ */ new Set([
|
|
3592
|
+
"id",
|
|
3593
|
+
"created_at",
|
|
3594
|
+
"created_by",
|
|
3595
|
+
"updated_at",
|
|
3596
|
+
"updated_by",
|
|
3597
|
+
"owner_id",
|
|
3598
|
+
"organization_id",
|
|
3599
|
+
"tenant_id",
|
|
3600
|
+
"user_id",
|
|
3601
|
+
"deleted_at"
|
|
3602
|
+
]);
|
|
3603
|
+
function asArray24(v) {
|
|
3604
|
+
if (Array.isArray(v)) return v;
|
|
3605
|
+
if (v && typeof v === "object") {
|
|
3606
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
3607
|
+
}
|
|
3608
|
+
return [];
|
|
3609
|
+
}
|
|
3610
|
+
function strName5(v) {
|
|
3611
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
3612
|
+
}
|
|
3613
|
+
function isRec3(v) {
|
|
3614
|
+
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
3615
|
+
}
|
|
3616
|
+
function fieldRefsFrom(value, basePath) {
|
|
3617
|
+
const out = [];
|
|
3618
|
+
const one = (v, path) => {
|
|
3619
|
+
const bare = strName5(v);
|
|
3620
|
+
if (bare) {
|
|
3621
|
+
out.push({ name: bare, path });
|
|
3622
|
+
return;
|
|
3623
|
+
}
|
|
3624
|
+
if (!isRec3(v)) return;
|
|
3625
|
+
const named = strName5(v.field) ?? strName5(v.name);
|
|
3626
|
+
if (named) out.push({ name: named, path: `${path}.${strName5(v.field) ? "field" : "name"}` });
|
|
3627
|
+
};
|
|
3628
|
+
if (Array.isArray(value)) {
|
|
3629
|
+
for (let i = 0; i < value.length; i++) one(value[i], `${basePath}[${i}]`);
|
|
3630
|
+
} else {
|
|
3631
|
+
one(value, basePath);
|
|
3632
|
+
}
|
|
3633
|
+
return out;
|
|
3634
|
+
}
|
|
3635
|
+
var COMPONENT_FIELD_SPECS = {
|
|
3636
|
+
"record:highlights": { props: ["fields"] },
|
|
3637
|
+
// `sections`/`hideFields` are not in RecordDetailsProps, but every real page
|
|
3638
|
+
// authors them (they survive because `properties` is unvalidated).
|
|
3639
|
+
"record:details": { props: ["fields", "hideFields"], nestedSections: ["sections"] },
|
|
3640
|
+
"record:path": { props: ["statusField"] },
|
|
3641
|
+
"element:number": { props: ["field"] },
|
|
3642
|
+
"element:filter": { props: ["fields"] },
|
|
3643
|
+
"element:form": { props: ["fields"] },
|
|
3644
|
+
// The schema says `displayField`; real pages author `labelField`. Accept both.
|
|
3645
|
+
"element:record_picker": { props: ["displayField", "labelField", "searchFields"] }
|
|
3646
|
+
};
|
|
3647
|
+
var RELATED_LIST_TYPE = "record:related_list";
|
|
3648
|
+
function validatePageFieldBindings(stack) {
|
|
3649
|
+
const findings = [];
|
|
3650
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
3651
|
+
const objectFields = /* @__PURE__ */ new Map();
|
|
3652
|
+
for (const obj of asArray24(stack.objects)) {
|
|
3653
|
+
const name = strName5(obj.name);
|
|
3654
|
+
if (!name) continue;
|
|
3655
|
+
const names = /* @__PURE__ */ new Set();
|
|
3656
|
+
for (const f of asArray24(obj.fields)) {
|
|
3657
|
+
const fn = strName5(f.name);
|
|
3658
|
+
if (fn) names.add(fn);
|
|
3659
|
+
}
|
|
3660
|
+
objectFields.set(name, names);
|
|
3661
|
+
}
|
|
3662
|
+
const pages = asArray24(stack.pages);
|
|
3663
|
+
for (let pi = 0; pi < pages.length; pi++) {
|
|
3664
|
+
const page = pages[pi];
|
|
3665
|
+
if (!page || typeof page !== "object") continue;
|
|
3666
|
+
const pageName = strName5(page.name) ?? `#${pi}`;
|
|
3667
|
+
const checkRefs = (refs, objectName, where) => {
|
|
3668
|
+
if (!objectName) return;
|
|
3669
|
+
const known = objectFields.get(objectName);
|
|
3670
|
+
if (!known) return;
|
|
3671
|
+
for (const ref of refs) {
|
|
3672
|
+
if (ref.name.includes(".")) continue;
|
|
3673
|
+
if (known.has(ref.name) || SYSTEM_FIELDS4.has(ref.name)) continue;
|
|
3674
|
+
findings.push({
|
|
3675
|
+
severity: "warning",
|
|
3676
|
+
rule: PAGE_FIELD_UNKNOWN,
|
|
3677
|
+
where,
|
|
3678
|
+
path: ref.path,
|
|
3679
|
+
message: `field "${ref.name}" is not a field on object "${objectName}" \u2014 the component silently skips it, so it never renders.`,
|
|
3680
|
+
hint: `Fix the field name, or add "${ref.name}" to ${objectName}. References must match the object's field names exactly.` + (known.size > 0 ? ` Object fields: ${[...known].sort().join(", ")}.` : "")
|
|
3681
|
+
});
|
|
3682
|
+
}
|
|
3683
|
+
};
|
|
3684
|
+
for (const { component, path, objectName } of walkPageComponents(page, `pages[${pi}]`)) {
|
|
3685
|
+
const type = strName5(component.type);
|
|
3686
|
+
const props = isRec3(component.properties) ? component.properties : void 0;
|
|
3687
|
+
if (!type || !props) continue;
|
|
3688
|
+
const where = `page "${pageName}" \xB7 ${type}`;
|
|
3689
|
+
if (type === RELATED_LIST_TYPE) {
|
|
3690
|
+
const relatedObject = strName5(props.objectName);
|
|
3691
|
+
const relatedRefs = [
|
|
3692
|
+
...fieldRefsFrom(props.columns, `${path}.properties.columns`),
|
|
3693
|
+
...fieldRefsFrom(props.sort, `${path}.properties.sort`),
|
|
3694
|
+
...fieldRefsFrom(props.filter, `${path}.properties.filter`),
|
|
3695
|
+
...fieldRefsFrom(props.relationshipField, `${path}.properties.relationshipField`)
|
|
3696
|
+
];
|
|
3697
|
+
checkRefs(relatedRefs, relatedObject, where);
|
|
3698
|
+
checkRefs(
|
|
3699
|
+
fieldRefsFrom(props.relationshipValueField, `${path}.properties.relationshipValueField`),
|
|
3700
|
+
objectName,
|
|
3701
|
+
where
|
|
3702
|
+
);
|
|
3703
|
+
const add = isRec3(props.add) ? props.add : void 0;
|
|
3704
|
+
const picker = add && isRec3(add.picker) ? add.picker : void 0;
|
|
3705
|
+
if (picker) {
|
|
3706
|
+
checkRefs(
|
|
3707
|
+
[
|
|
3708
|
+
...fieldRefsFrom(picker.valueField, `${path}.properties.add.picker.valueField`),
|
|
3709
|
+
...fieldRefsFrom(picker.labelField, `${path}.properties.add.picker.labelField`)
|
|
3710
|
+
],
|
|
3711
|
+
strName5(picker.object),
|
|
3712
|
+
where
|
|
3713
|
+
);
|
|
3714
|
+
}
|
|
3715
|
+
if (add) {
|
|
3716
|
+
checkRefs(
|
|
3717
|
+
fieldRefsFrom(add.linkField, `${path}.properties.add.linkField`),
|
|
3718
|
+
relatedObject,
|
|
3719
|
+
where
|
|
3720
|
+
);
|
|
3721
|
+
}
|
|
3722
|
+
continue;
|
|
3723
|
+
}
|
|
3724
|
+
const spec = COMPONENT_FIELD_SPECS[type];
|
|
3725
|
+
if (!spec) continue;
|
|
3726
|
+
const refs = [];
|
|
3727
|
+
for (const key of spec.props ?? []) {
|
|
3728
|
+
refs.push(...fieldRefsFrom(props[key], `${path}.properties.${key}`));
|
|
3729
|
+
}
|
|
3730
|
+
for (const key of spec.nestedSections ?? []) {
|
|
3731
|
+
const sections = Array.isArray(props[key]) ? props[key] : [];
|
|
3732
|
+
for (let si = 0; si < sections.length; si++) {
|
|
3733
|
+
const section = sections[si];
|
|
3734
|
+
if (!isRec3(section)) continue;
|
|
3735
|
+
refs.push(
|
|
3736
|
+
...fieldRefsFrom(section.fields, `${path}.properties.${key}[${si}].fields`)
|
|
3737
|
+
);
|
|
3738
|
+
}
|
|
3739
|
+
}
|
|
3740
|
+
checkRefs(refs, objectName, where);
|
|
3741
|
+
}
|
|
3742
|
+
const cfg = isRec3(page.interfaceConfig) ? page.interfaceConfig : void 0;
|
|
3743
|
+
if (cfg) {
|
|
3744
|
+
const cfgObject = strName5(cfg.source) ?? strName5(page.object);
|
|
3745
|
+
const base = `pages[${pi}].interfaceConfig`;
|
|
3746
|
+
const refs = [
|
|
3747
|
+
...fieldRefsFrom(cfg.columns, `${base}.columns`),
|
|
3748
|
+
...fieldRefsFrom(cfg.sort, `${base}.sort`),
|
|
3749
|
+
...fieldRefsFrom(cfg.filterBy, `${base}.filterBy`)
|
|
3750
|
+
];
|
|
3751
|
+
const userFilters = isRec3(cfg.userFilters) ? cfg.userFilters : void 0;
|
|
3752
|
+
if (userFilters) {
|
|
3753
|
+
refs.push(...fieldRefsFrom(userFilters.fields, `${base}.userFilters.fields`));
|
|
3754
|
+
}
|
|
3755
|
+
checkRefs(refs, cfgObject, `page "${pageName}" \xB7 interfaceConfig`);
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
return findings;
|
|
3759
|
+
}
|
|
3760
|
+
|
|
3761
|
+
// src/validate-chart-bindings.ts
|
|
3762
|
+
var CHART_DIMENSION_UNKNOWN = "chart-dimension-unknown";
|
|
3763
|
+
var CHART_MEASURE_UNKNOWN = "chart-measure-unknown";
|
|
3764
|
+
var CHART_DATASET_UNKNOWN = "chart-dataset-unknown";
|
|
3765
|
+
var CHART_AXIS_NOT_SELECTED = "chart-axis-not-selected";
|
|
3766
|
+
function asArray25(v) {
|
|
3767
|
+
if (Array.isArray(v)) return v;
|
|
3768
|
+
if (v && typeof v === "object") {
|
|
3769
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
3770
|
+
}
|
|
3771
|
+
return [];
|
|
3772
|
+
}
|
|
3773
|
+
function strName6(v) {
|
|
3774
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
3775
|
+
}
|
|
3776
|
+
function strList2(v) {
|
|
3777
|
+
return Array.isArray(v) ? v.filter((x) => typeof x === "string" && x.length > 0) : [];
|
|
3778
|
+
}
|
|
3779
|
+
function isRec4(v) {
|
|
3780
|
+
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
3781
|
+
}
|
|
3782
|
+
function distance3(a, b) {
|
|
3783
|
+
const m = a.length;
|
|
3784
|
+
const n = b.length;
|
|
3785
|
+
if (m === 0) return n;
|
|
3786
|
+
if (n === 0) return m;
|
|
3787
|
+
let prev = Array.from({ length: n + 1 }, (_, j) => j);
|
|
3788
|
+
for (let i = 1; i <= m; i++) {
|
|
3789
|
+
const curr = [i, ...new Array(n).fill(0)];
|
|
3790
|
+
for (let j = 1; j <= n; j++) {
|
|
3791
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
3792
|
+
curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);
|
|
3793
|
+
}
|
|
3794
|
+
prev = curr;
|
|
3795
|
+
}
|
|
3796
|
+
return prev[n];
|
|
3797
|
+
}
|
|
3798
|
+
function suggest4(target, known) {
|
|
3799
|
+
let best;
|
|
3800
|
+
let bestScore = Infinity;
|
|
3801
|
+
for (const c of known) {
|
|
3802
|
+
const d = distance3(target, c);
|
|
3803
|
+
if (d < bestScore) {
|
|
3804
|
+
bestScore = d;
|
|
3805
|
+
best = c;
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
const limit = Math.max(2, Math.floor(target.length / 3));
|
|
3809
|
+
return best && bestScore <= limit ? ` Did you mean "${best}"?` : "";
|
|
3810
|
+
}
|
|
3811
|
+
function list2(names) {
|
|
3812
|
+
const all = [...names].sort();
|
|
3813
|
+
return all.length ? all.join(", ") : "(none)";
|
|
3814
|
+
}
|
|
3815
|
+
function indexDatasets(stack) {
|
|
3816
|
+
const out = /* @__PURE__ */ new Map();
|
|
3817
|
+
for (const ds of asArray25(stack.datasets)) {
|
|
3818
|
+
const name = strName6(ds.name);
|
|
3819
|
+
if (!name) continue;
|
|
3820
|
+
const dimensions = /* @__PURE__ */ new Set();
|
|
3821
|
+
for (const d of asArray25(ds.dimensions)) {
|
|
3822
|
+
const n = strName6(d.name);
|
|
3823
|
+
if (n) dimensions.add(n);
|
|
3824
|
+
}
|
|
3825
|
+
const measures = /* @__PURE__ */ new Set();
|
|
3826
|
+
for (const m of asArray25(ds.measures)) {
|
|
3827
|
+
const n = strName6(m.name);
|
|
3828
|
+
if (n) measures.add(n);
|
|
3829
|
+
}
|
|
3830
|
+
out.set(name, { dimensions, measures });
|
|
3831
|
+
}
|
|
3832
|
+
return out;
|
|
3833
|
+
}
|
|
3834
|
+
function validateChartBindings(stack) {
|
|
3835
|
+
const findings = [];
|
|
3836
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
3837
|
+
const datasets = indexDatasets(stack);
|
|
3838
|
+
if (datasets.size === 0 && !stack.reports && !stack.views && !stack.pages) return findings;
|
|
3839
|
+
const check = (binding) => {
|
|
3840
|
+
const dsName = binding.dataset;
|
|
3841
|
+
if (!dsName) return;
|
|
3842
|
+
const ds = datasets.get(dsName);
|
|
3843
|
+
if (!ds) {
|
|
3844
|
+
findings.push({
|
|
3845
|
+
severity: "error",
|
|
3846
|
+
rule: CHART_DATASET_UNKNOWN,
|
|
3847
|
+
where: binding.where,
|
|
3848
|
+
path: `${binding.path}.dataset`,
|
|
3849
|
+
message: `binds dataset "${dsName}", which resolves to no declared dataset \u2014 the chart has no data to render.`,
|
|
3850
|
+
hint: `Declared datasets: ${list2(datasets.keys())}.${suggest4(dsName, datasets.keys())} Define it with defineDataset() or fix the reference (ADR-0021).`
|
|
3851
|
+
});
|
|
3852
|
+
return;
|
|
3853
|
+
}
|
|
3854
|
+
const dimensionRef = (name, path) => {
|
|
3855
|
+
if (ds.dimensions.has(name)) return;
|
|
3856
|
+
findings.push({
|
|
3857
|
+
severity: "error",
|
|
3858
|
+
rule: CHART_DIMENSION_UNKNOWN,
|
|
3859
|
+
where: binding.where,
|
|
3860
|
+
path,
|
|
3861
|
+
message: `"${name}" is not a dimension declared by dataset "${dsName}". Post-ADR-0021 result rows are keyed by DIMENSION NAME, not the base field, so this axis renders with no categories.`,
|
|
3862
|
+
hint: `Dataset dimensions: ${list2(ds.dimensions)}.${suggest4(name, ds.dimensions)} Declare the dimension on the dataset, or bind an existing one.`
|
|
3863
|
+
});
|
|
3864
|
+
};
|
|
3865
|
+
const measureRef = (name, path, selected2) => {
|
|
3866
|
+
if (!ds.measures.has(name)) {
|
|
3867
|
+
findings.push({
|
|
3868
|
+
severity: "error",
|
|
3869
|
+
rule: CHART_MEASURE_UNKNOWN,
|
|
3870
|
+
where: binding.where,
|
|
3871
|
+
path,
|
|
3872
|
+
message: `"${name}" is not a measure declared by dataset "${dsName}". Post-ADR-0021 result rows are keyed by MEASURE NAME (e.g. "sum_amount"), not the base field (e.g. "amount"), so this series comes back empty.`,
|
|
3873
|
+
hint: `Dataset measures: ${list2(ds.measures)}.${suggest4(name, ds.measures)} Declare the measure on the dataset, or bind an existing one.`
|
|
3874
|
+
});
|
|
3875
|
+
return;
|
|
3876
|
+
}
|
|
3877
|
+
if (selected2 && selected2.size > 0 && !selected2.has(name)) {
|
|
3878
|
+
findings.push({
|
|
3879
|
+
severity: "warning",
|
|
3880
|
+
rule: CHART_AXIS_NOT_SELECTED,
|
|
3881
|
+
where: binding.where,
|
|
3882
|
+
path,
|
|
3883
|
+
message: `"${name}" is a declared measure of "${dsName}" but is not in this chart's selected values (${list2(selected2)}) \u2014 the query does not return it, so the series plots nothing.`,
|
|
3884
|
+
hint: `Add "${name}" to \`values\`, or point the axis at a selected measure.`
|
|
3885
|
+
});
|
|
3886
|
+
}
|
|
3887
|
+
};
|
|
3888
|
+
const dimSel = binding.dimensions;
|
|
3889
|
+
if (dimSel) {
|
|
3890
|
+
for (let i = 0; i < dimSel.names.length; i++) {
|
|
3891
|
+
dimensionRef(dimSel.names[i], `${dimSel.path}[${i}]`);
|
|
3892
|
+
}
|
|
3893
|
+
}
|
|
3894
|
+
const valSel = binding.values;
|
|
3895
|
+
const selected = new Set(valSel?.names ?? []);
|
|
3896
|
+
if (valSel) {
|
|
3897
|
+
for (let i = 0; i < valSel.names.length; i++) {
|
|
3898
|
+
measureRef(valSel.names[i], `${valSel.path}[${i}]`);
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
if (binding.xAxis) dimensionRef(binding.xAxis.name, binding.xAxis.path);
|
|
3902
|
+
if (binding.yAxis) measureRef(binding.yAxis.name, binding.yAxis.path, selected);
|
|
3903
|
+
for (const s of binding.series ?? []) measureRef(s.name, s.path, selected);
|
|
3904
|
+
};
|
|
3905
|
+
const reports = asArray25(stack.reports);
|
|
3906
|
+
for (let ri = 0; ri < reports.length; ri++) {
|
|
3907
|
+
const report = reports[ri];
|
|
3908
|
+
if (!isRec4(report)) continue;
|
|
3909
|
+
const reportName = strName6(report.name) ?? `#${ri}`;
|
|
3910
|
+
const checkReportChart = (chart, dataset, values, where, path) => {
|
|
3911
|
+
if (!isRec4(chart)) return;
|
|
3912
|
+
check({
|
|
3913
|
+
dataset,
|
|
3914
|
+
// `values` is the report's measure SELECTION, not a chart ref; feeding
|
|
3915
|
+
// it in lets the yAxis "declared but not selected" check work without
|
|
3916
|
+
// reporting the selection itself twice.
|
|
3917
|
+
values: { names: values, path: `${path}.values` },
|
|
3918
|
+
xAxis: strName6(chart.xAxis) ? { name: strName6(chart.xAxis), path: `${path}.chart.xAxis` } : void 0,
|
|
3919
|
+
yAxis: strName6(chart.yAxis) ? { name: strName6(chart.yAxis), path: `${path}.chart.yAxis` } : void 0,
|
|
3920
|
+
series: asArray25(chart.series).map((s, si) => ({ name: strName6(s.name), path: `${path}.chart.series[${si}].name` })).filter((s) => !!s.name),
|
|
3921
|
+
where,
|
|
3922
|
+
path: `${path}.chart`
|
|
3923
|
+
});
|
|
3924
|
+
};
|
|
3925
|
+
checkReportChart(
|
|
3926
|
+
report.chart,
|
|
3927
|
+
strName6(report.dataset),
|
|
3928
|
+
strList2(report.values),
|
|
3929
|
+
`report "${reportName}" \xB7 chart`,
|
|
3930
|
+
`reports[${ri}]`
|
|
3931
|
+
);
|
|
3932
|
+
const blocks = Array.isArray(report.blocks) ? report.blocks : [];
|
|
3933
|
+
for (let bi = 0; bi < blocks.length; bi++) {
|
|
3934
|
+
const block = blocks[bi];
|
|
3935
|
+
if (!isRec4(block)) continue;
|
|
3936
|
+
checkReportChart(
|
|
3937
|
+
block.chart,
|
|
3938
|
+
strName6(block.dataset),
|
|
3939
|
+
strList2(block.values),
|
|
3940
|
+
`report "${reportName}" \xB7 block "${strName6(block.name) ?? `#${bi}`}" chart`,
|
|
3941
|
+
`reports[${ri}].blocks[${bi}]`
|
|
3942
|
+
);
|
|
3943
|
+
}
|
|
3944
|
+
}
|
|
3945
|
+
const checkListChart = (container, where, path) => {
|
|
3946
|
+
if (!isRec4(container)) return;
|
|
3947
|
+
const chart = container.chart;
|
|
3948
|
+
if (!isRec4(chart)) return;
|
|
3949
|
+
check({
|
|
3950
|
+
dataset: strName6(chart.dataset),
|
|
3951
|
+
dimensions: { names: strList2(chart.dimensions), path: `${path}.chart.dimensions` },
|
|
3952
|
+
values: { names: strList2(chart.values), path: `${path}.chart.values` },
|
|
3953
|
+
where,
|
|
3954
|
+
path: `${path}.chart`
|
|
3955
|
+
});
|
|
3956
|
+
};
|
|
3957
|
+
const views = asArray25(stack.views);
|
|
3958
|
+
for (let vi = 0; vi < views.length; vi++) {
|
|
3959
|
+
const view = views[vi];
|
|
3960
|
+
if (!isRec4(view)) continue;
|
|
3961
|
+
const viewName = strName6(view.name) ?? strName6(view.objectName) ?? `#${vi}`;
|
|
3962
|
+
checkListChart(view.list, `view "${viewName}" \xB7 list chart`, `views[${vi}].list`);
|
|
3963
|
+
if (isRec4(view.listViews)) {
|
|
3964
|
+
for (const [key, lv] of Object.entries(view.listViews)) {
|
|
3965
|
+
checkListChart(lv, `view "${viewName}" \xB7 listViews.${key} chart`, `views[${vi}].listViews.${key}`);
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
const objects = asArray25(stack.objects);
|
|
3970
|
+
for (let oi = 0; oi < objects.length; oi++) {
|
|
3971
|
+
const obj = objects[oi];
|
|
3972
|
+
if (!isRec4(obj) || !isRec4(obj.listViews)) continue;
|
|
3973
|
+
const objName = strName6(obj.name) ?? `#${oi}`;
|
|
3974
|
+
for (const [key, lv] of Object.entries(obj.listViews)) {
|
|
3975
|
+
checkListChart(
|
|
3976
|
+
lv,
|
|
3977
|
+
`object "${objName}" \xB7 listViews.${key} chart`,
|
|
3978
|
+
`objects[${oi}].listViews.${key}`
|
|
3979
|
+
);
|
|
3980
|
+
}
|
|
3981
|
+
}
|
|
3982
|
+
const pages = asArray25(stack.pages);
|
|
3983
|
+
for (let pi = 0; pi < pages.length; pi++) {
|
|
3984
|
+
const page = pages[pi];
|
|
3985
|
+
if (!isRec4(page)) continue;
|
|
3986
|
+
const pageName = strName6(page.name) ?? `#${pi}`;
|
|
3987
|
+
for (const { component, path } of walkPageComponents(page, `pages[${pi}]`)) {
|
|
3988
|
+
const props = isRec4(component.properties) ? component.properties : void 0;
|
|
3989
|
+
if (!props || !strName6(props.dataset)) continue;
|
|
3990
|
+
const axisRefs = asArray25(props.yAxis).map((a, ai) => ({ name: strName6(a.field), path: `${path}.properties.yAxis[${ai}].field` })).filter((a) => !!a.name);
|
|
3991
|
+
const seriesRefs = asArray25(props.series).map((s, si) => ({ name: strName6(s.name), path: `${path}.properties.series[${si}].name` })).filter((s) => !!s.name);
|
|
3992
|
+
check({
|
|
3993
|
+
dataset: strName6(props.dataset),
|
|
3994
|
+
dimensions: { names: strList2(props.dimensions), path: `${path}.properties.dimensions` },
|
|
3995
|
+
values: { names: strList2(props.values), path: `${path}.properties.values` },
|
|
3996
|
+
series: [...axisRefs, ...seriesRefs],
|
|
3997
|
+
where: `page "${pageName}" \xB7 ${strName6(component.type) ?? "chart"}`,
|
|
3998
|
+
path: `${path}.properties`
|
|
3999
|
+
});
|
|
4000
|
+
}
|
|
4001
|
+
}
|
|
4002
|
+
return findings;
|
|
4003
|
+
}
|
|
4004
|
+
|
|
4005
|
+
// src/validate-nav-access.ts
|
|
4006
|
+
import { isPlatformProvidedObjectName as isPlatformProvidedObjectName2 } from "@objectstack/spec/system";
|
|
4007
|
+
|
|
4008
|
+
// src/build-access-matrix.ts
|
|
4009
|
+
function asArray26(v) {
|
|
2037
4010
|
if (Array.isArray(v)) return v;
|
|
2038
4011
|
if (v && typeof v === "object") {
|
|
2039
4012
|
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
@@ -2044,13 +4017,13 @@ function buildAccessMatrix(stack) {
|
|
|
2044
4017
|
const entries = [];
|
|
2045
4018
|
if (!stack || typeof stack !== "object") return { version: 1, entries };
|
|
2046
4019
|
const owdByObject = /* @__PURE__ */ new Map();
|
|
2047
|
-
for (const obj of
|
|
4020
|
+
for (const obj of asArray26(stack.objects)) {
|
|
2048
4021
|
const name = typeof obj.name === "string" ? obj.name : "";
|
|
2049
4022
|
if (!name) continue;
|
|
2050
4023
|
const owd = obj.sharingModel ?? obj.security?.sharingModel;
|
|
2051
4024
|
if (typeof owd === "string") owdByObject.set(name, owd);
|
|
2052
4025
|
}
|
|
2053
|
-
for (const ps of
|
|
4026
|
+
for (const ps of asArray26(stack.permissions)) {
|
|
2054
4027
|
const psName = typeof ps.name === "string" ? ps.name : "";
|
|
2055
4028
|
if (!psName) continue;
|
|
2056
4029
|
const objects = ps.objects && typeof ps.objects === "object" ? ps.objects : {};
|
|
@@ -2099,13 +4072,13 @@ function diffAccessMatrix(before, after) {
|
|
|
2099
4072
|
for (const [k, a] of afterMap) {
|
|
2100
4073
|
const b = beforeMap.get(k);
|
|
2101
4074
|
if (!b) {
|
|
2102
|
-
const grants = BIT_LABELS.filter(([bit]) => a[bit] === true).map(([,
|
|
4075
|
+
const grants = BIT_LABELS.filter(([bit]) => a[bit] === true).map(([, label2]) => label2);
|
|
2103
4076
|
lines.push(`'${a.permissionSet}' gains access to '${a.object}' (${grants.join(", ") || "no bits set"})`);
|
|
2104
4077
|
continue;
|
|
2105
4078
|
}
|
|
2106
|
-
for (const [bit,
|
|
4079
|
+
for (const [bit, label2] of BIT_LABELS) {
|
|
2107
4080
|
if (b[bit] !== a[bit]) {
|
|
2108
|
-
lines.push(`'${a.permissionSet}' ${a[bit] ? "gains" : "loses"} ${
|
|
4081
|
+
lines.push(`'${a.permissionSet}' ${a[bit] ? "gains" : "loses"} ${label2} on '${a.object}'`);
|
|
2109
4082
|
}
|
|
2110
4083
|
}
|
|
2111
4084
|
if ((b.readScope ?? "own") !== (a.readScope ?? "own")) {
|
|
@@ -2120,23 +4093,834 @@ function diffAccessMatrix(before, after) {
|
|
|
2120
4093
|
}
|
|
2121
4094
|
return lines;
|
|
2122
4095
|
}
|
|
4096
|
+
|
|
4097
|
+
// src/validate-nav-access.ts
|
|
4098
|
+
var NAV_OBJECT_UNGRANTED = "nav-object-ungranted";
|
|
4099
|
+
function asArray27(v) {
|
|
4100
|
+
if (Array.isArray(v)) return v;
|
|
4101
|
+
if (v && typeof v === "object") {
|
|
4102
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
4103
|
+
}
|
|
4104
|
+
return [];
|
|
4105
|
+
}
|
|
4106
|
+
function strName7(v) {
|
|
4107
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
4108
|
+
}
|
|
4109
|
+
function collectNavExposures(stack) {
|
|
4110
|
+
const out = [];
|
|
4111
|
+
const apps = asArray27(stack.apps);
|
|
4112
|
+
for (let ai = 0; ai < apps.length; ai++) {
|
|
4113
|
+
const app = apps[ai];
|
|
4114
|
+
if (!app || typeof app !== "object") continue;
|
|
4115
|
+
const appName = strName7(app.name) ?? `#${ai}`;
|
|
4116
|
+
const walk = (items, basePath) => {
|
|
4117
|
+
const navItems = asArray27(items);
|
|
4118
|
+
for (let ni = 0; ni < navItems.length; ni++) {
|
|
4119
|
+
const nav = navItems[ni];
|
|
4120
|
+
if (!nav || typeof nav !== "object") continue;
|
|
4121
|
+
const navPath = `${basePath}[${ni}]`;
|
|
4122
|
+
const objectName = strName7(nav.objectName);
|
|
4123
|
+
if (nav.type === "object" && objectName) {
|
|
4124
|
+
out.push({
|
|
4125
|
+
objectName,
|
|
4126
|
+
where: `app "${appName}" \xB7 nav "${strName7(nav.id) ?? `#${ni}`}"`,
|
|
4127
|
+
path: `${navPath}.objectName`
|
|
4128
|
+
});
|
|
4129
|
+
}
|
|
4130
|
+
if (Array.isArray(nav.children)) walk(nav.children, `${navPath}.children`);
|
|
4131
|
+
}
|
|
4132
|
+
};
|
|
4133
|
+
walk(app.navigation, `apps[${ai}].navigation`);
|
|
4134
|
+
const areas = asArray27(app.areas);
|
|
4135
|
+
for (let ri = 0; ri < areas.length; ri++) {
|
|
4136
|
+
walk(areas[ri]?.navigation, `apps[${ai}].areas[${ri}].navigation`);
|
|
4137
|
+
}
|
|
4138
|
+
}
|
|
4139
|
+
return out;
|
|
4140
|
+
}
|
|
4141
|
+
function validateNavAccess(stack) {
|
|
4142
|
+
const findings = [];
|
|
4143
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
4144
|
+
const permissionSets = asArray27(stack.permissions);
|
|
4145
|
+
if (permissionSets.length === 0) return findings;
|
|
4146
|
+
const exposures = collectNavExposures(stack);
|
|
4147
|
+
if (exposures.length === 0) return findings;
|
|
4148
|
+
const ownObjects = /* @__PURE__ */ new Set();
|
|
4149
|
+
for (const obj of asArray27(stack.objects)) {
|
|
4150
|
+
const n = strName7(obj.name);
|
|
4151
|
+
if (n) ownObjects.add(n);
|
|
4152
|
+
}
|
|
4153
|
+
const readable = /* @__PURE__ */ new Set();
|
|
4154
|
+
for (const entry of buildAccessMatrix(stack).entries) {
|
|
4155
|
+
if (entry.read) readable.add(entry.object);
|
|
4156
|
+
}
|
|
4157
|
+
if (readable.has("*")) return findings;
|
|
4158
|
+
const reported = /* @__PURE__ */ new Set();
|
|
4159
|
+
for (const exposure of exposures) {
|
|
4160
|
+
const { objectName } = exposure;
|
|
4161
|
+
if (reported.has(objectName)) continue;
|
|
4162
|
+
if (isPlatformProvidedObjectName2(objectName)) continue;
|
|
4163
|
+
if (!ownObjects.has(objectName)) continue;
|
|
4164
|
+
if (readable.has(objectName)) continue;
|
|
4165
|
+
reported.add(objectName);
|
|
4166
|
+
findings.push({
|
|
4167
|
+
severity: "warning",
|
|
4168
|
+
rule: NAV_OBJECT_UNGRANTED,
|
|
4169
|
+
where: exposure.where,
|
|
4170
|
+
path: exposure.path,
|
|
4171
|
+
message: `navigation exposes object "${objectName}", but no permission set this stack declares grants read on it \u2014 the entry renders, and opening it fails permission-denied for every principal except one holding the platform's built-in wildcard admin set. It works when you browse as an administrator and breaks for the users the app ships permission sets for.`,
|
|
4172
|
+
hint: `Add "${objectName}" to a permission set's \`objects\` with \`allowRead: true\` (or \`viewAllRecords\`), gate the entry with \`requiredPermissions\`/\`visible\` if it is meant for admins only, or drop it. Ignore this if a permission set from another installed package grants it.`
|
|
4173
|
+
});
|
|
4174
|
+
}
|
|
4175
|
+
return findings;
|
|
4176
|
+
}
|
|
4177
|
+
|
|
4178
|
+
// src/validate-translation-references.ts
|
|
4179
|
+
import { hasPlatformObjectPrefix as hasPlatformObjectPrefix2, isPlatformProvidedObjectName as isPlatformProvidedObjectName3 } from "@objectstack/spec/system";
|
|
4180
|
+
var TRANSLATION_TARGET_UNKNOWN = "translation-target-unknown";
|
|
4181
|
+
var TRANSLATION_OPTION_KEY_UNKNOWN = "translation-option-key-unknown";
|
|
4182
|
+
function isRec5(v) {
|
|
4183
|
+
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
4184
|
+
}
|
|
4185
|
+
function asArray28(v) {
|
|
4186
|
+
if (Array.isArray(v)) return v;
|
|
4187
|
+
if (isRec5(v)) return Object.entries(v).map(([name, def]) => ({ name, ...isRec5(def) ? def : {} }));
|
|
4188
|
+
return [];
|
|
4189
|
+
}
|
|
4190
|
+
function strName8(v) {
|
|
4191
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
4192
|
+
}
|
|
4193
|
+
function distance4(a, b) {
|
|
4194
|
+
const m = a.length;
|
|
4195
|
+
const n = b.length;
|
|
4196
|
+
if (m === 0) return n;
|
|
4197
|
+
if (n === 0) return m;
|
|
4198
|
+
let prev = Array.from({ length: n + 1 }, (_, j) => j);
|
|
4199
|
+
for (let i = 1; i <= m; i++) {
|
|
4200
|
+
const curr = [i, ...new Array(n).fill(0)];
|
|
4201
|
+
for (let j = 1; j <= n; j++) {
|
|
4202
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
4203
|
+
curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);
|
|
4204
|
+
}
|
|
4205
|
+
prev = curr;
|
|
4206
|
+
}
|
|
4207
|
+
return prev[n];
|
|
4208
|
+
}
|
|
4209
|
+
function suggest5(target, known) {
|
|
4210
|
+
const names = [...known];
|
|
4211
|
+
const segmentMatch = names.find(
|
|
4212
|
+
(candidate) => candidate.endsWith(`_${target}`) || candidate.startsWith(`${target}_`)
|
|
4213
|
+
);
|
|
4214
|
+
if (segmentMatch) return ` Did you mean "${segmentMatch}"?`;
|
|
4215
|
+
let best;
|
|
4216
|
+
let bestScore = Infinity;
|
|
4217
|
+
for (const candidate of names) {
|
|
4218
|
+
const d = distance4(target, candidate);
|
|
4219
|
+
if (d < bestScore) {
|
|
4220
|
+
bestScore = d;
|
|
4221
|
+
best = candidate;
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
const limit = Math.max(2, Math.floor(target.length / 3));
|
|
4225
|
+
return best && bestScore <= limit ? ` Did you mean "${best}"?` : "";
|
|
4226
|
+
}
|
|
4227
|
+
function listNames(names, max = 12) {
|
|
4228
|
+
const all = [...names].sort();
|
|
4229
|
+
if (all.length === 0) return "";
|
|
4230
|
+
const shown = all.slice(0, max).join(", ");
|
|
4231
|
+
return all.length > max ? `${shown}, \u2026 (${all.length} total)` : shown;
|
|
4232
|
+
}
|
|
4233
|
+
var SYSTEM_FIELDS5 = /* @__PURE__ */ new Set([
|
|
4234
|
+
"id",
|
|
4235
|
+
"_id",
|
|
4236
|
+
"name",
|
|
4237
|
+
"created_at",
|
|
4238
|
+
"created_by",
|
|
4239
|
+
"updated_at",
|
|
4240
|
+
"updated_by",
|
|
4241
|
+
"owner_id",
|
|
4242
|
+
"organization_id",
|
|
4243
|
+
"tenant_id",
|
|
4244
|
+
"user_id",
|
|
4245
|
+
"is_deleted",
|
|
4246
|
+
"deleted_at",
|
|
4247
|
+
"space"
|
|
4248
|
+
]);
|
|
4249
|
+
function emptyFacts() {
|
|
4250
|
+
return { fields: /* @__PURE__ */ new Map(), views: /* @__PURE__ */ new Set(), actions: /* @__PURE__ */ new Map(), sections: /* @__PURE__ */ new Set() };
|
|
4251
|
+
}
|
|
4252
|
+
function collectViewRecord(view, factsFor) {
|
|
4253
|
+
const recordObject = viewObjectName(view);
|
|
4254
|
+
const bindingOf = (container) => viewObjectName(container) ?? recordObject;
|
|
4255
|
+
const addView = (objectName, name) => {
|
|
4256
|
+
if (objectName && name) factsFor(objectName).views.add(name);
|
|
4257
|
+
};
|
|
4258
|
+
const listBinding = isRec5(view.list) ? bindingOf(view.list) : void 0;
|
|
4259
|
+
if (isRec5(view.list)) addView(listBinding, strName8(view.list.name));
|
|
4260
|
+
addView(recordObject ?? listBinding, strName8(view.name));
|
|
4261
|
+
for (const key of ["listViews", "formViews"]) {
|
|
4262
|
+
const container = view[key];
|
|
4263
|
+
if (!isRec5(container)) continue;
|
|
4264
|
+
for (const [subKey, sub] of Object.entries(container)) {
|
|
4265
|
+
if (!isRec5(sub)) continue;
|
|
4266
|
+
const binding = bindingOf(sub) ?? listBinding;
|
|
4267
|
+
addView(binding, subKey);
|
|
4268
|
+
addView(binding, strName8(sub.name));
|
|
4269
|
+
if (binding) {
|
|
4270
|
+
for (const section of asArray28(sub.sections)) {
|
|
4271
|
+
const sectionName = strName8(section.name);
|
|
4272
|
+
if (sectionName) factsFor(binding).sections.add(sectionName);
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
}
|
|
4277
|
+
const sectionBinding = recordObject ?? listBinding;
|
|
4278
|
+
if (sectionBinding) {
|
|
4279
|
+
for (const section of asArray28(view.sections)) {
|
|
4280
|
+
const sectionName = strName8(section.name);
|
|
4281
|
+
if (sectionName) factsFor(sectionBinding).sections.add(sectionName);
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
function viewObjectName(view) {
|
|
4286
|
+
return strName8(view.objectName) ?? strName8(view.object) ?? (isRec5(view.data) ? strName8(view.data.object) : void 0);
|
|
4287
|
+
}
|
|
4288
|
+
function readOptions(field) {
|
|
4289
|
+
const raw = field.options;
|
|
4290
|
+
const values = /* @__PURE__ */ new Set();
|
|
4291
|
+
const byLabel = /* @__PURE__ */ new Map();
|
|
4292
|
+
if (Array.isArray(raw)) {
|
|
4293
|
+
for (const opt of raw) {
|
|
4294
|
+
if (typeof opt === "string") {
|
|
4295
|
+
values.add(opt);
|
|
4296
|
+
continue;
|
|
4297
|
+
}
|
|
4298
|
+
if (!isRec5(opt)) continue;
|
|
4299
|
+
const value = strName8(opt.value);
|
|
4300
|
+
if (!value) continue;
|
|
4301
|
+
values.add(value);
|
|
4302
|
+
const label2 = strName8(opt.label);
|
|
4303
|
+
if (label2) byLabel.set(label2.toLowerCase(), value);
|
|
4304
|
+
}
|
|
4305
|
+
} else if (isRec5(raw)) {
|
|
4306
|
+
for (const [value, label2] of Object.entries(raw)) {
|
|
4307
|
+
values.add(value);
|
|
4308
|
+
if (typeof label2 === "string" && label2.length > 0) byLabel.set(label2.toLowerCase(), value);
|
|
4309
|
+
}
|
|
4310
|
+
} else {
|
|
4311
|
+
return void 0;
|
|
4312
|
+
}
|
|
4313
|
+
return values.size > 0 ? { values, byLabel } : void 0;
|
|
4314
|
+
}
|
|
4315
|
+
function buildUniverse(stack) {
|
|
4316
|
+
const objects = /* @__PURE__ */ new Map();
|
|
4317
|
+
const factsFor = (name) => {
|
|
4318
|
+
let facts = objects.get(name);
|
|
4319
|
+
if (!facts) {
|
|
4320
|
+
facts = emptyFacts();
|
|
4321
|
+
objects.set(name, facts);
|
|
4322
|
+
}
|
|
4323
|
+
return facts;
|
|
4324
|
+
};
|
|
4325
|
+
for (const obj of asArray28(stack.objects)) {
|
|
4326
|
+
const objectName = strName8(obj.name);
|
|
4327
|
+
if (!objectName) continue;
|
|
4328
|
+
const facts = factsFor(objectName);
|
|
4329
|
+
for (const field of asArray28(obj.fields)) {
|
|
4330
|
+
const fieldName = strName8(field.name);
|
|
4331
|
+
if (fieldName) facts.fields.set(fieldName, field);
|
|
4332
|
+
}
|
|
4333
|
+
for (const action of asArray28(obj.actions)) {
|
|
4334
|
+
const actionName = strName8(action.name);
|
|
4335
|
+
if (actionName) facts.actions.set(actionName, action);
|
|
4336
|
+
}
|
|
4337
|
+
for (const view of asArray28(obj.views)) {
|
|
4338
|
+
collectViewRecord({ ...view, object: strName8(view.object) ?? objectName }, factsFor);
|
|
4339
|
+
}
|
|
4340
|
+
collectViewRecord({ object: objectName, listViews: obj.listViews }, factsFor);
|
|
4341
|
+
for (const group of asArray28(obj.fieldGroups)) {
|
|
4342
|
+
const key = strName8(group.key) ?? strName8(group.name);
|
|
4343
|
+
if (key) facts.sections.add(key);
|
|
4344
|
+
}
|
|
4345
|
+
}
|
|
4346
|
+
for (const view of asArray28(stack.views)) {
|
|
4347
|
+
collectViewRecord(view, factsFor);
|
|
4348
|
+
}
|
|
4349
|
+
const pages = asArray28(stack.pages);
|
|
4350
|
+
for (let pi = 0; pi < pages.length; pi++) {
|
|
4351
|
+
for (const walked of walkPageComponents(pages[pi], `pages[${pi}]`)) {
|
|
4352
|
+
if (!walked.objectName) continue;
|
|
4353
|
+
const props = isRec5(walked.component.properties) ? walked.component.properties : void 0;
|
|
4354
|
+
if (!props) continue;
|
|
4355
|
+
for (const section of asArray28(props.sections)) {
|
|
4356
|
+
const sectionName = strName8(section.name);
|
|
4357
|
+
if (sectionName) factsFor(walked.objectName).sections.add(sectionName);
|
|
4358
|
+
}
|
|
4359
|
+
}
|
|
4360
|
+
}
|
|
4361
|
+
const globalActions = /* @__PURE__ */ new Map();
|
|
4362
|
+
const actionOwners = /* @__PURE__ */ new Map();
|
|
4363
|
+
for (const action of asArray28(stack.actions)) {
|
|
4364
|
+
const actionName = strName8(action.name);
|
|
4365
|
+
if (!actionName) continue;
|
|
4366
|
+
const owner = strName8(action.objectName) ?? strName8(action.object);
|
|
4367
|
+
if (owner) {
|
|
4368
|
+
factsFor(owner).actions.set(actionName, action);
|
|
4369
|
+
actionOwners.set(actionName, owner);
|
|
4370
|
+
} else {
|
|
4371
|
+
globalActions.set(actionName, action);
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
for (const [objectName, facts] of objects) {
|
|
4375
|
+
for (const actionName of facts.actions.keys()) {
|
|
4376
|
+
if (!actionOwners.has(actionName)) actionOwners.set(actionName, objectName);
|
|
4377
|
+
}
|
|
4378
|
+
}
|
|
4379
|
+
const apps = /* @__PURE__ */ new Map();
|
|
4380
|
+
for (const app of asArray28(stack.apps)) {
|
|
4381
|
+
const appName = strName8(app.name);
|
|
4382
|
+
if (!appName) continue;
|
|
4383
|
+
const navIds = apps.get(appName) ?? /* @__PURE__ */ new Set();
|
|
4384
|
+
const walkNav = (items) => {
|
|
4385
|
+
for (const item of asArray28(items)) {
|
|
4386
|
+
const id = strName8(item.id);
|
|
4387
|
+
if (id) navIds.add(id);
|
|
4388
|
+
if (item.children) walkNav(item.children);
|
|
4389
|
+
}
|
|
4390
|
+
};
|
|
4391
|
+
walkNav(app.navigation);
|
|
4392
|
+
for (const area of asArray28(app.areas)) {
|
|
4393
|
+
const areaId = strName8(area.id);
|
|
4394
|
+
if (areaId) navIds.add(areaId);
|
|
4395
|
+
walkNav(area.navigation);
|
|
4396
|
+
}
|
|
4397
|
+
apps.set(appName, navIds);
|
|
4398
|
+
}
|
|
4399
|
+
const dashboards = /* @__PURE__ */ new Map();
|
|
4400
|
+
for (const dash of asArray28(stack.dashboards)) {
|
|
4401
|
+
const dashName = strName8(dash.name);
|
|
4402
|
+
if (!dashName) continue;
|
|
4403
|
+
const widgets = /* @__PURE__ */ new Set();
|
|
4404
|
+
for (const widget of asArray28(dash.widgets)) {
|
|
4405
|
+
const id = strName8(widget.id) ?? strName8(widget.name);
|
|
4406
|
+
if (id) widgets.add(id);
|
|
4407
|
+
}
|
|
4408
|
+
const actions = /* @__PURE__ */ new Set();
|
|
4409
|
+
const headerActions = [
|
|
4410
|
+
...asArray28(isRec5(dash.header) ? dash.header.actions : void 0),
|
|
4411
|
+
...asArray28(dash.actions)
|
|
4412
|
+
];
|
|
4413
|
+
for (const action of headerActions) {
|
|
4414
|
+
const key = strName8(action.actionUrl) ?? strName8(action.url) ?? strName8(action.name);
|
|
4415
|
+
if (key) actions.add(key);
|
|
4416
|
+
}
|
|
4417
|
+
dashboards.set(dashName, { widgets, actions });
|
|
4418
|
+
}
|
|
4419
|
+
return { objects, apps, dashboards, globalActions, actionOwners };
|
|
4420
|
+
}
|
|
4421
|
+
function localePath(bundleIndex, locale) {
|
|
4422
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(locale) ? `translations[${bundleIndex}].${locale}` : `translations[${bundleIndex}]["${locale}"]`;
|
|
4423
|
+
}
|
|
4424
|
+
function validateTranslationReferences(stack) {
|
|
4425
|
+
const findings = [];
|
|
4426
|
+
if (!isRec5(stack)) return findings;
|
|
4427
|
+
const bundles = Array.isArray(stack.translations) ? stack.translations : [];
|
|
4428
|
+
if (bundles.length === 0) return findings;
|
|
4429
|
+
const universe = buildUniverse(stack);
|
|
4430
|
+
const orphan = (where, path, message, hint) => {
|
|
4431
|
+
findings.push({ severity: "warning", rule: TRANSLATION_TARGET_UNKNOWN, where, path, message, hint });
|
|
4432
|
+
};
|
|
4433
|
+
for (let bi = 0; bi < bundles.length; bi++) {
|
|
4434
|
+
const bundle = bundles[bi];
|
|
4435
|
+
if (!isRec5(bundle)) continue;
|
|
4436
|
+
for (const [locale, rawData] of Object.entries(bundle)) {
|
|
4437
|
+
if (!isRec5(rawData)) continue;
|
|
4438
|
+
const base = localePath(bi, locale);
|
|
4439
|
+
const inLocale = `locale "${locale}"`;
|
|
4440
|
+
for (const [objectName, rawNode] of Object.entries(asRecord(rawData.objects))) {
|
|
4441
|
+
if (!isRec5(rawNode)) continue;
|
|
4442
|
+
const objPath = `${base}.objects.${objectName}`;
|
|
4443
|
+
const facts = universe.objects.get(objectName);
|
|
4444
|
+
if (!facts) {
|
|
4445
|
+
if (isPlatformProvidedObjectName3(objectName)) continue;
|
|
4446
|
+
orphan(
|
|
4447
|
+
`${inLocale} \xB7 object "${objectName}"`,
|
|
4448
|
+
objPath,
|
|
4449
|
+
hasPlatformObjectPrefix2(objectName) ? `Translations are keyed to "${objectName}", which carries a platform namespace prefix but is registered by no platform package, official plugin, or cloud runtime object \u2014 and this stack does not define it either. Nothing resolves these keys.` + suggest5(objectName, universe.objects.keys()) : `Translations are keyed to "${objectName}", which no object in this stack defines. The resolver looks up keys derived from the metadata, so this whole subtree is dead weight \u2014 every label it carries renders untranslated.` + suggest5(objectName, universe.objects.keys()),
|
|
4450
|
+
`Rename the key to the object it was written for, drop it, or ignore this if the object is contributed by another installed package.` + (universe.objects.size > 0 ? ` Defined objects: ${listNames(universe.objects.keys())}.` : "")
|
|
4451
|
+
);
|
|
4452
|
+
continue;
|
|
4453
|
+
}
|
|
4454
|
+
for (const [fieldName, rawField] of Object.entries(asRecord(rawNode.fields))) {
|
|
4455
|
+
const fieldPath = `${objPath}.fields.${fieldName}`;
|
|
4456
|
+
const field = facts.fields.get(fieldName);
|
|
4457
|
+
if (!field) {
|
|
4458
|
+
if (SYSTEM_FIELDS5.has(fieldName)) continue;
|
|
4459
|
+
orphan(
|
|
4460
|
+
`${inLocale} \xB7 object "${objectName}" \xB7 field "${fieldName}"`,
|
|
4461
|
+
fieldPath,
|
|
4462
|
+
`Translations are keyed to field "${fieldName}", which object "${objectName}" does not declare. The label renders untranslated in this locale \u2014 and because every neighbouring field DOES resolve, the hole reads as a styling quirk rather than a missing translation.` + suggest5(fieldName, facts.fields.keys()),
|
|
4463
|
+
`Point the key at a declared field, or drop it if the field was removed or renamed.` + (facts.fields.size > 0 ? ` Declared fields: ${listNames(facts.fields.keys())}.` : "")
|
|
4464
|
+
);
|
|
4465
|
+
continue;
|
|
4466
|
+
}
|
|
4467
|
+
if (!isRec5(rawField)) continue;
|
|
4468
|
+
checkOptionKeys(findings, {
|
|
4469
|
+
optionMap: rawField.options,
|
|
4470
|
+
field,
|
|
4471
|
+
fieldName,
|
|
4472
|
+
objectName,
|
|
4473
|
+
path: `${fieldPath}.options`,
|
|
4474
|
+
where: `${inLocale} \xB7 object "${objectName}" \xB7 field "${fieldName}"`
|
|
4475
|
+
});
|
|
4476
|
+
}
|
|
4477
|
+
for (const viewName of Object.keys(asRecord(rawNode._views))) {
|
|
4478
|
+
if (facts.views.has(viewName)) continue;
|
|
4479
|
+
orphan(
|
|
4480
|
+
`${inLocale} \xB7 object "${objectName}" \xB7 view "${viewName}"`,
|
|
4481
|
+
`${objPath}._views.${viewName}`,
|
|
4482
|
+
`Translations are keyed to view "${viewName}", which no view of object "${objectName}" declares. The view tab keeps its source-locale label.` + suggest5(viewName, facts.views),
|
|
4483
|
+
`Match the key to the view's \`name\` (not its label), or drop it.` + (facts.views.size > 0 ? ` Declared views: ${listNames(facts.views)}.` : "")
|
|
4484
|
+
);
|
|
4485
|
+
}
|
|
4486
|
+
for (const sectionName of Object.keys(asRecord(rawNode._sections))) {
|
|
4487
|
+
if (facts.sections.has(sectionName)) continue;
|
|
4488
|
+
orphan(
|
|
4489
|
+
`${inLocale} \xB7 object "${objectName}" \xB7 section "${sectionName}"`,
|
|
4490
|
+
`${objPath}._sections.${sectionName}`,
|
|
4491
|
+
`Translations are keyed to section "${sectionName}", which nothing on object "${objectName}" declares \u2014 no \`fieldGroups[].key\`, no named form-view section, no named \`record:details\` section. The section heading stays in the source locale.` + suggest5(sectionName, facts.sections),
|
|
4492
|
+
`Sections are translatable only through a STABLE NAME: give the group/section a \`key\`/\`name\` and use it here, or drop the translation.` + (facts.sections.size > 0 ? ` Declared sections: ${listNames(facts.sections)}.` : ` Object "${objectName}" declares no named section at all.`)
|
|
4493
|
+
);
|
|
4494
|
+
}
|
|
4495
|
+
for (const [actionName, rawAction] of Object.entries(asRecord(rawNode._actions))) {
|
|
4496
|
+
const actionPath = `${objPath}._actions.${actionName}`;
|
|
4497
|
+
const action = facts.actions.get(actionName);
|
|
4498
|
+
if (!action) {
|
|
4499
|
+
orphan(
|
|
4500
|
+
`${inLocale} \xB7 object "${objectName}" \xB7 action "${actionName}"`,
|
|
4501
|
+
actionPath,
|
|
4502
|
+
`Translations are keyed to action "${actionName}", which is defined by neither object "${objectName}"'s \`actions\` nor a \`stack.actions\` entry bound to it. The button keeps its source-locale label.` + suggest5(actionName, facts.actions.keys()),
|
|
4503
|
+
`Match the key to a defined action name, move it under the object that owns the action, or drop it.` + (facts.actions.size > 0 ? ` Actions on this object: ${listNames(facts.actions.keys())}.` : "")
|
|
4504
|
+
);
|
|
4505
|
+
continue;
|
|
4506
|
+
}
|
|
4507
|
+
checkActionParams(findings, {
|
|
4508
|
+
rawAction,
|
|
4509
|
+
action,
|
|
4510
|
+
path: actionPath,
|
|
4511
|
+
where: `${inLocale} \xB7 object "${objectName}" \xB7 action "${actionName}"`,
|
|
4512
|
+
subject: `action "${actionName}"`
|
|
4513
|
+
});
|
|
4514
|
+
}
|
|
4515
|
+
}
|
|
4516
|
+
for (const [actionName, rawAction] of Object.entries(asRecord(rawData.globalActions))) {
|
|
4517
|
+
const actionPath = `${base}.globalActions.${actionName}`;
|
|
4518
|
+
const action = universe.globalActions.get(actionName);
|
|
4519
|
+
if (!action) {
|
|
4520
|
+
const owner = universe.actionOwners.get(actionName);
|
|
4521
|
+
orphan(
|
|
4522
|
+
`${inLocale} \xB7 global action "${actionName}"`,
|
|
4523
|
+
actionPath,
|
|
4524
|
+
owner ? `Action "${actionName}" is bound to object "${owner}", so the resolver looks it up under \`objects.${owner}._actions.${actionName}\` \u2014 never under \`globalActions\`, which is only consulted for object-less actions. This key is never read.` : `Translations are keyed to global action "${actionName}", which no object-less action in this stack defines. The button keeps its source-locale label.` + suggest5(actionName, universe.globalActions.keys()),
|
|
4525
|
+
owner ? `Move these keys under \`objects.${owner}._actions.${actionName}\`.` : `Match the key to an object-less action's name, or drop it.` + (universe.globalActions.size > 0 ? ` Object-less actions: ${listNames(universe.globalActions.keys())}.` : "")
|
|
4526
|
+
);
|
|
4527
|
+
continue;
|
|
4528
|
+
}
|
|
4529
|
+
checkActionParams(findings, {
|
|
4530
|
+
rawAction,
|
|
4531
|
+
action,
|
|
4532
|
+
path: actionPath,
|
|
4533
|
+
where: `${inLocale} \xB7 global action "${actionName}"`,
|
|
4534
|
+
subject: `action "${actionName}"`
|
|
4535
|
+
});
|
|
4536
|
+
}
|
|
4537
|
+
for (const [appName, rawApp] of Object.entries(asRecord(rawData.apps))) {
|
|
4538
|
+
const appPath = `${base}.apps.${appName}`;
|
|
4539
|
+
const navIds = universe.apps.get(appName);
|
|
4540
|
+
if (!navIds) {
|
|
4541
|
+
orphan(
|
|
4542
|
+
`${inLocale} \xB7 app "${appName}"`,
|
|
4543
|
+
appPath,
|
|
4544
|
+
`Translations are keyed to app "${appName}", which this stack does not define. The app launcher shows the source-locale label.` + suggest5(appName, universe.apps.keys()),
|
|
4545
|
+
`Match the key to an app's \`name\`, or drop it.` + (universe.apps.size > 0 ? ` Defined apps: ${listNames(universe.apps.keys())}.` : "")
|
|
4546
|
+
);
|
|
4547
|
+
continue;
|
|
4548
|
+
}
|
|
4549
|
+
if (!isRec5(rawApp)) continue;
|
|
4550
|
+
for (const navId of Object.keys(asRecord(rawApp.navigation))) {
|
|
4551
|
+
if (navIds.has(navId)) continue;
|
|
4552
|
+
orphan(
|
|
4553
|
+
`${inLocale} \xB7 app "${appName}" \xB7 navigation "${navId}"`,
|
|
4554
|
+
`${appPath}.navigation.${navId}`,
|
|
4555
|
+
`Translations are keyed to navigation item "${navId}", which app "${appName}" does not declare. The menu entry keeps its source-locale label.` + suggest5(navId, navIds),
|
|
4556
|
+
`Match the key to the navigation item's \`id\`, or drop it.` + (navIds.size > 0 ? ` Declared navigation ids: ${listNames(navIds)}.` : "")
|
|
4557
|
+
);
|
|
4558
|
+
}
|
|
4559
|
+
}
|
|
4560
|
+
for (const [dashName, rawDash] of Object.entries(asRecord(rawData.dashboards))) {
|
|
4561
|
+
const dashPath = `${base}.dashboards.${dashName}`;
|
|
4562
|
+
const dash = universe.dashboards.get(dashName);
|
|
4563
|
+
if (!dash) {
|
|
4564
|
+
orphan(
|
|
4565
|
+
`${inLocale} \xB7 dashboard "${dashName}"`,
|
|
4566
|
+
dashPath,
|
|
4567
|
+
`Translations are keyed to dashboard "${dashName}", which this stack does not define. The dashboard title stays in the source locale.` + suggest5(dashName, universe.dashboards.keys()),
|
|
4568
|
+
`Match the key to a dashboard's \`name\`, or drop it.` + (universe.dashboards.size > 0 ? ` Defined dashboards: ${listNames(universe.dashboards.keys())}.` : "")
|
|
4569
|
+
);
|
|
4570
|
+
continue;
|
|
4571
|
+
}
|
|
4572
|
+
if (!isRec5(rawDash)) continue;
|
|
4573
|
+
for (const widgetId of Object.keys(asRecord(rawDash.widgets))) {
|
|
4574
|
+
if (dash.widgets.has(widgetId)) continue;
|
|
4575
|
+
orphan(
|
|
4576
|
+
`${inLocale} \xB7 dashboard "${dashName}" \xB7 widget "${widgetId}"`,
|
|
4577
|
+
`${dashPath}.widgets.${widgetId}`,
|
|
4578
|
+
`Translations are keyed to widget "${widgetId}", which dashboard "${dashName}" does not declare. The widget title stays in the source locale.` + suggest5(widgetId, dash.widgets),
|
|
4579
|
+
`Match the key to the widget's \`id\`, or drop it.` + (dash.widgets.size > 0 ? ` Declared widget ids: ${listNames(dash.widgets)}.` : "")
|
|
4580
|
+
);
|
|
4581
|
+
}
|
|
4582
|
+
for (const actionKey of Object.keys(asRecord(rawDash.actions))) {
|
|
4583
|
+
if (dash.actions.has(actionKey)) continue;
|
|
4584
|
+
orphan(
|
|
4585
|
+
`${inLocale} \xB7 dashboard "${dashName}" \xB7 action "${actionKey}"`,
|
|
4586
|
+
`${dashPath}.actions.${actionKey}`,
|
|
4587
|
+
`Translations are keyed to header action "${actionKey}", which dashboard "${dashName}" does not declare. The button keeps its source-locale label.` + suggest5(actionKey, dash.actions),
|
|
4588
|
+
`Header-action translations are keyed by the action's \`actionUrl\`, not its label.` + (dash.actions.size > 0 ? ` Declared header actions: ${listNames(dash.actions)}.` : "")
|
|
4589
|
+
);
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
4592
|
+
}
|
|
4593
|
+
}
|
|
4594
|
+
return findings;
|
|
4595
|
+
}
|
|
4596
|
+
function asRecord(v) {
|
|
4597
|
+
return isRec5(v) ? v : {};
|
|
4598
|
+
}
|
|
4599
|
+
function checkOptionKeys(findings, ctx) {
|
|
4600
|
+
const optionKeys = Object.keys(asRecord(ctx.optionMap));
|
|
4601
|
+
if (optionKeys.length === 0) return;
|
|
4602
|
+
const declared = readOptions(ctx.field);
|
|
4603
|
+
if (!declared) {
|
|
4604
|
+
findings.push({
|
|
4605
|
+
severity: "warning",
|
|
4606
|
+
rule: TRANSLATION_OPTION_KEY_UNKNOWN,
|
|
4607
|
+
where: ctx.where,
|
|
4608
|
+
path: ctx.path,
|
|
4609
|
+
message: `Option translations are keyed under field "${ctx.fieldName}" of object "${ctx.objectName}", which declares no \`options\` at all (field type "${strName8(ctx.field.type) ?? "unknown"}"). Nothing reads this map.`,
|
|
4610
|
+
hint: `Declare the options on the field, move the translations to the field that owns them, or drop them.`
|
|
4611
|
+
});
|
|
4612
|
+
return;
|
|
4613
|
+
}
|
|
4614
|
+
for (const key of optionKeys) {
|
|
4615
|
+
if (declared.values.has(key)) continue;
|
|
4616
|
+
const byLabel = declared.byLabel.get(key.toLowerCase());
|
|
4617
|
+
findings.push({
|
|
4618
|
+
severity: "warning",
|
|
4619
|
+
rule: TRANSLATION_OPTION_KEY_UNKNOWN,
|
|
4620
|
+
where: ctx.where,
|
|
4621
|
+
path: `${ctx.path}.${key}`,
|
|
4622
|
+
message: byLabel ? `Option translation is keyed by the DISPLAY LABEL "${key}" instead of the stored value "${byLabel}". The resolver looks the option up by value, so this entry is never found and the option renders with its source-locale label.` : `Option translation is keyed by "${key}", which is not one of the values declared by field "${ctx.objectName}.${ctx.fieldName}". The option renders untranslated.` + suggest5(key, declared.values),
|
|
4623
|
+
hint: byLabel ? `Rename the key to "${byLabel}".` : `Option keys are the stored \`value\`, not the label and not a variant spelling (\`direct_mail\`, not \`direct-mail\`). Declared values: ${listNames(declared.values)}.`
|
|
4624
|
+
});
|
|
4625
|
+
}
|
|
4626
|
+
}
|
|
4627
|
+
function checkActionParams(findings, ctx) {
|
|
4628
|
+
const rawParams = Object.keys(asRecord(isRec5(ctx.rawAction) ? ctx.rawAction.params : void 0));
|
|
4629
|
+
if (rawParams.length === 0) return;
|
|
4630
|
+
const declared = /* @__PURE__ */ new Set();
|
|
4631
|
+
for (const param of asArray28(ctx.action.params)) {
|
|
4632
|
+
const name = strName8(param.name) ?? strName8(param.field);
|
|
4633
|
+
if (name) declared.add(name);
|
|
4634
|
+
}
|
|
4635
|
+
for (const paramName of rawParams) {
|
|
4636
|
+
if (declared.has(paramName)) continue;
|
|
4637
|
+
findings.push({
|
|
4638
|
+
severity: "warning",
|
|
4639
|
+
rule: TRANSLATION_TARGET_UNKNOWN,
|
|
4640
|
+
where: `${ctx.where} \xB7 param "${paramName}"`,
|
|
4641
|
+
path: `${ctx.path}.params.${paramName}`,
|
|
4642
|
+
message: `Translations are keyed to parameter "${paramName}", which ${ctx.subject} does not declare. The parameter's label and help text render untranslated in the action dialog.` + suggest5(paramName, declared),
|
|
4643
|
+
hint: `Match the key to a declared param \`name\`, or drop it.` + (declared.size > 0 ? ` Declared params: ${listNames(declared)}.` : "")
|
|
4644
|
+
});
|
|
4645
|
+
}
|
|
4646
|
+
}
|
|
4647
|
+
|
|
4648
|
+
// src/validate-ai-surface-affinity.ts
|
|
4649
|
+
var AI_SKILL_SURFACE_MISMATCH = "ai-skill-surface-mismatch";
|
|
4650
|
+
function asArray29(v) {
|
|
4651
|
+
if (Array.isArray(v)) return v.filter((x) => !!x && typeof x === "object");
|
|
4652
|
+
if (v && typeof v === "object") {
|
|
4653
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
4654
|
+
}
|
|
4655
|
+
return [];
|
|
4656
|
+
}
|
|
4657
|
+
function strName9(v) {
|
|
4658
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
4659
|
+
}
|
|
4660
|
+
function surfaceOf(v) {
|
|
4661
|
+
return typeof v === "string" && v.length > 0 ? v : "ask";
|
|
4662
|
+
}
|
|
4663
|
+
function validateAiSurfaceAffinity(stack) {
|
|
4664
|
+
const findings = [];
|
|
4665
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
4666
|
+
const skillsByName = /* @__PURE__ */ new Map();
|
|
4667
|
+
for (const skill of asArray29(stack.skills)) {
|
|
4668
|
+
const n = strName9(skill.name);
|
|
4669
|
+
if (n) skillsByName.set(n, skill);
|
|
4670
|
+
}
|
|
4671
|
+
const agents = asArray29(stack.agents);
|
|
4672
|
+
for (let ai = 0; ai < agents.length; ai++) {
|
|
4673
|
+
const agent = agents[ai];
|
|
4674
|
+
const agentName = strName9(agent.name) ?? `#${ai}`;
|
|
4675
|
+
const agentSurface = surfaceOf(agent.surface);
|
|
4676
|
+
const skillRefs = Array.isArray(agent.skills) ? agent.skills : [];
|
|
4677
|
+
for (let si = 0; si < skillRefs.length; si++) {
|
|
4678
|
+
const ref = strName9(skillRefs[si]);
|
|
4679
|
+
if (!ref) continue;
|
|
4680
|
+
const skill = skillsByName.get(ref);
|
|
4681
|
+
if (!skill) continue;
|
|
4682
|
+
const skillSurface = surfaceOf(skill.surface);
|
|
4683
|
+
if (skillSurface === "both" || skillSurface === agentSurface) continue;
|
|
4684
|
+
findings.push({
|
|
4685
|
+
severity: "error",
|
|
4686
|
+
rule: AI_SKILL_SURFACE_MISMATCH,
|
|
4687
|
+
where: `agent "${agentName}" \xB7 skills`,
|
|
4688
|
+
path: `agents[${ai}].skills[${si}]`,
|
|
4689
|
+
message: `Agent "${agentName}" (surface: '${agentSurface}') references skill "${ref}" (surface: '${skillSurface}') \u2014 incompatible affinity (ADR-0064 \xA73). The runtime refuses this binding with a load error, so chatting with this agent fails at request time even though the stack parses and validates cleanly.`,
|
|
4690
|
+
hint: `A skill may only attach to an agent whose surface it matches. Move "${ref}" to a '${skillSurface}'-surface agent, change its \`surface\` to '${agentSurface}', or \u2014 only if it is a genuinely shared, read-only capability \u2014 declare \`surface: 'both'\`.`
|
|
4691
|
+
});
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4694
|
+
return findings;
|
|
4695
|
+
}
|
|
4696
|
+
|
|
4697
|
+
// src/validate-ai-tool-references.ts
|
|
4698
|
+
import { PLATFORM_PROVIDED_TOOL_NAMES, PLATFORM_TOOL_FAMILY_PREFIXES } from "@objectstack/spec/system";
|
|
4699
|
+
var AI_SKILL_TOOL_UNRESOLVED = "ai-skill-tool-unresolved";
|
|
4700
|
+
function asArray30(v) {
|
|
4701
|
+
if (Array.isArray(v)) return v.filter((x) => !!x && typeof x === "object");
|
|
4702
|
+
if (v && typeof v === "object") {
|
|
4703
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
4704
|
+
}
|
|
4705
|
+
return [];
|
|
4706
|
+
}
|
|
4707
|
+
function strName10(v) {
|
|
4708
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
4709
|
+
}
|
|
4710
|
+
function distance5(a, b) {
|
|
4711
|
+
const m = a.length;
|
|
4712
|
+
const n = b.length;
|
|
4713
|
+
if (m === 0) return n;
|
|
4714
|
+
if (n === 0) return m;
|
|
4715
|
+
let prev = Array.from({ length: n + 1 }, (_, j) => j);
|
|
4716
|
+
for (let i = 1; i <= m; i++) {
|
|
4717
|
+
const curr = [i, ...new Array(n).fill(0)];
|
|
4718
|
+
for (let j = 1; j <= n; j++) {
|
|
4719
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
4720
|
+
curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);
|
|
4721
|
+
}
|
|
4722
|
+
prev = curr;
|
|
4723
|
+
}
|
|
4724
|
+
return prev[n];
|
|
4725
|
+
}
|
|
4726
|
+
function suggest6(target, known) {
|
|
4727
|
+
for (const prefix of PLATFORM_TOOL_FAMILY_PREFIXES) {
|
|
4728
|
+
if (known.has(`${prefix}${target}`)) return ` Did you mean "${prefix}${target}"?`;
|
|
4729
|
+
}
|
|
4730
|
+
let best;
|
|
4731
|
+
let bestScore = Infinity;
|
|
4732
|
+
for (const candidate of known) {
|
|
4733
|
+
const d = distance5(target, candidate);
|
|
4734
|
+
if (d < bestScore) {
|
|
4735
|
+
bestScore = d;
|
|
4736
|
+
best = candidate;
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
const limit = Math.max(2, Math.floor(target.length / 3));
|
|
4740
|
+
return best && bestScore <= limit ? ` Did you mean "${best}"?` : "";
|
|
4741
|
+
}
|
|
4742
|
+
var HEADLESS_ACTION_TYPES = /* @__PURE__ */ new Set(["script", "api", "flow"]);
|
|
4743
|
+
function materialisesAsTool(action) {
|
|
4744
|
+
const ai = action.ai;
|
|
4745
|
+
if (!ai || typeof ai !== "object") return false;
|
|
4746
|
+
const aiRec = ai;
|
|
4747
|
+
if (aiRec.exposed !== true) return false;
|
|
4748
|
+
if (!strName10(aiRec.description)) return false;
|
|
4749
|
+
const type = strName10(action.type);
|
|
4750
|
+
if (!type || !HEADLESS_ACTION_TYPES.has(type)) return false;
|
|
4751
|
+
if (type === "script") return Boolean(action.target || action.body);
|
|
4752
|
+
return Boolean(action.target);
|
|
4753
|
+
}
|
|
4754
|
+
function collectToolUniverse(stack) {
|
|
4755
|
+
const universe = new Set(PLATFORM_PROVIDED_TOOL_NAMES);
|
|
4756
|
+
for (const tool of asArray30(stack.tools)) {
|
|
4757
|
+
const n = strName10(tool.name);
|
|
4758
|
+
if (n) universe.add(n);
|
|
4759
|
+
}
|
|
4760
|
+
const addActionFamily = (actions) => {
|
|
4761
|
+
for (const action of asArray30(actions)) {
|
|
4762
|
+
const n = strName10(action.name);
|
|
4763
|
+
if (n && materialisesAsTool(action)) universe.add(`action_${n}`);
|
|
4764
|
+
}
|
|
4765
|
+
};
|
|
4766
|
+
addActionFamily(stack.actions);
|
|
4767
|
+
for (const obj of asArray30(stack.objects)) {
|
|
4768
|
+
addActionFamily(obj.actions);
|
|
4769
|
+
}
|
|
4770
|
+
return universe;
|
|
4771
|
+
}
|
|
4772
|
+
function collectUnexposedActionNames(stack) {
|
|
4773
|
+
const names = /* @__PURE__ */ new Set();
|
|
4774
|
+
const scan = (actions) => {
|
|
4775
|
+
for (const action of asArray30(actions)) {
|
|
4776
|
+
const n = strName10(action.name);
|
|
4777
|
+
if (n && !materialisesAsTool(action)) names.add(n);
|
|
4778
|
+
}
|
|
4779
|
+
};
|
|
4780
|
+
scan(stack.actions);
|
|
4781
|
+
for (const obj of asArray30(stack.objects)) scan(obj.actions);
|
|
4782
|
+
return names;
|
|
4783
|
+
}
|
|
4784
|
+
function validateAiToolReferences(stack) {
|
|
4785
|
+
const findings = [];
|
|
4786
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
4787
|
+
const universe = collectToolUniverse(stack);
|
|
4788
|
+
const unexposedActions = collectUnexposedActionNames(stack);
|
|
4789
|
+
const resolves = (ref) => {
|
|
4790
|
+
if (ref.endsWith("*")) {
|
|
4791
|
+
const prefix = ref.slice(0, -1);
|
|
4792
|
+
for (const name of universe) {
|
|
4793
|
+
if (name.startsWith(prefix)) return true;
|
|
4794
|
+
}
|
|
4795
|
+
return false;
|
|
4796
|
+
}
|
|
4797
|
+
return universe.has(ref);
|
|
4798
|
+
};
|
|
4799
|
+
const skills = asArray30(stack.skills);
|
|
4800
|
+
for (let si = 0; si < skills.length; si++) {
|
|
4801
|
+
const skill = skills[si];
|
|
4802
|
+
const skillName = strName10(skill.name) ?? `#${si}`;
|
|
4803
|
+
const refs = Array.isArray(skill.tools) ? skill.tools : [];
|
|
4804
|
+
for (let ti = 0; ti < refs.length; ti++) {
|
|
4805
|
+
const ref = strName10(refs[ti]);
|
|
4806
|
+
if (!ref || resolves(ref)) continue;
|
|
4807
|
+
const isPattern = ref.endsWith("*");
|
|
4808
|
+
const unexposed = !isPattern && ref.startsWith("action_") && unexposedActions.has(ref.slice("action_".length)) ? ref.slice("action_".length) : void 0;
|
|
4809
|
+
findings.push({
|
|
4810
|
+
severity: "warning",
|
|
4811
|
+
rule: AI_SKILL_TOOL_UNRESOLVED,
|
|
4812
|
+
where: `skill "${skillName}" \xB7 tools`,
|
|
4813
|
+
path: `skills[${si}].tools[${ti}]`,
|
|
4814
|
+
message: isPattern ? `Skill "${skillName}" subscribes to tool family "${ref}", which matches nothing this stack can resolve (no declared tool, no platform tool, and no AI-exposed declarative action materialises into it). The subscription contributes zero tools at runtime.` : unexposed ? `Skill "${skillName}" references tool "${ref}", but the action "${unexposed}" does not become an AI tool: the runtime materialises \`action_<name>\` only for an action that opts in with \`ai.exposed: true\` + \`ai.description\` (ADR-0011) AND has a headless path (type \`script\`/\`api\`/\`flow\` with a target or body \u2014 \`url\`/\`modal\`/\`form\` are UI-only). The reference is dropped at runtime, so the skill promises a capability the agent cannot call.` : `Skill "${skillName}" references tool "${ref}", which resolves to nothing this stack can see: not a \`stack.tools\` record, not a platform-registered tool, and not a materialised action tool (\`action_<name>\`). The runtime silently drops the reference, so the skill's instructions claim a capability the agent does not have \u2014 the assistant will improvise or fail when asked to use it.` + suggest6(ref, universe),
|
|
4815
|
+
hint: unexposed ? `Either opt "${unexposed}" in \u2014 set \`ai: { exposed: true, description: '\u2026' }\` (\u226540 chars, LLM-facing) and give it a headless type \u2014 or drop the reference and have the skill's instructions recommend the UI action instead. A \`modal\`/\`form\`/\`url\` action stays human-driven by design; that is a legitimate answer, not a gap.` : `Back "${ref}" with a real executable: declare a declarative action (or flow), opt it in with \`ai.exposed: true\` + \`ai.description\`, and reference its materialised tool (\`action_<name>\` \u2014 the ADR-0109 default path, no tool record needed); or reference a platform tool by its registered name; or remove the reference and the instructions that mention it. Ignore this only if a runtime plugin outside the platform registry provides "${ref}". Family prefixes materialised by the runtime: ${PLATFORM_TOOL_FAMILY_PREFIXES.join(", ")}.`
|
|
4816
|
+
});
|
|
4817
|
+
}
|
|
4818
|
+
}
|
|
4819
|
+
return findings;
|
|
4820
|
+
}
|
|
4821
|
+
|
|
4822
|
+
// src/validate-ai-agent-authoring.ts
|
|
4823
|
+
var AGENT_AUTHORING_WITHDRAWN = "agent-authoring-withdrawn";
|
|
4824
|
+
function asArray31(v) {
|
|
4825
|
+
if (Array.isArray(v)) return v.filter((x) => !!x && typeof x === "object");
|
|
4826
|
+
if (v && typeof v === "object") {
|
|
4827
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
4828
|
+
}
|
|
4829
|
+
return [];
|
|
4830
|
+
}
|
|
4831
|
+
function strName11(v) {
|
|
4832
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
4833
|
+
}
|
|
4834
|
+
var PLATFORM_AGENT_NAMES = /* @__PURE__ */ new Set(["ask", "build", "data_chat", "metadata_assistant"]);
|
|
4835
|
+
function validateAiAgentAuthoring(stack) {
|
|
4836
|
+
const findings = [];
|
|
4837
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
4838
|
+
const agents = asArray31(stack.agents);
|
|
4839
|
+
for (let ai = 0; ai < agents.length; ai++) {
|
|
4840
|
+
const agent = agents[ai];
|
|
4841
|
+
const name = strName11(agent.name) ?? `#${ai}`;
|
|
4842
|
+
const isPlatformName = PLATFORM_AGENT_NAMES.has(name);
|
|
4843
|
+
const skillCount = Array.isArray(agent.skills) ? agent.skills.length : 0;
|
|
4844
|
+
findings.push({
|
|
4845
|
+
severity: "warning",
|
|
4846
|
+
rule: AGENT_AUTHORING_WITHDRAWN,
|
|
4847
|
+
where: `agent "${name}"`,
|
|
4848
|
+
path: `agents[${ai}]`,
|
|
4849
|
+
message: isPlatformName ? `This stack declares an agent named "${name}", which is a PLATFORM agent id. The runtime serves its own record for that name and ignores this one \u2014 the declaration has no effect and will drift from the platform's definition.` : `This stack declares the agent "${name}", but tenant/app-package agents were withdrawn (ADR-0063 \xA72): the kernel ships exactly two agents (\`ask\`, \`build\`) and the surface the user is in binds one. The runtime filters this record out of the agent catalog and refuses to load it, so it never runs \u2014 it parses, validates, and ships as inert metadata.`,
|
|
4850
|
+
hint: isPlatformName ? `Remove the declaration; the platform owns "${name}". Extend it with skills instead.` : `Delete the agent and express its capability as skills. Everything an agent carried that a skill does not is persona text: move the useful parts of \`instructions\` into the skills' own instructions.` + (skillCount > 0 ? ` The ${skillCount} skill${skillCount === 1 ? "" : "s"} this agent references already carry the capability \u2014 they attach to the platform agent by \`surface\` affinity, so nothing is lost by dropping the persona.` : ``)
|
|
4851
|
+
});
|
|
4852
|
+
}
|
|
4853
|
+
return findings;
|
|
4854
|
+
}
|
|
4855
|
+
|
|
4856
|
+
// src/reference-integrity-suite.ts
|
|
4857
|
+
var REFERENCE_INTEGRITY_RULES = [
|
|
4858
|
+
{ name: "validateObjectReferences", run: validateObjectReferences },
|
|
4859
|
+
{ name: "validateActionNameRefs", run: validateActionNameRefs },
|
|
4860
|
+
{ name: "validatePageFieldBindings", run: validatePageFieldBindings },
|
|
4861
|
+
{ name: "validateChartBindings", run: validateChartBindings },
|
|
4862
|
+
{ name: "validateNavAccess", run: validateNavAccess },
|
|
4863
|
+
{ name: "validateTranslationReferences", run: validateTranslationReferences },
|
|
4864
|
+
{ name: "validateFlowTemplatePaths", run: validateFlowTemplatePaths },
|
|
4865
|
+
{ name: "validateAiSurfaceAffinity", run: validateAiSurfaceAffinity },
|
|
4866
|
+
{ name: "validateAiToolReferences", run: validateAiToolReferences },
|
|
4867
|
+
{ name: "validateAiAgentAuthoring", run: validateAiAgentAuthoring }
|
|
4868
|
+
];
|
|
4869
|
+
function validateReferenceIntegrity(stack) {
|
|
4870
|
+
const findings = [];
|
|
4871
|
+
for (const rule of REFERENCE_INTEGRITY_RULES) {
|
|
4872
|
+
findings.push(...rule.run(stack));
|
|
4873
|
+
}
|
|
4874
|
+
return findings;
|
|
4875
|
+
}
|
|
2123
4876
|
export {
|
|
4877
|
+
ACTION_NAME_UNDEFINED,
|
|
4878
|
+
AGENT_AUTHORING_WITHDRAWN,
|
|
4879
|
+
AI_SKILL_SURFACE_MISMATCH,
|
|
4880
|
+
AI_SKILL_TOOL_UNRESOLVED,
|
|
4881
|
+
APPROVAL_APPROVERS_MAY_RESOLVE_EMPTY,
|
|
4882
|
+
APPROVAL_APPROVER_CROSS_ORG_UNSUPPORTED,
|
|
2124
4883
|
APPROVAL_APPROVER_NOT_MEMBERSHIP_TIER,
|
|
2125
4884
|
APPROVAL_APPROVER_TYPE_DEPRECATED,
|
|
2126
4885
|
APPROVAL_APPROVER_TYPE_UNKNOWN,
|
|
4886
|
+
APPROVAL_DECISION_OUTPUTS_RESERVED,
|
|
2127
4887
|
APPROVAL_ESCALATION_REASSIGN_NO_TARGET,
|
|
4888
|
+
APPROVAL_EXPRESSION_INVALID,
|
|
4889
|
+
APPROVAL_EXPRESSION_NO_EMPTY_POLICY,
|
|
2128
4890
|
CAPABILITY_REFERENCE_UNKNOWN,
|
|
4891
|
+
CHART_AXIS_NOT_SELECTED,
|
|
2129
4892
|
CHART_CONFIG_MISSING,
|
|
4893
|
+
CHART_DATASET_UNKNOWN,
|
|
4894
|
+
CHART_DIMENSION_UNKNOWN,
|
|
2130
4895
|
CHART_FIELD_UNKNOWN,
|
|
4896
|
+
CHART_MEASURE_UNKNOWN,
|
|
4897
|
+
DASHBOARD_ACTION_ROUTE_UNRESOLVED,
|
|
4898
|
+
DASHBOARD_ACTION_TARGET_UNDEFINED,
|
|
4899
|
+
DASHBOARD_FILTER_FIELD_UNKNOWN,
|
|
2131
4900
|
FIELD_GROUP_EMPTY,
|
|
2132
4901
|
FIELD_GROUP_UNDECLARED,
|
|
4902
|
+
FILTER_TOKEN_UNKNOWN,
|
|
2133
4903
|
FLOW_DRAFT_STATUS_AMBIGUOUS,
|
|
4904
|
+
FLOW_TEMPLATE_LOOKUP_TRAVERSAL,
|
|
4905
|
+
FLOW_TEMPLATE_UNKNOWN_FIELD,
|
|
2134
4906
|
FLOW_TRIGGER_UNKNOWN_OBJECT,
|
|
4907
|
+
FLOW_UPDATE_READONLY_FIELD,
|
|
4908
|
+
FLOW_UPDATE_READONLY_WHEN_FIELD,
|
|
2135
4909
|
FORM_COLSPAN_ABSOLUTE,
|
|
2136
4910
|
FORM_FIELD_UNKNOWN,
|
|
2137
4911
|
LIST_VIEW_FILTERS_IN_VIEWS_MODE,
|
|
2138
4912
|
MEASURE_AGGREGATE_INCOHERENT,
|
|
4913
|
+
NAV_OBJECT_UNGRANTED,
|
|
4914
|
+
OBJECT_REFERENCE_UNKNOWN,
|
|
4915
|
+
OBJECT_REFERENCE_UNREGISTERED_PLATFORM,
|
|
4916
|
+
ORG_AXIS_CROSS_ORG_BU_GRANT,
|
|
4917
|
+
ORG_AXIS_PERMISSION_INHERITANCE,
|
|
4918
|
+
PAGE_FIELD_UNKNOWN,
|
|
2139
4919
|
PAGE_SOURCE_CLASSNAME,
|
|
4920
|
+
REACT_CHART_AGGREGATE_INVALID,
|
|
4921
|
+
REACT_CHART_AXIS_UNKNOWN,
|
|
4922
|
+
REACT_CHART_FIELD_UNKNOWN,
|
|
4923
|
+
REFERENCE_INTEGRITY_RULES,
|
|
2140
4924
|
SECURITY_ANCHOR_HIGH_PRIVILEGE,
|
|
2141
4925
|
SECURITY_BOOK_AUDIENCE_UNKNOWN_SET,
|
|
2142
4926
|
SECURITY_DELEGATION_MISSING_REASON,
|
|
@@ -2148,6 +4932,8 @@ export {
|
|
|
2148
4932
|
SECURITY_PRIVATE_NO_READSCOPE,
|
|
2149
4933
|
SECURITY_ROLE_WORD,
|
|
2150
4934
|
SECURITY_WILDCARD_VAMA,
|
|
4935
|
+
SEED_INSERT_MODE_DUPLICATES_ON_REPLAY,
|
|
4936
|
+
SEED_VALUE_OUTSIDE_STATE_MACHINE,
|
|
2151
4937
|
SEMANTIC_ROLE_FIELD_UNKNOWN,
|
|
2152
4938
|
STYLE_CLASSNAME_TAILWIND,
|
|
2153
4939
|
STYLE_NODE_MISSING_ID,
|
|
@@ -2157,6 +4943,8 @@ export {
|
|
|
2157
4943
|
TABLE_COUNT_ONLY,
|
|
2158
4944
|
TITLE_FORMAT_RETIRED,
|
|
2159
4945
|
TITLE_UNRESOLVABLE,
|
|
4946
|
+
TRANSLATION_OPTION_KEY_UNKNOWN,
|
|
4947
|
+
TRANSLATION_TARGET_UNKNOWN,
|
|
2160
4948
|
VIEW_CONTAINER_SHAPE,
|
|
2161
4949
|
VISIBILITY_ALIAS_DEPRECATED,
|
|
2162
4950
|
VISIBILITY_ROOT_MISLAYERED,
|
|
@@ -2165,20 +4953,37 @@ export {
|
|
|
2165
4953
|
WIDGET_MEASURE_UNKNOWN,
|
|
2166
4954
|
buildAccessMatrix,
|
|
2167
4955
|
diffAccessMatrix,
|
|
4956
|
+
validateActionNameRefs,
|
|
4957
|
+
validateAiAgentAuthoring,
|
|
4958
|
+
validateAiSurfaceAffinity,
|
|
4959
|
+
validateAiToolReferences,
|
|
2168
4960
|
validateApprovalApprovers,
|
|
2169
4961
|
validateCapabilityReferences,
|
|
4962
|
+
validateChartBindings,
|
|
4963
|
+
validateDashboardActionRefs,
|
|
4964
|
+
validateFilterTokens,
|
|
4965
|
+
validateFlowTemplatePaths,
|
|
2170
4966
|
validateFlowTriggerReadiness,
|
|
2171
4967
|
validateFormLayout,
|
|
2172
4968
|
validateJsxPages,
|
|
2173
4969
|
validateListViewMode,
|
|
4970
|
+
validateNavAccess,
|
|
4971
|
+
validateObjectReferences,
|
|
4972
|
+
validateOrgAxisRedLines,
|
|
4973
|
+
validatePageFieldBindings,
|
|
2174
4974
|
validatePageSourceStyling,
|
|
2175
4975
|
validateReactPageProps,
|
|
2176
4976
|
validateReactPages,
|
|
4977
|
+
validateReadonlyFlowWrites,
|
|
2177
4978
|
validateRecordTitle,
|
|
4979
|
+
validateReferenceIntegrity,
|
|
2178
4980
|
validateResponsiveStyles,
|
|
2179
4981
|
validateSecurityPosture,
|
|
4982
|
+
validateSeedReplaySafety,
|
|
4983
|
+
validateSeedStateMachine,
|
|
2180
4984
|
validateSemanticRoles,
|
|
2181
4985
|
validateStackExpressions,
|
|
4986
|
+
validateTranslationReferences,
|
|
2182
4987
|
validateViewContainers,
|
|
2183
4988
|
validateVisibilityPredicates,
|
|
2184
4989
|
validateWidgetBindings
|