fitsms 1.0.5 → 2.0.0

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 (4) hide show
  1. package/README.md +2 -2
  2. package/index.js +11 -8
  3. package/package.json +1 -1
  4. package/test.js +11 -11
package/README.md CHANGED
@@ -62,7 +62,7 @@ async function sendAlert() {
62
62
  ### Checking Message Status
63
63
 
64
64
  ```js
65
- const status = await sms.getStatus("606812e63f78b");
65
+ const status = await sms.getStatus("606812e63f78b", "9476XXXXXXXX");
66
66
  console.log("Delivery Status:", status.data.status);
67
67
  ```
68
68
 
@@ -82,7 +82,7 @@ console.log("Remaining Units:", balance.data);
82
82
  | Method | Parameters | Description |
83
83
  | ------------ | ------------------------- | ------------------- |
84
84
  | send() | recipients, message, type | Sends an SMS |
85
- | getStatus() | uid | Get delivery status |
85
+ | getStatus() | ruid, recipient | Get delivery status |
86
86
  | getBalance() | none | Get SMS balance |
87
87
  | getProfile() | none | Get account profile |
88
88
 
package/index.js CHANGED
@@ -12,7 +12,7 @@ class FitSMS {
12
12
  this.apiToken = apiToken;
13
13
  this.senderId = senderId;
14
14
 
15
- this.v3Base = "https://app.fitsms.lk/api/v3";
15
+ this.v4Base = "https://app.fitsms.lk/api/v4";
16
16
 
17
17
  // Default Headers
18
18
  this.headers = {
@@ -23,7 +23,7 @@ class FitSMS {
23
23
  }
24
24
 
25
25
  /**
26
- * Send an SMS (v3 API)
26
+ * Send an SMS (v4 API)
27
27
  * @param {string|string[]} recipients - e.g., "9476XXXXX,9476XXXXX"
28
28
  * @param {string} message - The SMS body
29
29
  */
@@ -69,7 +69,7 @@ class FitSMS {
69
69
 
70
70
  try {
71
71
  const response = await axios.post(
72
- `${this.v3Base}/sms/send`,
72
+ `${this.v4Base}/sms/send`,
73
73
  {
74
74
  recipient: recipientList,
75
75
  sender_id: this.senderId,
@@ -87,13 +87,16 @@ class FitSMS {
87
87
  }
88
88
 
89
89
  /**
90
- * Check status of an existing SMS (v3 API)
90
+ * Check status of an existing SMS (v4 API)
91
91
  * @param {string} uid - The unique message ID
92
92
  */
93
- async getStatus(uid) {
93
+ async getStatus(ruid, recipient) {
94
94
  try {
95
- const response = await axios.get(`${this.v3Base}/sms/${uid}`, {
95
+ const response = await axios.get(`${this.v4Base}/sms/${ruid}`, {
96
96
  headers: this.headers,
97
+ params: {
98
+ recipient,
99
+ },
97
100
  });
98
101
  return response.data;
99
102
  } catch (error) {
@@ -108,7 +111,7 @@ class FitSMS {
108
111
  */
109
112
  async getBalance() {
110
113
  try {
111
- const response = await axios.get(`${this.v3Base}/balance`, {
114
+ const response = await axios.get(`${this.v4Base}/balance`, {
112
115
  headers: this.headers,
113
116
  });
114
117
  return response.data;
@@ -124,7 +127,7 @@ class FitSMS {
124
127
  */
125
128
  async getProfile() {
126
129
  try {
127
- const response = await axios.get(`${this.v3Base}/me`, {
130
+ const response = await axios.get(`${this.v4Base}/me`, {
128
131
  headers: this.headers,
129
132
  });
130
133
  return response.data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fitsms",
3
- "version": "1.0.5",
3
+ "version": "2.0.0",
4
4
  "description": "The official-style Node.js SDK for the FitSMS.lk gateway.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -2,10 +2,6 @@ const FitSMS = require("./index.js");
2
2
 
3
3
  /*
4
4
 
5
- THIS IMPLEMENTATION FOLLOWS FITSMS'S V3 API SPECIFICATION
6
-
7
- https://app.fitsms.lk/api/v3
8
-
9
5
  FOR V4 API, WEBHOOKS & FURTHER DOCUMENTATION, SEE:
10
6
  https://app.fitsms.lk/developers/docs
11
7
 
@@ -21,30 +17,34 @@ const TEST_MOBILE = "947XXXXXXX";
21
17
 
22
18
  const sms = new FitSMS(API_TOKEN, SENDER_ID);
23
19
 
20
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
21
+
24
22
  async function runTests() {
25
23
  console.log("🚀 Starting FitSMS Module Tests...\n");
26
24
 
27
25
  try {
28
- // 1. Test Balance (v3 API)
26
+ // 1. Test Balance (v4 API)
29
27
  console.log("--- Testing getBalance() ---");
30
28
  const balance = await sms.getBalance();
31
29
  console.log("✅ Balance Status:", balance.status);
32
30
  console.log("Remaining Units:", balance.data);
33
31
  console.log("----------------------------\n");
34
32
 
35
- // 2. Test Sending SMS (v3 API)
33
+ // 2. Test Sending SMS (v4 API)
36
34
  console.log("--- Testing send() ---");
37
35
  const sendRes = await sms.send(TEST_MOBILE, "Test message from local SDK");
38
36
  console.log("✅ Send Status:", sendRes.status);
39
37
 
40
- if (sendRes.data[0] && sendRes.data[0].uid) {
41
- const uid = sendRes.data[0].uid;
42
- console.log("Message UID:", uid);
38
+ if (sendRes.data && sendRes.data.ruid) {
39
+ const ruid = sendRes.data.ruid;
40
+ console.log("Message RUID:", ruid);
43
41
  console.log("----------------------------\n");
44
42
 
45
- // 3. Test Status Check (v3 API)
43
+ // 3. Test Status Check (v4 API)
44
+ await delay(10000);
45
+
46
46
  console.log("--- Testing getStatus() ---");
47
- const statusRes = await sms.getStatus(uid);
47
+ const statusRes = await sms.getStatus(ruid, TEST_MOBILE);
48
48
  console.log("✅ Status Check:", statusRes.status);
49
49
  console.log("Delivery Status:", statusRes.data.status);
50
50
  console.log("----------------------------\n");