fitsms 1.0.2 → 1.0.4

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.
Files changed (3) hide show
  1. package/README.md +2 -3
  2. package/index.js +39 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # FitSMS Node.js SDK
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/fitsms.svg)](https://www.npmjs.com/package/fitsms)
4
- [![license](https://img.shields.io/npm/l/fitsms.svg)](https://github.com/yourusername/fitsms)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/yourusername/fitsms/pulls)
4
+ [![license](https://img.shields.io/npm/l/fitsms.svg)](https://github.com/Global-Cloud-Media-Pvt-Ltd/fitsms-nodejs-sdk)
5
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Global-Cloud-Media-Pvt-Ltd/fitsms-nodejs-sdk/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
 
@@ -10,7 +10,6 @@ A high-performance, Promise-based Node.js wrapper for the [FitSMS.lk](https://fi
10
10
 
11
11
  ## 🚀 Features
12
12
 
13
- - **Multi-Version Support**: Handles v3 (Messaging) and v4 (Account/Profile) endpoints.
14
13
  - **Bearer Token Auth**: Secure authentication via headers.
15
14
  - **Flexible Recipients**: Supports strings, comma-separated lists, and arrays.
16
15
  - **Real-time Status**: Retrieve delivery reports using message UIDs.
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., "9476111,9476222"
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 recipientList = Array.isArray(recipients)
32
- ? recipients.join(",")
33
- : recipients;
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(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fitsms",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "The official-style Node.js SDK for the FitSMS.lk gateway.",
5
5
  "main": "index.js",
6
6
  "scripts": {