suppa-mcp-2 1.40.4 → 1.40.6
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 +20 -5
- package/dist/cli/api.js +238 -0
- package/dist/cli/help.js +1 -0
- package/dist/cli/run.js +12 -25
- package/dist/cli/tenantPoint.js +35 -0
- package/dist/server.js +137 -51
- package/dist/toolTable.js +2 -2
- package/dist/tools/customFields.js +9 -3
- package/dist/tools/customFieldsAsCode.js +11 -3
- package/dist/tools/entity.js +41 -0
- package/dist/tools/formLifecycle.js +525 -0
- package/dist/tools/formV2.js +181 -44
- package/dist/tools/query.js +269 -0
- package/dist/utils.js +9 -1
- package/package.json +1 -1
- package/skills/suppa-cli/SKILL.md +9 -1
- package/skills/suppa-entity-code/references/entities.md +1 -1
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +10 -3
- package/skills/suppa-form-v2/SKILL.md +9 -9
- package/skills/suppa-form-v2/references/charts.md +10 -2
- package/skills/suppa-form-v2/references/publishing.md +16 -5
- package/skills/suppa-form-v2/references/tables.md +1 -1
- package/skills/suppa-form-v2/scripts/form-rules.mjs +2 -1
- package/skills/suppa-form-v2/scripts/validate-form-schema.mjs +118 -0
package/dist/server.js
CHANGED
|
@@ -17,12 +17,14 @@ import * as customFieldSets from "./tools/customFieldSets.js";
|
|
|
17
17
|
import * as customFieldsAsCode from "./tools/customFieldsAsCode.js";
|
|
18
18
|
import * as entityCode from "./tools/entityCode.js";
|
|
19
19
|
import * as formV2 from "./tools/formV2.js";
|
|
20
|
+
import * as formLifecycle from "./tools/formLifecycle.js";
|
|
20
21
|
import { houseRulesDigest } from "./tools/entityCode.js";
|
|
21
22
|
import * as files from "./tools/files.js";
|
|
22
23
|
import * as forms from "./tools/forms.js";
|
|
23
24
|
import * as migrate from "./tools/migrate.js";
|
|
24
25
|
import * as workspace from "./tools/workspace.js";
|
|
25
26
|
import * as automation from "./tools/automation.js";
|
|
27
|
+
import * as query from "./tools/query.js";
|
|
26
28
|
import * as auth from "./auth.js";
|
|
27
29
|
import * as tenants from "./tenants.js";
|
|
28
30
|
import { confirmRequired, jsonResponse } from "./utils.js";
|
|
@@ -66,6 +68,13 @@ const _MUT = {
|
|
|
66
68
|
// the wrong thing to show in front of a recovery action (a user who hesitates
|
|
67
69
|
// there loses the record they were trying to save). It keeps the confirm gate:
|
|
68
70
|
// restoring still changes what every normal read returns.
|
|
71
|
+
// A write that destroys what it replaces and is not safe to repeat: publishing twice freezes two
|
|
72
|
+
// versions, rolling back twice publishes twice.
|
|
73
|
+
const _ONCE = {
|
|
74
|
+
readOnlyHint: false,
|
|
75
|
+
destructiveHint: true,
|
|
76
|
+
idempotentHint: false,
|
|
77
|
+
};
|
|
69
78
|
const _UNDO = {
|
|
70
79
|
readOnlyHint: false,
|
|
71
80
|
destructiveHint: false,
|
|
@@ -288,47 +297,47 @@ if (!HOUSE_RULES_DIGEST) {
|
|
|
288
297
|
process.stderr.write("[suppa-mcp] warning: skills/suppa-entity-code/scripts/house-rules.mjs is missing or unreadable — " +
|
|
289
298
|
"the server instructions carry no entity-code house rules. Reinstall suppa-mcp-2.\n");
|
|
290
299
|
}
|
|
291
|
-
const INSTRUCTIONS = `Suppa Platform MCP Server — Tasks, Docs/Pages, Entities, Forms, Automations and file attachments on Suppa tenants.
|
|
292
|
-
|
|
293
|
-
AUTHENTICATION — RESOLVE THIS BEFORE ANY OTHER SUPPA WORK
|
|
294
|
-
- Sign-in is an interactive Google flow in the browser. There is NO API key for a user to find or paste — NEVER ask for a token, key or password; call suppa_login instead.
|
|
295
|
-
- Signed in? suppa_list_tenants shows the STORED "authenticated"/"needs_login" (no network; a revoked session still reads signed in); suppa_diagnostics makes the live call that settles it.
|
|
296
|
-
- When not signed in — or any tool answers "No credentials" / HTTP 401 / "session could not be refreshed" / ReloginRequired — DO NOT STOP and DO NOT ask for a key:
|
|
297
|
-
1. Call suppa_login (suppa_login(tenant="<alias|host|url>") targets another instance; default is the active tenant). It OPENS A GOOGLE SIGN-IN PAGE in the default browser, served locally at http://localhost:${config.LOGIN_PORT}.
|
|
298
|
-
2. Tell the user: "I've opened a Google sign-in page in your browser — pick your account to finish signing in." If the browser did not open, the result carries the URL for them to open by hand.
|
|
299
|
-
3. It blocks until they finish and returns {"status":"ok"} — THEN retry the original action. Tokens go to the OS keychain and auto-refresh: one login per tenant, not per session.
|
|
300
|
-
- A static SUPPA_API_KEY in the client env (CI / single tenant) means no login is needed; it is optional and most users have none.
|
|
301
|
-
- suppa_diagnostics validates the whole setup and reports the login_origin to whitelist. ONE-TIME ORG SETUP: http://localhost:${config.LOGIN_PORT} must be in the Google OAuth client's "Authorized JavaScript origins" — a sign-in page that opens but never completes is almost always this; tell the user so an admin can add it.
|
|
302
|
-
- suppa_use_tenant switches the active instance for ALL later calls; suppa_list_tenants shows what is known and authenticated.
|
|
303
|
-
|
|
304
|
-
DATA BASICS
|
|
305
|
-
- IDs are integers, not UUIDs. Dates are ISO-8601; a naive datetime (no offset) is read as UTC, so pass an explicit offset (+03:00) or convert local times yourself. Task deadlines also accept 'today', 'tomorrow', '+3d', '+2h', '+30m', '+1w'.
|
|
306
|
-
- Each write tool's description states the shapes it demands — relations and enums as {"id": N}, list fields REPLACED unless merge_json says otherwise — and validates against the live schema before writing. Read it before calling: a bare number where a reference belongs returns 201 and stores null.
|
|
307
|
-
- DELETE IS A SOFT DELETE — every delete tool sets deletedAt and leaves the row in place, reversible with suppa_restore_record(entity_name, record_id); never tell the user their data was destroyed. It still needs confirm=true because the row leaves all normal reads; find it again with deleted_scope='deleted'.
|
|
308
|
-
- PERMANENT DELETE IS UNAVAILABLE HERE, BY DESIGN — this server performs REVERSIBLE deletes only. The platform's PERMANENT delete (POST /core/data/:entityName/delete — rows leave the table and cannot be restored) is BLOCKED in the HTTP client itself: no tool, flag, confirm=true or direct call reaches it, and an attempt is refused before any request is sent. Do not look for a tool, a parameter or a workaround — there is none. Asked to erase data for good, say so plainly and offer the soft delete (suppa_delete_record → /remove, undone by suppa_restore_record); permanent removal is an admin action in the platform's own UI.
|
|
309
|
-
- Reads are compact: relation objects omit deletedAt when null (a live row); schema reads omit nulls, false flags and default options and carry a _legend (full=true returns the raw form).
|
|
310
|
-
|
|
311
|
-
SEARCH & FILTERS — suppa_search_records' description carries the comparators, nested AND/OR groups, dotted field paths, "$current-user", paging and the auto-diagnosis of an empty result. Read it before your first search.
|
|
312
|
-
- PROJECT ONLY THE FIELDS YOU NEED: fields_json is on suppa_search_records AND on every task/doc read (suppa_get_task, suppa_search_tasks — which also takes task_ids, so several tasks are ONE call, never one suppa_get_task each — suppa_get_doc, suppa_list_pages, …). A 600-character answer instead of a 50 000-character one, re-sent on every later turn.
|
|
313
|
-
- Unsure of the schema: suppa_list_entities → suppa_describe_entity → suppa_search_records. One record by id needs no filters: suppa_get_record / suppa_get_task / suppa_get_doc.
|
|
314
|
-
|
|
315
|
-
APPROVAL GATES (human-in-the-loop)
|
|
316
|
-
- Every update/move/close/delete tool called without confirm=true returns {"status": "confirmation_required"} and performs NOTHING. Show the user what will change, get explicit approval, then re-call the same tool with confirm=true — never set it on the first call without their go-ahead. Create/read tools and comments need no confirmation.
|
|
317
|
-
- A value shown as <N chars — …> is NOT the stored text: the marker stands in for a long string you supplied in this same call, and the reason after the dash says which. Quote it to the user from your own arguments; never report the marker as the record's content.
|
|
318
|
-
|
|
319
|
-
ENTITY BUILDER (create + edit fields; core-field removal is UI-only) — suppa_add_field's description carries the real field types, the sub_type matrix and the field options; suppa_update_field's carries what may still be changed on a field that exists. Two things those cannot decide for you:
|
|
320
|
-
- OWNED CHILD COLLECTIONS ARE TABULAR PARTS: repeating rows that belong to ONE parent record (a part's BOM items) go through suppa_create_tabular_part(parent_entity, name), which creates the child's 'owner' relation and the parent link. Never model it by hand — suppa_add_field REFUSES field_type='one-to-many'; 'many-to-many' is for a shared lookup referenced by many records.
|
|
321
|
-
- An enum value on a RECORD is a reference, {"id": <Enums row id>} (an array of those for multi-enum), never a bare code like "red" — that is refused. Read the ids with suppa_search_records on 'Enums' filtered by name.
|
|
322
|
-
|
|
323
|
-
CUSTOM FIELDS — ANY entity, not just Tasks: one whose options.customFields is on (an admin enables it; suppa_describe_entity shows it) carries extra columns that vary BY CONTEXT, so which are live differs from record to record — suppa_resolve_custom_fields answers for a given record. Their values ride on the OWNER record under the reserved key customFields, e.g. fields_json {"customFields": {"budget": 600}}.
|
|
324
|
-
|
|
325
|
-
${formV2.FORM_V2_INSTRUCTION_LINE}
|
|
326
|
-
|
|
327
|
-
${HOUSE_RULES_DIGEST}
|
|
328
|
-
|
|
329
|
-
ATTACHMENTS — an entity holds files only through a 'file' or 'multi-file' field (add one with suppa_add_field). suppa_attach_file_to_record uploads from local disk and returns the file_ids that are the only handle to the bytes; suppa_list_record_files lists what a record carries; suppa_download_file and suppa_download_files_zip fetch them. Those descriptions carry the rest.
|
|
330
|
-
|
|
331
|
-
MIGRATION (Suppa 1.0 → 2.0) — always dry-run first: suppa_migrate_entities_from_v1(dry_run=true, output_file="plan.json"), review/edit the plan, then execute with plan_file="plan.json", dry_run=false.
|
|
300
|
+
const INSTRUCTIONS = `Suppa Platform MCP Server — Tasks, Docs/Pages, Entities, Forms, Automations and file attachments on Suppa tenants.
|
|
301
|
+
|
|
302
|
+
AUTHENTICATION — RESOLVE THIS BEFORE ANY OTHER SUPPA WORK
|
|
303
|
+
- Sign-in is an interactive Google flow in the browser. There is NO API key for a user to find or paste — NEVER ask for a token, key or password; call suppa_login instead.
|
|
304
|
+
- Signed in? suppa_list_tenants shows the STORED "authenticated"/"needs_login" (no network; a revoked session still reads signed in); suppa_diagnostics makes the live call that settles it.
|
|
305
|
+
- When not signed in — or any tool answers "No credentials" / HTTP 401 / "session could not be refreshed" / ReloginRequired — DO NOT STOP and DO NOT ask for a key:
|
|
306
|
+
1. Call suppa_login (suppa_login(tenant="<alias|host|url>") targets another instance; default is the active tenant). It OPENS A GOOGLE SIGN-IN PAGE in the default browser, served locally at http://localhost:${config.LOGIN_PORT}.
|
|
307
|
+
2. Tell the user: "I've opened a Google sign-in page in your browser — pick your account to finish signing in." If the browser did not open, the result carries the URL for them to open by hand.
|
|
308
|
+
3. It blocks until they finish and returns {"status":"ok"} — THEN retry the original action. Tokens go to the OS keychain and auto-refresh: one login per tenant, not per session.
|
|
309
|
+
- A static SUPPA_API_KEY in the client env (CI / single tenant) means no login is needed; it is optional and most users have none.
|
|
310
|
+
- suppa_diagnostics validates the whole setup and reports the login_origin to whitelist. ONE-TIME ORG SETUP: http://localhost:${config.LOGIN_PORT} must be in the Google OAuth client's "Authorized JavaScript origins" — a sign-in page that opens but never completes is almost always this; tell the user so an admin can add it.
|
|
311
|
+
- suppa_use_tenant switches the active instance for ALL later calls; suppa_list_tenants shows what is known and authenticated.
|
|
312
|
+
|
|
313
|
+
DATA BASICS
|
|
314
|
+
- IDs are integers, not UUIDs. Dates are ISO-8601; a naive datetime (no offset) is read as UTC, so pass an explicit offset (+03:00) or convert local times yourself. Task deadlines also accept 'today', 'tomorrow', '+3d', '+2h', '+30m', '+1w'.
|
|
315
|
+
- Each write tool's description states the shapes it demands — relations and enums as {"id": N}, list fields REPLACED unless merge_json says otherwise — and validates against the live schema before writing. Read it before calling: a bare number where a reference belongs returns 201 and stores null.
|
|
316
|
+
- DELETE IS A SOFT DELETE — every delete tool sets deletedAt and leaves the row in place, reversible with suppa_restore_record(entity_name, record_id); never tell the user their data was destroyed. It still needs confirm=true because the row leaves all normal reads; find it again with deleted_scope='deleted'.
|
|
317
|
+
- PERMANENT DELETE IS UNAVAILABLE HERE, BY DESIGN — this server performs REVERSIBLE deletes only. The platform's PERMANENT delete (POST /core/data/:entityName/delete — rows leave the table and cannot be restored) is BLOCKED in the HTTP client itself: no tool, flag, confirm=true or direct call reaches it, and an attempt is refused before any request is sent. Do not look for a tool, a parameter or a workaround — there is none. Asked to erase data for good, say so plainly and offer the soft delete (suppa_delete_record → /remove, undone by suppa_restore_record); permanent removal is an admin action in the platform's own UI.
|
|
318
|
+
- Reads are compact: relation objects omit deletedAt when null (a live row); schema reads omit nulls, false flags and default options and carry a _legend (full=true returns the raw form).
|
|
319
|
+
|
|
320
|
+
SEARCH & FILTERS — suppa_search_records' description carries the comparators, nested AND/OR groups, dotted field paths, "$current-user", paging and the auto-diagnosis of an empty result. Read it before your first search.
|
|
321
|
+
- PROJECT ONLY THE FIELDS YOU NEED: fields_json is on suppa_search_records AND on every task/doc read (suppa_get_task, suppa_search_tasks — which also takes task_ids, so several tasks are ONE call, never one suppa_get_task each — suppa_get_doc, suppa_list_pages, …). A 600-character answer instead of a 50 000-character one, re-sent on every later turn.
|
|
322
|
+
- Unsure of the schema: suppa_list_entities → suppa_describe_entity → suppa_search_records. One record by id needs no filters: suppa_get_record / suppa_get_task / suppa_get_doc.
|
|
323
|
+
|
|
324
|
+
APPROVAL GATES (human-in-the-loop)
|
|
325
|
+
- Every update/move/close/delete tool called without confirm=true returns {"status": "confirmation_required"} and performs NOTHING. Show the user what will change, get explicit approval, then re-call the same tool with confirm=true — never set it on the first call without their go-ahead. Create/read tools and comments need no confirmation.
|
|
326
|
+
- A value shown as <N chars — …> is NOT the stored text: the marker stands in for a long string you supplied in this same call, and the reason after the dash says which. Quote it to the user from your own arguments; never report the marker as the record's content.
|
|
327
|
+
|
|
328
|
+
ENTITY BUILDER (create + edit fields; core-field removal is UI-only) — suppa_add_field's description carries the real field types, the sub_type matrix and the field options; suppa_update_field's carries what may still be changed on a field that exists. Two things those cannot decide for you:
|
|
329
|
+
- OWNED CHILD COLLECTIONS ARE TABULAR PARTS: repeating rows that belong to ONE parent record (a part's BOM items) go through suppa_create_tabular_part(parent_entity, name), which creates the child's 'owner' relation and the parent link. Never model it by hand — suppa_add_field REFUSES field_type='one-to-many'; 'many-to-many' is for a shared lookup referenced by many records.
|
|
330
|
+
- An enum value on a RECORD is a reference, {"id": <Enums row id>} (an array of those for multi-enum), never a bare code like "red" — that is refused. Read the ids with suppa_search_records on 'Enums' filtered by name.
|
|
331
|
+
|
|
332
|
+
CUSTOM FIELDS — ANY entity, not just Tasks: one whose options.customFields is on (an admin enables it; suppa_describe_entity shows it) carries extra columns that vary BY CONTEXT, so which are live differs from record to record — suppa_resolve_custom_fields answers for a given record. Their values ride on the OWNER record under the reserved key customFields, e.g. fields_json {"customFields": {"budget": 600}}.
|
|
333
|
+
|
|
334
|
+
${formV2.FORM_V2_INSTRUCTION_LINE}
|
|
335
|
+
|
|
336
|
+
${HOUSE_RULES_DIGEST}
|
|
337
|
+
|
|
338
|
+
ATTACHMENTS — an entity holds files only through a 'file' or 'multi-file' field (add one with suppa_add_field). suppa_attach_file_to_record uploads from local disk and returns the file_ids that are the only handle to the bytes; suppa_list_record_files lists what a record carries; suppa_download_file and suppa_download_files_zip fetch them. Those descriptions carry the rest.
|
|
339
|
+
|
|
340
|
+
MIGRATION (Suppa 1.0 → 2.0) — always dry-run first: suppa_migrate_entities_from_v1(dry_run=true, output_file="plan.json"), review/edit the plan, then execute with plan_file="plan.json", dry_run=false.
|
|
332
341
|
`;
|
|
333
342
|
// ---------------------------------------------------------------------------
|
|
334
343
|
// Registered tool + prompt names (tests assert the counts).
|
|
@@ -1005,6 +1014,33 @@ export function buildToolTable() {
|
|
|
1005
1014
|
},
|
|
1006
1015
|
annotations: _READ,
|
|
1007
1016
|
}, async (a) => text(await entity.validateSelectQuery(a.entity_name, a.filters_json, a.fields_json, a.order_by, a.match_any)));
|
|
1017
|
+
reg("suppa_query", {
|
|
1018
|
+
description: "Run ONE read-only SuppaSQL statement — POST /core/data/query, the endpoint the\n" +
|
|
1019
|
+
" builder's SQL charts and tables use. Check a chart/table SQL source with it before\n" +
|
|
1020
|
+
" writing the form: an incomplete one shows demo data, a wrong one fails at runtime.\n\n" +
|
|
1021
|
+
" SELECT / WITH only, one statement; anything else is refused and nothing is sent.\n" +
|
|
1022
|
+
" Runs with the caller's read permissions; deleted rows are excluded. A missing LIMIT\n" +
|
|
1023
|
+
" is added and a bigger literal one clamped, so at most `limit` rows come back, with\n" +
|
|
1024
|
+
" `truncated` and `columns` — the result keys, nested ones as dot paths\n" +
|
|
1025
|
+
" (owner.firstName), which is what sqlValueColumns[].key and table columns must use.",
|
|
1026
|
+
inputSchema: {
|
|
1027
|
+
query: z
|
|
1028
|
+
.string()
|
|
1029
|
+
.describe('The SuppaSQL statement, e.g. SELECT "stage.name" AS stage, COUNT(id) AS n FROM Tasks GROUP BY "stage.name".'),
|
|
1030
|
+
bind_params_json: z
|
|
1031
|
+
.string()
|
|
1032
|
+
.optional()
|
|
1033
|
+
.describe('JSON object of bind values for $name / $1 / = ANY($arr), e.g. {"owner": 479}. $current-user is set by the server.'),
|
|
1034
|
+
limit: z
|
|
1035
|
+
.number()
|
|
1036
|
+
.int()
|
|
1037
|
+
.min(1)
|
|
1038
|
+
.max(query.QUERY_MAX_LIMIT)
|
|
1039
|
+
.default(query.QUERY_DEFAULT_LIMIT)
|
|
1040
|
+
.describe("Rows to show (1-500)."),
|
|
1041
|
+
},
|
|
1042
|
+
annotations: _READ,
|
|
1043
|
+
}, async (a) => text(await query.runQuery(a.query, a.bind_params_json ?? null, a.limit)));
|
|
1008
1044
|
reg("suppa_get_record", {
|
|
1009
1045
|
description: "Get a single record of any entity by id. fields_json: {field: true} projection —\n" +
|
|
1010
1046
|
' request only the fields you need (relations as nested objects, e.g. {"owner": {"id": true, "fullName": true}}).\n\n' +
|
|
@@ -2512,18 +2548,19 @@ export function buildToolTable() {
|
|
|
2512
2548
|
annotations: _READ,
|
|
2513
2549
|
}, async (a) => text(await formV2.validateFormSchema(a.path, a.baseline_path ?? null, a.normalize ?? false)));
|
|
2514
2550
|
reg("suppa_write_form_draft", {
|
|
2515
|
-
description: "Save a Suppa 2.0 form as a DRAFT on the tenant
|
|
2516
|
-
"
|
|
2517
|
-
"
|
|
2518
|
-
" FormVersions row is the published form. This writes the column and creates no version,\n" +
|
|
2519
|
-
" so nothing anyone else sees changes until a human publishes in the builder.\n\n" +
|
|
2551
|
+
description: "Save a Suppa 2.0 form as a DRAFT on the tenant, through the builder's own save\n" +
|
|
2552
|
+
" (PUT /core/forms/:id/schema). It never publishes: what others see stays the published\n" +
|
|
2553
|
+
" version; a published form reads `editing`. The save appears in the builder's History.\n\n" +
|
|
2520
2554
|
" The gate runs first on the same file: a refusal or any error and nothing is written.\n" +
|
|
2521
2555
|
" The row is read first and a read that does not clearly succeed ABORTS — merging over a\n" +
|
|
2522
2556
|
" failed read is how a saved mobile layout and code-form vanish on a call returning 200.\n" +
|
|
2523
|
-
"
|
|
2524
|
-
"
|
|
2525
|
-
"
|
|
2526
|
-
"
|
|
2557
|
+
" Writes schema and settings; `variables` only when the draft lists some — the list is the\n" +
|
|
2558
|
+
" FULL state (an omitted variable is deleted), so an empty one is never sent and one that\n" +
|
|
2559
|
+
" drops the form's default variable is refused. mobileSchema, code, localizations, entity,\n" +
|
|
2560
|
+
" alias and parent are never sent; a child form's `schema.overrides` is preserved.\n\n" +
|
|
2561
|
+
" Refuses while someone else has the form open in the builder (lockedBy). Without\n" +
|
|
2562
|
+
" confirm=true it returns the plan and a `revision`; pass it back as expected_revision and\n" +
|
|
2563
|
+
" a form that moved since the preview is refused, not overwritten.",
|
|
2527
2564
|
inputSchema: {
|
|
2528
2565
|
form_id: z.number().describe("The Forms row id — the `form=` in the builder URL."),
|
|
2529
2566
|
path: z
|
|
@@ -2537,9 +2574,58 @@ export function buildToolTable() {
|
|
|
2537
2574
|
.boolean()
|
|
2538
2575
|
.optional()
|
|
2539
2576
|
.describe("Run the repair pipeline before checking AND saving, so what is stored is what was verified."),
|
|
2577
|
+
expected_revision: z
|
|
2578
|
+
.string()
|
|
2579
|
+
.optional()
|
|
2580
|
+
.describe("The `revision` from the preview: the save is refused if the form changed since."),
|
|
2540
2581
|
},
|
|
2541
2582
|
annotations: _MUT,
|
|
2542
|
-
}, async (a) => text(await formV2.writeFormDraft(a.form_id, a.path, a.confirm ?? false, a.normalize ?? false)));
|
|
2583
|
+
}, async (a) => text(await formV2.writeFormDraft(a.form_id, a.path, a.confirm ?? false, a.normalize ?? false, a.expected_revision ?? null)));
|
|
2584
|
+
reg("suppa_create_form_v2", {
|
|
2585
|
+
description: "Create a Suppa 2.0 form: the row and its draft in one transaction (POST /core/forms/schema),\n" +
|
|
2586
|
+
" as the builder does — isFormBuilderV2 stamped, the default variable added (a relation named\n" +
|
|
2587
|
+
" after the entity, or `submitData` on an entity-less form). A draft, nothing is published.\n" +
|
|
2588
|
+
" `path` (optional) is a draft file, gated first. A duplicate name or an unknown entity or\n" +
|
|
2589
|
+
" folder is refused before any write. `workspace` forms inherit the base form: builder only.\n" +
|
|
2590
|
+
" A dashboard is `custom` with folder='dashboards'. Without confirm=true: the plan only.",
|
|
2591
|
+
inputSchema: {
|
|
2592
|
+
name: z.string().describe("Unique on the tenant."),
|
|
2593
|
+
type: z.enum(formLifecycle.CREATABLE_FORM_TYPES).describe("create / update need an entity; custom may have none."),
|
|
2594
|
+
entity: z.string().optional().describe("Entity system name the form edits."),
|
|
2595
|
+
path: z.string().optional().describe("Absolute path to a draft JSON { schema, settings, variables }."),
|
|
2596
|
+
folder: z.string().optional().describe("FormsFolders alias or id to file the form into."),
|
|
2597
|
+
confirm: z.boolean().default(false).describe("true = create. Omitted means NO."),
|
|
2598
|
+
},
|
|
2599
|
+
annotations: _ADD,
|
|
2600
|
+
}, async (a) => text(await formLifecycle.createFormV2(a.name, a.type, a.entity ?? null, a.path ?? null, a.folder ?? null, a.confirm ?? false)));
|
|
2601
|
+
reg("suppa_form_versions", {
|
|
2602
|
+
description: "A Suppa 2.0 form's published versions (newest first, which one users see), optionally the\n" +
|
|
2603
|
+
" component diff between two of THIS form's versions, and a summary of the last N draft\n" +
|
|
2604
|
+
" saves (change-sets, without their patches). Read-only.",
|
|
2605
|
+
inputSchema: {
|
|
2606
|
+
form_id: z.number().int(),
|
|
2607
|
+
diff_from: z.number().int().optional().describe("Version id to diff from (with diff_to)."),
|
|
2608
|
+
diff_to: z.number().int().optional().describe("Version id to diff to."),
|
|
2609
|
+
change_sets: z.number().int().min(1).max(50).optional().describe("How many recent draft saves to summarize."),
|
|
2610
|
+
},
|
|
2611
|
+
annotations: _READ,
|
|
2612
|
+
}, async (a) => text(await formLifecycle.formVersions(a.form_id, a.diff_from ?? null, a.diff_to ?? null, a.change_sets ?? null)));
|
|
2613
|
+
reg("suppa_form_lifecycle", {
|
|
2614
|
+
description: "Publish, roll back, discard or promote a Suppa 2.0 form. publish freezes the draft as the\n" +
|
|
2615
|
+
" new default version, live for every user. rollback RESTORES an old version over the draft\n" +
|
|
2616
|
+
" and PUBLISHES it. discard overwrites the draft with the live version — unrecoverable, no\n" +
|
|
2617
|
+
" history. promote makes a version the one users see. publish and rollback are refused when\n" +
|
|
2618
|
+
" the form gate finds errors the live version does not have; rollback and promote refuse a\n" +
|
|
2619
|
+
" version of another form (the platform would act on THAT form). Without confirm=true: the\n" +
|
|
2620
|
+
" preview only.",
|
|
2621
|
+
inputSchema: {
|
|
2622
|
+
form_id: z.number().int(),
|
|
2623
|
+
action: z.enum(formLifecycle.LIFECYCLE_ACTIONS),
|
|
2624
|
+
version_id: z.number().int().optional().describe("rollback / promote: the FormVersions id (suppa_form_versions)."),
|
|
2625
|
+
confirm: z.boolean().default(false).describe("true = do it. Omitted means NO."),
|
|
2626
|
+
},
|
|
2627
|
+
annotations: _ONCE,
|
|
2628
|
+
}, async (a) => text(await formLifecycle.formLifecycle(a.form_id, a.action, a.version_id ?? null, a.confirm ?? false)));
|
|
2543
2629
|
reg("suppa_validate_entity_code", {
|
|
2544
2630
|
description: "Run the schema gate over an application repo's *.entity.ts / *.seed.ts / module files.\n\n" +
|
|
2545
2631
|
" CALL THIS BEFORE REPORTING ANY ENTITY OR SEED FILE DONE. It is the same checker the\n" +
|
package/dist/toolTable.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const PROFILES = {
|
|
2
2
|
core: ["login", "logout", "use_tenant", "list_tenants", "get_me", "health_check", "diagnostics", "version"],
|
|
3
|
-
data: ["search_records", "get_record", "create_record", "update_record", "delete_record", "restore_record", "copy_record", "validate_select", "search_entities", "list_entities", "describe_entity", "search_users"],
|
|
3
|
+
data: ["search_records", "get_record", "create_record", "update_record", "delete_record", "restore_record", "copy_record", "validate_select", "query", "search_entities", "list_entities", "describe_entity", "search_users"],
|
|
4
4
|
tasks: ["search_tasks", "get_task", "create_task", "update_task", "close_task", "delete_task", "move_task", "count_tasks", "list_stages", "list_task_types", "list_workflows", "add_comment", "get_comments", "create_workspace", "add_menu_item"],
|
|
5
5
|
files: ["attach_file", "attach_file_to_record", "download_file", "download_files_zip", "list_record_files"],
|
|
6
6
|
schema: ["create_entity", "add_field", "update_field", "update_entity_options", "set_title_field", "create_tabular_part", "list_tabular_parts", "list_field_types", "add_enum_values", "add_custom_field", "add_custom_fields_batch", "remove_custom_field", "restore_custom_field", "resolve_custom_fields", "link_custom_field", "apply_custom_fields", "validate_entity_code", "migrate_entities_from_v1", "read_v1_entities", "read_v1_entity_props", "read_v1_enum"],
|
|
@@ -11,7 +11,7 @@ export const PROFILES = {
|
|
|
11
11
|
// entity-builder canvas — the `schema` COLUMN on the row since 2.1, 58 component
|
|
12
12
|
// types — and share nothing with them.
|
|
13
13
|
forms: ["create_form", "get_form", "list_forms", "update_form", "add_field_to_form", "generate_form_schema", "list_form_field_types", "form_kb", "validate_form_schema",
|
|
14
|
-
"write_form_draft"],
|
|
14
|
+
"write_form_draft", "create_form_v2", "form_versions", "form_lifecycle"],
|
|
15
15
|
automation: ["create_automation", "get_automation", "update_automation", "delete_automation", "list_automations", "publish_automation", "unpublish_automation", "list_automation_runs", "get_automation_run", "get_automation_node_schema", "list_automation_node_types"],
|
|
16
16
|
};
|
|
17
17
|
const BY_NAME = new Map();
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
import { makeRequest, searchEntity, updateEntity } from "../httpClient.js";
|
|
46
46
|
import { customFieldsHint } from "../customFieldHints.js";
|
|
47
47
|
import { jsonResponse, confirmRequired, makeFilter } from "../utils.js";
|
|
48
|
-
import { buildFieldDef, CUSTOM_FIELDS_EXTENSION_SUFFIX, CUSTOM_FIELDS_KEY, CUSTOM_FIELDS_OPTION, } from "./entity.js";
|
|
48
|
+
import { buildFieldDef, checkCustomFieldsOwner, 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
|
|
51
51
|
* entity-option catalogue:
|
|
@@ -171,9 +171,15 @@ export async function resolveCustomFields(entityName, recordId = null, contextFi
|
|
|
171
171
|
if (error) {
|
|
172
172
|
return jsonResponse({ error });
|
|
173
173
|
}
|
|
174
|
+
// The platform answers an empty list, not an error, for an owner or context field that is not
|
|
175
|
+
// there — which reads exactly like "no custom fields here".
|
|
176
|
+
const owner = await checkCustomFieldsOwner(entityName, recordId === null ? contextField : null);
|
|
177
|
+
if (owner.error) {
|
|
178
|
+
return owner.error;
|
|
179
|
+
}
|
|
174
180
|
try {
|
|
175
|
-
const result = await makeRequest("POST", `/api/core/custom-fields/${
|
|
176
|
-
return jsonResponse(await _withFieldTypes(
|
|
181
|
+
const result = await makeRequest("POST", `/api/core/custom-fields/${owner.name}/resolve`, body);
|
|
182
|
+
return jsonResponse(await _withFieldTypes(owner.name, result));
|
|
177
183
|
}
|
|
178
184
|
catch (e) {
|
|
179
185
|
return errorResponse(e);
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
*/
|
|
51
51
|
import { customFieldsEntity, customFieldsUsage, quotaNote } from "./customFields.js";
|
|
52
52
|
import { addCustomFieldsBatch, extensionFields, linkCustomFields } from "./customFieldSets.js";
|
|
53
|
+
import { checkCustomFieldsOwner } from "./entity.js";
|
|
53
54
|
import { jsonResponse, parseJsonParam } from "../utils.js";
|
|
54
55
|
import { makeRequest } from "../httpClient.js";
|
|
55
56
|
/** Read a declaration from JSON, saying plainly what is wrong with a bad one. */
|
|
@@ -191,9 +192,16 @@ async function readOffered(entity, contextField, contexts) {
|
|
|
191
192
|
* reading, and it is what a reviewer approves.
|
|
192
193
|
*/
|
|
193
194
|
export async function applyCustomFieldsDeclaration(declaration, opts = {}) {
|
|
194
|
-
const
|
|
195
|
-
if (error || !decl)
|
|
196
|
-
return jsonResponse({ error });
|
|
195
|
+
const parsed = parseDeclaration(declaration);
|
|
196
|
+
if (parsed.error || !parsed.decl)
|
|
197
|
+
return jsonResponse({ error: parsed.error });
|
|
198
|
+
// The plan is what a reviewer approves, so it must not be drawn for an owner or a context field
|
|
199
|
+
// that is not there: the platform's /resolve answers those with an empty list, which the diff
|
|
200
|
+
// below would read as "create everything".
|
|
201
|
+
const owner = await checkCustomFieldsOwner(parsed.decl.entity, parsed.decl.context_field);
|
|
202
|
+
if (owner.error)
|
|
203
|
+
return owner.error;
|
|
204
|
+
const decl = { ...parsed.decl, entity: owner.name };
|
|
197
205
|
const extension = customFieldsEntity(decl.entity);
|
|
198
206
|
const meta = await extensionFields(extension);
|
|
199
207
|
const live = new Map();
|
package/dist/tools/entity.js
CHANGED
|
@@ -2833,6 +2833,47 @@ async function _resolveEntity(name) {
|
|
|
2833
2833
|
}),
|
|
2834
2834
|
};
|
|
2835
2835
|
}
|
|
2836
|
+
/**
|
|
2837
|
+
* The owner of a custom-field read or plan, checked: the entity is on the tenant and, when one is
|
|
2838
|
+
* named, the context field is one of its fields.
|
|
2839
|
+
*
|
|
2840
|
+
* The platform checks neither on a read — /custom-fields/<E>/resolve answers 200 with empty
|
|
2841
|
+
* `fields` and `sets` for a missing entity AND for a missing context field (read live on dev,
|
|
2842
|
+
* 2026-09-28) — so without this a typo reads as "no custom fields here". Best-effort like
|
|
2843
|
+
* `_resolveEntity`: a list or schema that cannot be read verifies nothing and blocks nothing.
|
|
2844
|
+
* Returns the entity name as the tenant spells it (a case-only slip is corrected).
|
|
2845
|
+
*/
|
|
2846
|
+
export async function checkCustomFieldsOwner(entityName, contextField = null) {
|
|
2847
|
+
const ent = await _resolveEntity(entityName);
|
|
2848
|
+
if (ent.error || !contextField)
|
|
2849
|
+
return { name: ent.name, ...(ent.error ? { error: ent.error } : {}) };
|
|
2850
|
+
let fields;
|
|
2851
|
+
try {
|
|
2852
|
+
fields = _extractFields(await makeRequest("GET", `/api/core/schema/${ent.name}`))
|
|
2853
|
+
.map((f) => String(f.name ?? ""))
|
|
2854
|
+
.filter(Boolean);
|
|
2855
|
+
}
|
|
2856
|
+
catch {
|
|
2857
|
+
return { name: ent.name };
|
|
2858
|
+
}
|
|
2859
|
+
if (!fields.length || fields.includes(contextField))
|
|
2860
|
+
return { name: ent.name };
|
|
2861
|
+
const lc = contextField.toLowerCase();
|
|
2862
|
+
const near = fields.filter((f) => f.toLowerCase() === lc);
|
|
2863
|
+
if (!near.length) {
|
|
2864
|
+
near.push(...fields.filter((f) => f.toLowerCase().includes(lc) || lc.includes(f.toLowerCase())).slice(0, 8));
|
|
2865
|
+
}
|
|
2866
|
+
return {
|
|
2867
|
+
name: ent.name,
|
|
2868
|
+
error: jsonResponse({
|
|
2869
|
+
error: `Refused: context_field '${contextField}' is not a field of '${ent.name}'. A context is keyed ` +
|
|
2870
|
+
"on one of the owner's own fields (the builder answers 400 for any other), and a read keyed " +
|
|
2871
|
+
"on a missing one comes back empty rather than wrong, so this was not sent.",
|
|
2872
|
+
did_you_mean: near,
|
|
2873
|
+
...(near.length ? {} : { fields_on_entity: fields.slice(0, 60) }),
|
|
2874
|
+
}),
|
|
2875
|
+
};
|
|
2876
|
+
}
|
|
2836
2877
|
/**
|
|
2837
2878
|
* Validate a record write end-to-end BEFORE touching the platform, so a
|
|
2838
2879
|
* hallucinated field/entity can never produce a broken record:
|