fitsms 1.0.3 → 1.0.5

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.
@@ -0,0 +1,32 @@
1
+ name: Publish FitSMS to npm
2
+
3
+ on:
4
+ release:
5
+ types: [created]
6
+
7
+ jobs:
8
+ build_and_test:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-node@v4
13
+ with:
14
+ node-version: 20
15
+ - run: npm ci
16
+ - run: npm test
17
+
18
+ publish-npm:
19
+ needs: build_and_test
20
+ runs-on: ubuntu-latest
21
+ environment: production
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - uses: actions/setup-node@v4
25
+ with:
26
+ node-version: 20
27
+ # Official npm registry
28
+ registry-url: 'https://registry.npmjs.org'
29
+ - run: npm ci
30
+ - run: npm publish --access public
31
+ env:
32
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md CHANGED
@@ -1,106 +1,105 @@
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 = ["94XXXXXXXXX", "94XXXXXXXX"];
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 [Global Cloud Media (pvt) Ltd.](https://globalcloudmedia.lk)
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/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
+
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
+ - **Bearer Token Auth**: Secure authentication via headers.
14
+ - **Flexible Recipients**: Supports strings, comma-separated lists, and arrays.
15
+ - **Real-time Status**: Retrieve delivery reports using message UIDs.
16
+ - **Balance Monitoring**: Track remaining SMS units.
17
+ - **Lightweight**: Minimal dependencies.
18
+
19
+ ---
20
+
21
+ ## 📦 Installation
22
+
23
+ ```bash
24
+ npm install fitsms
25
+ ```
26
+
27
+ ---
28
+
29
+ ## 🛠 Usage
30
+
31
+ ### Initialization
32
+
33
+ ```js
34
+ const FitSMS = require("fitsms");
35
+
36
+ const sms = new FitSMS("YOUR_BEARER_TOKEN", "The Change");
37
+ ```
38
+
39
+ ---
40
+
41
+ ### Sending SMS
42
+
43
+ ```js
44
+ async function sendAlert() {
45
+ try {
46
+ const recipients = ["94XXXXXXXXX", "94XXXXXXXX"];
47
+
48
+ const response = await sms.send(
49
+ recipients,
50
+ "This is a test message from FitSMS SDK",
51
+ );
52
+
53
+ console.log("Success:", response.data.uid);
54
+ } catch (error) {
55
+ console.error("Error:", error.message);
56
+ }
57
+ }
58
+ ```
59
+
60
+ ---
61
+
62
+ ### Checking Message Status
63
+
64
+ ```js
65
+ const status = await sms.getStatus("606812e63f78b");
66
+ console.log("Delivery Status:", status.data.status);
67
+ ```
68
+
69
+ ---
70
+
71
+ ### Checking Balance
72
+
73
+ ```js
74
+ const balance = await sms.getBalance();
75
+ console.log("Remaining Units:", balance.data);
76
+ ```
77
+
78
+ ---
79
+
80
+ ## 📖 API Reference
81
+
82
+ | Method | Parameters | Description |
83
+ | ------------ | ------------------------- | ------------------- |
84
+ | send() | recipients, message, type | Sends an SMS |
85
+ | getStatus() | uid | Get delivery status |
86
+ | getBalance() | none | Get SMS balance |
87
+ | getProfile() | none | Get account profile |
88
+
89
+ ---
90
+
91
+ ## 📄 License
92
+
93
+ This project is licensed under the MIT License.
94
+
95
+ ---
96
+
97
+ ## 🤝 Contributing
98
+
99
+ Contributions, issues, and feature requests are welcome!
100
+
101
+ ---
102
+
103
+ ## 👨‍💻 Maintainer
104
+
105
+ Maintained by [Global Cloud Media (pvt) Ltd.](https://globalcloudmedia.lk)
package/index.js CHANGED
@@ -1,139 +1,139 @@
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., "9476XXXXX,9476XXXXX"
28
- * @param {string} message - The SMS body
29
- */
30
- async send(recipients, message, type = "plain") {
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(",");
69
-
70
- try {
71
- const response = await axios.post(
72
- `${this.v3Base}/sms/send`,
73
- {
74
- recipient: recipientList,
75
- sender_id: this.senderId,
76
- type: type,
77
- message: message,
78
- },
79
- { headers: this.headers },
80
- );
81
- return response.data;
82
- } catch (error) {
83
- throw new Error(
84
- `FitSMS Send Failed: ${error.response?.data?.message || error.message}`,
85
- );
86
- }
87
- }
88
-
89
- /**
90
- * Check status of an existing SMS (v3 API)
91
- * @param {string} uid - The unique message ID
92
- */
93
- async getStatus(uid) {
94
- try {
95
- const response = await axios.get(`${this.v3Base}/sms/${uid}`, {
96
- headers: this.headers,
97
- });
98
- return response.data;
99
- } catch (error) {
100
- throw new Error(
101
- `FitSMS Status Check Failed: ${error.response?.data?.message || error.message}`,
102
- );
103
- }
104
- }
105
-
106
- /**
107
- * Retrieve account balance and SMS units (v4 API)
108
- */
109
- async getBalance() {
110
- try {
111
- const response = await axios.get(`${this.v3Base}/balance`, {
112
- headers: this.headers,
113
- });
114
- return response.data;
115
- } catch (error) {
116
- throw new Error(
117
- `FitSMS Balance Check Failed: ${error.response?.data?.message || error.message}`,
118
- );
119
- }
120
- }
121
-
122
- /**
123
- * Retrieve full profile information (v4 API)
124
- */
125
- async getProfile() {
126
- try {
127
- const response = await axios.get(`${this.v3Base}/me`, {
128
- headers: this.headers,
129
- });
130
- return response.data;
131
- } catch (error) {
132
- throw new Error(
133
- `FitSMS Profile Retrieval Failed: ${error.response?.data?.message || error.message}`,
134
- );
135
- }
136
- }
137
- }
138
-
139
- module.exports = FitSMS;
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., "9476XXXXX,9476XXXXX"
28
+ * @param {string} message - The SMS body
29
+ */
30
+ async send(recipients, message, type = "plain") {
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(",");
69
+
70
+ try {
71
+ const response = await axios.post(
72
+ `${this.v3Base}/sms/send`,
73
+ {
74
+ recipient: recipientList,
75
+ sender_id: this.senderId,
76
+ type: type,
77
+ message: message,
78
+ },
79
+ { headers: this.headers },
80
+ );
81
+ return response.data;
82
+ } catch (error) {
83
+ throw new Error(
84
+ `FitSMS Send Failed: ${error.response?.data?.message || error.message}`,
85
+ );
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Check status of an existing SMS (v3 API)
91
+ * @param {string} uid - The unique message ID
92
+ */
93
+ async getStatus(uid) {
94
+ try {
95
+ const response = await axios.get(`${this.v3Base}/sms/${uid}`, {
96
+ headers: this.headers,
97
+ });
98
+ return response.data;
99
+ } catch (error) {
100
+ throw new Error(
101
+ `FitSMS Status Check Failed: ${error.response?.data?.message || error.message}`,
102
+ );
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Retrieve account balance and SMS units (v4 API)
108
+ */
109
+ async getBalance() {
110
+ try {
111
+ const response = await axios.get(`${this.v3Base}/balance`, {
112
+ headers: this.headers,
113
+ });
114
+ return response.data;
115
+ } catch (error) {
116
+ throw new Error(
117
+ `FitSMS Balance Check Failed: ${error.response?.data?.message || error.message}`,
118
+ );
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Retrieve full profile information (v4 API)
124
+ */
125
+ async getProfile() {
126
+ try {
127
+ const response = await axios.get(`${this.v3Base}/me`, {
128
+ headers: this.headers,
129
+ });
130
+ return response.data;
131
+ } catch (error) {
132
+ throw new Error(
133
+ `FitSMS Profile Retrieval Failed: ${error.response?.data?.message || error.message}`,
134
+ );
135
+ }
136
+ }
137
+ }
138
+
139
+ module.exports = FitSMS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fitsms",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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
@@ -1,60 +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();
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();