unismsgateway 1.2.1 → 1.3.1

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 RazakAlpha
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 CHANGED
@@ -1,93 +1,381 @@
1
+ # Unified SMS Gateway
1
2
 
2
- # Unified Sms Gateway
3
+ Most projects rely on more than one SMS provider so they can switch if a gateway is unavailable. Each provider’s API differs, so separate integrations are usually required.
3
4
 
4
- Most of the time a single project relies on multiple sms Gateway so it can switched if one goes off.
5
- However, each sms api specification is different from the other, hence the need to create separate implementation
6
- for each sms gateway.
5
+ **unismsgateway** exposes a single API for multiple SMS gateways. You implement once, then select or switch the platform; your send flow stays the same.
7
6
 
8
- Unified sms gateway is library that brings most common sms gateways under a Unified api.
9
- which means you only does one implementation in it works for all supported sms gateway.
10
- you just have select or switch your sms platform and your code still works fine like nothing has changed
7
+ ## Installation
11
8
 
9
+ ```bash
10
+ npm install unismsgateway
11
+ ```
12
12
 
13
- ## Usage/Examples
13
+ **Requirements:** Node.js `>= 12.0.0` (see `package.json` `engines`).
14
14
 
15
- ```javascript
16
- const unisms = require('unismsgateway')
15
+ ## Module import
16
+
17
+ **CommonJS**
17
18
 
18
- const param = { clientId, // hubtel sms client Id **optional
19
- clientSecret, // hubtel sms client secret ** optional
20
- username, // username for route sms
21
- password, // password for route sms
22
- host, // host address eg. rslr.connectbind.....
23
- port} // port defaults to 8080
19
+ ```javascript
20
+ const unisms = require('unismsgateway');
21
+ ```
24
22
 
25
- //init with prefered platform id. route => routemobile, hubtel => hubtel sms
26
- // more sms services will be added or supported in the future
27
- const gateway = unisms.init({platformId:'route', param})
23
+ **ESM / TypeScript**
28
24
 
25
+ ```typescript
26
+ import * as unisms from 'unismsgateway';
27
+ // or named:
28
+ import { init, getSmsPlatform, reset, smsPlatform } from 'unismsgateway';
29
29
  ```
30
30
 
31
- ### SEND MESSAGE
31
+ ---
32
+
33
+ ## Configuration overview
34
+
35
+ ### `IgatewaySettings`
36
+
37
+ | Field | Type | Description |
38
+ |-------|------|-------------|
39
+ | `platformId` | `'route' \| 'hubtel' \| 'nest'` | Which gateway to use. |
40
+ | `param` | `IgatewayParam` | Provider-specific options (see below). |
41
+
42
+ ### `IgatewayParam` (all fields optional except what your `platformId` requires)
43
+
44
+ | Field | Type | Used by | Description |
45
+ |-------|------|---------|-------------|
46
+ | `username` | `string` | `route` | Route Mobile account username. **Required** for `route`. |
47
+ | `password` | `string` | `route` | Route Mobile account password. **Required** for `route`. |
48
+ | `host` | `string` | `route`, `nest` | API host. See per-gateway defaults below. |
49
+ | `port` | `number` | `route` | TCP port for Route Mobile. Default: `8080`. |
50
+ | `protocol` | `'http' \| 'https'` | `route`, `nest` | URL scheme. See defaults per gateway. |
51
+ | `clientId` | `string` | `hubtel` | Hubtel client ID. **Required** for `hubtel`. |
52
+ | `clientSecret` | `string` | `hubtel` | Hubtel client secret. **Required** for `hubtel`. |
53
+ | `apiKey` | `string` | `nest` | SMSOnlineGH API key (`Authorization: key …`). **Required** for `nest`. |
54
+
55
+ Validation runs in `smsPlatform` when the instance is constructed: missing required fields for the chosen `platformId` throw `Error` with a clear message.
56
+
57
+ ---
58
+
59
+ ## Environment variables
60
+
61
+ **This library does not read `process.env` or any configuration files.** You pass all credentials and endpoints explicitly in `init({ platformId, param })`.
62
+
63
+ In your own application it is common to map environment variables into `param`. Suggested names (you define these in `.env` or your host’s secret store):
64
+
65
+ | Suggested env name | Maps to `param` | Gateways |
66
+ |--------------------|-----------------|----------|
67
+ | `SMS_PLATFORM_ID` | `platformId` | all |
68
+ | `ROUTE_SMS_USERNAME` | `username` | `route` |
69
+ | `ROUTE_SMS_PASSWORD` | `password` | `route` |
70
+ | `ROUTE_SMS_HOST` | `host` | `route` (optional; has default) |
71
+ | `ROUTE_SMS_PORT` | `port` | `route` (optional) |
72
+ | `ROUTE_SMS_PROTOCOL` | `protocol` | `route` (optional) |
73
+ | `HUBTEL_CLIENT_ID` | `clientId` | `hubtel` |
74
+ | `HUBTEL_CLIENT_SECRET` | `clientSecret` | `hubtel` |
75
+ | `SMSONLINEGH_API_KEY` or `NEST_API_KEY` | `apiKey` | `nest` |
76
+ | `SMSONLINEGH_HOST` or `NEST_HOST` | `host` | `nest` (optional) |
77
+ | `SMSONLINEGH_PROTOCOL` or `NEST_PROTOCOL` | `protocol` | `nest` (optional) |
78
+
79
+ Example wiring (conceptual): branch on `platformId` and build `param` so you do not mix unrelated fields.
80
+
32
81
  ```javascript
82
+ const unisms = require('unismsgateway');
33
83
 
34
- const testSms = async function(){
35
- try{
36
- // const gateway = unisms.getSmsPlatform();
37
- await gateway.quickSend({From:'xxxxx', To: xxxxxxxx, Content: 'Testing unisms', Type: 0}, (response)=>{
38
- console.log(response)
39
- }).then(r => {
40
- console.log(r)
41
- }).catch(err => {
42
- console.log(err)
43
- })
44
- }catch(err){
45
- console.log(err)
84
+ const platformId = process.env.SMS_PLATFORM_ID;
85
+
86
+ const paramByPlatform = {
87
+ route: {
88
+ username: process.env.ROUTE_SMS_USERNAME,
89
+ password: process.env.ROUTE_SMS_PASSWORD,
90
+ host: process.env.ROUTE_SMS_HOST,
91
+ port: process.env.ROUTE_SMS_PORT ? Number(process.env.ROUTE_SMS_PORT) : undefined,
92
+ protocol: process.env.ROUTE_SMS_PROTOCOL
93
+ },
94
+ hubtel: {
95
+ clientId: process.env.HUBTEL_CLIENT_ID,
96
+ clientSecret: process.env.HUBTEL_CLIENT_SECRET
97
+ },
98
+ nest: {
99
+ apiKey: process.env.SMSONLINEGH_API_KEY,
100
+ host: process.env.SMSONLINEGH_HOST,
101
+ protocol: process.env.SMSONLINEGH_PROTOCOL
46
102
  }
103
+ };
47
104
 
105
+ const gateway = unisms.init({
106
+ platformId,
107
+ param: paramByPlatform[platformId]
108
+ });
109
+ ```
48
110
 
49
- }
111
+ ---
112
+
113
+ ## How initialization works
114
+
115
+ 1. **`init(settings: IgatewaySettings): smsPlatform`** (in `src/lib/lib.ts`):
116
+ - Validates and constructs a new `smsPlatform` with your `settings`.
117
+ - Stores it as the **module singleton** (`smsPlatformInstance`).
118
+ - Calls `smsPlatform.init()` on that instance (returns the same facade for chaining).
119
+ - Returns the `smsPlatform` instance.
120
+
121
+ 2. **`smsPlatform` constructor** (in `src/lib/platform.ts`):
122
+ - Runs `validateSettings()` (platform id + required `param` fields for that id).
123
+ - Calls `createGateway()` to instantiate the underlying provider (`routeSms`, `HubtelSms`, or `NestSmsGateway`).
50
124
 
125
+ 3. **`getSmsPlatform(): smsPlatform | null`**: Returns the current singleton, or `null` if `reset()` was called and no new `init()` has run.
126
+
127
+ There is **no async bootstrap**; after `init()` returns, `quickSend` is ready.
128
+
129
+ ---
130
+
131
+ ## Re-initializing and reset
132
+
133
+ - **Switch platform or credentials:** Call **`init(newSettings)`** again. Each call **replaces** the stored singleton with a new `smsPlatform`. You do not have to call `reset()` first.
134
+ - **Clear the singleton:** **`reset()`** sets the internal reference to `null`. `getSmsPlatform()` then returns `null` until the next `init()`. Use this when you want to guarantee nothing holds a gateway instance (e.g. tests or explicit teardown).
135
+
136
+ ```javascript
137
+ const unisms = require('unismsgateway');
138
+
139
+ const a = unisms.init({ platformId: 'nest', param: { apiKey: 'key-1' } });
140
+ // Later: new config
141
+ const b = unisms.init({ platformId: 'hubtel', param: { clientId: 'x', clientSecret: 'y' } });
142
+ // b replaces a; unisms.getSmsPlatform() === b
143
+
144
+ unisms.reset();
145
+ // unisms.getSmsPlatform() === null
146
+
147
+ const c = unisms.init({ platformId: 'nest', param: { apiKey: 'key-2' } });
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Supported gateways
153
+
154
+ | `platformId` | Provider | Package / implementation |
155
+ |----------------|----------|---------------------------|
156
+ | `route` | Route Mobile | `routemobilesms` |
157
+ | `hubtel` | Hubtel SMS (Ghana) | `hubtel-sms-extended` |
158
+ | `nest` | SMSOnlineGH | Built-in REST client (`NestSmsGateway`) |
159
+
160
+ ### `route` (Route Mobile)
161
+
162
+ **Required `param`:** `username`, `password`.
163
+
164
+ **Optional `param` (defaults in this library):**
165
+
166
+ | Field | Default if omitted |
167
+ |-------|-------------------|
168
+ | `host` | `rslr.connectbind.com` |
169
+ | `protocol` | `'http'` |
170
+ | `port` | `8080` |
171
+
172
+ These are passed into `routeSms` from `routemobilesms`.
173
+
174
+ ```javascript
175
+ const gateway = unisms.init({
176
+ platformId: 'route',
177
+ param: {
178
+ username: 'your-username',
179
+ password: 'your-password',
180
+ host: 'rslr.connectbind.com',
181
+ protocol: 'http',
182
+ port: 8080
183
+ }
184
+ });
51
185
  ```
52
186
 
53
- ### SEND PERSONALIZED MESSAGE
187
+ ### `hubtel` (Hubtel)
188
+
189
+ **Required `param`:** `clientId`, `clientSecret`.
190
+
191
+ No `host` / `protocol` in `IgatewayParam` for Hubtel in this library; configuration follows `hubtel-sms-extended`.
192
+
54
193
  ```javascript
194
+ const gateway = unisms.init({
195
+ platformId: 'hubtel',
196
+ param: {
197
+ clientId: 'your-client-id',
198
+ clientSecret: 'your-client-secret'
199
+ }
200
+ });
201
+ ```
202
+
203
+ ### `nest` (SMSOnlineGH)
204
+
205
+ **Required `param`:** `apiKey`.
206
+
207
+ **Optional `param`:**
208
+
209
+ | Field | Default if omitted |
210
+ |-------|-------------------|
211
+ | `host` | `api.smsonlinegh.com` |
212
+ | `protocol` | `'https'` |
55
213
 
56
- const testSms = async function(){
57
- try{
58
- // const gateway = unisms.getSmsPlatform();
59
- await gateway.sendPersonalized({From:'xxxxx',
60
- To: {to: 233XXXXXXXXX, values: ['Alpha', 65332]}, // [{to: 233XXXXXXXXX, values: ['Alpha', 65332]}, {to: 211XXXXXXXXX, values: ['James', 2000]}, ]
61
- Content: 'Testing unisms',
62
- Type: 0}).then(r => {
63
- console.log(r)
64
- }).catch(err => {
65
- console.log(err)
66
- })
67
- }catch(err){
68
- console.log(err)
214
+ Requests use `POST` to path **`/v5/<endpoint>`** (e.g. send: `message/sms/send`, balance: `account/balance`). Authorization header: `Authorization: key <apiKey>`.
215
+
216
+ ```javascript
217
+ const gateway = unisms.init({
218
+ platformId: 'nest',
219
+ param: {
220
+ apiKey: 'your-api-key'
221
+ // optional: host, protocol
69
222
  }
223
+ });
224
+ ```
225
+
226
+ **Balance (nest only):** The underlying `NestSmsGateway` implements `getBalance()`. Access it via the facade’s `getGateway()`:
227
+
228
+ ```javascript
229
+ const gateway = unisms.init({
230
+ platformId: 'nest',
231
+ param: { apiKey: 'your-api-key' }
232
+ });
233
+
234
+ const nest = gateway.getGateway();
235
+ const balance = await nest.getBalance();
236
+ console.log(balance.balance, balance.model);
237
+ ```
238
+
239
+ ---
240
+
241
+ ## Sending messages
242
+
243
+ ### `QuickSendParams`
244
+
245
+ | Field | Type | Required | Description |
246
+ |-------|------|----------|-------------|
247
+ | `From` | `string` | yes | Sender ID or label. |
248
+ | `To` | `string \| number` | yes | Recipient number (format as required by the provider). |
249
+ | `Content` | `string` | yes | Message body. |
250
+ | `Type` | `number` | no | Message type; **nest** maps this to request body `type` (default `0`). |
251
+
252
+ ### `quickSend(params, callback?)`
253
+
254
+ Returns `Promise<SendResult>`. Optional `callback` is invoked with the same result when the promise completes.
255
+
256
+ **`SendResult`:**
257
+
258
+ ```typescript
259
+ {
260
+ success: boolean;
261
+ messageId?: string;
262
+ data?: any;
263
+ error?: string;
264
+ }
265
+ ```
70
266
 
267
+ **Example**
71
268
 
269
+ ```javascript
270
+ const unisms = require('unismsgateway');
271
+
272
+ const gateway = unisms.init({
273
+ platformId: 'nest',
274
+ param: { apiKey: 'your-api-key' }
275
+ });
276
+
277
+ async function sendSms() {
278
+ try {
279
+ const result = await gateway.quickSend({
280
+ From: 'SenderName',
281
+ To: '233XXXXXXXXX',
282
+ Content: 'Hello from unismsgateway!',
283
+ Type: 0
284
+ });
285
+
286
+ if (result.success) {
287
+ console.log('Sent:', result.messageId);
288
+ } else {
289
+ console.error('Failed:', result.error);
290
+ }
291
+ } catch (err) {
292
+ console.error(err);
293
+ }
72
294
  }
295
+ ```
296
+
297
+ **With callback**
298
+
299
+ ```javascript
300
+ gateway.quickSend(
301
+ { From: 'SenderName', To: '233XXXXXXXXX', Content: 'Test' },
302
+ (response) => {
303
+ console.log(response);
304
+ }
305
+ );
306
+ ```
307
+
308
+ ---
73
309
 
310
+ ## Testing (live integration)
311
+
312
+ There is no unit test suite in this package. For **manual integration checks** against real gateways, use the script in `scripts/test-live.ts`.
313
+
314
+ **Setup**
315
+
316
+ 1. Clone the repo and install dependencies: `npm install`
317
+ 2. Copy `.env.example` to `.env` and fill in credentials for the platform you want to exercise
318
+ 3. Run:
319
+
320
+ ```bash
321
+ npm test
322
+ # same as:
323
+ npm run test:live
74
324
  ```
75
325
 
326
+ **Selecting a platform**
327
+
328
+ | Env variable | Description |
329
+ |--------------|-------------|
330
+ | `GATEWAY_PLATFORM` | One of `nest`, `hubtel`, or `route`. Required unless you use `TEST_ALL`. |
331
+ | `TEST_ALL` | If set to `true`, runs tests for `nest`, `hubtel`, and `route` in sequence (each needs its env vars set). |
332
+
333
+ **What runs**
76
334
 
77
- ## supported bulk sms gateways
335
+ 1. **Init** Builds `param` from your `.env`, calls `init()`, and checks configuration validation.
336
+ 2. **Balance** — For `nest` and `hubtel` only, calls `getBalance()` when the adapter supports it. `route` skips this step.
337
+ 3. **Send** — **Opt-in.** By default no SMS is sent. Set `TEST_SEND=true` to call `quickSend()` with `TEST_FROM`, `TEST_TO`, and optional `TEST_CONTENT`.
78
338
 
79
- Hubtel bulk sms (Ghana) using hubtel-sms-extended
80
- routeMobile sms (India) using routemobilesms
81
- Nest SMS(Ghana) using nestsms
339
+ **Environment variables (live script)**
82
340
 
83
- ## Roadmap
341
+ Variables below match `.env.example` and `scripts/test-live.ts`.
84
342
 
85
- - Additional browser support
343
+ | Variable | Required when | Purpose |
344
+ |----------|----------------|---------|
345
+ | `GATEWAY_PLATFORM` | Unless `TEST_ALL=true` | `nest` \| `hubtel` \| `route` |
346
+ | `TEST_ALL` | Optional | `true` to test all three platforms |
347
+ | `NEST_API_KEY` | `nest` | SMSOnlineGH API key |
348
+ | `NEST_HOST`, `NEST_PROTOCOL` | `nest` | Optional overrides |
349
+ | `HUBTEL_CLIENT_ID`, `HUBTEL_CLIENT_SECRET` | `hubtel` | Hubtel credentials |
350
+ | `ROUTE_USERNAME`, `ROUTE_PASSWORD` | `route` | Route Mobile credentials |
351
+ | `ROUTE_HOST`, `ROUTE_PORT`, `ROUTE_PROTOCOL` | `route` | Optional overrides |
352
+ | `TEST_SEND` | To send SMS | Set to `true` to enable live send |
353
+ | `TEST_FROM`, `TEST_TO` | When `TEST_SEND=true` | Sender and recipient |
354
+ | `TEST_CONTENT` | When `TEST_SEND=true` | Message body (script has a default if omitted) |
86
355
 
87
- - Add more third party sms integrations
356
+ The script loads `.env` via `dotenv` (dev dependency). Exit code is `0` when all checks pass, non-zero if a step fails or no platform is selected.
88
357
 
358
+ ---
359
+
360
+ ## API reference
361
+
362
+ | Export | Description |
363
+ |--------|-------------|
364
+ | `init(settings)` | Create and register the singleton `smsPlatform`, return it. |
365
+ | `getSmsPlatform()` | Current `smsPlatform` or `null` after `reset()` and before `init()`. |
366
+ | `reset()` | Clear the singleton. |
367
+ | `smsPlatform` | Class type for typing/advanced use. |
368
+
369
+ **`smsPlatform` instance methods**
370
+
371
+ | Method | Returns | Description |
372
+ |--------|---------|-------------|
373
+ | `init()` | `ISmsGateway` | Returns `this` (facade). |
374
+ | `quickSend(params, callback?)` | `Promise<SendResult>` | Delegates to the active gateway. |
375
+ | `getGateway()` | `ISmsGateway` | Underlying adapter (for nest: `getBalance()`). |
376
+
377
+ ---
89
378
 
90
379
  ## License
91
380
 
92
381
  [MIT](https://choosealicense.com/licenses/mit/)
93
-
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './lib/lib';
1
+ export * from './lib/lib';
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./lib/lib"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./lib/lib"), exports);
@@ -0,0 +1,44 @@
1
+ export declare type PlatformId = 'route' | 'hubtel' | 'nest';
2
+ export interface QuickSendParams {
3
+ From: string;
4
+ To: string | number;
5
+ Content: string;
6
+ Type?: number;
7
+ }
8
+ export interface SendResult {
9
+ success: boolean;
10
+ messageId?: string;
11
+ data?: any;
12
+ error?: string;
13
+ }
14
+ export interface IgatewayParam {
15
+ host?: string;
16
+ port?: number;
17
+ username?: string;
18
+ password?: string;
19
+ clientId?: string;
20
+ clientSecret?: string;
21
+ apiKey?: string;
22
+ protocol?: 'http' | 'https';
23
+ }
24
+ export interface IgatewaySettings {
25
+ platformId: PlatformId;
26
+ param: IgatewayParam;
27
+ }
28
+ export interface ISmsGateway {
29
+ init(): ISmsGateway;
30
+ quickSend(params: QuickSendParams, callback?: Function): Promise<SendResult>;
31
+ getBalance?(): Promise<any>;
32
+ }
33
+ export interface NestSmsConfig {
34
+ apiKey: string;
35
+ host?: string;
36
+ protocol?: 'http' | 'https';
37
+ }
38
+ export interface NestSendResponse {
39
+ handshake: {
40
+ id: number;
41
+ label: string;
42
+ };
43
+ data?: any;
44
+ }
package/dist/lib/lib.d.ts CHANGED
@@ -1,10 +1,5 @@
1
- import { smsPlatform, IgatewaySettings, IQuickSendPersonalized } from './platform';
2
- export declare function init(settings: IgatewaySettings): smsPlatform;
3
- export declare function getSmsPlatform(): smsPlatform;
4
- export declare function quickSend(param: {
5
- From: string;
6
- To: number;
7
- Content: string;
8
- Type?: number;
9
- }, callback?: Function): any;
10
- export declare function sendPersonalized(body: IQuickSendPersonalized): any;
1
+ import { smsPlatform, IgatewaySettings, IgatewayParam, PlatformId, QuickSendParams, SendResult, ISmsGateway } from './platform';
2
+ export declare function init(settings: IgatewaySettings): smsPlatform;
3
+ export declare function getSmsPlatform(): smsPlatform | null;
4
+ export declare function reset(): void;
5
+ export { smsPlatform, IgatewaySettings, IgatewayParam, PlatformId, QuickSendParams, SendResult, ISmsGateway };
package/dist/lib/lib.js CHANGED
@@ -1,23 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendPersonalized = exports.quickSend = exports.getSmsPlatform = exports.init = void 0;
4
- const platform_1 = require("./platform");
5
- let smsplatform;
6
- function init(settings) {
7
- const smsPlatform_ = new platform_1.smsPlatform(settings);
8
- smsplatform = smsPlatform_;
9
- return smsPlatform_.init();
10
- }
11
- exports.init = init;
12
- function getSmsPlatform() {
13
- return smsplatform;
14
- }
15
- exports.getSmsPlatform = getSmsPlatform;
16
- function quickSend(param, callback) {
17
- return smsplatform.quickSend(param, callback);
18
- }
19
- exports.quickSend = quickSend;
20
- function sendPersonalized(body) {
21
- return smsplatform.sendPersonalized(body);
22
- }
23
- exports.sendPersonalized = sendPersonalized;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.smsPlatform = exports.reset = exports.getSmsPlatform = exports.init = void 0;
4
+ const platform_1 = require("./platform");
5
+ Object.defineProperty(exports, "smsPlatform", { enumerable: true, get: function () { return platform_1.smsPlatform; } });
6
+ let smsPlatformInstance = null;
7
+ function init(settings) {
8
+ smsPlatformInstance = new platform_1.smsPlatform(settings);
9
+ smsPlatformInstance.init();
10
+ return smsPlatformInstance;
11
+ }
12
+ exports.init = init;
13
+ function getSmsPlatform() {
14
+ return smsPlatformInstance;
15
+ }
16
+ exports.getSmsPlatform = getSmsPlatform;
17
+ function reset() {
18
+ smsPlatformInstance = null;
19
+ }
20
+ exports.reset = reset;
@@ -0,0 +1,12 @@
1
+ import { ISmsGateway, QuickSendParams, SendResult, NestSmsConfig } from './types';
2
+ export declare class NestSmsGateway implements ISmsGateway {
3
+ private config;
4
+ constructor(config: NestSmsConfig);
5
+ init(): ISmsGateway;
6
+ private makeRequest;
7
+ quickSend(params: QuickSendParams, callback?: Function): Promise<SendResult>;
8
+ getBalance(): Promise<{
9
+ balance: number;
10
+ model: string;
11
+ }>;
12
+ }