suppa-mcp-2 1.36.0 → 1.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.js +31 -5
- package/dist/tools/customFields.js +181 -19
- package/dist/tools/entity.js +112 -5
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -162,6 +162,26 @@ const BlocksJson = z
|
|
|
162
162
|
const EntityName = z
|
|
163
163
|
.string()
|
|
164
164
|
.describe("Exact entity name, e.g. 'Tasks' — discover via suppa_list_entities.");
|
|
165
|
+
/**
|
|
166
|
+
* A field label: a plain string, or the LOCALIZATION OBJECT the builder doc
|
|
167
|
+
* prescribes (`title | object | Localization object`, builder.txt:56).
|
|
168
|
+
*
|
|
169
|
+
* It was typed `string` here while buildFieldDef had accepted either for two
|
|
170
|
+
* releases, so the documented shape was rejected by input validation before it
|
|
171
|
+
* could reach the platform at all — `{ en, uk }` came back as "Expected string,
|
|
172
|
+
* received object" and never left this process.
|
|
173
|
+
*/
|
|
174
|
+
const FieldTitle = z
|
|
175
|
+
.union([z.string(), z.record(z.string())])
|
|
176
|
+
// OPTIONAL, not nullable: a two-branch union plus a null branch is an `anyOf`
|
|
177
|
+
// the listing's compaction cannot collapse into a type list (the object
|
|
178
|
+
// branch carries additionalProperties, which a type list cannot say), and
|
|
179
|
+
// toolsListEconomy refuses a nullable spelled as anyOf. Omitting the
|
|
180
|
+
// parameter and passing null mean the same thing downstream — buildFieldDef
|
|
181
|
+
// tests for both — so the null branch bought nothing and cost the collapse.
|
|
182
|
+
.optional()
|
|
183
|
+
.describe('Label users see: "Budget", or {"en": "Budget", "uk": "Бюджет"}. Omitted: no title, and ' +
|
|
184
|
+
"none is invented from the name.");
|
|
165
185
|
// Entity Options (captures/api-entity-builder-builder.txt:74-90) — the platform's
|
|
166
186
|
// 15 per-entity features, plus customFields (newer than that capture, verified live). The TIP at :91-92 is quoted in full: enabling one is a
|
|
167
187
|
// schema change (it creates the backing side table), not a preference toggle.
|
|
@@ -1134,7 +1154,7 @@ export function buildServer() {
|
|
|
1134
1154
|
field_type: z
|
|
1135
1155
|
.string()
|
|
1136
1156
|
.describe("A real Suppa 2.0 type (see suppa_list_field_types). NO date/richtext/email type exists — use 'timestamp' (+sub_type='date') or 'multi-language'. 'one-to-many' is refused — use suppa_create_tabular_part for owned children, 'many-to-many' for shared lookups."),
|
|
1137
|
-
title:
|
|
1157
|
+
title: FieldTitle,
|
|
1138
1158
|
required: z.boolean().default(false),
|
|
1139
1159
|
default_value: z
|
|
1140
1160
|
.string()
|
|
@@ -1429,9 +1449,9 @@ export function buildServer() {
|
|
|
1429
1449
|
" Needs context_field + context_value (the set for that context is created if it has\n" +
|
|
1430
1450
|
" none) or set_ids — a custom field belonging to neither is refused. The entity needs\n" +
|
|
1431
1451
|
" options.customFields on (suppa_update_entity_options).\n" +
|
|
1432
|
-
" Types, sub_type and options are suppa_add_field's.
|
|
1433
|
-
"
|
|
1434
|
-
"
|
|
1452
|
+
" Types, sub_type and options are suppa_add_field's. required=true marks it mandatory in\n" +
|
|
1453
|
+
" THIS context (its CustomFieldSetFields row), binding when the values row is written;\n" +
|
|
1454
|
+
" column-level notNull is a different thing this build cannot create.\n" +
|
|
1435
1455
|
" Enum values come after: suppa_add_enum_values(entity_name='<Entity>CustomFields',\n" +
|
|
1436
1456
|
" field_name='<field>') — both, or it cannot read the group off the field.",
|
|
1437
1457
|
inputSchema: {
|
|
@@ -1441,7 +1461,7 @@ export function buildServer() {
|
|
|
1441
1461
|
.describe("camelCase, letters/numbers/underscores, 1-50 — and the English MEANING of the title, " +
|
|
1442
1462
|
"never the title in Latin letters (opysPrychyny is refused; reasonDescription is the name)."),
|
|
1443
1463
|
field_type: z.string().describe("As suppa_add_field (see suppa_list_field_types)."),
|
|
1444
|
-
title:
|
|
1464
|
+
title: FieldTitle,
|
|
1445
1465
|
context_field: z
|
|
1446
1466
|
.string()
|
|
1447
1467
|
.nullable()
|
|
@@ -1457,6 +1477,11 @@ export function buildServer() {
|
|
|
1457
1477
|
.nullable()
|
|
1458
1478
|
.default(null)
|
|
1459
1479
|
.describe("Existing CustomFieldSets ids, instead of a context."),
|
|
1480
|
+
required: z
|
|
1481
|
+
.boolean()
|
|
1482
|
+
.default(false)
|
|
1483
|
+
.describe("Mandatory in THIS context — set on the field's CustomFieldSetFields row. An insert " +
|
|
1484
|
+
"naming it null is refused; one with no customFields key still passes."),
|
|
1460
1485
|
relation_entity: z.string().nullable().default(null),
|
|
1461
1486
|
options_json: z.string().nullable().default(null),
|
|
1462
1487
|
sub_type: z.string().nullable().default(null),
|
|
@@ -1469,6 +1494,7 @@ export function buildServer() {
|
|
|
1469
1494
|
contextField: a.context_field,
|
|
1470
1495
|
contextValue: a.context_value,
|
|
1471
1496
|
setIds: a.set_ids,
|
|
1497
|
+
required: a.required,
|
|
1472
1498
|
relationEntity: a.relation_entity,
|
|
1473
1499
|
options: a.options_json,
|
|
1474
1500
|
subType: a.sub_type,
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
* field mandatory is `required` on the CustomFieldSetFields link row, which
|
|
43
43
|
* the platform enforces when the values row is created.
|
|
44
44
|
*/
|
|
45
|
-
import { makeRequest, searchEntity } from "../httpClient.js";
|
|
45
|
+
import { makeRequest, searchEntity, updateEntity } from "../httpClient.js";
|
|
46
46
|
import { customFieldsHint } from "../customFieldHints.js";
|
|
47
|
-
import { jsonResponse, confirmRequired } from "../utils.js";
|
|
47
|
+
import { jsonResponse, confirmRequired, makeFilter } from "../utils.js";
|
|
48
48
|
import { buildFieldDef, CUSTOM_FIELDS_EXTENSION_SUFFIX, CUSTOM_FIELDS_KEY, CUSTOM_FIELDS_OPTION, } from "./entity.js";
|
|
49
49
|
/**
|
|
50
50
|
* Re-exported from ./entity.ts, where the option lives beside the rest of the
|
|
@@ -173,12 +173,76 @@ export async function resolveCustomFields(entityName, recordId = null, contextFi
|
|
|
173
173
|
}
|
|
174
174
|
try {
|
|
175
175
|
const result = await makeRequest("POST", `/api/core/custom-fields/${entityName}/resolve`, body);
|
|
176
|
-
return jsonResponse(result);
|
|
176
|
+
return jsonResponse(await _withFieldTypes(entityName, result));
|
|
177
177
|
}
|
|
178
178
|
catch (e) {
|
|
179
179
|
return errorResponse(e);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
+
function _isObj(v) {
|
|
183
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The platform's /resolve answer with each field's TYPE joined on.
|
|
187
|
+
*
|
|
188
|
+
* /resolve says which custom fields a record may carry and nothing about what
|
|
189
|
+
* may be written into them — no type, no subType. A caller that follows this
|
|
190
|
+
* tool (every refusal in this server points at it) therefore sends a string
|
|
191
|
+
* into a numeric field and gets back "A value has an invalid format for type
|
|
192
|
+
* numeric", which does not even name the field. The entity schema carries the
|
|
193
|
+
* type in its own `customFields` array, keyed by the same field id.
|
|
194
|
+
*
|
|
195
|
+
* Best-effort, like every other join here: an unreadable schema, or an answer
|
|
196
|
+
* that is not the documented shape, returns the platform's response untouched.
|
|
197
|
+
*/
|
|
198
|
+
async function _withFieldTypes(entityName, result) {
|
|
199
|
+
if (!_isObj(result) || !Array.isArray(result.fields)) {
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
let defs;
|
|
203
|
+
try {
|
|
204
|
+
const schema = await makeRequest("GET", `/api/core/schema/${entityName}`);
|
|
205
|
+
const raw = _isObj(schema) ? schema[CUSTOM_FIELDS_KEY] : null;
|
|
206
|
+
if (!Array.isArray(raw)) {
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
defs = raw.filter(_isObj);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
const byId = new Map();
|
|
215
|
+
const byName = new Map();
|
|
216
|
+
for (const d of defs) {
|
|
217
|
+
const id = Number(d.id);
|
|
218
|
+
if (Number.isFinite(id)) {
|
|
219
|
+
byId.set(id, d);
|
|
220
|
+
}
|
|
221
|
+
if (typeof d.name === "string") {
|
|
222
|
+
byName.set(d.name, d);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const fields = result.fields.map((f) => {
|
|
226
|
+
if (!_isObj(f)) {
|
|
227
|
+
return f;
|
|
228
|
+
}
|
|
229
|
+
// By id first: a field renamed between the two reads still matches.
|
|
230
|
+
const def = byId.get(Number(f.fieldId)) ?? byName.get(String(f.fieldName ?? ""));
|
|
231
|
+
if (!def) {
|
|
232
|
+
return f;
|
|
233
|
+
}
|
|
234
|
+
const out = { ...f };
|
|
235
|
+
if (typeof def.type === "string") {
|
|
236
|
+
out.type = def.type;
|
|
237
|
+
}
|
|
238
|
+
// An enum or relation needs its group/target as much as its type.
|
|
239
|
+
if (typeof def.subType === "string") {
|
|
240
|
+
out.subType = def.subType;
|
|
241
|
+
}
|
|
242
|
+
return out;
|
|
243
|
+
});
|
|
244
|
+
return { ...result, fields };
|
|
245
|
+
}
|
|
182
246
|
/**
|
|
183
247
|
* Create a custom field on `entityName` and put it in a set.
|
|
184
248
|
*
|
|
@@ -235,22 +299,23 @@ export async function addCustomField(entityName, fieldName, fieldType, title, op
|
|
|
235
299
|
"ways to name the same thing and the builder reads only one of them. Nothing was sent.",
|
|
236
300
|
});
|
|
237
301
|
}
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
302
|
+
// `required` is NOT notNull. Column-level notNull is refused by this build
|
|
303
|
+
// (without a default the builder answers "`defaultValue` is required when
|
|
304
|
+
// creating a field with `notNull: true`"; with one it answers "Field x is not
|
|
305
|
+
// available for this record's context", even for a context holding no values).
|
|
306
|
+
// Per-CONTEXT obligation is a different mechanism and it works: it lives on
|
|
307
|
+
// the CustomFieldSetFields link row, resolve reports it, and the platform
|
|
308
|
+
// enforces it when the values row is created — an insert naming the field as
|
|
309
|
+
// null is refused with "is required for this record's context" (verified on
|
|
310
|
+
// dev 2026-09-15, traceId 70caccc643d55bdf3f021331510c1c89).
|
|
311
|
+
//
|
|
312
|
+
// This used to be a refusal telling the caller to go and set that row by
|
|
313
|
+
// hand — and the refusal was unreachable, because the tool exposed no
|
|
314
|
+
// `required` parameter at all and `options_json` rejects notNull as an
|
|
315
|
+
// unknown option. So a caller who asked for a mandatory field got an optional
|
|
316
|
+
// one and no warning. Do the two steps instead of describing them.
|
|
317
|
+
const wantRequired = Boolean(fieldOpts.required);
|
|
318
|
+
delete fieldOpts.required; // never forwarded to the builder as notNull
|
|
254
319
|
// An enum custom field is bound through relationTarget, exactly like a normal
|
|
255
320
|
// one; the tenant convention (every enum field already on the tenant) is the
|
|
256
321
|
// qualified '<ExtensionEntity>.<field>' name, and the variants are ordinary
|
|
@@ -290,6 +355,8 @@ export async function addCustomField(entityName, fieldName, fieldType, title, op
|
|
|
290
355
|
return errorResponse(e, { sent: { customFields: envelope } });
|
|
291
356
|
}
|
|
292
357
|
const out = { result };
|
|
358
|
+
if (wantRequired)
|
|
359
|
+
out.required = await _markRequiredInSets(entityName, fieldName, result);
|
|
293
360
|
if (usage)
|
|
294
361
|
Object.assign(out, quotaNote(usage, 1));
|
|
295
362
|
if (built.notApplicable && built.notApplicable.length > 0) {
|
|
@@ -336,6 +403,101 @@ export async function addCustomField(entityName, fieldName, fieldType, title, op
|
|
|
336
403
|
`{"${fieldName}": <value>}}')`;
|
|
337
404
|
return jsonResponse(out);
|
|
338
405
|
}
|
|
406
|
+
/**
|
|
407
|
+
* Turn on per-context obligation for a custom field that was just created.
|
|
408
|
+
*
|
|
409
|
+
* `required` is a property of the LINK between a field and a set
|
|
410
|
+
* (`CustomFieldSetFields`), not of the column — one field can be mandatory in
|
|
411
|
+
* one context and optional in another, which is the whole point of sets. The
|
|
412
|
+
* builder has no way to set it, so this is a second call by design.
|
|
413
|
+
*
|
|
414
|
+
* NEVER turns a successful creation into a failure: the field exists either
|
|
415
|
+
* way, and the caller has to be told exactly which half happened rather than
|
|
416
|
+
* being handed an error for a column that is sitting on the tenant.
|
|
417
|
+
*/
|
|
418
|
+
async function _markRequiredInSets(entityName, fieldName, result) {
|
|
419
|
+
const manual = `suppa_search_records("CustomFieldSetFields", filters on field.name="${fieldName}") to find ` +
|
|
420
|
+
'the link row, then suppa_update_record on it with {"required": true}.';
|
|
421
|
+
const created = result?.[CUSTOM_FIELDS_KEY];
|
|
422
|
+
const fieldId = Array.isArray(created)
|
|
423
|
+
? created.find((f) => f?.name === fieldName)?.id
|
|
424
|
+
: undefined;
|
|
425
|
+
if (typeof fieldId !== "number") {
|
|
426
|
+
return {
|
|
427
|
+
applied: false,
|
|
428
|
+
field_is_optional: true,
|
|
429
|
+
reason: "the builder's answer carried no id for this field, so its set link could not be found",
|
|
430
|
+
do_this: manual,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
// PAGED, not capped: a fixed page left every link past it optional while the
|
|
434
|
+
// answer still said applied: true — the wrong result, quietly, which is the
|
|
435
|
+
// failure this whole helper exists to avoid.
|
|
436
|
+
const ids = [];
|
|
437
|
+
try {
|
|
438
|
+
const PAGE = 200;
|
|
439
|
+
const seen = new Set();
|
|
440
|
+
for (let offset = 0;; offset += PAGE) {
|
|
441
|
+
const page = await searchEntity("CustomFieldSetFields", [makeFilter("field.id", fieldId)], { id: true, set: { id: true } }, PAGE, offset);
|
|
442
|
+
let fresh = 0;
|
|
443
|
+
for (const row of page) {
|
|
444
|
+
const id = row?.id;
|
|
445
|
+
if (typeof id !== "number" || seen.has(id)) {
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
seen.add(id);
|
|
449
|
+
ids.push(id);
|
|
450
|
+
fresh++;
|
|
451
|
+
}
|
|
452
|
+
// A short page is the last one; no new ids is the backstop for a server
|
|
453
|
+
// that ignores offset, which would otherwise page forever.
|
|
454
|
+
if (page.length < PAGE || fresh === 0) {
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
catch (e) {
|
|
460
|
+
return {
|
|
461
|
+
applied: false,
|
|
462
|
+
field_is_optional: true,
|
|
463
|
+
reason: `the field was created, but its set links could not be read: ${e instanceof Error ? e.message : String(e)}`,
|
|
464
|
+
do_this: manual,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
if (ids.length === 0) {
|
|
468
|
+
return {
|
|
469
|
+
applied: false,
|
|
470
|
+
field_is_optional: true,
|
|
471
|
+
reason: "the field was created but is linked to no set, so there is no context to be required in",
|
|
472
|
+
do_this: manual,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
const done = [];
|
|
476
|
+
const failed = {};
|
|
477
|
+
for (const id of ids) {
|
|
478
|
+
try {
|
|
479
|
+
await updateEntity("CustomFieldSetFields", id, { required: true });
|
|
480
|
+
done.push(id);
|
|
481
|
+
}
|
|
482
|
+
catch (e) {
|
|
483
|
+
failed[String(id)] = e instanceof Error ? e.message : String(e);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return {
|
|
487
|
+
applied: done.length > 0 && Object.keys(failed).length === 0,
|
|
488
|
+
link_rows_marked: done,
|
|
489
|
+
...(Object.keys(failed).length > 0 ? { link_rows_that_failed: failed, do_this: manual } : {}),
|
|
490
|
+
// Obligation binds when the values row is created, not on every insert —
|
|
491
|
+
// an insert that never mentions customFields at all still passes (verified
|
|
492
|
+
// on dev 2026-09-15: record 120 went in with no customFields key).
|
|
493
|
+
means: `'${fieldName}' is now mandatory in this context: an insert or update that names it as ` +
|
|
494
|
+
`null is refused with "is required for this record's context". An insert that carries no ` +
|
|
495
|
+
`customFields key at all still passes — the obligation binds when the values row is written.`,
|
|
496
|
+
undo: `suppa_update_record("CustomFieldSetFields", <link row id>, '{"required": false}') — the ` +
|
|
497
|
+
`rows are listed above. suppa_resolve_custom_fields("${entityName}", …) shows each field's ` +
|
|
498
|
+
`current required flag.`,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
339
501
|
// ---------------------------------------------------------------------------
|
|
340
502
|
// Remove / restore
|
|
341
503
|
// ---------------------------------------------------------------------------
|
package/dist/tools/entity.js
CHANGED
|
@@ -1780,11 +1780,50 @@ export async function buildFieldDef(entityName, fieldName, fieldType, title, opt
|
|
|
1780
1780
|
* 'encrypted', enum/multi-enum have it set by the platform, and no other type
|
|
1781
1781
|
* takes one.
|
|
1782
1782
|
*/
|
|
1783
|
+
/**
|
|
1784
|
+
* The entity's custom field of this name, or null.
|
|
1785
|
+
*
|
|
1786
|
+
* Best-effort: an unreadable schema answers null, because a failed lookup is
|
|
1787
|
+
* not evidence of a clash and must not block a legitimate migration.
|
|
1788
|
+
*/
|
|
1789
|
+
async function _customFieldNamed(entityName, fieldName) {
|
|
1790
|
+
try {
|
|
1791
|
+
const schema = await makeRequest("GET", `/api/core/schema/${entityName}`);
|
|
1792
|
+
return _extractCustomFields(schema).find((f) => f.name === fieldName) ?? null;
|
|
1793
|
+
}
|
|
1794
|
+
catch {
|
|
1795
|
+
return null;
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1783
1798
|
export async function addField(entityName, fieldName, fieldType, title, opts = {}) {
|
|
1784
1799
|
const built = await buildFieldDef(entityName, fieldName, fieldType, title, opts);
|
|
1785
1800
|
if (built.error) {
|
|
1786
1801
|
return built.error;
|
|
1787
1802
|
}
|
|
1803
|
+
// A custom field of the same name is NOT a collision the platform stops:
|
|
1804
|
+
// custom values live in <Entity>CustomFields, so this call would add a
|
|
1805
|
+
// SECOND, ordinary column of that name on the owner and the entity would
|
|
1806
|
+
// carry two different fields under one name, bound to different values.
|
|
1807
|
+
// _enumNameFromField already refuses to guess between such a pair; refusing
|
|
1808
|
+
// to CREATE the pair is the same rule, one step earlier — and the migration
|
|
1809
|
+
// this call runs cannot be taken back by removing the field afterwards.
|
|
1810
|
+
//
|
|
1811
|
+
// AFTER buildFieldDef, never before: every refusal this server can make from
|
|
1812
|
+
// the arguments alone still costs zero requests.
|
|
1813
|
+
const clash = await _customFieldNamed(entityName, fieldName);
|
|
1814
|
+
if (clash) {
|
|
1815
|
+
return jsonResponse({
|
|
1816
|
+
error: `Refused: '${entityName}' already has a CUSTOM field called '${fieldName}'` +
|
|
1817
|
+
`${clash.type ? ` (type ${String(clash.type)})` : ""}. This call would create a ` +
|
|
1818
|
+
`SECOND field of that name — an ordinary column on '${entityName}', beside the ` +
|
|
1819
|
+
`custom one in '${entityName}${CUSTOM_FIELDS_EXTENSION_SUFFIX}' — and the entity ` +
|
|
1820
|
+
"would then carry two different fields under one name. Nothing was sent.",
|
|
1821
|
+
write_the_custom_one: `suppa_update_record("${entityName}", <record id>, fields_json='{"${CUSTOM_FIELDS_KEY}": ` +
|
|
1822
|
+
`{"${fieldName}": <value>}}')`,
|
|
1823
|
+
see_where_it_is_live: `suppa_resolve_custom_fields("${entityName}", record_id=<record id>)`,
|
|
1824
|
+
really_want_a_separate_column: "Pick a different field_name.",
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1788
1827
|
// Correct endpoint is /builder/{Entity}/add-fields and the body is the bare
|
|
1789
1828
|
// array of field defs (the old /builder/add-fields with an {entityName,fields}
|
|
1790
1829
|
// wrapper 404s).
|
|
@@ -2788,12 +2827,48 @@ async function _validateRecordWrites(entityName, records) {
|
|
|
2788
2827
|
Object.keys(r).filter((k) => !fieldNames.has(k) && k !== CUSTOM_FIELDS_KEY))),
|
|
2789
2828
|
];
|
|
2790
2829
|
if (unknown.length > 0) {
|
|
2830
|
+
// A name that IS a custom field of this entity is not unknown — it is in
|
|
2831
|
+
// the wrong PLACE. This gate used to call it non-existent and point at
|
|
2832
|
+
// suppa_add_field, which would have created a SECOND, ordinary column of
|
|
2833
|
+
// the same name: a migration on the tenant, to fix a shape mistake.
|
|
2834
|
+
const customNames = new Set(customDefs.map((f) => f.name).filter((n) => Boolean(n)));
|
|
2835
|
+
const misplaced = unknown.filter((n) => customNames.has(n));
|
|
2836
|
+
const absent = unknown.filter((n) => !customNames.has(n));
|
|
2837
|
+
const parts = [];
|
|
2838
|
+
const detail = {};
|
|
2839
|
+
if (misplaced.length > 0) {
|
|
2840
|
+
parts.push(`field(s) [${misplaced.join(", ")}] are CUSTOM fields of '${entityName}', and a ` +
|
|
2841
|
+
"custom field is not addressable as a top-level key — the platform drops it in " +
|
|
2842
|
+
`silence. Nest them under "${CUSTOM_FIELDS_KEY}": corrected_fields_json is this ` +
|
|
2843
|
+
"same write, fixed. Do NOT add them with suppa_add_field — that creates a " +
|
|
2844
|
+
"SECOND, ordinary column of the same name on the tenant. custom_fields_on_entity " +
|
|
2845
|
+
"lists them ALL; which are live on a given record depends on its context — " +
|
|
2846
|
+
"suppa_resolve_custom_fields answers that.");
|
|
2847
|
+
detail.custom_fields_at_top_level = misplaced;
|
|
2848
|
+
const offender = records.find((r) => misplaced.some((n) => n in r)) ?? records[0];
|
|
2849
|
+
const fixed = _nestCustomKeys(offender, misplaced);
|
|
2850
|
+
detail.corrected_fields_json = jsonResponse(fixed.fields);
|
|
2851
|
+
if (many) {
|
|
2852
|
+
detail.corrected_from_record_index = records.indexOf(offender);
|
|
2853
|
+
}
|
|
2854
|
+
if (fixed.conflicts.length > 0) {
|
|
2855
|
+
detail.conflict_note =
|
|
2856
|
+
`[${fixed.conflicts.join(", ")}] were written BOTH at the top level and under ` +
|
|
2857
|
+
`"${CUSTOM_FIELDS_KEY}". corrected_fields_json keeps the NESTED value; if the ` +
|
|
2858
|
+
"top-level one was meant, replace it there.";
|
|
2859
|
+
}
|
|
2860
|
+
detail.custom_fields_on_entity = [...customNames].sort();
|
|
2861
|
+
}
|
|
2862
|
+
if (absent.length > 0) {
|
|
2863
|
+
parts.push(`field(s) [${absent.join(", ")}] do not exist on '${entityName}'. The platform ` +
|
|
2864
|
+
"silently drops unknown keys, so this would create a record missing that data " +
|
|
2865
|
+
"(a 'broken' entity). Use only real fields (see valid_fields), or add the " +
|
|
2866
|
+
"field first with suppa_add_field.");
|
|
2867
|
+
detail.unknown_fields = absent;
|
|
2868
|
+
}
|
|
2791
2869
|
const body = {
|
|
2792
|
-
error: `Refused:
|
|
2793
|
-
|
|
2794
|
-
"that data (a 'broken' entity). Use only real fields (see valid_fields), or add " +
|
|
2795
|
-
"the field first with suppa_add_field.",
|
|
2796
|
-
unknown_fields: unknown,
|
|
2870
|
+
error: `Refused: ${parts.join(" Also: ")}`,
|
|
2871
|
+
...detail,
|
|
2797
2872
|
valid_fields: [...fieldNames].sort(),
|
|
2798
2873
|
};
|
|
2799
2874
|
if (many) {
|
|
@@ -3127,6 +3202,38 @@ export async function updateRecord(entityName, recordId, fieldsJson, mergeJson =
|
|
|
3127
3202
|
* The schema endpoint may return the field list directly, or a dict carrying it
|
|
3128
3203
|
* under ``fields``/``properties``/``columns``, or a name→def mapping.
|
|
3129
3204
|
*/
|
|
3205
|
+
/**
|
|
3206
|
+
* The same record with `names` moved from the top level into the custom-values
|
|
3207
|
+
* envelope — the write the caller meant, ready to paste back as fields_json.
|
|
3208
|
+
*
|
|
3209
|
+
* A name present in BOTH places is not guessed at: the value already under
|
|
3210
|
+
* `customFields` is kept and the name comes back as a conflict, because which of
|
|
3211
|
+
* two different values the caller meant is not knowable from here.
|
|
3212
|
+
*/
|
|
3213
|
+
function _nestCustomKeys(record, names) {
|
|
3214
|
+
const existing = isPlainObject(record[CUSTOM_FIELDS_KEY])
|
|
3215
|
+
? record[CUSTOM_FIELDS_KEY]
|
|
3216
|
+
: {};
|
|
3217
|
+
const nested = { ...existing };
|
|
3218
|
+
const conflicts = [];
|
|
3219
|
+
const out = {};
|
|
3220
|
+
for (const [k, v] of Object.entries(record)) {
|
|
3221
|
+
if (k === CUSTOM_FIELDS_KEY) {
|
|
3222
|
+
continue;
|
|
3223
|
+
}
|
|
3224
|
+
if (!names.includes(k)) {
|
|
3225
|
+
out[k] = v;
|
|
3226
|
+
continue;
|
|
3227
|
+
}
|
|
3228
|
+
if (Object.prototype.hasOwnProperty.call(existing, k)) {
|
|
3229
|
+
conflicts.push(k);
|
|
3230
|
+
continue;
|
|
3231
|
+
}
|
|
3232
|
+
nested[k] = v;
|
|
3233
|
+
}
|
|
3234
|
+
out[CUSTOM_FIELDS_KEY] = nested;
|
|
3235
|
+
return { fields: out, conflicts };
|
|
3236
|
+
}
|
|
3130
3237
|
/**
|
|
3131
3238
|
* The entity's CUSTOM field definitions — the schema's own `customFields` array.
|
|
3132
3239
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.38.0",
|
|
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": {
|