suppa-mcp-2 1.3.0 → 1.3.2

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.
@@ -69,12 +69,6 @@ const PERMANENT_DELETE_ROUTE = /^(?:api\/)?core\/data\/[^/]+\/delete$/;
69
69
  // "a single-dot path segment must be '.' or '%2e'; a double-dot path segment
70
70
  // must be '..', '.%2e', '%2e.' or '%2e%2e'" (URL Standard) — so `%2e%2e` climbs
71
71
  // a level on the wire exactly like `..` does.
72
- //
73
- // These are tested AFTER one decodeURIComponent pass, where a surviving `%2e`
74
- // can only have come from a double-encoded `%252e`. fetch would leave that one
75
- // encoded, so accepting it here over-matches by exactly one decoding level:
76
- // the safe direction for a block, and the reason no second decode pass is
77
- // needed to be sure the matcher has seen every form the wire can resolve.
78
72
  const SINGLE_DOT_SEGMENT = /^(?:\.|%2e)$/i;
79
73
  const DOUBLE_DOT_SEGMENT = /^(?:\.|%2e){2}$/i;
80
74
  /**
@@ -98,42 +92,75 @@ function resolveDotSegments(path) {
98
92
  }
99
93
  return out.join("/");
100
94
  }
101
- /** Normalize a path or absolute URL down to comparable route segments. */
102
- function routePath(pathOrUrl) {
95
+ /**
96
+ * Strip an input down to its path, undoing the rewrites fetch performs BEFORE
97
+ * it parses.
98
+ *
99
+ * The URL parser inside fetch DELETES every tab, LF and CR from the input and
100
+ * trims leading/trailing C0 controls and spaces, so `de<TAB>lete` and
101
+ * `delete\x00` are the segment `delete` on the wire. It also maps `\` to `/`
102
+ * for http(s). Undoing all three here is what keeps this matcher and the wire
103
+ * looking at the same path — each was a live bypass.
104
+ */
105
+ function rawPath(pathOrUrl) {
103
106
  let p = String(pathOrUrl ?? "");
104
- // The URL parser inside fetch DELETES every tab, LF and CR from the input and
105
- // trims leading/trailing C0 controls and spaces, so `de<TAB>lete` and
106
- // `delete\x00` are the segment `delete` on the wire. It also maps `\` to `/`
107
- // for http(s). Undoing all three here first is what keeps this matcher and
108
- // the wire looking at the same path — each was a live bypass.
109
107
  p = p.replace(/[\t\n\r]/g, "").replace(/^[\x00-\x20]+|[\x00-\x20]+$/g, "").replace(/\\/g, "/");
110
108
  const scheme = p.indexOf("://");
111
109
  if (scheme !== -1) {
112
110
  const slash = p.indexOf("/", scheme + 3);
113
111
  p = slash === -1 ? "" : p.slice(slash);
114
112
  }
115
- p = p.split("?")[0].split("#")[0];
113
+ return p.split("?")[0].split("#")[0];
114
+ }
115
+ /** Collapse, trim and lowercase a resolved path into comparable route segments. */
116
+ function comparable(path) {
117
+ return path
118
+ .replace(/\/+/g, "/")
119
+ .replace(/^\/+|\/+$/g, "")
120
+ .toLowerCase();
121
+ }
122
+ /**
123
+ * Every path this input can be READ as by the time it reaches the platform's
124
+ * router — the block is the OR over all of them, because a single normalization
125
+ * cannot model both ends of the wire at once.
126
+ *
127
+ * Resolving dot segments on a DECODED path was a live bypass:
128
+ * `/core/data/%252e/%2e%2e/Tasks/delete` decodes to `.../%2e/../Tasks/delete`,
129
+ * where the matcher read `%2e` as a dot segment, DROPPED it, and then let the
130
+ * real `..` pop `data` — landing on `core/Tasks/delete`, which is not the
131
+ * blocked shape. fetch never decodes, so on the wire `%252e` stays a literal
132
+ * segment, `%2e%2e` pops THAT instead, and the request left as
133
+ * POST /core/data/Tasks/delete. Treating a decoded escape as a dot segment
134
+ * REMOVES a segment, so it under-matches as readily as it over-matches — the
135
+ * earlier "over-matches by one decoding level, the safe direction" reasoning
136
+ * was simply wrong.
137
+ *
138
+ * So each candidate is derived for one reader, and none of them has to be
139
+ * conservative on its own:
140
+ * 1. what fetch puts on the wire — dot segments resolved, nothing decoded;
141
+ * 2. that path decoded once, for a router that decodes before routing (this
142
+ * is also what keeps %2F from smuggling a separator past the matcher);
143
+ * 3. the decoded path re-resolved, for one that normalizes after decoding.
144
+ */
145
+ function routeCandidates(pathOrUrl) {
146
+ const onWire = resolveDotSegments(rawPath(pathOrUrl));
147
+ const candidates = [comparable(onWire)];
148
+ let decoded = null;
116
149
  try {
117
- // %2F-encoded separators must not smuggle the route past the matcher.
118
- p = decodeURIComponent(p);
150
+ decoded = decodeURIComponent(onWire);
119
151
  }
120
152
  catch {
121
- // Malformed escapes: match the raw form rather than giving up. The dot
122
- // segment patterns below still catch the %2e forms in that raw path.
153
+ // Malformed escapes: the wire form above is the whole answer. A router
154
+ // cannot decode this either, so there is no second reading to model.
123
155
  }
124
- // Decode first, THEN resolve dot segments, THEN collapse and lowercase: the
125
- // matcher and fetch must agree on the path, and fetch resolves '.' / '..'
126
- // while this function used to leave them in place — `Tasks/./delete` reached
127
- // the permanent delete with the block silently looking at a different path.
128
- p = resolveDotSegments(p);
129
- return p
130
- .replace(/\/+/g, "/")
131
- .replace(/^\/+|\/+$/g, "")
132
- .toLowerCase();
156
+ if (decoded !== null && decoded !== onWire) {
157
+ candidates.push(comparable(decoded), comparable(resolveDotSegments(decoded)));
158
+ }
159
+ return candidates;
133
160
  }
134
161
  /** True for POST /core/data/:entityName/delete — and only for that route. */
135
162
  export function isPermanentDeletePath(pathOrUrl) {
136
- return PERMANENT_DELETE_ROUTE.test(routePath(pathOrUrl));
163
+ return routeCandidates(pathOrUrl).some((p) => PERMANENT_DELETE_ROUTE.test(p));
137
164
  }
138
165
  /** The refusal raised in place of a permanent delete. Names the reversible pair. */
139
166
  export function permanentDeleteRefusal(pathOrUrl) {
package/dist/server.js CHANGED
@@ -260,7 +260,8 @@ ENTITY BUILDER (create + edit fields; removal is UI-only)
260
260
  - sub_type matrix: timestamp → 'date' | 'time' | 'timestamp'; text → 'encrypted'; enum/multi-enum → the enum's global name, set by the platform (never pass it); every other type takes none. Anything else is refused before the request.
261
261
  - FIELD OPTIONS decide whether a field is usable: searchable, searchPriority (1-4), readOnly, canGroup, canSort, showInTable, editFromTable, canFilter. Pass options_json on suppa_add_field — a field created without them is missing from table views, and suppa_search_records' free-text search only covers fields marked searchable. Turn them on later with suppa_update_field.
262
262
  - OWNED CHILD COLLECTIONS ARE TABULAR PARTS. Repeating rows that belong to one parent record (e.g. a part's BOM items) → suppa_create_tabular_part(parent_entity, name), which auto-creates the child's 'owner' relation and the parent link. NEVER model this by hand as parent.one-to-many + child.owner: suppa_add_field REFUSES field_type='one-to-many'. Use 'many-to-many' only for a shared lookup referenced by many records.
263
- - Relations need relation_entity; enums need enum_name (qualified 'Entity.field') with values added via suppa_add_enum_values.
263
+ - Relations need relation_entity; enums need enum_name (the enum's global name, conventionally 'Entity.field'). Add the values FIRST with suppa_add_enum_values, then create the field with the same enum_name — the field is bound to the enum by that name.
264
+ - An enum value on a RECORD is a reference, not a string: write {"id": <Enums row id>} for enum and [{"id": ...}, ...] for multi-enum. A bare code like "red" is refused with 'field must contain id for many-to-one relationship'. Read the ids with suppa_search_records on 'Enums' filtered by name = the enum name.
264
265
  - Existing fields CAN be edited with suppa_update_field (name, title, notNull/unique/default, relation target, and the options above), within the platform's own limits: a field's TYPE can never be changed, its SUBTYPE only toggles 'encrypted' on/off (text fields only), and a system field takes just title + the options keys. Removing a field is still UI-only — this server has no remove-field call.
265
266
 
266
267
  MIGRATION (Suppa 1.0 → 2.0)
@@ -296,7 +297,7 @@ export function buildServer() {
296
297
  // Reset so repeated buildServer() calls (e.g. in tests) do not double-count.
297
298
  TOOL_NAMES.length = 0;
298
299
  PROMPT_NAMES.length = 0;
299
- const server = new McpServer({ name: "suppa-2.0", version: "1.3.0" }, { instructions: INSTRUCTIONS });
300
+ const server = new McpServer({ name: "suppa-2.0", version: "1.3.2" }, { instructions: INSTRUCTIONS });
300
301
  const reg = (name, cfg, handler) => {
301
302
  server.registerTool(name, {
302
303
  description: cfg.description,
@@ -1272,15 +1273,21 @@ export function buildServer() {
1272
1273
  }));
1273
1274
  });
1274
1275
  reg("suppa_add_enum_values", {
1275
- description: "Add values to an enum (lookup table). enum_name: qualified 'Entity.field'\n" +
1276
- " key (e.g. 'Receipts.type'). values: comma-separated list.",
1276
+ description: "Add values to an enum (lookup table). enum_name: the enum's global name,\n" +
1277
+ " conventionally 'Entity.field' (e.g. 'Receipts.type'). values:\n" +
1278
+ " comma-separated 'code' or 'code:Label' — a value with no label is\n" +
1279
+ " stored with the code as its label, never blank.\n" +
1280
+ " Call this BEFORE creating the enum field, then pass the same\n" +
1281
+ " enum_name to suppa_add_field.",
1277
1282
  inputSchema: {
1278
1283
  enum_name: z
1279
1284
  .string()
1280
- .describe("Qualified 'Entity.field' enum key, e.g. 'Receipts.type'."),
1285
+ .describe("The enum's global name, conventionally 'Entity.field' (e.g. 'Receipts.type'). " +
1286
+ "It need not match the field name — one enum can back several fields."),
1281
1287
  values: z
1282
1288
  .string()
1283
- .describe("Comma-separated values to add; existing ones are skipped."),
1289
+ .describe("Comma-separated 'code' or 'code:Label' (e.g. \"new:New request,done:Done\"). " +
1290
+ "The label is what users see in the picker. Existing codes are skipped."),
1284
1291
  },
1285
1292
  annotations: _ADD,
1286
1293
  }, async (a) => text(await entity.addEnumValues(a.enum_name, a.values)));
@@ -70,9 +70,17 @@ export const RELATION_LIKE_FIELD_TYPES = [
70
70
  // Where `defaultValue` does NOT apply. builder.txt:43 — "defaultValue | string |
71
71
  // false | Default value. Not applicable to relations, enums, or unique fields."
72
72
  // So: every relation-like type above, plus ANY type when unique is set.
73
- // (`notNull` has its own, narrower exclusion — builder.txt:41: "Not applicable to
74
- // many-to-many / multi-enum" — and is still sent for the rest.)
75
73
  export const NO_DEFAULT_VALUE_FIELD_TYPES = RELATION_LIKE_FIELD_TYPES;
74
+ // Where `notNull` does NOT apply — its own, narrower exclusion. builder.txt:41 —
75
+ // "notNull | boolean | false | Field is required. Not applicable to many-to-many
76
+ // / multi-enum." The comment above used to claim this exclusion was honoured
77
+ // while the wire body set `notNull` unconditionally, so a required=true on these
78
+ // two types was sent to the builder and reported back as applied.
79
+ export const NO_NOT_NULL_FIELD_TYPES = ["many-to-many", "multi-enum"];
80
+ /** True when `notNull` is applicable to this field type (builder.txt:41). */
81
+ export function notNullApplies(fieldType) {
82
+ return !NO_NOT_NULL_FIELD_TYPES.includes(fieldType);
83
+ }
76
84
  /**
77
85
  * True when `defaultValue` is applicable to this field — and therefore when
78
86
  * `notNull` on it also demands one. Recorded evidence for that demand, on the
@@ -1336,9 +1344,30 @@ export async function addField(entityName, fieldName, fieldType, title, opts = {
1336
1344
  name: fieldName,
1337
1345
  type: resolvedType,
1338
1346
  title: await _expandTitle(title, fieldName),
1339
- notNull: required,
1340
- unique,
1341
1347
  };
1348
+ // Applicability is per the builder's own table, and a constraint that does not
1349
+ // apply is DROPPED by the builder without complaint — so sending it would be
1350
+ // reported back to the agent as applied while nothing changed. Each of these
1351
+ // is instead withheld and named in `not_applicable`, so the caller learns the
1352
+ // constraint is not in force.
1353
+ const notApplicable = [];
1354
+ if (notNullApplies(resolvedType)) {
1355
+ fieldDef.notNull = required;
1356
+ }
1357
+ else if (required) {
1358
+ notApplicable.push(`notNull was NOT set: builder.txt:41 — "Not applicable to many-to-many / multi-enum" ` +
1359
+ `(this field is '${resolvedType}'). The field was created WITHOUT the required ` +
1360
+ "constraint; enforce it in application logic if you need it.");
1361
+ }
1362
+ // builder.txt:42 — "unique | boolean | false | Field must be unique. Not
1363
+ // applicable to relations and enums."
1364
+ if (!RELATION_LIKE_FIELD_TYPES.includes(resolvedType)) {
1365
+ fieldDef.unique = unique;
1366
+ }
1367
+ else if (unique) {
1368
+ notApplicable.push(`unique was NOT set: builder.txt:42 — "Not applicable to relations and enums" ` +
1369
+ `(this field is '${resolvedType}'). The field was created WITHOUT the unique constraint.`);
1370
+ }
1342
1371
  // builder.txt:43 — "Not applicable to relations, enums, or unique fields":
1343
1372
  // sending it there is at best ignored, so it is never emitted.
1344
1373
  if (defaultText.trim() !== "" && typeNeedsDefault) {
@@ -1369,8 +1398,21 @@ export async function addField(entityName, fieldName, fieldType, title, opts = {
1369
1398
  if (relTarget) {
1370
1399
  fieldDef.relationTarget = relTarget;
1371
1400
  }
1372
- if (enumName) {
1373
- fieldDef.enumName = enumName;
1401
+ // An enum field is bound to its enum through `relationTarget`, exactly like a
1402
+ // relation — builder.txt:63 groups enum/multi-enum under "Relation types" and
1403
+ // :44 types relationTarget as "Related entity", which for these is the enum's
1404
+ // global name.
1405
+ //
1406
+ // This server used to send `enumName` instead. That key is in no doc capture,
1407
+ // and it is INERT: verified on a live 2.0 tenant (modern-expo.dev.suppa.me,
1408
+ // 2026-08-05) by creating the same field both ways and reading the schema
1409
+ // back — `enumName` produced subType=null, relationTarget=null (an unbound
1410
+ // field with no values behind it), while `relationTarget` produced
1411
+ // subType=relationTarget=<enum name>, matching every working enum field on
1412
+ // that tenant. The add-fields response echoes `enumName` back, which is why
1413
+ // the failure looked like success for so long.
1414
+ if (enumName && (resolvedType === "enum" || resolvedType === "multi-enum")) {
1415
+ fieldDef.relationTarget = enumName;
1374
1416
  }
1375
1417
  // builder.txt:60 — "options | object | false | Field options configuration."
1376
1418
  // (example body: builder.txt:127-132).
@@ -1383,7 +1425,12 @@ export async function addField(entityName, fieldName, fieldType, title, opts = {
1383
1425
  const result = await makeRequest("POST", `/api/core/builder/${entityName}/add-fields`, [
1384
1426
  fieldDef,
1385
1427
  ]);
1386
- return jsonResponse(result);
1428
+ // Plain result when everything asked for was applied — the shape callers and
1429
+ // tests already read. The wrapper appears only when something was withheld,
1430
+ // because that is the case a bare success would misreport.
1431
+ return notApplicable.length > 0
1432
+ ? jsonResponse({ result, not_applicable: notApplicable })
1433
+ : jsonResponse(result);
1387
1434
  }
1388
1435
  // builder.txt:391-398 — on a field created by the system (initiator = system)
1389
1436
  // these are the only accepted keys. Note searchPriority is NOT among them.
@@ -1604,27 +1651,50 @@ export async function updateField(entityName, fieldName, opts = {}) {
1604
1651
  * create duplicate rows.
1605
1652
  */
1606
1653
  export async function addEnumValues(enumName, values) {
1607
- const valueList = values
1654
+ // "code" or "code:Label". The label is what a user sees in the picker; the
1655
+ // code is what the row stores. Every working enum on a live tenant carries a
1656
+ // title, and a row inserted without one reads back title:null — an option
1657
+ // that shows up blank. This server used to insert {name, value} only, so
1658
+ // every enum it created had untitled options.
1659
+ const parsed = values
1608
1660
  .split(",")
1609
- .map((v) => v.trim())
1610
- .filter((v) => v);
1611
- if (valueList.length === 0) {
1612
- return jsonResponse({ error: "No values provided — pass a comma-separated list." });
1661
+ .map((raw) => raw.trim())
1662
+ .filter((raw) => raw)
1663
+ .map((raw) => {
1664
+ const sep = raw.indexOf(":");
1665
+ const value = (sep === -1 ? raw : raw.slice(0, sep)).trim();
1666
+ const title = (sep === -1 ? "" : raw.slice(sep + 1).trim()) || value;
1667
+ return { value, title };
1668
+ })
1669
+ .filter((v) => v.value);
1670
+ if (parsed.length === 0) {
1671
+ return jsonResponse({
1672
+ error: "No values provided — pass a comma-separated list, e.g. \"new,inProgress\" or " +
1673
+ '"new:New request,inProgress:In progress" to set the labels users see.',
1674
+ });
1613
1675
  }
1614
1676
  const existingRows = await searchEntity("Enums", [makeFilter("name", enumName)], { id: true, value: true }, 1000);
1615
1677
  const existing = new Set(existingRows
1616
1678
  .filter((r) => r !== null && typeof r === "object")
1617
1679
  .map((r) => String(r.value)));
1618
- const newValues = valueList.filter((v) => !existing.has(v));
1619
- const skipped = valueList.filter((v) => existing.has(v));
1680
+ const newValues = parsed.filter((v) => !existing.has(v.value));
1681
+ const skipped = parsed.filter((v) => existing.has(v.value)).map((v) => v.value);
1620
1682
  let result = [];
1621
1683
  if (newValues.length > 0) {
1622
1684
  // The /api/core/data-bulk/{entity} endpoint returns 201 but silently
1623
1685
  // persists nothing; the regular insert action actually stores the batch.
1624
- result = await insertEntity("Enums", newValues.map((v) => ({ name: enumName, value: v })));
1686
+ // `title` goes as a plain string: that is the shape the platform's own enum
1687
+ // rows read back as, while a localization object read back as raw JSON.
1688
+ result = await insertEntity("Enums", newValues.map((v, i) => ({
1689
+ name: enumName,
1690
+ value: v.value,
1691
+ title: v.title,
1692
+ order: existing.size + i,
1693
+ })));
1625
1694
  }
1626
1695
  return jsonResponse({
1627
- added: newValues,
1696
+ added: newValues.map((v) => v.value),
1697
+ titles: Object.fromEntries(newValues.map((v) => [v.value, v.title])),
1628
1698
  skipped_existing: skipped,
1629
1699
  result,
1630
1700
  });
@@ -1018,6 +1018,13 @@ const _NO_DEFAULT_VALUE_TYPES = new Set([
1018
1018
  "file",
1019
1019
  "multi-file",
1020
1020
  ]);
1021
+ // Where `notNull` does not apply — its own, narrower exclusion.
1022
+ // (api-entity-builder-builder.txt:41 — "notNull ... Not applicable to
1023
+ // many-to-many / multi-enum".) Mirrors NO_NOT_NULL_FIELD_TYPES in
1024
+ // tools/entity.ts, kept local for the same reason as the set above: entity.js is
1025
+ // module-mocked in the migrator's tests. notNullFieldTypesMatch.test.ts fails if
1026
+ // the two copies drift.
1027
+ const _NO_NOT_NULL_TYPES = new Set(["many-to-many", "multi-enum"]);
1021
1028
  const _DOWNGRADE_NOTE = "Some fields that are required in Suppa 1.0 were created NULLABLE here: the 2.0 " +
1022
1029
  "builder refuses NOT NULL without a defaultValue, and this migrator will not " +
1023
1030
  "invent one — the value empty rows should carry is a data decision, not a " +
@@ -1036,7 +1043,23 @@ function _requiredOpts(entity, f, downgrades) {
1036
1043
  if (!(f.required ?? false)) {
1037
1044
  return { required: false };
1038
1045
  }
1039
- if (_NO_DEFAULT_VALUE_TYPES.has(String(f.type ?? ""))) {
1046
+ const planType = String(f.type ?? "");
1047
+ // builder.txt:41 — notNull is "Not applicable to many-to-many / multi-enum".
1048
+ // The builder drops it there, so asking for it would report a constraint that
1049
+ // was never created; record the downgrade instead of claiming success.
1050
+ if (_NO_NOT_NULL_TYPES.has(planType)) {
1051
+ downgrades.push({
1052
+ entity,
1053
+ field: f.name,
1054
+ type: f.type ?? null,
1055
+ v1_required: true,
1056
+ created_as: "nullable",
1057
+ reason: `the 2.0 builder does not apply notNull to '${planType}' fields ` +
1058
+ '(builder.txt:41 — "Not applicable to many-to-many / multi-enum")',
1059
+ });
1060
+ return { required: false };
1061
+ }
1062
+ if (_NO_DEFAULT_VALUE_TYPES.has(planType)) {
1040
1063
  return { required: true }; // defaultValue does not apply — notNull needs none
1041
1064
  }
1042
1065
  // `default_value` is put on every planned field by _planFields (from the v1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "MCP server for the Suppa platform (modern.suppa.me) — Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments, with multi-tenant Google auth. Node port of PyPI suppa-mcp.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -159,7 +159,7 @@ Step 1 exists to catch exactly this: an unregistered class is E301 and the gate
159
159
 
160
160
  `validate-suppa-schema.mjs` exits `0` on a clean run, `1` when errors are found, `2` on a usage error or a missing path. The gate requires exit `0` — warnings alone do not block.
161
161
 
162
- The validator parses with the TypeScript compiler API, read from the app repo you point it at (a Suppa application compiles with `tsc`, so it has one). If it reports `cannot resolve 'typescript'`, run `npm install` in that repo — or `npm i -D typescript` if it genuinely has none.
162
+ The validator parses with the TypeScript compiler API, read from the app repo you point it at (a Suppa application compiles with `tsc`, so it has one). If it reports `cannot resolve 'typescript'`, run `npm install` in that repo — or `npm i -D typescript@5` if it genuinely has none. Pin the major: plain `typescript` now installs 7.x, whose main entry exports only version info and carries no compiler API.
163
163
 
164
164
  ## Troubleshooting
165
165
 
@@ -62,18 +62,39 @@ export function loadTypescript(rootDir) {
62
62
  if (rootDir) froms.push(join(resolve(rootDir), "package.json"));
63
63
  froms.push(join(process.cwd(), "package.json"));
64
64
  froms.push(import.meta.url);
65
+ let sawStub = false;
65
66
  for (const from of froms) {
67
+ let mod;
66
68
  try {
67
- return createRequire(from)("typescript");
69
+ mod = createRequire(from)("typescript");
68
70
  } catch {
69
- /* try next */
71
+ continue; // not resolvable from here — try the next candidate
70
72
  }
73
+ // Resolvability is NOT proof the compiler API is there. TypeScript 7 — what
74
+ // plain `npm i -D typescript` installs today — maps exports["."] to
75
+ // lib/version.cjs, which exports only { version, versionMajorMinor }; the
76
+ // parser moved behind ./unstable/*. That require SUCCEEDS and used to be
77
+ // handed straight to the parser, which then died on `ts.ScriptTarget.Latest`
78
+ // being undefined. Check the two members this validator actually uses, and
79
+ // keep looking: a usable TS 5 further down the list still rescues the run.
80
+ if (typeof mod?.createSourceFile === "function" && mod?.ScriptTarget) {
81
+ return mod;
82
+ }
83
+ sawStub = true;
71
84
  }
72
- throw new Error(
73
- "validate-suppa-schema: cannot resolve 'typescript'. It is read from the app repo " +
74
- "being validated (a Suppa application compiles with tsc, so it normally has it). " +
75
- "Install it there — `npm i -D typescript` — or run this from a directory where it resolves.",
76
- );
85
+ // Tagged so the CLI can report it as an environment problem — one actionable
86
+ // line and exit 2 — instead of an uncaught stack trace.
87
+ throw Object.assign(new Error(
88
+ sawStub
89
+ ? "validate-suppa-schema: the 'typescript' found here is TypeScript 7 (or newer), whose " +
90
+ "main entry exports only version info — it has no createSourceFile/ScriptTarget, so " +
91
+ "this validator cannot parse with it. Install the 5.x line in the app repo being " +
92
+ "validated: `npm i -D typescript@5`."
93
+ : "validate-suppa-schema: cannot resolve 'typescript'. It is read from the app repo " +
94
+ "being validated (a Suppa application compiles with tsc, so it normally has it). " +
95
+ "Install it there — `npm i -D typescript@5` — or run this from a directory where it " +
96
+ "resolves.",
97
+ ), { code: "SUPPA_VALIDATOR_ENV" });
77
98
  }
78
99
 
79
100
  /**
@@ -1240,7 +1261,17 @@ if (isMain) {
1240
1261
  }
1241
1262
  }
1242
1263
  const dedupedFiles = [...new Set(files)];
1243
- const res = validateSchema({ files: dedupedFiles, rootDir });
1264
+ let res;
1265
+ try {
1266
+ res = validateSchema({ files: dedupedFiles, rootDir });
1267
+ } catch (err) {
1268
+ // A missing/unusable toolchain is the caller's to fix: one actionable line,
1269
+ // same exit code as the other argument problems. Anything else is a bug in
1270
+ // this validator and keeps its stack trace.
1271
+ if (err?.code !== "SUPPA_VALIDATOR_ENV") throw err;
1272
+ console.error(err.message);
1273
+ process.exit(2);
1274
+ }
1244
1275
  for (const f of res.findings) {
1245
1276
  console.log(
1246
1277
  `${displayPath(process.cwd(), f.file)}:${f.line}:${f.col} ${f.code} [${f.level}] ${f.message}`,