unismsgateway 1.3.3 → 1.4.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/README.md CHANGED
@@ -37,23 +37,24 @@ import { init, getSmsPlatform, reset, smsPlatform } from 'unismsgateway';
37
37
 
38
38
  | Field | Type | Description |
39
39
  | ------------ | --------------- | -------------------------------------- |
40
- | `platformId` | `'route' | 'hubtel' |
40
+ | `platformId` | `'route' \| 'hubtel' \| 'nest'` | Which gateway to use. |
41
41
  | `param` | `IgatewayParam` | Provider-specific options (see below). |
42
42
 
43
43
 
44
44
  ### `IgatewayParam` (all fields optional except what your `platformId` requires)
45
45
 
46
46
 
47
- | Field | Type | Used by | Description |
48
- | -------------- | -------- | --------------- | ---------------------------------------------------------------------- |
49
- | `username` | `string` | `route` | Route Mobile account username. **Required** for `route`. |
50
- | `password` | `string` | `route` | Route Mobile account password. **Required** for `route`. |
51
- | `host` | `string` | `route`, `nest` | API host. See per-gateway defaults below. |
52
- | `port` | `number` | `route` | TCP port for Route Mobile. Default: `8080`. |
53
- | `protocol` | `'http' | 'https'` | `route`, `nest` |
54
- | `clientId` | `string` | `hubtel` | Hubtel client ID. **Required** for `hubtel`. |
55
- | `clientSecret` | `string` | `hubtel` | Hubtel client secret. **Required** for `hubtel`. |
56
- | `apiKey` | `string` | `nest` | SMSOnlineGH API key (`Authorization: key …`). **Required** for `nest`. |
47
+ | Field | Type | Used by | Description |
48
+ | -------------- | --------- | --------------- | ---------------------------------------------------------------------- |
49
+ | `username` | `string` | `route` | Route Mobile account username. **Required** for `route`. |
50
+ | `password` | `string` | `route` | Route Mobile account password. **Required** for `route`. |
51
+ | `host` | `string` | `route`, `nest` | API host. See per-gateway defaults below. |
52
+ | `port` | `number` | `route` | TCP port for Route Mobile. Default: `8080`. |
53
+ | `protocol` | `'http' \| 'https'` | `route`, `nest` | HTTPS or HTTP to the provider API. |
54
+ | `clientId` | `string` | `hubtel` | Hubtel client ID. **Required** for `hubtel`. |
55
+ | `clientSecret` | `string` | `hubtel` | Hubtel client secret. **Required** for `hubtel`. |
56
+ | `apiKey` | `string` | `nest` | SMSOnlineGH API key (`Authorization: key …`). **Required** for `nest`. |
57
+ | `debug` | `boolean` | all | If `true`, the active gateway logs each request/response to the console (prefix `[unismsgateway:…]`). Off by default. |
57
58
 
58
59
 
59
60
  Validation runs in `smsPlatform` when the instance is constructed: missing required fields for the chosen `platformId` throw `Error` with a clear message.
@@ -80,9 +81,9 @@ Nothing is read from the environment unless **you** wire it. Required fields are
80
81
 
81
82
  | `platformId` | Required in `param` | Optional in `param` (defaults in this library) |
82
83
  | ------------ | -------------------------- | --------------------------------------------------------------------------------------------- |
83
- | `nest` | `apiKey` | `host` (default `api.smsonlinegh.com`), `protocol` (default `https`) |
84
- | `hubtel` | `clientId`, `clientSecret` | |
85
- | `route` | `username`, `password` | `host` (default `rslr.connectbind.com`), `protocol` (default `http`), `port` (default `8080`) |
84
+ | `nest` | `apiKey` | `host` (default `api.smsonlinegh.com`), `protocol` (default `https`), `debug` |
85
+ | `hubtel` | `clientId`, `clientSecret` | `debug` |
86
+ | `route` | `username`, `password` | `host` (default `rslr.connectbind.com`), `protocol` (default `http`), `port` (default `8080`), `debug` |
86
87
 
87
88
 
88
89
  **Suggested env names for your app** (optional; you can rename them). Credential keys (`NEST_`*, `HUBTEL_`*, `ROUTE_*`) match [live test](#live-integration-test-environment-variables) and `.env.example`. Platform selection differs: the test script requires `GATEWAY_PLATFORM` (or `TEST_ALL`); in your app you choose any name (the example below uses `SMS_PLATFORM_ID`):
@@ -340,7 +341,7 @@ console.log(balance.balance, balance.model);
340
341
  | Field | Type | Required | Description |
341
342
  | --------- | -------- | -------- | ---------------------------------------------------------------------- |
342
343
  | `From` | `string` | yes | Sender ID or label. |
343
- | `To` | `string | number` | yes |
344
+ | `To` | `string \| number` | yes |
344
345
  | `Content` | `string` | yes | Message body. |
345
346
  | `Type` | `number` | no | Message type; **nest** maps this to request body `type` (default `0`). |
346
347
 
@@ -357,9 +358,14 @@ Returns `Promise<SendResult>`. Optional `callback` is invoked with the same resu
357
358
  messageId?: string;
358
359
  data?: any;
359
360
  error?: string;
361
+ statusCode?: number; // HTTP status from the provider when available (nest, etc.)
360
362
  }
361
363
  ```
362
364
 
365
+ When `success` is `false`, always read **`error`** — it contains a human-readable reason (provider status codes, API handshake labels, network errors, and so on). For **`nest`**, if the API rejects the send but returns JSON, **`data`** is the **full parsed response body** (not only `response.data`), so you can inspect `handshake` and any provider fields. For HTTP errors, `data` may be the raw response body string. **`statusCode`** is set when the adapter knows the HTTP status (for example nest).
366
+
367
+ **Debugging:** Set `param.debug: true` when calling `init()` to print request URLs, bodies, and responses to the console. The live test script enables debug for the `nest` platform so you can trace `quickSend` and `getBalance` without changing application code.
368
+
363
369
  **Example**
364
370
 
365
371
  ```javascript
@@ -91,8 +91,10 @@ function testPlatform(platformId) {
91
91
  param.apiKey = requireEnv('NEST_API_KEY');
92
92
  if (env('NEST_HOST'))
93
93
  param.host = env('NEST_HOST');
94
- if (env('NEST_PROTOCOL'))
94
+ if (env('NEST_PROTOCOL')) {
95
95
  param.protocol = env('NEST_PROTOCOL');
96
+ }
97
+ param.debug = true;
96
98
  break;
97
99
  case 'hubtel':
98
100
  param.clientId = requireEnv('HUBTEL_CLIENT_ID');
@@ -105,11 +107,12 @@ function testPlatform(platformId) {
105
107
  param.host = env('ROUTE_HOST');
106
108
  if (env('ROUTE_PORT'))
107
109
  param.port = Number(env('ROUTE_PORT'));
108
- if (env('ROUTE_PROTOCOL'))
110
+ if (env('ROUTE_PROTOCOL')) {
109
111
  param.protocol = env('ROUTE_PROTOCOL');
112
+ }
110
113
  break;
111
114
  }
112
- platform = (0, lib_1.init)({ platformId, param: param });
115
+ platform = (0, lib_1.init)({ platformId, param });
113
116
  pass(`Initialized ${platformId} platform`);
114
117
  }));
115
118
  // 2. Balance check (only nest and hubtel expose getBalance)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unismsgateway",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "A unified SMS gateway library that brings access to multiple SMS gateways under a single API",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",