@takentrade/takentrade-libs 4.0.5 → 4.0.7

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.
@@ -158,16 +158,21 @@ function toSmsSafeNigerianPhone(phone) {
158
158
  let digits = `${phone}`.replace(/\D/g, '').trim();
159
159
  if (digits === '')
160
160
  return '';
161
- // If already 234... and correct length, return as is
162
161
  if (digits.startsWith('234') && digits.length === 13) {
163
162
  return digits;
164
163
  }
165
- // If starts with 0 and length is 11 (e.g. 0803...), strip the 0
166
164
  if (digits.startsWith('0') && digits.length === 11) {
167
- digits = digits.slice(1);
165
+ return '234' + digits.slice(1);
168
166
  }
169
- // Prepend 234 if not already present
170
- return '234' + digits;
167
+ if (digits.length === 10 && /^[789]/.test(digits)) {
168
+ return '234' + digits;
169
+ }
170
+ if (digits.length >= 11 &&
171
+ !digits.startsWith('0') &&
172
+ !digits.startsWith('234')) {
173
+ return digits;
174
+ }
175
+ return digits.startsWith('234') ? digits : '234' + digits;
171
176
  }
172
177
  const formatTransactionStatus = (status) => {
173
178
  const statusMap = {
@@ -92,6 +92,8 @@ const sanitizePhoneNumber = (phone, withPlus = false) => {
92
92
  if (!phone)
93
93
  return '';
94
94
  const digits = phone.replace(/\D/g, '');
95
+ if (digits === '')
96
+ return '';
95
97
  if (digits.startsWith('234') && digits.length >= 13) {
96
98
  return withPlus ? '+' + digits : digits;
97
99
  }
@@ -106,9 +108,14 @@ const sanitizePhoneNumber = (phone, withPlus = false) => {
106
108
  if (digits.startsWith('234')) {
107
109
  return withPlus ? '+' + digits : digits;
108
110
  }
109
- const cleaned = digits.replace(/^0+/, '').slice(0, 10);
110
- const result = '234' + cleaned;
111
- return withPlus ? '+' + result : result;
111
+ if (phone.trim().startsWith('+') || digits.length >= 11) {
112
+ return withPlus ? '+' + digits : digits;
113
+ }
114
+ if (digits.length === 10) {
115
+ const result = '234' + digits;
116
+ return withPlus ? '+' + result : result;
117
+ }
118
+ return withPlus && phone.trim().startsWith('+') ? '+' + digits : digits;
112
119
  };
113
120
  exports.sanitizePhoneNumber = sanitizePhoneNumber;
114
121
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takentrade/takentrade-libs",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "author": "Solomon Olatunji",
5
5
  "description": "TakeNTrade shared libraries",
6
6
  "main": "./dist/index.js",
@@ -31,22 +31,22 @@
31
31
  "dependencies": {
32
32
  "@nestjs/axios": "^4.0.1",
33
33
  "@nestjs/bullmq": "^11.0.4",
34
- "@nestjs/common": "^11.1.14",
34
+ "@nestjs/common": "^11.1.17",
35
35
  "@nestjs/config": "^4.0.3",
36
36
  "@nestjs/jwt": "^11.0.2",
37
- "@nestjs/microservices": "^11.1.14",
37
+ "@nestjs/microservices": "^11.1.17",
38
38
  "@nestjs/passport": "^11.0.5",
39
39
  "@nestjs/terminus": "^11.1.1",
40
- "@sentry/node": "^10.39.0",
40
+ "@sentry/node": "^10.45.0",
41
41
  "@sentry/tracing": "^7.120.4",
42
42
  "class-transformer": "^0.5.1",
43
- "class-validator": "^0.14.3",
43
+ "class-validator": "^0.15.1",
44
44
  "cloudinary": "^2.9.0",
45
45
  "cockatiel": "^3.2.1",
46
46
  "country-codes-list": "^2.0.0",
47
47
  "decimal.js": "^10.6.0",
48
- "ioredis": "^5.9.3",
49
- "joi": "^18.0.2",
48
+ "ioredis": "^5.10.1",
49
+ "joi": "^18.1.1",
50
50
  "jsonwebtoken": "^9.0.3",
51
51
  "object-hash": "^3.0.0",
52
52
  "opossum": "^9.0.0",
@@ -60,19 +60,19 @@
60
60
  "uuid": "^13.0.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@nestjs/core": "^11.1.14",
64
- "@nestjs/testing": "^11.1.14",
63
+ "@nestjs/core": "^11.1.17",
64
+ "@nestjs/testing": "^11.1.17",
65
65
  "@types/jest": "^30.0.0",
66
- "@types/multer": "^2.0.0",
67
- "@types/node": "^25.3.0",
66
+ "@types/multer": "^2.1.0",
67
+ "@types/node": "^25.5.0",
68
68
  "@types/object-hash": "^3.0.6",
69
69
  "@types/opossum": "^8.1.9",
70
70
  "@types/passport": "^1.0.17",
71
71
  "@types/passport-jwt": "^4.0.1",
72
- "jest": "^30.2.0",
72
+ "jest": "^29.7.0",
73
73
  "prettier": "^3.8.1",
74
- "ts-jest": "^29.4.6",
75
- "typescript": "^5.9.3"
74
+ "ts-jest": "^29.1.1",
75
+ "typescript": "^5.7.3"
76
76
  },
77
77
  "exports": {
78
78
  ".": "./dist/index.js",