smsalert-js 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Xelandru Software SRL
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # smsalert-js
2
+
3
+ Node.js client for the [SMSAlert](https://smsalert.mobi) API. Send SMS, WhatsApp messages, and push notifications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install smsalert-js
9
+ ```
10
+
11
+ ## Requirements
12
+
13
+ - Node.js >= 18.0.0
14
+
15
+ ## Quick Start
16
+
17
+ ```js
18
+ const { SmsAlertClient } = require('smsalert-js');
19
+
20
+ const client = new SmsAlertClient('your_username', 'your_api_key');
21
+
22
+ const response = await client.sendMessage('0720123456', 'Hello from smsalert-js!');
23
+ console.log(response.id);
24
+ ```
25
+
26
+ ## API
27
+
28
+ ### `new SmsAlertClient(username, apiKey)`
29
+
30
+ Create a new client. Credentials are available in your [SMSAlert dashboard](https://smsalert.mobi).
31
+
32
+ ---
33
+
34
+ ### `sendMessage(phoneNumber, message, options?)`
35
+
36
+ Send a single message.
37
+
38
+ ```js
39
+ const response = await client.sendMessage('0720123456', 'Hello!', {
40
+ cleanupUtf8: true, // default: true
41
+ autoShortUrl: false, // default: false
42
+ onlySmsModems: false, // default: false
43
+ modemId: null, // default: null
44
+ });
45
+ // { id: '...', smsCount: 1, status: true }
46
+ ```
47
+
48
+ ---
49
+
50
+ ### `sendBulkMessage(phoneList, message, date?)`
51
+
52
+ Send a message to multiple numbers.
53
+
54
+ ```js
55
+ const { PhoneList } = require('smsalert-js');
56
+
57
+ const phones = new PhoneList()
58
+ .addPhoneNumber('0720123456')
59
+ .addPhoneNumber('0730654321');
60
+
61
+ const response = await client.sendBulkMessage(phones, 'Bulk message!');
62
+ // { status: true, campaignId: 42 }
63
+
64
+ // With scheduled delivery:
65
+ const scheduled = await client.sendBulkMessage(phones, 'Scheduled bulk!', '2026-04-01 10:00:00');
66
+ ```
67
+
68
+ ---
69
+
70
+ ### `scheduleMessage(phoneNumber, message, date, modemId?)`
71
+
72
+ Schedule a message for future delivery. Date format: `YYYY-MM-DD HH:mm:ss`.
73
+
74
+ ```js
75
+ const response = await client.scheduleMessage(
76
+ '0720123456',
77
+ 'Reminder!',
78
+ '2026-04-01 09:00:00'
79
+ );
80
+ // { id: '...', smsCount: 1, status: true }
81
+ ```
82
+
83
+ ---
84
+
85
+ ### `checkMessageStatus(id)`
86
+
87
+ Check the delivery status of a message.
88
+
89
+ ```js
90
+ const status = await client.checkMessageStatus('message_id_here');
91
+ // { id: '...', modemId: '...', status: 'delivered', reason: '' }
92
+ ```
93
+
94
+ Status values: `delivered`, `terminal_accepted`, `failed`, `pending`, `scheduled`, `rerouted`
95
+
96
+ ---
97
+
98
+ ### `listSentMessages(page?, perPage?)`
99
+
100
+ List sent messages (paginated).
101
+
102
+ ```js
103
+ const result = await client.listSentMessages(1, 50);
104
+ // { status: true, page: 1, totalPages: 5, totalResults: 230, resultsPerPage: 50, sentMessages: [...] }
105
+ ```
106
+
107
+ ---
108
+
109
+ ### `listReceivedMessages(page?, perPage?)`
110
+
111
+ List received messages (paginated).
112
+
113
+ ```js
114
+ const result = await client.listReceivedMessages(1, 50);
115
+ ```
116
+
117
+ ---
118
+
119
+ ### `listDevices(page?, perPage?)`
120
+
121
+ List connected devices.
122
+
123
+ ```js
124
+ const result = await client.listDevices(1, 50);
125
+ // { status: true, ..., devices: [{ id, nickName, isOnline, lastSeenAt, ... }] }
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Error Handling
131
+
132
+ ```js
133
+ const { InvalidCredentials, InvalidParameters, InvalidDate } = require('smsalert-js');
134
+
135
+ try {
136
+ await client.sendMessage('0720123456', 'Hello!');
137
+ } catch (err) {
138
+ if (err instanceof InvalidCredentials) {
139
+ console.error('Wrong username or API key');
140
+ } else if (err instanceof InvalidParameters) {
141
+ console.error('Invalid parameters:', err.message);
142
+ } else if (err instanceof InvalidDate) {
143
+ console.error('Invalid date format. Use: YYYY-MM-DD HH:mm:ss');
144
+ } else {
145
+ throw err;
146
+ }
147
+ }
148
+ ```
149
+
150
+ ## ESM Support
151
+
152
+ ```js
153
+ import { SmsAlertClient, PhoneList } from 'smsalert-js';
154
+ ```
155
+
156
+ ## License
157
+
158
+ MIT — [smsalert.mobi](https://smsalert.mobi)
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "smsalert-js",
3
+ "version": "1.0.0",
4
+ "description": "Node.js client for the SMSAlert API - send SMS, WhatsApp and push notifications",
5
+ "main": "src/index.js",
6
+ "types": "src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./src/index.js",
10
+ "import": "./src/index.mjs"
11
+ }
12
+ },
13
+ "files": [
14
+ "src/",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "scripts": {
19
+ "test": "node --test"
20
+ },
21
+ "keywords": [
22
+ "sms",
23
+ "smsalert",
24
+ "whatsapp",
25
+ "messaging",
26
+ "notifications"
27
+ ],
28
+ "author": "Alexandru Dinu <contact@smsalert.mobi>",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/smsalert-mobi/smsalert-js"
33
+ },
34
+ "homepage": "https://smsalert.mobi",
35
+ "engines": {
36
+ "node": ">=18.0.0"
37
+ },
38
+ "dependencies": {
39
+ "axios": "^1.6.0"
40
+ }
41
+ }
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ class PhoneList {
4
+ constructor() {
5
+ this._list = [];
6
+ }
7
+
8
+ addPhoneNumber(phoneNumber) {
9
+ this._list.push(phoneNumber);
10
+ return this;
11
+ }
12
+
13
+ getPhoneList() {
14
+ return this._list;
15
+ }
16
+ }
17
+
18
+ module.exports = PhoneList;
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ const axios = require('axios');
4
+ const { InvalidCredentials, InvalidParameters, InvalidDate } = require('./errors');
5
+
6
+ const BASE_URL = 'https://smsalert.mobi/api/v2';
7
+ const DATE_REGEX = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
8
+
9
+ class SmsAlertClient {
10
+ constructor(username, apiKey) {
11
+ this._http = axios.create({
12
+ baseURL: BASE_URL,
13
+ auth: { username, password: apiKey },
14
+ headers: { 'Content-Type': 'application/json' },
15
+ });
16
+
17
+ this._http.interceptors.response.use(
18
+ (res) => res,
19
+ (err) => {
20
+ if (err.response?.status === 401) throw new InvalidCredentials();
21
+ if (err.response?.status === 422) throw new InvalidParameters(JSON.stringify(err.response.data));
22
+ throw err;
23
+ }
24
+ );
25
+ }
26
+
27
+ /**
28
+ * Send a single SMS message.
29
+ * @param {string} phoneNumber
30
+ * @param {string} message
31
+ * @param {object} [options]
32
+ * @param {boolean} [options.cleanupUtf8=true]
33
+ * @param {boolean} [options.autoShortUrl=false]
34
+ * @param {boolean} [options.onlySmsModems=false]
35
+ * @param {string|null} [options.modemId=null]
36
+ * @returns {Promise<{id: string, smsCount: number, status: boolean}>}
37
+ */
38
+ async sendMessage(phoneNumber, message, options = {}) {
39
+ const { cleanupUtf8 = true, autoShortUrl = false, onlySmsModems = false, modemId = null } = options;
40
+
41
+ const payload = { phoneNumber, message, cleanupUtf8, autoShortUrl, onlySmsModems };
42
+ if (modemId) payload.modemId = modemId;
43
+
44
+ const { data } = await this._http.post('/message/send', payload);
45
+ return data;
46
+ }
47
+
48
+ /**
49
+ * Send a message to multiple phone numbers.
50
+ * @param {import('./PhoneList')} phoneList
51
+ * @param {string} message
52
+ * @param {string|null} [date=null] - Format: "YYYY-MM-DD HH:mm:ss"
53
+ * @returns {Promise<{status: boolean, campaignId: number}>}
54
+ */
55
+ async sendBulkMessage(phoneList, message, date = null) {
56
+ if (date && !DATE_REGEX.test(date)) throw new InvalidDate();
57
+
58
+ const payload = { phoneList: phoneList.getPhoneList(), message };
59
+ if (date) payload.date = date;
60
+
61
+ const { data } = await this._http.post('/message/bulk', payload);
62
+ return data;
63
+ }
64
+
65
+ /**
66
+ * Schedule a message for future delivery.
67
+ * @param {string} phoneNumber
68
+ * @param {string} message
69
+ * @param {string} date - Format: "YYYY-MM-DD HH:mm:ss"
70
+ * @param {string|null} [modemId=null]
71
+ * @returns {Promise<{id: string, smsCount: number, status: boolean}>}
72
+ */
73
+ async scheduleMessage(phoneNumber, message, date, modemId = null) {
74
+ if (!DATE_REGEX.test(date)) throw new InvalidDate();
75
+
76
+ const payload = { phoneNumber, message, date };
77
+ if (modemId) payload.modemId = modemId;
78
+
79
+ const { data } = await this._http.post('/message/schedule', payload);
80
+ return data;
81
+ }
82
+
83
+ /**
84
+ * Check the delivery status of a message.
85
+ * @param {string} id - Message ID
86
+ * @returns {Promise<{id: string, modemId: string, status: string, reason: string}>}
87
+ */
88
+ async checkMessageStatus(id) {
89
+ const { data } = await this._http.post('/message/getStatus', { id });
90
+ return data;
91
+ }
92
+
93
+ /**
94
+ * List sent messages (paginated).
95
+ * @param {number} [page=1]
96
+ * @param {number} [perPage=50]
97
+ * @returns {Promise<{status: boolean, page: number, totalPages: number, totalResults: number, resultsPerPage: number, sentMessages: Array}>}
98
+ */
99
+ async listSentMessages(page = 1, perPage = 50) {
100
+ const { data } = await this._http.get('/message/sent/list', { params: { page, perPage } });
101
+ return data;
102
+ }
103
+
104
+ /**
105
+ * List received messages (paginated).
106
+ * @param {number} [page=1]
107
+ * @param {number} [perPage=50]
108
+ * @returns {Promise<{status: boolean, page: number, totalPages: number, totalResults: number, resultsPerPage: number, sentMessages: Array}>}
109
+ */
110
+ async listReceivedMessages(page = 1, perPage = 50) {
111
+ const { data } = await this._http.get('/message/list', { params: { page, perPage } });
112
+ return data;
113
+ }
114
+
115
+ /**
116
+ * List devices (paginated).
117
+ * @param {number} [page=1]
118
+ * @param {number} [perPage=50]
119
+ * @returns {Promise<{status: boolean, page: number, totalPages: number, totalResults: number, resultsPerPage: number, devices: Array}>}
120
+ */
121
+ async listDevices(page = 1, perPage = 50) {
122
+ const { data } = await this._http.get('/device/list', { params: { page, perPage } });
123
+ return data;
124
+ }
125
+ }
126
+
127
+ module.exports = SmsAlertClient;
package/src/errors.js ADDED
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ class InvalidCredentials extends Error {
4
+ constructor(message = 'Invalid credentials') {
5
+ super(message);
6
+ this.name = 'InvalidCredentials';
7
+ }
8
+ }
9
+
10
+ class InvalidParameters extends Error {
11
+ constructor(message = 'Invalid parameters') {
12
+ super(message);
13
+ this.name = 'InvalidParameters';
14
+ }
15
+ }
16
+
17
+ class InvalidDate extends Error {
18
+ constructor(message = 'Invalid date format. Use: YYYY-MM-DD HH:mm:ss') {
19
+ super(message);
20
+ this.name = 'InvalidDate';
21
+ }
22
+ }
23
+
24
+ module.exports = { InvalidCredentials, InvalidParameters, InvalidDate };
package/src/index.d.ts ADDED
@@ -0,0 +1,90 @@
1
+ export declare class PhoneList {
2
+ addPhoneNumber(phoneNumber: string): this;
3
+ getPhoneList(): string[];
4
+ }
5
+
6
+ export interface SendMessageOptions {
7
+ cleanupUtf8?: boolean;
8
+ autoShortUrl?: boolean;
9
+ onlySmsModems?: boolean;
10
+ modemId?: string | null;
11
+ }
12
+
13
+ export interface SendMessageResponse {
14
+ id: string;
15
+ smsCount: number;
16
+ status: boolean;
17
+ }
18
+
19
+ export interface SendBulkMessageResponse {
20
+ status: boolean;
21
+ campaignId: number;
22
+ }
23
+
24
+ export interface MessageStatusResponse {
25
+ id: string;
26
+ modemId: string;
27
+ status: string;
28
+ reason: string;
29
+ }
30
+
31
+ export interface SentMessage {
32
+ id: string;
33
+ message: string;
34
+ to: string;
35
+ status: string;
36
+ failReason?: string;
37
+ sentAt: string;
38
+ }
39
+
40
+ export interface ReceivedMessage {
41
+ id: string;
42
+ message: string;
43
+ from: string;
44
+ seen: boolean;
45
+ receivedAt: string;
46
+ }
47
+
48
+ export interface Device {
49
+ id: string;
50
+ nickName: string;
51
+ lastSeenAt?: string;
52
+ isOnline: boolean;
53
+ connectionToken?: string;
54
+ version?: string;
55
+ }
56
+
57
+ export interface PaginatedResponse<T> {
58
+ status: boolean;
59
+ page: number;
60
+ totalPages: number;
61
+ totalResults: number;
62
+ resultsPerPage: number;
63
+ }
64
+
65
+ export interface ListSentMessagesResponse extends PaginatedResponse<SentMessage> {
66
+ sentMessages: SentMessage[];
67
+ }
68
+
69
+ export interface ListReceivedMessagesResponse extends PaginatedResponse<ReceivedMessage> {
70
+ sentMessages: ReceivedMessage[];
71
+ }
72
+
73
+ export interface ListDevicesResponse extends PaginatedResponse<Device> {
74
+ devices: Device[];
75
+ }
76
+
77
+ export declare class SmsAlertClient {
78
+ constructor(username: string, apiKey: string);
79
+ sendMessage(phoneNumber: string, message: string, options?: SendMessageOptions): Promise<SendMessageResponse>;
80
+ sendBulkMessage(phoneList: PhoneList, message: string, date?: string | null): Promise<SendBulkMessageResponse>;
81
+ scheduleMessage(phoneNumber: string, message: string, date: string, modemId?: string | null): Promise<SendMessageResponse>;
82
+ checkMessageStatus(id: string): Promise<MessageStatusResponse>;
83
+ listSentMessages(page?: number, perPage?: number): Promise<ListSentMessagesResponse>;
84
+ listReceivedMessages(page?: number, perPage?: number): Promise<ListReceivedMessagesResponse>;
85
+ listDevices(page?: number, perPage?: number): Promise<ListDevicesResponse>;
86
+ }
87
+
88
+ export declare class InvalidCredentials extends Error {}
89
+ export declare class InvalidParameters extends Error {}
90
+ export declare class InvalidDate extends Error {}
package/src/index.js ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const SmsAlertClient = require('./SmsAlertClient');
4
+ const PhoneList = require('./PhoneList');
5
+ const { InvalidCredentials, InvalidParameters, InvalidDate } = require('./errors');
6
+
7
+ module.exports = {
8
+ SmsAlertClient,
9
+ PhoneList,
10
+ InvalidCredentials,
11
+ InvalidParameters,
12
+ InvalidDate,
13
+ };
package/src/index.mjs ADDED
@@ -0,0 +1,10 @@
1
+ import { createRequire } from 'module';
2
+ const require = createRequire(import.meta.url);
3
+ const pkg = require('./index.js');
4
+
5
+ export const SmsAlertClient = pkg.SmsAlertClient;
6
+ export const PhoneList = pkg.PhoneList;
7
+ export const InvalidCredentials = pkg.InvalidCredentials;
8
+ export const InvalidParameters = pkg.InvalidParameters;
9
+ export const InvalidDate = pkg.InvalidDate;
10
+ export default pkg.SmsAlertClient;