jsfe 1.74.0 → 1.76.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.
@@ -375,7 +375,7 @@ export function formSubmissionReaders(submission, getSession) {
375
375
  const read = profile.kind === 'choice'
376
376
  ? (profile.choices || []).some(choice => String(choice.key) === raw && (!choice.current_only || hit.form === current.form && (hit.name === current.name || current.names?.includes(hit.name)))) ? { value: raw }
377
377
  // A combobox's own text: a choice that takes other text keeps it (with a letter when the profile asks for one).
378
- : profile.accept_other === true && raw.trim() && (!profile.other_needs_letter || /\p{L}/u.test(raw)) ? { value: raw.trim() } : null
378
+ : profile.accept_other === true && raw.trim() && (!profile.other_needs_letter || /\p{L}/u.test(raw)) && (!profile.other_needs_digit || /\d/.test(raw)) ? { value: raw.trim() } : null
379
379
  : readInputProfile({ ...profile, marked: false }, raw, true);
380
380
  const valid = read && Object.hasOwn(read, 'value') && read.value !== '' && read.refused !== true && !read.incompleteMoney;
381
381
  return { ...hit, value: valid ? read.value : raw, invalid: !valid, origin: 'form_submission', current: false, utterance: '' };
@@ -4,6 +4,8 @@ export function setTaskGate(cargo: any, form: any, gate: any, active: any): bool
4
4
  export function serviceDigits(text: any): string;
5
5
  export function otpDigits(text: any): string;
6
6
  export function contactPrompt(cargo: any, options: any, callerAllowed: any, partial?: boolean, es?: boolean): string;
7
+ /** The line a ranked pick at the contact question is answered with, before the question again (owner 2026-11-18). */
8
+ export function rankedContactLine(kind: any, options: any, cargo: any, es?: boolean): string;
7
9
  export function contactError(kind: any, options: any, es?: boolean): string;
8
10
  export function otpWhere(cargo: any, es?: boolean): string;
9
11
  export function otpPrompt(cargo: any, es?: boolean): string;
@@ -1 +1 @@
1
- {"version":3,"file":"identity-flows.d.ts","sourceRoot":"","sources":["../../src/forms/identity-flows.js"],"names":[],"mappings":"AA8CA,+GAA+G;AAC/G,oFAOC;AAQD,wFAAwF;AACxF,iDAGC;AACD,6CAMC;AACD,qHAQC;AASD,4EAKC;AAiGD,2DAOC;AACD,4DAOC;AACD,gHAAgH;AAChH,8DAGC;AAyJD,8EAGC;AA4BD,4FAA4F;AAC5F;;;;EAOC;AAWD,oGAOC;AApQD,iCAAgC,wIAAwI,CAAC;AACzK,wCAAuC,CAAC,CAAC;AAuRzC,0BAAsK"}
1
+ {"version":3,"file":"identity-flows.d.ts","sourceRoot":"","sources":["../../src/forms/identity-flows.js"],"names":[],"mappings":"AAgDA,+GAA+G;AAC/G,oFAOC;AAQD,wFAAwF;AACxF,iDAGC;AACD,6CAiBC;AACD,qHAQC;AASD,qHAAqH;AACrH,6FAKC;AACD,4EAMC;AAkHD,2DAOC;AACD,4DAOC;AACD,gHAAgH;AAChH,8DAGC;AA0JD,8EAGC;AA4BD,4FAA4F;AAC5F;;;;EAOC;AAWD,oGAOC;AArQD,iCAAgC,wIAAwI,CAAC;AACzK,wCAAuC,CAAC,CAAC;AAwRzC,0BAAsK"}
@@ -2,7 +2,9 @@
2
2
  import { defineWorker, defineForm } from './contracts.js';
3
3
  import { OTP_EXPIRY_MS } from '../helpers/otp-check.js';
4
4
  // maskEmail is a standard function: these functions run as flow expressions too, where it is in scope by name.
5
- import { maskEmail } from '../helpers/contact.js';
5
+ import { maskEmail, emailAttempt } from '../helpers/contact.js';
6
+ // an answer that tries to give an email is never a phone number (prod 2026-11-17); inlined, so it needs no host function
7
+ const emailTry = `(${emailAttempt.toString()})(contact_text)`;
6
8
  const vars = o => Object.fromEntries(Object.entries(o).map(([k, v]) => [k, { type: Array.isArray(v) ? 'array' : v === null || typeof v === 'object' ? 'object' : typeof v, value: v }]));
7
9
  const param = (name, description, type = 'string') => ({ name, type, description });
8
10
  const set = (id, variable, value) => ({ id, type: 'SET', variable, value });
@@ -79,7 +81,22 @@ export function otpDigits(text) {
79
81
  const filler = new Set(['el', 'mi', 'es', 'codigo', 'code', 'is', 'my', 'the', 'numero', 'number', 'a', 'ver']);
80
82
  const tokens = String(text || '').toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').split(/[\s,.;:!?-]+/).filter(t => t && !filler.has(t));
81
83
  const spoken = tokens.length && tokens.some(t => Object.hasOwn(map, t)) && tokens.every(t => /^\d+$/.test(t) || Object.hasOwn(map, t)) ? tokens.map(t => map[t] ?? t).join('') : '';
82
- return spoken.length === 6 ? spoken : String(text || '').replace(/\D/g, '');
84
+ if (spoken.length === 6)
85
+ return spoken;
86
+ // A caller who restarts the code ("57. 57, 21, 80.") or says it twice gives the code last (owner 2026-11-18). Only an answer
87
+ // that is nothing but digits: the same six twice, or a restart that ends at a pause the transcript marks (a period or
88
+ // comma) and is how the last six begin. A number said digit by digit, a single run, or one with other words is left as it was.
89
+ if (tokens.length && tokens.every(t => /^\d+$/.test(t) || Object.hasOwn(map, t))) {
90
+ const all = tokens.map(t => map[t] ?? t).join(''), cut = all.length - 6, head = all.slice(0, cut), tail = all.slice(cut);
91
+ const marked = String(text || '').toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').split(/[.,;]/).map(p => p.split(/\s+/).filter(t => t && !filler.has(t)).map(t => map[t] ?? t).join('')).filter(Boolean);
92
+ let at = 0;
93
+ const pauses = new Set(marked.map(p => (at += p.length)));
94
+ const twice = cut === 6 && head === tail && tokens.length >= 2, restart = cut > 0 && cut < 6 && pauses.has(cut) && tail.startsWith(head);
95
+ if (twice || restart)
96
+ return tail;
97
+ }
98
+ else { /* other words: read as before */ }
99
+ return String(text || '').replace(/\D/g, '');
83
100
  }
84
101
  export function contactPrompt(cargo, options, callerAllowed, partial = false, es = false) {
85
102
  if (partial)
@@ -100,23 +117,33 @@ const contactReplay = (id, extra = {}) => call(id, 'get-cell-or-email', { contac
100
117
  // third miss in a row offers the retry menu.
101
118
  const contactMiss = id => call(id, 'contact-misread', { contact_options: '{{contact_options}}', error_message: '{{contact_error}}', error_message_es: '{{contact_error_es}}' }, 'replace');
102
119
  const contactMenu = id => call(id, 'generic-retry-with-options', { error_message: '{{contact_error}}', error_message_es: '{{contact_error_es}}', retry_flow: '{{contact_options.retry_flow}}', cancel_flow: '{{contact_options.cancel_flow}}', capture_patterns: '{{cargo.authCapture}}', retry_call_type: '{{contact_options.retry_call_type}}', parent_form: '{{contact_options.parent_form}}', contact_options: '{{contact_options}}', gce_menu: true }, 'replace');
120
+ /** The line a ranked pick at the contact question is answered with, before the question again (owner 2026-11-18). */
121
+ export function rankedContactLine(kind, options, cargo, es = false) {
122
+ const verb = es ? cargo.verb_es : cargo.verb;
123
+ const account = options.account_pattern ? (es ? options.account_name_es || options.account_name : options.account_name) : '';
124
+ if (kind === 'other_contact')
125
+ return es ? `Claro, ${verb} ese teléfono o correo electrónico.` : `Sure, ${verb} that phone number or email.`;
126
+ return es ? `No hay problema. Sirve cualquier teléfono o correo electrónico de su cuenta${account ? ', o ' + account : ''}. Si no tiene ninguno, ${verb} AGENTE para hablar con una persona.` : `No problem. Any phone number or email on your account works${account ? ', or ' + account : ''}. If you don't have any of them, ${verb} AGENT to speak with a person.`;
127
+ }
103
128
  export function contactError(kind, options, es = false) {
104
129
  const account = options.account_pattern ? (es ? options.account_name_es || options.account_name : options.account_name) : '';
105
130
  if (kind === 'international')
106
131
  return es ? "Un número fuera de EE. UU. y Canadá no se puede usar aquí. Por favor indique el correo de su cuenta" + (account ? ', o ' + account : '') + ", o un celular de EE. UU. o Canadá." : "A number outside the US and Canada can't be used here. Please give the email on your account" + (account ? ', or ' + account : '') + ", or a US or Canadian mobile number.";
132
+ if (kind === 'invalid_email')
133
+ return es ? 'Lo siento, no entendí el correo electrónico completo, por ejemplo: nombre arroba gmail punto com.' : "Sorry, I didn't get the whole email address, for example: name at gmail dot com.";
107
134
  if (kind === 'invalid_phone')
108
135
  return es ? 'El número de teléfono que proporcionó no es válido.' : "Sorry, the phone number you provided isn't valid.";
109
136
  return es ? 'Lo siento, necesito el teléfono o correo electrónico asociado con su cuenta' + (account ? ', o ' + account : '') + ' para continuar.' : 'Sorry, I do need the phone or email associated with your account' + (account ? ', or ' + account : '') + ' to proceed.';
110
137
  }
111
138
  const contact = worker('get-cell-or-email', 'GetCellOrEmail', 'Identify a supplied contact or account number; collect missing data through a FORM, with caller-ID eligibility and bounded contact validation.', {
112
- parameters: contactParams, variables: vars({ ...contactDefaults, contact_profiles_base: contactProfiles, contact_named_options: null, contact_names_account: ['número de cuenta', 'numero de cuenta', 'mi número de cuenta', 'mi numero de cuenta', 'con mi número de cuenta', 'con mi numero de cuenta', 'con el número de cuenta', 'con el numero de cuenta', 'account number', 'my account number', 'with my account number', 'with the account number'] }), contract: { role: 'collector', summary: 'Contact identification with FORM ancestry', result: { paths: ['cell_number', 'email', 'acct_number', 'cargo.contactKind', 'cargo.contactValue'], type: 'object' } },
139
+ parameters: contactParams, variables: vars({ ...contactDefaults, contact_profiles_base: contactProfiles, contact_named_options: null, contact_rank_asked: '', contact_rank_offers: [], contact_rank_reply: null, contact_rank_kind: '', contact_rank_options: null, contact_rank_first: false, contact_names_account: ['número de cuenta', 'numero de cuenta', 'mi número de cuenta', 'mi numero de cuenta', 'con mi número de cuenta', 'con mi numero de cuenta', 'con el número de cuenta', 'con el numero de cuenta', 'account number', 'my account number', 'with my account number', 'with the account number'] }), contract: { role: 'collector', summary: 'Contact identification with FORM ancestry', result: { paths: ['cell_number', 'email', 'acct_number', 'cargo.contactKind', 'cargo.contactValue'], type: 'object' } },
113
140
  steps: [
114
141
  set('identity_contact_options', 'contact_options', "contact_options || (retrying && cargo.contactOptions ? Object.assign({},cargo.contactOptions,{fromMenu:true,intro:'',intro_es:''}) : {retry_flow:retry_flow || 'authenticate-user',cancel_flow:cancel_flow || 'contact-support',account_pattern:account_pattern,account_name:account_name,account_name_es:account_name_es,account_shape:account_shape,intro:intro,intro_es:intro_es,caller_on_file:caller_on_file,retry_call_type:retry_call_type || 'reboot',validate_flow:validate_flow,merge_partials:merge_partials === true || merge_partials === 'true',parent_form:parent_form})"),
115
142
  // options carried from an earlier verification may name a task the caller has since closed; opening under it fails
116
143
  set('identity_contact_live_parent', 'contact_options', "contact_options.parent_form && !(cargo.forms && cargo.forms[contact_options.parent_form]) ? Object.assign({},contact_options,{parent_form:''}) : contact_options"),
117
144
  effect('identity_contact_remember', '(cargo.contactOptions=contact_options,cargo.authCapture=[{variable:"cell_number",reader:"phone"},{variable:"email",reader:"email"}].concat(contact_options.account_pattern?[{variable:"acct_number",regex:contact_options.account_pattern,normalizer:"[^0-9]"}]:[]),true)'),
118
145
  when('identity_contact_new_rejection_series', '!gce_rejected', effect('identity_contact_rejections_reset', '(cargo.gceRejects=0,true)')),
119
- when('identity_contact_new_miss_series', '!gce_missed', effect('identity_contact_misses_reset', '(cargo.gceMisses=0,true)')),
146
+ when('identity_contact_new_miss_series', '!gce_missed', effect('identity_contact_misses_reset', '(cargo.gceMisses=0,cargo.gceRanked=false,true)')),
120
147
  set('identity_contact_partial', 'contact_partial', "!!(contact_options.merge_partials && gce_partial && cargo.gcePartial)"),
121
148
  when('identity_contact_partial_reset', '!contact_partial', effect('identity_contact_partial_forget', "(cargo.gcePartial='',true)")),
122
149
  set('identity_contact_allowed', 'contact_allowed', "!!cargo.callerId && !callerIsInternational(cargo) && !cargo.callerDeclined && contact_options.caller_on_file !== 'no'"),
@@ -132,7 +159,7 @@ const contact = worker('get-cell-or-email', 'GetCellOrEmail', 'Identify a suppli
132
159
  call('identity_contact_collect', 'collect-service-answer', { profiles: '{{contact_profiles}}', question: '{{contact_question}}', question_es: '{{contact_question_es}}', keypad: '{{contact_keypad}}', prefill: '{{contact_prefill}}', parent_form: '{{contact_options.parent_form}}', context: 'account verification', context_es: 'verificación de cuenta' }),
133
160
  set('identity_contact_answer', 'contact_text', expression(contactAnswer, 'cargo.serviceAnswer')),
134
161
  set('identity_contact_spoken', 'contact_digits', `(${serviceDigits.toString()})(contact_text)`),
135
- set('identity_contact_piece', 'contact_digits', "!/@/.test(contact_text) && !readEmail(contact_text) && /^[^0-9]*[0-9][0-9\\s.,-]*[^0-9]*$/.test(contact_digits) ? contact_digits.replace(/\\D/g,'') : ''"),
162
+ set('identity_contact_piece', 'contact_digits', "!/@/.test(contact_text) && !readEmail(contact_text) && !" + emailTry + " && /^[^0-9]*[0-9][0-9\\s.,-]*[^0-9]*$/.test(contact_digits) ? contact_digits.replace(/\\D/g,'') : ''"),
136
163
  set('identity_contact_join', 'contact_text', "contact_partial && contact_digits ? String(cargo.gcePartial)+contact_digits : contact_text"),
137
164
  set('identity_contact_join_digits', 'contact_digits', "contact_partial && contact_digits ? String(cargo.gcePartial)+contact_digits : contact_digits"), effect('identity_contact_piece_consumed', "(cargo.gcePartial='',cargo.contactIntroSkip=false,true)"),
138
165
  when('identity_contact_split', "contact_options.merge_partials && contact_digits && (contact_options.account_shape || []).some(function(s){return String(s.first || '').includes(contact_digits.charAt(0)) && contact_digits.length < Math.min.apply(null,s.lengths || [0]);})", effect('identity_contact_hold', '(cargo.gcePartial=contact_digits,true)')),
@@ -140,9 +167,14 @@ const contact = worker('get-cell-or-email', 'GetCellOrEmail', 'Identify a suppli
140
167
  when('identity_contact_split_overshoot', "contact_partial && contact_digits.length > (contact_options.account_shape || []).reduce(function(max,s){return Math.max(max,Math.max.apply(null,s.lengths || [0]));},0)", call('identity_contact_restart_split', 'contact-split-failed', { contact_options: '{{contact_options}}' }, 'replace')),
141
168
  set('identity_contact_identifier', 'contact_id', "contact_options.account_pattern ? readIdentifier(contact_text,contact_options.account_pattern) : null"),
142
169
  set('identity_contact_phone', 'contact_phone', "readPhone(contact_text) || (validatePhone(contact_digits) ? contact_digits : '')"), set('identity_contact_email', 'contact_mail', 'readEmail(contact_text)'),
143
- set('identity_contact_classify', 'contact_kind', "contact_id && contact_id.kind === 'account' ? 'account' : contact_phone ? 'phone' : contact_mail ? 'email' : contact_options.account_pattern && !contact_digits && matchesChoice(contact_text,contact_names_account) ? 'names_account' : readInternationalPhone(contact_text) ? 'international' : isAgentRequest(contact_text) ? 'agent' : isExitRequest(contact_text) ? 'exit' : contact_allowed && /^(?:no|nope|nah)\\b/i.test(contact_text.trim()) && !/[0-9@]/.test(contact_text) ? 'decline' : contact_allowed && cargo.serviceAnswer && cargo.serviceAnswer.values.caller_decision === 'yes' ? 'caller' : contact_digits ? 'invalid_phone' : contact_text.trim().split(/\\s+/).length>=3 && !/[0-9@]/.test(contact_text) ? 'unmapped' : 'invalid'"),
170
+ set('identity_contact_classify', 'contact_kind', "contact_id && contact_id.kind === 'account' ? 'account' : contact_phone ? 'phone' : contact_mail ? 'email' : contact_options.account_pattern && !contact_digits && matchesChoice(contact_text,contact_names_account) ? 'names_account' : readInternationalPhone(contact_text) ? 'international' : isAgentRequest(contact_text) ? 'agent' : isExitRequest(contact_text) ? 'exit' : " + emailTry + " ? 'invalid_email' : contact_allowed && /^(?:no|nope|nah)\\b/i.test(contact_text.trim()) && !/[0-9@]/.test(contact_text) ? 'decline' : contact_allowed && cargo.serviceAnswer && cargo.serviceAnswer.values.caller_decision === 'yes' ? 'caller' : contact_digits ? 'invalid_phone' : /[a-záéíóúñü]/i.test(contact_text) ? 'unmapped' : 'invalid'"),
144
171
  set('identity_contact_named', 'contact_named_options', "Object.assign({},contact_options,{fromMenu:false,intro:'Sure, your account number.',intro_es:'Claro, su número de cuenta.'})"),
145
172
  set('identity_contact_error', 'contact_error', expression(contactError, 'contact_kind', 'contact_options')), set('identity_contact_error_es', 'contact_error_es', expression(contactError, 'contact_kind', 'contact_options', 'true')),
173
+ // A reply with letters and no identifier goes to the reply ranker with the question's own options (owner 2026-11-18): the
174
+ // identifiers above are read lexically anywhere in the reply; the ranker only picks one of these, never an identifier.
175
+ set('identity_contact_rank_asked', 'contact_rank_asked', "language === 'es' ? contact_question_es : contact_question"),
176
+ set('identity_contact_rank_offers', 'contact_rank_offers', "[{key:'no_identifier',label:'does not know or does not have the phone number, email or account number on the account'},{key:'other_contact',label:'has or wants to give a different phone number or email'},{key:'__agent',label:'speak with a person (a live agent)'},{key:'exit',label:'does not want to continue and stops here'}].concat(callerTextNumber(cargo) ? [{key:'text',label:'continue by text message'}] : [])"),
177
+ set('identity_contact_rank_clear', 'contact_rank_reply', 'null'),
146
178
  cases('identity_contact_route', {
147
179
  "condition: contact_kind === 'agent'": call('identity_contact_agent', 'live-agent-requested', undefined, 'reboot'),
148
180
  "condition: contact_kind === 'exit'": call('identity_contact_exit', '{{contact_options.cancel_flow}}', undefined, 'reboot'),
@@ -152,11 +184,24 @@ const contact = worker('get-cell-or-email', 'GetCellOrEmail', 'Identify a suppli
152
184
  "condition: contact_kind === 'names_account'": contactReplay('identity_contact_names_account', { contact_options: '{{contact_named_options}}' }),
153
185
  "condition: contact_kind === 'international'": contactMiss('identity_contact_international'),
154
186
  "condition: contact_kind === 'invalid_phone'": contactMiss('identity_contact_invalid_phone'),
155
- "condition: contact_kind === 'unmapped'": { id: 'identity_contact_off_topic', type: 'DISPATCH', onResponse: 'continue', responseContext: 'account identifier: phone number, email address or account number (teléfono, correo o número de cuenta)', outcome: 'unresolved', reason: 'auth_prompt_off_topic' },
187
+ "condition: contact_kind === 'invalid_email'": contactMiss('identity_contact_invalid_email'),
188
+ "condition: contact_kind === 'unmapped'": { id: 'identity_contact_off_topic', type: 'DISPATCH', onResponse: 'continue', responseContext: 'Current question: {{contact_rank_asked}}', responseChoices: 'contact_rank_offers', responseVariable: 'contact_rank_reply', outcome: 'unresolved', reason: 'auth_prompt_off_topic' },
156
189
  "condition: contact_kind === 'invalid'": contactMiss('identity_contact_missing'), default: effect('identity_contact_typed', 'true')
157
190
  }),
191
+ set('identity_contact_rank_read', 'contact_rank_kind', "contact_kind === 'unmapped' && contact_rank_reply && contact_rank_reply.key ? String(contact_rank_reply.key) : ''"),
192
+ set('identity_contact_rank_options', 'contact_rank_options', "['no_identifier','other_contact'].includes(contact_rank_kind) ? Object.assign({},contact_options,{fromMenu:false,intro:" + expression(rankedContactLine, 'contact_rank_kind', 'contact_options', 'cargo') + ",intro_es:" + expression(rankedContactLine, 'contact_rank_kind', 'contact_options', 'cargo', 'true') + "}) : null"),
193
+ // the first such pick in a row is answered and asked again; a second counts as a miss, with the same line
194
+ set('identity_contact_rank_first', 'contact_rank_first', '!!contact_rank_options && !cargo.gceRanked'),
195
+ effect('identity_contact_rank_mark', '(contact_rank_options ? cargo.gceRanked=true : true,true)'),
196
+ set('identity_contact_rank_line', 'contact_error', 'contact_rank_options ? contact_rank_options.intro : contact_error'), set('identity_contact_rank_line_es', 'contact_error_es', 'contact_rank_options ? contact_rank_options.intro_es : contact_error_es'),
158
197
  // A classified response is not authority to abandon identification: the question again, then the bounded recovery menu.
159
- when('identity_contact_unmapped_retry', "contact_kind === 'unmapped'", contactMiss('identity_contact_unmapped')),
198
+ cases('identity_contact_unmapped_retry', {
199
+ "condition: contact_rank_kind === '__agent'": call('identity_contact_rank_agent', 'live-agent-requested', undefined, 'reboot'),
200
+ "condition: contact_rank_kind === 'exit'": call('identity_contact_rank_exit', '{{contact_options.cancel_flow}}', undefined, 'reboot'),
201
+ "condition: contact_rank_kind === 'text'": call('identity_contact_rank_text', 'switch-to-text', undefined, 'reboot'),
202
+ "condition: contact_rank_first": contactReplay('identity_contact_rank_again', { contact_options: '{{contact_rank_options}}', gce_missed: true }),
203
+ "condition: contact_kind === 'unmapped'": contactMiss('identity_contact_unmapped'), default: effect('identity_contact_unmapped_retry_skip', 'true')
204
+ }),
160
205
  set('identity_contact_number', 'acct_number', "contact_kind === 'account' ? String(contact_id.value) : ''"),
161
206
  set('identity_contact_cell', 'cell_number', "contact_kind === 'caller' ? String(cargo.callerId) : contact_kind === 'phone' ? contact_phone : ''"), set('identity_contact_mail', 'email', "contact_kind === 'email' ? contact_mail : ''"),
162
207
  effect('identity_contact_record', "(cargo.contactKind=acct_number?'account':email?'email':String(cell_number).replace(/\\D/g,'').slice(-10)===String(cargo.callerId || '').replace(/\\D/g,'').slice(-10)?'caller':'phone',cargo.contactValue=String(acct_number || email || cell_number),cargo.contactAlternatives=cargo.serviceAnswer.values,true)"),
@@ -282,20 +327,21 @@ const validateCode = worker('validate-otp-code', 'ValidateOtpCode', 'Validate a
282
327
  set('otp_cancel', 'otp_cancel', "cargo.authCancelFlow || 'contact-support'"),
283
328
  set('otp_email_too_ready', 'email_too', "!!(cargo.otp_cell_number && cargo.otpAltSent !== true && cargo.otpAltSent !== 'failed' && validateEmail(String(cargo.otpAltEmail || '')))"),
284
329
  set('otp_reset_no_code', 'no_code_given', 'false'), set('otp_reset_invite', 'whatsapp_invite_sent', 'false'), set('otp_reset_callback', 'answer_key', "''"),
285
- when('otp_tenant_code', 'cargo.authOptions && cargo.authOptions.code_validator && normalized_otp_code.length !== 6 && /[0-9]/.test(user_choice)', call('otp_tenant_code_call', '{{cargo.authOptions.code_validator}}', { answer: '{{user_choice}}' })),
330
+ when('otp_tenant_code', 'cargo.authOptions && cargo.authOptions.code_validator && String(user_choice).replace(/\\D/g,\'\').length !== 6 && /[0-9]/.test(user_choice)', call('otp_tenant_code_call', '{{cargo.authOptions.code_validator}}', { answer: '{{user_choice}}' })),
286
331
  set('otp_other_given', 'other_account_given', "answer_key === 'another_account' ? (cargo.authOtherAccount=String(answer_value || ''),true) : false"),
287
332
  set('otp_other_requested', 'wants_other_account', 'other_account_given || !!(cargo.callerPreselected && normalized_otp_code.length !== 6 && ((cargo.authOptions && cargo.authOptions.other_whole_answer ? pickChoice(user_choice,[{key:\'other\',phrases:otp_phrases.other,exact:true}],false) === \'other\' : matchesChoice(user_choice,otp_phrases.other)) || otp_phrases.other_alone.includes(user_choice.replace(/[.,!?¡¿]/g,\'\').trim())))'),
288
333
  when('otp_tenant_answer', 'cargo.authOptions && cargo.authOptions.answer_handler && normalized_otp_code.length !== 6 && !wants_other_account && answer_key !== \'code_notice\'', call('otp_tenant_answer_call', '{{cargo.authOptions.answer_handler}}', { answer: '{{user_choice}}' })),
289
334
  set('otp_where_early', 'otp_where', expression(otpWhere, 'cargo')), set('otp_where_early_es', 'otp_where_es', expression(otpWhere, 'cargo', 'true')),
290
335
  cases('otp_response', {
291
- 'condition: normalized_otp_code.length === 6': { id: 'otp_check_tool', type: 'CALL-TOOL', tool: 'validate-otp', variable: 'otp_validation_result', args: { otp: '{{normalized_otp_code}}', container: '{{cargo}}' }, onFail: call('otp_check_failed', 'get-and-validate-otp-code', undefined, 'replace') },
336
+ // The tenant's reading of the digits comes first (owner 2026-11-18: a real account number is taken before a code is tried).
337
+ "condition: normalized_otp_code.length === 6 && answer_key !== 'another_account' && answer_key !== 'code_notice'": { id: 'otp_check_tool', type: 'CALL-TOOL', tool: 'validate-otp', variable: 'otp_validation_result', args: { otp: '{{normalized_otp_code}}', container: '{{cargo}}' }, onFail: call('otp_check_failed', 'get-and-validate-otp-code', undefined, 'replace') },
292
338
  'condition: wants_other_account': toParent(call('otp_change_account', 'authenticate-user', { cell_number: '', email: '', retrying: true, declined_caller: true }, 'replace')),
293
339
  // Email asked for at a code sent by text: authentication is an input step, so the contact question is asked again
294
340
  // (without the caller-ID offer) and the caller gives the email; a code sent by email keeps "no me llegó el correo" a resend.
295
341
  ['condition: email_too && normalized_otp_code.length !== 6 && (' + 'matchesChoice(user_choice,otp_phrases.resend) || matchesChoice(user_choice,otp_phrases.cannot_find) || matchesChoice(user_choice,otp_phrases.another_way) || matchesChoice(user_choice,otp_phrases.email)' + ')']: call('otp_email_too', 'send-otp-email-too'),
296
342
  'condition: !!cargo.otp_cell_number && normalized_otp_code.length !== 6 && matchesChoice(user_choice,otp_phrases.email)': toParent(call('otp_use_email', 'authenticate-user', { cell_number: '', email: '', retrying: true, declined_caller: true }, 'replace')),
297
343
  "condition: isExitRequest(user_choice)": call('otp_exit', '{{otp_cancel}}', undefined, 'reboot'),
298
- "condition: isAnswer(user_choice,'agent')": call('otp_agent', 'live-agent-requested', undefined, 'reboot'),
344
+ "condition: isAgentRequest(user_choice)": call('otp_agent', 'live-agent-requested', undefined, 'reboot'),
299
345
  "condition: isAnswer(user_choice,'text')": call('otp_text', 'switch-to-text', undefined, 'reboot'),
300
346
  'condition: matchesChoice(user_choice,otp_phrases.resend)': call('otp_resend', 'resend-otp-code', { resend_reason: 'requested' }),
301
347
  'condition: matchesChoice(user_choice,otp_phrases.cannot_find)': say('otp_cannot_find', '{{otp_where}}', '{{otp_where_es}}'),
@@ -10,6 +10,12 @@
10
10
  export function readEmail(text: any, { literal }?: {
11
11
  literal?: boolean | undefined;
12
12
  }): string;
13
+ /**
14
+ * True when an answer tries to give an email address that could not be read: an @, "arroba", or a known provider's name
15
+ * ("at gmail", "Yahoo"), so the caller hears the email was incomplete rather than that a phone number was invalid (prod
16
+ * 2026-11-17: "Juana Perez 12 34 at gmail." heard "the phone number you provided isn't valid").
17
+ */
18
+ export function emailAttempt(text: any): boolean;
13
19
  /**
14
20
  * The 10-digit North American number in the answer (a leading 1 dropped), or ''. A caller who restates the number
15
21
  * ("Area code 21. 213 555 0147.", "Area code, 213 555. Area code 213-555-0147.") is read by the last complete number
@@ -1 +1 @@
1
- {"version":3,"file":"contact.d.ts","sourceRoot":"","sources":["../../src/helpers/contact.js"],"names":[],"mappings":"AAiBA;;;;;;;;GAQG;AACH;;WAiCC;AAID;;;;;GAKG;AACH,0CAWC;AAED;;;;;GAKG;AACH,0DAgBC;AAED,qHAAqH;AACrH,2DAIC;AAED;;;;GAIG;AACH;;;SAmBC;AAED;;;GAGG;AACH,sDAOC;AAED;;;;;GAKG;AACH,yEAUC;AAQD;;;;;GAKG;AACH,qDAIC;AAED,mHAAmH;AACnH,oDAIC"}
1
+ {"version":3,"file":"contact.d.ts","sourceRoot":"","sources":["../../src/helpers/contact.js"],"names":[],"mappings":"AAiBA;;;;;;;;GAQG;AACH;;WAiDC;AAoBD;;;;GAIG;AACH,iDAEC;AAID;;;;;GAKG;AACH,0CAWC;AAED;;;;;GAKG;AACH,0DAgBC;AAED,qHAAqH;AACrH,2DAIC;AAED;;;;GAIG;AACH;;;SAmBC;AAED;;;GAGG;AACH,sDAOC;AAED;;;;;GAKG;AACH,yEAUC;AAQD;;;;;GAKG;AACH,qDAIC;AAED,mHAAmH;AACnH,oDAIC"}
@@ -30,11 +30,24 @@ export function readEmail(text, { literal = false } = {}) {
30
30
  if (addresses.length)
31
31
  return new Set(addresses).size === 1 ? addresses[0] : '';
32
32
  }
33
- const spoken = String(text ?? '')
34
- .replace(/\s+(?:at|arroba)\s+/gi, ' @ ')
35
- .replace(/\s+(?:dot|punto)\s+/gi, '.')
33
+ let spoken = String(text ?? '')
34
+ // how speech engines write the commonest providers and endings (prod 2026-11-10..17): "g mail", "Gmaildot",
35
+ // "punt com", "ponto com", "Gmail com"
36
+ .replace(/\b(?:g[\s-]mail|gee\s?mail|gmai|gmial|gamil|gmaill)\b/gi, 'gmail')
37
+ .replace(/\b(gmail|hotmail|yahoo|outlook|icloud|aol)dot\b/gi, '$1') // its "com" was lost: read as the bare provider
38
+ .replace(/(?:^|\s+)(?:at|arroba)\s+/gi, ' @ ')
39
+ .replace(/\s+(?:dot|punto|punt|ponto)\s+/gi, '.')
40
+ .replace(/\b(gmail|hotmail|yahoo|outlook|icloud|aol)\s+(?:com|con)\b/gi, '$1.com')
36
41
  .replace(/\s+(?:underscore|gui[oó]n bajo)[.,]?(?:\s+|$)/gi, '_')
37
42
  .replace(/\s+(?:dash|hyphen|gui[oó]n)[.,]?(?:\s+|$)/gi, '-');
43
+ // a provider with its ending and no "at" (the speech engine dropped it): "Castillo Mónica 22 Gmail punto com"
44
+ const inferred = !spoken.includes('@') && PROVIDER_WITH_ENDING.test(spoken);
45
+ if (inferred) {
46
+ spoken = spoken.replace(PROVIDER_WITH_ENDING, ' @ $1');
47
+ }
48
+ else {
49
+ // the @ was said or typed, or there is none
50
+ }
38
51
  const at = spoken.lastIndexOf('@'); // a speech engine may write an @ inside the name too: the last one is the address's
39
52
  if (at < 0) {
40
53
  return '';
@@ -55,9 +68,39 @@ export function readEmail(text, { literal = false } = {}) {
55
68
  local.unshift(pieces[k]);
56
69
  }
57
70
  }
58
- const email = (local.join('') + '@' + domain).toLowerCase();
59
- return /^[a-z0-9][a-z0-9._%+-]*@[a-z0-9.-]+\.[a-z]{2,}$/.test(email) ? email : '';
71
+ // "gmail dot" cut short (a window of "gmail dot com") is no bare gmail
72
+ const fixed = /^\s*(?:dot|punto|punt|ponto)\b/i.test(after.slice(after.toLowerCase().indexOf(domain.toLowerCase()) + domain.length)) ? domain : providerDomain(domain);
73
+ const email = (local.join('') + '@' + fixed).toLowerCase();
74
+ // a guessed @ or ending needs a name with a letter: "8 4 Gmail punto com" is the end of an address given across turns
75
+ const guessed = inferred || fixed !== domain.toLowerCase();
76
+ return /^[a-z0-9][a-z0-9._%+-]*@[a-z0-9.-]+\.[a-z]{2,}$/.test(email) && (!guessed || /[a-z]/i.test(local.join(''))) ? email : '';
77
+ }
78
+ }
79
+ const PROVIDER_WITH_ENDING = /\s+((?:gmail|hotmail|yahoo|outlook|icloud|aol)\.(?:com|net|es|com\.mx|co\.uk)\b)/i;
80
+ /**
81
+ * A provider's domain as callers say it: "gmail" alone is gmail.com (the one consumer Gmail address), and a misheard
82
+ * ending of a known provider (".con", ".cmo") is ".com". Another provider without its ending is left alone: hotmail and
83
+ * yahoo have country domains, so the caller is asked again (owner 2026-11-17).
84
+ */
85
+ function providerDomain(domain) {
86
+ const d = domain.toLowerCase();
87
+ if (d === 'gmail') {
88
+ return 'gmail.com';
60
89
  }
90
+ else if (/^(?:gmail|hotmail|yahoo|outlook|icloud|aol)\.(?:con|cmo|calm|come|comm|om)$/.test(d)) {
91
+ return d.replace(/\.[a-z]+$/, '.com');
92
+ }
93
+ else {
94
+ return d;
95
+ }
96
+ }
97
+ /**
98
+ * True when an answer tries to give an email address that could not be read: an @, "arroba", or a known provider's name
99
+ * ("at gmail", "Yahoo"), so the caller hears the email was incomplete rather than that a phone number was invalid (prod
100
+ * 2026-11-17: "Juana Perez 12 34 at gmail." heard "the phone number you provided isn't valid").
101
+ */
102
+ export function emailAttempt(text) {
103
+ return /@|\barroba\b|\b(?:g\s?mail|gmai|hotmail|hot mail|yahoo|outlook|icloud|aol)\b/i.test(String(text ?? ''));
61
104
  }
62
105
  const northAmerican = (digits) => digits.length === 11 && digits.startsWith('1') ? digits.slice(1) : digits.length === 10 ? digits : '';
63
106
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"match-inputs.d.ts","sourceRoot":"","sources":["../../src/helpers/match-inputs.js"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,sEAQC;AA2FD;;;GAGG;AACH,sFA8HC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;mHACmH;AAEnH,iEAEC;AAGD,gGAOC;AAYD,kDAGC;AAED;;;;;;;;;;;;;;;;;;;;;;EAeC;AACD;;;;;;;;;;;;;;;;;;;;;;;EAgXC"}
1
+ {"version":3,"file":"match-inputs.d.ts","sourceRoot":"","sources":["../../src/helpers/match-inputs.js"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,sEAQC;AAkGD;;;GAGG;AACH,sFAiIC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;mHACmH;AAEnH,iEAEC;AAGD,gGAOC;AAYD,kDAGC;AAED;;;;;;;;;;;;;;;;;;;;;;EAeC;AACD;;;;;;;;;;;;;;;;;;;;;;;EAgXC"}
@@ -106,8 +106,16 @@ function emailSpans(raw, value) {
106
106
  const spans = [];
107
107
  for (let i = 0; i + size <= tokens.length; i++) {
108
108
  const a = tokens[i].index, b = tokens[i + size - 1].index + tokens[i + size - 1][0].length;
109
- if (readEmail(raw.slice(a, b)) === value)
110
- spans.push([a, b]);
109
+ if (readEmail(raw.slice(a, b)) === value) {
110
+ // "juan at gmail" already reads as gmail.com: the spoken ending after it belongs to the same address
111
+ let j = i + size;
112
+ while (j < tokens.length && /^(?:dot|punto|punt|ponto|com|con|\.com)[.,;:!?]*$/i.test(tokens[j][0]))
113
+ j++;
114
+ spans.push([a, j > i + size ? tokens[j - 1].index + tokens[j - 1][0].length : b]);
115
+ }
116
+ else {
117
+ // this window is not the address
118
+ }
111
119
  }
112
120
  if (spans.length)
113
121
  return spans;
@@ -175,6 +183,10 @@ export function readInputProfile(profile, answer, isCurrent = true) {
175
183
  // other_needs_letter: a name, so a number that is no offered choice is not an answer ("15" at a city list).
176
184
  if (profile.other_needs_letter === true && !/\p{L}/u.test(raw))
177
185
  return null;
186
+ // other_needs_digit: a number (an account number), so a word that is no offered choice is not an answer: the reply
187
+ // ranker reads it against the choices ("Omitr" at OMITIR; owner 2026-11-18).
188
+ if (profile.other_needs_digit === true && !/\d/.test(raw))
189
+ return null;
178
190
  return isCurrent && profile.accept_other === true && raw.trim() ? { value: raw.trim(), ...(profile.narrative === true ? { fallback: true } : {}), spans: [[0, raw.length]] } : null;
179
191
  }
180
192
  else if (kind === 'amount') {
@@ -1 +1 @@
1
- export const JSFE_RUNTIME_FINGERPRINT = "sha256:a27000b2742e60c8a49cbe6d7e33125ca51b2cb364acae42de7c5731bd9c479f";
1
+ export const JSFE_RUNTIME_FINGERPRINT = "sha256:4712b40cf38385dbcf624dddb1f5b5f968a919ea8a6ae2be1d03dbccb72868ec";
@@ -196,7 +196,7 @@ Profiles:
196
196
 
197
197
  | `profile.kind` | Options |
198
198
  | --- | --- |
199
- | `choice` | `choices:[{key,phrases,label?,label_es?,keys?,exact?,neutral?,negative?,current_only?}]`; optional `accept_other`, `numeric_values`, `narrative`, `whole_phrases`, `template_words`. |
199
+ | `choice` | `choices:[{key,phrases,label?,label_es?,keys?,exact?,neutral?,negative?,current_only?}]`; optional `accept_other` (with `other_needs_letter`: other text only with a letter, such as a city; with `other_needs_digit`: only with a digit, such as an account number, so a word that is no choice goes to the reply ranker), `numeric_values`, `narrative`, `whole_phrases`, `template_words`. |
200
200
  | `digits` | `min`, `max`: one unambiguous digit run of that length. |
201
201
  | `identifier` | `pattern`: permitted account identifier shape. |
202
202
  | `pattern` | `regex`, optional `flags`, `group`; optional `accept_other` for the current field only, `whole_phrases`, `template_words`; `spoken_digits` (`true`, or `'house_number'` when a numbered street can follow) reads a number said in pieces as one number ("5 0 9 Lazy Lane", "apt 2 0 4"), required on any pattern that reads digits. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsfe",
3
- "version": "1.74.0",
3
+ "version": "1.76.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",