powr-sdk-web 5.8.1 → 5.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.js +2 -2
- package/dist/index.js +6 -0
- package/dist/utils/phone.js +18 -0
- package/package.json +1 -1
package/dist/auth/index.js
CHANGED
|
@@ -433,7 +433,7 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
433
433
|
if (isLogin) {
|
|
434
434
|
if (isEmail && !isValidEmail(value)) {
|
|
435
435
|
errors.phoneOrEmail = 'Please enter a valid email address';
|
|
436
|
-
} else if (!isEmail && !(0, _phone.
|
|
436
|
+
} else if (!isEmail && !(0, _phone.coercePhoneForStorage)(value, resolvedDefaultCountry)) {
|
|
437
437
|
errors.phoneOrEmail = 'Please enter a valid phone number (include country code, e.g. +1…) or email';
|
|
438
438
|
}
|
|
439
439
|
}
|
|
@@ -464,7 +464,7 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
464
464
|
case 1:
|
|
465
465
|
_context4.p = 1;
|
|
466
466
|
endpoint = isLogin ? "/auth/login" : "/auth/register";
|
|
467
|
-
normalizedPhone = isLogin ? isEmail ? value : (0, _phone.normalizePhone)(value, resolvedDefaultCountry) : registerPhoneE164 || (0, _phone.normalizePhone)(value, phoneCountry);
|
|
467
|
+
normalizedPhone = isLogin ? isEmail ? value : (0, _phone.coercePhoneForStorage)(value, resolvedDefaultCountry) || (0, _phone.normalizePhone)(value, resolvedDefaultCountry) : registerPhoneE164 || (0, _phone.coercePhoneForStorage)(value, phoneCountry) || (0, _phone.normalizePhone)(value, phoneCountry);
|
|
468
468
|
payload = isLogin ? {
|
|
469
469
|
phoneOrEmail: isEmail ? value : normalizedPhone,
|
|
470
470
|
password: formData.password
|
package/dist/index.js
CHANGED
|
@@ -183,6 +183,12 @@ Object.defineProperty(exports, "buildPhoneFromParts", {
|
|
|
183
183
|
return _phone.buildPhoneFromParts;
|
|
184
184
|
}
|
|
185
185
|
});
|
|
186
|
+
Object.defineProperty(exports, "coercePhoneForStorage", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function get() {
|
|
189
|
+
return _phone.coercePhoneForStorage;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
186
192
|
Object.defineProperty(exports, "defineAppStep", {
|
|
187
193
|
enumerable: true,
|
|
188
194
|
get: function get() {
|
package/dist/utils/phone.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.PRIORITY_COUNTRIES = exports.DEFAULT_COUNTRY_CODE = exports.DEFAULT_COUNTRY = void 0;
|
|
7
7
|
exports.buildPhoneFromParts = buildPhoneFromParts;
|
|
8
|
+
exports.coercePhoneForStorage = coercePhoneForStorage;
|
|
8
9
|
exports.digitsOnly = digitsOnly;
|
|
9
10
|
exports.formatPhoneForSms = formatPhoneForSms;
|
|
10
11
|
exports.getCountryOptions = getCountryOptions;
|
|
@@ -69,6 +70,23 @@ function normalizePhone(input) {
|
|
|
69
70
|
var parsed = parsePhone(input, defaultCountry);
|
|
70
71
|
return parsed ? parsed.format('E.164') : '';
|
|
71
72
|
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Normalize phone for storage. Salvages digit runs when input has trailing junk.
|
|
76
|
+
* Returns null when invalid — never returns raw input.
|
|
77
|
+
*/
|
|
78
|
+
function coercePhoneForStorage(input) {
|
|
79
|
+
var defaultCountry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COUNTRY;
|
|
80
|
+
if (!input || typeof input !== 'string') return null;
|
|
81
|
+
if (input.includes('@')) return null;
|
|
82
|
+
var trimmed = input.trim();
|
|
83
|
+
if (!trimmed) return null;
|
|
84
|
+
var direct = normalizePhone(trimmed, defaultCountry);
|
|
85
|
+
if (direct) return direct;
|
|
86
|
+
var digits = digitsOnly(trimmed);
|
|
87
|
+
if (!digits) return null;
|
|
88
|
+
return normalizePhone(digits, defaultCountry) || null;
|
|
89
|
+
}
|
|
72
90
|
function isValidPhone(input) {
|
|
73
91
|
var defaultCountry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COUNTRY;
|
|
74
92
|
if (!input || typeof input !== 'string' || input.includes('@')) return false;
|