jsfe 1.43.0 → 1.44.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/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm i jsfe
|
|
|
14
14
|
- **[README.md](README.md)** - Technical API reference (this document)
|
|
15
15
|
- **[Flows architecture guide](docs/architecture-guide.md)** - start here: the concepts, the building blocks, what the caller experiences, and how conversational AI and exact transactional flows work together (the reply ranker and DISPATCH)
|
|
16
16
|
- **[Flow author reference](docs/copilot-reference.md)** - the authoritative engine and JSON authoring specification for flow authors and AI flow generators (shipped in the package; the Flow Designer's CoPilot reads it from the published version, so change it with the engine)
|
|
17
|
-
- **[Form client adapter](docs/form-client.md)** - optional: a host renders the pending FORM question as a form for a capable client and reads its strict named submission through the same FORM workers
|
|
17
|
+
- **[Form client adapter](docs/form-client.md)** - optional: a host renders the pending FORM question as a form for a capable client and reads its strict named submission through the same FORM workers; an input may name its control (`form_client`: date, date range, number; jsfe 1.44.0)
|
|
18
18
|
- **[Development candidate acceptance](docs/development-release.md)** - reproducible package and cross-repository verification
|
|
19
19
|
- **[System Flows](docs/flows/system/README.md)** and **[Shopify Flows](docs/flows/shopify/README.md)** - the bundled flow and tool libraries in `flows/`: a page and a chart per flow, generated from the JSON (`node scripts/flow-docs.mjs`), plus the conventions the system flows share
|
|
20
20
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/forms/flows.js"],"names":[],"mappings":"AAgHA;;;;;;;GAOG;AACH;;;;GAIG;AACH,8HAA8H;AAC9H,uFAIC;
|
|
1
|
+
{"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/forms/flows.js"],"names":[],"mappings":"AAgHA;;;;;;;GAOG;AACH;;;;GAIG;AACH,8HAA8H;AAC9H,uFAIC;AAuDD;;2EAE2E;AAC3E,qEAEC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsEC;AACD;;;GAGG;AACH;;;;;;EAGC;AA+lBD,wHAAwH;AACxH,wEAaC;AACD,4FAA4F;AAC5F;;;EAYC;AACD,sGAAsG;AACtG;;;EAOC;AAv2BM,6CAAuG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAikC9G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAOG"}
|
package/dist/forms/flows.js
CHANGED
|
@@ -148,6 +148,63 @@ function validateAcceptanceDeclarations(id, inputs) {
|
|
|
148
148
|
else { /* no invites, or a list of names */ }
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* input.form_client: false (never on a form card) or the control a form card draws for it (docs/form-client.md):
|
|
153
|
+
* {control: 'date', range_from?, min?, max?, timezone?} or {control: 'number', min?, max?}. A date's min and max are whole
|
|
154
|
+
* days from today in `timezone` (required with either); range_from names the start of a range, a date input of this
|
|
155
|
+
* form that is not itself an end. A number's min and max bound its value. Checked at definition time; malformed fails.
|
|
156
|
+
*/
|
|
157
|
+
const FORM_CLIENT_KEYS = { date: ['control', 'range_from', 'min', 'max', 'timezone'], number: ['control', 'min', 'max'] };
|
|
158
|
+
const FORM_CLIENT_KINDS = ['pattern', 'text', 'digits', 'amount', 'identifier'];
|
|
159
|
+
function validateFormClientControls(id, inputs) {
|
|
160
|
+
const all = (inputs || []).flatMap((input) => input.any_of || [input]);
|
|
161
|
+
const fail = (input, message) => { throw new Error(`FORM ${id}: ${input.name} form_client ${message}`); };
|
|
162
|
+
for (const input of all) {
|
|
163
|
+
const declared = input.form_client;
|
|
164
|
+
if (declared === undefined || declared === false)
|
|
165
|
+
continue;
|
|
166
|
+
else if (!declared || typeof declared !== 'object' || Array.isArray(declared))
|
|
167
|
+
fail(input, 'must be false or {control, ...}');
|
|
168
|
+
else if (!Object.hasOwn(FORM_CLIENT_KEYS, declared.control))
|
|
169
|
+
fail(input, 'control must be "date" or "number"');
|
|
170
|
+
else { /* a control object, checked below */ }
|
|
171
|
+
const extra = Object.keys(declared).filter((key) => !FORM_CLIENT_KEYS[declared.control].includes(key));
|
|
172
|
+
if (extra.length)
|
|
173
|
+
fail(input, `${declared.control} cannot declare ${extra.join(', ')}`);
|
|
174
|
+
if (!FORM_CLIENT_KINDS.includes(input.profile?.kind))
|
|
175
|
+
fail(input, `control needs a profile of kind ${FORM_CLIENT_KINDS.join(', ')}`);
|
|
176
|
+
if (input.pii === true)
|
|
177
|
+
fail(input, 'control cannot draw a sensitive input');
|
|
178
|
+
for (const key of ['min', 'max'])
|
|
179
|
+
if (declared[key] !== undefined && !Number.isInteger(declared[key]))
|
|
180
|
+
fail(input, `${key} must be a whole number`);
|
|
181
|
+
if (Number.isInteger(declared.min) && Number.isInteger(declared.max) && declared.min > declared.max)
|
|
182
|
+
fail(input, 'min is above max');
|
|
183
|
+
if (declared.control === 'date') {
|
|
184
|
+
if ((declared.min !== undefined || declared.max !== undefined) && declared.timezone === undefined)
|
|
185
|
+
fail(input, 'min and max are days from today: declare the timezone they count in');
|
|
186
|
+
if (declared.timezone !== undefined) {
|
|
187
|
+
try {
|
|
188
|
+
new Intl.DateTimeFormat('en-CA', { timeZone: declared.timezone });
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
fail(input, `timezone ${JSON.stringify(declared.timezone)} is not an IANA time zone`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else { /* no bounds, no time zone */ }
|
|
195
|
+
if (declared.range_from !== undefined) {
|
|
196
|
+
const start = all.find((other) => other.name === declared.range_from);
|
|
197
|
+
if (!start || start === input)
|
|
198
|
+
fail(input, 'range_from must name another input of this form');
|
|
199
|
+
else if (start.form_client?.control !== 'date' || start.form_client.range_from !== undefined)
|
|
200
|
+
fail(input, `range_from ${start.name} must be a date control that is not itself a range end`);
|
|
201
|
+
else { /* a valid range start */ }
|
|
202
|
+
}
|
|
203
|
+
else { /* a single date or a range start */ }
|
|
204
|
+
}
|
|
205
|
+
else { /* a number */ }
|
|
206
|
+
}
|
|
207
|
+
}
|
|
151
208
|
/** How firm a form's confirmation is: firm ONLY when an action it authorizes is a payment (effect 'charge'); every other
|
|
152
209
|
* confirmation is soft, a plain form's (no action) included (owner 2026-11-09). confirm.exact is separate: it binds the
|
|
153
210
|
* action to the confirmed values, whatever the confirmation's firmness. */
|
|
@@ -163,6 +220,7 @@ export function formFlow({ id, name, version, description, inputs, after = [], e
|
|
|
163
220
|
if (typeof must_complete !== 'boolean')
|
|
164
221
|
throw new Error(`FORM ${id}: must_complete must be true or false`);
|
|
165
222
|
validateAcceptanceDeclarations(id, inputs);
|
|
223
|
+
validateFormClientControls(id, inputs);
|
|
166
224
|
if (confirm && typeof confirm === 'object')
|
|
167
225
|
validateRankParameters(id, 'confirm', 'rank_parameters', confirm.rank_parameters);
|
|
168
226
|
else { /* no confirmation */ }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-client.d.ts","sourceRoot":"","sources":["../../src/forms/form-client.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"form-client.d.ts","sourceRoot":"","sources":["../../src/forms/form-client.js"],"names":[],"mappings":"AAiCA,iGAAiG;AACjG;;;;;SAsFC;AAED,+GAA+G;AAC/G;;;;SAgCC;AAED;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BC;AAvLD,qCAAsC,eAAe,CAAC"}
|
|
@@ -27,6 +27,11 @@ const pendingForm = session => {
|
|
|
27
27
|
}
|
|
28
28
|
return { state, context };
|
|
29
29
|
};
|
|
30
|
+
/** Today in an IANA time zone, moved by whole days, as YYYY-MM-DD (UTC arithmetic: no DST shift). */
|
|
31
|
+
function daysFromToday(days, timeZone) {
|
|
32
|
+
const [year, month, day] = new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date()).split('-').map(Number);
|
|
33
|
+
return new Date(Date.UTC(year, month - 1, day + days)).toISOString().slice(0, 10);
|
|
34
|
+
}
|
|
30
35
|
/** A public rendering projection, never a serialized flow, executable expression, or session. */
|
|
31
36
|
export function projectForm(session, flows) {
|
|
32
37
|
if (flows && Object.values(session?.cargo?.forms || {}).some(state => state?.derived)) {
|
|
@@ -104,6 +109,17 @@ export function projectForm(session, flows) {
|
|
|
104
109
|
continue;
|
|
105
110
|
}
|
|
106
111
|
field.constraints = Object.fromEntries(['min', 'max'].filter(key => typeof profile[key] === 'number').map(key => [key, profile[key]]));
|
|
112
|
+
// The control the input declares (validated at definition time). Its bounds replace the profile's, which for
|
|
113
|
+
// some kinds are lengths: a number's are values, a date's are days from today turned into YYYY-MM-DD dates.
|
|
114
|
+
const control = input.form_client?.control;
|
|
115
|
+
if (control === 'number' || control === 'date') {
|
|
116
|
+
field.control = control;
|
|
117
|
+
field.constraints = Object.fromEntries(['min', 'max'].filter(key => Number.isInteger(input.form_client[key]))
|
|
118
|
+
.map(key => [key, control === 'date' ? daysFromToday(input.form_client[key], input.form_client.timezone) : input.form_client[key]]));
|
|
119
|
+
if (control === 'date' && input.form_client.range_from)
|
|
120
|
+
field.range_from = prefix + input.form_client.range_from;
|
|
121
|
+
}
|
|
122
|
+
else { /* the profile's own box */ }
|
|
107
123
|
if (!field.sensitive && ['string', 'number', 'boolean'].includes(typeof state.values?.[input.name]))
|
|
108
124
|
field.value = state.values[input.name];
|
|
109
125
|
// A worded refusal is shown with its field; the bare 'invalid' flag (a refusal with no message, or a whole-form
|
package/dist/runtime-identity.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const JSFE_RUNTIME_FINGERPRINT = "sha256:
|
|
1
|
+
export const JSFE_RUNTIME_FINGERPRINT = "sha256:eb871898cda6efbbfc0eb7229f79d74168ed50f1a3a3e102cc29f345b72acb36";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsfe",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.44.0",
|
|
4
4
|
"description": "TypeScript workflow engine for conversational/automation apps: multi-flow orchestration, interrupt/resume, stack-based control, robust errors, and flexible tool/REST integration.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ron Pinkas",
|