vesal 0.1.0 → 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/README.md +472 -0
- package/dist/vesal.cjs +1 -1
- package/dist/vesal.cjs.map +1 -1
- package/dist/vesal.d.ts +1 -1
- package/dist/vesal.mjs +1 -1
- package/dist/vesal.mjs.map +1 -1
- package/dist/vesal.umd.js +1 -1
- package/dist/vesal.umd.js.map +1 -1
- package/package.json +91 -89
- package/src/vesal.ts +0 -2
package/README.md
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
# Vesal
|
|
2
|
+
|
|
3
|
+
A modern TypeScript/JavaScript client for the Armaghan Vesal SMS API.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/vesal)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🚀 Modern ESM/CommonJS support
|
|
11
|
+
- 📘 Full TypeScript support with type definitions
|
|
12
|
+
- 🔄 Promise-based API
|
|
13
|
+
- ✨ Simple and intuitive interface
|
|
14
|
+
- 🛡️ Built-in error handling
|
|
15
|
+
- 📱 Send SMS (one-to-many and many-to-many)
|
|
16
|
+
- 📊 Check message status
|
|
17
|
+
- 📥 Receive messages
|
|
18
|
+
- 👤 Account management
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install vesal
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn add vesal
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pnpm add vesal
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { Vesal } from 'vesal';
|
|
38
|
+
|
|
39
|
+
// Initialize the client
|
|
40
|
+
const client = new Vesal(
|
|
41
|
+
'your-username',
|
|
42
|
+
'your-password',
|
|
43
|
+
'your-sender-number'
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// Send a simple SMS
|
|
47
|
+
const result = await client.Send({
|
|
48
|
+
recipients: '09123456789',
|
|
49
|
+
messages: 'Hello, World!'
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
console.log(`Sent ${result.count.success} messages successfully`);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API Reference
|
|
56
|
+
|
|
57
|
+
### Constructor
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
new Vesal(username: string, password: string, from: string)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Creates a new Vesal client instance.
|
|
64
|
+
|
|
65
|
+
**Parameters:**
|
|
66
|
+
- `username` - Your Vesal API username
|
|
67
|
+
- `password` - Your Vesal API password
|
|
68
|
+
- `from` - Default sender number
|
|
69
|
+
|
|
70
|
+
**Example:**
|
|
71
|
+
```typescript
|
|
72
|
+
const client = new Vesal('myusername', 'mypassword', '50002710000000');
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
### Send()
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
async Send({
|
|
81
|
+
recipients,
|
|
82
|
+
messages,
|
|
83
|
+
from
|
|
84
|
+
}: {
|
|
85
|
+
recipients: string | string[];
|
|
86
|
+
messages: string | string[];
|
|
87
|
+
from?: string | string[];
|
|
88
|
+
}): Promise<IVesalResponse_Send_WithCount>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Sends SMS messages to one or multiple recipients.
|
|
92
|
+
|
|
93
|
+
**Parameters:**
|
|
94
|
+
- `recipients` - Phone number(s) to send to (e.g., `'09123456789'` or `['09123456789', '09987654321']`)
|
|
95
|
+
- `messages` - Message content(s) to send
|
|
96
|
+
- `from` - (Optional) Sender number(s), defaults to the number set in constructor
|
|
97
|
+
|
|
98
|
+
**Return Value:**
|
|
99
|
+
```typescript
|
|
100
|
+
{
|
|
101
|
+
references: (number | string)[], // Reference IDs for sent messages
|
|
102
|
+
count: {
|
|
103
|
+
success: number, // Number of successfully sent messages
|
|
104
|
+
fail: number // Number of failed messages
|
|
105
|
+
},
|
|
106
|
+
errorModel: {
|
|
107
|
+
errorCode: number,
|
|
108
|
+
timestamp: string | number | null
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Send Methods
|
|
114
|
+
|
|
115
|
+
**One-to-Many (Same message to multiple recipients):**
|
|
116
|
+
```typescript
|
|
117
|
+
await client.Send({
|
|
118
|
+
recipients: ['09123456789', '09987654321'],
|
|
119
|
+
messages: 'Hello everyone!'
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Many-to-Many (Different messages to different recipients):**
|
|
124
|
+
```typescript
|
|
125
|
+
await client.Send({
|
|
126
|
+
recipients: ['09123456789', '09987654321'],
|
|
127
|
+
messages: ['Hello John!', 'Hello Jane!']
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Single message with custom sender:**
|
|
132
|
+
```typescript
|
|
133
|
+
await client.Send({
|
|
134
|
+
recipients: '09123456789',
|
|
135
|
+
messages: 'Your verification code is 1234',
|
|
136
|
+
from: '50002710000001'
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
### GetMessageStatus()
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
async GetMessageStatus(referencesIds: number[]): Promise<IVesalResponse_MessageState>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Gets the delivery status of sent messages.
|
|
149
|
+
|
|
150
|
+
**Parameters:**
|
|
151
|
+
- `referencesIds` - Array of reference IDs returned from `Send()`
|
|
152
|
+
|
|
153
|
+
**Return Value:**
|
|
154
|
+
```typescript
|
|
155
|
+
{
|
|
156
|
+
states: Array<{
|
|
157
|
+
id: number, // Reference ID
|
|
158
|
+
state: number // Status code (see Message States below)
|
|
159
|
+
}>,
|
|
160
|
+
errorModel: {
|
|
161
|
+
errorCode: number,
|
|
162
|
+
timestamp: string | number | null
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Example:**
|
|
168
|
+
```typescript
|
|
169
|
+
const sendResult = await client.Send({
|
|
170
|
+
recipients: '09123456789',
|
|
171
|
+
messages: 'Test message'
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// Wait a bit for delivery
|
|
175
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
176
|
+
|
|
177
|
+
const statusResult = await client.GetMessageStatus(sendResult.references);
|
|
178
|
+
console.log(statusResult.states);
|
|
179
|
+
// Output: [{ id: 123456, state: 2 }]
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
### GetReceivedMessages()
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
async GetReceivedMessages(): Promise<IVesalResponse_ReceivedMessages>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Retrieves all received messages.
|
|
191
|
+
|
|
192
|
+
**Return Value:**
|
|
193
|
+
```typescript
|
|
194
|
+
{
|
|
195
|
+
messageModels: Array<{
|
|
196
|
+
originator: string, // Sender's phone number
|
|
197
|
+
destination: string, // Your receiving number
|
|
198
|
+
content: string // Message content
|
|
199
|
+
}>,
|
|
200
|
+
errorModel: {
|
|
201
|
+
errorCode: number,
|
|
202
|
+
timestamp: string | number | null
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Example:**
|
|
208
|
+
```typescript
|
|
209
|
+
const received = await client.GetReceivedMessages();
|
|
210
|
+
received.messageModels.forEach(msg => {
|
|
211
|
+
console.log(`From: ${msg.originator}`);
|
|
212
|
+
console.log(`To: ${msg.destination}`);
|
|
213
|
+
console.log(`Message: ${msg.content}`);
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### GetReceivedMessagesCount()
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
async GetReceivedMessagesCount(): Promise<IVesalResponse_ReceivedMessagesCount>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Gets the count of received messages.
|
|
226
|
+
|
|
227
|
+
**Return Value:**
|
|
228
|
+
```typescript
|
|
229
|
+
{
|
|
230
|
+
count: number,
|
|
231
|
+
errorModel: {
|
|
232
|
+
errorCode: number,
|
|
233
|
+
timestamp: string | number | null
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Example:**
|
|
239
|
+
```typescript
|
|
240
|
+
const result = await client.GetReceivedMessagesCount();
|
|
241
|
+
console.log(`You have ${result.count} new messages`);
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
### GetUserInfo()
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
async GetUserInfo(): Promise<IVesalResponse_UserInfo>
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Retrieves user account information including credit balance, active numbers, and account status.
|
|
253
|
+
|
|
254
|
+
**Return Value:**
|
|
255
|
+
```typescript
|
|
256
|
+
{
|
|
257
|
+
user: {
|
|
258
|
+
credit: number, // Account credit balance
|
|
259
|
+
numbers: string[], // Your sender numbers
|
|
260
|
+
username: string,
|
|
261
|
+
active: boolean,
|
|
262
|
+
expirationDate: string,
|
|
263
|
+
// ... other account details
|
|
264
|
+
},
|
|
265
|
+
errorModel: {
|
|
266
|
+
errorCode: number,
|
|
267
|
+
timestamp: string | number | null
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
**Example:**
|
|
273
|
+
```typescript
|
|
274
|
+
const userInfo = await client.GetUserInfo();
|
|
275
|
+
console.log(`Credit: ${userInfo.user.credit}`);
|
|
276
|
+
console.log(`Active: ${userInfo.user.active}`);
|
|
277
|
+
console.log(`Numbers: ${userInfo.user.numbers.join(', ')}`);
|
|
278
|
+
console.log(`Expires: ${userInfo.user.expirationDate}`);
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Error Handling
|
|
284
|
+
|
|
285
|
+
The package includes a custom `VesalError` class for API errors:
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import { Vesal, VesalError } from 'vesal';
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
await client.Send({
|
|
292
|
+
recipients: '09123456789',
|
|
293
|
+
messages: 'Test'
|
|
294
|
+
});
|
|
295
|
+
} catch (error) {
|
|
296
|
+
if (error instanceof VesalError) {
|
|
297
|
+
console.error(`Vesal Error ${error.status}: ${error.message}`);
|
|
298
|
+
} else {
|
|
299
|
+
console.error('Unexpected error:', error);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Common Error Codes
|
|
305
|
+
|
|
306
|
+
| Code | Description (English) | توضیحات (فارسی) |
|
|
307
|
+
|------|----------------------|------------------|
|
|
308
|
+
| 0 | Success | عملیات با موفقیت انجام شد |
|
|
309
|
+
| -100 | Reference ID not found | refrenceId مورد نظر یافت نشد |
|
|
310
|
+
| -101 | Authentication failed | احراز هویت کاربر موفقیت آمیز نبود |
|
|
311
|
+
| -102 | Username not found | نام کاربری یافت نشد |
|
|
312
|
+
| -103 | Invalid originator number | شماره originator اشتباه یا در بازه شماره های کاربر نیست |
|
|
313
|
+
| -104 | Insufficient credit | اعتبار کم است |
|
|
314
|
+
| -105 | Invalid request format | فرمت درخواست اشتباه است |
|
|
315
|
+
| -107 | Invalid recipient number | شماره گیرنده پیامک اشتباه است |
|
|
316
|
+
| -109 | Account expired | تاریخ انقضای حساب کاربری فرارسیده است |
|
|
317
|
+
| -110 | IP not allowed | درخواست از ip مجاز کاربر ارسال نشده است |
|
|
318
|
+
| -111 | Number blacklisted | شماره گیرنده در بلک لیست قرار دارد |
|
|
319
|
+
| -112 | Account inactive | حساب مشتری فعال نیست |
|
|
320
|
+
| -119 | Access denied | کاربر به سرویس مورد نظر دسترسی ندارد |
|
|
321
|
+
| -120 | No valid recipients | پیام ارسال شده دارای هیچ شماره معتبری نیست |
|
|
322
|
+
| -137 | Forbidden content | پیام نباید حاوی کلمات غیرمجاز می باشد |
|
|
323
|
+
|
|
324
|
+
**Get error description:**
|
|
325
|
+
```typescript
|
|
326
|
+
import { GetStatusText } from 'vesal';
|
|
327
|
+
|
|
328
|
+
const errorMessage = GetStatusText(-104);
|
|
329
|
+
console.log(errorMessage); // "اعتبار کم است"
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## Message States
|
|
335
|
+
|
|
336
|
+
After sending a message, you can check its delivery status:
|
|
337
|
+
|
|
338
|
+
| State | Description (English) | توضیحات (فارسی) |
|
|
339
|
+
|-------|----------------------|------------------|
|
|
340
|
+
| 0 | In queue | پیامک در صف ارسال قرار دارد |
|
|
341
|
+
| 1 | Sent to operator | ارسال شده |
|
|
342
|
+
| 2 | Delivered | پیامک به موبایل گیرنده تحویل شده است |
|
|
343
|
+
| 3 | Not delivered | پیامک به موبایل گیرنده تحویل نشده است |
|
|
344
|
+
| 4 | Unknown status | وضعیت نامشخص |
|
|
345
|
+
| 5 | Received by system | پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است |
|
|
346
|
+
| 6 | Cancelled by operator | پیام از سمت اپراتور لغو شده است |
|
|
347
|
+
| 7 | Expired by operator | پیام از سمت اپراتور منقضی شده است |
|
|
348
|
+
| 8 | Rejected by operator | پیام از سمت اپراتور reject شده است |
|
|
349
|
+
|
|
350
|
+
**Access state descriptions:**
|
|
351
|
+
```typescript
|
|
352
|
+
import { messageStates } from 'vesal';
|
|
353
|
+
|
|
354
|
+
console.log(messageStates[2]); // "پیامک به موبایل گیرنده تحویل شده است"
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## Complete Example
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
import { Vesal, VesalError, messageStates } from 'vesal';
|
|
363
|
+
|
|
364
|
+
async function main() {
|
|
365
|
+
// Initialize client
|
|
366
|
+
const client = new Vesal(
|
|
367
|
+
'your-username',
|
|
368
|
+
'your-password',
|
|
369
|
+
'50002710000000'
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
try {
|
|
373
|
+
// Check account info
|
|
374
|
+
const userInfo = await client.GetUserInfo();
|
|
375
|
+
console.log(`Credit: ${userInfo.user.credit}`);
|
|
376
|
+
console.log(`Active: ${userInfo.user.active}`);
|
|
377
|
+
|
|
378
|
+
// Send SMS
|
|
379
|
+
const sendResult = await client.Send({
|
|
380
|
+
recipients: ['09123456789', '09987654321'],
|
|
381
|
+
messages: 'Hello from Vesal!'
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
console.log(`Successfully sent: ${sendResult.count.success}`);
|
|
385
|
+
console.log(`Failed: ${sendResult.count.fail}`);
|
|
386
|
+
|
|
387
|
+
// Check status after a delay
|
|
388
|
+
await new Promise(resolve => setTimeout(resolve, 10000));
|
|
389
|
+
|
|
390
|
+
const validRefs = sendResult.references.filter(
|
|
391
|
+
ref => typeof ref === 'number'
|
|
392
|
+
) as number[];
|
|
393
|
+
|
|
394
|
+
if (validRefs.length > 0) {
|
|
395
|
+
const status = await client.GetMessageStatus(validRefs);
|
|
396
|
+
status.states.forEach(state => {
|
|
397
|
+
console.log(
|
|
398
|
+
`Message ${state.id}: ${messageStates[state.state]}`
|
|
399
|
+
);
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// Check received messages
|
|
404
|
+
const received = await client.GetReceivedMessages();
|
|
405
|
+
console.log(`Received ${received.messageModels.length} messages`);
|
|
406
|
+
|
|
407
|
+
} catch (error) {
|
|
408
|
+
if (error instanceof VesalError) {
|
|
409
|
+
console.error(`Error ${error.status}: ${error.message}`);
|
|
410
|
+
} else {
|
|
411
|
+
console.error('Unexpected error:', error);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
main();
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
## TypeScript Support
|
|
422
|
+
|
|
423
|
+
The package includes full TypeScript definitions. All types are automatically available:
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
import type {
|
|
427
|
+
IVesalResponse_Send_WithCount,
|
|
428
|
+
IVesalResponse_MessageState,
|
|
429
|
+
IVesalResponse_ReceivedMessages,
|
|
430
|
+
IVesalResponse_ReceivedMessagesCount,
|
|
431
|
+
IVesalResponse_UserInfo
|
|
432
|
+
} from 'vesal';
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
You can also import the source TypeScript directly:
|
|
436
|
+
```typescript
|
|
437
|
+
import { Vesal } from 'vesal/ts';
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
---
|
|
441
|
+
|
|
442
|
+
## API Endpoint
|
|
443
|
+
|
|
444
|
+
The package connects to: `http://vesal.armaghan.net:8080/rest`
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
## License
|
|
449
|
+
|
|
450
|
+
MIT © [Shahab Movahhedi](https://shmovahhedi.com)
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
## Contributing
|
|
455
|
+
|
|
456
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
## Support
|
|
461
|
+
|
|
462
|
+
- **Issues**: [GitHub Issues](https://github.com/movahhedi/vesal/issues)
|
|
463
|
+
- **Author**: [Shahab Movahhedi](https://shmovahhedi.com)
|
|
464
|
+
- **Email**: dev@shmovahhedi.com
|
|
465
|
+
|
|
466
|
+
---
|
|
467
|
+
|
|
468
|
+
## Links
|
|
469
|
+
|
|
470
|
+
- [npm Package](https://www.npmjs.com/package/vesal)
|
|
471
|
+
- [GitHub Repository](https://github.com/movahhedi/vesal)
|
|
472
|
+
- [Author's Website](https://shmovahhedi.com)
|
package/dist/vesal.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(e=function(){return!!t})()}function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function o(t){var s="function"==typeof Map?new Map:void 0;return o=function(t){if(null===t||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==s){if(s.has(t))return s.get(t);s.set(t,o)}function o(){return function(t,r,o){if(e())return Reflect.construct.apply(null,arguments);var s=[null];s.push.apply(s,r);var i=new(t.bind.apply(t,s));return o&&n(i,o.prototype),i}(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,t)},o(t)}var s;function i(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var c=/*#__PURE__*/function(){function e(e,t,r){return this.apiUrl="http://vesal.armaghan.net:8080/rest",this.username=void 0,this.password=void 0,this.from=void 0,this.username=e||"",this.password=t,this.from=r,this}var r=e.prototype;return r.Api=function(e,r,n){void 0===r&&(r="POST");try{var o,s,c=function(e){function t(e){if(!s.references)throw new a(void 0,"The server didn't respond correctly");return s}var r=i(function(){return Promise.resolve(o.json()).then(function(e){s=e})},function(){throw new a(void 0,"The server didn't respond correctly")});return r&&r.then?r.then(t):t()},u=this;n=t({},n,{username:u.username,password:u.password});var f=i(function(){return Promise.resolve(fetch(u.apiUrl+"/"+e,{headers:{Accept:"application/json","Content-Type":"application/json"},method:r,body:n&&JSON.stringify(n)})).then(function(e){o=e})},function(){throw new a(void 0,"Server connection failed")});return Promise.resolve(f&&f.then?f.then(c):c())}catch(e){return Promise.reject(e)}},r.Send=function(e){var r=e.recipients,n=e.messages,o=e.from;try{if(!r||!n)throw new a(void 0,"recipients and messages should not be empty");"string"==typeof r&&(r=[r]),o||(o=this.from);var s=Array.isArray(n)||Array.isArray(o);if(s){if(!r.length)throw new a(void 0,"recipients and messages should have the same length");if(Array.isArray(n)&&!n.length)throw new a(void 0,"recipients and messages should have the same length");if("string"==typeof n&&(n=Array(r.length).fill(n)),"string"==typeof o&&(o=Array(r.length).fill(o)),r.length!==n.length||r.length!==o.length)throw new a(void 0,"recipients and messages should have the same length")}var i=t({destinations:r},s?{originators:o}:{originator:o},s?{contents:n}:{content:n});return Promise.resolve(this.Api(s?"ManyToMany":"OneToMany","POST",i)).then(function(e){var r,n=0,o=0;return null==(r=e.references)||r.map(function(e){e?n++:o++}),t({},e,{references:e.references||[],count:{success:n,fail:o}})})}catch(e){return Promise.reject(e)}},r.GetMessageStatus=function(e){try{return Promise.resolve(this.Api("messageState","POST",{referenceids:e}))}catch(e){return Promise.reject(e)}},r.GetReceivedMessages=function(){try{return Promise.resolve(this.Api("pullReceivedMessages"))}catch(e){return Promise.reject(e)}},r.GetReceivedMessagesCount=function(){try{return Promise.resolve(this.Api("receivedMessageCount"))}catch(e){return Promise.reject(e)}},r.GetUserInfo=function(){try{return Promise.resolve(this.Api("userInfo"))}catch(e){return Promise.reject(e)}},e}(),a=/*#__PURE__*/function(e){var t,r;function o(t,r){var n,o,s;return t&&Object.keys(f).includes(""+t)?(o=u(t),s=t):(o=r||"Unknown Vesal error",s=void 0),(n=e.call(this,o)||this).status=void 0,n.message=o,n.status=s,n}return r=e,(t=o).prototype=Object.create(r.prototype),t.prototype.constructor=t,n(t,r),o}(/*#__PURE__*/o(Error));function u(e){return 0===e?"success":Object.keys(f).includes(""+e)?f[e]:""}var f=((s={0:"عملیات با موفقیت انجام شد"})[-100]="refrenceId مورد نظر یافت نشد",s[-101]="احراز هویت کاربر موفقیت آمیز نبود",s[-102]="نام کاربری یافت نشد",s[-103]="شماره originator اشتباه یا در بازه شماره های کاربر نیست",s[-104]="اعتبار کم است",s[-105]="فرمت درخواست اشتباه است",s[-106]="تعداد refrenceId ها بیش از 1000 عدد است",s[-107]="شماره گیرنده پیامک اشتباه است",s[-109]="تاریخ انقضای حساب کاربری فرارسیده است",s[-110]="درخواست از ip مجاز کاربر ارسال نشده است",s[-111]="شماره گیرنده در بلک لیست قرار دارد",s[-112]="حساب مشتری فعال نیست",s[-115]="فرمت UDH اشتباه است",s[-117]="مقدار mclass وارد شده اشتباه است",s[-118]="شماره پورت وارد شده صحیح نیست",s[-119]="کاربر به سرویس مورد نظر دسترسی ندارد",s[-120]="پیام ارسال شده دارای هیچ شماره معتبری نیست",s[-200]="خطای داخلی در پایگاه داده رخ داده است",s[-201]="خطای نامشخص داخل پایگاه داده",s[-137]="پیام نباید حاوی کلمات غیرمجاز می باشد",s);exports.GetStatusText=u,exports.Vesal=c,exports.VesalError=a,exports.
|
|
1
|
+
function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(e=function(){return!!t})()}function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function o(t){var s="function"==typeof Map?new Map:void 0;return o=function(t){if(null===t||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==s){if(s.has(t))return s.get(t);s.set(t,o)}function o(){return function(t,r,o){if(e())return Reflect.construct.apply(null,arguments);var s=[null];s.push.apply(s,r);var i=new(t.bind.apply(t,s));return o&&n(i,o.prototype),i}(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,t)},o(t)}var s;function i(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var c=/*#__PURE__*/function(){function e(e,t,r){return this.apiUrl="http://vesal.armaghan.net:8080/rest",this.username=void 0,this.password=void 0,this.from=void 0,this.username=e||"",this.password=t,this.from=r,this}var r=e.prototype;return r.Api=function(e,r,n){void 0===r&&(r="POST");try{var o,s,c=function(e){function t(e){if(!s.references)throw new a(void 0,"The server didn't respond correctly");return s}var r=i(function(){return Promise.resolve(o.json()).then(function(e){s=e})},function(){throw new a(void 0,"The server didn't respond correctly")});return r&&r.then?r.then(t):t()},u=this;n=t({},n,{username:u.username,password:u.password});var f=i(function(){return Promise.resolve(fetch(u.apiUrl+"/"+e,{headers:{Accept:"application/json","Content-Type":"application/json"},method:r,body:n&&JSON.stringify(n)})).then(function(e){o=e})},function(){throw new a(void 0,"Server connection failed")});return Promise.resolve(f&&f.then?f.then(c):c())}catch(e){return Promise.reject(e)}},r.Send=function(e){var r=e.recipients,n=e.messages,o=e.from;try{if(!r||!n)throw new a(void 0,"recipients and messages should not be empty");"string"==typeof r&&(r=[r]),o||(o=this.from);var s=Array.isArray(n)||Array.isArray(o);if(s){if(!r.length)throw new a(void 0,"recipients and messages should have the same length");if(Array.isArray(n)&&!n.length)throw new a(void 0,"recipients and messages should have the same length");if("string"==typeof n&&(n=Array(r.length).fill(n)),"string"==typeof o&&(o=Array(r.length).fill(o)),r.length!==n.length||r.length!==o.length)throw new a(void 0,"recipients and messages should have the same length")}var i=t({destinations:r},s?{originators:o}:{originator:o},s?{contents:n}:{content:n});return Promise.resolve(this.Api(s?"ManyToMany":"OneToMany","POST",i)).then(function(e){var r,n=0,o=0;return null==(r=e.references)||r.map(function(e){e?n++:o++}),t({},e,{references:e.references||[],count:{success:n,fail:o}})})}catch(e){return Promise.reject(e)}},r.GetMessageStatus=function(e){try{return Promise.resolve(this.Api("messageState","POST",{referenceids:e}))}catch(e){return Promise.reject(e)}},r.GetReceivedMessages=function(){try{return Promise.resolve(this.Api("pullReceivedMessages"))}catch(e){return Promise.reject(e)}},r.GetReceivedMessagesCount=function(){try{return Promise.resolve(this.Api("receivedMessageCount"))}catch(e){return Promise.reject(e)}},r.GetUserInfo=function(){try{return Promise.resolve(this.Api("userInfo"))}catch(e){return Promise.reject(e)}},e}(),a=/*#__PURE__*/function(e){var t,r;function o(t,r){var n,o,s;return t&&Object.keys(f).includes(""+t)?(o=u(t),s=t):(o=r||"Unknown Vesal error",s=void 0),(n=e.call(this,o)||this).status=void 0,n.message=o,n.status=s,n}return r=e,(t=o).prototype=Object.create(r.prototype),t.prototype.constructor=t,n(t,r),o}(/*#__PURE__*/o(Error));function u(e){return 0===e?"success":Object.keys(f).includes(""+e)?f[e]:""}var f=((s={0:"عملیات با موفقیت انجام شد"})[-100]="refrenceId مورد نظر یافت نشد",s[-101]="احراز هویت کاربر موفقیت آمیز نبود",s[-102]="نام کاربری یافت نشد",s[-103]="شماره originator اشتباه یا در بازه شماره های کاربر نیست",s[-104]="اعتبار کم است",s[-105]="فرمت درخواست اشتباه است",s[-106]="تعداد refrenceId ها بیش از 1000 عدد است",s[-107]="شماره گیرنده پیامک اشتباه است",s[-109]="تاریخ انقضای حساب کاربری فرارسیده است",s[-110]="درخواست از ip مجاز کاربر ارسال نشده است",s[-111]="شماره گیرنده در بلک لیست قرار دارد",s[-112]="حساب مشتری فعال نیست",s[-115]="فرمت UDH اشتباه است",s[-117]="مقدار mclass وارد شده اشتباه است",s[-118]="شماره پورت وارد شده صحیح نیست",s[-119]="کاربر به سرویس مورد نظر دسترسی ندارد",s[-120]="پیام ارسال شده دارای هیچ شماره معتبری نیست",s[-200]="خطای داخلی در پایگاه داده رخ داده است",s[-201]="خطای نامشخص داخل پایگاه داده",s[-137]="پیام نباید حاوی کلمات غیرمجاز می باشد",s);exports.GetStatusText=u,exports.Vesal=c,exports.VesalError=a,exports.messageStates={0:"پیامک در صف ارسال قرار دارد",1:"ارسال شده",2:"پیامک به موبایل گیرنده تحویل شده است",3:"پیامک به موبایل گیرنده تحویل نشده است",4:"وضعیت نامشخص",5:"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است",6:"پیام از سمت اپراتور لغو شده است",7:"پیام از سمت اپراتور منقضی شده است",8:"پیام از سمت اپراتور reject شده است"},exports.vesalErrors=f;
|
|
2
2
|
//# sourceMappingURL=vesal.cjs.map
|
package/dist/vesal.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vesal.cjs","sources":["../src/vesal.ts"],"sourcesContent":["/**\r\n * The Vesal API Class\r\n * @author Shahab Movahhedi\r\n * @see {@link https://shmovahhedi.com Shahab Movahhedi's Website}\r\n * @see {@link https://github.com/movahhedi/vesal vesal's Repository}\r\n * @license MIT\r\n */\r\nexport class Vesal {\r\n\tpublic readonly apiUrl = \"http://vesal.armaghan.net:8080/rest\";\r\n\tprivate username: string;\r\n\tprivate password: string;\r\n\tprivate from: string;\r\n\r\n\tconstructor(username: string, password: string, from: string) {\r\n\t\tthis.username = username || \"\";\r\n\t\tthis.password = password;\r\n\t\tthis.from = from;\r\n\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Make an API request to the Vesal API\r\n\t * @private\r\n\t * @param {string} urlSuffix - The URL suffix for the API endpoint\r\n\t * @param {(\"GET\"|\"POST\")} [method=\"GET\"] - The HTTP method to use for the request\r\n\t * @param {object|null} [data=null] - The data to send with the request\r\n\t * @returns {Promise} The response from the API\r\n\t */\r\n\tprivate async Api(\r\n\t\turlSuffix: string,\r\n\t\tmethod: \"GET\" | \"POST\" = \"POST\",\r\n\t\tdata?: object,\r\n\t): Promise<any> {\r\n\t\tlet response: Response, responseBody: any;\r\n\r\n\t\tdata = {\r\n\t\t\t...data,\r\n\t\t\tusername: this.username,\r\n\t\t\tpassword: this.password,\r\n\t\t};\r\n\r\n\t\ttry {\r\n\t\t\tresponse = await fetch(`${this.apiUrl}/${urlSuffix}`, {\r\n\t\t\t\theaders: {\r\n\t\t\t\t\tAccept: \"application/json\",\r\n\t\t\t\t\t\"Content-Type\": \"application/json\",\r\n\t\t\t\t},\r\n\t\t\t\tmethod,\r\n\t\t\t\tbody: data && JSON.stringify(data),\r\n\t\t\t});\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"Server connection failed\");\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tresponseBody = await response.json();\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\tif (!responseBody.references) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\treturn responseBody;\r\n\t}\r\n\r\n\tasync Send({\r\n\t\trecipients,\r\n\t\tmessages,\r\n\t\tfrom,\r\n\t}: {\r\n\t\trecipients: string | string[];\r\n\t\tmessages: string | string[];\r\n\t\tfrom?: string | string[];\r\n\t}): Promise<IVesalResponse_Send_WithCount> {\r\n\t\tif (!recipients || !messages) {\r\n\t\t\tthrow new VesalError(\r\n\t\t\t\tundefined,\r\n\t\t\t\t\"recipients and messages should not be empty\",\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif (typeof recipients === \"string\") {\r\n\t\t\trecipients = [recipients];\r\n\t\t}\r\n\r\n\t\tif (!from) {\r\n\t\t\tfrom = this.from;\r\n\t\t}\r\n\r\n\t\tconst isManyToMany = Array.isArray(messages) || Array.isArray(from);\r\n\r\n\t\tif (isManyToMany) {\r\n\t\t\tif (!recipients.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t\tif (Array.isArray(messages) && !messages.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (typeof messages === \"string\") {\r\n\t\t\t\t// messages = recipients.map(() => messages);\r\n\t\t\t\tmessages = Array(recipients.length).fill(messages);\r\n\t\t\t}\r\n\t\t\tif (typeof from === \"string\") {\r\n\t\t\t\t// from = recipients.map(() => from);\r\n\t\t\t\tfrom = Array(recipients.length).fill(from);\r\n\t\t\t}\r\n\r\n\t\t\tif (\r\n\t\t\t\trecipients.length !== messages.length ||\r\n\t\t\t\trecipients.length !== from.length\r\n\t\t\t) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst sendData = {\r\n\t\t\tdestinations: recipients,\r\n\t\t\t...(isManyToMany ? { originators: from } : { originator: from }),\r\n\t\t\t...(isManyToMany ? { contents: messages } : { content: messages }),\r\n\t\t};\r\n\r\n\t\tconst result: IVesalResponse_Send = await this.Api(\r\n\t\t\tisManyToMany ? \"ManyToMany\" : \"OneToMany\",\r\n\t\t\t\"POST\",\r\n\t\t\tsendData,\r\n\t\t);\r\n\r\n\t\tlet successCount: number = 0,\r\n\t\t\tfailCount: number = 0;\r\n\r\n\t\tresult.references?.map((messageResult) => {\r\n\t\t\tif (messageResult) {\r\n\t\t\t\tsuccessCount++;\r\n\t\t\t} else {\r\n\t\t\t\tfailCount++;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn {\r\n\t\t\t...result,\r\n\t\t\treferences: result.references || [],\r\n\t\t\tcount: {\r\n\t\t\t\tsuccess: successCount,\r\n\t\t\t\tfail: failCount,\r\n\t\t\t},\r\n\t\t};\r\n\t}\r\n\r\n\tasync GetMessageStatus(\r\n\t\treferencesIds: number[],\r\n\t): Promise<IVesalResponse_MessageState> {\r\n\t\treturn await this.Api(\"messageState\", \"POST\", {\r\n\t\t\treferenceids: referencesIds,\r\n\t\t});\r\n\t}\r\n\r\n\tasync GetReceivedMessages(): Promise<IVesalResponse_ReceivedMessages> {\r\n\t\treturn await this.Api(\"pullReceivedMessages\");\r\n\t}\r\n\r\n\tasync GetReceivedMessagesCount(): Promise<IVesalResponse_ReceivedMessagesCount> {\r\n\t\treturn await this.Api(\"receivedMessageCount\");\r\n\t}\r\n\r\n\tasync GetUserInfo(): Promise<IVesalResponse_UserInfo> {\r\n\t\treturn await this.Api(\"userInfo\");\r\n\t}\r\n}\r\n\r\nexport class VesalError extends Error {\r\n\tstatus: keyof typeof vesalErrors | undefined;\r\n\r\n\tconstructor(statusParam: number | undefined, messageParam?: string) {\r\n\t\tlet message: string, status: keyof typeof vesalErrors | undefined;\r\n\r\n\t\tif (statusParam && Object.keys(vesalErrors).includes(\"\" + statusParam)) {\r\n\t\t\tmessage = GetStatusText(statusParam);\r\n\t\t\tstatus = statusParam as any;\r\n\t\t} else {\r\n\t\t\tmessage = messageParam || \"Unknown Vesal error\";\r\n\t\t\tstatus = undefined;\r\n\t\t}\r\n\r\n\t\tsuper(message);\r\n\r\n\t\tthis.message = message;\r\n\t\tthis.status = status;\r\n\t}\r\n}\r\n\r\ninterface IVesalResponse_Base {\r\n\terrorModel: {\r\n\t\terrorCode: number;\r\n\t\ttimestamp: string | number | null;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_Send extends IVesalResponse_Base {\r\n\treferences: (number | Omit<keyof typeof vesalErrors, 0>)[];\r\n}\r\n\r\ninterface IVesalResponse_Send_WithCount extends IVesalResponse_Send {\r\n\tcount: {\r\n\t\tsuccess: number;\r\n\t\tfail: number;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_MessageState extends IVesalResponse_Base {\r\n\tstates: {\r\n\t\tid: number;\r\n\t\tstate: number;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessages extends IVesalResponse_Base {\r\n\tmessageModels: {\r\n\t\toriginator: string;\r\n\t\tdestination: string;\r\n\t\tcontent: string;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessagesCount extends IVesalResponse_Base {\r\n\tcount: number;\r\n}\r\ninterface IVesalResponse_UserInfo extends IVesalResponse_Base {\r\n\tuser: {\r\n\t\tcredit: number;\r\n\t\tdeliveryUrl: unknown;\r\n\t\treceiveUrl: unknown;\r\n\t\tiPs: string[];\r\n\t\tnumbers: string[];\r\n\t\tid: number;\r\n\t\tusername: string;\r\n\t\tpassword: unknown;\r\n\t\tfirstName: unknown;\r\n\t\tlastName: unknown;\r\n\t\tmobile: unknown;\r\n\t\temail: unknown;\r\n\t\tnationalId: number;\r\n\t\texpirationDate: string;\r\n\t\tactive: boolean;\r\n\t\tdeleted: boolean;\r\n\t\tdbProxyStandalone: boolean;\r\n\t\tinsertDate: unknown;\r\n\t\tupdateDate: unknown;\r\n\t\tcustomer: unknown;\r\n\t\troles: unknown;\r\n\t};\r\n}\r\n\r\nexport function GetStatusText(status: number) {\r\n\tif (status === 0) {\r\n\t\treturn \"success\";\r\n\t}\r\n\tif (Object.keys(vesalErrors).includes(\"\" + status)) {\r\n\t\treturn vesalErrors[status];\r\n\t}\r\n\treturn \"\";\r\n}\r\n\r\nexport const messageStates = {\r\n\t0: \"پیامک در صف ارسال قرار دارد\",\r\n\t1: \"ارسال شده\",\r\n\t2: \"پیامک به موبایل گیرنده تحویل شده است\",\r\n\t3: \"پیامک به موبایل گیرنده تحویل نشده است\",\r\n\t4: \"وضعیت نامشخص\",\r\n\t5: \"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است\",\r\n\t6: \"پیام از سمت اپراتور لغو شده است\",\r\n\t7: \"پیام از سمت اپراتور منقضی شده است\",\r\n\t8: \"پیام از سمت اپراتور reject شده است\",\r\n} as const;\r\n\r\nexport const vesalErrors = {\r\n\t0: \"عملیات با موفقیت انجام شد\",\r\n\t[-100]: \"refrenceId مورد نظر یافت نشد\",\r\n\t[-101]: \"احراز هویت کاربر موفقیت آمیز نبود\",\r\n\t[-102]: \"نام کاربری یافت نشد\",\r\n\t[-103]: \"شماره originator اشتباه یا در بازه شماره های کاربر نیست\",\r\n\t[-104]: \"اعتبار کم است\",\r\n\t[-105]: \"فرمت درخواست اشتباه است\",\r\n\t[-106]: \"تعداد refrenceId ها بیش از 1000 عدد است\",\r\n\t[-107]: \"شماره گیرنده پیامک اشتباه است\",\r\n\t[-109]: \"تاریخ انقضای حساب کاربری فرارسیده است\",\r\n\t[-110]: \"درخواست از ip مجاز کاربر ارسال نشده است\",\r\n\t[-111]: \"شماره گیرنده در بلک لیست قرار دارد\",\r\n\t[-112]: \"حساب مشتری فعال نیست\",\r\n\t[-115]: \"فرمت UDH اشتباه است\",\r\n\t[-117]: \"مقدار mclass وارد شده اشتباه است\",\r\n\t[-118]: \"شماره پورت وارد شده صحیح نیست\",\r\n\t[-119]: \"کاربر به سرویس مورد نظر دسترسی ندارد\",\r\n\t[-120]: \"پیام ارسال شده دارای هیچ شماره معتبری نیست\",\r\n\t[-200]: \"خطای داخلی در پایگاه داده رخ داده است\",\r\n\t[-201]: \"خطای نامشخص داخل پایگاه داده\",\r\n\t[-137]: \"پیام نباید حاوی کلمات غیرمجاز می باشد\",\r\n} as const;\r\n\r\nexport default Vesal;\r\n"],"names":["Vesal","username","password","from","this","apiUrl","_proto","prototype","Api","urlSuffix","method","data","response","responseBody","_temp4","_result","_temp2","_result2","references","VesalError","undefined","_temp","_catch","Promise","resolve","json","then","_response$json","_exit","_this","_extends","_temp3","fetch","headers","Accept","body","JSON","stringify","_fetch","e","reject","Send","_ref","recipients","messages","isManyToMany","Array","isArray","length","fill","sendData","destinations","originators","originator","contents","content","result","_result$references","successCount","failCount","map","messageResult","count","success","fail","GetMessageStatus","referencesIds","referenceids","GetReceivedMessages","GetReceivedMessagesCount","GetUserInfo","_Error","statusParam","messageParam","_this7","message","status","Object","keys","vesalErrors","includes","GetStatusText","call","_wrapNativeSuper","Error","_vesalErrors"],"mappings":"y5CAOa,IAAAA,eAAK,WAMjB,SAAAA,EAAYC,EAAkBC,EAAkBC,GAK/C,OAL2DC,KAL5CC,OAAS,sCACjBJ,KAAAA,qBACAC,cAAQ,EAAAE,KACRD,UAAI,EAGXC,KAAKH,SAAWA,GAAY,GAC5BG,KAAKF,SAAWA,EAChBE,KAAKD,KAAOA,EAELC,IACR,CAAC,IAAAE,EAAAN,EAAAO,UAgKAP,OAhKAM,EAUaE,IAAGA,SAChBC,EACAC,EACAC,QADAD,IAAAA,IAAAA,EAAyB,QACZ,IAAA,IAETE,EAAoBC,EAFXC,EAAA,SAAAC,GAAA,SAAAC,EAAAC,GA6Bb,IAAKJ,EAAaK,WACjB,MAAU,IAAAC,OAAWC,EAAW,uCAGjC,OAAOP,CAAa,CAAA,IAAAQ,EAAAC,EAVhB,WAAA,OAAAC,QAAAC,QACkBZ,EAASa,QAAMC,KAAA,SAAAC,GAApCd,EAAYc,CAAyB,EACtC,EAAgB,WACf,MAAM,IAAIR,OAAWC,EAAW,sCACjC,GAAC,OAAAC,GAAAA,EAAAK,KAAAL,EAAAK,KAAAV,GAAAA,GAAAY,EAAAC,EArBUzB,KAFXO,EAAImB,EACAnB,CAAAA,EAAAA,EACHV,CAAAA,SAAU4B,EAAK5B,SACfC,SAAU2B,EAAK3B,WACd,IAAA6B,EAAAT,aAEEC,OAAAA,QAAAC,QACcQ,MAASH,EAAKxB,OAAM,IAAII,EAAa,CACrDw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BH,KAAApD,yEAkBtBA,CAAA,CAlBsB,cAkBtBgE,EAlB8BC,QAiFhB,SAAAH,EAAcL,GAC7B,OAAe,IAAXA,EACI,UAEJC,OAAOC,KAAKC,GAAaC,SAAS,GAAKJ,GACnCG,EAAYH,GAEb,EACR,CAEa,IAYAG,IAAWM,EAAA,CACvB,EAAG,+BACD,KAAM,+BAA8BA,GACpC,KAAM,oCAAmCA,GACzC,KAAM,sBAAqBA,GAC3B,KAAM,0DAAyDA,GAC/D,KAAM,gBAAeA,GACrB,KAAM,0BAAyBA,GAC/B,KAAM,0CAAyCA,GAC/C,KAAM,gCAA+BA,GACrC,KAAM,wCAAuCA,GAC7C,KAAM,0CAAyCA,GAC/C,KAAM,qCAAoCA,GAC1C,KAAM,uBAAsBA,GAC5B,KAAM,sBAAqBA,GAC3B,KAAM,mCAAkCA,GACxC,KAAM,gCAA+BA,GACrC,KAAM,uCAAsCA,GAC5C,KAAM,6CAA4CA,GAClD,KAAM,wCAAuCA,GAC7C,KAAM,+BAA8BA,GACpC,KAAM,wCAAuCA,wGAjCnB,CAC5B,EAAG,8BACH,EAAG,YACH,EAAG,uCACH,EAAG,wCACH,EAAG,eACH,EAAG,yDACH,EAAG,kCACH,EAAG,oCACH,EAAG"}
|
|
1
|
+
{"version":3,"file":"vesal.cjs","sources":["../src/vesal.ts"],"sourcesContent":["/**\r\n * The Vesal API Class\r\n * @author Shahab Movahhedi\r\n * @see {@link https://shmovahhedi.com Shahab Movahhedi's Website}\r\n * @see {@link https://github.com/movahhedi/vesal vesal's Repository}\r\n * @license MIT\r\n */\r\nexport class Vesal {\r\n\tpublic readonly apiUrl = \"http://vesal.armaghan.net:8080/rest\";\r\n\tprivate username: string;\r\n\tprivate password: string;\r\n\tprivate from: string;\r\n\r\n\tconstructor(username: string, password: string, from: string) {\r\n\t\tthis.username = username || \"\";\r\n\t\tthis.password = password;\r\n\t\tthis.from = from;\r\n\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Make an API request to the Vesal API\r\n\t * @private\r\n\t * @param {string} urlSuffix - The URL suffix for the API endpoint\r\n\t * @param {(\"GET\"|\"POST\")} [method=\"GET\"] - The HTTP method to use for the request\r\n\t * @param {object|null} [data=null] - The data to send with the request\r\n\t * @returns {Promise} The response from the API\r\n\t */\r\n\tprivate async Api(\r\n\t\turlSuffix: string,\r\n\t\tmethod: \"GET\" | \"POST\" = \"POST\",\r\n\t\tdata?: object,\r\n\t): Promise<any> {\r\n\t\tlet response: Response, responseBody: any;\r\n\r\n\t\tdata = {\r\n\t\t\t...data,\r\n\t\t\tusername: this.username,\r\n\t\t\tpassword: this.password,\r\n\t\t};\r\n\r\n\t\ttry {\r\n\t\t\tresponse = await fetch(`${this.apiUrl}/${urlSuffix}`, {\r\n\t\t\t\theaders: {\r\n\t\t\t\t\tAccept: \"application/json\",\r\n\t\t\t\t\t\"Content-Type\": \"application/json\",\r\n\t\t\t\t},\r\n\t\t\t\tmethod,\r\n\t\t\t\tbody: data && JSON.stringify(data),\r\n\t\t\t});\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"Server connection failed\");\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tresponseBody = await response.json();\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\tif (!responseBody.references) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\treturn responseBody;\r\n\t}\r\n\r\n\tasync Send({\r\n\t\trecipients,\r\n\t\tmessages,\r\n\t\tfrom,\r\n\t}: {\r\n\t\trecipients: string | string[];\r\n\t\tmessages: string | string[];\r\n\t\tfrom?: string | string[];\r\n\t}): Promise<IVesalResponse_Send_WithCount> {\r\n\t\tif (!recipients || !messages) {\r\n\t\t\tthrow new VesalError(\r\n\t\t\t\tundefined,\r\n\t\t\t\t\"recipients and messages should not be empty\",\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif (typeof recipients === \"string\") {\r\n\t\t\trecipients = [recipients];\r\n\t\t}\r\n\r\n\t\tif (!from) {\r\n\t\t\tfrom = this.from;\r\n\t\t}\r\n\r\n\t\tconst isManyToMany = Array.isArray(messages) || Array.isArray(from);\r\n\r\n\t\tif (isManyToMany) {\r\n\t\t\tif (!recipients.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t\tif (Array.isArray(messages) && !messages.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (typeof messages === \"string\") {\r\n\t\t\t\t// messages = recipients.map(() => messages);\r\n\t\t\t\tmessages = Array(recipients.length).fill(messages);\r\n\t\t\t}\r\n\t\t\tif (typeof from === \"string\") {\r\n\t\t\t\t// from = recipients.map(() => from);\r\n\t\t\t\tfrom = Array(recipients.length).fill(from);\r\n\t\t\t}\r\n\r\n\t\t\tif (\r\n\t\t\t\trecipients.length !== messages.length ||\r\n\t\t\t\trecipients.length !== from.length\r\n\t\t\t) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst sendData = {\r\n\t\t\tdestinations: recipients,\r\n\t\t\t...(isManyToMany ? { originators: from } : { originator: from }),\r\n\t\t\t...(isManyToMany ? { contents: messages } : { content: messages }),\r\n\t\t};\r\n\r\n\t\tconst result: IVesalResponse_Send = await this.Api(\r\n\t\t\tisManyToMany ? \"ManyToMany\" : \"OneToMany\",\r\n\t\t\t\"POST\",\r\n\t\t\tsendData,\r\n\t\t);\r\n\r\n\t\tlet successCount: number = 0,\r\n\t\t\tfailCount: number = 0;\r\n\r\n\t\tresult.references?.map((messageResult) => {\r\n\t\t\tif (messageResult) {\r\n\t\t\t\tsuccessCount++;\r\n\t\t\t} else {\r\n\t\t\t\tfailCount++;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn {\r\n\t\t\t...result,\r\n\t\t\treferences: result.references || [],\r\n\t\t\tcount: {\r\n\t\t\t\tsuccess: successCount,\r\n\t\t\t\tfail: failCount,\r\n\t\t\t},\r\n\t\t};\r\n\t}\r\n\r\n\tasync GetMessageStatus(\r\n\t\treferencesIds: number[],\r\n\t): Promise<IVesalResponse_MessageState> {\r\n\t\treturn await this.Api(\"messageState\", \"POST\", {\r\n\t\t\treferenceids: referencesIds,\r\n\t\t});\r\n\t}\r\n\r\n\tasync GetReceivedMessages(): Promise<IVesalResponse_ReceivedMessages> {\r\n\t\treturn await this.Api(\"pullReceivedMessages\");\r\n\t}\r\n\r\n\tasync GetReceivedMessagesCount(): Promise<IVesalResponse_ReceivedMessagesCount> {\r\n\t\treturn await this.Api(\"receivedMessageCount\");\r\n\t}\r\n\r\n\tasync GetUserInfo(): Promise<IVesalResponse_UserInfo> {\r\n\t\treturn await this.Api(\"userInfo\");\r\n\t}\r\n}\r\n\r\nexport class VesalError extends Error {\r\n\tstatus: keyof typeof vesalErrors | undefined;\r\n\r\n\tconstructor(statusParam: number | undefined, messageParam?: string) {\r\n\t\tlet message: string, status: keyof typeof vesalErrors | undefined;\r\n\r\n\t\tif (statusParam && Object.keys(vesalErrors).includes(\"\" + statusParam)) {\r\n\t\t\tmessage = GetStatusText(statusParam);\r\n\t\t\tstatus = statusParam as any;\r\n\t\t} else {\r\n\t\t\tmessage = messageParam || \"Unknown Vesal error\";\r\n\t\t\tstatus = undefined;\r\n\t\t}\r\n\r\n\t\tsuper(message);\r\n\r\n\t\tthis.message = message;\r\n\t\tthis.status = status;\r\n\t}\r\n}\r\n\r\ninterface IVesalResponse_Base {\r\n\terrorModel: {\r\n\t\terrorCode: number;\r\n\t\ttimestamp: string | number | null;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_Send extends IVesalResponse_Base {\r\n\treferences: (number | Omit<keyof typeof vesalErrors, 0>)[];\r\n}\r\n\r\ninterface IVesalResponse_Send_WithCount extends IVesalResponse_Send {\r\n\tcount: {\r\n\t\tsuccess: number;\r\n\t\tfail: number;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_MessageState extends IVesalResponse_Base {\r\n\tstates: {\r\n\t\tid: number;\r\n\t\tstate: number;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessages extends IVesalResponse_Base {\r\n\tmessageModels: {\r\n\t\toriginator: string;\r\n\t\tdestination: string;\r\n\t\tcontent: string;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessagesCount extends IVesalResponse_Base {\r\n\tcount: number;\r\n}\r\ninterface IVesalResponse_UserInfo extends IVesalResponse_Base {\r\n\tuser: {\r\n\t\tcredit: number;\r\n\t\tdeliveryUrl: unknown;\r\n\t\treceiveUrl: unknown;\r\n\t\tiPs: string[];\r\n\t\tnumbers: string[];\r\n\t\tid: number;\r\n\t\tusername: string;\r\n\t\tpassword: unknown;\r\n\t\tfirstName: unknown;\r\n\t\tlastName: unknown;\r\n\t\tmobile: unknown;\r\n\t\temail: unknown;\r\n\t\tnationalId: number;\r\n\t\texpirationDate: string;\r\n\t\tactive: boolean;\r\n\t\tdeleted: boolean;\r\n\t\tdbProxyStandalone: boolean;\r\n\t\tinsertDate: unknown;\r\n\t\tupdateDate: unknown;\r\n\t\tcustomer: unknown;\r\n\t\troles: unknown;\r\n\t};\r\n}\r\n\r\nexport function GetStatusText(status: number) {\r\n\tif (status === 0) {\r\n\t\treturn \"success\";\r\n\t}\r\n\tif (Object.keys(vesalErrors).includes(\"\" + status)) {\r\n\t\treturn vesalErrors[status];\r\n\t}\r\n\treturn \"\";\r\n}\r\n\r\nexport const messageStates = {\r\n\t0: \"پیامک در صف ارسال قرار دارد\",\r\n\t1: \"ارسال شده\",\r\n\t2: \"پیامک به موبایل گیرنده تحویل شده است\",\r\n\t3: \"پیامک به موبایل گیرنده تحویل نشده است\",\r\n\t4: \"وضعیت نامشخص\",\r\n\t5: \"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است\",\r\n\t6: \"پیام از سمت اپراتور لغو شده است\",\r\n\t7: \"پیام از سمت اپراتور منقضی شده است\",\r\n\t8: \"پیام از سمت اپراتور reject شده است\",\r\n} as const;\r\n\r\nexport const vesalErrors = {\r\n\t0: \"عملیات با موفقیت انجام شد\",\r\n\t[-100]: \"refrenceId مورد نظر یافت نشد\",\r\n\t[-101]: \"احراز هویت کاربر موفقیت آمیز نبود\",\r\n\t[-102]: \"نام کاربری یافت نشد\",\r\n\t[-103]: \"شماره originator اشتباه یا در بازه شماره های کاربر نیست\",\r\n\t[-104]: \"اعتبار کم است\",\r\n\t[-105]: \"فرمت درخواست اشتباه است\",\r\n\t[-106]: \"تعداد refrenceId ها بیش از 1000 عدد است\",\r\n\t[-107]: \"شماره گیرنده پیامک اشتباه است\",\r\n\t[-109]: \"تاریخ انقضای حساب کاربری فرارسیده است\",\r\n\t[-110]: \"درخواست از ip مجاز کاربر ارسال نشده است\",\r\n\t[-111]: \"شماره گیرنده در بلک لیست قرار دارد\",\r\n\t[-112]: \"حساب مشتری فعال نیست\",\r\n\t[-115]: \"فرمت UDH اشتباه است\",\r\n\t[-117]: \"مقدار mclass وارد شده اشتباه است\",\r\n\t[-118]: \"شماره پورت وارد شده صحیح نیست\",\r\n\t[-119]: \"کاربر به سرویس مورد نظر دسترسی ندارد\",\r\n\t[-120]: \"پیام ارسال شده دارای هیچ شماره معتبری نیست\",\r\n\t[-200]: \"خطای داخلی در پایگاه داده رخ داده است\",\r\n\t[-201]: \"خطای نامشخص داخل پایگاه داده\",\r\n\t[-137]: \"پیام نباید حاوی کلمات غیرمجاز می باشد\",\r\n} as const;\r\n"],"names":["Vesal","username","password","from","apiUrl","this","_proto","prototype","Api","urlSuffix","method","data","_temp4","response","responseBody","_result","_temp2","_result2","references","VesalError","undefined","_temp","_catch","Promise","resolve","json","then","_response$json","_this","_extends","_temp3","fetch","headers","Accept","body","JSON","stringify","_fetch","e","reject","Send","_ref","recipients","messages","isManyToMany","Array","isArray","length","fill","sendData","destinations","originators","originator","contents","content","result","_result$references","successCount","failCount","map","messageResult","count","success","fail","GetMessageStatus","referencesIds","referenceids","GetReceivedMessages","GetReceivedMessagesCount","GetUserInfo","_Error","statusParam","messageParam","_this7","message","status","Object","keys","vesalErrors","includes","GetStatusText","call","_wrapNativeSuper","Error","_vesalErrors"],"mappings":"y5CAOa,IAAAA,eAMZ,WAAA,SAAAA,EAAYC,EAAkBC,EAAkBC,GAK/C,YAVeC,OAAS,sCAAqCC,KACtDJ,cACAC,EAAAA,KAAAA,cACAC,EAAAA,KAAAA,UAGP,EAAAE,KAAKJ,SAAWA,GAAY,GAC5BI,KAAKH,SAAWA,EAChBG,KAAKF,KAAOA,MAGb,CAAC,IAAAG,EAAAN,EAAAO,UAgKA,OAhKAD,EAUaE,IAAG,SAChBC,EACAC,EACAC,QADyB,IAAzBD,IAAAA,EAAyB,QAAM,IAClBE,IAETC,EAAoBC,EAFXF,WAAAG,YAAAC,EAAAC,GA6Bb,IAAKH,EAAaI,WACjB,MAAM,IAAIC,OAAWC,EAAW,uCAGjC,OAAON,CAAa,KAAAO,EAAAC,EAAA,WAVhBC,OAAAA,QAAAC,QACkBX,EAASY,QAAMC,KAAAC,SAAAA,GAApCb,EAAYa,CAAyB,EACtC,EAAC,WACA,UAAUR,OAAWC,EAAW,sCACjC,UAACC,GAAAA,EAAAK,KAAAL,EAAAK,KAAAV,GAAAA,GAAA,EAAAY,EArBUvB,KAFXM,EAAIkB,EAAA,CAAA,EACAlB,EAAI,CACPV,SAAU2B,EAAK3B,SACfC,SAAU0B,EAAK1B,WACd,IAAA4B,EAAAR,EAEE,WAAA,OAAAC,QAAAC,QACcO,MAASH,EAAKxB,OAAUK,IAAAA,EAAa,CACrDuB,QA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AkBtBA,CAAA,eAAA+D,EAlB8BC,QAiFhB,SAAAH,EAAcL,GAC7B,OAAe,IAAXA,EACI,UAEJC,OAAOC,KAAKC,GAAaC,SAAS,GAAKJ,GACnCG,EAAYH,GAEb,EACR,CAEa,IAYAG,IAAWM,EACvB,CAAA,EAAG,+BACD,KAAM,+BAA8BA,GACpC,KAAM,oCAAmCA,GACzC,KAAM,sBAAqBA,GAC3B,KAAM,0DAAyDA,GAC/D,KAAM,gBAAeA,GACrB,KAAM,0BAAyBA,GAC/B,KAAM,0CAAyCA,GAC/C,KAAM,gCAA+BA,GACrC,KAAM,wCAAuCA,GAC7C,KAAM,0CAAyCA,GAC/C,KAAM,qCAAoCA,GAC1C,KAAM,uBAAsBA,GAC5B,KAAM,sBAAqBA,GAC3B,KAAM,mCAAkCA,GACxC,KAAM,gCAA+BA,GACrC,KAAM,uCAAsCA,GAC5C,KAAM,6CAA4CA,GAClD,KAAM,wCAAuCA,GAC7C,KAAM,+BAA8BA,GACpC,KAAM,wCAAuCA,sFAjCnB,CAC5B,EAAG,8BACH,EAAG,YACH,EAAG,uCACH,EAAG,wCACH,EAAG,eACH,EAAG,yDACH,EAAG,kCACH,EAAG,oCACH,EAAG"}
|
package/dist/vesal.d.ts
CHANGED
package/dist/vesal.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(e=function(){return!!t})()}function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function o(t){var i="function"==typeof Map?new Map:void 0;return o=function(t){if(null===t||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(t))return i.get(t);i.set(t,o)}function o(){return function(t,r,o){if(e())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,r);var s=new(t.bind.apply(t,i));return o&&n(s,o.prototype),s}(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,t)},o(t)}var i;function s(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var c=/*#__PURE__*/function(){function e(e,t,r){return this.apiUrl="http://vesal.armaghan.net:8080/rest",this.username=void 0,this.password=void 0,this.from=void 0,this.username=e||"",this.password=t,this.from=r,this}var r=e.prototype;return r.Api=function(e,r,n){void 0===r&&(r="POST");try{var o,i,c=function(e){function t(e){if(!i.references)throw new a(void 0,"The server didn't respond correctly");return i}var r=s(function(){return Promise.resolve(o.json()).then(function(e){i=e})},function(){throw new a(void 0,"The server didn't respond correctly")});return r&&r.then?r.then(t):t()},u=this;n=t({},n,{username:u.username,password:u.password});var f=s(function(){return Promise.resolve(fetch(u.apiUrl+"/"+e,{headers:{Accept:"application/json","Content-Type":"application/json"},method:r,body:n&&JSON.stringify(n)})).then(function(e){o=e})},function(){throw new a(void 0,"Server connection failed")});return Promise.resolve(f&&f.then?f.then(c):c())}catch(e){return Promise.reject(e)}},r.Send=function(e){var r=e.recipients,n=e.messages,o=e.from;try{if(!r||!n)throw new a(void 0,"recipients and messages should not be empty");"string"==typeof r&&(r=[r]),o||(o=this.from);var i=Array.isArray(n)||Array.isArray(o);if(i){if(!r.length)throw new a(void 0,"recipients and messages should have the same length");if(Array.isArray(n)&&!n.length)throw new a(void 0,"recipients and messages should have the same length");if("string"==typeof n&&(n=Array(r.length).fill(n)),"string"==typeof o&&(o=Array(r.length).fill(o)),r.length!==n.length||r.length!==o.length)throw new a(void 0,"recipients and messages should have the same length")}var s=t({destinations:r},i?{originators:o}:{originator:o},i?{contents:n}:{content:n});return Promise.resolve(this.Api(i?"ManyToMany":"OneToMany","POST",s)).then(function(e){var r,n=0,o=0;return null==(r=e.references)||r.map(function(e){e?n++:o++}),t({},e,{references:e.references||[],count:{success:n,fail:o}})})}catch(e){return Promise.reject(e)}},r.GetMessageStatus=function(e){try{return Promise.resolve(this.Api("messageState","POST",{referenceids:e}))}catch(e){return Promise.reject(e)}},r.GetReceivedMessages=function(){try{return Promise.resolve(this.Api("pullReceivedMessages"))}catch(e){return Promise.reject(e)}},r.GetReceivedMessagesCount=function(){try{return Promise.resolve(this.Api("receivedMessageCount"))}catch(e){return Promise.reject(e)}},r.GetUserInfo=function(){try{return Promise.resolve(this.Api("userInfo"))}catch(e){return Promise.reject(e)}},e}(),a=/*#__PURE__*/function(e){var t,r;function o(t,r){var n,o,i;return t&&Object.keys(h).includes(""+t)?(o=u(t),i=t):(o=r||"Unknown Vesal error",i=void 0),(n=e.call(this,o)||this).status=void 0,n.message=o,n.status=i,n}return r=e,(t=o).prototype=Object.create(r.prototype),t.prototype.constructor=t,n(t,r),o}(/*#__PURE__*/o(Error));function u(e){return 0===e?"success":Object.keys(h).includes(""+e)?h[e]:""}var f={0:"پیامک در صف ارسال قرار دارد",1:"ارسال شده",2:"پیامک به موبایل گیرنده تحویل شده است",3:"پیامک به موبایل گیرنده تحویل نشده است",4:"وضعیت نامشخص",5:"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است",6:"پیام از سمت اپراتور لغو شده است",7:"پیام از سمت اپراتور منقضی شده است",8:"پیام از سمت اپراتور reject شده است"},h=((i={0:"عملیات با موفقیت انجام شد"})[-100]="refrenceId مورد نظر یافت نشد",i[-101]="احراز هویت کاربر موفقیت آمیز نبود",i[-102]="نام کاربری یافت نشد",i[-103]="شماره originator اشتباه یا در بازه شماره های کاربر نیست",i[-104]="اعتبار کم است",i[-105]="فرمت درخواست اشتباه است",i[-106]="تعداد refrenceId ها بیش از 1000 عدد است",i[-107]="شماره گیرنده پیامک اشتباه است",i[-109]="تاریخ انقضای حساب کاربری فرارسیده است",i[-110]="درخواست از ip مجاز کاربر ارسال نشده است",i[-111]="شماره گیرنده در بلک لیست قرار دارد",i[-112]="حساب مشتری فعال نیست",i[-115]="فرمت UDH اشتباه است",i[-117]="مقدار mclass وارد شده اشتباه است",i[-118]="شماره پورت وارد شده صحیح نیست",i[-119]="کاربر به سرویس مورد نظر دسترسی ندارد",i[-120]="پیام ارسال شده دارای هیچ شماره معتبری نیست",i[-200]="خطای داخلی در پایگاه داده رخ داده است",i[-201]="خطای نامشخص داخل پایگاه داده",i[-137]="پیام نباید حاوی کلمات غیرمجاز می باشد",i);export{u as GetStatusText,c as Vesal,a as VesalError,
|
|
1
|
+
function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(e=function(){return!!t})()}function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function o(t){var i="function"==typeof Map?new Map:void 0;return o=function(t){if(null===t||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(t))return i.get(t);i.set(t,o)}function o(){return function(t,r,o){if(e())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,r);var s=new(t.bind.apply(t,i));return o&&n(s,o.prototype),s}(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,t)},o(t)}var i;function s(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var c=/*#__PURE__*/function(){function e(e,t,r){return this.apiUrl="http://vesal.armaghan.net:8080/rest",this.username=void 0,this.password=void 0,this.from=void 0,this.username=e||"",this.password=t,this.from=r,this}var r=e.prototype;return r.Api=function(e,r,n){void 0===r&&(r="POST");try{var o,i,c=function(e){function t(e){if(!i.references)throw new a(void 0,"The server didn't respond correctly");return i}var r=s(function(){return Promise.resolve(o.json()).then(function(e){i=e})},function(){throw new a(void 0,"The server didn't respond correctly")});return r&&r.then?r.then(t):t()},u=this;n=t({},n,{username:u.username,password:u.password});var f=s(function(){return Promise.resolve(fetch(u.apiUrl+"/"+e,{headers:{Accept:"application/json","Content-Type":"application/json"},method:r,body:n&&JSON.stringify(n)})).then(function(e){o=e})},function(){throw new a(void 0,"Server connection failed")});return Promise.resolve(f&&f.then?f.then(c):c())}catch(e){return Promise.reject(e)}},r.Send=function(e){var r=e.recipients,n=e.messages,o=e.from;try{if(!r||!n)throw new a(void 0,"recipients and messages should not be empty");"string"==typeof r&&(r=[r]),o||(o=this.from);var i=Array.isArray(n)||Array.isArray(o);if(i){if(!r.length)throw new a(void 0,"recipients and messages should have the same length");if(Array.isArray(n)&&!n.length)throw new a(void 0,"recipients and messages should have the same length");if("string"==typeof n&&(n=Array(r.length).fill(n)),"string"==typeof o&&(o=Array(r.length).fill(o)),r.length!==n.length||r.length!==o.length)throw new a(void 0,"recipients and messages should have the same length")}var s=t({destinations:r},i?{originators:o}:{originator:o},i?{contents:n}:{content:n});return Promise.resolve(this.Api(i?"ManyToMany":"OneToMany","POST",s)).then(function(e){var r,n=0,o=0;return null==(r=e.references)||r.map(function(e){e?n++:o++}),t({},e,{references:e.references||[],count:{success:n,fail:o}})})}catch(e){return Promise.reject(e)}},r.GetMessageStatus=function(e){try{return Promise.resolve(this.Api("messageState","POST",{referenceids:e}))}catch(e){return Promise.reject(e)}},r.GetReceivedMessages=function(){try{return Promise.resolve(this.Api("pullReceivedMessages"))}catch(e){return Promise.reject(e)}},r.GetReceivedMessagesCount=function(){try{return Promise.resolve(this.Api("receivedMessageCount"))}catch(e){return Promise.reject(e)}},r.GetUserInfo=function(){try{return Promise.resolve(this.Api("userInfo"))}catch(e){return Promise.reject(e)}},e}(),a=/*#__PURE__*/function(e){var t,r;function o(t,r){var n,o,i;return t&&Object.keys(h).includes(""+t)?(o=u(t),i=t):(o=r||"Unknown Vesal error",i=void 0),(n=e.call(this,o)||this).status=void 0,n.message=o,n.status=i,n}return r=e,(t=o).prototype=Object.create(r.prototype),t.prototype.constructor=t,n(t,r),o}(/*#__PURE__*/o(Error));function u(e){return 0===e?"success":Object.keys(h).includes(""+e)?h[e]:""}var f={0:"پیامک در صف ارسال قرار دارد",1:"ارسال شده",2:"پیامک به موبایل گیرنده تحویل شده است",3:"پیامک به موبایل گیرنده تحویل نشده است",4:"وضعیت نامشخص",5:"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است",6:"پیام از سمت اپراتور لغو شده است",7:"پیام از سمت اپراتور منقضی شده است",8:"پیام از سمت اپراتور reject شده است"},h=((i={0:"عملیات با موفقیت انجام شد"})[-100]="refrenceId مورد نظر یافت نشد",i[-101]="احراز هویت کاربر موفقیت آمیز نبود",i[-102]="نام کاربری یافت نشد",i[-103]="شماره originator اشتباه یا در بازه شماره های کاربر نیست",i[-104]="اعتبار کم است",i[-105]="فرمت درخواست اشتباه است",i[-106]="تعداد refrenceId ها بیش از 1000 عدد است",i[-107]="شماره گیرنده پیامک اشتباه است",i[-109]="تاریخ انقضای حساب کاربری فرارسیده است",i[-110]="درخواست از ip مجاز کاربر ارسال نشده است",i[-111]="شماره گیرنده در بلک لیست قرار دارد",i[-112]="حساب مشتری فعال نیست",i[-115]="فرمت UDH اشتباه است",i[-117]="مقدار mclass وارد شده اشتباه است",i[-118]="شماره پورت وارد شده صحیح نیست",i[-119]="کاربر به سرویس مورد نظر دسترسی ندارد",i[-120]="پیام ارسال شده دارای هیچ شماره معتبری نیست",i[-200]="خطای داخلی در پایگاه داده رخ داده است",i[-201]="خطای نامشخص داخل پایگاه داده",i[-137]="پیام نباید حاوی کلمات غیرمجاز می باشد",i);export{u as GetStatusText,c as Vesal,a as VesalError,f as messageStates,h as vesalErrors};
|
|
2
2
|
//# sourceMappingURL=vesal.mjs.map
|
package/dist/vesal.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vesal.mjs","sources":["../src/vesal.ts"],"sourcesContent":["/**\r\n * The Vesal API Class\r\n * @author Shahab Movahhedi\r\n * @see {@link https://shmovahhedi.com Shahab Movahhedi's Website}\r\n * @see {@link https://github.com/movahhedi/vesal vesal's Repository}\r\n * @license MIT\r\n */\r\nexport class Vesal {\r\n\tpublic readonly apiUrl = \"http://vesal.armaghan.net:8080/rest\";\r\n\tprivate username: string;\r\n\tprivate password: string;\r\n\tprivate from: string;\r\n\r\n\tconstructor(username: string, password: string, from: string) {\r\n\t\tthis.username = username || \"\";\r\n\t\tthis.password = password;\r\n\t\tthis.from = from;\r\n\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Make an API request to the Vesal API\r\n\t * @private\r\n\t * @param {string} urlSuffix - The URL suffix for the API endpoint\r\n\t * @param {(\"GET\"|\"POST\")} [method=\"GET\"] - The HTTP method to use for the request\r\n\t * @param {object|null} [data=null] - The data to send with the request\r\n\t * @returns {Promise} The response from the API\r\n\t */\r\n\tprivate async Api(\r\n\t\turlSuffix: string,\r\n\t\tmethod: \"GET\" | \"POST\" = \"POST\",\r\n\t\tdata?: object,\r\n\t): Promise<any> {\r\n\t\tlet response: Response, responseBody: any;\r\n\r\n\t\tdata = {\r\n\t\t\t...data,\r\n\t\t\tusername: this.username,\r\n\t\t\tpassword: this.password,\r\n\t\t};\r\n\r\n\t\ttry {\r\n\t\t\tresponse = await fetch(`${this.apiUrl}/${urlSuffix}`, {\r\n\t\t\t\theaders: {\r\n\t\t\t\t\tAccept: \"application/json\",\r\n\t\t\t\t\t\"Content-Type\": \"application/json\",\r\n\t\t\t\t},\r\n\t\t\t\tmethod,\r\n\t\t\t\tbody: data && JSON.stringify(data),\r\n\t\t\t});\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"Server connection failed\");\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tresponseBody = await response.json();\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\tif (!responseBody.references) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\treturn responseBody;\r\n\t}\r\n\r\n\tasync Send({\r\n\t\trecipients,\r\n\t\tmessages,\r\n\t\tfrom,\r\n\t}: {\r\n\t\trecipients: string | string[];\r\n\t\tmessages: string | string[];\r\n\t\tfrom?: string | string[];\r\n\t}): Promise<IVesalResponse_Send_WithCount> {\r\n\t\tif (!recipients || !messages) {\r\n\t\t\tthrow new VesalError(\r\n\t\t\t\tundefined,\r\n\t\t\t\t\"recipients and messages should not be empty\",\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif (typeof recipients === \"string\") {\r\n\t\t\trecipients = [recipients];\r\n\t\t}\r\n\r\n\t\tif (!from) {\r\n\t\t\tfrom = this.from;\r\n\t\t}\r\n\r\n\t\tconst isManyToMany = Array.isArray(messages) || Array.isArray(from);\r\n\r\n\t\tif (isManyToMany) {\r\n\t\t\tif (!recipients.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t\tif (Array.isArray(messages) && !messages.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (typeof messages === \"string\") {\r\n\t\t\t\t// messages = recipients.map(() => messages);\r\n\t\t\t\tmessages = Array(recipients.length).fill(messages);\r\n\t\t\t}\r\n\t\t\tif (typeof from === \"string\") {\r\n\t\t\t\t// from = recipients.map(() => from);\r\n\t\t\t\tfrom = Array(recipients.length).fill(from);\r\n\t\t\t}\r\n\r\n\t\t\tif (\r\n\t\t\t\trecipients.length !== messages.length ||\r\n\t\t\t\trecipients.length !== from.length\r\n\t\t\t) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst sendData = {\r\n\t\t\tdestinations: recipients,\r\n\t\t\t...(isManyToMany ? { originators: from } : { originator: from }),\r\n\t\t\t...(isManyToMany ? { contents: messages } : { content: messages }),\r\n\t\t};\r\n\r\n\t\tconst result: IVesalResponse_Send = await this.Api(\r\n\t\t\tisManyToMany ? \"ManyToMany\" : \"OneToMany\",\r\n\t\t\t\"POST\",\r\n\t\t\tsendData,\r\n\t\t);\r\n\r\n\t\tlet successCount: number = 0,\r\n\t\t\tfailCount: number = 0;\r\n\r\n\t\tresult.references?.map((messageResult) => {\r\n\t\t\tif (messageResult) {\r\n\t\t\t\tsuccessCount++;\r\n\t\t\t} else {\r\n\t\t\t\tfailCount++;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn {\r\n\t\t\t...result,\r\n\t\t\treferences: result.references || [],\r\n\t\t\tcount: {\r\n\t\t\t\tsuccess: successCount,\r\n\t\t\t\tfail: failCount,\r\n\t\t\t},\r\n\t\t};\r\n\t}\r\n\r\n\tasync GetMessageStatus(\r\n\t\treferencesIds: number[],\r\n\t): Promise<IVesalResponse_MessageState> {\r\n\t\treturn await this.Api(\"messageState\", \"POST\", {\r\n\t\t\treferenceids: referencesIds,\r\n\t\t});\r\n\t}\r\n\r\n\tasync GetReceivedMessages(): Promise<IVesalResponse_ReceivedMessages> {\r\n\t\treturn await this.Api(\"pullReceivedMessages\");\r\n\t}\r\n\r\n\tasync GetReceivedMessagesCount(): Promise<IVesalResponse_ReceivedMessagesCount> {\r\n\t\treturn await this.Api(\"receivedMessageCount\");\r\n\t}\r\n\r\n\tasync GetUserInfo(): Promise<IVesalResponse_UserInfo> {\r\n\t\treturn await this.Api(\"userInfo\");\r\n\t}\r\n}\r\n\r\nexport class VesalError extends Error {\r\n\tstatus: keyof typeof vesalErrors | undefined;\r\n\r\n\tconstructor(statusParam: number | undefined, messageParam?: string) {\r\n\t\tlet message: string, status: keyof typeof vesalErrors | undefined;\r\n\r\n\t\tif (statusParam && Object.keys(vesalErrors).includes(\"\" + statusParam)) {\r\n\t\t\tmessage = GetStatusText(statusParam);\r\n\t\t\tstatus = statusParam as any;\r\n\t\t} else {\r\n\t\t\tmessage = messageParam || \"Unknown Vesal error\";\r\n\t\t\tstatus = undefined;\r\n\t\t}\r\n\r\n\t\tsuper(message);\r\n\r\n\t\tthis.message = message;\r\n\t\tthis.status = status;\r\n\t}\r\n}\r\n\r\ninterface IVesalResponse_Base {\r\n\terrorModel: {\r\n\t\terrorCode: number;\r\n\t\ttimestamp: string | number | null;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_Send extends IVesalResponse_Base {\r\n\treferences: (number | Omit<keyof typeof vesalErrors, 0>)[];\r\n}\r\n\r\ninterface IVesalResponse_Send_WithCount extends IVesalResponse_Send {\r\n\tcount: {\r\n\t\tsuccess: number;\r\n\t\tfail: number;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_MessageState extends IVesalResponse_Base {\r\n\tstates: {\r\n\t\tid: number;\r\n\t\tstate: number;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessages extends IVesalResponse_Base {\r\n\tmessageModels: {\r\n\t\toriginator: string;\r\n\t\tdestination: string;\r\n\t\tcontent: string;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessagesCount extends IVesalResponse_Base {\r\n\tcount: number;\r\n}\r\ninterface IVesalResponse_UserInfo extends IVesalResponse_Base {\r\n\tuser: {\r\n\t\tcredit: number;\r\n\t\tdeliveryUrl: unknown;\r\n\t\treceiveUrl: unknown;\r\n\t\tiPs: string[];\r\n\t\tnumbers: string[];\r\n\t\tid: number;\r\n\t\tusername: string;\r\n\t\tpassword: unknown;\r\n\t\tfirstName: unknown;\r\n\t\tlastName: unknown;\r\n\t\tmobile: unknown;\r\n\t\temail: unknown;\r\n\t\tnationalId: number;\r\n\t\texpirationDate: string;\r\n\t\tactive: boolean;\r\n\t\tdeleted: boolean;\r\n\t\tdbProxyStandalone: boolean;\r\n\t\tinsertDate: unknown;\r\n\t\tupdateDate: unknown;\r\n\t\tcustomer: unknown;\r\n\t\troles: unknown;\r\n\t};\r\n}\r\n\r\nexport function GetStatusText(status: number) {\r\n\tif (status === 0) {\r\n\t\treturn \"success\";\r\n\t}\r\n\tif (Object.keys(vesalErrors).includes(\"\" + status)) {\r\n\t\treturn vesalErrors[status];\r\n\t}\r\n\treturn \"\";\r\n}\r\n\r\nexport const messageStates = {\r\n\t0: \"پیامک در صف ارسال قرار دارد\",\r\n\t1: \"ارسال شده\",\r\n\t2: \"پیامک به موبایل گیرنده تحویل شده است\",\r\n\t3: \"پیامک به موبایل گیرنده تحویل نشده است\",\r\n\t4: \"وضعیت نامشخص\",\r\n\t5: \"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است\",\r\n\t6: \"پیام از سمت اپراتور لغو شده است\",\r\n\t7: \"پیام از سمت اپراتور منقضی شده است\",\r\n\t8: \"پیام از سمت اپراتور reject شده است\",\r\n} as const;\r\n\r\nexport const vesalErrors = {\r\n\t0: \"عملیات با موفقیت انجام شد\",\r\n\t[-100]: \"refrenceId مورد نظر یافت نشد\",\r\n\t[-101]: \"احراز هویت کاربر موفقیت آمیز نبود\",\r\n\t[-102]: \"نام کاربری یافت نشد\",\r\n\t[-103]: \"شماره originator اشتباه یا در بازه شماره های کاربر نیست\",\r\n\t[-104]: \"اعتبار کم است\",\r\n\t[-105]: \"فرمت درخواست اشتباه است\",\r\n\t[-106]: \"تعداد refrenceId ها بیش از 1000 عدد است\",\r\n\t[-107]: \"شماره گیرنده پیامک اشتباه است\",\r\n\t[-109]: \"تاریخ انقضای حساب کاربری فرارسیده است\",\r\n\t[-110]: \"درخواست از ip مجاز کاربر ارسال نشده است\",\r\n\t[-111]: \"شماره گیرنده در بلک لیست قرار دارد\",\r\n\t[-112]: \"حساب مشتری فعال نیست\",\r\n\t[-115]: \"فرمت UDH اشتباه است\",\r\n\t[-117]: \"مقدار mclass وارد شده اشتباه است\",\r\n\t[-118]: \"شماره پورت وارد شده صحیح نیست\",\r\n\t[-119]: \"کاربر به سرویس مورد نظر دسترسی ندارد\",\r\n\t[-120]: \"پیام ارسال شده دارای هیچ شماره معتبری نیست\",\r\n\t[-200]: \"خطای داخلی در پایگاه داده رخ داده است\",\r\n\t[-201]: \"خطای نامشخص داخل پایگاه داده\",\r\n\t[-137]: \"پیام نباید حاوی کلمات غیرمجاز می باشد\",\r\n} as const;\r\n\r\nexport default Vesal;\r\n"],"names":["Vesal","username","password","from","this","apiUrl","_proto","prototype","Api","urlSuffix","method","data","response","responseBody","_temp4","_result","_temp2","_result2","references","VesalError","undefined","_temp","_catch","Promise","resolve","json","then","_response$json","_exit","_this","_extends","_temp3","fetch","headers","Accept","body","JSON","stringify","_fetch","e","reject","Send","_ref","recipients","messages","isManyToMany","Array","isArray","length","fill","sendData","destinations","originators","originator","contents","content","result","_result$references","successCount","failCount","map","messageResult","count","success","fail","GetMessageStatus","referencesIds","referenceids","GetReceivedMessages","GetReceivedMessagesCount","GetUserInfo","_Error","statusParam","messageParam","_this7","message","status","Object","keys","vesalErrors","includes","GetStatusText","call","_wrapNativeSuper","Error","messageStates","_vesalErrors"],"mappings":"y5CAOa,IAAAA,eAAK,WAMjB,SAAAA,EAAYC,EAAkBC,EAAkBC,GAK/C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AM,0DAAyDA,GAC/D,KAAM,gBAAeA,GACrB,KAAM,0BAAyBA,GAC/B,KAAM,0CAAyCA,GAC/C,KAAM,gCAA+BA,GACrC,KAAM,wCAAuCA,GAC7C,KAAM,0CAAyCA,GAC/C,KAAM,qCAAoCA,GAC1C,KAAM,uBAAsBA,GAC5B,KAAM,sBAAqBA,GAC3B,KAAM,mCAAkCA,GACxC,KAAM,gCAA+BA,GACrC,KAAM,uCAAsCA,GAC5C,KAAM,6CAA4CA,GAClD,KAAM,wCAAuCA,GAC7C,KAAM,+BAA8BA,GACpC,KAAM,wCAAuCA"}
|
|
1
|
+
{"version":3,"file":"vesal.mjs","sources":["../src/vesal.ts"],"sourcesContent":["/**\r\n * The Vesal API Class\r\n * @author Shahab Movahhedi\r\n * @see {@link https://shmovahhedi.com Shahab Movahhedi's Website}\r\n * @see {@link https://github.com/movahhedi/vesal vesal's Repository}\r\n * @license MIT\r\n */\r\nexport class Vesal {\r\n\tpublic readonly apiUrl = \"http://vesal.armaghan.net:8080/rest\";\r\n\tprivate username: string;\r\n\tprivate password: string;\r\n\tprivate from: string;\r\n\r\n\tconstructor(username: string, password: string, from: string) {\r\n\t\tthis.username = username || \"\";\r\n\t\tthis.password = password;\r\n\t\tthis.from = from;\r\n\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Make an API request to the Vesal API\r\n\t * @private\r\n\t * @param {string} urlSuffix - The URL suffix for the API endpoint\r\n\t * @param {(\"GET\"|\"POST\")} [method=\"GET\"] - The HTTP method to use for the request\r\n\t * @param {object|null} [data=null] - The data to send with the request\r\n\t * @returns {Promise} The response from the API\r\n\t */\r\n\tprivate async Api(\r\n\t\turlSuffix: string,\r\n\t\tmethod: \"GET\" | \"POST\" = \"POST\",\r\n\t\tdata?: object,\r\n\t): Promise<any> {\r\n\t\tlet response: Response, responseBody: any;\r\n\r\n\t\tdata = {\r\n\t\t\t...data,\r\n\t\t\tusername: this.username,\r\n\t\t\tpassword: this.password,\r\n\t\t};\r\n\r\n\t\ttry {\r\n\t\t\tresponse = await fetch(`${this.apiUrl}/${urlSuffix}`, {\r\n\t\t\t\theaders: {\r\n\t\t\t\t\tAccept: \"application/json\",\r\n\t\t\t\t\t\"Content-Type\": \"application/json\",\r\n\t\t\t\t},\r\n\t\t\t\tmethod,\r\n\t\t\t\tbody: data && JSON.stringify(data),\r\n\t\t\t});\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"Server connection failed\");\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tresponseBody = await response.json();\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\tif (!responseBody.references) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\treturn responseBody;\r\n\t}\r\n\r\n\tasync Send({\r\n\t\trecipients,\r\n\t\tmessages,\r\n\t\tfrom,\r\n\t}: {\r\n\t\trecipients: string | string[];\r\n\t\tmessages: string | string[];\r\n\t\tfrom?: string | string[];\r\n\t}): Promise<IVesalResponse_Send_WithCount> {\r\n\t\tif (!recipients || !messages) {\r\n\t\t\tthrow new VesalError(\r\n\t\t\t\tundefined,\r\n\t\t\t\t\"recipients and messages should not be empty\",\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif (typeof recipients === \"string\") {\r\n\t\t\trecipients = [recipients];\r\n\t\t}\r\n\r\n\t\tif (!from) {\r\n\t\t\tfrom = this.from;\r\n\t\t}\r\n\r\n\t\tconst isManyToMany = Array.isArray(messages) || Array.isArray(from);\r\n\r\n\t\tif (isManyToMany) {\r\n\t\t\tif (!recipients.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t\tif (Array.isArray(messages) && !messages.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (typeof messages === \"string\") {\r\n\t\t\t\t// messages = recipients.map(() => messages);\r\n\t\t\t\tmessages = Array(recipients.length).fill(messages);\r\n\t\t\t}\r\n\t\t\tif (typeof from === \"string\") {\r\n\t\t\t\t// from = recipients.map(() => from);\r\n\t\t\t\tfrom = Array(recipients.length).fill(from);\r\n\t\t\t}\r\n\r\n\t\t\tif (\r\n\t\t\t\trecipients.length !== messages.length ||\r\n\t\t\t\trecipients.length !== from.length\r\n\t\t\t) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst sendData = {\r\n\t\t\tdestinations: recipients,\r\n\t\t\t...(isManyToMany ? { originators: from } : { originator: from }),\r\n\t\t\t...(isManyToMany ? { contents: messages } : { content: messages }),\r\n\t\t};\r\n\r\n\t\tconst result: IVesalResponse_Send = await this.Api(\r\n\t\t\tisManyToMany ? \"ManyToMany\" : \"OneToMany\",\r\n\t\t\t\"POST\",\r\n\t\t\tsendData,\r\n\t\t);\r\n\r\n\t\tlet successCount: number = 0,\r\n\t\t\tfailCount: number = 0;\r\n\r\n\t\tresult.references?.map((messageResult) => {\r\n\t\t\tif (messageResult) {\r\n\t\t\t\tsuccessCount++;\r\n\t\t\t} else {\r\n\t\t\t\tfailCount++;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn {\r\n\t\t\t...result,\r\n\t\t\treferences: result.references || [],\r\n\t\t\tcount: {\r\n\t\t\t\tsuccess: successCount,\r\n\t\t\t\tfail: failCount,\r\n\t\t\t},\r\n\t\t};\r\n\t}\r\n\r\n\tasync GetMessageStatus(\r\n\t\treferencesIds: number[],\r\n\t): Promise<IVesalResponse_MessageState> {\r\n\t\treturn await this.Api(\"messageState\", \"POST\", {\r\n\t\t\treferenceids: referencesIds,\r\n\t\t});\r\n\t}\r\n\r\n\tasync GetReceivedMessages(): Promise<IVesalResponse_ReceivedMessages> {\r\n\t\treturn await this.Api(\"pullReceivedMessages\");\r\n\t}\r\n\r\n\tasync GetReceivedMessagesCount(): Promise<IVesalResponse_ReceivedMessagesCount> {\r\n\t\treturn await this.Api(\"receivedMessageCount\");\r\n\t}\r\n\r\n\tasync GetUserInfo(): Promise<IVesalResponse_UserInfo> {\r\n\t\treturn await this.Api(\"userInfo\");\r\n\t}\r\n}\r\n\r\nexport class VesalError extends Error {\r\n\tstatus: keyof typeof vesalErrors | undefined;\r\n\r\n\tconstructor(statusParam: number | undefined, messageParam?: string) {\r\n\t\tlet message: string, status: keyof typeof vesalErrors | undefined;\r\n\r\n\t\tif (statusParam && Object.keys(vesalErrors).includes(\"\" + statusParam)) {\r\n\t\t\tmessage = GetStatusText(statusParam);\r\n\t\t\tstatus = statusParam as any;\r\n\t\t} else {\r\n\t\t\tmessage = messageParam || \"Unknown Vesal error\";\r\n\t\t\tstatus = undefined;\r\n\t\t}\r\n\r\n\t\tsuper(message);\r\n\r\n\t\tthis.message = message;\r\n\t\tthis.status = status;\r\n\t}\r\n}\r\n\r\ninterface IVesalResponse_Base {\r\n\terrorModel: {\r\n\t\terrorCode: number;\r\n\t\ttimestamp: string | number | null;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_Send extends IVesalResponse_Base {\r\n\treferences: (number | Omit<keyof typeof vesalErrors, 0>)[];\r\n}\r\n\r\ninterface IVesalResponse_Send_WithCount extends IVesalResponse_Send {\r\n\tcount: {\r\n\t\tsuccess: number;\r\n\t\tfail: number;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_MessageState extends IVesalResponse_Base {\r\n\tstates: {\r\n\t\tid: number;\r\n\t\tstate: number;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessages extends IVesalResponse_Base {\r\n\tmessageModels: {\r\n\t\toriginator: string;\r\n\t\tdestination: string;\r\n\t\tcontent: string;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessagesCount extends IVesalResponse_Base {\r\n\tcount: number;\r\n}\r\ninterface IVesalResponse_UserInfo extends IVesalResponse_Base {\r\n\tuser: {\r\n\t\tcredit: number;\r\n\t\tdeliveryUrl: unknown;\r\n\t\treceiveUrl: unknown;\r\n\t\tiPs: string[];\r\n\t\tnumbers: string[];\r\n\t\tid: number;\r\n\t\tusername: string;\r\n\t\tpassword: unknown;\r\n\t\tfirstName: unknown;\r\n\t\tlastName: unknown;\r\n\t\tmobile: unknown;\r\n\t\temail: unknown;\r\n\t\tnationalId: number;\r\n\t\texpirationDate: string;\r\n\t\tactive: boolean;\r\n\t\tdeleted: boolean;\r\n\t\tdbProxyStandalone: boolean;\r\n\t\tinsertDate: unknown;\r\n\t\tupdateDate: unknown;\r\n\t\tcustomer: unknown;\r\n\t\troles: unknown;\r\n\t};\r\n}\r\n\r\nexport function GetStatusText(status: number) {\r\n\tif (status === 0) {\r\n\t\treturn \"success\";\r\n\t}\r\n\tif (Object.keys(vesalErrors).includes(\"\" + status)) {\r\n\t\treturn vesalErrors[status];\r\n\t}\r\n\treturn \"\";\r\n}\r\n\r\nexport const messageStates = {\r\n\t0: \"پیامک در صف ارسال قرار دارد\",\r\n\t1: \"ارسال شده\",\r\n\t2: \"پیامک به موبایل گیرنده تحویل شده است\",\r\n\t3: \"پیامک به موبایل گیرنده تحویل نشده است\",\r\n\t4: \"وضعیت نامشخص\",\r\n\t5: \"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است\",\r\n\t6: \"پیام از سمت اپراتور لغو شده است\",\r\n\t7: \"پیام از سمت اپراتور منقضی شده است\",\r\n\t8: \"پیام از سمت اپراتور reject شده است\",\r\n} as const;\r\n\r\nexport const vesalErrors = {\r\n\t0: \"عملیات با موفقیت انجام شد\",\r\n\t[-100]: \"refrenceId مورد نظر یافت نشد\",\r\n\t[-101]: \"احراز هویت کاربر موفقیت آمیز نبود\",\r\n\t[-102]: \"نام کاربری یافت نشد\",\r\n\t[-103]: \"شماره originator اشتباه یا در بازه شماره های کاربر نیست\",\r\n\t[-104]: \"اعتبار کم است\",\r\n\t[-105]: \"فرمت درخواست اشتباه است\",\r\n\t[-106]: \"تعداد refrenceId ها بیش از 1000 عدد است\",\r\n\t[-107]: \"شماره گیرنده پیامک اشتباه است\",\r\n\t[-109]: \"تاریخ انقضای حساب کاربری فرارسیده است\",\r\n\t[-110]: \"درخواست از ip مجاز کاربر ارسال نشده است\",\r\n\t[-111]: \"شماره گیرنده در بلک لیست قرار دارد\",\r\n\t[-112]: \"حساب مشتری فعال نیست\",\r\n\t[-115]: \"فرمت UDH اشتباه است\",\r\n\t[-117]: \"مقدار mclass وارد شده اشتباه است\",\r\n\t[-118]: \"شماره پورت وارد شده صحیح نیست\",\r\n\t[-119]: \"کاربر به سرویس مورد نظر دسترسی ندارد\",\r\n\t[-120]: \"پیام ارسال شده دارای هیچ شماره معتبری نیست\",\r\n\t[-200]: \"خطای داخلی در پایگاه داده رخ داده است\",\r\n\t[-201]: \"خطای نامشخص داخل پایگاه داده\",\r\n\t[-137]: \"پیام نباید حاوی کلمات غیرمجاز می باشد\",\r\n} as const;\r\n"],"names":["Vesal","username","password","from","apiUrl","this","_proto","prototype","Api","urlSuffix","method","data","_temp4","response","responseBody","_result","_temp2","_result2","references","VesalError","undefined","_temp","_catch","Promise","resolve","json","then","_response$json","_this","_extends","_temp3","fetch","headers","Accept","body","JSON","stringify","_fetch","e","reject","Send","_ref","recipients","messages","isManyToMany","Array","isArray","length","fill","sendData","destinations","originators","originator","contents","content","result","_result$references","successCount","failCount","map","messageResult","count","success","fail","GetMessageStatus","referencesIds","referenceids","GetReceivedMessages","GetReceivedMessagesCount","GetUserInfo","_Error","statusParam","messageParam","_this7","message","status","Object","keys","vesalErrors","includes","GetStatusText","call","_wrapNativeSuper","Error","messageStates","_vesalErrors"],"mappings":"y5CAOa,IAAAA,eAMZ,WAAA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,GAC/D,KAAM,gBAAeA,GACrB,KAAM,0BAAyBA,GAC/B,KAAM,0CAAyCA,GAC/C,KAAM,gCAA+BA,GACrC,KAAM,wCAAuCA,GAC7C,KAAM,0CAAyCA,GAC/C,KAAM,qCAAoCA,GAC1C,KAAM,uBAAsBA,GAC5B,KAAM,sBAAqBA,GAC3B,KAAM,mCAAkCA,GACxC,KAAM,gCAA+BA,GACrC,KAAM,uCAAsCA,GAC5C,KAAM,6CAA4CA,GAClD,KAAM,wCAAuCA,GAC7C,KAAM,+BAA8BA,GACpC,KAAM,wCAAuCA"}
|
package/dist/vesal.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).vesal={})}(this,function(e){function t(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(t=function(){return!!e})()}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},r.apply(this,arguments)}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function i(e){var r="function"==typeof Map?new Map:void 0;return i=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,i)}function i(){return function(e,r,n){if(t())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,r);var s=new(e.bind.apply(e,i));return n&&o(s,n.prototype),s}(e,arguments,n(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,e)},i(e)}var s;function c(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var a=/*#__PURE__*/function(){function e(e,t,r){return this.apiUrl="http://vesal.armaghan.net:8080/rest",this.username=void 0,this.password=void 0,this.from=void 0,this.username=e||"",this.password=t,this.from=r,this}var t=e.prototype;return t.Api=function(e,t,n){void 0===t&&(t="POST");try{var o,i,s=function(e){function t(e){if(!i.references)throw new u(void 0,"The server didn't respond correctly");return i}var r=c(function(){return Promise.resolve(o.json()).then(function(e){i=e})},function(){throw new u(void 0,"The server didn't respond correctly")});return r&&r.then?r.then(t):t()},a=this;n=r({},n,{username:a.username,password:a.password});var f=c(function(){return Promise.resolve(fetch(a.apiUrl+"/"+e,{headers:{Accept:"application/json","Content-Type":"application/json"},method:t,body:n&&JSON.stringify(n)})).then(function(e){o=e})},function(){throw new u(void 0,"Server connection failed")});return Promise.resolve(f&&f.then?f.then(s):s())}catch(e){return Promise.reject(e)}},t.Send=function(e){var t=e.recipients,n=e.messages,o=e.from;try{if(!t||!n)throw new u(void 0,"recipients and messages should not be empty");"string"==typeof t&&(t=[t]),o||(o=this.from);var i=Array.isArray(n)||Array.isArray(o);if(i){if(!t.length)throw new u(void 0,"recipients and messages should have the same length");if(Array.isArray(n)&&!n.length)throw new u(void 0,"recipients and messages should have the same length");if("string"==typeof n&&(n=Array(t.length).fill(n)),"string"==typeof o&&(o=Array(t.length).fill(o)),t.length!==n.length||t.length!==o.length)throw new u(void 0,"recipients and messages should have the same length")}var s=r({destinations:t},i?{originators:o}:{originator:o},i?{contents:n}:{content:n});return Promise.resolve(this.Api(i?"ManyToMany":"OneToMany","POST",s)).then(function(e){var t,n=0,o=0;return null==(t=e.references)||t.map(function(e){e?n++:o++}),r({},e,{references:e.references||[],count:{success:n,fail:o}})})}catch(e){return Promise.reject(e)}},t.GetMessageStatus=function(e){try{return Promise.resolve(this.Api("messageState","POST",{referenceids:e}))}catch(e){return Promise.reject(e)}},t.GetReceivedMessages=function(){try{return Promise.resolve(this.Api("pullReceivedMessages"))}catch(e){return Promise.reject(e)}},t.GetReceivedMessagesCount=function(){try{return Promise.resolve(this.Api("receivedMessageCount"))}catch(e){return Promise.reject(e)}},t.GetUserInfo=function(){try{return Promise.resolve(this.Api("userInfo"))}catch(e){return Promise.reject(e)}},e}(),u=/*#__PURE__*/function(e){var t,r;function n(t,r){var n,o,i;return t&&Object.keys(l).includes(""+t)?(o=f(t),i=t):(o=r||"Unknown Vesal error",i=void 0),(n=e.call(this,o)||this).status=void 0,n.message=o,n.status=i,n}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,o(t,r),n}(/*#__PURE__*/i(Error));function f(e){return 0===e?"success":Object.keys(l).includes(""+e)?l[e]:""}var l=((s={0:"عملیات با موفقیت انجام شد"})[-100]="refrenceId مورد نظر یافت نشد",s[-101]="احراز هویت کاربر موفقیت آمیز نبود",s[-102]="نام کاربری یافت نشد",s[-103]="شماره originator اشتباه یا در بازه شماره های کاربر نیست",s[-104]="اعتبار کم است",s[-105]="فرمت درخواست اشتباه است",s[-106]="تعداد refrenceId ها بیش از 1000 عدد است",s[-107]="شماره گیرنده پیامک اشتباه است",s[-109]="تاریخ انقضای حساب کاربری فرارسیده است",s[-110]="درخواست از ip مجاز کاربر ارسال نشده است",s[-111]="شماره گیرنده در بلک لیست قرار دارد",s[-112]="حساب مشتری فعال نیست",s[-115]="فرمت UDH اشتباه است",s[-117]="مقدار mclass وارد شده اشتباه است",s[-118]="شماره پورت وارد شده صحیح نیست",s[-119]="کاربر به سرویس مورد نظر دسترسی ندارد",s[-120]="پیام ارسال شده دارای هیچ شماره معتبری نیست",s[-200]="خطای داخلی در پایگاه داده رخ داده است",s[-201]="خطای نامشخص داخل پایگاه داده",s[-137]="پیام نباید حاوی کلمات غیرمجاز می باشد",s);e.GetStatusText=f,e.Vesal=a,e.VesalError=u,e.
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).vesal={})}(this,function(e){function t(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(t=function(){return!!e})()}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},r.apply(this,arguments)}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function i(e){var r="function"==typeof Map?new Map:void 0;return i=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,i)}function i(){return function(e,r,n){if(t())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,r);var s=new(e.bind.apply(e,i));return n&&o(s,n.prototype),s}(e,arguments,n(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,e)},i(e)}var s;function c(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var a=/*#__PURE__*/function(){function e(e,t,r){return this.apiUrl="http://vesal.armaghan.net:8080/rest",this.username=void 0,this.password=void 0,this.from=void 0,this.username=e||"",this.password=t,this.from=r,this}var t=e.prototype;return t.Api=function(e,t,n){void 0===t&&(t="POST");try{var o,i,s=function(e){function t(e){if(!i.references)throw new u(void 0,"The server didn't respond correctly");return i}var r=c(function(){return Promise.resolve(o.json()).then(function(e){i=e})},function(){throw new u(void 0,"The server didn't respond correctly")});return r&&r.then?r.then(t):t()},a=this;n=r({},n,{username:a.username,password:a.password});var f=c(function(){return Promise.resolve(fetch(a.apiUrl+"/"+e,{headers:{Accept:"application/json","Content-Type":"application/json"},method:t,body:n&&JSON.stringify(n)})).then(function(e){o=e})},function(){throw new u(void 0,"Server connection failed")});return Promise.resolve(f&&f.then?f.then(s):s())}catch(e){return Promise.reject(e)}},t.Send=function(e){var t=e.recipients,n=e.messages,o=e.from;try{if(!t||!n)throw new u(void 0,"recipients and messages should not be empty");"string"==typeof t&&(t=[t]),o||(o=this.from);var i=Array.isArray(n)||Array.isArray(o);if(i){if(!t.length)throw new u(void 0,"recipients and messages should have the same length");if(Array.isArray(n)&&!n.length)throw new u(void 0,"recipients and messages should have the same length");if("string"==typeof n&&(n=Array(t.length).fill(n)),"string"==typeof o&&(o=Array(t.length).fill(o)),t.length!==n.length||t.length!==o.length)throw new u(void 0,"recipients and messages should have the same length")}var s=r({destinations:t},i?{originators:o}:{originator:o},i?{contents:n}:{content:n});return Promise.resolve(this.Api(i?"ManyToMany":"OneToMany","POST",s)).then(function(e){var t,n=0,o=0;return null==(t=e.references)||t.map(function(e){e?n++:o++}),r({},e,{references:e.references||[],count:{success:n,fail:o}})})}catch(e){return Promise.reject(e)}},t.GetMessageStatus=function(e){try{return Promise.resolve(this.Api("messageState","POST",{referenceids:e}))}catch(e){return Promise.reject(e)}},t.GetReceivedMessages=function(){try{return Promise.resolve(this.Api("pullReceivedMessages"))}catch(e){return Promise.reject(e)}},t.GetReceivedMessagesCount=function(){try{return Promise.resolve(this.Api("receivedMessageCount"))}catch(e){return Promise.reject(e)}},t.GetUserInfo=function(){try{return Promise.resolve(this.Api("userInfo"))}catch(e){return Promise.reject(e)}},e}(),u=/*#__PURE__*/function(e){var t,r;function n(t,r){var n,o,i;return t&&Object.keys(l).includes(""+t)?(o=f(t),i=t):(o=r||"Unknown Vesal error",i=void 0),(n=e.call(this,o)||this).status=void 0,n.message=o,n.status=i,n}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,o(t,r),n}(/*#__PURE__*/i(Error));function f(e){return 0===e?"success":Object.keys(l).includes(""+e)?l[e]:""}var l=((s={0:"عملیات با موفقیت انجام شد"})[-100]="refrenceId مورد نظر یافت نشد",s[-101]="احراز هویت کاربر موفقیت آمیز نبود",s[-102]="نام کاربری یافت نشد",s[-103]="شماره originator اشتباه یا در بازه شماره های کاربر نیست",s[-104]="اعتبار کم است",s[-105]="فرمت درخواست اشتباه است",s[-106]="تعداد refrenceId ها بیش از 1000 عدد است",s[-107]="شماره گیرنده پیامک اشتباه است",s[-109]="تاریخ انقضای حساب کاربری فرارسیده است",s[-110]="درخواست از ip مجاز کاربر ارسال نشده است",s[-111]="شماره گیرنده در بلک لیست قرار دارد",s[-112]="حساب مشتری فعال نیست",s[-115]="فرمت UDH اشتباه است",s[-117]="مقدار mclass وارد شده اشتباه است",s[-118]="شماره پورت وارد شده صحیح نیست",s[-119]="کاربر به سرویس مورد نظر دسترسی ندارد",s[-120]="پیام ارسال شده دارای هیچ شماره معتبری نیست",s[-200]="خطای داخلی در پایگاه داده رخ داده است",s[-201]="خطای نامشخص داخل پایگاه داده",s[-137]="پیام نباید حاوی کلمات غیرمجاز می باشد",s);e.GetStatusText=f,e.Vesal=a,e.VesalError=u,e.messageStates={0:"پیامک در صف ارسال قرار دارد",1:"ارسال شده",2:"پیامک به موبایل گیرنده تحویل شده است",3:"پیامک به موبایل گیرنده تحویل نشده است",4:"وضعیت نامشخص",5:"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است",6:"پیام از سمت اپراتور لغو شده است",7:"پیام از سمت اپراتور منقضی شده است",8:"پیام از سمت اپراتور reject شده است"},e.vesalErrors=l});
|
|
2
2
|
//# sourceMappingURL=vesal.umd.js.map
|
package/dist/vesal.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vesal.umd.js","sources":["../src/vesal.ts"],"sourcesContent":["/**\r\n * The Vesal API Class\r\n * @author Shahab Movahhedi\r\n * @see {@link https://shmovahhedi.com Shahab Movahhedi's Website}\r\n * @see {@link https://github.com/movahhedi/vesal vesal's Repository}\r\n * @license MIT\r\n */\r\nexport class Vesal {\r\n\tpublic readonly apiUrl = \"http://vesal.armaghan.net:8080/rest\";\r\n\tprivate username: string;\r\n\tprivate password: string;\r\n\tprivate from: string;\r\n\r\n\tconstructor(username: string, password: string, from: string) {\r\n\t\tthis.username = username || \"\";\r\n\t\tthis.password = password;\r\n\t\tthis.from = from;\r\n\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Make an API request to the Vesal API\r\n\t * @private\r\n\t * @param {string} urlSuffix - The URL suffix for the API endpoint\r\n\t * @param {(\"GET\"|\"POST\")} [method=\"GET\"] - The HTTP method to use for the request\r\n\t * @param {object|null} [data=null] - The data to send with the request\r\n\t * @returns {Promise} The response from the API\r\n\t */\r\n\tprivate async Api(\r\n\t\turlSuffix: string,\r\n\t\tmethod: \"GET\" | \"POST\" = \"POST\",\r\n\t\tdata?: object,\r\n\t): Promise<any> {\r\n\t\tlet response: Response, responseBody: any;\r\n\r\n\t\tdata = {\r\n\t\t\t...data,\r\n\t\t\tusername: this.username,\r\n\t\t\tpassword: this.password,\r\n\t\t};\r\n\r\n\t\ttry {\r\n\t\t\tresponse = await fetch(`${this.apiUrl}/${urlSuffix}`, {\r\n\t\t\t\theaders: {\r\n\t\t\t\t\tAccept: \"application/json\",\r\n\t\t\t\t\t\"Content-Type\": \"application/json\",\r\n\t\t\t\t},\r\n\t\t\t\tmethod,\r\n\t\t\t\tbody: data && JSON.stringify(data),\r\n\t\t\t});\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"Server connection failed\");\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tresponseBody = await response.json();\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\tif (!responseBody.references) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\treturn responseBody;\r\n\t}\r\n\r\n\tasync Send({\r\n\t\trecipients,\r\n\t\tmessages,\r\n\t\tfrom,\r\n\t}: {\r\n\t\trecipients: string | string[];\r\n\t\tmessages: string | string[];\r\n\t\tfrom?: string | string[];\r\n\t}): Promise<IVesalResponse_Send_WithCount> {\r\n\t\tif (!recipients || !messages) {\r\n\t\t\tthrow new VesalError(\r\n\t\t\t\tundefined,\r\n\t\t\t\t\"recipients and messages should not be empty\",\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif (typeof recipients === \"string\") {\r\n\t\t\trecipients = [recipients];\r\n\t\t}\r\n\r\n\t\tif (!from) {\r\n\t\t\tfrom = this.from;\r\n\t\t}\r\n\r\n\t\tconst isManyToMany = Array.isArray(messages) || Array.isArray(from);\r\n\r\n\t\tif (isManyToMany) {\r\n\t\t\tif (!recipients.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t\tif (Array.isArray(messages) && !messages.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (typeof messages === \"string\") {\r\n\t\t\t\t// messages = recipients.map(() => messages);\r\n\t\t\t\tmessages = Array(recipients.length).fill(messages);\r\n\t\t\t}\r\n\t\t\tif (typeof from === \"string\") {\r\n\t\t\t\t// from = recipients.map(() => from);\r\n\t\t\t\tfrom = Array(recipients.length).fill(from);\r\n\t\t\t}\r\n\r\n\t\t\tif (\r\n\t\t\t\trecipients.length !== messages.length ||\r\n\t\t\t\trecipients.length !== from.length\r\n\t\t\t) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst sendData = {\r\n\t\t\tdestinations: recipients,\r\n\t\t\t...(isManyToMany ? { originators: from } : { originator: from }),\r\n\t\t\t...(isManyToMany ? { contents: messages } : { content: messages }),\r\n\t\t};\r\n\r\n\t\tconst result: IVesalResponse_Send = await this.Api(\r\n\t\t\tisManyToMany ? \"ManyToMany\" : \"OneToMany\",\r\n\t\t\t\"POST\",\r\n\t\t\tsendData,\r\n\t\t);\r\n\r\n\t\tlet successCount: number = 0,\r\n\t\t\tfailCount: number = 0;\r\n\r\n\t\tresult.references?.map((messageResult) => {\r\n\t\t\tif (messageResult) {\r\n\t\t\t\tsuccessCount++;\r\n\t\t\t} else {\r\n\t\t\t\tfailCount++;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn {\r\n\t\t\t...result,\r\n\t\t\treferences: result.references || [],\r\n\t\t\tcount: {\r\n\t\t\t\tsuccess: successCount,\r\n\t\t\t\tfail: failCount,\r\n\t\t\t},\r\n\t\t};\r\n\t}\r\n\r\n\tasync GetMessageStatus(\r\n\t\treferencesIds: number[],\r\n\t): Promise<IVesalResponse_MessageState> {\r\n\t\treturn await this.Api(\"messageState\", \"POST\", {\r\n\t\t\treferenceids: referencesIds,\r\n\t\t});\r\n\t}\r\n\r\n\tasync GetReceivedMessages(): Promise<IVesalResponse_ReceivedMessages> {\r\n\t\treturn await this.Api(\"pullReceivedMessages\");\r\n\t}\r\n\r\n\tasync GetReceivedMessagesCount(): Promise<IVesalResponse_ReceivedMessagesCount> {\r\n\t\treturn await this.Api(\"receivedMessageCount\");\r\n\t}\r\n\r\n\tasync GetUserInfo(): Promise<IVesalResponse_UserInfo> {\r\n\t\treturn await this.Api(\"userInfo\");\r\n\t}\r\n}\r\n\r\nexport class VesalError extends Error {\r\n\tstatus: keyof typeof vesalErrors | undefined;\r\n\r\n\tconstructor(statusParam: number | undefined, messageParam?: string) {\r\n\t\tlet message: string, status: keyof typeof vesalErrors | undefined;\r\n\r\n\t\tif (statusParam && Object.keys(vesalErrors).includes(\"\" + statusParam)) {\r\n\t\t\tmessage = GetStatusText(statusParam);\r\n\t\t\tstatus = statusParam as any;\r\n\t\t} else {\r\n\t\t\tmessage = messageParam || \"Unknown Vesal error\";\r\n\t\t\tstatus = undefined;\r\n\t\t}\r\n\r\n\t\tsuper(message);\r\n\r\n\t\tthis.message = message;\r\n\t\tthis.status = status;\r\n\t}\r\n}\r\n\r\ninterface IVesalResponse_Base {\r\n\terrorModel: {\r\n\t\terrorCode: number;\r\n\t\ttimestamp: string | number | null;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_Send extends IVesalResponse_Base {\r\n\treferences: (number | Omit<keyof typeof vesalErrors, 0>)[];\r\n}\r\n\r\ninterface IVesalResponse_Send_WithCount extends IVesalResponse_Send {\r\n\tcount: {\r\n\t\tsuccess: number;\r\n\t\tfail: number;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_MessageState extends IVesalResponse_Base {\r\n\tstates: {\r\n\t\tid: number;\r\n\t\tstate: number;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessages extends IVesalResponse_Base {\r\n\tmessageModels: {\r\n\t\toriginator: string;\r\n\t\tdestination: string;\r\n\t\tcontent: string;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessagesCount extends IVesalResponse_Base {\r\n\tcount: number;\r\n}\r\ninterface IVesalResponse_UserInfo extends IVesalResponse_Base {\r\n\tuser: {\r\n\t\tcredit: number;\r\n\t\tdeliveryUrl: unknown;\r\n\t\treceiveUrl: unknown;\r\n\t\tiPs: string[];\r\n\t\tnumbers: string[];\r\n\t\tid: number;\r\n\t\tusername: string;\r\n\t\tpassword: unknown;\r\n\t\tfirstName: unknown;\r\n\t\tlastName: unknown;\r\n\t\tmobile: unknown;\r\n\t\temail: unknown;\r\n\t\tnationalId: number;\r\n\t\texpirationDate: string;\r\n\t\tactive: boolean;\r\n\t\tdeleted: boolean;\r\n\t\tdbProxyStandalone: boolean;\r\n\t\tinsertDate: unknown;\r\n\t\tupdateDate: unknown;\r\n\t\tcustomer: unknown;\r\n\t\troles: unknown;\r\n\t};\r\n}\r\n\r\nexport function GetStatusText(status: number) {\r\n\tif (status === 0) {\r\n\t\treturn \"success\";\r\n\t}\r\n\tif (Object.keys(vesalErrors).includes(\"\" + status)) {\r\n\t\treturn vesalErrors[status];\r\n\t}\r\n\treturn \"\";\r\n}\r\n\r\nexport const messageStates = {\r\n\t0: \"پیامک در صف ارسال قرار دارد\",\r\n\t1: \"ارسال شده\",\r\n\t2: \"پیامک به موبایل گیرنده تحویل شده است\",\r\n\t3: \"پیامک به موبایل گیرنده تحویل نشده است\",\r\n\t4: \"وضعیت نامشخص\",\r\n\t5: \"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است\",\r\n\t6: \"پیام از سمت اپراتور لغو شده است\",\r\n\t7: \"پیام از سمت اپراتور منقضی شده است\",\r\n\t8: \"پیام از سمت اپراتور reject شده است\",\r\n} as const;\r\n\r\nexport const vesalErrors = {\r\n\t0: \"عملیات با موفقیت انجام شد\",\r\n\t[-100]: \"refrenceId مورد نظر یافت نشد\",\r\n\t[-101]: \"احراز هویت کاربر موفقیت آمیز نبود\",\r\n\t[-102]: \"نام کاربری یافت نشد\",\r\n\t[-103]: \"شماره originator اشتباه یا در بازه شماره های کاربر نیست\",\r\n\t[-104]: \"اعتبار کم است\",\r\n\t[-105]: \"فرمت درخواست اشتباه است\",\r\n\t[-106]: \"تعداد refrenceId ها بیش از 1000 عدد است\",\r\n\t[-107]: \"شماره گیرنده پیامک اشتباه است\",\r\n\t[-109]: \"تاریخ انقضای حساب کاربری فرارسیده است\",\r\n\t[-110]: \"درخواست از ip مجاز کاربر ارسال نشده است\",\r\n\t[-111]: \"شماره گیرنده در بلک لیست قرار دارد\",\r\n\t[-112]: \"حساب مشتری فعال نیست\",\r\n\t[-115]: \"فرمت UDH اشتباه است\",\r\n\t[-117]: \"مقدار mclass وارد شده اشتباه است\",\r\n\t[-118]: \"شماره پورت وارد شده صحیح نیست\",\r\n\t[-119]: \"کاربر به سرویس مورد نظر دسترسی ندارد\",\r\n\t[-120]: \"پیام ارسال شده دارای هیچ شماره معتبری نیست\",\r\n\t[-200]: \"خطای داخلی در پایگاه داده رخ داده است\",\r\n\t[-201]: \"خطای نامشخص داخل پایگاه داده\",\r\n\t[-137]: \"پیام نباید حاوی کلمات غیرمجاز می باشد\",\r\n} as const;\r\n\r\nexport default Vesal;\r\n"],"names":["Vesal","username","password","from","this","apiUrl","_proto","prototype","Api","urlSuffix","method","data","response","responseBody","_temp4","_result","_temp2","_result2","references","VesalError","undefined","_temp","_catch","Promise","resolve","json","then","_response$json","_exit","_this","_extends","_temp3","fetch","headers","Accept","body","JSON","stringify","_fetch","e","reject","Send","_ref","recipients","messages","isManyToMany","Array","isArray","length","fill","sendData","destinations","originators","originator","contents","content","result","_result$references","successCount","failCount","map","messageResult","count","success","fail","GetMessageStatus","referencesIds","referenceids","GetReceivedMessages","GetReceivedMessagesCount","GetUserInfo","_Error","statusParam","messageParam","_this7","message","status","Object","keys","vesalErrors","includes","GetStatusText","call","_wrapNativeSuper","Error","_vesalErrors"],"mappings":"wnDAOa,IAAAA,eAAK,WAMjB,SAAAA,EAAYC,EAAkBC,EAAkBC,GAK/C,OAL2DC,KAL5CC,OAAS,sCACjBJ,KAAAA,qBACAC,cAAQ,EAAAE,KACRD,UAAI,EAGXC,KAAKH,SAAWA,GAAY,GAC5BG,KAAKF,SAAWA,EAChBE,KAAKD,KAAOA,EAELC,IACR,CAAC,IAAAE,EAAAN,EAAAO,UAgKAP,OAhKAM,EAUaE,IAAGA,SAChBC,EACAC,EACAC,QADAD,IAAAA,IAAAA,EAAyB,QACZ,IAAA,IAETE,EAAoBC,EAFXC,EAAA,SAAAC,GAAA,SAAAC,EAAAC,GA6Bb,IAAKJ,EAAaK,WACjB,MAAU,IAAAC,OAAWC,EAAW,uCAGjC,OAAOP,CAAa,CAAA,IAAAQ,EAAAC,EAVhB,WAAA,OAAAC,QAAAC,QAC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ab Movahhedi\r\n * @see {@link https://shmovahhedi.com Shahab Movahhedi's Website}\r\n * @see {@link https://github.com/movahhedi/vesal vesal's Repository}\r\n * @license MIT\r\n */\r\nexport class Vesal {\r\n\tpublic readonly apiUrl = \"http://vesal.armaghan.net:8080/rest\";\r\n\tprivate username: string;\r\n\tprivate password: string;\r\n\tprivate from: string;\r\n\r\n\tconstructor(username: string, password: string, from: string) {\r\n\t\tthis.username = username || \"\";\r\n\t\tthis.password = password;\r\n\t\tthis.from = from;\r\n\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Make an API request to the Vesal API\r\n\t * @private\r\n\t * @param {string} urlSuffix - The URL suffix for the API endpoint\r\n\t * @param {(\"GET\"|\"POST\")} [method=\"GET\"] - The HTTP method to use for the request\r\n\t * @param {object|null} [data=null] - The data to send with the request\r\n\t * @returns {Promise} The response from the API\r\n\t */\r\n\tprivate async Api(\r\n\t\turlSuffix: string,\r\n\t\tmethod: \"GET\" | \"POST\" = \"POST\",\r\n\t\tdata?: object,\r\n\t): Promise<any> {\r\n\t\tlet response: Response, responseBody: any;\r\n\r\n\t\tdata = {\r\n\t\t\t...data,\r\n\t\t\tusername: this.username,\r\n\t\t\tpassword: this.password,\r\n\t\t};\r\n\r\n\t\ttry {\r\n\t\t\tresponse = await fetch(`${this.apiUrl}/${urlSuffix}`, {\r\n\t\t\t\theaders: {\r\n\t\t\t\t\tAccept: \"application/json\",\r\n\t\t\t\t\t\"Content-Type\": \"application/json\",\r\n\t\t\t\t},\r\n\t\t\t\tmethod,\r\n\t\t\t\tbody: data && JSON.stringify(data),\r\n\t\t\t});\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"Server connection failed\");\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tresponseBody = await response.json();\r\n\t\t} catch (error) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\tif (!responseBody.references) {\r\n\t\t\tthrow new VesalError(undefined, \"The server didn't respond correctly\");\r\n\t\t}\r\n\r\n\t\treturn responseBody;\r\n\t}\r\n\r\n\tasync Send({\r\n\t\trecipients,\r\n\t\tmessages,\r\n\t\tfrom,\r\n\t}: {\r\n\t\trecipients: string | string[];\r\n\t\tmessages: string | string[];\r\n\t\tfrom?: string | string[];\r\n\t}): Promise<IVesalResponse_Send_WithCount> {\r\n\t\tif (!recipients || !messages) {\r\n\t\t\tthrow new VesalError(\r\n\t\t\t\tundefined,\r\n\t\t\t\t\"recipients and messages should not be empty\",\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif (typeof recipients === \"string\") {\r\n\t\t\trecipients = [recipients];\r\n\t\t}\r\n\r\n\t\tif (!from) {\r\n\t\t\tfrom = this.from;\r\n\t\t}\r\n\r\n\t\tconst isManyToMany = Array.isArray(messages) || Array.isArray(from);\r\n\r\n\t\tif (isManyToMany) {\r\n\t\t\tif (!recipients.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t\tif (Array.isArray(messages) && !messages.length) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (typeof messages === \"string\") {\r\n\t\t\t\t// messages = recipients.map(() => messages);\r\n\t\t\t\tmessages = Array(recipients.length).fill(messages);\r\n\t\t\t}\r\n\t\t\tif (typeof from === \"string\") {\r\n\t\t\t\t// from = recipients.map(() => from);\r\n\t\t\t\tfrom = Array(recipients.length).fill(from);\r\n\t\t\t}\r\n\r\n\t\t\tif (\r\n\t\t\t\trecipients.length !== messages.length ||\r\n\t\t\t\trecipients.length !== from.length\r\n\t\t\t) {\r\n\t\t\t\tthrow new VesalError(\r\n\t\t\t\t\tundefined,\r\n\t\t\t\t\t\"recipients and messages should have the same length\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst sendData = {\r\n\t\t\tdestinations: recipients,\r\n\t\t\t...(isManyToMany ? { originators: from } : { originator: from }),\r\n\t\t\t...(isManyToMany ? { contents: messages } : { content: messages }),\r\n\t\t};\r\n\r\n\t\tconst result: IVesalResponse_Send = await this.Api(\r\n\t\t\tisManyToMany ? \"ManyToMany\" : \"OneToMany\",\r\n\t\t\t\"POST\",\r\n\t\t\tsendData,\r\n\t\t);\r\n\r\n\t\tlet successCount: number = 0,\r\n\t\t\tfailCount: number = 0;\r\n\r\n\t\tresult.references?.map((messageResult) => {\r\n\t\t\tif (messageResult) {\r\n\t\t\t\tsuccessCount++;\r\n\t\t\t} else {\r\n\t\t\t\tfailCount++;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn {\r\n\t\t\t...result,\r\n\t\t\treferences: result.references || [],\r\n\t\t\tcount: {\r\n\t\t\t\tsuccess: successCount,\r\n\t\t\t\tfail: failCount,\r\n\t\t\t},\r\n\t\t};\r\n\t}\r\n\r\n\tasync GetMessageStatus(\r\n\t\treferencesIds: number[],\r\n\t): Promise<IVesalResponse_MessageState> {\r\n\t\treturn await this.Api(\"messageState\", \"POST\", {\r\n\t\t\treferenceids: referencesIds,\r\n\t\t});\r\n\t}\r\n\r\n\tasync GetReceivedMessages(): Promise<IVesalResponse_ReceivedMessages> {\r\n\t\treturn await this.Api(\"pullReceivedMessages\");\r\n\t}\r\n\r\n\tasync GetReceivedMessagesCount(): Promise<IVesalResponse_ReceivedMessagesCount> {\r\n\t\treturn await this.Api(\"receivedMessageCount\");\r\n\t}\r\n\r\n\tasync GetUserInfo(): Promise<IVesalResponse_UserInfo> {\r\n\t\treturn await this.Api(\"userInfo\");\r\n\t}\r\n}\r\n\r\nexport class VesalError extends Error {\r\n\tstatus: keyof typeof vesalErrors | undefined;\r\n\r\n\tconstructor(statusParam: number | undefined, messageParam?: string) {\r\n\t\tlet message: string, status: keyof typeof vesalErrors | undefined;\r\n\r\n\t\tif (statusParam && Object.keys(vesalErrors).includes(\"\" + statusParam)) {\r\n\t\t\tmessage = GetStatusText(statusParam);\r\n\t\t\tstatus = statusParam as any;\r\n\t\t} else {\r\n\t\t\tmessage = messageParam || \"Unknown Vesal error\";\r\n\t\t\tstatus = undefined;\r\n\t\t}\r\n\r\n\t\tsuper(message);\r\n\r\n\t\tthis.message = message;\r\n\t\tthis.status = status;\r\n\t}\r\n}\r\n\r\ninterface IVesalResponse_Base {\r\n\terrorModel: {\r\n\t\terrorCode: number;\r\n\t\ttimestamp: string | number | null;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_Send extends IVesalResponse_Base {\r\n\treferences: (number | Omit<keyof typeof vesalErrors, 0>)[];\r\n}\r\n\r\ninterface IVesalResponse_Send_WithCount extends IVesalResponse_Send {\r\n\tcount: {\r\n\t\tsuccess: number;\r\n\t\tfail: number;\r\n\t};\r\n}\r\n\r\ninterface IVesalResponse_MessageState extends IVesalResponse_Base {\r\n\tstates: {\r\n\t\tid: number;\r\n\t\tstate: number;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessages extends IVesalResponse_Base {\r\n\tmessageModels: {\r\n\t\toriginator: string;\r\n\t\tdestination: string;\r\n\t\tcontent: string;\r\n\t}[];\r\n}\r\ninterface IVesalResponse_ReceivedMessagesCount extends IVesalResponse_Base {\r\n\tcount: number;\r\n}\r\ninterface IVesalResponse_UserInfo extends IVesalResponse_Base {\r\n\tuser: {\r\n\t\tcredit: number;\r\n\t\tdeliveryUrl: unknown;\r\n\t\treceiveUrl: unknown;\r\n\t\tiPs: string[];\r\n\t\tnumbers: string[];\r\n\t\tid: number;\r\n\t\tusername: string;\r\n\t\tpassword: unknown;\r\n\t\tfirstName: unknown;\r\n\t\tlastName: unknown;\r\n\t\tmobile: unknown;\r\n\t\temail: unknown;\r\n\t\tnationalId: number;\r\n\t\texpirationDate: string;\r\n\t\tactive: boolean;\r\n\t\tdeleted: boolean;\r\n\t\tdbProxyStandalone: boolean;\r\n\t\tinsertDate: unknown;\r\n\t\tupdateDate: unknown;\r\n\t\tcustomer: unknown;\r\n\t\troles: unknown;\r\n\t};\r\n}\r\n\r\nexport function GetStatusText(status: number) {\r\n\tif (status === 0) {\r\n\t\treturn \"success\";\r\n\t}\r\n\tif (Object.keys(vesalErrors).includes(\"\" + status)) {\r\n\t\treturn vesalErrors[status];\r\n\t}\r\n\treturn \"\";\r\n}\r\n\r\nexport const messageStates = {\r\n\t0: \"پیامک در صف ارسال قرار دارد\",\r\n\t1: \"ارسال شده\",\r\n\t2: \"پیامک به موبایل گیرنده تحویل شده است\",\r\n\t3: \"پیامک به موبایل گیرنده تحویل نشده است\",\r\n\t4: \"وضعیت نامشخص\",\r\n\t5: \"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است\",\r\n\t6: \"پیام از سمت اپراتور لغو شده است\",\r\n\t7: \"پیام از سمت اپراتور منقضی شده است\",\r\n\t8: \"پیام از سمت اپراتور reject شده است\",\r\n} as const;\r\n\r\nexport const vesalErrors = {\r\n\t0: \"عملیات با موفقیت انجام شد\",\r\n\t[-100]: \"refrenceId مورد نظر یافت نشد\",\r\n\t[-101]: \"احراز هویت کاربر موفقیت آمیز نبود\",\r\n\t[-102]: \"نام کاربری یافت نشد\",\r\n\t[-103]: \"شماره originator اشتباه یا در بازه شماره های کاربر نیست\",\r\n\t[-104]: \"اعتبار کم است\",\r\n\t[-105]: \"فرمت درخواست اشتباه است\",\r\n\t[-106]: \"تعداد refrenceId ها بیش از 1000 عدد است\",\r\n\t[-107]: \"شماره گیرنده پیامک اشتباه است\",\r\n\t[-109]: \"تاریخ انقضای حساب کاربری فرارسیده است\",\r\n\t[-110]: \"درخواست از ip مجاز کاربر ارسال نشده است\",\r\n\t[-111]: \"شماره گیرنده در بلک لیست قرار دارد\",\r\n\t[-112]: \"حساب مشتری فعال نیست\",\r\n\t[-115]: \"فرمت UDH اشتباه است\",\r\n\t[-117]: \"مقدار mclass وارد شده اشتباه است\",\r\n\t[-118]: \"شماره پورت وارد شده صحیح نیست\",\r\n\t[-119]: \"کاربر به سرویس مورد نظر دسترسی ندارد\",\r\n\t[-120]: \"پیام ارسال شده دارای هیچ شماره معتبری نیست\",\r\n\t[-200]: \"خطای داخلی در پایگاه داده رخ داده است\",\r\n\t[-201]: \"خطای نامشخص داخل پایگاه داده\",\r\n\t[-137]: \"پیام نباید حاوی کلمات غیرمجاز می باشد\",\r\n} as const;\r\n"],"names":["Vesal","username","password","from","apiUrl","this","_proto","prototype","Api","urlSuffix","method","data","_temp4","response","responseBody","_result","_temp2","_result2","references","VesalError","undefined","_temp","_catch","Promise","resolve","json","then","_response$json","_this","_extends","_temp3","fetch","headers","Accept","body","JSON","stringify","_fetch","e","reject","Send","_ref","recipients","messages","isManyToMany","Array","isArray","length","fill","sendData","destinations","originators","originator","contents","content","result","_result$references","successCount","failCount","map","messageResult","count","success","fail","GetMessageStatus","referencesIds","referenceids","GetReceivedMessages","GetReceivedMessagesCount","GetUserInfo","_Error","statusParam","messageParam","_this7","message","status","Object","keys","vesalErrors","includes","GetStatusText","call","_wrapNativeSuper","Error","_vesalErrors"],"mappings":"wnDAOa,IAAAA,eAMZ,WAAA,SAAAA,EAAYC,EAAkBC,EAAkBC,GAK/C,YAVeC,OAAS,sCAAqCC,KACtDJ,cACAC,EAAAA,KAAAA,cACAC,EAAAA,KAAAA,UAGP,EAAAE,KAAKJ,SAAWA,GAAY,GAC5BI,KAAKH,SAAWA,EAChBG,KAAKF,KAAOA,MAGb,CAAC,IAAAG,EAAAN,EAAAO,UAgKA,OAhKAD,EAUaE,IAAG,SAChBC,EACAC,EACAC,QADyB,IAAzBD,IAAAA,EAAyB,QAAM,IAClBE,IAETC,EAAoBC,EAFXF,WAAAG,YAAAC,EAAAC,GA6Bb,IAAKH,EAAaI,WACjB,MAAM,IAAIC,OAAWC,EAAW,uCAGjC,OAAON,CAAa,KAAAO,EAAAC,EAAA,WAVhBC,OAAAA,Q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ghan Vesal SMS API client for JS/TS/ESM/Node.js",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Shahab Movahhedi",
|
|
7
|
-
"email": "dev@shmovahhedi.com",
|
|
8
|
-
"url": "https://shmovahhedi.com/"
|
|
9
|
-
},
|
|
10
|
-
"homepage": "https://github.com/movahhedi/vesal",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "https://github.com/movahhedi/vesal.git",
|
|
14
|
-
"directory": "/"
|
|
15
|
-
},
|
|
16
|
-
"bugs": "https://github.com/movahhedi/vesal",
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"keywords": [
|
|
19
|
-
"vesal",
|
|
20
|
-
"vesal-sdk",
|
|
21
|
-
"vesal-js",
|
|
22
|
-
"sms-ir",
|
|
23
|
-
"armaghan-vesal",
|
|
24
|
-
"vesal.armaghan.net",
|
|
25
|
-
"armaghan",
|
|
26
|
-
"sms",
|
|
27
|
-
"messaging",
|
|
28
|
-
"api"
|
|
29
|
-
],
|
|
30
|
-
"type": "module",
|
|
31
|
-
"source": "./src/vesal.ts",
|
|
32
|
-
"main": "./dist/vesal.cjs",
|
|
33
|
-
"module": "./dist/vesal.mjs",
|
|
34
|
-
"types": "./dist/vesal.d.ts",
|
|
35
|
-
"typings": "./dist/vesal.d.ts",
|
|
36
|
-
"umd:main": "./dist/vesal.umd.js",
|
|
37
|
-
"unpkg": "./dist/vesal.umd.js",
|
|
38
|
-
"exports": {
|
|
39
|
-
".": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
"eslint": "^
|
|
79
|
-
"
|
|
80
|
-
"eslint
|
|
81
|
-
"eslint-
|
|
82
|
-
"eslint-plugin-
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "vesal",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Armaghan Vesal SMS API client for JS/TS/ESM/Node.js",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Shahab Movahhedi",
|
|
7
|
+
"email": "dev@shmovahhedi.com",
|
|
8
|
+
"url": "https://shmovahhedi.com/"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/movahhedi/vesal",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/movahhedi/vesal.git",
|
|
14
|
+
"directory": "/"
|
|
15
|
+
},
|
|
16
|
+
"bugs": "https://github.com/movahhedi/vesal",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"vesal",
|
|
20
|
+
"vesal-sdk",
|
|
21
|
+
"vesal-js",
|
|
22
|
+
"sms-ir",
|
|
23
|
+
"armaghan-vesal",
|
|
24
|
+
"vesal.armaghan.net",
|
|
25
|
+
"armaghan",
|
|
26
|
+
"sms",
|
|
27
|
+
"messaging",
|
|
28
|
+
"api"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"source": "./src/vesal.ts",
|
|
32
|
+
"main": "./dist/vesal.cjs",
|
|
33
|
+
"module": "./dist/vesal.mjs",
|
|
34
|
+
"types": "./dist/vesal.d.ts",
|
|
35
|
+
"typings": "./dist/vesal.d.ts",
|
|
36
|
+
"umd:main": "./dist/vesal.umd.js",
|
|
37
|
+
"unpkg": "./dist/vesal.umd.js",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/vesal.d.ts",
|
|
41
|
+
"require": "./dist/vesal.cjs",
|
|
42
|
+
"import": "./dist/vesal.mjs",
|
|
43
|
+
"default": "./dist/vesal.modern.js"
|
|
44
|
+
},
|
|
45
|
+
"./ts": "./src/vesal.ts",
|
|
46
|
+
"./package.json": "./package.json"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"src",
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
52
|
+
"cspell": {
|
|
53
|
+
"version": "0.2",
|
|
54
|
+
"language": [
|
|
55
|
+
"en",
|
|
56
|
+
"fa"
|
|
57
|
+
],
|
|
58
|
+
"words": [
|
|
59
|
+
"Armaghan",
|
|
60
|
+
"likeToLike",
|
|
61
|
+
"mclass",
|
|
62
|
+
"microbundle",
|
|
63
|
+
"referenceids",
|
|
64
|
+
"refrence",
|
|
65
|
+
"Vesal"
|
|
66
|
+
],
|
|
67
|
+
"ignorePaths": [
|
|
68
|
+
"README.fa.md"
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
"packageManager": "yarn@4.1.0",
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "microbundle build --raw true --generateType -f modern,esm,cjs,umd",
|
|
74
|
+
"dev": "microbundle watch -f modern,esm,cjs,umd"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
78
|
+
"@typescript-eslint/parser": "^6.19.0",
|
|
79
|
+
"concurrently": "^8.2.2",
|
|
80
|
+
"eslint": "^8.56.0",
|
|
81
|
+
"eslint-config-prettier": "^9.1.0",
|
|
82
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
83
|
+
"eslint-plugin-react": "^7.33.2",
|
|
84
|
+
"eslint-plugin-redos": "^4.4.5",
|
|
85
|
+
"microbundle": "^0.15.1",
|
|
86
|
+
"npm-check-updates": "^16.14.12",
|
|
87
|
+
"prettier": "^3.2.4",
|
|
88
|
+
"rimraf": "^5.0.5",
|
|
89
|
+
"typescript": "^5.3.3"
|
|
90
|
+
}
|
|
91
|
+
}
|