fitsms 1.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 +106 -0
  2. package/index.js +104 -0
  3. package/package.json +22 -0
  4. package/test.js +60 -0
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # FitSMS Node.js SDK
2
+
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)
6
+
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
+
9
+ ---
10
+
11
+ ## 🚀 Features
12
+
13
+ - **Multi-Version Support**: Handles v3 (Messaging) and v4 (Account/Profile) endpoints.
14
+ - **Bearer Token Auth**: Secure authentication via headers.
15
+ - **Flexible Recipients**: Supports strings, comma-separated lists, and arrays.
16
+ - **Real-time Status**: Retrieve delivery reports using message UIDs.
17
+ - **Balance Monitoring**: Track remaining SMS units.
18
+ - **Lightweight**: Minimal dependencies.
19
+
20
+ ---
21
+
22
+ ## 📦 Installation
23
+
24
+ ```bash
25
+ npm install fitsms
26
+ ```
27
+
28
+ ---
29
+
30
+ ## 🛠 Usage
31
+
32
+ ### Initialization
33
+
34
+ ```js
35
+ const FitSMS = require("fitsms");
36
+
37
+ const sms = new FitSMS("YOUR_BEARER_TOKEN", "The Change");
38
+ ```
39
+
40
+ ---
41
+
42
+ ### Sending SMS
43
+
44
+ ```js
45
+ async function sendAlert() {
46
+ try {
47
+ const recipients = ["94761695904", "94771234567"];
48
+
49
+ const response = await sms.send(
50
+ recipients,
51
+ "This is a test message from FitSMS SDK",
52
+ );
53
+
54
+ console.log("Success:", response.data.uid);
55
+ } catch (error) {
56
+ console.error("Error:", error.message);
57
+ }
58
+ }
59
+ ```
60
+
61
+ ---
62
+
63
+ ### Checking Message Status
64
+
65
+ ```js
66
+ const status = await sms.getStatus("606812e63f78b");
67
+ console.log("Delivery Status:", status.data.status);
68
+ ```
69
+
70
+ ---
71
+
72
+ ### Checking Balance
73
+
74
+ ```js
75
+ const balance = await sms.getBalance();
76
+ console.log("Remaining Units:", balance.data);
77
+ ```
78
+
79
+ ---
80
+
81
+ ## 📖 API Reference
82
+
83
+ | Method | Parameters | Description |
84
+ | ------------ | ------------------------- | ------------------- |
85
+ | send() | recipients, message, type | Sends an SMS |
86
+ | getStatus() | uid | Get delivery status |
87
+ | getBalance() | none | Get SMS balance |
88
+ | getProfile() | none | Get account profile |
89
+
90
+ ---
91
+
92
+ ## 📄 License
93
+
94
+ This project is licensed under the MIT License.
95
+
96
+ ---
97
+
98
+ ## 🤝 Contributing
99
+
100
+ Contributions, issues, and feature requests are welcome!
101
+
102
+ ---
103
+
104
+ ## 👨‍💻 Maintainer
105
+
106
+ Maintained by **Danuja Dilanka**
package/index.js ADDED
@@ -0,0 +1,104 @@
1
+ const axios = require("axios");
2
+
3
+ class FitSMS {
4
+ /**
5
+ * @param {string} apiToken - Your Bearer Token
6
+ * @param {string} senderId - Your approved Sender ID (e.g., "The Change")
7
+ */
8
+ constructor(apiToken, senderId) {
9
+ if (!apiToken || !senderId) {
10
+ throw new Error("FitSMS: API Token and Sender ID are required.");
11
+ }
12
+ this.apiToken = apiToken;
13
+ this.senderId = senderId;
14
+
15
+ this.v3Base = "https://app.fitsms.lk/api/v3";
16
+
17
+ // Default Headers
18
+ this.headers = {
19
+ Authorization: `Bearer ${this.apiToken}`,
20
+ "Content-Type": "application/json",
21
+ Accept: "application/json",
22
+ };
23
+ }
24
+
25
+ /**
26
+ * Send an SMS (v3 API)
27
+ * @param {string|string[]} recipients - e.g., "9476111,9476222"
28
+ * @param {string} message - The SMS body
29
+ */
30
+ async send(recipients, message, type = "plain") {
31
+ const recipientList = Array.isArray(recipients)
32
+ ? recipients.join(",")
33
+ : recipients;
34
+
35
+ try {
36
+ const response = await axios.post(
37
+ `${this.v3Base}/sms/send`,
38
+ {
39
+ recipient: recipientList,
40
+ sender_id: this.senderId,
41
+ type: type,
42
+ message: message,
43
+ },
44
+ { headers: this.headers },
45
+ );
46
+ return response.data;
47
+ } catch (error) {
48
+ throw new Error(
49
+ `FitSMS Send Failed: ${error.response?.data?.message || error.message}`,
50
+ );
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Check status of an existing SMS (v3 API)
56
+ * @param {string} uid - The unique message ID
57
+ */
58
+ async getStatus(uid) {
59
+ try {
60
+ const response = await axios.get(`${this.v3Base}/sms/${uid}`, {
61
+ headers: this.headers,
62
+ });
63
+ return response.data;
64
+ } catch (error) {
65
+ throw new Error(
66
+ `FitSMS Status Check Failed: ${error.response?.data?.message || error.message}`,
67
+ );
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Retrieve account balance and SMS units (v4 API)
73
+ */
74
+ async getBalance() {
75
+ try {
76
+ const response = await axios.get(`${this.v3Base}/balance`, {
77
+ headers: this.headers,
78
+ });
79
+ return response.data;
80
+ } catch (error) {
81
+ throw new Error(
82
+ `FitSMS Balance Check Failed: ${error.response?.data?.message || error.message}`,
83
+ );
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Retrieve full profile information (v4 API)
89
+ */
90
+ async getProfile() {
91
+ try {
92
+ const response = await axios.get(`${this.v3Base}/me`, {
93
+ headers: this.headers,
94
+ });
95
+ return response.data;
96
+ } catch (error) {
97
+ throw new Error(
98
+ `FitSMS Profile Retrieval Failed: ${error.response?.data?.message || error.message}`,
99
+ );
100
+ }
101
+ }
102
+ }
103
+
104
+ module.exports = FitSMS;
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "fitsms",
3
+ "version": "1.0.0",
4
+ "description": "The official-style Node.js SDK for the FitSMS.lk gateway.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node test.js"
8
+ },
9
+ "keywords": [
10
+ "fitsms",
11
+ "sms",
12
+ "srilanka",
13
+ "gateway",
14
+ "bulk-sms",
15
+ "947"
16
+ ],
17
+ "author": "Danuja Dilanka",
18
+ "license": "MIT",
19
+ "dependencies": {
20
+ "axios": "^1.6.0"
21
+ }
22
+ }
package/test.js ADDED
@@ -0,0 +1,60 @@
1
+ const FitSMS = require("./index.js");
2
+
3
+ /*
4
+
5
+ THIS IMPLEMENTATION FOLLOWS FITSMS'S V3 API SPECIFICATION
6
+
7
+ https://app.fitsms.lk/api/v3
8
+
9
+ FOR V4 API, WEBHOOKS & FURTHER DOCUMENTATION, SEE:
10
+ https://app.fitsms.lk/developers/docs
11
+
12
+ DEV. BY GLOBAL CLOUD MEDIA (https://globalcloudmedia.lk)
13
+ REPOSITORY: https://github.com/Global-Cloud-Media-Pvt-Ltd/fitsms-nodejs-sdk
14
+
15
+ */
16
+
17
+ // REPLACE THESE WITH YOUR ACTUAL CREDENTIALS FOR TESTING
18
+ const API_TOKEN = "YOUR_ACTUAL_BEARER_TOKEN_HERE";
19
+ const SENDER_ID = "YOUR_ACTUAL_SENDER_ID_HERE";
20
+ const TEST_MOBILE = "947XXXXXXX";
21
+
22
+ const sms = new FitSMS(API_TOKEN, SENDER_ID);
23
+
24
+ async function runTests() {
25
+ console.log("🚀 Starting FitSMS Module Tests...\n");
26
+
27
+ try {
28
+ // 1. Test Balance (v3 API)
29
+ console.log("--- Testing getBalance() ---");
30
+ const balance = await sms.getBalance();
31
+ console.log("✅ Balance Status:", balance.status);
32
+ console.log("Remaining Units:", balance.data);
33
+ console.log("----------------------------\n");
34
+
35
+ // 2. Test Sending SMS (v3 API)
36
+ console.log("--- Testing send() ---");
37
+ const sendRes = await sms.send(TEST_MOBILE, "Test message from local SDK");
38
+ console.log("✅ Send Status:", sendRes.status);
39
+
40
+ if (sendRes.data[0] && sendRes.data[0].uid) {
41
+ const uid = sendRes.data[0].uid;
42
+ console.log("Message UID:", uid);
43
+ console.log("----------------------------\n");
44
+
45
+ // 3. Test Status Check (v3 API)
46
+ console.log("--- Testing getStatus() ---");
47
+ const statusRes = await sms.getStatus(uid);
48
+ console.log("✅ Status Check:", statusRes.status);
49
+ console.log("Delivery Status:", statusRes.data.status);
50
+ console.log("----------------------------\n");
51
+ }
52
+
53
+ console.log("🎉 All tests passed successfully!");
54
+ } catch (error) {
55
+ console.error("❌ Test Failed!");
56
+ console.error("Error Message:", error.message);
57
+ }
58
+ }
59
+
60
+ runTests();