suppa-mcp-2 1.2.4 → 1.3.1

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.
@@ -604,6 +604,11 @@ async function _planFields(props, entName, v2EntName, targetResolver, entIndex,
604
604
  title: ftitle,
605
605
  type: cls.v2Type,
606
606
  required,
607
+ // Builder Field Options (builder.txt:60, keys :66-73). Null = "send none",
608
+ // which is what 1.0 tells us: it has no equivalent metadata, so nothing is
609
+ // invented here. The key exists so an EDITED plan can carry them —
610
+ // {"searchable": true, "showInTable": true} — and _execute forwards it.
611
+ options: null,
607
612
  // The v1 default must travel with the planned field: _requiredOpts reads
608
613
  // `default_value` off the PLAN, so a plan that omits it downgrades every
609
614
  // required field to nullable and the notNull path is never taken.
@@ -637,6 +642,7 @@ async function _planFields(props, entName, v2EntName, targetResolver, entIndex,
637
642
  default_value: p.default_value ?? null,
638
643
  enum_name: _enumNameFor(v2EntName, v2Fname),
639
644
  values,
645
+ options: null, // see relation_fields above — builder.txt:60 / :66-73
640
646
  });
641
647
  continue;
642
648
  }
@@ -652,6 +658,7 @@ async function _planFields(props, entName, v2EntName, targetResolver, entIndex,
652
658
  max_length: cls.v2Type === "text" ? maxLength : null,
653
659
  decimal_places: cls.v2Type === "numeric" ? decimalPlaces : null,
654
660
  multilingual: cls.multilingual,
661
+ options: null, // see relation_fields above — builder.txt:60 / :66-73
655
662
  };
656
663
  if (cls.note) {
657
664
  field.note = cls.note;
@@ -1011,6 +1018,13 @@ const _NO_DEFAULT_VALUE_TYPES = new Set([
1011
1018
  "file",
1012
1019
  "multi-file",
1013
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"]);
1014
1028
  const _DOWNGRADE_NOTE = "Some fields that are required in Suppa 1.0 were created NULLABLE here: the 2.0 " +
1015
1029
  "builder refuses NOT NULL without a defaultValue, and this migrator will not " +
1016
1030
  "invent one — the value empty rows should carry is a data decision, not a " +
@@ -1029,7 +1043,23 @@ function _requiredOpts(entity, f, downgrades) {
1029
1043
  if (!(f.required ?? false)) {
1030
1044
  return { required: false };
1031
1045
  }
1032
- 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)) {
1033
1063
  return { required: true }; // defaultValue does not apply — notNull needs none
1034
1064
  }
1035
1065
  // `default_value` is put on every planned field by _planFields (from the v1
@@ -1097,6 +1127,7 @@ export async function _execute(plan, mode = "create") {
1097
1127
  subType: f.sub_type ?? null,
1098
1128
  maxLength: f.max_length ?? null,
1099
1129
  decimalPlaces: f.decimal_places ?? null,
1130
+ options: f.options ?? null, // builder.txt:60 — plan-carried Field Options
1100
1131
  }));
1101
1132
  step.entity = name;
1102
1133
  details.push(step);
@@ -1122,6 +1153,7 @@ export async function _execute(plan, mode = "create") {
1122
1153
  const step = await _runWrite(`add_enum_field:${f.name}`, () => entityTools.addField(name, f.name, f.type ?? "enum", f.title, {
1123
1154
  ..._requiredOpts(name, { ...f, type: f.type ?? "enum" }, requiredDowngrades),
1124
1155
  enumName: f.enum_name,
1156
+ options: f.options ?? null, // builder.txt:60
1125
1157
  }));
1126
1158
  step.entity = name;
1127
1159
  details.push(step);
@@ -1148,6 +1180,7 @@ export async function _execute(plan, mode = "create") {
1148
1180
  subType: f.sub_type ?? null,
1149
1181
  maxLength: f.max_length ?? null,
1150
1182
  decimalPlaces: f.decimal_places ?? null,
1183
+ options: f.options ?? null, // builder.txt:60
1151
1184
  }));
1152
1185
  step.entity = tpName;
1153
1186
  details.push(step);
@@ -1168,6 +1201,7 @@ export async function _execute(plan, mode = "create") {
1168
1201
  const step = await _runWrite(`add_enum_field:${f.name}`, () => entityTools.addField(tpName, f.name, f.type ?? "enum", f.title, {
1169
1202
  ..._requiredOpts(tpName, { ...f, type: f.type ?? "enum" }, requiredDowngrades),
1170
1203
  enumName: f.enum_name,
1204
+ options: f.options ?? null, // builder.txt:60
1171
1205
  }));
1172
1206
  step.entity = tpName;
1173
1207
  details.push(step);
@@ -1212,6 +1246,7 @@ export async function _execute(plan, mode = "create") {
1212
1246
  const step = await _runWrite(`add_relation:${f.name}`, () => entityTools.addField(name, f.name, f.type, f.title, {
1213
1247
  ..._requiredOpts(name, f, requiredDowngrades),
1214
1248
  relationEntity: f.relation_entity,
1249
+ options: f.options ?? null, // builder.txt:60
1215
1250
  }));
1216
1251
  step.entity = name;
1217
1252
  details.push(step);
@@ -1250,6 +1285,7 @@ export async function _execute(plan, mode = "create") {
1250
1285
  const step = await _runWrite(`add_relation:${f.name}`, () => entityTools.addField(tp.name, f.name, f.type, f.title, {
1251
1286
  ..._requiredOpts(tp.name, f, requiredDowngrades),
1252
1287
  relationEntity: f.relation_entity,
1288
+ options: f.options ?? null, // builder.txt:60
1253
1289
  }));
1254
1290
  step.entity = tp.name;
1255
1291
  details.push(step);
package/dist/utils.js CHANGED
@@ -9,6 +9,117 @@ import { extname, basename } from "node:path";
9
9
  export function makeFilter(field, value, comparator = "=") {
10
10
  return { field, value, comparator };
11
11
  }
12
+ // ---------------------------------------------------------------------------
13
+ // Conditions: flat filters AND nested groups
14
+ //
15
+ // Shared objects, captures/api-entity-builder-data.txt:33-42 —
16
+ // Condition: operator (string, required, "and or or", :35)
17
+ // filters (object[], required, "Filters, or NESTED CONDITION
18
+ // OBJECTS", :36)
19
+ // Filter: field (string, required, "Field path, e.g. owner.id", :39)
20
+ // comparator (string, required, :40)
21
+ // value (any, required, :41)
22
+ // function (string, optional, "Field function", :42)
23
+ //
24
+ // Because a Condition's `filters` may hold Conditions, an expression like
25
+ // (status=open AND owner=me) OR priority=high is one payload:
26
+ // {"operator": "or", "filters": [
27
+ // {"operator": "and", "filters": [
28
+ // {"field": "status.value", "value": "open", "comparator": "="},
29
+ // {"field": "owner.id", "value": "$current-user", "comparator": "="}]},
30
+ // {"field": "priority.value", "value": "high", "comparator": "="}]}
31
+ // ---------------------------------------------------------------------------
32
+ /** data.txt:35 — the only two condition operators. */
33
+ export const CONDITION_OPERATORS = ["and", "or"];
34
+ /** Comparators that stand alone — the platform ignores any value sent with them. */
35
+ const VALUELESS_COMPARATORS = new Set(["is null", "is not null", "isnull", "isnotnull"]);
36
+ /** Build a nested condition group (data.txt:33-36). */
37
+ export function makeCondition(operator, nodes) {
38
+ return normalizeConditionNode({ operator, filters: nodes }, "condition");
39
+ }
40
+ /** True for a node that is a group rather than a leaf filter. */
41
+ export function isConditionNode(node) {
42
+ return (node !== null &&
43
+ typeof node === "object" &&
44
+ !Array.isArray(node) &&
45
+ "operator" in node);
46
+ }
47
+ function isPlainObj(v) {
48
+ return v !== null && typeof v === "object" && !Array.isArray(v);
49
+ }
50
+ /**
51
+ * Validate + normalize ONE node: either a flat filter or a nested condition
52
+ * group. Flat "f=v" filters (what makeFilter produces, used across the tasks /
53
+ * docs / forms tools) pass through with their keys unchanged — this only adds
54
+ * the nested case and refuses shapes the platform would silently mis-read.
55
+ *
56
+ * Accepts the documented group shape {"operator": "or", "filters": [...]} and
57
+ * the shorthand {"or": [...]} / {"and": [...]}, which normalizes to it.
58
+ */
59
+ export function normalizeConditionNode(node, path = "filters_json") {
60
+ if (!isPlainObj(node)) {
61
+ throw new Error(`${path} must be a filter object {"field", "value", "comparator"} or a ` +
62
+ `condition group {"operator": "and"|"or", "filters": [...]} — got ${typeName(node)}.`);
63
+ }
64
+ // Shorthand: {"or": [...]} / {"and": [...]}.
65
+ for (const op of CONDITION_OPERATORS) {
66
+ if (op in node && !("operator" in node)) {
67
+ return normalizeConditionNode({ operator: op, filters: node[op] }, path);
68
+ }
69
+ }
70
+ if ("operator" in node || "filters" in node) {
71
+ const rawOp = node.operator;
72
+ const operator = typeof rawOp === "string" ? rawOp.trim().toLowerCase() : "";
73
+ if (!CONDITION_OPERATORS.includes(operator)) {
74
+ throw new Error(`${path}: a condition group needs "operator": "and" or "or" ` +
75
+ `(data.txt:35) — got ${JSON.stringify(rawOp ?? null)}.`);
76
+ }
77
+ const rawFilters = node.filters;
78
+ if (!Array.isArray(rawFilters)) {
79
+ throw new Error(`${path}: a condition group needs "filters": [...] — an array of filters ` +
80
+ "or nested groups (data.txt:36).");
81
+ }
82
+ return {
83
+ operator: operator,
84
+ filters: rawFilters.map((child, i) => normalizeConditionNode(child, `${path}[${i}]`)),
85
+ };
86
+ }
87
+ // Leaf filter.
88
+ const field = node.field;
89
+ if (typeof field !== "string" || !field.trim()) {
90
+ throw new Error(`${path}: a filter needs "field" — a field name or dotted path such as ` +
91
+ '"owner.id" (data.txt:39). Nested groups instead need "operator" + "filters".');
92
+ }
93
+ const rawCmp = node.comparator;
94
+ if (rawCmp !== undefined && rawCmp !== null && typeof rawCmp !== "string") {
95
+ throw new Error(`${path}: "comparator" must be a string (data.txt:40).`);
96
+ }
97
+ const comparator = (rawCmp ?? "=").trim() || "=";
98
+ if (!("value" in node) && !VALUELESS_COMPARATORS.has(comparator.toLowerCase())) {
99
+ throw new Error(`${path}: a filter needs "value" (data.txt:41) — only 'is null' / ` +
100
+ "'is not null' may omit it.");
101
+ }
102
+ const out = {
103
+ field: field.trim(),
104
+ value: "value" in node ? node.value : null,
105
+ comparator,
106
+ };
107
+ if (typeof node.function === "string" && node.function.trim()) {
108
+ out.function = node.function.trim(); // data.txt:42 — optional field function
109
+ }
110
+ return out;
111
+ }
112
+ /**
113
+ * Normalize a list of filters/groups (the `filters` of the top-level Condition).
114
+ * A single object is tolerated as a one-element list, as before.
115
+ */
116
+ export function normalizeConditionNodes(nodes, path = "filters_json") {
117
+ if (nodes === null || nodes === undefined) {
118
+ return [];
119
+ }
120
+ const list = Array.isArray(nodes) ? nodes : [nodes];
121
+ return list.map((n, i) => normalizeConditionNode(n, `${path}[${i}]`));
122
+ }
12
123
  /**
13
124
  * Parse human-friendly deadline strings into ISO datetime.
14
125
  *
@@ -464,13 +575,15 @@ export function confirmRequired(action, target, proposedChanges) {
464
575
  "with confirm=true." +
465
576
  (isDelete
466
577
  ? " Semantics: this is a SOFT delete — it sets deletedAt, the row remains " +
467
- "in the database and the delete is reversible (restore in the Suppa UI; " +
468
- "this server has no restore tool yet). It is NOT a permanent purge, but " +
469
- "the record does disappear from every normal read."
578
+ "in the database and the delete is reversible with suppa_restore_record " +
579
+ "(find the row again with deleted_scope='deleted'). It is NOT the platform's " +
580
+ "permanent delete, which this server does not expose, but the record does " +
581
+ "disappear from every normal read."
470
582
  : ""),
471
583
  };
472
584
  if (isDelete) {
473
- body.delete_semantics = "soft — sets deletedAt, row remains, reversible";
585
+ body.delete_semantics =
586
+ "soft — sets deletedAt, row remains, reversible via suppa_restore_record";
474
587
  }
475
588
  if (proposedChanges !== undefined) {
476
589
  body.proposed_changes = proposedChanges;
package/package.json CHANGED
@@ -1,12 +1,21 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.2.4",
3
+ "version": "1.3.1",
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
- "bin": { "suppa-mcp": "dist/bin.js" },
6
+ "bin": {
7
+ "suppa-mcp": "dist/bin.js"
8
+ },
7
9
  "main": "dist/bin.js",
8
- "files": ["dist", "skills", "README.md", "LICENSE"],
9
- "engines": { "node": ">=18" },
10
+ "files": [
11
+ "dist",
12
+ "skills",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "engines": {
17
+ "node": ">=18"
18
+ },
10
19
  "scripts": {
11
20
  "build": "tsc",
12
21
  "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
@@ -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}`,