@selfhelp/shared 1.23.0 → 1.25.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/dist/index.d.mts +300 -100
  3. package/dist/index.d.ts +300 -100
  4. package/dist/index.js +531 -3
  5. package/dist/index.mjs +506 -3
  6. package/dist/plugin-sdk/index.d.mts +1 -1
  7. package/dist/plugin-sdk/index.d.ts +1 -1
  8. package/dist/plugin-sdk/index.js +7 -1
  9. package/dist/plugin-sdk/index.mjs +7 -1
  10. package/dist/registry/index.d.mts +2 -2
  11. package/dist/registry/index.d.ts +2 -2
  12. package/dist/registry/index.js +15 -1
  13. package/dist/registry/index.mjs +14 -1
  14. package/dist/{styles.registry-BBd9T2Ox.d.ts → styles.registry-C2ACy7H0.d.ts} +734 -2
  15. package/dist/{styles.registry-IjDTff8P.d.mts → styles.registry-DnIJqEzM.d.mts} +734 -2
  16. package/package.json +1 -1
  17. package/src/api/__tests__/endpoints.test.ts +45 -0
  18. package/src/api/__tests__/formListErrors.test.ts +143 -0
  19. package/src/api/endpoints.ts +41 -0
  20. package/src/api/formListErrors.ts +134 -0
  21. package/src/api/index.ts +1 -0
  22. package/src/content/__tests__/formListState.test.ts +448 -0
  23. package/src/content/__tests__/formRecordPrefill.test.ts +120 -0
  24. package/src/content/formListState.ts +559 -0
  25. package/src/content/formRecordPrefill.ts +108 -5
  26. package/src/content/index.ts +1 -0
  27. package/src/registry/__tests__/platform.test.ts +15 -6
  28. package/src/registry/__tests__/registry.test.ts +14 -0
  29. package/src/registry/styles.registry.ts +23 -0
  30. package/src/types/api/__tests__/formWrites.test.ts +84 -0
  31. package/src/types/api/form-lists.ts +475 -0
  32. package/src/types/api/forms.ts +149 -4
  33. package/src/types/api/index.ts +1 -0
  34. package/src/types/styles/__tests__/entryFormListFormFields.test.ts +44 -0
  35. package/src/types/styles/composite.ts +13 -0
  36. package/src/types/styles/forms.ts +124 -0
  37. package/src/types/styles/unknown.ts +5 -1
@@ -0,0 +1,475 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * DTOs of the `entry-form-list` and `data-view` styles ("lists").
7
+ *
8
+ * They mirror the backend contracts under
9
+ * `config/schemas/api/v1/{common/_form_list_state,common/_form_list_error,
10
+ * responses/frontend/form_list_*,requests/frontend/list_*}.json` and
11
+ * `docs/reference/api/22-form-lists.md`. The server decides, clients draw:
12
+ * nothing in here lets a client evaluate access, conditions, filters or
13
+ * quick-action assignments. A list's state is read from the page payload
14
+ * (`list_state` / `list_error` on the section) or from
15
+ * `GET /cms-api/v1/lists/{section_id}/state`.
16
+ */
17
+ import type { TStyle } from '../styles/unknown';
18
+ import type { IBaseApiResponse } from './envelope';
19
+ import type { IFormEffectiveContext } from './forms';
20
+
21
+ // -- vocabulary ----------------------------------------------------------------
22
+
23
+ export type TFormListStyleName = 'entry-form-list' | 'data-view';
24
+ /**
25
+ * `custom` (a `data-view` only): the sections placed inside the view are the layout of one
26
+ * record; the server renders them per record into each row's `sections`.
27
+ */
28
+ export type TFormListLayout = 'table' | 'cards' | 'custom';
29
+ export type TFormListPresentation = 'modal' | 'page';
30
+ export type TFormListColumnFormat = 'text' | 'number' | 'date' | 'datetime' | 'boolean' | 'badge' | 'file' | 'image';
31
+ export type TFormListControlType = 'text' | 'select' | 'multi_select' | 'boolean' | 'date_range' | 'number_range';
32
+ export type TFormListTextMatch = 'contains' | 'eq' | 'starts_with';
33
+ export type TFormListSortDirection = 'asc' | 'desc';
34
+ /** What the URL asks for next to a record: look at it, edit it, or start a new one. */
35
+ export type TFormListMode = 'view' | 'edit' | 'create' | 'history';
36
+ /** The modes of an open record (`create` has no record). */
37
+ export type TFormListOpenMode = Exclude<TFormListMode, 'create'>;
38
+
39
+ // -- state ----------------------------------------------------------------------
40
+
41
+ /** An uploaded file in a cell. `url` is a section-scoped download route; no storage path ever leaves the server. */
42
+ export interface IFormListFileValue {
43
+ index: number;
44
+ name: string;
45
+ mime?: string | null;
46
+ size?: number | null;
47
+ url: string;
48
+ }
49
+
50
+ /**
51
+ * A file / image cell: the `files` list of contract 2. Format `image` is drawn as a
52
+ * thumbnail; `file` as download links. Never a bare array of files and never a storage key.
53
+ */
54
+ export interface IFormListFilesCell {
55
+ files: IFormListFileValue[];
56
+ }
57
+
58
+ /** A cell as the server sends it: text, a number, nothing, or a file/image cell. */
59
+ export type TFormListCellValue = string | number | null | IFormListFilesCell;
60
+
61
+ /** Author text in the visitor's language. `add` and `confirm_delete` exist on `entry-form-list` only. */
62
+ export type TFormListLabels = Partial<Record<'add' | 'empty' | 'search' | 'confirm_delete', string>>;
63
+
64
+ export interface IFormListInfo {
65
+ section_id: number;
66
+ page_id: number;
67
+ /** The list's name in the URL: `<key>.page`, `<key>.q`, ... */
68
+ key: string;
69
+ style: TFormListStyleName;
70
+ layout: TFormListLayout;
71
+ form_presentation: TFormListPresentation;
72
+ /**
73
+ * The section that creates and edits records.
74
+ * For an `entry-form-list` that owns its table (no foreign `data_table`),
75
+ * this is the **list's own** section id. It is `null` for a `data-view`
76
+ * and for an `entry-form-list` with a foreign `data_table` (read-only
77
+ * override: delete and quick actions only, no form).
78
+ */
79
+ form_section_id: number | null;
80
+ /** False while the list's form was never submitted: there is nothing to read yet. */
81
+ table_exists: boolean;
82
+ labels: TFormListLabels;
83
+ /** Classes of the element that holds the records of the `custom` layout (web only); empty otherwise. */
84
+ row_css: string;
85
+ /**
86
+ * True when the author placed sections inside a data view with the `custom` layout.
87
+ * A `custom` layout without any is drawn as cards.
88
+ */
89
+ has_template: boolean;
90
+ }
91
+
92
+ export interface IFormListColumn {
93
+ /** The key of `values` in rows. */
94
+ field: string;
95
+ label: string;
96
+ format: TFormListColumnFormat;
97
+ sortable: boolean;
98
+ searchable: boolean;
99
+ }
100
+
101
+ export interface IFormListControlOption {
102
+ value: string;
103
+ label: string;
104
+ /** Records holding the value inside the visitor's dataset; null for fixed choices. */
105
+ count: number | null;
106
+ }
107
+
108
+ export interface IFormListControl {
109
+ /** The `<key>.f.<id>` URL parameter. */
110
+ id: string;
111
+ type: TFormListControlType;
112
+ field: string;
113
+ label: string;
114
+ match?: TFormListTextMatch;
115
+ options?: IFormListControlOption[];
116
+ }
117
+
118
+ export interface IFormListSort {
119
+ field: string;
120
+ direction: TFormListSortDirection;
121
+ }
122
+
123
+ /** The state that was served: the page after clamping, the order in effect, and the URL parameters that express it. */
124
+ export interface IFormListServedState {
125
+ page: number;
126
+ page_size: number;
127
+ q: string | null;
128
+ sort: IFormListSort[];
129
+ /** Control id to the control's raw value. */
130
+ filters: Record<string, string>;
131
+ record: number | null;
132
+ mode: TFormListMode | null;
133
+ /** The URL parameters (`news.page`, `news.q`, ...) that express this state; build links from them. */
134
+ query: Record<string, string>;
135
+ }
136
+
137
+ export interface IFormListQuickActionInfo {
138
+ id: string;
139
+ label: string;
140
+ confirm: string | null;
141
+ }
142
+
143
+ export interface IFormListCapabilities {
144
+ /** False for a guest on an own-entries list. */
145
+ create: boolean;
146
+ search: boolean;
147
+ history: boolean;
148
+ /** Labels and confirmations; a row's `quick_actions` say which of them apply to it. */
149
+ quick_actions: IFormListQuickActionInfo[];
150
+ }
151
+
152
+ /** What the visitor may do with one record. These are rendering hints; the server re-checks on every write. */
153
+ export interface IFormListRecordAccess {
154
+ is_own: boolean;
155
+ can_update: boolean;
156
+ can_delete: boolean;
157
+ can_view_history: boolean;
158
+ /** Ids of the quick actions whose condition holds now for this record. Offer no other. */
159
+ quick_actions: string[];
160
+ detail_url: string | null;
161
+ }
162
+
163
+ export interface IFormListRow extends IFormListRecordAccess {
164
+ record_id: number;
165
+ entry_date: string;
166
+ /** Send back as `expected_version` when changing the record. */
167
+ version: number;
168
+ /** Exactly the configured columns, by field. */
169
+ values: Record<string, TFormListCellValue>;
170
+ /**
171
+ * Only with the `custom` layout: the author's row template rendered for this record, in the
172
+ * shape of page sections (tokens, translations and conditions already resolved). Render them
173
+ * like any other sections; never evaluate anything.
174
+ */
175
+ sections?: TStyle[];
176
+ }
177
+
178
+ /** The record that is open (view or edit). */
179
+ export interface IFormListSelected extends IFormListRecordAccess {
180
+ record_id: number;
181
+ mode: TFormListOpenMode;
182
+ entry_date: string;
183
+ /** Send back as `expected_version` when saving, deleting, running an action or restoring. */
184
+ version: number;
185
+ values: Record<string, TFormListCellValue>;
186
+ /** The prefill the inline form receives on a page load; null when the caller cannot edit the record. */
187
+ form_values: Record<string, unknown> | unknown[] | null;
188
+ }
189
+
190
+ export interface IFormListPagination {
191
+ page: number;
192
+ page_size: number;
193
+ total: number;
194
+ total_pages: number;
195
+ }
196
+
197
+ /** The server-rendered state of one list for one visitor and one URL state. */
198
+ export interface IFormListState {
199
+ list: IFormListInfo;
200
+ columns: IFormListColumn[];
201
+ controls: IFormListControl[];
202
+ state: IFormListServedState;
203
+ capabilities: IFormListCapabilities;
204
+ rows: IFormListRow[];
205
+ pagination: IFormListPagination;
206
+ selected: IFormListSelected | null;
207
+ }
208
+
209
+ /**
210
+ * Why a list on a page has no state. The page is still served; the client draws
211
+ * the list's error state. `parameter` names the URL parameter that caused it - a
212
+ * client may drop it and retry.
213
+ */
214
+ export interface IFormListError {
215
+ /** The HTTP status the state endpoint would answer with: 400, 401, 403, 404 or 500. */
216
+ status: number;
217
+ message: string;
218
+ reason?: TFormListErrorReason | string | null;
219
+ parameter?: string | null;
220
+ }
221
+
222
+ export type TFormListErrorReason =
223
+ | 'login_required'
224
+ | 'operation_disabled'
225
+ | 'history_disabled'
226
+ | 'invalid_list_parameter'
227
+ | 'unknown_list_parameter'
228
+ | 'duplicate_list_parameter'
229
+ | 'field_not_allowed'
230
+ | 'table_mismatch'
231
+ | 'unknown_action'
232
+ | 'stale_version'
233
+ | 'action_not_available'
234
+ | 'restore_blocked'
235
+ | 'invalid_list_config';
236
+
237
+ export type IFormListStateResponse = IBaseApiResponse<IFormListState>;
238
+
239
+ // -- writes: conflict ---------------------------------------------------------------
240
+
241
+ /**
242
+ * `data` of the 409 envelope a stale save, delete, quick action or restore answers
243
+ * with. Nothing was written: keep the draft and offer reload, comparison and re-apply.
244
+ */
245
+ export interface IFormStaleVersionData {
246
+ reason: 'stale_version';
247
+ record_id: number;
248
+ expected_version: number;
249
+ current_version: number;
250
+ }
251
+
252
+ // -- quick action --------------------------------------------------------------------
253
+
254
+ export interface IFormListQuickActionRequest extends IFormEffectiveContext {
255
+ page_id: number;
256
+ /** REQUIRED: the record `version` the action is based on; missing or malformed answers 400, an old one 409. */
257
+ expected_version: number;
258
+ }
259
+
260
+ export interface IFormListQuickActionData {
261
+ record_id: number;
262
+ /** The record's version after the action. */
263
+ version: number;
264
+ action: string;
265
+ }
266
+
267
+ export type IFormListQuickActionResponse = IBaseApiResponse<IFormListQuickActionData>;
268
+
269
+ // -- history -------------------------------------------------------------------------
270
+
271
+ export type TDataRevisionOperation = 'create' | 'update' | 'delete' | 'restore' | 'baseline';
272
+ export type TDataRevisionSource = 'form' | 'admin' | 'quick_action' | 'job' | 'import' | 'system';
273
+
274
+ export interface IFormListActor {
275
+ id: number;
276
+ name: string | null;
277
+ }
278
+
279
+ /** One revision of a record: who changed it, how, and how much. */
280
+ export interface IFormListRevision {
281
+ version: number;
282
+ /** UTC, ISO 8601 (ATOM). */
283
+ created_at: string;
284
+ operation: TDataRevisionOperation;
285
+ source: TDataRevisionSource;
286
+ actor: IFormListActor | null;
287
+ impersonated_by: IFormListActor | null;
288
+ restored_from_version: number | null;
289
+ /** The number of fields the revision changed. */
290
+ changed_fields: number;
291
+ is_checkpoint: boolean;
292
+ }
293
+
294
+ /** A file a revision held; `available` is false once the file was erased. */
295
+ export interface IFormListHistoricalFile {
296
+ index: number;
297
+ name: string;
298
+ available: boolean;
299
+ /** Historical-file download route when `available` (list or admin data browser). */
300
+ url?: string;
301
+ }
302
+
303
+ /**
304
+ * Explicit file-field instruction on update (contract 4). Omit the field to keep
305
+ * files; send this object (or its JSON string in multipart) to clear or drop indexes.
306
+ * A new upload then replaces (single-file) or appends (multi-file).
307
+ */
308
+ export interface IFormFileFieldOp {
309
+ remove?: boolean;
310
+ remove_indexes?: number[];
311
+ }
312
+
313
+ interface IFormListChangeBase {
314
+ field_key: string;
315
+ field_label: string | null;
316
+ language_id: number;
317
+ truncated: boolean;
318
+ }
319
+
320
+ export interface IFormListValueChange extends IFormListChangeBase {
321
+ change: 'added' | 'changed' | 'removed';
322
+ kind: 'value';
323
+ before: string | null;
324
+ after: string | null;
325
+ }
326
+
327
+ export interface IFormListFileChange extends IFormListChangeBase {
328
+ change: 'added' | 'changed' | 'removed';
329
+ kind: 'file';
330
+ before: null;
331
+ after: null;
332
+ before_files: IFormListHistoricalFile[];
333
+ after_files: IFormListHistoricalFile[];
334
+ }
335
+
336
+ /** A change of a revision or of a comparison. */
337
+ export type TFormListChange = IFormListValueChange | IFormListFileChange;
338
+
339
+ /** A field of the record as it stood after a version. */
340
+ export interface IFormListStateField {
341
+ field_key: string;
342
+ field_label: string | null;
343
+ language_id: number;
344
+ kind: 'value' | 'file';
345
+ value: string | null;
346
+ files: IFormListHistoricalFile[];
347
+ }
348
+
349
+ export interface IFormListHistoryQuery extends IFormEffectiveContext {
350
+ page_id: number;
351
+ page?: number;
352
+ /** 1 to 100, default 20. */
353
+ page_size?: number;
354
+ }
355
+
356
+ export interface IFormListHistoryData {
357
+ /** Newest first. */
358
+ items: IFormListRevision[];
359
+ total: number;
360
+ page: number;
361
+ page_size: number;
362
+ current_version: number;
363
+ }
364
+
365
+ export interface IFormListVersionData {
366
+ revision: {
367
+ revision: IFormListRevision;
368
+ changes: TFormListChange[];
369
+ };
370
+ state: {
371
+ version: number;
372
+ current_version: number;
373
+ fields: IFormListStateField[];
374
+ };
375
+ }
376
+
377
+ export interface IFormListCompareQuery extends IFormEffectiveContext {
378
+ page_id: number;
379
+ from: number;
380
+ to: number;
381
+ }
382
+
383
+ export interface IFormListCompareData {
384
+ from_version: number;
385
+ to_version: number;
386
+ current_version: number;
387
+ changes: TFormListChange[];
388
+ }
389
+
390
+ export type TFormListRestoreBlockerReason = 'field_missing' | 'language_missing' | 'file_unavailable' | 'invalid_value';
391
+
392
+ /** Why one field of an earlier version cannot be written back today. */
393
+ export interface IFormListRestoreBlocker {
394
+ field_key: string;
395
+ field_label: string | null;
396
+ language_id: number;
397
+ reason: TFormListRestoreBlockerReason;
398
+ detail: string | null;
399
+ }
400
+
401
+ /** What a restore would write: set a value (and files) or remove what that version did not have. */
402
+ export interface IFormListRestoreChange {
403
+ field_key: string;
404
+ field_label: string | null;
405
+ language_id: number;
406
+ action: 'set' | 'remove';
407
+ kind: 'value' | 'file';
408
+ before: string | null;
409
+ after: string | null;
410
+ before_files?: IFormListHistoricalFile[];
411
+ after_files?: IFormListHistoricalFile[];
412
+ }
413
+
414
+ export interface IFormListRestoreRequest extends IFormEffectiveContext {
415
+ page_id: number;
416
+ /** The earlier version to restore. */
417
+ version: number;
418
+ /**
419
+ * The current version the person saw. REQUIRED for a real restore (missing or
420
+ * malformed answers 400, an old one 409); a `dry_run` needs none.
421
+ */
422
+ expected_version?: number;
423
+ /** Restore only these fields (1 to 100) - the way to resolve a blocked restore. */
424
+ field_keys?: string[];
425
+ /** Only report what a restore would change and what blocks it; write nothing. */
426
+ dry_run?: boolean;
427
+ }
428
+
429
+ export interface IFormListRestorePreview {
430
+ dry_run: true;
431
+ restorable: boolean;
432
+ record_id: number;
433
+ from_version: number;
434
+ current_version: number;
435
+ changes: IFormListRestoreChange[];
436
+ blockers: IFormListRestoreBlocker[];
437
+ }
438
+
439
+ export interface IFormListRestoreResult {
440
+ dry_run: false;
441
+ record_id: number;
442
+ restored_from_version: number;
443
+ /** The record's version after the restore (unchanged when nothing differed). */
444
+ version: number;
445
+ }
446
+
447
+ export type TFormListRestoreData = IFormListRestorePreview | IFormListRestoreResult;
448
+
449
+ /** `data` of the 422 envelope a restore that cannot be applied whole answers with. Nothing was applied. */
450
+ export interface IFormListRestoreBlockedData {
451
+ reason: 'restore_blocked';
452
+ record_id: number;
453
+ from_version: number;
454
+ blockers: IFormListRestoreBlocker[];
455
+ }
456
+
457
+ export type IFormListHistoryResponse = IBaseApiResponse<IFormListHistoryData>;
458
+ export type IFormListVersionResponse = IBaseApiResponse<IFormListVersionData>;
459
+ export type IFormListCompareResponse = IBaseApiResponse<IFormListCompareData>;
460
+ export type IFormListRestoreResponse = IBaseApiResponse<TFormListRestoreData>;
461
+
462
+ // -- admin data-browser history (same payloads, no page_id) -------------------------
463
+
464
+ /** Restore body for the data browser (contract 6); no page context. */
465
+ export interface IAdminDataRecordRestoreRequest {
466
+ version: number;
467
+ expected_version?: number;
468
+ field_keys?: string[];
469
+ dry_run?: boolean;
470
+ }
471
+
472
+ export type IAdminDataRecordHistoryResponse = IFormListHistoryResponse;
473
+ export type IAdminDataRecordVersionResponse = IFormListVersionResponse;
474
+ export type IAdminDataRecordCompareResponse = IFormListCompareResponse;
475
+ export type IAdminDataRecordRestoreResponse = IFormListRestoreResponse;
@@ -3,28 +3,156 @@ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
3
  SPDX-License-Identifier: MPL-2.0
4
4
  */
5
5
  import type { IBaseApiResponse } from './envelope';
6
+ import type { IFormStaleVersionData } from './form-lists';
6
7
 
7
- export interface IFormSubmitRequest {
8
+ /** `data` of a 409 form-write envelope (re-exported for form consumers). */
9
+ export type TFormConflictData = IFormStaleVersionData;
10
+
11
+ /**
12
+ * Which configuration a form or list request acts on: every write (submit,
13
+ * update, delete, quick action, restore) and every list read (state, history,
14
+ * version, comparison, historical file). The server decides what is allowed;
15
+ * the client only says which version of the page it is looking at.
16
+ */
17
+ export interface IFormEffectiveContext {
18
+ /**
19
+ * Act on the DRAFT of the page instead of its published version. Send it
20
+ * exactly when the person looks at the draft (the page was fetched with
21
+ * `preview`): the request must be judged by the same inputs, conditions,
22
+ * list properties and quick actions the person sees. Honoured for a
23
+ * signed-in person who may read the draft, refused otherwise; without it the
24
+ * published version decides, also for a signed-in person. Page access
25
+ * rights, live data and permissions are not part of the draft and stay the
26
+ * same. A request body carries it as a boolean, a query string as `preview=true`.
27
+ */
28
+ preview?: boolean;
29
+ }
30
+
31
+ /**
32
+ * `form_data` holds the values of the inputs of the form the server resolves for
33
+ * `section_id` (keyed by input name). It is untrusted: the server refuses (400)
34
+ * an unknown input, an owner or trigger field and any internal key, on JSON and
35
+ * on multipart requests, signed in or as a guest.
36
+ */
37
+ export interface IFormSubmitRequest extends IFormEffectiveContext {
8
38
  section_id: number;
9
39
  page_id?: number;
10
40
  record_id?: number;
11
41
  form_data: Record<string, unknown>;
12
42
  }
13
43
 
14
- export interface IFormUpdateRequest {
44
+ export interface IFormUpdateRequest extends IFormEffectiveContext {
15
45
  section_id: number;
16
46
  page_id?: number;
17
47
  record_id?: number;
18
48
  form_data: Record<string, unknown>;
49
+ /**
50
+ * The record the update changes: `{ record_id }` alone, or the documented
51
+ * alternative of plain field values. Anything else (empty, both, malformed)
52
+ * answers 400 `unsupported_target_selection`; a record outside the dataset
53
+ * of the form or list answers 404.
54
+ */
19
55
  update_based_on?: Record<string, unknown>;
56
+ /**
57
+ * REQUIRED: the record `version` the change is based on (the `version` the
58
+ * client last received from the record, a list row or the previous write).
59
+ * Missing, not a whole number of at least 1 (also as multipart text) answers
60
+ * 400 `expected_version_required` / `invalid_expected_version` before
61
+ * anything is stored; a save based on an older version answers 409 with
62
+ * {@link IFormStaleVersionData} and writes nothing. The schema marks it
63
+ * optional only so the refusal can carry its reason; the type does not.
64
+ */
65
+ expected_version: number;
20
66
  }
21
67
 
22
- export interface IFormDeleteRequest {
68
+ export interface IFormDeleteRequest extends IFormEffectiveContext {
23
69
  record_id: number;
24
70
  page_id?: number;
71
+ /** The form's section, or the id of the entry list the record belongs to. */
25
72
  section_id: number;
73
+ /**
74
+ * REQUIRED: the record `version` the delete is based on, with the same
75
+ * refusals as {@link IFormUpdateRequest.expected_version} (400 when missing
76
+ * or malformed, 409 `stale_version` when old).
77
+ */
78
+ expected_version: number;
79
+ }
80
+
81
+ /**
82
+ * The rule of an input a value broke (`422 invalid_form_data`). The server
83
+ * checks the CURRENT effective form: `required`, `read_only` and `not_available`
84
+ * (hidden by a condition or not an input of the form), `invalid` (not a value
85
+ * this kind of input takes), `too_many` (selections or files), `type`, `min`,
86
+ * `max`, `max_length`, `format` (email, web address), `option`, `min_date`,
87
+ * `max_date` and `file_type`.
88
+ */
89
+ export type TFormInputRule =
90
+ | 'not_available'
91
+ | 'read_only'
92
+ | 'required'
93
+ | 'invalid'
94
+ | 'too_many'
95
+ | 'type'
96
+ | 'min'
97
+ | 'max'
98
+ | 'max_length'
99
+ | 'format'
100
+ | 'option'
101
+ | 'min_date'
102
+ | 'max_date'
103
+ | 'file_type';
104
+
105
+ /** One refused input of a write. Show `message` at the input named `field`; branch on `rule`, never on the text. */
106
+ export interface IFormInputError {
107
+ /** The input's name, as the person knows it. */
108
+ field: string;
109
+ /** The stable column key of the input (`section_<input id>`). */
110
+ key: string;
111
+ rule: TFormInputRule;
112
+ message: string;
113
+ }
114
+
115
+ /**
116
+ * `data` of the 422 envelope a write answers with when a value breaks the rules
117
+ * of the CURRENT form (a save, a quick action's candidate state or a restore). The
118
+ * whole write is refused: nothing was stored, uploaded or scheduled, so a client
119
+ * keeps the person's draft and files and shows the errors.
120
+ */
121
+ export interface IFormInvalidData {
122
+ reason: 'invalid_form_data';
123
+ errors: IFormInputError[];
26
124
  }
27
125
 
126
+ /**
127
+ * The `data.reason` of the refusals a form or list write can answer with, besides
128
+ * `stale_version` and `restore_blocked` ({@link IFormStaleVersionData},
129
+ * {@link IFormListRestoreBlockedData}) and `invalid_form_data`
130
+ * ({@link IFormInvalidData}). They are statuses of one request, not page state.
131
+ *
132
+ * - 400: `expected_version_required`, `invalid_expected_version`,
133
+ * `unsupported_target_selection`, `protected_field`, `unknown_field`,
134
+ * `invalid_file_value`, `table_mismatch`.
135
+ * - 401 `login_required`: a guest on an own-entries list.
136
+ * - 403: `operation_disabled` (create, update or delete switched off on the list),
137
+ * `history_disabled`, or no right to the page, the record or the table.
138
+ * - 404: `unknown_action`, or a record that is not part of the list's dataset
139
+ * (never a hint whether it exists elsewhere).
140
+ * - 409: `action_not_available` (the action's condition no longer holds).
141
+ */
142
+ export type TFormWriteRefusalReason =
143
+ | 'expected_version_required'
144
+ | 'invalid_expected_version'
145
+ | 'unsupported_target_selection'
146
+ | 'protected_field'
147
+ | 'unknown_field'
148
+ | 'invalid_file_value'
149
+ | 'table_mismatch'
150
+ | 'login_required'
151
+ | 'operation_disabled'
152
+ | 'history_disabled'
153
+ | 'unknown_action'
154
+ | 'action_not_available';
155
+
28
156
  /**
29
157
  * Legacy/aspirational form-result fields.
30
158
  *
@@ -57,6 +185,8 @@ export interface IFormSubmitData extends IFormResultLegacyFields {
57
185
  page_id: number;
58
186
  submitted_at: string;
59
187
  user_authenticated: boolean;
188
+ /** The record's version after the submit (1 for a new record). */
189
+ version: number;
60
190
  }
61
191
 
62
192
  /**
@@ -69,8 +199,23 @@ export interface IFormUpdateData extends IFormResultLegacyFields {
69
199
  section_id: number;
70
200
  page_id: number;
71
201
  updated_at: string;
202
+ /** The record's version after the update. */
203
+ version: number;
204
+ }
205
+
206
+ /**
207
+ * Data returned by a successful DELETE form delete. Mirrors the backend contract
208
+ * `config/schemas/api/v1/responses/frontend/form_deleted.json`. The delete is
209
+ * soft: the record's history is kept.
210
+ */
211
+ export interface IFormDeleteData extends IFormResultLegacyFields {
212
+ record_id: number;
213
+ section_id?: number;
214
+ page_id?: number;
215
+ /** The record's version after the delete. */
216
+ version: number;
72
217
  }
73
218
 
74
219
  export type IFormSubmitResponse = IBaseApiResponse<IFormSubmitData>;
75
220
  export type IFormUpdateResponse = IBaseApiResponse<IFormUpdateData>;
76
- export type IFormDeleteResponse = IBaseApiResponse<{ success: boolean; message?: string }>;
221
+ export type IFormDeleteResponse = IBaseApiResponse<IFormDeleteData>;
@@ -5,6 +5,7 @@ SPDX-License-Identifier: MPL-2.0
5
5
  export * from './envelope';
6
6
  export * from './auth';
7
7
  export * from './forms';
8
+ export * from './form-lists';
8
9
  export * from './language';
9
10
  export * from './page';
10
11
  export * from './system';