jsfe 1.9.1 → 1.9.3
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/forms/address-flows.d.ts.map +1 -1
- package/dist/forms/address-flows.js +18 -12
- package/dist/forms/contracts.d.ts +1 -0
- package/dist/forms/contracts.d.ts.map +1 -1
- package/dist/forms/flows.d.ts +1 -0
- package/dist/forms/flows.d.ts.map +1 -1
- package/dist/forms/flows.js +13 -5
- package/dist/helpers/address.d.ts +2 -0
- package/dist/helpers/address.d.ts.map +1 -1
- package/dist/helpers/address.js +9 -2
- package/dist/helpers/form-conversation.d.ts.map +1 -1
- package/dist/helpers/form-conversation.js +2 -0
- package/dist/runtime-identity.js +1 -1
- package/docs/development-release.md +11 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address-flows.d.ts","sourceRoot":"","sources":["../../src/forms/address-flows.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"address-flows.d.ts","sourceRoot":"","sources":["../../src/forms/address-flows.js"],"names":[],"mappings":"AA4CA,0BAAmF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Shared geocoded mailing-address collector over host-provided geocode tools. */
|
|
2
2
|
import { defineForm, defineWorker } from './contracts.js';
|
|
3
|
-
import { addressDraft, zipLocation, streetLocation, resolvedAddress } from '../helpers/address.js';
|
|
3
|
+
import { addressDraft, zipLocation, cityChoices, streetLocation, resolvedAddress } from '../helpers/address.js';
|
|
4
4
|
const S = (id, variable, value) => ({ id, type: 'SET', variable, value });
|
|
5
5
|
const F = (id, value, parameters = {}, callType = 'call') => ({ id, type: 'FLOW', value, parameters, callType });
|
|
6
6
|
const W = (id, condition, step) => ({ id, type: 'CASE', branches: { ['condition: ' + condition]: step, default: S(id + '_skip', 'noop', 'true') } });
|
|
@@ -11,17 +11,18 @@ const C = (id, summary, steps, extra = {}) => defineWorker({ id, name: id.split(
|
|
|
11
11
|
const streetPattern = '\\b\\d{1,6}\\s+(?:[A-Za-z0-9.\\xC0-\\xFF-]+\\s+){1,8}(?:st(?:reet)?|ave(?:nue)?|blvd|boulevard|rd|road|ln|lane|dr(?:ive)?|way|ct|court|pl(?:ace)?|pkwy|parkway|cir(?:cle)?|ter(?:race)?)\\b';
|
|
12
12
|
const address = defineForm({ id: 'collect-geocoded-address', name: 'CollectGeocodedAddress', version: '1.0.0', description: 'Collect a mailing address in any order, project geocoder evidence, and read the complete address back for confirmation.', contract: { summary: 'Collect and confirm a geocoded mailing address', result: { path: 'form result.resolved', type: 'object' } }, parameters: [P('given')], extraVars: { given: '', zip: '', street: '', unit: '', draft: null, address_result: null, exit_context: 'your address', exit_context_es: 'su dirección' },
|
|
13
13
|
before: [S('address_given', 'given', "given || (cargo.forms[cargo.forms[form_instance].parent] || {}).context && (cargo.forms[cargo.forms[form_instance].parent].context.given || '') || ''"), S('address_draft', 'draft', E(addressDraft, "given || (cargo.forms[form_instance].seeds && cargo.forms[form_instance].seeds.given) || ''")), S('address_seed_zip', 'zip', "zip || draft.zip"), S('address_seed_street', 'street', "street || draft.street"), S('address_seed_unit', 'unit', "unit || draft.unit"), S('address_data', 'noop', "(cargo.forms[form_instance].data=Object.assign({need_city:false},cargo.forms[form_instance].data || {}), draft.street ? (cargo.addressDraft={said:draft.street}) : null, true)")],
|
|
14
|
-
inputs: [{ name: 'zip', field: 'zip', validator: 'address-zip-validate', prepare: 'address-zip-prompt', question_from: 'zip_question', question: 'What is the 5-digit zip code of your new address?', question_es: '¿Cuál es el código postal de 5 dígitos de su nueva dirección?' },
|
|
15
|
-
{ name: '
|
|
16
|
-
{ name: '
|
|
17
|
-
{ name: '
|
|
14
|
+
inputs: [{ name: 'zip', field: 'zip', names: ['zip', 'zip code', 'postal code', 'código postal', 'codigo postal'], validator: 'address-zip-validate', prepare: 'address-zip-prompt', question_from: 'zip_question', question: 'What is the 5-digit zip code of your new address?', question_es: '¿Cuál es el código postal de 5 dígitos de su nueva dirección?' },
|
|
15
|
+
{ name: 'city', label: 'city', label_es: 'ciudad', names: ['city', 'ciudad'], profile: { kind: 'choice', choices: [], accept_other: true }, choices_from: 'city_choices', when: { 'form.data.city_known': true }, depends_on: ['zip'], reset_on: ['zip'], prepare: 'address-city-prompt', question_from: 'city_question', question: 'Which city is it?', question_es: '¿Qué ciudad es?' },
|
|
16
|
+
{ name: 'city_state', label: 'city and state', label_es: 'ciudad y estado', names: ['city', 'ciudad'], profile: { kind: 'text' }, when: { 'form.data.need_city': true }, depends_on: ['zip'], question: 'What city and state is that in?', question_es: '¿En qué ciudad y estado está?' },
|
|
17
|
+
{ name: 'street', label: 'street address', label_es: 'dirección', names: ['street', 'calle'], profile: { kind: 'pattern', regex: streetPattern, accept_other: true }, depends_on: ['zip'], validator: 'address-street-validate', prepare: 'address-street-prompt', question_from: 'street_question', question: 'What is the street address?', question_es: '¿Cuál es la dirección?' },
|
|
18
|
+
{ name: 'unit', reset_on: ['street'], label: 'apartment or unit', label_es: 'apartamento o unidad', names: ['apartment', 'apt', 'unit', 'apartamento', 'unidad', 'departamento'], profile: { kind: 'pattern', regex: '(?:\\bapt\\.?|\\bunit|#)\\s*([\\w-]+)', group: 1, accept_other: true }, question: 'Is there an apartment or unit number? Type the number, or NONE.', question_es: '¿Hay un número de apartamento o unidad? Escriba el número, o NINGUNO.' }],
|
|
18
19
|
before_confirm: [S('address_resolved', 'address_result', E(resolvedAddress, 'cargo.forms[form_instance].values', 'cargo.forms[form_instance].data'))],
|
|
19
|
-
confirm: { no_keys: ['2', 'not right', 'not correct', 'incorrect', 'wrong', 'no es correcto', 'no es correcta', 'incorrecta'], question: 'Your new address is {{address_result.line}}. Is that correct?', question_es: 'Su nueva dirección es {{address_result.line}}. ¿Es correcta?' },
|
|
20
|
+
confirm: { named_fields: true, no_keys: ['2', 'not right', 'not correct', 'incorrect', 'wrong', 'no es correcto', 'no es correcta', 'incorrecta'], question: 'Your new address is {{address_result.line}}. Is that correct?', question_es: 'Su nueva dirección es {{address_result.line}}. ¿Es correcta?' },
|
|
20
21
|
after: [S('address_result_store', 'noop', '(cargo.forms[form_instance].values.resolved = address_result, cargo.address = address_result, cargo.addressDraft = null, true)')], declined: [S('address_retry_noop', 'noop', 'true')] });
|
|
21
22
|
const zip = C('address-zip-validate', 'Read city and state from geocoder evidence for the proposed ZIP; missing geocoder data requires an explicit city.', [
|
|
22
23
|
S('address_zip_components', 'components', "'postal_code:'+value+'|country:US'"), { id: 'address_zip_tool', type: 'CALL-TOOL', tool: 'geocode-zip', variable: 'result', args: { components: '{{components}}', address: '' }, onFail: S('address_zip_failed', 'result', 'null') },
|
|
23
24
|
S('address_zip_location', 'location', E(zipLocation, 'result')),
|
|
24
|
-
S('address_zip_result', 'noop', "(cargo.forms[form].data=Object.assign({},cargo.forms[form].data,{location:location,need_city:!location}), cargo.inputCheck={ok:true,value:String(value)}, true)")
|
|
25
|
+
S('address_zip_result', 'noop', "(cargo.forms[form].data=Object.assign({},cargo.forms[form].data,{location:location,need_city:!location,city_known:!!location,city_choice:!!(location&&location.cities.length),city_choices:" + E(cityChoices, 'location') + "}), location&&!location.cities.length&&cargo.forms[form].values.city===undefined?(cargo.forms[form].values.city=location.city,cargo.forms[form].accepted.city={origin:'derived',revision:cargo.forms[form].revision||0}):null, cargo.inputCheck={ok:true,value:String(value)}, true)")
|
|
25
26
|
], { parameters: [P('form'), P('value')], variables: V({ components: '', result: null, location: null }), contract: { tools: ['geocode-zip'], result: { path: 'cargo.inputCheck', type: 'object' } } });
|
|
26
27
|
const street = C('address-street-validate', 'Validate a proposed street against its ZIP; retain unverified wording when geocoding is inconclusive.', [
|
|
27
28
|
W('address_street_malformed', "!/^\\d{1,6}\\s+[A-Za-z\\xC0-\\xFF]/.test(String(value))", S('address_street_invalid', 'noop', "(cargo.inputCheck={ok:false,message:'Please give the street number and street name.',message_es:'Indique el número y nombre de la calle.'},true)")), W('address_street_stop', "!/^\\d{1,6}\\s+[A-Za-z\\xC0-\\xFF]/.test(String(value))", { id: 'address_street_invalid_end', type: 'END' }),
|
|
@@ -30,10 +31,15 @@ const street = C('address-street-validate', 'Validate a proposed street against
|
|
|
30
31
|
S('address_street_result', 'noop', "(cargo.forms[form].data.street=location, cargo.inputCheck={ok:true,value:String(value)}, true)")
|
|
31
32
|
], { parameters: [P('form'), P('value'), P('values', 'object')], variables: V({ components: '', result: null, location: null }), contract: { tools: ['geocode-street'], result: { path: 'cargo.inputCheck', type: 'object' } } });
|
|
32
33
|
const zipPrompt = C('address-zip-prompt', 'Render the ZIP retry wording from the owned address instance.', [S('address_zip_prompt', 'noop', "(cargo.forms[form].data.zip_question=(cargo.forms[form].data.retry ? \"Let's try again. \" : '')+'What is the 5-digit zip code of your new address?',cargo.forms[form].data.zip_question_es=(cargo.forms[form].data.retry?'Intentémoslo otra vez. ':'')+'¿Cuál es el código postal de 5 dígitos de su nueva dirección?',true)")], { parameters: [P('form')], contract: { result: { path: 'cargo.forms[form].data', type: 'object' } } });
|
|
33
|
-
const streetPrompt = C('address-street-prompt', 'Include the ZIP-derived location when asking for the street.', [S('address_street_prompt', 'noop', "(cargo.forms[form].data.street_question=(cargo.forms[form].data.location?'Got it, '+cargo.forms[form].data.location.line+'. ':'')+'What is the street address?',cargo.forms[form].data.street_question_es=(cargo.forms[form].data.location?'Entendido, '+cargo.forms[form].data.location.line+'. ':'')+'¿Cuál es la dirección?',true)")], { parameters: [P('form')], contract: { result: { path: 'cargo.forms[form].data', type: 'object' } } });
|
|
34
|
-
const
|
|
34
|
+
const streetPrompt = C('address-street-prompt', 'Include the ZIP-derived location when asking for the street.', [S('address_street_prompt', 'noop', "(cargo.forms[form].data.street_question=(cargo.forms[form].data.location?'Got it, '+(cargo.forms[form].values.city?cargo.forms[form].values.city+', '+cargo.forms[form].data.location.state:cargo.forms[form].data.location.line)+'. ':'')+'What is the street address?',cargo.forms[form].data.street_question_es=(cargo.forms[form].data.location?'Entendido, '+(cargo.forms[form].values.city?cargo.forms[form].values.city+', '+cargo.forms[form].data.location.state:cargo.forms[form].data.location.line)+'. ':'')+'¿Cuál es la dirección?',true)")], { parameters: [P('form')], contract: { result: { path: 'cargo.forms[form].data', type: 'object' } } });
|
|
35
|
+
const cityPrompt = C('address-city-prompt', 'Ask which of the ZIP code\'s place names the address carries.', [S('address_city_prompt', 'noop', "(function(data,voice){var names=(data.location&&data.location.cities)||[],n=names.length,list=function(and){return names.slice(0,-1).join(', ')+' '+and+' '+names[n-1];};if(n<2){data.city_question='What city is it?';data.city_question_es='¿Qué ciudad es?';return true;}data.city_question='Which city is it: '+list('or')+'? '+(voice?names.map(function(c,i){return (i?'':'Press ')+(i+1)+' for '+c;}).join(', ')+'.':'Type the city or its number, 1 to '+n+'.');data.city_question_es='¿Qué ciudad es: '+list('o')+'? '+(voice?names.map(function(c,i){return (i?'':'Presione ')+(i+1)+' para '+c;}).join(', ')+'.':'Escriba la ciudad o su número, del 1 al '+n+'.');return true;})(cargo.forms[form].data,cargo.voice===true)")], { parameters: [P('form')], contract: { result: { path: 'cargo.forms[form].data', type: 'object' } } });
|
|
36
|
+
// NO at the read-back asks which part is wrong and re-asks only that part; ALL starts over.
|
|
37
|
+
const PARTS = [{ key: 'zip', phrases: ['1', 'zip', 'zip code', 'postal code', 'código postal', 'codigo postal'] }, { key: 'city', phrases: ['2', 'city', 'ciudad'] }, { key: 'street', phrases: ['3', 'street', 'calle'] }, { key: 'unit', phrases: ['4', 'apartment', 'apt', 'unit', 'apartamento', 'unidad', 'departamento'] }, { key: 'all', phrases: ['5', 'all', 'everything', 'all of it', 'todo', 'toda'] }];
|
|
38
|
+
const declined = C('collect-geocoded-address-declined', 'Ask which part of the declined address is wrong, re-ask only that part, or start a fresh pass.', [
|
|
35
39
|
S('address_retry_owner', 'parent_form', 'cargo.forms[form_instance].parent'), S('address_retry_input', 'result_input', 'cargo.forms[form_instance].result_input'),
|
|
36
|
-
|
|
40
|
+
F('address_retry_part_ask', 'ask-choice', { question: '{{part_question}}', question_es: '{{part_question_es}}', choices: '{{parts}}' }),
|
|
41
|
+
S('address_retry_part', 'part', "['zip','city','street','unit','all'].indexOf(cargo.choice)>=0 ? cargo.choice : 'all'"),
|
|
42
|
+
S('address_retry_clear', 'noop', "(part==='all' ? (resetFormInputs(cargo,form_instance,['zip','city','city_state','street','unit']),cargo.forms[form_instance].data={retry:true,need_city:false}) : resetFormInputs(cargo,form_instance,[part==='city' ? (cargo.forms[form_instance].data.city_choice ? 'city' : 'city_state') : part]),true)"),
|
|
37
43
|
F('address_retry', 'collect-geocoded-address', { form_instance: '{{form_instance}}', parent_form: '{{parent_form}}', result_input: '{{result_input}}' }, 'replace')
|
|
38
|
-
], { parameters: [P('form_instance')], variables: V({ parent_form: '', result_input: '' }) });
|
|
39
|
-
export const FLOWS = [address, zip, street, zipPrompt, streetPrompt, declined];
|
|
44
|
+
], { parameters: [P('form_instance')], variables: V({ parent_form: '', result_input: '', part: '', parts: PARTS, part_question: "Which part is wrong: 1 the zip code, 2 the city, 3 the street, or 4 the apartment? Or say ALL to start over.", part_question_es: "¿Qué parte está mal: 1 el código postal, 2 la ciudad, 3 la calle, o 4 el apartamento? O diga TODO para empezar de nuevo." }) });
|
|
45
|
+
export const FLOWS = [address, zip, street, zipPrompt, cityPrompt, streetPrompt, declined];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/forms/contracts.js"],"names":[],"mappings":"AAgBA;;;IAGC;AACD;;;;;EAGC;AACD,qGAAqG;AACrG;;QAwCC;AAqBD;;;QAEC;AAgBD;;;;;;;;;QASC;AACD;;;;QAGC;AACD;;;;;;;;QA8BC;AAED,mHAAmH;AACnH,kDAgBC;AAED,+GAA+G;AAC/G
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/forms/contracts.js"],"names":[],"mappings":"AAgBA;;;IAGC;AACD;;;;;EAGC;AACD,qGAAqG;AACrG;;QAwCC;AAqBD;;;QAEC;AAgBD;;;;;;;;;QASC;AACD;;;;QAGC;AACD;;;;;;;;QA8BC;AAED,mHAAmH;AACnH,kDAgBC;AAED,+GAA+G;AAC/G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2EC"}
|
package/dist/forms/flows.d.ts
CHANGED
|
@@ -264,6 +264,7 @@ export namespace FIELD_PRESETS {
|
|
|
264
264
|
export { label_9 as label };
|
|
265
265
|
let label_es_9: string;
|
|
266
266
|
export { label_es_9 as label_es };
|
|
267
|
+
export let accumulate: boolean;
|
|
267
268
|
export namespace profile_9 {
|
|
268
269
|
let kind_9: string;
|
|
269
270
|
export { kind_9 as kind };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/forms/flows.js"],"names":[],"mappings":"AA4FA;;;;;;GAMG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0DC;AACD;;;GAGG;AACH;;;;;;EAGC;
|
|
1
|
+
{"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/forms/flows.js"],"names":[],"mappings":"AA4FA;;;;;;GAMG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0DC;AACD;;;GAGG;AACH;;;;;;EAGC;AAuYD,wHAAwH;AACxH,wEAaC;AACD,4FAA4F;AAC5F;;;EAYC;AACD,sGAAsG;AACtG;;;EAOC;AAviBM,6CAAuG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8tB9G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAOG"}
|
package/dist/forms/flows.js
CHANGED
|
@@ -65,7 +65,7 @@ export const FIELD_PRESETS = {
|
|
|
65
65
|
city: { label: 'city', label_es: 'ciudad', profile: { kind: 'text' }, question: 'What city?', question_es: '¿En qué ciudad?' },
|
|
66
66
|
state: { label: 'state', label_es: 'estado', profile: { kind: 'pattern', regex: '^\\s*(?:Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming|District of Columbia|Puerto Rico|AL|AK|AZ|AR|CA|CO|CT|DE|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY|DC|PR)\\s*$' },
|
|
67
67
|
question: 'What state?', question_es: '¿En qué estado?' },
|
|
68
|
-
card_number: { label: 'card number', label_es: 'número de tarjeta', profile: { kind: 'digits', min: 13, max: 19 }, digits: { min: 13, max: 19, complete: [{ first: '4', lengths: [16, 19] }, { first: '25', lengths: [16] }, { first: '3', lengths: [15] }, { first: '6', lengths: [16, 19] }] },
|
|
68
|
+
card_number: { label: 'card number', label_es: 'número de tarjeta', accumulate: true, profile: { kind: 'digits', min: 13, max: 19 }, digits: { min: 13, max: 19, complete: [{ first: '4', lengths: [16, 19] }, { first: '25', lengths: [16] }, { first: '3', lengths: [15] }, { first: '6', lengths: [16, 19] }] },
|
|
69
69
|
pii: true, validator: 'validate-card-number',
|
|
70
70
|
question: 'Please say or enter your card number.', question_es: 'Por favor diga o ingrese el número de su tarjeta.',
|
|
71
71
|
retry: 'Please say or enter the full card number.', retry_es: 'Por favor diga o ingrese el número completo de su tarjeta.' },
|
|
@@ -105,7 +105,7 @@ export function formFlow({ id, name, version, description, inputs, after = [], e
|
|
|
105
105
|
// FLOW parameters are paths only: the question is built here, as a SAY-style template, then passed by name
|
|
106
106
|
SET(`${id}_confirm_q`, 'form_confirm_q', textValue(confirm.question)),
|
|
107
107
|
SET(`${id}_confirm_q_es`, 'form_confirm_q_es', textValue(confirm.question_es || confirm.question)),
|
|
108
|
-
FLOW(`${id}_confirm`, 'confirm-form', 'call', { form: '{{form_instance}}', question: '{{form_confirm_q}}', question_es: '{{form_confirm_q_es}}', phrases: '{{form_confirmation.phrases}}', words: '{{form_confirmation.words}}', clarifications: '{{form_confirmation.clarifications}}', no_keys: '{{form_confirmation.no_keys}}', interrupts: '{{form_confirmation.interrupts}}', exit_context: '{{exit_context}}', exit_context_es: '{{exit_context_es}}' }),
|
|
108
|
+
FLOW(`${id}_confirm`, 'confirm-form', 'call', { form: '{{form_instance}}', question: '{{form_confirm_q}}', question_es: '{{form_confirm_q_es}}', phrases: '{{form_confirmation.phrases}}', words: '{{form_confirmation.words}}', clarifications: '{{form_confirmation.clarifications}}', no_keys: '{{form_confirmation.no_keys}}', interrupts: '{{form_confirmation.interrupts}}', named_fields: '{{form_confirmation.named_fields}}', exit_context: '{{exit_context}}', exit_context_es: '{{exit_context_es}}' }),
|
|
109
109
|
{ id: `${id}_confirmed`, type: 'CASE', branches: {
|
|
110
110
|
[`condition: (cargo.formConfirm || {})[form_instance] === 'changed'`]: FLOW(`${id}_again`, id, 'replace', { parent_form: '{{parent_form}}', result_input: '{{result_input}}', form_instance: '{{form_instance}}' }),
|
|
111
111
|
// NO: the declined flow takes the form's place, so the action below never runs
|
|
@@ -211,7 +211,7 @@ const collectInput = {
|
|
|
211
211
|
id: 'collect-input', name: 'CollectInput', version: '1.0.0', scope: 'isolated',
|
|
212
212
|
description: "Worker: ask the form's current input once and file the answer wherever it belongs in the form chain (matchInputs, decided by scope; a declared confirm_against pair is asked). One reading → collect-input-accept; ambiguous → disambiguate-input; a question about the form's data → provide-data; a short miss → counted, the loop re-asks; 3+ words that fit nothing → DISPATCH. Params: form, current, questions, provides, exit_context(_es).",
|
|
213
213
|
parameters: ['form', 'current', 'questions', 'provides', 'exit_context', 'exit_context_es'].map((n) => ({ name: n, type: ['questions'].includes(n) ? 'array' : n === 'provides' ? 'object' : 'string', description: n })),
|
|
214
|
-
variables: vars({ ci_exhaustion: null, ci_d: {}, ci_pre: '', ci_val: '', ci_routed: '', ci_names: [], ci_chain: [], ci_spec: null, ci_choices: [], ci_q: '', ci_q_es: '', ci_missed: 0, ci_max: 3, ci_misses: 0, ci_miss_limit: 2, ci_m: null, ci_qkey: '', ci_skip_gate: '', ci_words: 0, ci_digits: null, ci_amount: false, ci_as_spoken: false, ci_reader: {}, ci_pii: false, ci_ctx: '', ci_ctx_es: '' }),
|
|
214
|
+
variables: vars({ ci_partial: '', ci_exhaustion: null, ci_d: {}, ci_pre: '', ci_val: '', ci_routed: '', ci_names: [], ci_chain: [], ci_spec: null, ci_choices: [], ci_q: '', ci_q_es: '', ci_missed: 0, ci_max: 3, ci_misses: 0, ci_miss_limit: 2, ci_m: null, ci_qkey: '', ci_skip_gate: '', ci_words: 0, ci_digits: null, ci_amount: false, ci_as_spoken: false, ci_reader: {}, ci_pii: false, ci_ctx: '', ci_ctx_es: '' }),
|
|
215
215
|
steps: [
|
|
216
216
|
SET('ci_find_spec', 'ci_spec', "(function () { var s = ((cargo.forms[form] || {}).specs || []).filter(function (s) { return s.name === current; })[0]; return s ? (Array.isArray(s.any_of) ? Object.assign({}, s, { profile: { kind: 'group' } }) : s) : null; })()"),
|
|
217
217
|
SET('ci_current_names', 'ci_names', "Array.isArray(ci_spec && ci_spec.any_of) ? ci_spec.any_of.map(function (m) { return m.name; }) : [current]"),
|
|
@@ -251,6 +251,10 @@ const collectInput = {
|
|
|
251
251
|
SET('ci_route_to', 'ci_routed', "(ci_spec.route_keys || []).filter(function (r) { return String(cargo.choice || '').indexOf(r.prefix) === 0; }).map(function (r) { return r.flow; })[0] || ''"),
|
|
252
252
|
WHEN('ci_route_key', 'ci_routed', FLOW('ci_route_key_flow', '{{ci_routed}}', 'call', { form: '{{form}}', input: '{{current}}' })),
|
|
253
253
|
WHEN('ci_routed_end', 'ci_routed', END('ci_routed_done')),
|
|
254
|
+
// `accumulate` (opt-in, digit inputs): a number said in groups across turns ("4347", "6971 2210"…) is kept and joined;
|
|
255
|
+
// short of the input's minimum the next question is "Go on." Anything that is not digits drops the partial.
|
|
256
|
+
SET('ci_partial_join', 'ci_partial', "(function () { var state = cargo.forms[form]; if (!ci_spec || ci_spec.accumulate !== true || !ci_spec.digits) return ''; var said = String(cargo.choiceText || '').trim(); var data = state.data = state.data || {}; var key = '__partial_' + current; if (!/^[0-9][0-9\\s.,-]*$/.test(said)) { delete data[key]; return ''; } var joined = String(data[key] || '') + said.replace(/[^0-9]/g, ''); if (joined.length < Number(ci_spec.digits.min || 0)) { data[key] = joined; var fb = state.feedback || {}; fb[current] = 'partial'; state.feedback = fb; return 'hold'; } delete data[key]; cargo.choiceText = joined; cargo.choice = joined; return 'joined'; })()"),
|
|
257
|
+
WHEN('ci_partial_hold', "ci_partial === 'hold'", END('ci_partial_wait')),
|
|
254
258
|
SET('ci_build_chain', 'ci_chain', CHAIN_JS),
|
|
255
259
|
SET('ci_match', 'ci_m', "readFormAnswer(cargo.choiceText, ci_chain, Array.isArray(ci_spec.any_of) ? { form: form, names: ci_names } : { form: form, name: current }, cargo.choice, provides && Array.isArray(questions) ? questions : [])"),
|
|
256
260
|
// The labels and validators ride on each reading, so the presets stay in this one flow.
|
|
@@ -421,8 +425,8 @@ const disambiguate = {
|
|
|
421
425
|
const confirmForm = {
|
|
422
426
|
id: 'confirm-form', name: 'ConfirmForm', version: '1.0.0', scope: 'isolated',
|
|
423
427
|
description: "Worker: ask a form's confirmation (exact YES / NO; keys 1 and 2). A correction instead ('no, make it $40') is read against the form chain and stored, and the result is 'changed' so the form runs again; an unclear short answer is asked again, a long unrelated one is DISPATCHed. Result: cargo.formConfirm[form] = 'yes' | 'no' | 'changed'. Params: form, question(_es), exit_context(_es).",
|
|
424
|
-
parameters: ['form', 'question', 'question_es', 'exit_context', 'exit_context_es', 'phrases', 'words', 'interrupts', 'no_keys', 'clarifications'].map((n) => ({ name: n, type: ['phrases', 'words', 'interrupts', 'no_keys', 'clarifications'].includes(n) ? 'array' : 'string', description: n })),
|
|
425
|
-
variables: vars({ cf_presets: FIELD_PRESETS, cf_chain: [], cf_m: null, cf_current: null, cf_result: '', cf_prompt: '', cf_prompt_es: '', cf_words: 0, cf_tries: 0, phrases: null, words: [], clarifications: [], no_keys: ['2'], interrupts: [], cf_choices: [], cf_event: '', cf_amount: false, cf_questions: [], cf_provides: null, cf_skip_gate: '' }),
|
|
428
|
+
parameters: ['form', 'question', 'question_es', 'exit_context', 'exit_context_es', 'phrases', 'words', 'interrupts', 'no_keys', 'clarifications'].map((n) => ({ name: n, type: ['phrases', 'words', 'interrupts', 'no_keys', 'clarifications'].includes(n) ? 'array' : 'string', description: n })).concat([{ name: 'named_fields', type: 'boolean', description: "true: an answer that names one of the form's inputs (its names) without a value re-asks only that input" }]),
|
|
429
|
+
variables: vars({ named_fields: false, cf_named: null, cf_presets: FIELD_PRESETS, cf_chain: [], cf_m: null, cf_current: null, cf_result: '', cf_prompt: '', cf_prompt_es: '', cf_words: 0, cf_tries: 0, phrases: null, words: [], clarifications: [], no_keys: ['2'], interrupts: [], cf_choices: [], cf_event: '', cf_amount: false, cf_questions: [], cf_provides: null, cf_skip_gate: '' }),
|
|
426
430
|
steps: [
|
|
427
431
|
SIDE('cf_reset', "(cargo.formConfirm = cargo.formConfirm || {}, cargo.formConfirm[form] = '', true)"),
|
|
428
432
|
SET('cf_choices', 'cf_choices', `[{key:'yes',phrases:['1'].concat(Array.isArray(phrases)?phrases:Array.isArray(words)?words:[]),exact:true},{key:'no',phrases:(Array.isArray(no_keys)?no_keys:['2']).concat(${JSON.stringify(ANSWER_WORDS.no)}),exact:true}].concat((Array.isArray(interrupts)?interrupts:[]).map(function(event){return {key:'event:'+event.key,phrases:event.phrases ?? event.words,exact:event.exact!==false};}))`),
|
|
@@ -443,6 +447,9 @@ const confirmForm = {
|
|
|
443
447
|
SET('cf_match', 'cf_m', "cargo.choice === 'yes' || cargo.choice === 'no' && pickChoice(cargo.choiceText, [{key:'no',phrases:Array.isArray(no_keys)?no_keys:['2'],exact:true}], false) === 'no' ? { hits: [], ambiguous: [], questions:[] } : readFormAnswer(cargo.choiceText, cf_chain, cf_current, '',cf_questions)"),
|
|
444
448
|
SET('cf_enrich', 'cf_m', "(function(m){m.hits=m.hits.map(function(h){return Object.assign({},h,{silent:true});});return m;})(enrichFormMatches(cf_m, cf_chain, form))"),
|
|
445
449
|
SET('cf_count_words', 'cf_words', "String(cargo.choiceText || '').split(/\\s+/).filter(function (w) { return /[a-záéíóúüñ]/i.test(w); }).length"),
|
|
450
|
+
// opt-in (confirm.named_fields): 'the city is wrong' / 'la ciudad no' names exactly one input and gives no value; that
|
|
451
|
+
// input alone is asked again instead of the answer being DISPATCHed
|
|
452
|
+
SET('cf_named_field', 'cf_named', "(named_fields === true || named_fields === 'true') && cargo.choice !== 'yes' && !cf_m.hits.length && !cf_m.ambiguous.length && !cf_m.questions.length ? (function (text, chain) { var plain = function (v) { return ' ' + String(v || '').toLowerCase().replace(/[^a-z0-9áéíóúüñ]+/g, ' ').trim() + ' '; }; var said = plain(text); var named = chain.filter(function (input) { return (input.names || []).some(function (name) { return said.indexOf(plain(name)) >= 0; }); }); return named.length === 1 ? { form: named[0].form, name: named[0].name } : null; })(cargo.choiceText, cf_chain) : null"),
|
|
446
453
|
WHEN('cf_question_fields', 'cf_m.questions.length > 0 && cf_m.hits.length > 0', FLOW('cf_question_accept', 'collect-input-accept', 'call', { hits: '{{cf_m.hits}}' })),
|
|
447
454
|
WHEN('cf_question_provide', 'cf_m.questions.length > 0', FLOW('cf_question_answer', 'provide-data', 'call', { form: '{{form}}', provides: '{{cf_provides}}', asked_keys: '{{cf_m.questions}}', no_menu: 'true', no_gate: '{{cf_skip_gate}}' })),
|
|
448
455
|
{ id: 'cf_route', type: 'CASE', branches: {
|
|
@@ -450,6 +457,7 @@ const confirmForm = {
|
|
|
450
457
|
"condition: cargo.choice === 'yes'": SET('cf_answered', 'cf_result', "'yes'"),
|
|
451
458
|
'condition: cf_m.ambiguous.length > 0': FLOW('cf_ambiguous', 'disambiguate-input', 'call', { readings: '{{cf_m.ambiguous}}', hits: '{{cf_m.hits}}', remaining: '{{cf_m.remaining}}' }),
|
|
452
459
|
'condition: cf_m.hits.length > 0': FLOW('cf_accept', 'collect-input-accept', 'call', { hits: '{{cf_m.hits}}' }),
|
|
460
|
+
'condition: cf_named': SET('cf_named_reset', 'cf_result', "(resetFormInputs(cargo, cf_named.form, [cf_named.name]), 'changed')"),
|
|
453
461
|
"condition: cargo.choice === 'no'": SET('cf_declined', 'cf_result', "'no'"),
|
|
454
462
|
"condition: Array.isArray(clarifications) && pickChoice(String(cargo.choiceText || '').replace(/[?¿]/g,''),[{key:'clarify',phrases:clarifications,exact:true}],false)==='clarify'": SET('cf_clarification', 'cf_result', "'clarification'"),
|
|
455
463
|
'condition: cf_words >= 3 || cf_amount && cf_words > 0': yieldDispatch('cf_elsewhere', 'form', "'confirmation_not_matched'"),
|
|
@@ -9,7 +9,9 @@ export function zipLocation(result: any): {
|
|
|
9
9
|
city: string;
|
|
10
10
|
state: string;
|
|
11
11
|
line: string;
|
|
12
|
+
cities: string[];
|
|
12
13
|
} | null;
|
|
14
|
+
export function cityChoices(location: any): any;
|
|
13
15
|
export function streetLocation(result: any, said: any, zip: any): {
|
|
14
16
|
street: string;
|
|
15
17
|
said: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/helpers/address.js"],"names":[],"mappings":"AAAA,uFAAuF;AACvF;;;;;EAQC;AACD
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/helpers/address.js"],"names":[],"mappings":"AAAA,uFAAuF;AACvF;;;;;EAQC;AACD;;;;;SASC;AACD,gDAEC;AACD;;;;EAMC;AACD;;;;;;;;EAIC"}
|
package/dist/helpers/address.js
CHANGED
|
@@ -13,7 +13,14 @@ export function zipLocation(result) {
|
|
|
13
13
|
const components = result?.components || result?.results?.[0]?.address_components || [];
|
|
14
14
|
const part = (kind, short = false) => { const row = components.find(c => (c.types || []).includes(kind)); return row ? String(short ? row.short_name || row.long_name : row.long_name || row.short_name) : ''; };
|
|
15
15
|
const city = part('locality') || part('postal_town') || part('sublocality'), state = part('administrative_area_level_1', true);
|
|
16
|
-
|
|
16
|
+
// A ZIP code can belong to several places (90023: Commerce, East Los Angeles, Los Angeles, Vernon); each is a name its
|
|
17
|
+
// mail may carry, so the caller picks one. Google lists them as postcode_localities; at most 7 (8 is a reserved key).
|
|
18
|
+
const listed = [].concat(result?.localities || result?.results?.[0]?.postcode_localities || []).map(String).filter(Boolean);
|
|
19
|
+
const cities = listed.length > 1 ? [...new Set(listed)].slice(0, 7) : [];
|
|
20
|
+
return result?.status === 'OK' && city && state ? { city, state, line: city + ', ' + state, cities } : null;
|
|
21
|
+
}
|
|
22
|
+
export function cityChoices(location) {
|
|
23
|
+
return (location?.cities || []).map((name, index) => ({ key: name, keys: [String(index + 1)], phrases: [name], label: name, neutral: true }));
|
|
17
24
|
}
|
|
18
25
|
export function streetLocation(result, said, zip) {
|
|
19
26
|
const row = result?.results?.[0] || result || {}, components = row.components || row.address_components || [];
|
|
@@ -24,6 +31,6 @@ export function streetLocation(result, said, zip) {
|
|
|
24
31
|
}
|
|
25
32
|
export function resolvedAddress(values, data) {
|
|
26
33
|
const unit = /^(none|no|ninguno|ninguna|sin|no hay)$/i.test(String(values.unit || '')) ? '' : String(values.unit || '').replace(/^(apt\.?|unit|#)\s*/i, '');
|
|
27
|
-
const street = data.street?.street || values.street || '', city = data.location?.line || values.city_state || '';
|
|
34
|
+
const street = data.street?.street || values.street || '', city = values.city && data.location?.state ? values.city + ', ' + data.location.state : data.location?.line || values.city_state || '';
|
|
28
35
|
return { street, unit, city, zip: String(values.zip || ''), line: street + (unit ? ' Apt ' + unit : '') + ', ' + city + ' ' + values.zip, verified: data.street?.verified === true, said: data.street?.said || values.street || '' };
|
|
29
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-conversation.d.ts","sourceRoot":"","sources":["../../src/helpers/form-conversation.js"],"names":[],"mappings":"AAGA,0EAGC;AACD,oEAGC;AACD,sGAAsG;AACtG,+
|
|
1
|
+
{"version":3,"file":"form-conversation.d.ts","sourceRoot":"","sources":["../../src/helpers/form-conversation.js"],"names":[],"mappings":"AAGA,0EAGC;AACD,oEAGC;AACD,sGAAsG;AACtG,+GAOC;AACD,8EAAwI;AAExI,yGAAyG;AACzG;;;;;;;;;;;;;;;;;;;;EAUC;AAED,sGAAsG;AACtG;;;;;;;;;;;;;;;;;;;;EAeC"}
|
|
@@ -25,6 +25,8 @@ export function formInputPrompt(cargo, id, input, spec, data = {}, language = 'e
|
|
|
25
25
|
const es = language === 'es', feedback = cargo.forms?.[id]?.feedback?.[input];
|
|
26
26
|
const question = spec.question_from && (es ? (data[spec.question_from + '_es'] || data[spec.question_from]) : data[spec.question_from]) || (es ? (spec.question_es || spec.question) : spec.question) || '';
|
|
27
27
|
const retry = es ? spec.retry_es : spec.retry;
|
|
28
|
+
if (feedback === 'partial')
|
|
29
|
+
return es ? 'Continúe.' : 'Go on.';
|
|
28
30
|
if (feedback && retry)
|
|
29
31
|
return retry;
|
|
30
32
|
return (feedback === 'miss' ? (es ? 'Disculpe, no le entendí. ' : "Sorry, I didn't catch that. ") : '') + question;
|
package/dist/runtime-identity.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const JSFE_RUNTIME_FINGERPRINT = "sha256:
|
|
1
|
+
export const JSFE_RUNTIME_FINGERPRINT = "sha256:7a048ac938debc2bb9dcd648489cde344d9eba57521231cabe6c2b49f36251bd";
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## 1.9.3: a card number said in groups
|
|
2
|
+
|
|
3
|
+
A digit input may opt in to `accumulate: true`: an answer that is only digits and short of the input's minimum is kept, and
|
|
4
|
+
the next question is "Go on." / "Continúe."; the next digits are joined to it, and anything that is not digits drops the
|
|
5
|
+
partial. The shared `card_number` preset opts in, so a card read in groups across turns is collected whole instead of each
|
|
6
|
+
group being read as another field (an account number, an amount).
|
|
7
|
+
|
|
8
|
+
## 1.9.2: address city list and part corrections
|
|
9
|
+
|
|
10
|
+
The shared address form (`collect-geocoded-address`) asks the city when the ZIP code carries several place names (`geocode-zip` returns `localities`, Google's `postcode_localities`; at most 7): "Which city is it: Commerce, East Los Angeles, Los Angeles or Vernon?", by name or key. With one name it is not asked, and a caller who says the city is wrong is asked it plainly and any city is taken. At the read-back, naming one part without a value ("the city is wrong", "la ciudad no") asks only that part again, and a plain NO asks which part is wrong (zip code, city, street, apartment, or ALL to start over) instead of starting over. The part naming is an opt-in form confirmation setting, `confirm.named_fields: true`, read from each input's `names`; other forms keep their behavior. A host whose `geocode-zip` returns no `localities` keeps the one city it returns.
|
|
11
|
+
|
|
1
12
|
## 1.9.1: stored sessions without definition copies
|
|
2
13
|
|
|
3
14
|
`engine.storedSession(session)` returns the session as a host should store it: each open form instance's input specs, providers and questions that its loaded definition (or its parent's schema) reproduces exactly are replaced by a named source (`derived`), and continuation revision hashes are kept only for the definitions of open form instances, the only ones read back. Anything a flow built at run time is stored as it is. `updateActivity` restores a stored session from the loaded flows; a source that no longer exists is left absent and the continuation safety check retires it. The session passed in is never changed, and a session never stored this way continues as before. Measured on a production payment call: 182 KB to 110 KB, 245 revision hashes to 5.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsfe",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.3",
|
|
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",
|