jsfe 1.89.0 → 1.90.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.
@@ -134,7 +134,7 @@ const contact = worker('get-cell-or-email', 'GetCellOrEmail', 'Identify a suppli
134
134
  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})"),
135
135
  // options carried from an earlier verification may name a task the caller has since closed; opening under it fails
136
136
  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"),
137
- 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)'),
137
+ 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",reader:"account",regex:contact_options.account_pattern}]:[]),true)'),
138
138
  when('identity_contact_new_rejection_series', '!gce_rejected', effect('identity_contact_rejections_reset', '(cargo.gceRejects=0,true)')),
139
139
  when('identity_contact_new_miss_series', '!gce_missed', effect('identity_contact_misses_reset', '(cargo.gceMisses=0,cargo.gceRanked=false,true)')),
140
140
  set('identity_contact_partial', 'contact_partial', "!!(contact_options.merge_partials && gce_partial && cargo.gcePartial)"),
@@ -1 +1 @@
1
- {"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../src/helpers/capture.js"],"names":[],"mappings":"AAeA;;;SA8BC"}
1
+ {"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../src/helpers/capture.js"],"names":[],"mappings":"AAoBA;;;SA8BC"}
@@ -6,12 +6,17 @@
6
6
  * through `warn`, so one bad tenant pattern cannot stop the others.
7
7
  *
8
8
  * A pattern may name a reader instead of a regex: { variable, reader: 'phone' | 'email' } reads the answer with
9
- * readPhone / readEmail (spoken and spelled forms included).
9
+ * readPhone / readEmail (spoken and spelled forms included); { variable, reader: 'account', regex } reads it with
10
+ * readIdentifier, an account whose digits match the tenant's regex (a number inside an email is the email's).
10
11
  *
11
12
  * Part of jsfe/helpers; imports only its sibling contact.js.
12
13
  */
13
- import { readEmail, readPhone } from './contact.js';
14
- const READERS = { phone: readPhone, email: readEmail };
14
+ import { readEmail, readPhone, readIdentifier } from './contact.js';
15
+ const READERS = {
16
+ phone: (input) => readPhone(input),
17
+ email: (input) => readEmail(input),
18
+ account: (input, pattern) => { const id = readIdentifier(input, pattern.regex || ''); return id && id.kind === 'account' ? id.value : ''; }
19
+ };
15
20
  export function normalizeAndFindCapture(userInput, patterns, warn = () => { }) {
16
21
  if (!Array.isArray(patterns)) {
17
22
  return null;
@@ -19,7 +24,7 @@ export function normalizeAndFindCapture(userInput, patterns, warn = () => { }) {
19
24
  else {
20
25
  for (const pattern of patterns) {
21
26
  if (pattern && READERS[pattern.reader]) {
22
- const value = READERS[pattern.reader](userInput);
27
+ const value = READERS[pattern.reader](userInput, pattern);
23
28
  if (value) {
24
29
  return { variable: pattern.variable, value };
25
30
  }
@@ -7,9 +7,7 @@
7
7
  * With `{literal:true}`, a complete visible address wins over surrounding prose; absent one,
8
8
  * the same spoken/spelled parsing applies. Distinct visible addresses are ambiguous and return empty.
9
9
  */
10
- export function readEmail(text: any, { literal }?: {
11
- literal?: boolean | undefined;
12
- }): string;
10
+ export function readEmail(text: any, options?: {}): string;
13
11
  /**
14
12
  * An address at a known provider said without its ending ("Cecilia 41, at Yahoo."): its name and provider
15
13
  * ("cecilia41@yahoo"), so the caller is asked only for what comes after the provider (owner 2026-11-18, prod 11-18 17:30:
@@ -29,6 +27,9 @@ export function emailSaid(address: any, voice: any, es?: boolean): string;
29
27
  * 2026-11-17: "Juana Perez 12 34 at gmail." heard "the phone number you provided isn't valid").
30
28
  */
31
29
  export function emailAttempt(text: any): boolean;
30
+ /** Where the address rawEmail read sits in the answer: [[start, end], ...]. Typed, the address itself; spoken (at / arroba /
31
+ * dot / punto), the shortest run of words that reads as it, with a spoken ending after it. */
32
+ export function emailSpans(raw: any, value: any): any[][];
32
33
  /**
33
34
  * The 10-digit North American number in the answer (a leading 1 dropped), or ''. A caller who restates the number
34
35
  * ("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;;WAiDC;AAED;;;;GAIG;AACH,sDASC;AAED;;;GAGG;AACH,+CASC;AAED,+GAA+G;AAC/G,0EAGC;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"}
1
+ {"version":3,"file":"contact.d.ts","sourceRoot":"","sources":["../../src/helpers/contact.js"],"names":[],"mappings":"AAwBA;;;;;;;;GAQG;AACH,2DAEC;AAsDD;;;;GAIG;AACH,sDASC;AAED;;;GAGG;AACH,+CASC;AAED,+GAA+G;AAC/G,0EAGC;AAoBD;;;;GAIG;AACH,iDAEC;AAID;8FAC8F;AAC9F,0DAsBC;AA+BD;;;;;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"}
@@ -5,8 +5,15 @@
5
5
  * address ("juan at gmail dot com", "j u a n arroba gmail punto com"), so the same answer worked for a statement and
6
6
  * failed at the identity question (flow design review 2026-10-13).
7
7
  *
8
- * Part of jsfe/helpers; zero imports.
8
+ * An email and a phone claim the part of the answer they were read from, and a number inside the email is never read as
9
+ * another field (owner 2026-11-24: the longest match wins; a fragment of a match is never another field's). When the email
10
+ * and a complete phone overlap, the one that begins first keeps its part (a tie: the phone) and the other is read again on
11
+ * the rest. Prod 2026-11-23: the digits inside an address were read as an account number, an address's digits joined an
12
+ * account number into a phone, and a phone typed before an address became the start of the address.
13
+ *
14
+ * Part of jsfe/helpers; imports its sibling numbers.js.
9
15
  */
16
+ import { findNumbers } from './numbers.js';
10
17
  // Words that introduce an address and are never part of it ("my email is", "mi correo es", "send it to").
11
18
  const EMAIL_LEAD_IN = new Set(['my', 'mi', 'su', 'your', 'email', 'e-mail', 'mail', 'correo', 'electronico', 'electrónico',
12
19
  'address', 'dirección', 'direccion', 'de', 'is', 'es', "it's", 'its', 'it', 'the', 'el', 'la', 'to', 'para', 'send',
@@ -22,7 +29,11 @@ const EMAIL_LEAD_IN = new Set(['my', 'mi', 'su', 'your', 'email', 'e-mail', 'mai
22
29
  * With `{literal:true}`, a complete visible address wins over surrounding prose; absent one,
23
30
  * the same spoken/spelled parsing applies. Distinct visible addresses are ambiguous and return empty.
24
31
  */
25
- export function readEmail(text, { literal = false } = {}) {
32
+ export function readEmail(text, options = {}) {
33
+ return emailClaim(text, options).email;
34
+ }
35
+ /** readEmail's reading of the whole answer, before any phone claims its part. */
36
+ function rawEmail(text, { literal = false } = {}) {
26
37
  // Contextual prose must not become part of an already complete, visible address. This
27
38
  // explicit mode preserves the default spoken/spelled-name grammar for existing callers.
28
39
  if (literal) {
@@ -139,6 +150,64 @@ export function emailAttempt(text) {
139
150
  return /@|\barroba\b|\b(?:g\s?mail|gmai|hotmail|hot mail|yahoo|outlook|icloud|aol)\b/i.test(String(text ?? ''));
140
151
  }
141
152
  const northAmerican = (digits) => digits.length === 11 && digits.startsWith('1') ? digits.slice(1) : digits.length === 10 ? digits : '';
153
+ /** Where the address rawEmail read sits in the answer: [[start, end], ...]. Typed, the address itself; spoken (at / arroba /
154
+ * dot / punto), the shortest run of words that reads as it, with a spoken ending after it. */
155
+ export function emailSpans(raw, value) {
156
+ const literal = raw.toLowerCase().indexOf(value);
157
+ if (literal >= 0)
158
+ return [[literal, literal + value.length]];
159
+ // Spoken addresses may use at / arroba / dot / punto. Select the shortest source window yielding this address.
160
+ const tokens = [...raw.matchAll(/\S+/g)];
161
+ if (tokens.length > 128)
162
+ return [[0, raw.length]];
163
+ for (let size = 1; size <= tokens.length; size++) {
164
+ const spans = [];
165
+ for (let i = 0; i + size <= tokens.length; i++) {
166
+ const a = tokens[i].index, b = tokens[i + size - 1].index + tokens[i + size - 1][0].length;
167
+ if (rawEmail(raw.slice(a, b)) === value) {
168
+ // "juan at gmail" already reads as gmail.com: the spoken ending after it belongs to the same address
169
+ let j = i + size;
170
+ while (j < tokens.length && /^(?:dot|punto|punt|ponto|com|con|\.com)[.,;:!?]*$/i.test(tokens[j][0]))
171
+ j++;
172
+ spans.push([a, j > i + size ? tokens[j - 1].index + tokens[j - 1][0].length : b]);
173
+ }
174
+ else {
175
+ // this window is not the address
176
+ }
177
+ }
178
+ if (spans.length)
179
+ return spans;
180
+ }
181
+ return [[0, raw.length]];
182
+ }
183
+ const blank = (text, spans) => spans.reduce((out, [a, b]) => out.slice(0, a) + ' '.repeat(b - a) + out.slice(b), text);
184
+ /** The email in the answer and the part it claims: {email, spans}. A complete North American phone number overlapping it
185
+ * that begins no later than the email keeps its part, and the email is read again on the rest. */
186
+ function emailClaim(text, options = {}) {
187
+ const t = String(text ?? '');
188
+ const email = rawEmail(t, options);
189
+ if (!email) {
190
+ return { email: '', spans: [] };
191
+ }
192
+ else {
193
+ const spans = emailSpans(t, email);
194
+ const start = Math.min(...spans.map(([a]) => a));
195
+ const phone = findNumbers(t).find((n) => northAmerican(n.value) && spans.some(([a, b]) => n.start < b && n.end > a));
196
+ if (phone && phone.start <= start) {
197
+ const rest = blank(t, [[phone.start, phone.end]]);
198
+ const again = rawEmail(rest, options);
199
+ return again ? { email: again, spans: emailSpans(rest, again) } : { email: '', spans: [] };
200
+ }
201
+ else {
202
+ return { email, spans };
203
+ }
204
+ }
205
+ }
206
+ /** The answer with the email's part blanked, for the digit readers: its digits are the email's. */
207
+ function withoutEmail(text) {
208
+ const t = String(text ?? '');
209
+ return blank(t, emailClaim(t).spans);
210
+ }
142
211
  /**
143
212
  * The 10-digit North American number in the answer (a leading 1 dropped), or ''. A caller who restates the number
144
213
  * ("Area code 21. 213 555 0147.", "Area code, 213 555. Area code 213-555-0147.") is read by the last complete number
@@ -146,7 +215,7 @@ const northAmerican = (digits) => digits.length === 11 && digits.startsWith('1')
146
215
  * nothing. An answer with an international prefix (+, plus, más, 00) is never split, so it stays international.
147
216
  */
148
217
  export function readPhone(text) {
149
- const t = String(text ?? '');
218
+ const t = withoutEmail(text);
150
219
  const whole = northAmerican(t.replace(/[^0-9]/g, ''));
151
220
  if (whole) {
152
221
  return whole;
@@ -197,7 +266,7 @@ export function callerIsInternational(cargo) {
197
266
  * accountPattern (a regex source, e.g. '^5\\d{6,7}$') is the tenant's account-number shape; its digits win first.
198
267
  */
199
268
  export function readIdentifier(text, accountPattern = '') {
200
- const digits = String(text ?? '').replace(/[^0-9]/g, '');
269
+ const digits = withoutEmail(text).replace(/[^0-9]/g, '');
201
270
  let account = false;
202
271
  try {
203
272
  account = !!accountPattern && new RegExp(accountPattern).test(digits);
@@ -1 +1 @@
1
- {"version":3,"file":"match-inputs.d.ts","sourceRoot":"","sources":["../../src/helpers/match-inputs.js"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,sEAQC;AAoGD;;;GAGG;AACH,sFAiIC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;mHACmH;AAEnH,iEAEC;AAID,gGAQC;AAYD,kDAGC;AAED;;;;;;;GAOG;AACH;;;;SAcC;AACD;;;;;GAKG;AACH;;;;;;;;;;;;;;;;;;;;;;EAaC;AACD;;;;;;;;;;;;;;;;;;;;;;EAeC;AAyDD;;;;;;;;;;;;;;;;;;;;;;;EAiZC"}
1
+ {"version":3,"file":"match-inputs.d.ts","sourceRoot":"","sources":["../../src/helpers/match-inputs.js"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,sEAQC;AA4ED;;;GAGG;AACH,sFAiIC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;mHACmH;AAEnH,iEAEC;AAID,gGAQC;AAYD,kDAGC;AAED;;;;;;;GAOG;AACH;;;;SAcC;AACD;;;;;GAKG;AACH;;;;;;;;;;;;;;;;;;;;;;EAaC;AACD;;;;;;;;;;;;;;;;;;;;;;EAeC;AAyDD;;;;;;;;;;;;;;;;;;;;;;;EAiZC"}
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { matchesChoice } from './matches-choice.js';
12
12
  import { pickChoice, amountInAnswer, isAmountAnswer, isReaderFiller, ANSWER_WORDS, CONFIRM_WORDS } from './answer.js';
13
- import { readEmail, readPhone, readInternationalPhone, readIdentifier } from './contact.js';
13
+ import { readEmail, readPhone, readInternationalPhone, readIdentifier, emailSpans } from './contact.js';
14
14
  import { readSpokenMoney } from './spoken-money.js';
15
15
  import { readMoneyAmount, isPartialMoneyAnswer } from './money.js';
16
16
  import { pickProviderQuestion } from './form-sources.js';
@@ -92,34 +92,6 @@ function choiceSpans(raw, words) {
92
92
  }
93
93
  return spans;
94
94
  }
95
- function emailSpans(raw, value) {
96
- const literal = raw.toLowerCase().indexOf(value);
97
- if (literal >= 0)
98
- return [[literal, literal + value.length]];
99
- // Spoken addresses may use at / arroba / dot / punto. Select the shortest source window yielding this address.
100
- const tokens = [...raw.matchAll(/\S+/g)];
101
- if (tokens.length > 128)
102
- return [[0, raw.length]];
103
- for (let size = 1; size <= tokens.length; size++) {
104
- const spans = [];
105
- for (let i = 0; i + size <= tokens.length; i++) {
106
- const a = tokens[i].index, b = tokens[i + size - 1].index + tokens[i + size - 1][0].length;
107
- if (readEmail(raw.slice(a, b)) === value) {
108
- // "juan at gmail" already reads as gmail.com: the spoken ending after it belongs to the same address
109
- let j = i + size;
110
- while (j < tokens.length && /^(?:dot|punto|punt|ponto|com|con|\.com)[.,;:!?]*$/i.test(tokens[j][0]))
111
- j++;
112
- spans.push([a, j > i + size ? tokens[j - 1].index + tokens[j - 1][0].length : b]);
113
- }
114
- else {
115
- // this window is not the address
116
- }
117
- }
118
- if (spans.length)
119
- return spans;
120
- }
121
- return [[0, raw.length]];
122
- }
123
95
  /** Remove independently spent evidence while leaving the original narrative value intact. */
124
96
  function unclaimedSpans(raw, readings) {
125
97
  let spans = [[0, raw.length]];
@@ -1 +1 @@
1
- export const JSFE_RUNTIME_FINGERPRINT = "sha256:df2aef8397134376b8abc730555c4de6ba14116f1953c16067c0d88fc5423857";
1
+ export const JSFE_RUNTIME_FINGERPRINT = "sha256:2da4505cfef524d9ab9a5b9975111726f6885c8f7ef6fb63130ccd3abc6d6b5d";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsfe",
3
- "version": "1.89.0",
3
+ "version": "1.90.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",