@webority-technologies/mobile-core 0.0.9 → 0.0.11

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.
@@ -3,12 +3,30 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "AsYouType", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _phone.AsYouType;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "addDays", {
7
13
  enumerable: true,
8
14
  get: function () {
9
15
  return _dateMath.addDays;
10
16
  }
11
17
  });
18
+ Object.defineProperty(exports, "clampNationalNumber", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _phone.clampNationalNumber;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "countryFlagEmoji", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _phone.countryFlagEmoji;
28
+ }
29
+ });
12
30
  Object.defineProperty(exports, "detectPhoneCountry", {
13
31
  enumerable: true,
14
32
  get: function () {
@@ -81,6 +99,12 @@ Object.defineProperty(exports, "formatPhone", {
81
99
  return _phone.formatPhone;
82
100
  }
83
101
  });
102
+ Object.defineProperty(exports, "formatPhoneAsTyped", {
103
+ enumerable: true,
104
+ get: function () {
105
+ return _phone.formatPhoneAsTyped;
106
+ }
107
+ });
84
108
  Object.defineProperty(exports, "formatRelativeTime", {
85
109
  enumerable: true,
86
110
  get: function () {
@@ -111,12 +135,30 @@ Object.defineProperty(exports, "formatTimeInZone", {
111
135
  return _dateMath.formatTimeInZone;
112
136
  }
113
137
  });
138
+ Object.defineProperty(exports, "getCountries", {
139
+ enumerable: true,
140
+ get: function () {
141
+ return _phone.getCountries;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, "getCountryCallingCode", {
145
+ enumerable: true,
146
+ get: function () {
147
+ return _phone.getCountryCallingCode;
148
+ }
149
+ });
114
150
  Object.defineProperty(exports, "getInitials", {
115
151
  enumerable: true,
116
152
  get: function () {
117
153
  return _initials.getInitials;
118
154
  }
119
155
  });
156
+ Object.defineProperty(exports, "getPhoneCountries", {
157
+ enumerable: true,
158
+ get: function () {
159
+ return _phone.getPhoneCountries;
160
+ }
161
+ });
120
162
  Object.defineProperty(exports, "isDateAfter", {
121
163
  enumerable: true,
122
164
  get: function () {
@@ -135,12 +177,30 @@ Object.defineProperty(exports, "isSameDay", {
135
177
  return _dateMath.isSameDay;
136
178
  }
137
179
  });
180
+ Object.defineProperty(exports, "isSupportedCountry", {
181
+ enumerable: true,
182
+ get: function () {
183
+ return _phone.isSupportedCountry;
184
+ }
185
+ });
186
+ Object.defineProperty(exports, "isValidNationalNumber", {
187
+ enumerable: true,
188
+ get: function () {
189
+ return _phone.isValidNationalNumber;
190
+ }
191
+ });
138
192
  Object.defineProperty(exports, "isValidPhoneNumber", {
139
193
  enumerable: true,
140
194
  get: function () {
141
195
  return _phone.isValidPhoneNumber;
142
196
  }
143
197
  });
198
+ Object.defineProperty(exports, "maxNationalNumberLength", {
199
+ enumerable: true,
200
+ get: function () {
201
+ return _phone.maxNationalNumberLength;
202
+ }
203
+ });
144
204
  Object.defineProperty(exports, "normalizePhone", {
145
205
  enumerable: true,
146
206
  get: function () {
@@ -159,12 +219,24 @@ Object.defineProperty(exports, "parsePhoneNumberFromString", {
159
219
  return _phone.parsePhoneNumberFromString;
160
220
  }
161
221
  });
222
+ Object.defineProperty(exports, "splitPhoneNumber", {
223
+ enumerable: true,
224
+ get: function () {
225
+ return _phone.splitPhoneNumber;
226
+ }
227
+ });
162
228
  Object.defineProperty(exports, "startOfDay", {
163
229
  enumerable: true,
164
230
  get: function () {
165
231
  return _dateMath.startOfDay;
166
232
  }
167
233
  });
234
+ Object.defineProperty(exports, "validatePhoneNumberLength", {
235
+ enumerable: true,
236
+ get: function () {
237
+ return _phone.validatePhoneNumberLength;
238
+ }
239
+ });
168
240
  var _currency = require("./currency.js");
169
241
  var _date = require("./date.js");
170
242
  var _dateMath = require("./dateMath.js");
@@ -3,15 +3,42 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.detectPhoneCountry = void 0;
6
+ Object.defineProperty(exports, "AsYouType", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _max.AsYouType;
10
+ }
11
+ });
12
+ exports.detectPhoneCountry = exports.countryFlagEmoji = exports.clampNationalNumber = void 0;
7
13
  exports.formatPhone = formatPhone;
14
+ exports.formatPhoneAsTyped = void 0;
15
+ Object.defineProperty(exports, "getCountries", {
16
+ enumerable: true,
17
+ get: function () {
18
+ return _max.getCountries;
19
+ }
20
+ });
21
+ Object.defineProperty(exports, "getCountryCallingCode", {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _max.getCountryCallingCode;
25
+ }
26
+ });
27
+ exports.getPhoneCountries = void 0;
28
+ Object.defineProperty(exports, "isSupportedCountry", {
29
+ enumerable: true,
30
+ get: function () {
31
+ return _max.isSupportedCountry;
32
+ }
33
+ });
34
+ exports.isValidNationalNumber = void 0;
8
35
  Object.defineProperty(exports, "isValidPhoneNumber", {
9
36
  enumerable: true,
10
37
  get: function () {
11
38
  return _max.isValidPhoneNumber;
12
39
  }
13
40
  });
14
- exports.normalizePhone = void 0;
41
+ exports.normalizePhone = exports.maxNationalNumberLength = void 0;
15
42
  Object.defineProperty(exports, "parsePhoneNumber", {
16
43
  enumerable: true,
17
44
  get: function () {
@@ -24,7 +51,17 @@ Object.defineProperty(exports, "parsePhoneNumberFromString", {
24
51
  return _max.parsePhoneNumberFromString;
25
52
  }
26
53
  });
54
+ exports.splitPhoneNumber = void 0;
55
+ Object.defineProperty(exports, "validatePhoneNumberLength", {
56
+ enumerable: true,
57
+ get: function () {
58
+ return _max.validatePhoneNumberLength;
59
+ }
60
+ });
61
+ var _core = require("libphonenumber-js/core");
27
62
  var _max = require("libphonenumber-js/max");
63
+ var _metadataMax = _interopRequireDefault(require("libphonenumber-js/metadata.max.json"));
64
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
28
65
  /**
29
66
  * The bare 'libphonenumber-js' entry point actually resolves to the library's
30
67
  * OWN slimmed-down min/ metadata internally, not its full data - './max' is
@@ -33,6 +70,10 @@ var _max = require("libphonenumber-js/max");
33
70
  * variant wins throughout this file, not just for validation.
34
71
  */
35
72
 
73
+ // `Metadata` comes from the core entry with the max data passed in by hand:
74
+ // the max entry exports it in its ESM build only, and the CommonJS build jest
75
+ // and node resolve has no `Metadata` at all (libphonenumber-js 1.13.12).
76
+
36
77
  /**
37
78
  * Re-exported under our own name rather than importing CountryCode directly
38
79
  * everywhere, so a future need to diverge (or re-narrow) has one place to do
@@ -147,4 +188,182 @@ function formatPhone(input, arg) {
147
188
  }
148
189
  return fallbackRest.startsWith('+') ? bestEffortGroup(fallbackRest.slice(1)) : fallbackRest.replace(/(.{4})(?=.)/g, '$1 ').trim();
149
190
  }
191
+
192
+ // ---------------------------------------------------------------------------
193
+ // Structured-value helpers. These back PhoneNumberInput in mobile-ui, and are
194
+ // exported so an app's own form and API code validates with the same rules
195
+ // the field shows on screen, rather than a second regex table.
196
+ // ---------------------------------------------------------------------------
197
+
198
+ /** Country calling code + national digits, the way a phone field stores them. */
199
+
200
+ /**
201
+ * Which kinds of number count as valid. `'any'` is libphonenumber's own
202
+ * answer (a fixed line passes). `'mobile'` narrows to MOBILE and
203
+ * FIXED_LINE_OR_MOBILE, which is what an OTP or WhatsApp field wants: in India
204
+ * a 10-digit number starting with 1 to 5 is a real fixed line and passes
205
+ * `'any'`, but no SMS will ever reach it.
206
+ */
207
+
208
+ const onlyDigits = input => input.replace(/\D/g, '');
209
+
210
+ /**
211
+ * Split a typed or pasted number into calling code + national digits.
212
+ * `'+919876543210'` resolves to IN / 91 / 9876543210 from its own prefix; a
213
+ * bare `'9876543210'` needs `defaultCountry` to resolve at all. Returns null
214
+ * when the input has no digits or no country can be told. A shared calling
215
+ * code (`+1` for US and CA) resolves to the country whose area code matches,
216
+ * which is why the country comes back as part of the answer rather than being
217
+ * looked up again from the code.
218
+ */
219
+ const splitPhoneNumber = (input, defaultCountry) => {
220
+ const normalized = normalizePhone(input);
221
+ if (!normalized || onlyDigits(normalized).length === 0) {
222
+ return null;
223
+ }
224
+ const parsed = normalized.startsWith('+') ? (0, _max.parsePhoneNumberFromString)(normalized) : defaultCountry ? (0, _max.parsePhoneNumberFromString)(normalized, defaultCountry) : undefined;
225
+ if (!parsed) {
226
+ return null;
227
+ }
228
+ return {
229
+ country: parsed.country ?? null,
230
+ callingCode: parsed.countryCallingCode,
231
+ nationalNumber: parsed.nationalNumber
232
+ };
233
+ };
234
+
235
+ /**
236
+ * Cut national digits that run past the longest number the country's plan
237
+ * allows, so a field stops accepting the impossible without a per-country
238
+ * length table. This is the PLAN's ceiling, not a mobile number's: India runs
239
+ * to 13 digits (toll-free 1800 numbers), the US to 10, Germany to 15. A field
240
+ * that should stop where a subscriber's number ends asks
241
+ * `maxNationalNumberLength` instead. Digits within range, including a number
242
+ * still too short, pass through untouched.
243
+ */
244
+ exports.splitPhoneNumber = splitPhoneNumber;
245
+ const clampNationalNumber = (nationalDigits, country) => {
246
+ let digits = onlyDigits(nationalDigits);
247
+ while (digits.length > 0 && (0, _max.validatePhoneNumberLength)(digits, country) === 'TOO_LONG') {
248
+ digits = digits.slice(0, -1);
249
+ }
250
+ return digits;
251
+ };
252
+
253
+ // The number types a person types into a phone field. Toll-free, premium,
254
+ // shared-cost and pager ranges are what push a plan's ceiling past them.
255
+ exports.clampNationalNumber = clampNationalNumber;
256
+ const SUBSCRIBER_TYPES = {
257
+ any: ['MOBILE', 'FIXED_LINE'],
258
+ mobile: ['MOBILE']
259
+ };
260
+
261
+ // libphonenumber-js types `numberingPlan` without its per-type accessor; the
262
+ // runtime object has it, and a type with no lengths of its own answers with the
263
+ // plan's.
264
+
265
+ /**
266
+ * The most national digits a subscriber's number can have in a country, so a
267
+ * field can refuse the next digit as it is typed rather than trimming after.
268
+ * `'any'` (default) covers mobile and fixed lines, `'mobile'` mobiles only: India
269
+ * is 10 either way (its plan's 13 belongs to toll-free numbers), Germany is 15
270
+ * for `'any'` and 11 for `'mobile'`, the UAE 9. A country whose metadata lists
271
+ * no lengths by type falls back to the plan's longest number.
272
+ */
273
+ const maxNationalNumberLength = (country, kind = 'any') => {
274
+ const metadata = new _core.Metadata(_metadataMax.default);
275
+ metadata.selectNumberingPlan(country);
276
+ const plan = metadata.numberingPlan;
277
+ if (!plan) {
278
+ return E164_MAX_NATIONAL_DIGITS;
279
+ }
280
+ const byType = SUBSCRIBER_TYPES[kind].flatMap(type => plan.type(type)?.possibleLengths() ?? []);
281
+ return Math.max(...(byType.length > 0 ? byType : plan.possibleLengths()));
282
+ };
283
+
284
+ // E.164 allows 15 digits in total; a national number can never exceed it.
285
+ exports.maxNationalNumberLength = maxNationalNumberLength;
286
+ const E164_MAX_NATIONAL_DIGITS = 15;
287
+
288
+ /**
289
+ * National digits grouped the way the country writes them, updated on every
290
+ * keystroke: `'98765'` for IN is `'98765'`, `'9876543210'` is `'98765 43210'`,
291
+ * `'2025550123'` for US is `'(202) 555-0123'`. Output is for display only; the
292
+ * digits are what a value stores. Digits past the plan's longest possible
293
+ * number are dropped first, so an overflowing paste never formats as a longer
294
+ * number; digits that fit no pattern come back ungrouped rather than forced
295
+ * into a shape.
296
+ *
297
+ * Countries that write a leading 0 (the UAE, the UK, Australia, Saudi Arabia)
298
+ * only group in national mode when that 0 is typed, and a value never holds
299
+ * it. When national mode hands the digits back untouched, the grouping comes
300
+ * from the international form with the calling code removed: `'501234567'`
301
+ * for AE is `'50 123 4567'`. Countries that group nationally are unaffected.
302
+ */
303
+ const formatPhoneAsTyped = (nationalDigits, country) => {
304
+ const digits = clampNationalNumber(nationalDigits, country);
305
+ if (!digits) {
306
+ return '';
307
+ }
308
+ const national = new _max.AsYouType(country).input(digits);
309
+ if (national !== digits) {
310
+ return national;
311
+ }
312
+ const prefix = `+${(0, _max.getCountryCallingCode)(country)}`;
313
+ const international = new _max.AsYouType().input(`${prefix}${digits}`);
314
+ return international.startsWith(prefix) ? international.slice(prefix.length).trimStart() || digits : digits;
315
+ };
316
+
317
+ /**
318
+ * Whether national digits form a real number for the country, by the
319
+ * country's own numbering plan rather than a length check. `kind: 'mobile'`
320
+ * additionally rejects fixed lines; a number whose type the metadata cannot
321
+ * tell is accepted, since the metadata, not the number, is what is missing.
322
+ */
323
+ exports.formatPhoneAsTyped = formatPhoneAsTyped;
324
+ const isValidNationalNumber = (nationalDigits, country, kind = 'any') => {
325
+ const digits = onlyDigits(nationalDigits);
326
+ if (!digits) {
327
+ return false;
328
+ }
329
+ const parsed = (0, _max.parsePhoneNumberFromString)(digits, country);
330
+ if (!parsed?.isValid()) {
331
+ return false;
332
+ }
333
+ if (kind === 'any') {
334
+ return true;
335
+ }
336
+ const type = parsed.getType();
337
+ return type === undefined || type === 'MOBILE' || type === 'FIXED_LINE_OR_MOBILE';
338
+ };
339
+
340
+ /**
341
+ * The flag as an emoji built from the ISO code's two regional-indicator
342
+ * letters, so no font asset ships with the library: iOS and Android both draw
343
+ * these from the system font. An unknown or malformed code returns ''. (Windows
344
+ * browsers render the two letters instead of a flag; that is the platform, not
345
+ * the code.)
346
+ */
347
+ exports.isValidNationalNumber = isValidNationalNumber;
348
+ const countryFlagEmoji = iso => {
349
+ const code = iso.trim().toUpperCase();
350
+ if (!/^[A-Z]{2}$/.test(code)) {
351
+ return '';
352
+ }
353
+ return String.fromCodePoint(0x1f1e6 + code.charCodeAt(0) - 65, 0x1f1e6 + code.charCodeAt(1) - 65);
354
+ };
355
+
356
+ /** Calling code + ISO for one country, the shape a country picker lists. */
357
+ exports.countryFlagEmoji = countryFlagEmoji;
358
+ /**
359
+ * Every country libphonenumber-js knows, with its calling code, in metadata
360
+ * order. Names are deliberately not here: they are display data, in one
361
+ * language, and live on their own import path (`mobile-core/phone/countries`)
362
+ * so an app that never opens a full country list does not carry them.
363
+ */
364
+ const getPhoneCountries = () => (0, _max.getCountries)().map(iso => ({
365
+ iso,
366
+ callingCode: (0, _max.getCountryCallingCode)(iso)
367
+ }));
368
+ exports.getPhoneCountries = getPhoneCountries;
150
369
  //# sourceMappingURL=phone.js.map
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "ACCESS_TOKEN_KEY", {
9
9
  return _authStore.ACCESS_TOKEN_KEY;
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "AsYouType", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _index3.AsYouType;
16
+ }
17
+ });
12
18
  Object.defineProperty(exports, "DeepLink", {
13
19
  enumerable: true,
14
20
  get: function () {
@@ -75,12 +81,24 @@ Object.defineProperty(exports, "buildCurl", {
75
81
  return _curl.buildCurl;
76
82
  }
77
83
  });
84
+ Object.defineProperty(exports, "clampNationalNumber", {
85
+ enumerable: true,
86
+ get: function () {
87
+ return _index3.clampNationalNumber;
88
+ }
89
+ });
78
90
  Object.defineProperty(exports, "configureLogger", {
79
91
  enumerable: true,
80
92
  get: function () {
81
93
  return _index4.configureLogger;
82
94
  }
83
95
  });
96
+ Object.defineProperty(exports, "countryFlagEmoji", {
97
+ enumerable: true,
98
+ get: function () {
99
+ return _index3.countryFlagEmoji;
100
+ }
101
+ });
84
102
  Object.defineProperty(exports, "decodeJWT", {
85
103
  enumerable: true,
86
104
  get: function () {
@@ -159,6 +177,12 @@ Object.defineProperty(exports, "formatPhone", {
159
177
  return _index3.formatPhone;
160
178
  }
161
179
  });
180
+ Object.defineProperty(exports, "formatPhoneAsTyped", {
181
+ enumerable: true,
182
+ get: function () {
183
+ return _index3.formatPhoneAsTyped;
184
+ }
185
+ });
162
186
  Object.defineProperty(exports, "formatRelativeTime", {
163
187
  enumerable: true,
164
188
  get: function () {
@@ -201,6 +225,18 @@ Object.defineProperty(exports, "getConfigValue", {
201
225
  return _index.getConfigValue;
202
226
  }
203
227
  });
228
+ Object.defineProperty(exports, "getCountries", {
229
+ enumerable: true,
230
+ get: function () {
231
+ return _index3.getCountries;
232
+ }
233
+ });
234
+ Object.defineProperty(exports, "getCountryCallingCode", {
235
+ enumerable: true,
236
+ get: function () {
237
+ return _index3.getCountryCallingCode;
238
+ }
239
+ });
204
240
  Object.defineProperty(exports, "getDeviceContext", {
205
241
  enumerable: true,
206
242
  get: function () {
@@ -225,6 +261,12 @@ Object.defineProperty(exports, "getNetworkStatus", {
225
261
  return _index5.getNetworkStatus;
226
262
  }
227
263
  });
264
+ Object.defineProperty(exports, "getPhoneCountries", {
265
+ enumerable: true,
266
+ get: function () {
267
+ return _index3.getPhoneCountries;
268
+ }
269
+ });
228
270
  Object.defineProperty(exports, "getToken", {
229
271
  enumerable: true,
230
272
  get: function () {
@@ -381,12 +423,24 @@ Object.defineProperty(exports, "isStrongPassword", {
381
423
  return _index7.isStrongPassword;
382
424
  }
383
425
  });
426
+ Object.defineProperty(exports, "isSupportedCountry", {
427
+ enumerable: true,
428
+ get: function () {
429
+ return _index3.isSupportedCountry;
430
+ }
431
+ });
384
432
  Object.defineProperty(exports, "isUrl", {
385
433
  enumerable: true,
386
434
  get: function () {
387
435
  return _index7.isUrl;
388
436
  }
389
437
  });
438
+ Object.defineProperty(exports, "isValidNationalNumber", {
439
+ enumerable: true,
440
+ get: function () {
441
+ return _index3.isValidNationalNumber;
442
+ }
443
+ });
390
444
  Object.defineProperty(exports, "isValidPhoneNumber", {
391
445
  enumerable: true,
392
446
  get: function () {
@@ -405,6 +459,12 @@ Object.defineProperty(exports, "maxLength", {
405
459
  return _index7.maxLength;
406
460
  }
407
461
  });
462
+ Object.defineProperty(exports, "maxNationalNumberLength", {
463
+ enumerable: true,
464
+ get: function () {
465
+ return _index3.maxNationalNumberLength;
466
+ }
467
+ });
408
468
  Object.defineProperty(exports, "minLength", {
409
469
  enumerable: true,
410
470
  get: function () {
@@ -501,6 +561,12 @@ Object.defineProperty(exports, "setStorageImplementation", {
501
561
  return _index6.setStorageImplementation;
502
562
  }
503
563
  });
564
+ Object.defineProperty(exports, "splitPhoneNumber", {
565
+ enumerable: true,
566
+ get: function () {
567
+ return _index3.splitPhoneNumber;
568
+ }
569
+ });
504
570
  Object.defineProperty(exports, "startOfDay", {
505
571
  enumerable: true,
506
572
  get: function () {
@@ -537,6 +603,12 @@ Object.defineProperty(exports, "userClient", {
537
603
  return _userClient.default;
538
604
  }
539
605
  });
606
+ Object.defineProperty(exports, "validatePhoneNumberLength", {
607
+ enumerable: true,
608
+ get: function () {
609
+ return _index3.validatePhoneNumberLength;
610
+ }
611
+ });
540
612
  var _curl = require("./api/curl.js");
541
613
  var _publicClient = _interopRequireDefault(require("./api/publicClient.js"));
542
614
  var _retry = require("./api/retry.js");