uz-sms-glmv 0.1.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 +21 -0
- package/README.md +372 -0
- package/dist/index.cjs +480 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +150 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +448 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 golibnarzullayev
|
|
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,372 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# uz-sms-glmv
|
|
4
|
+
|
|
5
|
+
**Unified SMS client for Uzbekistan providers â one API for [Eskiz](https://eskiz.uz), [Play Mobile](https://playmobile.uz), [SMS.uz](https://sms.uz), and [Octotelecom](https://octotelecom.uz).**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/uz-sms-glmv)
|
|
8
|
+
[](https://www.npmjs.com/package/uz-sms-glmv)
|
|
9
|
+
[](https://github.com/golibnarzullayev/uz-sms/actions)
|
|
10
|
+
[](./LICENSE)
|
|
11
|
+
[](https://www.npmjs.com/package/uz-sms-glmv)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
Swap SMS providers by changing one config field. Every provider returns the
|
|
18
|
+
same result shape, throws the same typed errors, and accepts phone numbers in
|
|
19
|
+
any common Uzbek format.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
const sms = createSmsClient({ provider: "eskiz", eskiz: { /* ... */ } });
|
|
23
|
+
await sms.send({ to: "+998 90 123 45 67", text: "Salom!" });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- ðą **Four providers, one API** â Eskiz, Play Mobile, SMS.uz, Octotelecom behind a single interface.
|
|
29
|
+
- ð **Drop-in swappable** â change `provider`, keep the rest of your code.
|
|
30
|
+
- ð§Đ **Fully typed** â ships `.d.ts`, strict mode, exhaustive provider checks.
|
|
31
|
+
- ðĶ **ESM + CJS** â works with `import` and `require`.
|
|
32
|
+
- âïļ **Phone normalization** â `+998 90 âĶ`, `998âĶ`, `(90) 123-45-67`, 9-digit â all accepted.
|
|
33
|
+
- ðĄïļ **Typed errors** â `SmsError`, `SmsConfigError`, `SmsProviderError` with provider/status/raw.
|
|
34
|
+
- âąïļ **Per-request timeout** â `AbortController`-based, configurable.
|
|
35
|
+
- ðŠķ **Zero runtime dependencies** â just the platform `fetch`.
|
|
36
|
+
|
|
37
|
+
## Table of contents
|
|
38
|
+
|
|
39
|
+
- [Install](#install)
|
|
40
|
+
- [Quick start](#quick-start)
|
|
41
|
+
- [Providers](#providers)
|
|
42
|
+
- [Eskiz](#eskiz)
|
|
43
|
+
- [Play Mobile](#play-mobile)
|
|
44
|
+
- [SMS.uz](#smsuz)
|
|
45
|
+
- [Octotelecom](#octotelecom)
|
|
46
|
+
- [Phone numbers](#phone-numbers)
|
|
47
|
+
- [API reference](#api-reference)
|
|
48
|
+
- [Error handling](#error-handling)
|
|
49
|
+
- [Recipes](#recipes)
|
|
50
|
+
- [FAQ](#faq)
|
|
51
|
+
- [Contributing](#contributing)
|
|
52
|
+
- [License](#license)
|
|
53
|
+
|
|
54
|
+
## Install
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install uz-sms-glmv
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pnpm add uz-sms-glmv
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
yarn add uz-sms-glmv
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
> **Requirements:** Node.js >= 18 (relies on the global `fetch`).
|
|
69
|
+
|
|
70
|
+
## Quick start
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { createSmsClient } from "uz-sms-glmv";
|
|
74
|
+
|
|
75
|
+
const sms = createSmsClient({
|
|
76
|
+
provider: "eskiz",
|
|
77
|
+
eskiz: {
|
|
78
|
+
email: "you@example.uz",
|
|
79
|
+
password: "secret",
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const result = await sms.send({
|
|
84
|
+
to: "+998 90 123 45 67",
|
|
85
|
+
text: "Salom!",
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
console.log(result);
|
|
89
|
+
// {
|
|
90
|
+
// provider: "eskiz",
|
|
91
|
+
// messageId: "4385062",
|
|
92
|
+
// status: "sent",
|
|
93
|
+
// raw: { ... }
|
|
94
|
+
// }
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
CommonJS works too:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
const { createSmsClient } = require("uz-sms-glmv");
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Providers
|
|
104
|
+
|
|
105
|
+
| Provider | `provider` value | Auth | `getBalance()` | `callbackUrl` | Send status |
|
|
106
|
+
| ------------ | ---------------- | ------------ | :------------: | :-----------: | ----------- |
|
|
107
|
+
| Eskiz | `"eskiz"` | Bearer token | â
| â
| `sent` |
|
|
108
|
+
| Play Mobile | `"playmobile"` | HTTP Basic | â | â | `queued` |
|
|
109
|
+
| SMS.uz | `"smsuz"` | Query params | â | â | `sent` |
|
|
110
|
+
| Octotelecom | `"octotelecom"` | HTTP Basic | â | â
| `sent` |
|
|
111
|
+
|
|
112
|
+
### Eskiz
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
const sms = createSmsClient({
|
|
116
|
+
provider: "eskiz",
|
|
117
|
+
eskiz: {
|
|
118
|
+
email: "you@example.uz",
|
|
119
|
+
password: "secret",
|
|
120
|
+
from: "4546", // optional â 4546 is the Eskiz test sender
|
|
121
|
+
baseUrl: "https://notify.eskiz.uz/api", // optional override
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
await sms.send({
|
|
126
|
+
to: "998901234567",
|
|
127
|
+
text: "Your code: 1234",
|
|
128
|
+
callbackUrl: "https://your-app.uz/sms/dlr", // delivery report webhook
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const balance = await sms.getBalance(); // UZS
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The bearer token is minted on demand, cached, and **refreshed automatically on a 401** â you never manage tokens.
|
|
135
|
+
|
|
136
|
+
### Play Mobile
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
const sms = createSmsClient({
|
|
140
|
+
provider: "playmobile",
|
|
141
|
+
playmobile: {
|
|
142
|
+
login: "your-login",
|
|
143
|
+
password: "secret",
|
|
144
|
+
from: "ALPHANAME", // registered originator
|
|
145
|
+
baseUrl: "https://send.smsxabar.uz/broker-api", // optional override
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
await sms.send({ to: "998901234567", text: "Salom!" });
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Play Mobile accepts messages into a queue, so `result.status` is `"queued"`.
|
|
153
|
+
|
|
154
|
+
### SMS.uz
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
const sms = createSmsClient({
|
|
158
|
+
provider: "smsuz",
|
|
159
|
+
smsuz: {
|
|
160
|
+
login: "your-login",
|
|
161
|
+
password: "secret",
|
|
162
|
+
from: "ALPHANAME", // optional
|
|
163
|
+
// SMS.uz query-param names vary per account â override if yours differ:
|
|
164
|
+
params: {
|
|
165
|
+
phone: "number",
|
|
166
|
+
text: "msg",
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
await sms.send({ to: "998901234567", text: "Salom!" });
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
SMS.uz is a plain HTTP GET gateway. Defaults match the common
|
|
175
|
+
`login/password/phone/text/from` shape; use `params` to remap field names.
|
|
176
|
+
|
|
177
|
+
### Octotelecom
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
const sms = createSmsClient({
|
|
181
|
+
provider: "octotelecom",
|
|
182
|
+
octotelecom: {
|
|
183
|
+
clientId: "your-client-id",
|
|
184
|
+
username: "your-username",
|
|
185
|
+
password: "secret",
|
|
186
|
+
from: "ALPHANAME", // default alpha-name / sender
|
|
187
|
+
callbackUrl: "https://your-app.uz/dlr", // optional delivery-report webhook
|
|
188
|
+
tag: "uz-sms", // optional, default "uz-sms"
|
|
189
|
+
ttl: 300, // optional message TTL in seconds
|
|
190
|
+
baseUrl: "https://api.octotelecom.uz", // optional override
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
await sms.send({ to: "998901234567", text: "Salom!" });
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Octotelecom uses the JSONv2 endpoint `{baseUrl}/{clientId}/json2/simple` with
|
|
198
|
+
HTTP Basic auth. It may return HTTP 200 with an `error_text` field â that case
|
|
199
|
+
is detected and surfaced as `SmsProviderError`.
|
|
200
|
+
|
|
201
|
+
## Phone numbers
|
|
202
|
+
|
|
203
|
+
`to` is normalized before every request. All of these resolve to `998901234567`:
|
|
204
|
+
|
|
205
|
+
| Input | Normalized |
|
|
206
|
+
| ---------------------- | -------------- |
|
|
207
|
+
| `+998 90 123 45 67` | `998901234567` |
|
|
208
|
+
| `998901234567` | `998901234567` |
|
|
209
|
+
| `(90) 123-45-67` | `998901234567` |
|
|
210
|
+
| `901234567` | `998901234567` |
|
|
211
|
+
|
|
212
|
+
A 9-digit national number is assumed Uzbek and prefixed with `998`. Anything
|
|
213
|
+
else throws [`SmsError`](#error-handling).
|
|
214
|
+
|
|
215
|
+
`normalizePhone` is exported standalone for form validation:
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
import { normalizePhone } from "uz-sms-glmv";
|
|
219
|
+
|
|
220
|
+
normalizePhone("+998 90 123 45 67"); // "998901234567"
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## API reference
|
|
224
|
+
|
|
225
|
+
### `createSmsClient(config): SmsClient`
|
|
226
|
+
|
|
227
|
+
Builds a client bound to exactly one provider. Throws `SmsConfigError` if the
|
|
228
|
+
matching provider config block is missing.
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
interface SmsClientConfig {
|
|
232
|
+
provider: "eskiz" | "playmobile" | "smsuz" | "octotelecom";
|
|
233
|
+
timeoutMs?: number; // per-request timeout, default 15000
|
|
234
|
+
eskiz?: EskizConfig;
|
|
235
|
+
playmobile?: PlayMobileConfig;
|
|
236
|
+
smsuz?: SmsUzConfig;
|
|
237
|
+
octotelecom?: OctotelecomConfig;
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### `SmsClient`
|
|
242
|
+
|
|
243
|
+
| Member | Returns | Notes |
|
|
244
|
+
| --------------------------- | ------------------------ | ------------------------------------------------------------ |
|
|
245
|
+
| `client.providerName` | `ProviderName` | The active provider. |
|
|
246
|
+
| `client.send(params)` | `Promise<SendSmsResult>` | Sends one SMS. |
|
|
247
|
+
| `client.getBalance()` | `Promise<number>` | Balance in UZS. Throws `SmsConfigError` if unsupported. |
|
|
248
|
+
|
|
249
|
+
#### `send(params)`
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
interface SendSmsParams {
|
|
253
|
+
to: string; // any common Uzbek format â normalized internally
|
|
254
|
+
text: string; // message body
|
|
255
|
+
from?: string; // overrides the provider's configured sender
|
|
256
|
+
callbackUrl?: string; // delivery-report webhook (Eskiz only)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
interface SendSmsResult {
|
|
260
|
+
provider: "eskiz" | "playmobile" | "smsuz" | "octotelecom";
|
|
261
|
+
messageId?: string; // provider-side id, when available
|
|
262
|
+
status: "sent" | "queued" | "failed";
|
|
263
|
+
raw: unknown; // untouched provider response
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### `normalizePhone(input): string`
|
|
268
|
+
|
|
269
|
+
Normalizes an Uzbek number to `998XXXXXXXXX`. Throws `SmsError` on invalid input.
|
|
270
|
+
|
|
271
|
+
## Error handling
|
|
272
|
+
|
|
273
|
+
Every failure is a typed subclass of `SmsError`.
|
|
274
|
+
|
|
275
|
+
| Error | Thrown when |
|
|
276
|
+
| ------------------ | ---------------------------------------------------------------- |
|
|
277
|
+
| `SmsError` | Base class. Also thrown directly for invalid phone numbers. |
|
|
278
|
+
| `SmsConfigError` | Missing credentials, unknown provider, unsupported operation. |
|
|
279
|
+
| `SmsProviderError` | Provider rejected the request, timed out, or a network failure. |
|
|
280
|
+
|
|
281
|
+
`SmsProviderError` carries debugging context:
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
import { SmsProviderError } from "uz-sms-glmv";
|
|
285
|
+
|
|
286
|
+
try {
|
|
287
|
+
await sms.send({ to: "998901234567", text: "hi" });
|
|
288
|
+
} catch (err) {
|
|
289
|
+
if (err instanceof SmsProviderError) {
|
|
290
|
+
console.error(err.provider); // "eskiz"
|
|
291
|
+
console.error(err.status); // 422 (when from an HTTP response)
|
|
292
|
+
console.error(err.raw); // raw provider payload
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Recipes
|
|
298
|
+
|
|
299
|
+
### Choose a provider from an environment variable
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
import { createSmsClient, type ProviderName } from "uz-sms-glmv";
|
|
303
|
+
|
|
304
|
+
const sms = createSmsClient({
|
|
305
|
+
provider: process.env.SMS_PROVIDER as ProviderName,
|
|
306
|
+
eskiz: { email: process.env.ESKIZ_EMAIL!, password: process.env.ESKIZ_PASSWORD! },
|
|
307
|
+
playmobile: {
|
|
308
|
+
login: process.env.PM_LOGIN!,
|
|
309
|
+
password: process.env.PM_PASSWORD!,
|
|
310
|
+
from: process.env.PM_FROM!,
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Express OTP endpoint
|
|
316
|
+
|
|
317
|
+
```ts
|
|
318
|
+
import express from "express";
|
|
319
|
+
import { createSmsClient, SmsError } from "uz-sms-glmv";
|
|
320
|
+
|
|
321
|
+
const sms = createSmsClient({
|
|
322
|
+
provider: "eskiz",
|
|
323
|
+
eskiz: { email: process.env.ESKIZ_EMAIL!, password: process.env.ESKIZ_PASSWORD! },
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
app.post("/otp", async (req, res) => {
|
|
327
|
+
const code = String(Math.floor(100000 + Math.random() * 900000));
|
|
328
|
+
try {
|
|
329
|
+
await sms.send({ to: req.body.phone, text: `Code: ${code}` });
|
|
330
|
+
res.json({ ok: true });
|
|
331
|
+
} catch (err) {
|
|
332
|
+
const message = err instanceof SmsError ? err.message : "SMS failed";
|
|
333
|
+
res.status(502).json({ ok: false, error: message });
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## FAQ
|
|
339
|
+
|
|
340
|
+
**Does it send to one number at a time?**
|
|
341
|
+
Yes â `send()` sends a single message. Loop for bulk sends.
|
|
342
|
+
|
|
343
|
+
**Can I use one client for multiple providers?**
|
|
344
|
+
No. A client is bound to one provider; create one client per provider and pick at call time.
|
|
345
|
+
|
|
346
|
+
**Which Node versions are supported?**
|
|
347
|
+
Node 18, 20, and 22 are tested in CI. Node < 18 lacks the global `fetch`.
|
|
348
|
+
|
|
349
|
+
**Does it work in the browser / edge runtimes?**
|
|
350
|
+
The code only uses `fetch`, `URL`, and `Buffer` (Play Mobile auth). Node-like
|
|
351
|
+
runtimes with `Buffer` work; pure-browser use is not a supported target.
|
|
352
|
+
|
|
353
|
+
## Contributing
|
|
354
|
+
|
|
355
|
+
This repo uses [pnpm](https://pnpm.io).
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
git clone https://github.com/golibnarzullayev/uz-sms.git
|
|
359
|
+
cd uz-sms
|
|
360
|
+
pnpm install
|
|
361
|
+
|
|
362
|
+
pnpm run typecheck # tsc --noEmit
|
|
363
|
+
pnpm test # build, then node --test
|
|
364
|
+
pnpm run build # tsup â dist/ (ESM + CJS + d.ts)
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Issues and PRs welcome at
|
|
368
|
+
[github.com/golibnarzullayev/uz-sms](https://github.com/golibnarzullayev/uz-sms).
|
|
369
|
+
|
|
370
|
+
## License
|
|
371
|
+
|
|
372
|
+
[MIT](./LICENSE) ÂĐ golibnarzullayev
|