jsfe 1.104.0 → 1.104.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"address-flows.d.ts","sourceRoot":"","sources":["../../src/forms/address-flows.js"],"names":[],"mappings":"AA+EA,0BAA0H"}
1
+ {"version":3,"file":"address-flows.d.ts","sourceRoot":"","sources":["../../src/forms/address-flows.js"],"names":[],"mappings":"AAgFA,0BAA0H"}
@@ -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, cityChoices, streetLocation, resolvedAddress, listedPlace, addressLine, addressVerdict, streetCheck, checkDeclined, unitQuestion, unitPrecheck, unitResult, unitsGiven, streetAccepted } from '../helpers/address.js';
3
+ import { addressDraft, zipLocation, cityChoices, streetLocation, resolvedAddress, listedPlace, addressLine, addressVerdict, streetCheck, checkDeclined, unitQuestion, unitPrecheck, unitResult, unitsGiven, streetAccepted, streetUnit } 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') } });
@@ -20,7 +20,7 @@ const address = defineForm({ id: 'collect-geocoded-address', name: 'CollectGeoco
20
20
  { name: 'city', argument_description: 'city name alone', label: 'city', label_es: 'ciudad', names: ['city', 'ciudad'], profile: { kind: 'choice', choices: [], accept_other: true, other_needs_letter: true }, choices_from: 'city_choices', validator: 'address-city-validate', when: { 'form.data.city_known': true }, required_when: { 'form.data.city_ask': 'yes' }, depends_on: ['zip'], reset_on: ['zip'], prepare: 'address-city-prompt', question_from: 'city_question', question: 'Which city is it?', question_es: '¿Qué ciudad es?', form_client: { control: 'combobox', autofill: 'address-level2' } },
21
21
  { name: 'city_state', argument_description: 'city and 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_from: 'city_state_question', question: 'What city and state is that in?', question_es: '¿En qué ciudad y estado está?' },
22
22
  { name: 'street', argument_description: 'street number and street name, without the apartment', label: 'street address', label_es: 'dirección', names: ['street', 'calle'], profile: { kind: 'pattern', regex: streetPattern, spoken_digits: 'house_number', accept_other: true }, depends_on: ['zip'], validator: 'address-street-validate', after: 'address-street-accepted', prepare: 'address-street-prompt', question_from: 'street_question', question: 'What is the street address?', question_es: '¿Cuál es la dirección?', form_client: { control: 'place', types: 'address', regions: ['us'], fills: { zip: 'postal_code', city: 'locality' }, autofill: 'address-line1' } },
23
- { name: 'unit', declinable: true, validator: 'address-unit-validate', argument_description: 'apartment or unit number alone, such as 4 or 12B', depends_on: ['street'], reset_on: ['street'], label: 'apartment or unit', label_es: 'apartamento o unidad', names: ['apartment', 'apt', 'unit', 'apartamento', 'unidad', 'departamento'], profile: { kind: 'pattern', regex: '(?:\\bapartment|\\bapartamento|\\bdepartamento|\\bapt\\.?|\\bunit|\\bunidad|#)\\s*([\\w-]+)', group: 1, spoken_digits: true, accept_other: true }, question_from: 'unit_question', question: 'Is there an apartment or unit number? {{channelVerb(\'en\', cargo, true)}} the number, or NONE.', question_es: '¿Hay un número de apartamento o unidad? {{channelVerb(\'es\', cargo, true)}} el número, o NINGUNO.', form_client: { autofill: 'address-line2' } }],
23
+ { name: 'unit', declinable: true, silent: true, validator: 'address-unit-validate', argument_description: 'apartment or unit number alone, such as 4 or 12B', reset_on: ['street'], label: 'apartment or unit', label_es: 'apartamento o unidad', names: ['apartment', 'apt', 'unit', 'apartamento', 'unidad', 'departamento'], profile: { kind: 'pattern', regex: '(?:\\bapartment|\\bapartamento|\\bdepartamento|\\bapt\\.?|\\bunit|\\bunidad|#)\\s*([\\w-]+)', group: 1, spoken_digits: true, accept_other: true }, question_from: 'unit_question', question: 'Is there an apartment or unit number? {{channelVerb(\'en\', cargo, true)}} the number, or NONE.', question_es: '¿Hay un número de apartamento o unidad? {{channelVerb(\'es\', cargo, true)}} el número, o NINGUNO.', form_client: { autofill: 'address-line2' } }],
24
24
  before_confirm: [S('address_resolved', 'address_result', E(resolvedAddress, 'cargo.forms[form_instance].values', 'cargo.forms[form_instance].data'))],
25
25
  confirm: { named_fields: true, reply_context: 'This is a mailing address read back for confirmation. A reply may correct one part or several at once: the street number, street name or street type, the apartment or unit, the city, or the ZIP code.', no_keys: ['2', 'not right', 'not correct', 'incorrect', 'wrong', 'no es correcto', 'no es correcta', 'incorrecta'], question: "Your {{address_label}} is {{address_result.line}}. Is that correct? {{yesNoKeys('en', cargo)}}", question_es: "Su {{address_label_es}} es {{address_result.line}}. ¿Es correcta? {{yesNoKeys('es', cargo)}}" },
26
26
  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')] });
@@ -37,12 +37,13 @@ const street = C('address-street-validate', 'Validate a proposed street against
37
37
  W('address_street_located', '!held', S('address_street_projection', 'location', E(streetLocation, 'result', 'value', 'values.zip'))),
38
38
  W('address_street_derive', '!held', S('address_street_result', 'noop', "(cargo.forms[form].data.street=location, location.city&&cargo.forms[form].accepted&&cargo.forms[form].accepted.city&&cargo.forms[form].accepted.city.origin==='derived'&&cargo.forms[form].values.city!==location.city?(cargo.forms[form].values.city=location.city):null, true)")),
39
39
  // The whole address, checked once by Google Address Validation (owner 2026-12-05). Its failure leaves the form as before.
40
- S('address_street_line', 'line', E(addressLine, 'value', "''", 'Object.assign({},cargo.forms[form].values,values)', 'cargo.forms[form].data')),
40
+ S('address_street_unit', 'unit', E(streetUnit, 'cargo.forms[form]', 'values', 'reading')),
41
+ S('address_street_line', 'line', E(addressLine, 'value', 'unit', 'Object.assign({},cargo.forms[form].values,values)', 'cargo.forms[form].data')),
41
42
  W('address_street_check', '!held', { id: 'address_street_validate', type: 'CALL-TOOL', tool: 'validate-address', variable: 'checked', args: { address: '{{line}}', previous_response_id: '' }, onFail: S('address_street_check_failed', 'checked', 'null') }),
42
43
  S('address_street_verdict', 'verdict', E(addressVerdict, 'checked', 'value')),
43
- S('address_street_checked', 'noop', '(cargo.inputCheck=' + E(streetCheck, 'cargo.forms[form]', 'values', 'verdict', 'value', 'reading', "({en:yesNoKeys('en',cargo),es:yesNoKeys('es',cargo)})") + ', true)'),
44
+ S('address_street_checked', 'noop', '(cargo.inputCheck=' + E(streetCheck, 'cargo.forms[form]', 'values', 'verdict', 'value', 'reading', "({en:yesNoKeys('en',cargo),es:yesNoKeys('es',cargo)})", 'unit') + ', true)'),
44
45
  S('address_street_unit_question', 'noop', E(unitQuestion, 'cargo.forms[form].data', BUILDING))
45
- ], { parameters: [P('form'), P('value'), P('values', 'object'), P('reading', 'object')], variables: V({ components: '', result: null, location: null, held: false, line: '', checked: null, verdict: null }), contract: { tools: ['geocode-street', 'validate-address'], result: { path: 'cargo.inputCheck', type: 'object' } } });
46
+ ], { parameters: [P('form'), P('value'), P('values', 'object'), P('reading', 'object')], variables: V({ components: '', result: null, location: null, held: false, unit: '', line: '', checked: null, verdict: null }), contract: { tools: ['geocode-street', 'validate-address'], result: { path: 'cargo.inputCheck', type: 'object' } } });
46
47
  // A ZIP code with several place names: the city is one of them (accents, case and edge punctuation folded), never other text.
47
48
  const city = C('address-city-validate', 'Match a city to the ZIP code\'s listed place names; any city when the ZIP code lists none.', [
48
49
  S('address_city_check', 'noop', "(function(choices,listed){cargo.inputCheck=!choices.length?{ok:true,value:String(value)}:listed?{ok:true,value:listed}:{ok:false,quiet:true};return true;})(cargo.forms[form].data.city_choices || []," + E(listedPlace, 'value', 'cargo.forms[form].data.city_choices') + ")")
@@ -52,7 +53,7 @@ const unit = C('address-unit-validate', 'Refuse a unit answer that is not a unit
52
53
  S('address_unit_pre', 'pre', E(unitPrecheck, 'cargo.forms[form].data', 'value')),
53
54
  S('address_unit_line', 'line', "pre.check ? " + E(addressLine, 'cargo.forms[form].data.check_street', 'pre.unit', 'Object.assign({},cargo.forms[form].values,values)', 'cargo.forms[form].data') + " : ''"),
54
55
  S('address_unit_rid', 'rid', "String(cargo.forms[form].data.check_rid || '')"),
55
- W('address_unit_check', 'pre.check === true', { id: 'address_unit_validate', type: 'CALL-TOOL', tool: 'validate-address', variable: 'checked', args: { address: '{{line}}', previous_response_id: '{{rid}}' }, onFail: S('address_unit_check_failed', 'checked', 'null') }),
56
+ W('address_unit_check', 'pre.check === true && !pre.known', { id: 'address_unit_validate', type: 'CALL-TOOL', tool: 'validate-address', variable: 'checked', args: { address: '{{line}}', previous_response_id: '{{rid}}' }, onFail: S('address_unit_check_failed', 'checked', 'null') }),
56
57
  S('address_unit_result', 'noop', '(cargo.inputCheck=' + E(unitResult, 'cargo.forms[form].data', 'pre', 'checked') + ', true)')
57
58
  ], { parameters: [P('form'), P('value'), P('values', 'object')], variables: V({ pre: null, line: '', rid: '', checked: null }), contract: { tools: ['validate-address'], result: { path: 'cargo.inputCheck', type: 'object' } } });
58
59
  const formCheck = C('address-form-validate', 'The whole address: a card that left the unit blank on a building with units is asked it once.', [
@@ -65,7 +66,7 @@ const checkNo = C('address-check-declined', 'NO to Google\'s version of the addr
65
66
  S('address_check_declined', 'noop', E(checkDeclined, 'cargo', 'form', 'acceptFormReadings', 'resetFormInputs'))
66
67
  ], { parameters: [P('form'), P('input'), P('value'), P('reading', 'object')] });
67
68
  const zipPrompt = C('address-zip-prompt', 'Render the ZIP question from the owned address instance, naming the calling form\'s label.', [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 '+(cargo.forms[form].data.label||'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 '+(cargo.forms[form].data.label_es||'nueva dirección')+'?',true)")], { parameters: [P('form')], contract: { result: { path: 'cargo.forms[form].data', type: 'object' } } });
68
- 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.city_choice&&!cargo.forms[form].values.city?'Got it. ':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)+'. ':'')+(cargo.forms[form].data.labelled?'What is the street of your '+cargo.forms[form].data.label+'?':'What is the street address?'),cargo.forms[form].data.street_question_es=(cargo.forms[form].data.city_choice&&!cargo.forms[form].values.city?'Entendido. ':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)+'. ':'')+(cargo.forms[form].data.labelled?'¿Cuál es la calle de su '+cargo.forms[form].data.label_es+'?':'¿Cuál es la dirección?'),true)")], { parameters: [P('form')], contract: { result: { path: 'cargo.forms[form].data', type: 'object' } } });
69
+ const streetPrompt = C('address-street-prompt', 'Include the ZIP-derived location when asking for the street; no acknowledgement when no city is named yet.', [S('address_street_prompt', 'noop', "(cargo.forms[form].data.street_question=(cargo.forms[form].data.city_choice&&!cargo.forms[form].values.city?'':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)+'. ':'')+(cargo.forms[form].data.labelled?'What is the street of your '+cargo.forms[form].data.label+'?':'What is the street address?'),cargo.forms[form].data.street_question_es=(cargo.forms[form].data.city_choice&&!cargo.forms[form].values.city?'':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)+'. ':'')+(cargo.forms[form].data.labelled?'¿Cuál es la calle de su '+cargo.forms[form].data.label_es+'?':'¿Cuál es la dirección?'),true)")], { parameters: [P('form')], contract: { result: { path: 'cargo.forms[form].data', type: 'object' } } });
69
70
  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=data.labelled?'What city is your '+data.label+' in?':'What city is it?';data.city_question_es=data.labelled?'¿En qué ciudad está su '+data.label_es+'?':'¿Qué ciudad es?';return true;}data.city_question=(data.labelled?'Which city is your '+data.label+' in: ':'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=(data.labelled?'¿En qué ciudad está su '+data.label_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' } } });
70
71
  // NO at the read-back asks which part is wrong and re-asks only that part; ALL starts over.
71
72
  const PARTS = [{ key: 'zip', label: 'ZIP code', label_es: 'Código postal', phrases: ['1', 'zip', 'zip code', 'postal code', 'código postal', 'codigo postal'] }, { key: 'city', label: 'City', label_es: 'Ciudad', phrases: ['2', 'city', 'ciudad'] }, { key: 'street', label: 'Street', label_es: 'Calle', phrases: ['3', 'street', 'calle'] }, { key: 'unit', label: 'Apartment', label_es: 'Apartamento', phrases: ['4', 'apartment', 'apt', 'unit', 'apartamento', 'unidad', 'departamento'] }, { key: 'all', label: 'Everything', label_es: 'Todo', phrases: ['5', 'all', 'everything', 'all of it', 'todo', 'toda'] }];
@@ -43,7 +43,10 @@ export function addressVerdict(result: any, said: any): {
43
43
  } | null;
44
44
  /** The validate-address verdict applied to the street answer (the street validator's last step). Returns the validator's
45
45
  * answer: a proposal to confirm Google's version first, or the street accepted. `keys` are the yes/no words for each language. */
46
- export function streetCheck(state: any, values: any, verdict: any, value: any, reading: any, keys: any): {
46
+ /** The unit that goes into the street's one check: the form's, else the unit the street answer itself carries ("# 2",
47
+ * "Apt 2", "apartamento 2"), read with the unit input's own pattern. '' when none, or when it is not unit-shaped. */
48
+ export function streetUnit(state: any, values: any, reading: any): any;
49
+ export function streetCheck(state: any, values: any, verdict: any, value: any, reading: any, keys: any, unit: any): {
47
50
  ok: boolean;
48
51
  value: string;
49
52
  proposal: any;
@@ -73,9 +76,20 @@ export function unitsGiven(state: any): {
73
76
  invalid: {
74
77
  name: string;
75
78
  }[];
79
+ message?: undefined;
80
+ message_es?: undefined;
81
+ } | {
82
+ ok: boolean;
83
+ invalid: {
84
+ name: string;
85
+ }[];
86
+ message: string;
87
+ message_es: string;
76
88
  } | {
77
89
  ok: boolean;
78
90
  invalid?: undefined;
91
+ message?: undefined;
92
+ message_es?: undefined;
79
93
  };
80
94
  /** The unit question: the building's own wording once Google says it has units, else the form's ordinary one. */
81
95
  export function unitQuestion(data: any, building: any): boolean;
@@ -87,24 +101,43 @@ export function unitPrecheck(data: any, value: any): {
87
101
  message_es: string;
88
102
  value?: undefined;
89
103
  check?: undefined;
104
+ known?: undefined;
105
+ confirmed?: undefined;
90
106
  unit?: undefined;
91
107
  } | {
92
108
  ok: boolean;
93
109
  value: string;
94
110
  check: boolean;
111
+ known: boolean;
112
+ confirmed: any;
95
113
  unit: string;
96
114
  message?: undefined;
97
115
  message_es?: undefined;
116
+ } | {
117
+ ok: boolean;
118
+ value: string;
119
+ check: boolean;
120
+ unit: string;
121
+ message?: undefined;
122
+ message_es?: undefined;
123
+ known?: undefined;
124
+ confirmed?: undefined;
98
125
  } | {
99
126
  ok: boolean;
100
127
  value: string;
101
128
  message?: undefined;
102
129
  message_es?: undefined;
103
130
  check?: undefined;
131
+ known?: undefined;
132
+ confirmed?: undefined;
104
133
  unit?: undefined;
105
134
  };
106
135
  /** Google's answer for the address with its unit: a unit it could not confirm is asked once more, then kept as given. */
107
136
  export function unitResult(data: any, pre: any, checked: any): {
137
+ ok: boolean;
138
+ message: string;
139
+ message_es: string;
140
+ } | {
108
141
  message?: any;
109
142
  message_es?: any;
110
143
  quiet?: boolean | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/helpers/address.js"],"names":[],"mappings":"AAEA;;;;;EAQC;AACD;;;;;SAWC;AACD,gDAEC;AACD;;;;;EASC;AACD;gHACgH;AAChH,8DAIC;AACD,sGAAsG;AACtG,oFAKC;AACD;;;uGAGuG;AACvG;;;;;;;;;;;;;;SAeC;AACD;kIACkI;AAClI;;;;;;;;;;;;;;;;EAyCC;AACD;qFACqF;AACrF,uFASC;AACD;mGACmG;AACnG,oDAKC;AACD;sDACsD;AACtD;;;;;;;;EAIC;AACD,iHAAiH;AACjH,gEAIC;AACD;0EAC0E;AAC1E;;;;;;;;;;;;;;;;;;;;;EAKC;AACD,yHAAyH;AACzH;;;;;;EAUC;AACD;;;;;;;;;;;EAQC"}
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/helpers/address.js"],"names":[],"mappings":"AAEA;;;;;EAQC;AACD;;;;;SAWC;AACD,gDAEC;AACD;;;;;EASC;AACD;gHACgH;AAChH,8DAIC;AACD,sGAAsG;AACtG,oFAKC;AACD;;;uGAGuG;AACvG;;;;;;;;;;;;;;SAeC;AACD;kIACkI;AAClI;qHACqH;AACrH,uEASC;AACD;;;;;;;;;;;;;;;;EA2CC;AACD;qFACqF;AACrF,uFASC;AACD;mGACmG;AACnG,oDAKC;AACD;sDACsD;AACtD;;;;;;;;;;;;;;;;;;;EAUC;AACD,iHAAiH;AACjH,gEAIC;AACD;0EAC0E;AAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMC;AACD,yHAAyH;AACzH;;;;;;;;;;EAaC;AACD;;;;;;;;;;;EAQC"}
@@ -72,7 +72,21 @@ export function addressVerdict(result, said) {
72
72
  }
73
73
  /** The validate-address verdict applied to the street answer (the street validator's last step). Returns the validator's
74
74
  * answer: a proposal to confirm Google's version first, or the street accepted. `keys` are the yes/no words for each language. */
75
- export function streetCheck(state, values, verdict, value, reading, keys) {
75
+ /** The unit that goes into the street's one check: the form's, else the unit the street answer itself carries ("# 2",
76
+ * "Apt 2", "apartamento 2"), read with the unit input's own pattern. '' when none, or when it is not unit-shaped. */
77
+ export function streetUnit(state, values, reading) {
78
+ const norm = x => String(x ?? '').replace(/^(apartment|apartamento|departamento|apt\.?|unit|unidad|#)\s*/i, '').replace(/[.,#:]+/g, ' ').replace(/\s+/g, ' ').trim();
79
+ const shaped = u => /^[A-Za-z]$/.test(u) || /\d/.test(u) && /^[A-Za-z0-9-]{1,8}(?:\s[A-Za-z0-9-]{1,4})?$/.test(u) ? u : '';
80
+ const given = Object.assign({}, state.values, values).unit;
81
+ if (given)
82
+ return shaped(norm(given));
83
+ const spec = (state.specs || []).find(x => x.name === 'unit'), profile = spec && spec.profile, raw = String(reading && reading.raw || '');
84
+ if (!raw || !profile || !profile.regex)
85
+ return '';
86
+ const m = new RegExp(profile.regex, 'i').exec(raw);
87
+ return m ? shaped(norm(m[profile.group || 0])) : '';
88
+ }
89
+ export function streetCheck(state, values, verdict, value, reading, keys, unit) {
76
90
  const data = state.data, said = String(value), cur = Object.assign({}, state.values, values);
77
91
  const derived = state.accepted?.city?.origin === 'derived', cityInput = data.city_known === true;
78
92
  const setCity = v => { if (!v.city)
@@ -112,6 +126,8 @@ export function streetCheck(state, values, verdict, value, reading, keys) {
112
126
  data.check = null;
113
127
  return { ok: true, value: said };
114
128
  }
129
+ // the unit checked with the street, and whether Google confirmed it: the unit's own check and the form's check read it
130
+ data.check_unit = unit && verdict && verdict.street ? { unit: String(unit), confirmed: verdict.unit_confirmed === true } : null;
115
131
  data.check = null;
116
132
  data.street_city = cityFrom(verdict);
117
133
  data.check_street = verdict && verdict.street ? verdict.street : '';
@@ -184,6 +200,12 @@ export function unitsGiven(state) {
184
200
  data.units_told = true;
185
201
  return { ok: false, invalid: [{ name: 'unit' }] };
186
202
  }
203
+ // the unit Google checked with the street (given with it or before it) and could not confirm: asked once more, then kept as given
204
+ const c = data.check_unit, given = String(state.values.unit ?? '').replace(/^(apartment|apartamento|departamento|apt\.?|unit|unidad|#)\s*/i, '').replace(/[.,#:]+/g, ' ').replace(/\s+/g, ' ').trim();
205
+ if (c && c.confirmed === false && given === c.unit && !data.unit_retry) {
206
+ data.unit_retry = true;
207
+ return { ok: false, invalid: [{ name: 'unit' }], message: 'I could not confirm apartment ' + c.unit + ' at that address.', message_es: 'No pude confirmar el apartamento ' + c.unit + ' en esa dirección.' };
208
+ }
187
209
  return { ok: true };
188
210
  }
189
211
  /** The unit question: the building's own wording once Google says it has units, else the form's ordinary one. */
@@ -202,16 +224,25 @@ export function unitPrecheck(data, value) {
202
224
  const u = String(value).replace(/^(apartment|apartamento|departamento|apt\.?|unit|unidad|#)\s*/i, '').replace(/[.,#:]+/g, ' ').replace(/\s+/g, ' ').trim();
203
225
  if (!(/^[A-Za-z]$/.test(u) || /\d/.test(u) && /^[A-Za-z0-9-]{1,8}(?:\s[A-Za-z0-9-]{1,4})?$/.test(u)))
204
226
  return { ok: false, message: "That doesn't look like an apartment number.", message_es: 'Eso no parece un número de apartamento.' };
227
+ if (data.check_unit && data.check_unit.unit === u)
228
+ return { ok: true, value: String(value), check: true, known: true, confirmed: data.check_unit.confirmed, unit: u };
205
229
  return data.check_street ? { ok: true, value: String(value), check: true, unit: u } : { ok: true, value: String(value) };
206
230
  }
207
231
  /** Google's answer for the address with its unit: a unit it could not confirm is asked once more, then kept as given. */
208
232
  export function unitResult(data, pre, checked) {
209
233
  if (!pre.check)
210
234
  return { ok: pre.ok, ...(pre.value !== undefined ? { value: pre.value } : {}), ...(pre.quiet ? { quiet: true } : {}), ...(pre.message ? { message: pre.message, message_es: pre.message_es } : {}) };
235
+ // a unit the street's check already carried: taken without a second call; the form's check asks it once more when unconfirmed
236
+ const unconfirmed = () => ({ ok: false, message: 'I could not confirm apartment ' + pre.unit + ' at that address.', message_es: 'No pude confirmar el apartamento ' + pre.unit + ' en esa dirección.' });
237
+ if (pre.known) {
238
+ if (data.validation)
239
+ data.validation.unit_confirmed = pre.confirmed;
240
+ return { ok: true, value: pre.value };
241
+ }
211
242
  const confirmed = !!(checked && checked.status === 'ok' && checked.parts && checked.parts.subpremise && checked.parts.subpremise.level === 'CONFIRMED');
212
243
  if (checked && checked.status === 'ok' && !confirmed && !data.unit_retry) {
213
244
  data.unit_retry = true;
214
- return { ok: false, message: 'I could not confirm apartment ' + pre.unit + ' at that address.', message_es: 'No pude confirmar el apartamento ' + pre.unit + ' en esa dirección.' };
245
+ return unconfirmed();
215
246
  }
216
247
  data.unit_retry = false;
217
248
  if (data.validation)
@@ -1 +1 @@
1
- export const JSFE_RUNTIME_FINGERPRINT = "sha256:8d8b251566be0f473808d9214fce948a1df751d57a13d7f41c7c90b4198c4957";
1
+ export const JSFE_RUNTIME_FINGERPRINT = "sha256:a3ad9d949b8c7921e96bcf374089ff2203b16432b7ac42d0e6735883fbea1fde";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsfe",
3
- "version": "1.104.0",
3
+ "version": "1.104.1",
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",