powr-sdk-web 5.7.1 → 5.8.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.
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PRIORITY_COUNTRIES = exports.DEFAULT_COUNTRY_CODE = exports.DEFAULT_COUNTRY = void 0;
7
+ exports.buildPhoneFromParts = buildPhoneFromParts;
8
+ exports.digitsOnly = digitsOnly;
9
+ exports.formatPhoneForSms = formatPhoneForSms;
10
+ exports.getCountryOptions = getCountryOptions;
11
+ exports.getLocalPhoneNumber = getLocalPhoneNumber;
12
+ exports.getPhoneLookupVariants = getPhoneLookupVariants;
13
+ exports.hasValidPhone = hasValidPhone;
14
+ exports.isValidPhone = isValidPhone;
15
+ exports.normalizePhone = normalizePhone;
16
+ exports.parsePhone = parsePhone;
17
+ exports.resolveCountry = resolveCountry;
18
+ var _libphonenumberJs = require("libphonenumber-js");
19
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
20
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
21
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
22
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
23
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
24
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
25
+ var DEFAULT_COUNTRY = exports.DEFAULT_COUNTRY = 'IN';
26
+ /** @deprecated Use DEFAULT_COUNTRY ('IN') or defaultCountry prop */
27
+ var DEFAULT_COUNTRY_CODE = exports.DEFAULT_COUNTRY_CODE = '91';
28
+ var CALLING_CODE_TO_COUNTRY = {
29
+ '91': 'IN',
30
+ '1': 'US',
31
+ '44': 'GB',
32
+ '971': 'AE',
33
+ '65': 'SG',
34
+ '61': 'AU',
35
+ '49': 'DE',
36
+ '33': 'FR',
37
+ '81': 'JP'
38
+ };
39
+ var PRIORITY_COUNTRIES = exports.PRIORITY_COUNTRIES = ['US', 'IN', 'GB', 'CA', 'AU', 'AE', 'SG', 'DE', 'FR', 'NL', 'NZ', 'JP'];
40
+ function resolveCountry(defaultCountry, defaultCountryCode) {
41
+ if (defaultCountry) return defaultCountry;
42
+ if (defaultCountryCode) {
43
+ return CALLING_CODE_TO_COUNTRY[String(defaultCountryCode)] || DEFAULT_COUNTRY;
44
+ }
45
+ return DEFAULT_COUNTRY;
46
+ }
47
+ function digitsOnly(value) {
48
+ return (value || '').replace(/\D/g, '');
49
+ }
50
+ function parsePhone(input) {
51
+ var _parsed, _parsed2, _parsed3;
52
+ var defaultCountry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COUNTRY;
53
+ if (!input || typeof input !== 'string' || input.includes('@')) return null;
54
+ var trimmed = input.trim();
55
+ if (!trimmed) return null;
56
+ var parsed = (0, _libphonenumberJs.parsePhoneNumberFromString)(trimmed);
57
+ if (!((_parsed = parsed) !== null && _parsed !== void 0 && _parsed.isValid())) {
58
+ parsed = (0, _libphonenumberJs.parsePhoneNumberFromString)(trimmed, defaultCountry);
59
+ }
60
+ if (!((_parsed2 = parsed) !== null && _parsed2 !== void 0 && _parsed2.isValid()) && !trimmed.startsWith('+')) {
61
+ parsed = (0, _libphonenumberJs.parsePhoneNumberFromString)("+".concat(digitsOnly(trimmed)));
62
+ }
63
+ return (_parsed3 = parsed) !== null && _parsed3 !== void 0 && _parsed3.isValid() ? parsed : null;
64
+ }
65
+ function normalizePhone(input) {
66
+ var defaultCountry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COUNTRY;
67
+ if (!input || typeof input !== 'string') return '';
68
+ if (input.includes('@')) return input.trim();
69
+ var parsed = parsePhone(input, defaultCountry);
70
+ return parsed ? parsed.format('E.164') : '';
71
+ }
72
+ function isValidPhone(input) {
73
+ var defaultCountry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COUNTRY;
74
+ if (!input || typeof input !== 'string' || input.includes('@')) return false;
75
+ return !!parsePhone(input, defaultCountry);
76
+ }
77
+ function hasValidPhone(phone) {
78
+ var defaultCountry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COUNTRY;
79
+ return isValidPhone(phone, defaultCountry);
80
+ }
81
+ function getLocalPhoneNumber(input) {
82
+ var defaultCountry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COUNTRY;
83
+ var parsed = parsePhone(input, defaultCountry);
84
+ return parsed ? parsed.nationalNumber : digitsOnly(input).slice(-15);
85
+ }
86
+ function formatPhoneForSms(input) {
87
+ var defaultCountry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COUNTRY;
88
+ return normalizePhone(input, defaultCountry);
89
+ }
90
+ function legacyIndiaVariants(input) {
91
+ var digits = digitsOnly(input);
92
+ if (!digits) return [];
93
+ var variants = new Set();
94
+ if (digits.length === 10) {
95
+ variants.add(digits);
96
+ variants.add("91".concat(digits));
97
+ variants.add("+91".concat(digits));
98
+ variants.add("0".concat(digits));
99
+ }
100
+ if (digits.length === 12 && digits.startsWith('91')) {
101
+ var local = digits.slice(2);
102
+ variants.add(local);
103
+ variants.add("+".concat(digits));
104
+ variants.add(digits);
105
+ variants.add("0".concat(local));
106
+ }
107
+ return _toConsumableArray(variants);
108
+ }
109
+ function getPhoneLookupVariants(input) {
110
+ var defaultCountry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COUNTRY;
111
+ if (!input || typeof input !== 'string') return [];
112
+ if (input.includes('@')) return [input.trim()];
113
+ var variants = new Set([input.trim()]);
114
+ var parsed = parsePhone(input, defaultCountry);
115
+ if (parsed) {
116
+ var e164 = parsed.format('E.164');
117
+ variants.add(e164);
118
+ variants.add(e164.replace(/^\+/, ''));
119
+ variants.add(parsed.nationalNumber);
120
+ variants.add("+".concat(parsed.countryCallingCode).concat(parsed.nationalNumber));
121
+ variants.add("".concat(parsed.countryCallingCode).concat(parsed.nationalNumber));
122
+ }
123
+ legacyIndiaVariants(input).forEach(function (v) {
124
+ return variants.add(v);
125
+ });
126
+ return _toConsumableArray(variants).filter(Boolean);
127
+ }
128
+ function getCountryOptions() {
129
+ var allowedCountries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
130
+ var pool = allowedCountries && allowedCountries.length > 0 ? allowedCountries.filter(function (c) {
131
+ return (0, _libphonenumberJs.getCountries)().includes(c);
132
+ }) : (0, _libphonenumberJs.getCountries)();
133
+ var ordered = [].concat(_toConsumableArray(PRIORITY_COUNTRIES.filter(function (c) {
134
+ return pool.includes(c);
135
+ })), _toConsumableArray(pool.filter(function (c) {
136
+ return !PRIORITY_COUNTRIES.includes(c);
137
+ }).sort()));
138
+ return ordered.map(function (code) {
139
+ return {
140
+ code: code,
141
+ callingCode: (0, _libphonenumberJs.getCountryCallingCode)(code),
142
+ label: "".concat(code, " (+").concat((0, _libphonenumberJs.getCountryCallingCode)(code), ")")
143
+ };
144
+ });
145
+ }
146
+ function buildPhoneFromParts(localNumber) {
147
+ var country = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COUNTRY;
148
+ var digits = digitsOnly(localNumber);
149
+ if (!digits) return '';
150
+ return normalizePhone(digits, country);
151
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SESSION_MESSAGES = void 0;
7
+ exports.getFriendlyAuthError = getFriendlyAuthError;
8
+ var SESSION_MESSAGES = exports.SESSION_MESSAGES = {
9
+ expiredTitle: 'Your session timed out',
10
+ expiredBody: 'For your security, sign-in sessions expire after a while. Sign in again to save your phone number and continue.',
11
+ signInAgain: 'Sign in again',
12
+ loginBannerTitle: 'Your session timed out',
13
+ loginBannerBody: 'Please sign in again to continue where you left off.',
14
+ saveFailed: 'We could not save your phone number. Please try again.',
15
+ invalidPhone: 'Please enter a valid phone number.'
16
+ };
17
+ function getFriendlyAuthError(message) {
18
+ if (!message || typeof message !== 'string') {
19
+ return SESSION_MESSAGES.saveFailed;
20
+ }
21
+ var lower = message.toLowerCase();
22
+ if (lower.includes('jwt expired') || lower.includes('invalid token') || lower.includes('no authorization token') || lower.includes('no token provided') || lower.includes('missing user session')) {
23
+ return null;
24
+ }
25
+ return message;
26
+ }
package/package.json CHANGED
@@ -1,43 +1,44 @@
1
- {
2
- "name": "powr-sdk-web",
3
- "version": "5.7.1",
4
- "main": "dist/index.js",
5
- "scripts": {
6
- "build": "babel src -d dist --copy-files",
7
- "prepublishOnly": "npm run build"
8
- },
9
- "keywords": [
10
- "react",
11
- "component",
12
- "npm",
13
- "file-upload",
14
- "powrbase",
15
- "comments"
16
- ],
17
- "author": "Lawazia Tech",
18
- "license": "MIT",
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/lawaziatech/powr-sdk-web.git"
22
- },
23
- "peerDependencies": {
24
- "filepond": "*",
25
- "react": "*",
26
- "react-dom": "*",
27
- "react-toastify": "*"
28
- },
29
- "dependencies": {
30
- "axios": "^1.7.7",
31
- "filepond": "*",
32
- "firebase": "^12.2.1",
33
- "react-filepond": "^7.1.2",
34
- "react-hook-form": "^7.58.0"
35
- },
36
- "devDependencies": {
37
- "@babel/cli": "^7.24.1",
38
- "@babel/core": "^7.24.4",
39
- "@babel/preset-env": "^7.24.4",
40
- "@babel/preset-react": "^7.24.1",
41
- "prop-types": "^15.8.1"
42
- }
43
- }
1
+ {
2
+ "name": "powr-sdk-web",
3
+ "version": "5.8.1",
4
+ "main": "dist/index.js",
5
+ "scripts": {
6
+ "build": "babel src -d dist --copy-files",
7
+ "prepublishOnly": "npm run build"
8
+ },
9
+ "keywords": [
10
+ "react",
11
+ "component",
12
+ "npm",
13
+ "file-upload",
14
+ "powrbase",
15
+ "comments"
16
+ ],
17
+ "author": "Lawazia Tech",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/lawaziatech/powr-sdk-web.git"
22
+ },
23
+ "peerDependencies": {
24
+ "filepond": "*",
25
+ "react": "*",
26
+ "react-dom": "*",
27
+ "react-toastify": "*"
28
+ },
29
+ "dependencies": {
30
+ "axios": "^1.7.7",
31
+ "filepond": "*",
32
+ "firebase": "^12.2.1",
33
+ "libphonenumber-js": "^1.12.9",
34
+ "react-filepond": "^7.1.2",
35
+ "react-hook-form": "^7.58.0"
36
+ },
37
+ "devDependencies": {
38
+ "@babel/cli": "^7.24.1",
39
+ "@babel/core": "^7.24.4",
40
+ "@babel/preset-env": "^7.24.4",
41
+ "@babel/preset-react": "^7.24.1",
42
+ "prop-types": "^15.8.1"
43
+ }
44
+ }