unismsgateway 1.4.0 → 1.5.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/README.md +24 -11
- package/dist/src/lib/lib.d.ts +2 -2
- package/dist/src/lib/lib.js +2 -1
- package/dist/src/lib/nest-gateway.js +5 -0
- package/dist/src/lib/platform.d.ts +2 -2
- package/dist/src/lib/platform.js +3 -1
- package/dist/src/lib/types.d.ts +17 -0
- package/dist/src/lib/types.js +40 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -306,7 +306,7 @@ const gateway = unisms.init({
|
|
|
306
306
|
| `protocol` | `'https'` |
|
|
307
307
|
|
|
308
308
|
|
|
309
|
-
Requests use `POST` to path `**/v5/<endpoint>`** (e.g. send: `message/sms/send`, balance: `account/balance`). Authorization header: `Authorization: key <apiKey>`.
|
|
309
|
+
Requests use `POST` to path `**/v5/<endpoint>`** (e.g. send: `message/sms/send`, balance: `account/balance`). Authorization header: `Authorization: key <apiKey>`. Each request opens a fresh connection (keep-alive pooling is disabled) to prevent stale-socket errors in long-running processes.
|
|
310
310
|
|
|
311
311
|
```javascript
|
|
312
312
|
const gateway = unisms.init({
|
|
@@ -337,18 +337,18 @@ console.log(balance.balance, balance.model);
|
|
|
337
337
|
|
|
338
338
|
### `QuickSendParams`
|
|
339
339
|
|
|
340
|
-
|
|
341
340
|
| Field | Type | Required | Description |
|
|
342
341
|
| --------- | -------- | -------- | ---------------------------------------------------------------------- |
|
|
343
342
|
| `From` | `string` | yes | Sender ID or label. |
|
|
344
|
-
| `To` | `string \| number` | yes
|
|
343
|
+
| `To` | `string \| number` | yes | Recipient MSISDN or number. |
|
|
345
344
|
| `Content` | `string` | yes | Message body. |
|
|
346
345
|
| `Type` | `number` | no | Message type; **nest** maps this to request body `type` (default `0`). |
|
|
347
346
|
|
|
347
|
+
**camelCase:** You may pass **`from`**, **`to`**, **`content`**, and **`type`** instead of the PascalCase names above. Many JavaScript projects use camelCase; if you pass only `content` and `Content` is missing, the SMSOnlineGH (`nest`) API receives no message body and may return handshake **1305** (`MV_ERR_MESSAGE` — missing or invalid message body). The library normalizes both conventions before calling the gateway.
|
|
348
348
|
|
|
349
349
|
### `quickSend(params, callback?)`
|
|
350
350
|
|
|
351
|
-
Returns `Promise<SendResult>`. Optional `callback` is invoked with the same result when the promise completes.
|
|
351
|
+
Returns `Promise<SendResult>`. Optional `callback` is invoked with the same result when the promise completes. The `params` argument accepts **`QuickSendParams`** (PascalCase) or **`QuickSendParamsCamel`** (`{ from, to, content, type? }`). See **`normalizeQuickSendParams`** in the public API if you need the same mapping outside `quickSend`.
|
|
352
352
|
|
|
353
353
|
`**SendResult`:**
|
|
354
354
|
|
|
@@ -438,12 +438,15 @@ Full variable reference (selection, per-gateway credentials, live send): [Live i
|
|
|
438
438
|
## API reference
|
|
439
439
|
|
|
440
440
|
|
|
441
|
-
| Export
|
|
442
|
-
|
|
|
443
|
-
| `init(settings)`
|
|
444
|
-
| `getSmsPlatform()`
|
|
445
|
-
| `reset()`
|
|
446
|
-
| `smsPlatform`
|
|
441
|
+
| Export | Description |
|
|
442
|
+
| -------------------------- | -------------------------------------------------------------------- |
|
|
443
|
+
| `init(settings)` | Create and register the singleton `smsPlatform`, return it. |
|
|
444
|
+
| `getSmsPlatform()` | Current `smsPlatform` or `null` after `reset()` and before `init()`. |
|
|
445
|
+
| `reset()` | Clear the singleton. |
|
|
446
|
+
| `smsPlatform` | Class type for typing/advanced use. |
|
|
447
|
+
| `QuickSendParamsInput` | Union: PascalCase `QuickSendParams` or camelCase `QuickSendParamsCamel`. |
|
|
448
|
+
| `QuickSendParamsCamel` | `{ from, to, content, type? }` for `quickSend`. |
|
|
449
|
+
| `normalizeQuickSendParams` | Maps input to canonical `QuickSendParams` (throws if body/sender missing). |
|
|
447
450
|
|
|
448
451
|
|
|
449
452
|
`**smsPlatform` instance methods**
|
|
@@ -452,10 +455,20 @@ Full variable reference (selection, per-gateway credentials, live send): [Live i
|
|
|
452
455
|
| Method | Returns | Description |
|
|
453
456
|
| ------------------------------ | --------------------- | ---------------------------------------------- |
|
|
454
457
|
| `init()` | `ISmsGateway` | Returns `this` (facade). |
|
|
455
|
-
| `quickSend(params, callback?)` | `Promise<SendResult>` |
|
|
458
|
+
| `quickSend(params, callback?)` | `Promise<SendResult>` | Normalizes PascalCase or camelCase params, then delegates to the active gateway. |
|
|
456
459
|
| `getGateway()` | `ISmsGateway` | Underlying adapter (for nest: `getBalance()`). |
|
|
457
460
|
|
|
458
461
|
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
## Changelog
|
|
465
|
+
|
|
466
|
+
### 1.5.1
|
|
467
|
+
- **Fix (`nest` / all gateways):** `quickSend` now accepts **camelCase** (`from`, `to`, `content`, `type`) as well as PascalCase (`From`, `To`, `Content`, `Type`). Passing only camelCase previously left `Content` undefined, so the nest JSON body omitted `text` and the API returned handshake **1305** (missing or invalid message body). Validation errors throw clear messages when body or sender is empty after trim.
|
|
468
|
+
|
|
469
|
+
### 1.5.0
|
|
470
|
+
- **Fix (`nest`):** `quickSend` now reliably works in long-running processes (servers, workers). Node's global HTTP agent reuses keep-alive sockets across calls; when the provider closes an idle socket server-side, the next `quickSend` that writes a request body received `write ECONNABORTED` while `getBalance` (no body) appeared to work fine. Fixed by setting `agent: false` on each request so every call opens a fresh connection rather than reusing a potentially stale one from the pool.
|
|
471
|
+
|
|
459
472
|
---
|
|
460
473
|
|
|
461
474
|
## License
|
package/dist/src/lib/lib.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { smsPlatform, IgatewaySettings, IgatewayParam, PlatformId, QuickSendParams, SendResult, ISmsGateway } from './platform';
|
|
1
|
+
import { smsPlatform, IgatewaySettings, IgatewayParam, PlatformId, QuickSendParams, QuickSendParamsInput, QuickSendParamsCamel, normalizeQuickSendParams, SendResult, ISmsGateway } from './platform';
|
|
2
2
|
export declare function init(settings: IgatewaySettings): smsPlatform;
|
|
3
3
|
export declare function getSmsPlatform(): smsPlatform | null;
|
|
4
4
|
export declare function reset(): void;
|
|
5
|
-
export { smsPlatform, IgatewaySettings, IgatewayParam, PlatformId, QuickSendParams, SendResult, ISmsGateway };
|
|
5
|
+
export { smsPlatform, IgatewaySettings, IgatewayParam, PlatformId, QuickSendParams, QuickSendParamsInput, QuickSendParamsCamel, normalizeQuickSendParams, SendResult, ISmsGateway };
|
package/dist/src/lib/lib.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.smsPlatform = exports.reset = exports.getSmsPlatform = exports.init = void 0;
|
|
3
|
+
exports.normalizeQuickSendParams = exports.smsPlatform = exports.reset = exports.getSmsPlatform = exports.init = void 0;
|
|
4
4
|
const platform_1 = require("./platform");
|
|
5
5
|
Object.defineProperty(exports, "smsPlatform", { enumerable: true, get: function () { return platform_1.smsPlatform; } });
|
|
6
|
+
Object.defineProperty(exports, "normalizeQuickSendParams", { enumerable: true, get: function () { return platform_1.normalizeQuickSendParams; } });
|
|
6
7
|
let smsPlatformInstance = null;
|
|
7
8
|
function init(settings) {
|
|
8
9
|
smsPlatformInstance = new platform_1.smsPlatform(settings);
|
|
@@ -67,6 +67,11 @@ class NestSmsGateway {
|
|
|
67
67
|
port,
|
|
68
68
|
path: `/v5/${endpoint}`,
|
|
69
69
|
method: 'POST',
|
|
70
|
+
// Disable keep-alive connection pooling. Node's global agent reuses
|
|
71
|
+
// sockets across calls; when the server closes an idle socket server-side
|
|
72
|
+
// the next write (i.e. the request body in quickSend) gets ECONNABORTED.
|
|
73
|
+
// agent:false forces a fresh connection for every request.
|
|
74
|
+
agent: false,
|
|
70
75
|
headers: {
|
|
71
76
|
'Host': hostname,
|
|
72
77
|
'Content-Type': 'application/json',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IgatewaySettings, IgatewayParam, ISmsGateway, ISmsGatewayDelegate,
|
|
1
|
+
import { IgatewaySettings, IgatewayParam, ISmsGateway, ISmsGatewayDelegate, QuickSendParamsInput, SendResult } from './types';
|
|
2
2
|
export * from './types';
|
|
3
3
|
export declare class smsPlatform implements ISmsGateway {
|
|
4
4
|
private _settings;
|
|
@@ -7,7 +7,7 @@ export declare class smsPlatform implements ISmsGateway {
|
|
|
7
7
|
private validateSettings;
|
|
8
8
|
private createGateway;
|
|
9
9
|
init(): ISmsGateway;
|
|
10
|
-
quickSend(param:
|
|
10
|
+
quickSend(param: QuickSendParamsInput, callback?: Function): Promise<SendResult>;
|
|
11
11
|
getGateway(): ISmsGatewayDelegate;
|
|
12
12
|
}
|
|
13
13
|
export { IgatewaySettings, IgatewayParam };
|
package/dist/src/lib/platform.js
CHANGED
|
@@ -14,6 +14,7 @@ exports.smsPlatform = void 0;
|
|
|
14
14
|
const nest_gateway_1 = require("./nest-gateway");
|
|
15
15
|
const hubtel_gateway_1 = require("./hubtel-gateway");
|
|
16
16
|
const route_gateway_1 = require("./route-gateway");
|
|
17
|
+
const types_1 = require("./types");
|
|
17
18
|
__exportStar(require("./types"), exports);
|
|
18
19
|
const GATEWAY_CONFIGS = {
|
|
19
20
|
route: { requiresUsernamePassword: true },
|
|
@@ -79,7 +80,8 @@ class smsPlatform {
|
|
|
79
80
|
if (!this._gateway) {
|
|
80
81
|
throw new Error('Gateway not initialized. Call init() first.');
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
const normalized = (0, types_1.normalizeQuickSendParams)(param);
|
|
84
|
+
return this._gateway.quickSend(normalized, callback);
|
|
83
85
|
}
|
|
84
86
|
getGateway() {
|
|
85
87
|
return this._gateway;
|
package/dist/src/lib/types.d.ts
CHANGED
|
@@ -5,6 +5,23 @@ export interface QuickSendParams {
|
|
|
5
5
|
Content: string;
|
|
6
6
|
Type?: number;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* camelCase variant of {@link QuickSendParams}. Plain JS consumers often pass
|
|
10
|
+
* `{ from, to, content }`; without normalization those would not read `Content`
|
|
11
|
+
* and the nest API would receive no message body (e.g. handshake 1305).
|
|
12
|
+
*/
|
|
13
|
+
export interface QuickSendParamsCamel {
|
|
14
|
+
from: string;
|
|
15
|
+
to: string | number;
|
|
16
|
+
content: string;
|
|
17
|
+
type?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare type QuickSendParamsInput = QuickSendParams | QuickSendParamsCamel;
|
|
20
|
+
/**
|
|
21
|
+
* Maps PascalCase or camelCase quick-send fields to {@link QuickSendParams}.
|
|
22
|
+
* PascalCase wins when both are present.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeQuickSendParams(params: QuickSendParamsInput): QuickSendParams;
|
|
8
25
|
export interface SendResult {
|
|
9
26
|
success: boolean;
|
|
10
27
|
messageId?: string;
|
package/dist/src/lib/types.js
CHANGED
|
@@ -1,2 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeQuickSendParams = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Maps PascalCase or camelCase quick-send fields to {@link QuickSendParams}.
|
|
6
|
+
* PascalCase wins when both are present.
|
|
7
|
+
*/
|
|
8
|
+
function normalizeQuickSendParams(params) {
|
|
9
|
+
var _a, _b, _c, _d;
|
|
10
|
+
const p = params;
|
|
11
|
+
const from = (_a = p.From) !== null && _a !== void 0 ? _a : p.from;
|
|
12
|
+
const to = (_b = p.To) !== null && _b !== void 0 ? _b : p.to;
|
|
13
|
+
const content = (_c = p.Content) !== null && _c !== void 0 ? _c : p.content;
|
|
14
|
+
const type = (_d = p.Type) !== null && _d !== void 0 ? _d : p.type;
|
|
15
|
+
const contentStr = content == null ? '' : String(content);
|
|
16
|
+
const trimmedBody = contentStr.trim();
|
|
17
|
+
if (trimmedBody === '') {
|
|
18
|
+
throw new Error('quickSend: message body is missing. Pass Content or content with a non-empty string.');
|
|
19
|
+
}
|
|
20
|
+
const fromStr = from == null ? '' : String(from).trim();
|
|
21
|
+
if (fromStr === '') {
|
|
22
|
+
throw new Error('quickSend: sender is missing. Pass From or from with a non-empty string.');
|
|
23
|
+
}
|
|
24
|
+
if (to === null || to === undefined) {
|
|
25
|
+
throw new Error('quickSend: recipient is missing. Pass To or to.');
|
|
26
|
+
}
|
|
27
|
+
const toVal = typeof to === 'number' ? to : String(to).trim();
|
|
28
|
+
let typeNum;
|
|
29
|
+
if (type !== undefined && type !== null) {
|
|
30
|
+
const n = Number(type);
|
|
31
|
+
if (!Number.isNaN(n)) {
|
|
32
|
+
typeNum = n;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
From: fromStr,
|
|
37
|
+
To: toVal,
|
|
38
|
+
Content: trimmedBody,
|
|
39
|
+
Type: typeNum
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.normalizeQuickSendParams = normalizeQuickSendParams;
|
package/package.json
CHANGED