airalo-sdk-type 0.0.7 → 0.0.9
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 +352 -59
- package/dist/api/auth.d.ts +17 -0
- package/dist/api/auth.js +76 -0
- package/dist/api/balance.d.ts +15 -0
- package/dist/api/balance.js +38 -0
- package/dist/api/misc.d.ts +26 -0
- package/dist/api/misc.js +71 -0
- package/dist/api/notification.d.ts +36 -0
- package/dist/api/notification.js +142 -0
- package/dist/api/order.d.ts +63 -0
- package/dist/api/order.js +283 -0
- package/dist/api/package.d.ts +17 -0
- package/dist/{package.js → api/package.js} +12 -17
- package/dist/api/sims.d.ts +30 -0
- package/dist/api/sims.js +246 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +32 -0
- package/dist/index.d.ts +144 -73
- package/dist/index.js +86 -64
- package/dist/types/order.d.ts +39 -22
- package/dist/types/package.d.ts +48 -46
- package/dist/types/sim.d.ts +53 -13
- package/dist/utils/helpers.d.ts +34 -0
- package/dist/utils/helpers.js +29 -0
- package/package.json +50 -51
- package/dist/auth.d.ts +0 -13
- package/dist/auth.js +0 -99
- package/dist/balance.d.ts +0 -29
- package/dist/balance.js +0 -48
- package/dist/order.d.ts +0 -26
- package/dist/order.js +0 -76
- package/dist/package.d.ts +0 -24
- package/dist/sims.d.ts +0 -46
- package/dist/sims.js +0 -135
package/README.md
CHANGED
|
@@ -1,59 +1,352 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
# airalo-sdk-type
|
|
2
|
+
|
|
3
|
+
> Unofficial TypeScript/JavaScript SDK for the [Airalo Partner API](https://partners-api.airalo.com)
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/airalo-sdk-type)
|
|
6
|
+
[](https://opensource.org/licenses/ISC)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Table of contents
|
|
12
|
+
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Quick start](#quick-start)
|
|
15
|
+
- [Environments](#environments)
|
|
16
|
+
- [API reference](#api-reference)
|
|
17
|
+
- [Auth](#auth)
|
|
18
|
+
- [Packages](#packages)
|
|
19
|
+
- [Orders](#orders)
|
|
20
|
+
- [eSIMs](#esims)
|
|
21
|
+
- [Balance](#balance)
|
|
22
|
+
- [Notifications](#notifications)
|
|
23
|
+
- [Misc](#misc)
|
|
24
|
+
- [Response format](#response-format)
|
|
25
|
+
- [All methods](#all-methods)
|
|
26
|
+
- [Contributing](#contributing)
|
|
27
|
+
- [License](#license)
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install airalo-sdk-type
|
|
35
|
+
# or
|
|
36
|
+
yarn add airalo-sdk-type
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Quick start
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import Airalo from "airalo-sdk-type";
|
|
45
|
+
|
|
46
|
+
// 1. Point to sandbox or production
|
|
47
|
+
Airalo.setHost("https://sandbox-partners-api.airalo.com");
|
|
48
|
+
|
|
49
|
+
// 2. Authenticate — token is stored automatically
|
|
50
|
+
await Airalo.auth.TOKEN({
|
|
51
|
+
client_id: "YOUR_CLIENT_ID",
|
|
52
|
+
client_secret: "YOUR_CLIENT_SECRET"
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// 3. Fetch available packages
|
|
56
|
+
const { data } = await Airalo.Package.Packages();
|
|
57
|
+
console.log(data);
|
|
58
|
+
|
|
59
|
+
// 4. Place an order
|
|
60
|
+
const order = await Airalo.Order.SubmitOrder({
|
|
61
|
+
quantity: "1",
|
|
62
|
+
package_id: "chinacom-7days-1gb"
|
|
63
|
+
});
|
|
64
|
+
console.log(order.data?.sims[0].qrcode);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Environments
|
|
70
|
+
|
|
71
|
+
| Environment | Base URL |
|
|
72
|
+
| ----------- | ----------------------------------------- |
|
|
73
|
+
| Sandbox | `https://sandbox-partners-api.airalo.com` |
|
|
74
|
+
| Production | `https://partners-api.airalo.com` |
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
// Sandbox (default)
|
|
78
|
+
Airalo.setHost("https://sandbox-partners-api.airalo.com");
|
|
79
|
+
|
|
80
|
+
// Production
|
|
81
|
+
Airalo.setHost("https://partners-api.airalo.com");
|
|
82
|
+
|
|
83
|
+
// Enable request/response logging
|
|
84
|
+
Airalo.setLogger(true);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## API reference
|
|
90
|
+
|
|
91
|
+
### Auth
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// Fetch and store an access token
|
|
95
|
+
await Airalo.auth.TOKEN({
|
|
96
|
+
client_id: "YOUR_CLIENT_ID",
|
|
97
|
+
client_secret: "YOUR_CLIENT_SECRET"
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
### Packages
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// List all available packages
|
|
107
|
+
const all = await Airalo.Package.Packages();
|
|
108
|
+
|
|
109
|
+
// Filter by country, page, and limit
|
|
110
|
+
const jp = await Airalo.Package.Packages({
|
|
111
|
+
"filter[country]": "JP",
|
|
112
|
+
limit: 10,
|
|
113
|
+
page: 1
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### Orders
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// Place a synchronous order — response includes SIM + QR code immediately
|
|
123
|
+
const order = await Airalo.Order.SubmitOrder({
|
|
124
|
+
quantity: "1",
|
|
125
|
+
package_id: "chinacom-7days-1gb",
|
|
126
|
+
type: "sim", // optional, defaults to "sim"
|
|
127
|
+
description: "My order", // optional
|
|
128
|
+
brand_settings_name: "MyBrand" // optional, null = unbranded
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Place an asynchronous order — result is delivered via webhook
|
|
132
|
+
await Airalo.Order.SubmitOrderAsync({
|
|
133
|
+
quantity: "1",
|
|
134
|
+
package_id: "chinacom-7days-1gb",
|
|
135
|
+
webhook_url: "https://myapp.com/webhook",
|
|
136
|
+
to_email: "user@example.com", // optional
|
|
137
|
+
sharing_option: ["link", "pdf"], // optional, required if to_email is set
|
|
138
|
+
copy_address: ["cc@example.com"] // optional
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Place a top-up order for an existing eSIM
|
|
142
|
+
await Airalo.Order.SubmitTopUpOrder({
|
|
143
|
+
package_id: "bonbon-mobile-30days-3gb-topup",
|
|
144
|
+
iccid: "8934000000000087299",
|
|
145
|
+
description: "Top-up" // optional
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// List orders with filters
|
|
149
|
+
const orders = await Airalo.Order.GetOrderList({
|
|
150
|
+
"filter[order_status]": "completed", // completed | failed | refunded
|
|
151
|
+
"filter[iccid]": "89343",
|
|
152
|
+
"filter[code]": "20221021-003188",
|
|
153
|
+
"filter[created_at]": "2024-01-01 - 2024-12-31",
|
|
154
|
+
include: "sims,status",
|
|
155
|
+
limit: 20,
|
|
156
|
+
page: 1
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Get a single order by ID
|
|
160
|
+
const single = await Airalo.Order.GetOrder(731579);
|
|
161
|
+
|
|
162
|
+
// List all order statuses
|
|
163
|
+
const statuses = await Airalo.Order.GetOrderStatuses();
|
|
164
|
+
|
|
165
|
+
// Get a specific status by slug
|
|
166
|
+
const status = await Airalo.Order.GetOrderStatusBySlug("completed");
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
### eSIMs
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
// List eSIMs with optional filters
|
|
175
|
+
const sims = await Airalo.Sims.GetSimList({
|
|
176
|
+
"filter[iccid]": "8910300000",
|
|
177
|
+
"filter[created_at]": "2024-01-01 - 2024-12-31",
|
|
178
|
+
include: "order,order.status,share",
|
|
179
|
+
limit: 10,
|
|
180
|
+
page: 1
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Get a single eSIM by ICCID
|
|
184
|
+
const sim = await Airalo.Sims.GetSim("8910300000033289733");
|
|
185
|
+
|
|
186
|
+
// Get installation instructions (QR + manual)
|
|
187
|
+
const instructions = await Airalo.Sims.GetSimInstructions(
|
|
188
|
+
"8910300000033289733"
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
// Get current data usage
|
|
192
|
+
const usage = await Airalo.Sims.GetDataUsage("8910300000033289733");
|
|
193
|
+
// usage.data.remaining — bytes remaining
|
|
194
|
+
// usage.data.total — total bytes
|
|
195
|
+
// usage.data.status — NOT_ACTIVE | ACTIVE | FINISHED | EXPIRED
|
|
196
|
+
|
|
197
|
+
// List available top-up packages for an eSIM
|
|
198
|
+
const topups = await Airalo.Sims.GetTopUpPackageList("8910300000033289733");
|
|
199
|
+
|
|
200
|
+
// Get package history for an eSIM
|
|
201
|
+
const history = await Airalo.Sims.GetSimPackageHistory("8910300000033289733");
|
|
202
|
+
|
|
203
|
+
// Update the brand name shown on an eSIM
|
|
204
|
+
await Airalo.Sims.UpdateSimBrand("8910300000033289733", "MyBrand");
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
### Balance
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
const balance = await Airalo.Balance.GetBalance();
|
|
213
|
+
console.log(balance.data?.balances.availableBalance.amount);
|
|
214
|
+
console.log(balance.data?.balances.availableBalance.currency);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### Notifications
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
// Opt in to low-data webhook notifications
|
|
223
|
+
await Airalo.Notification.NotificationOptIn({
|
|
224
|
+
type: "webhook_low_data",
|
|
225
|
+
webhook_url: "https://myapp.com/webhook"
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Opt in to credit-limit notifications with threshold levels (%)
|
|
229
|
+
await Airalo.Notification.NotificationOptIn({
|
|
230
|
+
type: "webhook_credit_limit",
|
|
231
|
+
webhook_url: "https://myapp.com/webhook",
|
|
232
|
+
levels: [50, 70, 80, 90]
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// Opt out
|
|
236
|
+
await Airalo.Notification.NotificationOptOut({
|
|
237
|
+
type: "webhook_low_data" // email_low_data | email_credit_limit | webhook_low_data | webhook_credit_limit
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// Get current notification settings
|
|
241
|
+
const settings = await Airalo.Notification.GetNotification();
|
|
242
|
+
|
|
243
|
+
// Simulate a webhook event (sandbox only)
|
|
244
|
+
await Airalo.Notification.SimulateWebhook({
|
|
245
|
+
event: "low_data_notification",
|
|
246
|
+
type: "expire_1",
|
|
247
|
+
iccid: "8997212330099025334"
|
|
248
|
+
});
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
### Misc
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
// List eSIM-compatible devices
|
|
257
|
+
const devices = await Airalo.Misc.GetCompatibleDevices();
|
|
258
|
+
|
|
259
|
+
// Create an eSIM voucher
|
|
260
|
+
const voucher = await Airalo.Misc.CreateEsimVoucher({
|
|
261
|
+
package_id: "chinacom-7days-1gb",
|
|
262
|
+
quantity: 1
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Response format
|
|
269
|
+
|
|
270
|
+
Every method returns an `ApiResult<T>` object:
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
// Success
|
|
274
|
+
{
|
|
275
|
+
success: true,
|
|
276
|
+
data: T,
|
|
277
|
+
message: "Амжилттай."
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Error
|
|
281
|
+
{
|
|
282
|
+
success: false,
|
|
283
|
+
data: null,
|
|
284
|
+
message: "Error message from API"
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Check `result.success` before accessing `result.data`:
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
const result = await Airalo.Order.SubmitOrder({
|
|
292
|
+
quantity: "1",
|
|
293
|
+
package_id: "chinacom-7days-1gb"
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
if (result.success) {
|
|
297
|
+
console.log(result.data.sims[0].qrcode_url);
|
|
298
|
+
} else {
|
|
299
|
+
console.error(result.message);
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## All methods
|
|
306
|
+
|
|
307
|
+
| Module | Method | Description |
|
|
308
|
+
| -------------- | ---------------------- | --------------------------------------- |
|
|
309
|
+
| `auth` | `TOKEN` | Fetch and store access token |
|
|
310
|
+
| `Package` | `Packages` | List packages (filterable by country) |
|
|
311
|
+
| `Order` | `SubmitOrder` | Place a synchronous order |
|
|
312
|
+
| `Order` | `SubmitOrderAsync` | Place an asynchronous order via webhook |
|
|
313
|
+
| `Order` | `SubmitTopUpOrder` | Top up an existing eSIM |
|
|
314
|
+
| `Order` | `GetOrderList` | List orders with filters |
|
|
315
|
+
| `Order` | `GetOrder` | Get a single order by ID |
|
|
316
|
+
| `Order` | `GetOrderStatuses` | List all order statuses |
|
|
317
|
+
| `Order` | `GetOrderStatusBySlug` | Get a single status by slug |
|
|
318
|
+
| `Sims` | `GetSimList` | List eSIMs with filters |
|
|
319
|
+
| `Sims` | `GetSim` | Get a single eSIM by ICCID |
|
|
320
|
+
| `Sims` | `GetSimInstructions` | Get installation instructions |
|
|
321
|
+
| `Sims` | `GetDataUsage` | Get current data usage |
|
|
322
|
+
| `Sims` | `GetTopUpPackageList` | List available top-up packages |
|
|
323
|
+
| `Sims` | `GetSimPackageHistory` | Get package history |
|
|
324
|
+
| `Sims` | `UpdateSimBrand` | Update eSIM brand name |
|
|
325
|
+
| `Balance` | `GetBalance` | Get account balance |
|
|
326
|
+
| `Notification` | `NotificationOptIn` | Enable a notification type |
|
|
327
|
+
| `Notification` | `NotificationOptOut` | Disable a notification type |
|
|
328
|
+
| `Notification` | `GetNotification` | Get current notification settings |
|
|
329
|
+
| `Notification` | `SimulateWebhook` | Simulate a webhook event (sandbox) |
|
|
330
|
+
| `Misc` | `GetCompatibleDevices` | List eSIM-compatible devices |
|
|
331
|
+
| `Misc` | `CreateEsimVoucher` | Create an eSIM voucher |
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## Contributing
|
|
336
|
+
|
|
337
|
+
Pull requests are welcome. For major changes, please open an issue first.
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
git clone https://github.com/togtokh-dev/airalo.git
|
|
341
|
+
cd airalo
|
|
342
|
+
npm install
|
|
343
|
+
npm test
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## License
|
|
349
|
+
|
|
350
|
+
[ISC](https://opensource.org/licenses/ISC) © Buyantogtokh
|
|
351
|
+
|
|
352
|
+
> This is an **unofficial** SDK and is not affiliated with or endorsed by Airalo.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ApiResult } from "../utils/helpers";
|
|
2
|
+
export declare const TOKEN: (auth: {
|
|
3
|
+
client_id: string;
|
|
4
|
+
client_secret: string;
|
|
5
|
+
}) => Promise<ApiResult<{
|
|
6
|
+
access_token: string;
|
|
7
|
+
}>>;
|
|
8
|
+
export declare const getToken: () => Promise<string>;
|
|
9
|
+
declare const _default: {
|
|
10
|
+
TOKEN: (auth: {
|
|
11
|
+
client_id: string;
|
|
12
|
+
client_secret: string;
|
|
13
|
+
}) => Promise<ApiResult<{
|
|
14
|
+
access_token: string;
|
|
15
|
+
}>>;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
package/dist/api/auth.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getToken = exports.TOKEN = void 0;
|
|
7
|
+
const config_1 = require("../config");
|
|
8
|
+
const axios_master_1 = require("axios-master");
|
|
9
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
10
|
+
// Token авах дотоод функц
|
|
11
|
+
async function fetchToken(client_id, client_secret) {
|
|
12
|
+
const formData = new form_data_1.default();
|
|
13
|
+
formData.append("client_id", client_id);
|
|
14
|
+
formData.append("client_secret", client_secret);
|
|
15
|
+
formData.append("grant_type", "client_credentials");
|
|
16
|
+
const response = await (0, axios_master_1.axiosMasterLogger)({
|
|
17
|
+
method: "POST",
|
|
18
|
+
url: `${config_1.config.host}/v2/token`,
|
|
19
|
+
headers: {
|
|
20
|
+
Accept: "application/json",
|
|
21
|
+
...formData.getHeaders()
|
|
22
|
+
},
|
|
23
|
+
data: formData
|
|
24
|
+
}, {
|
|
25
|
+
name: "Token",
|
|
26
|
+
timeout: 20000,
|
|
27
|
+
logger: (data) => config_1.config.logger && console.log("Token:", data.json)
|
|
28
|
+
});
|
|
29
|
+
return response?.data?.access_token ?? "";
|
|
30
|
+
}
|
|
31
|
+
// Нэвтрэлт хийж token авах - гадаад ашиглалт
|
|
32
|
+
const TOKEN = async (auth) => {
|
|
33
|
+
try {
|
|
34
|
+
const token = await fetchToken(auth.client_id, auth.client_secret);
|
|
35
|
+
if (token) {
|
|
36
|
+
// Тохиргоонд хадгалах
|
|
37
|
+
config_1.config.token = token;
|
|
38
|
+
config_1.config.auth = auth;
|
|
39
|
+
return {
|
|
40
|
+
success: true,
|
|
41
|
+
data: { access_token: token },
|
|
42
|
+
message: "Token амжилттай авлаа."
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
data: null,
|
|
48
|
+
message: "Token авахад амжилтгүй болсон."
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const axiosError = error;
|
|
53
|
+
console.error("Token хүсэлт амжилтгүй:", axiosError.message);
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
data: null,
|
|
57
|
+
message: axiosError?.response?.data?.meta?.message ?? "Алдаа гарлаа."
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.TOKEN = TOKEN;
|
|
62
|
+
// 401 алдааны үед автоматаар token шинэчлэх функц (axiosMasterLogger-т дамжуулна)
|
|
63
|
+
const getToken = async () => {
|
|
64
|
+
try {
|
|
65
|
+
const token = await fetchToken(config_1.config.auth.client_id, config_1.config.auth.client_secret);
|
|
66
|
+
if (token)
|
|
67
|
+
config_1.config.token = token;
|
|
68
|
+
return token;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error("Token шинэчлэлт амжилтгүй:", error.message);
|
|
72
|
+
return "";
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.getToken = getToken;
|
|
76
|
+
exports.default = { TOKEN: exports.TOKEN };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiResult } from "../utils/helpers";
|
|
2
|
+
type BalanceData = {
|
|
3
|
+
balances: {
|
|
4
|
+
name: "balance";
|
|
5
|
+
availableBalance: {
|
|
6
|
+
amount: number;
|
|
7
|
+
currency: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const GetBalance: () => Promise<ApiResult<BalanceData>>;
|
|
12
|
+
declare const _default: {
|
|
13
|
+
GetBalance: () => Promise<ApiResult<BalanceData>>;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetBalance = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const axios_master_1 = require("axios-master");
|
|
6
|
+
const auth_1 = require("./auth");
|
|
7
|
+
// Дансны үлдэгдлийг авах
|
|
8
|
+
const GetBalance = async () => {
|
|
9
|
+
try {
|
|
10
|
+
const result = await (0, axios_master_1.axiosMasterLogger)({
|
|
11
|
+
method: "GET",
|
|
12
|
+
url: `${config_1.config.host}/v2/balance`,
|
|
13
|
+
headers: {
|
|
14
|
+
Accept: "application/json",
|
|
15
|
+
Authorization: `Bearer ${config_1.config.token}`
|
|
16
|
+
}
|
|
17
|
+
}, {
|
|
18
|
+
name: "GetBalance",
|
|
19
|
+
timeout: 20000,
|
|
20
|
+
retryFunction: auth_1.getToken,
|
|
21
|
+
shouldRetry: true,
|
|
22
|
+
shouldRetryStatus: [401],
|
|
23
|
+
logger: (data) => config_1.config.logger && console.log("GetBalance:", data.json)
|
|
24
|
+
});
|
|
25
|
+
return { success: true, data: result.data ?? null, message: "Амжилттай." };
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
const axiosError = error;
|
|
29
|
+
console.error("GetBalance амжилтгүй:", axiosError.message);
|
|
30
|
+
return {
|
|
31
|
+
success: false,
|
|
32
|
+
data: null,
|
|
33
|
+
message: axiosError?.response?.data?.meta?.message ?? "Алдаа гарлаа."
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.GetBalance = GetBalance;
|
|
38
|
+
exports.default = { GetBalance: exports.GetBalance };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ApiResult } from "../utils/helpers";
|
|
2
|
+
type CompatibleDevice = {
|
|
3
|
+
name: string;
|
|
4
|
+
model: string;
|
|
5
|
+
brand: string;
|
|
6
|
+
os: string;
|
|
7
|
+
compatible: boolean;
|
|
8
|
+
};
|
|
9
|
+
type EsimVoucher = {
|
|
10
|
+
code: string;
|
|
11
|
+
package_id: string;
|
|
12
|
+
created_at: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const GetCompatibleDevices: () => Promise<ApiResult<CompatibleDevice[]>>;
|
|
15
|
+
export declare const CreateEsimVoucher: (params: {
|
|
16
|
+
package_id: string;
|
|
17
|
+
quantity?: number;
|
|
18
|
+
}) => Promise<ApiResult<EsimVoucher[]>>;
|
|
19
|
+
declare const _default: {
|
|
20
|
+
GetCompatibleDevices: () => Promise<ApiResult<CompatibleDevice[]>>;
|
|
21
|
+
CreateEsimVoucher: (params: {
|
|
22
|
+
package_id: string;
|
|
23
|
+
quantity?: number;
|
|
24
|
+
}) => Promise<ApiResult<EsimVoucher[]>>;
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
package/dist/api/misc.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateEsimVoucher = exports.GetCompatibleDevices = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const axios_master_1 = require("axios-master");
|
|
6
|
+
const auth_1 = require("./auth");
|
|
7
|
+
// eSIM-тэй тохирох төхөөрөмжүүдийн жагсаалтыг авах
|
|
8
|
+
const GetCompatibleDevices = async () => {
|
|
9
|
+
try {
|
|
10
|
+
const result = await (0, axios_master_1.axiosMasterLogger)({
|
|
11
|
+
method: "GET",
|
|
12
|
+
url: `${config_1.config.host}/v2/compatible-devices`,
|
|
13
|
+
headers: {
|
|
14
|
+
Accept: "application/json",
|
|
15
|
+
Authorization: `Bearer ${config_1.config.token}`
|
|
16
|
+
}
|
|
17
|
+
}, {
|
|
18
|
+
name: "GetCompatibleDevices",
|
|
19
|
+
timeout: 20000,
|
|
20
|
+
retryFunction: auth_1.getToken,
|
|
21
|
+
shouldRetry: true,
|
|
22
|
+
shouldRetryStatus: [401],
|
|
23
|
+
logger: (data) => config_1.config.logger && console.log("GetCompatibleDevices:", data.json)
|
|
24
|
+
});
|
|
25
|
+
return { success: true, data: result.data ?? [], message: "Амжилттай." };
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
const axiosError = error;
|
|
29
|
+
console.error("GetCompatibleDevices амжилтгүй:", axiosError.message);
|
|
30
|
+
return {
|
|
31
|
+
success: false,
|
|
32
|
+
data: null,
|
|
33
|
+
message: axiosError?.response?.data?.meta?.message ?? "Алдаа гарлаа."
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.GetCompatibleDevices = GetCompatibleDevices;
|
|
38
|
+
// eSIM ваучер үүсгэх
|
|
39
|
+
const CreateEsimVoucher = async (params) => {
|
|
40
|
+
try {
|
|
41
|
+
const result = await (0, axios_master_1.axiosMasterLogger)({
|
|
42
|
+
method: "POST",
|
|
43
|
+
url: `${config_1.config.host}/v2/voucher/esim`,
|
|
44
|
+
headers: {
|
|
45
|
+
Accept: "application/json",
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
|
+
Authorization: `Bearer ${config_1.config.token}`
|
|
48
|
+
},
|
|
49
|
+
data: params
|
|
50
|
+
}, {
|
|
51
|
+
name: "CreateEsimVoucher",
|
|
52
|
+
timeout: 20000,
|
|
53
|
+
retryFunction: auth_1.getToken,
|
|
54
|
+
shouldRetry: true,
|
|
55
|
+
shouldRetryStatus: [401],
|
|
56
|
+
logger: (data) => config_1.config.logger && console.log("CreateEsimVoucher:", data.json)
|
|
57
|
+
});
|
|
58
|
+
return { success: true, data: result.data ?? [], message: "Амжилттай." };
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
const axiosError = error;
|
|
62
|
+
console.error("CreateEsimVoucher амжилтгүй:", axiosError.message);
|
|
63
|
+
return {
|
|
64
|
+
success: false,
|
|
65
|
+
data: null,
|
|
66
|
+
message: axiosError?.response?.data?.meta?.message ?? "Алдаа гарлаа."
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.CreateEsimVoucher = CreateEsimVoucher;
|
|
71
|
+
exports.default = { GetCompatibleDevices: exports.GetCompatibleDevices, CreateEsimVoucher: exports.CreateEsimVoucher };
|