fitsms 1.0.1 → 1.0.3
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/README.md +4 -4
- package/index.js +39 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# FitSMS Node.js SDK
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/fitsms)
|
|
4
|
-
[](https://github.com/
|
|
5
|
-
[](https://github.com/
|
|
4
|
+
[](https://github.com/yourusername/fitsms)
|
|
5
|
+
[](https://github.com/yourusername/fitsms/pulls)
|
|
6
6
|
|
|
7
7
|
A high-performance, Promise-based Node.js wrapper for the [FitSMS.lk](https://fitsms.lk) API. This SDK provides a clean interface for sending SMS, checking delivery status, and managing account balances.
|
|
8
8
|
|
|
@@ -44,7 +44,7 @@ const sms = new FitSMS("YOUR_BEARER_TOKEN", "The Change");
|
|
|
44
44
|
```js
|
|
45
45
|
async function sendAlert() {
|
|
46
46
|
try {
|
|
47
|
-
const recipients = ["
|
|
47
|
+
const recipients = ["94XXXXXXXXX", "94XXXXXXXX"];
|
|
48
48
|
|
|
49
49
|
const response = await sms.send(
|
|
50
50
|
recipients,
|
|
@@ -103,4 +103,4 @@ Contributions, issues, and feature requests are welcome!
|
|
|
103
103
|
|
|
104
104
|
## 👨💻 Maintainer
|
|
105
105
|
|
|
106
|
-
Maintained by
|
|
106
|
+
Maintained by [Global Cloud Media (pvt) Ltd.](https://globalcloudmedia.lk)
|
package/index.js
CHANGED
|
@@ -24,13 +24,48 @@ class FitSMS {
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Send an SMS (v3 API)
|
|
27
|
-
* @param {string|string[]} recipients - e.g., "
|
|
27
|
+
* @param {string|string[]} recipients - e.g., "9476XXXXX,9476XXXXX"
|
|
28
28
|
* @param {string} message - The SMS body
|
|
29
29
|
*/
|
|
30
30
|
async send(recipients, message, type = "plain") {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const allowedTypes = ["plain", "unicode"];
|
|
32
|
+
if (!allowedTypes.includes(type)) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`FitSMS Validation Error: Invalid type '${type}'. Use 'plain' or 'unicode'.`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 2. Process and Validate Recipients
|
|
39
|
+
let rawList = Array.isArray(recipients)
|
|
40
|
+
? recipients
|
|
41
|
+
: recipients.split(",");
|
|
42
|
+
|
|
43
|
+
const validatedNumbers = rawList.map((num) => {
|
|
44
|
+
// Remove all non-numeric characters (spaces, +, dashes)
|
|
45
|
+
let cleaned = num.replace(/\D/g, "");
|
|
46
|
+
|
|
47
|
+
// Convert local 07... format to 947...
|
|
48
|
+
if (cleaned.startsWith("07") && cleaned.length === 10) {
|
|
49
|
+
cleaned = "94" + cleaned.substring(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Convert 7... format to 947...
|
|
53
|
+
if (cleaned.startsWith("7") && cleaned.length === 9) {
|
|
54
|
+
cleaned = "94" + cleaned;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Final Sri Lankan Format Check (947XXXXXXXX)
|
|
58
|
+
const slRegex = /^(94)(7[01245678])\d{7}$/;
|
|
59
|
+
if (!slRegex.test(cleaned)) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`FitSMS Validation Error: Invalid Sri Lankan number found: ${num}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return cleaned;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const recipientList = validatedNumbers.join(",");
|
|
34
69
|
|
|
35
70
|
try {
|
|
36
71
|
const response = await axios.post(
|