@formigio/fazemos-cli 0.11.1 → 0.12.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/commands/asset/index.d.ts +4 -1
- package/dist/commands/asset/index.js +9 -3
- package/dist/commands/asset/index.js.map +1 -1
- package/dist/commands/asset/list.d.ts +44 -0
- package/dist/commands/asset/list.js +198 -0
- package/dist/commands/asset/list.js.map +1 -0
- package/dist/commands/asset/put.js +31 -0
- package/dist/commands/asset/put.js.map +1 -1
- package/dist/dispatch.d.ts +8 -1
- package/dist/dispatch.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +206 -8
- package/dist/index.js.map +1 -1
- package/dist/lib/dispatchForm.d.ts +112 -0
- package/dist/lib/dispatchForm.js +263 -0
- package/dist/lib/dispatchForm.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* F84 S1 C1: a vendored client copy of the dispatch form schema (v1).
|
|
3
|
+
*
|
|
4
|
+
* CANONICAL: fazemos-api `src/services/dispatchFormValidator.ts`. That file
|
|
5
|
+
* exports the limits as constants (tech spec §1 AC-9, manifest A1). This
|
|
6
|
+
* module mirrors them so `fazemos dispatch <to> question --form-file` can
|
|
7
|
+
* fail fast, offline, with the same named 400 codes the API returns.
|
|
8
|
+
*
|
|
9
|
+
* The API is the contract and this file conforms. Two rules follow:
|
|
10
|
+
* 1. Any limit stated in the spec (tech spec §2.1 + manifest
|
|
11
|
+
* `form_payload_v1`) is enforced here exactly.
|
|
12
|
+
* 2. Where the spec is silent, this copy is PERMISSIVE. A client mirror
|
|
13
|
+
* must never refuse a form the server would accept. Anything looser
|
|
14
|
+
* here is still caught by the server's 400.
|
|
15
|
+
*
|
|
16
|
+
* Drift is pinned in `src/cli-api-contract.test.ts` ("F84 C1 vendored form
|
|
17
|
+
* schema drift pin"). One leg pins these values to the spec literals and
|
|
18
|
+
* always runs. The other compares them, name for name, with the api's
|
|
19
|
+
* exported constants when a sibling fazemos-api checkout is present (or
|
|
20
|
+
* FAZEMOS_API_REPO points at one).
|
|
21
|
+
*
|
|
22
|
+
* AT-12-03 / ED-12-03q (12-03/12-04): the vendored constants below were
|
|
23
|
+
* renamed to match the api's exported names exactly (previously this file
|
|
24
|
+
* used shorter aliases — FORM_VERSION, FORM_ASK_MAX, etc — that the drift
|
|
25
|
+
* pin's "leg 2" name-for-name comparison could never match, since the api
|
|
26
|
+
* never exported those shorter names). `ANSWER_OTHER_TEXT_MAX_LENGTH` and
|
|
27
|
+
* `ANSWER_NOTE_MAX_LENGTH` are intentionally NOT vendored here: this module
|
|
28
|
+
* only validates an outbound form_payload_v1 (the `--form-file` question
|
|
29
|
+
* payload); the CLI has no offline-constructed/validated answer payload
|
|
30
|
+
* (answers are submitted by other callers and merely read back by
|
|
31
|
+
* `dispatch answer`, src/index.ts), so there is nothing here that needs
|
|
32
|
+
* those two limits.
|
|
33
|
+
*/
|
|
34
|
+
export declare const FORM_PAYLOAD_VERSION = 1;
|
|
35
|
+
export declare const FORM_ASK_MAX_LENGTH = 1000;
|
|
36
|
+
export declare const FORM_QUESTIONS_MIN = 1;
|
|
37
|
+
export declare const FORM_QUESTIONS_MAX = 4;
|
|
38
|
+
export declare const FORM_OPTIONS_MIN = 2;
|
|
39
|
+
export declare const FORM_OPTIONS_MAX = 4;
|
|
40
|
+
export declare const FORM_QUESTION_HEADER_MAX_LENGTH = 12;
|
|
41
|
+
export declare const FORM_QUESTION_TEXT_MAX_LENGTH = 300;
|
|
42
|
+
export declare const FORM_OPTION_VALUE_MAX_LENGTH = 40;
|
|
43
|
+
export declare const FORM_OPTION_LABEL_MAX_LENGTH = 40;
|
|
44
|
+
export declare const FORM_OPTION_DESCRIPTION_MAX_LENGTH = 160;
|
|
45
|
+
export declare const FORM_MAX_RECOMMENDED_PER_QUESTION = 1;
|
|
46
|
+
export declare const FORM_EVIDENCE_PROVENANCE: readonly ["OBSERVED", "CARRIED"];
|
|
47
|
+
export declare const FORM_EVIDENCE_ALLOWED_URL_SCHEMES: readonly ["http:", "https:"];
|
|
48
|
+
/** R3 retract `reason` is 1..300 chars (tech spec §3 R3). Not an api-side
|
|
49
|
+
* form_payload_v1 limit, so it keeps its CLI-local name (no rename target). */
|
|
50
|
+
export declare const RETRACT_REASON_MAX = 300;
|
|
51
|
+
/** The named 400 codes from tech spec §2.1. */
|
|
52
|
+
export declare const FORM_ERROR_CODES: readonly ["FORM_TYPE_NOT_QUESTION", "FORM_EXPIRES_AT_REQUIRED", "FORM_QUESTION_COUNT", "FORM_OPTION_COUNT", "FORM_MULTIPLE_RECOMMENDED", "FORM_FIELD_TOO_LONG", "FORM_DEFAULT_ON_EXPIRY_FORBIDDEN", "FORM_DUPLICATE_ID", "FORM_SCHEMA", "FORM_EXPIRES_AT_PAST"];
|
|
53
|
+
export type FormErrorCode = (typeof FORM_ERROR_CODES)[number];
|
|
54
|
+
export interface FormError {
|
|
55
|
+
code: FormErrorCode;
|
|
56
|
+
path: string;
|
|
57
|
+
message: string;
|
|
58
|
+
/** Present on FORM_FIELD_TOO_LONG, mirroring the api's `details[{path,max}]`. */
|
|
59
|
+
max?: number;
|
|
60
|
+
}
|
|
61
|
+
export interface DispatchFormOption {
|
|
62
|
+
value: string;
|
|
63
|
+
label: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
recommended?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface DispatchFormQuestion {
|
|
68
|
+
id: string;
|
|
69
|
+
header: string;
|
|
70
|
+
text: string;
|
|
71
|
+
multi_select?: boolean;
|
|
72
|
+
options: DispatchFormOption[];
|
|
73
|
+
}
|
|
74
|
+
export interface DispatchFormEvidence {
|
|
75
|
+
label: string;
|
|
76
|
+
url: string;
|
|
77
|
+
provenance: (typeof FORM_EVIDENCE_PROVENANCE)[number];
|
|
78
|
+
}
|
|
79
|
+
export interface DispatchFormV1 {
|
|
80
|
+
version: 1;
|
|
81
|
+
ask: string;
|
|
82
|
+
questions: DispatchFormQuestion[];
|
|
83
|
+
evidence?: DispatchFormEvidence[];
|
|
84
|
+
default_on_expiry?: null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Validate the form payload itself (tech spec §2.1). Returns every error
|
|
88
|
+
* found, so the operator can fix the file in a single edit.
|
|
89
|
+
*/
|
|
90
|
+
export declare function validateDispatchForm(form: unknown): FormError[];
|
|
91
|
+
/**
|
|
92
|
+
* Validate the dispatch envelope a form travels in: the form is
|
|
93
|
+
* question-only and needs a future `expires_at` (CHECK
|
|
94
|
+
* `dispatches_form_question_only` + FORM_EXPIRES_AT_PAST).
|
|
95
|
+
*/
|
|
96
|
+
export declare function validateFormEnvelope(type: string, expiresAt: string | undefined, now?: Date): FormError[];
|
|
97
|
+
export declare function formatFormErrors(errors: FormError[]): string;
|
|
98
|
+
/**
|
|
99
|
+
* Decide what `fazemos dispatch answer` prints from an R4 body. An answered
|
|
100
|
+
* form with a latest answer prints that answer. Every other state prints
|
|
101
|
+
* `{form_state}`, with `pending` reported as `open` (tech spec §4 C2).
|
|
102
|
+
*/
|
|
103
|
+
export declare function selectAnswerOutput(r4: {
|
|
104
|
+
form_state?: string | null;
|
|
105
|
+
latest_answer?: unknown;
|
|
106
|
+
}): {
|
|
107
|
+
kind: 'answer';
|
|
108
|
+
answer: unknown;
|
|
109
|
+
} | {
|
|
110
|
+
kind: 'state';
|
|
111
|
+
form_state: string | null;
|
|
112
|
+
};
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* F84 S1 C1: a vendored client copy of the dispatch form schema (v1).
|
|
3
|
+
*
|
|
4
|
+
* CANONICAL: fazemos-api `src/services/dispatchFormValidator.ts`. That file
|
|
5
|
+
* exports the limits as constants (tech spec §1 AC-9, manifest A1). This
|
|
6
|
+
* module mirrors them so `fazemos dispatch <to> question --form-file` can
|
|
7
|
+
* fail fast, offline, with the same named 400 codes the API returns.
|
|
8
|
+
*
|
|
9
|
+
* The API is the contract and this file conforms. Two rules follow:
|
|
10
|
+
* 1. Any limit stated in the spec (tech spec §2.1 + manifest
|
|
11
|
+
* `form_payload_v1`) is enforced here exactly.
|
|
12
|
+
* 2. Where the spec is silent, this copy is PERMISSIVE. A client mirror
|
|
13
|
+
* must never refuse a form the server would accept. Anything looser
|
|
14
|
+
* here is still caught by the server's 400.
|
|
15
|
+
*
|
|
16
|
+
* Drift is pinned in `src/cli-api-contract.test.ts` ("F84 C1 vendored form
|
|
17
|
+
* schema drift pin"). One leg pins these values to the spec literals and
|
|
18
|
+
* always runs. The other compares them, name for name, with the api's
|
|
19
|
+
* exported constants when a sibling fazemos-api checkout is present (or
|
|
20
|
+
* FAZEMOS_API_REPO points at one).
|
|
21
|
+
*
|
|
22
|
+
* AT-12-03 / ED-12-03q (12-03/12-04): the vendored constants below were
|
|
23
|
+
* renamed to match the api's exported names exactly (previously this file
|
|
24
|
+
* used shorter aliases — FORM_VERSION, FORM_ASK_MAX, etc — that the drift
|
|
25
|
+
* pin's "leg 2" name-for-name comparison could never match, since the api
|
|
26
|
+
* never exported those shorter names). `ANSWER_OTHER_TEXT_MAX_LENGTH` and
|
|
27
|
+
* `ANSWER_NOTE_MAX_LENGTH` are intentionally NOT vendored here: this module
|
|
28
|
+
* only validates an outbound form_payload_v1 (the `--form-file` question
|
|
29
|
+
* payload); the CLI has no offline-constructed/validated answer payload
|
|
30
|
+
* (answers are submitted by other callers and merely read back by
|
|
31
|
+
* `dispatch answer`, src/index.ts), so there is nothing here that needs
|
|
32
|
+
* those two limits.
|
|
33
|
+
*/
|
|
34
|
+
// ── Limits (names match the api's exported constants exactly) ──────────────
|
|
35
|
+
export const FORM_PAYLOAD_VERSION = 1;
|
|
36
|
+
export const FORM_ASK_MAX_LENGTH = 1000;
|
|
37
|
+
export const FORM_QUESTIONS_MIN = 1;
|
|
38
|
+
export const FORM_QUESTIONS_MAX = 4;
|
|
39
|
+
export const FORM_OPTIONS_MIN = 2;
|
|
40
|
+
export const FORM_OPTIONS_MAX = 4;
|
|
41
|
+
export const FORM_QUESTION_HEADER_MAX_LENGTH = 12;
|
|
42
|
+
export const FORM_QUESTION_TEXT_MAX_LENGTH = 300;
|
|
43
|
+
export const FORM_OPTION_VALUE_MAX_LENGTH = 40;
|
|
44
|
+
export const FORM_OPTION_LABEL_MAX_LENGTH = 40;
|
|
45
|
+
export const FORM_OPTION_DESCRIPTION_MAX_LENGTH = 160;
|
|
46
|
+
export const FORM_MAX_RECOMMENDED_PER_QUESTION = 1;
|
|
47
|
+
export const FORM_EVIDENCE_PROVENANCE = ['OBSERVED', 'CARRIED'];
|
|
48
|
+
export const FORM_EVIDENCE_ALLOWED_URL_SCHEMES = ['http:', 'https:'];
|
|
49
|
+
/** R3 retract `reason` is 1..300 chars (tech spec §3 R3). Not an api-side
|
|
50
|
+
* form_payload_v1 limit, so it keeps its CLI-local name (no rename target). */
|
|
51
|
+
export const RETRACT_REASON_MAX = 300;
|
|
52
|
+
/** The named 400 codes from tech spec §2.1. */
|
|
53
|
+
export const FORM_ERROR_CODES = [
|
|
54
|
+
'FORM_TYPE_NOT_QUESTION',
|
|
55
|
+
'FORM_EXPIRES_AT_REQUIRED',
|
|
56
|
+
'FORM_QUESTION_COUNT',
|
|
57
|
+
'FORM_OPTION_COUNT',
|
|
58
|
+
'FORM_MULTIPLE_RECOMMENDED',
|
|
59
|
+
'FORM_FIELD_TOO_LONG',
|
|
60
|
+
'FORM_DEFAULT_ON_EXPIRY_FORBIDDEN',
|
|
61
|
+
'FORM_DUPLICATE_ID',
|
|
62
|
+
'FORM_SCHEMA',
|
|
63
|
+
'FORM_EXPIRES_AT_PAST',
|
|
64
|
+
];
|
|
65
|
+
// ── Validation ─────────────────────────────────────────────────────────────
|
|
66
|
+
function isPlainObject(v) {
|
|
67
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Validate the form payload itself (tech spec §2.1). Returns every error
|
|
71
|
+
* found, so the operator can fix the file in a single edit.
|
|
72
|
+
*/
|
|
73
|
+
export function validateDispatchForm(form) {
|
|
74
|
+
const errors = [];
|
|
75
|
+
const push = (code, path, message, max) => {
|
|
76
|
+
errors.push(max === undefined ? { code, path, message } : { code, path, message, max });
|
|
77
|
+
};
|
|
78
|
+
const checkString = (v, path, max, opts) => {
|
|
79
|
+
if (v === undefined || v === null) {
|
|
80
|
+
if (opts.required)
|
|
81
|
+
push('FORM_SCHEMA', path, `${path} is required`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (typeof v !== 'string') {
|
|
85
|
+
push('FORM_SCHEMA', path, `${path} must be a string`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (opts.minLen !== undefined && v.length < opts.minLen) {
|
|
89
|
+
push('FORM_SCHEMA', path, `${path} must not be empty`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (v.length > max) {
|
|
93
|
+
push('FORM_FIELD_TOO_LONG', path, `${path} is ${v.length} chars (max ${max})`, max);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
if (!isPlainObject(form)) {
|
|
97
|
+
push('FORM_SCHEMA', '', 'form must be a JSON object');
|
|
98
|
+
return errors;
|
|
99
|
+
}
|
|
100
|
+
if (form.version !== FORM_PAYLOAD_VERSION) {
|
|
101
|
+
push('FORM_SCHEMA', 'version', `version must be ${FORM_PAYLOAD_VERSION} (got ${JSON.stringify(form.version)})`);
|
|
102
|
+
// An unknown version means the rest of the shape is not ours to judge.
|
|
103
|
+
return errors;
|
|
104
|
+
}
|
|
105
|
+
checkString(form.ask, 'ask', FORM_ASK_MAX_LENGTH, { required: true, minLen: 1 });
|
|
106
|
+
if ('default_on_expiry' in form && form.default_on_expiry !== null && form.default_on_expiry !== undefined) {
|
|
107
|
+
push('FORM_DEFAULT_ON_EXPIRY_FORBIDDEN', 'default_on_expiry', 'default_on_expiry must be null: an unanswered form expires loudly and never decides');
|
|
108
|
+
}
|
|
109
|
+
const questions = form.questions;
|
|
110
|
+
if (!Array.isArray(questions)) {
|
|
111
|
+
push('FORM_SCHEMA', 'questions', 'questions must be an array');
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (questions.length < FORM_QUESTIONS_MIN || questions.length > FORM_QUESTIONS_MAX) {
|
|
115
|
+
push('FORM_QUESTION_COUNT', 'questions', `questions has ${questions.length} entries (allowed ${FORM_QUESTIONS_MIN}..${FORM_QUESTIONS_MAX})`);
|
|
116
|
+
}
|
|
117
|
+
const seenQuestionIds = new Set();
|
|
118
|
+
questions.forEach((q, qi) => {
|
|
119
|
+
const qp = `questions[${qi}]`;
|
|
120
|
+
if (!isPlainObject(q)) {
|
|
121
|
+
push('FORM_SCHEMA', qp, `${qp} must be an object`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
checkString(q.id, `${qp}.id`, Number.POSITIVE_INFINITY, { required: true, minLen: 1 });
|
|
125
|
+
if (typeof q.id === 'string' && q.id.length > 0) {
|
|
126
|
+
if (seenQuestionIds.has(q.id)) {
|
|
127
|
+
push('FORM_DUPLICATE_ID', `${qp}.id`, `duplicate question id "${q.id}"`);
|
|
128
|
+
}
|
|
129
|
+
seenQuestionIds.add(q.id);
|
|
130
|
+
}
|
|
131
|
+
checkString(q.header, `${qp}.header`, FORM_QUESTION_HEADER_MAX_LENGTH, { required: true, minLen: 1 });
|
|
132
|
+
checkString(q.text, `${qp}.text`, FORM_QUESTION_TEXT_MAX_LENGTH, { required: true, minLen: 1 });
|
|
133
|
+
if (q.multi_select !== undefined && typeof q.multi_select !== 'boolean') {
|
|
134
|
+
push('FORM_SCHEMA', `${qp}.multi_select`, `${qp}.multi_select must be a boolean`);
|
|
135
|
+
}
|
|
136
|
+
const options = q.options;
|
|
137
|
+
if (!Array.isArray(options)) {
|
|
138
|
+
push('FORM_SCHEMA', `${qp}.options`, `${qp}.options must be an array`);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (options.length < FORM_OPTIONS_MIN || options.length > FORM_OPTIONS_MAX) {
|
|
142
|
+
push('FORM_OPTION_COUNT', `${qp}.options`, `${qp}.options has ${options.length} entries (allowed ${FORM_OPTIONS_MIN}..${FORM_OPTIONS_MAX})`);
|
|
143
|
+
}
|
|
144
|
+
const seenValues = new Set();
|
|
145
|
+
let recommended = 0;
|
|
146
|
+
options.forEach((o, oi) => {
|
|
147
|
+
const op = `${qp}.options[${oi}]`;
|
|
148
|
+
if (!isPlainObject(o)) {
|
|
149
|
+
push('FORM_SCHEMA', op, `${op} must be an object`);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
checkString(o.value, `${op}.value`, FORM_OPTION_VALUE_MAX_LENGTH, { required: true, minLen: 1 });
|
|
153
|
+
if (typeof o.value === 'string' && o.value.length > 0) {
|
|
154
|
+
if (seenValues.has(o.value)) {
|
|
155
|
+
push('FORM_DUPLICATE_ID', `${op}.value`, `duplicate option value "${o.value}" in ${qp}`);
|
|
156
|
+
}
|
|
157
|
+
seenValues.add(o.value);
|
|
158
|
+
}
|
|
159
|
+
checkString(o.label, `${op}.label`, FORM_OPTION_LABEL_MAX_LENGTH, { required: true, minLen: 1 });
|
|
160
|
+
checkString(o.description, `${op}.description`, FORM_OPTION_DESCRIPTION_MAX_LENGTH, { required: false });
|
|
161
|
+
if (o.recommended !== undefined && typeof o.recommended !== 'boolean') {
|
|
162
|
+
push('FORM_SCHEMA', `${op}.recommended`, `${op}.recommended must be a boolean`);
|
|
163
|
+
}
|
|
164
|
+
if (o.recommended === true)
|
|
165
|
+
recommended++;
|
|
166
|
+
});
|
|
167
|
+
if (recommended > FORM_MAX_RECOMMENDED_PER_QUESTION) {
|
|
168
|
+
push('FORM_MULTIPLE_RECOMMENDED', `${qp}.options`, `${qp} marks ${recommended} options recommended (max ${FORM_MAX_RECOMMENDED_PER_QUESTION})`);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (form.evidence !== undefined && form.evidence !== null) {
|
|
173
|
+
if (!Array.isArray(form.evidence)) {
|
|
174
|
+
push('FORM_SCHEMA', 'evidence', 'evidence must be an array');
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
form.evidence.forEach((e, ei) => {
|
|
178
|
+
const ep = `evidence[${ei}]`;
|
|
179
|
+
if (!isPlainObject(e)) {
|
|
180
|
+
push('FORM_SCHEMA', ep, `${ep} must be an object`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
checkString(e.label, `${ep}.label`, Number.POSITIVE_INFINITY, { required: true, minLen: 1 });
|
|
184
|
+
if (typeof e.url !== 'string') {
|
|
185
|
+
push('FORM_SCHEMA', `${ep}.url`, `${ep}.url must be a string`);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
let scheme = null;
|
|
189
|
+
try {
|
|
190
|
+
scheme = new URL(e.url).protocol;
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
scheme = null;
|
|
194
|
+
}
|
|
195
|
+
if (!scheme || !FORM_EVIDENCE_ALLOWED_URL_SCHEMES.includes(scheme)) {
|
|
196
|
+
push('FORM_SCHEMA', `${ep}.url`, `${ep}.url must be an http(s) URL`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (!FORM_EVIDENCE_PROVENANCE.includes(e.provenance)) {
|
|
200
|
+
push('FORM_SCHEMA', `${ep}.provenance`, `${ep}.provenance must be one of ${FORM_EVIDENCE_PROVENANCE.join(' | ')}`);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return errors;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Validate the dispatch envelope a form travels in: the form is
|
|
209
|
+
* question-only and needs a future `expires_at` (CHECK
|
|
210
|
+
* `dispatches_form_question_only` + FORM_EXPIRES_AT_PAST).
|
|
211
|
+
*/
|
|
212
|
+
export function validateFormEnvelope(type, expiresAt, now = new Date()) {
|
|
213
|
+
const errors = [];
|
|
214
|
+
if (type !== 'question') {
|
|
215
|
+
errors.push({
|
|
216
|
+
code: 'FORM_TYPE_NOT_QUESTION',
|
|
217
|
+
path: 'type',
|
|
218
|
+
message: `--form-file is only allowed with type "question" (got "${type}")`,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (!expiresAt) {
|
|
222
|
+
errors.push({
|
|
223
|
+
code: 'FORM_EXPIRES_AT_REQUIRED',
|
|
224
|
+
path: 'expires_at',
|
|
225
|
+
message: '--form-file requires --expires-at <iso>',
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
const t = Date.parse(expiresAt);
|
|
230
|
+
if (Number.isNaN(t)) {
|
|
231
|
+
errors.push({
|
|
232
|
+
code: 'FORM_SCHEMA',
|
|
233
|
+
path: 'expires_at',
|
|
234
|
+
message: `--expires-at "${expiresAt}" is not a valid ISO 8601 timestamp`,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
else if (t <= now.getTime()) {
|
|
238
|
+
errors.push({
|
|
239
|
+
code: 'FORM_EXPIRES_AT_PAST',
|
|
240
|
+
path: 'expires_at',
|
|
241
|
+
message: `--expires-at "${expiresAt}" is not in the future`,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return errors;
|
|
246
|
+
}
|
|
247
|
+
export function formatFormErrors(errors) {
|
|
248
|
+
return errors.map((e) => ` ${e.code}${e.path ? ` (${e.path})` : ''}: ${e.message}`).join('\n');
|
|
249
|
+
}
|
|
250
|
+
// ── C2: answer read-back shape (R4) ────────────────────────────────────────
|
|
251
|
+
/**
|
|
252
|
+
* Decide what `fazemos dispatch answer` prints from an R4 body. An answered
|
|
253
|
+
* form with a latest answer prints that answer. Every other state prints
|
|
254
|
+
* `{form_state}`, with `pending` reported as `open` (tech spec §4 C2).
|
|
255
|
+
*/
|
|
256
|
+
export function selectAnswerOutput(r4) {
|
|
257
|
+
const raw = r4.form_state ?? null;
|
|
258
|
+
if (raw === 'answered' && r4.latest_answer != null) {
|
|
259
|
+
return { kind: 'answer', answer: r4.latest_answer };
|
|
260
|
+
}
|
|
261
|
+
return { kind: 'state', form_state: raw === 'pending' ? 'open' : raw };
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=dispatchForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatchForm.js","sourceRoot":"","sources":["../../src/lib/dispatchForm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,8EAA8E;AAE9E,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACxC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAClC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAClC,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,CAAC;AAClD,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AACjD,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAC/C,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAC/C,MAAM,CAAC,MAAM,kCAAkC,GAAG,GAAG,CAAC;AACtD,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,CAAC;AACnD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,UAAU,EAAE,SAAS,CAAU,CAAC;AACzE,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAU,CAAC;AAC9E;+EAC+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAEtC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,gBAAgB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