@tourist-esim/touristesim-nodejs-sdk 1.0.4 → 1.2.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 +8 -10
- package/dist/Models/Model.d.ts +14 -2
- package/dist/Models/Model.js +53 -10
- package/dist/Resources/Plans.d.ts +1 -1
- package/dist/Resources/Plans.js +2 -2
- package/dist/Resources/index.d.ts +1 -2
- package/dist/Resources/index.js +2 -6
- package/package.json +2 -2
- package/src/Models/Model.ts +66 -11
- package/src/Resources/Plans.ts +2 -2
- package/src/Resources/index.ts +2 -7
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ const plans = await sdk.plans().get({
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
// Get single plan
|
|
63
|
-
const plan = await sdk.plans().find(
|
|
63
|
+
const plan = await sdk.plans().find('vietnam_100mb_7days_7e87c5');
|
|
64
64
|
|
|
65
65
|
// Get plans by country
|
|
66
66
|
const usPlans = await sdk.plans().byCountry('US');
|
|
@@ -69,7 +69,7 @@ const usPlans = await sdk.plans().byCountry('US');
|
|
|
69
69
|
const globalPlans = await sdk.plans().global();
|
|
70
70
|
|
|
71
71
|
// Validate plan
|
|
72
|
-
const validation = await sdk.plans().validate(
|
|
72
|
+
const validation = await sdk.plans().validate('vietnam_100mb_7days_7e87c5', 5);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
### Countries
|
|
@@ -93,19 +93,17 @@ const featured = await sdk.countries().featured();
|
|
|
93
93
|
```typescript
|
|
94
94
|
// Create order
|
|
95
95
|
const order = await sdk.orders().create({
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
customer_email: 'customer@example.com'
|
|
96
|
+
plans: [{ plan_slug: 'vietnam_100mb_7days_7e87c5', quantity: 1 }],
|
|
97
|
+
customer: { email: 'customer@example.com', name: 'Jane Doe' },
|
|
99
98
|
});
|
|
100
99
|
|
|
101
100
|
// Get orders
|
|
102
101
|
const orders = await sdk.orders().all();
|
|
103
102
|
|
|
104
|
-
// Get single order
|
|
105
|
-
const order = await sdk.orders().find(
|
|
103
|
+
// Get single order by order number
|
|
104
|
+
const order = await sdk.orders().find('PO-260519MKAUVE');
|
|
106
105
|
|
|
107
|
-
//
|
|
108
|
-
await sdk.orders().cancel(456);
|
|
106
|
+
// To request a cancellation or refund, contact Tourist eSIM support
|
|
109
107
|
```
|
|
110
108
|
|
|
111
109
|
### eSIMs
|
|
@@ -141,7 +139,7 @@ import {
|
|
|
141
139
|
} from '@tourist-esim/touristesim-nodejs-sdk';
|
|
142
140
|
|
|
143
141
|
try {
|
|
144
|
-
const plan = await sdk.plans().find(
|
|
142
|
+
const plan = await sdk.plans().find('nonexistent_plan_slug');
|
|
145
143
|
} catch (error) {
|
|
146
144
|
if (error instanceof AuthenticationException) {
|
|
147
145
|
console.error('Auth failed:', error.message);
|
package/dist/Models/Model.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare class Model {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare class Plan extends Model {
|
|
21
21
|
protected casts: Record<string, string>;
|
|
22
|
+
getPlanSlug(): string;
|
|
22
23
|
getType(): string;
|
|
23
24
|
isLocal(): boolean;
|
|
24
25
|
isRegional(): boolean;
|
|
@@ -59,8 +60,7 @@ export declare class Order extends Model {
|
|
|
59
60
|
isPending(): boolean;
|
|
60
61
|
isFailed(): boolean;
|
|
61
62
|
isCancelled(): boolean;
|
|
62
|
-
|
|
63
|
-
getQuantity(): number;
|
|
63
|
+
getItemsCount(): number;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* eSIM Model
|
|
@@ -75,4 +75,16 @@ export declare class Esim extends Model {
|
|
|
75
75
|
getIccid(): string;
|
|
76
76
|
getBalanceData(): number;
|
|
77
77
|
getValidityEnd(): string | null;
|
|
78
|
+
getCoverage(): Record<string, unknown> | null;
|
|
79
|
+
getCoverageType(): string | null;
|
|
80
|
+
getCoverageLabel(): string | null;
|
|
81
|
+
getCoverageCountries(): Record<string, unknown>[];
|
|
82
|
+
getCoverageRegion(): Record<string, unknown> | null;
|
|
83
|
+
getNetworkOperators(): Record<string, unknown> | null;
|
|
84
|
+
getNetworkOperatorsCount(): number;
|
|
85
|
+
getNetworkOperatorNames(): string[];
|
|
86
|
+
getShareLink(): Record<string, unknown> | null;
|
|
87
|
+
getShareLinkSlug(): string | null;
|
|
88
|
+
getShareLinkUrl(): string | null;
|
|
89
|
+
getShareLinkPin(): string | null;
|
|
78
90
|
}
|
package/dist/Models/Model.js
CHANGED
|
@@ -64,7 +64,6 @@ export class Plan extends Model {
|
|
|
64
64
|
constructor() {
|
|
65
65
|
super(...arguments);
|
|
66
66
|
this.casts = {
|
|
67
|
-
id: 'integer',
|
|
68
67
|
price: 'float',
|
|
69
68
|
data: 'integer',
|
|
70
69
|
validity_days: 'integer',
|
|
@@ -72,6 +71,9 @@ export class Plan extends Model {
|
|
|
72
71
|
countries_count: 'integer',
|
|
73
72
|
};
|
|
74
73
|
}
|
|
74
|
+
getPlanSlug() {
|
|
75
|
+
return this.get('plan_slug', '');
|
|
76
|
+
}
|
|
75
77
|
getType() {
|
|
76
78
|
return this.get('type', 'local');
|
|
77
79
|
}
|
|
@@ -152,10 +154,9 @@ export class Order extends Model {
|
|
|
152
154
|
constructor() {
|
|
153
155
|
super(...arguments);
|
|
154
156
|
this.casts = {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
total_price: 'float',
|
|
157
|
+
items_count: 'integer',
|
|
158
|
+
amount: 'float',
|
|
159
|
+
is_sandbox: 'boolean',
|
|
159
160
|
};
|
|
160
161
|
}
|
|
161
162
|
getStatus() {
|
|
@@ -173,11 +174,8 @@ export class Order extends Model {
|
|
|
173
174
|
isCancelled() {
|
|
174
175
|
return this.getStatus() === 'cancelled';
|
|
175
176
|
}
|
|
176
|
-
|
|
177
|
-
return this.get('
|
|
178
|
-
}
|
|
179
|
-
getQuantity() {
|
|
180
|
-
return this.get('quantity', 0);
|
|
177
|
+
getItemsCount() {
|
|
178
|
+
return this.get('items_count', 0);
|
|
181
179
|
}
|
|
182
180
|
}
|
|
183
181
|
/**
|
|
@@ -214,4 +212,49 @@ export class Esim extends Model {
|
|
|
214
212
|
getValidityEnd() {
|
|
215
213
|
return this.get('validity_end', null);
|
|
216
214
|
}
|
|
215
|
+
getCoverage() {
|
|
216
|
+
return this.get('coverage', null);
|
|
217
|
+
}
|
|
218
|
+
getCoverageType() {
|
|
219
|
+
const coverage = this.getCoverage();
|
|
220
|
+
return coverage?.type;
|
|
221
|
+
}
|
|
222
|
+
getCoverageLabel() {
|
|
223
|
+
const coverage = this.getCoverage();
|
|
224
|
+
return coverage?.label;
|
|
225
|
+
}
|
|
226
|
+
getCoverageCountries() {
|
|
227
|
+
const coverage = this.getCoverage();
|
|
228
|
+
return coverage?.countries || [];
|
|
229
|
+
}
|
|
230
|
+
getCoverageRegion() {
|
|
231
|
+
const coverage = this.getCoverage();
|
|
232
|
+
return coverage?.region || null;
|
|
233
|
+
}
|
|
234
|
+
getNetworkOperators() {
|
|
235
|
+
return this.get('network_operators', null);
|
|
236
|
+
}
|
|
237
|
+
getNetworkOperatorsCount() {
|
|
238
|
+
const operators = this.getNetworkOperators();
|
|
239
|
+
return operators?.count || 0;
|
|
240
|
+
}
|
|
241
|
+
getNetworkOperatorNames() {
|
|
242
|
+
const operators = this.getNetworkOperators();
|
|
243
|
+
return operators?.operators || [];
|
|
244
|
+
}
|
|
245
|
+
getShareLink() {
|
|
246
|
+
return this.get('share_link', null);
|
|
247
|
+
}
|
|
248
|
+
getShareLinkSlug() {
|
|
249
|
+
const shareLink = this.getShareLink();
|
|
250
|
+
return shareLink?.slug || null;
|
|
251
|
+
}
|
|
252
|
+
getShareLinkUrl() {
|
|
253
|
+
const shareLink = this.getShareLink();
|
|
254
|
+
return shareLink?.url || null;
|
|
255
|
+
}
|
|
256
|
+
getShareLinkPin() {
|
|
257
|
+
const shareLink = this.getShareLink();
|
|
258
|
+
return shareLink?.pin || null;
|
|
259
|
+
}
|
|
217
260
|
}
|
|
@@ -7,7 +7,7 @@ import { Collection, PaginatedCollection } from '../Support/Collection.js';
|
|
|
7
7
|
export declare class Plans extends Resource {
|
|
8
8
|
get(filters?: Record<string, any>): Promise<PaginatedCollection>;
|
|
9
9
|
find(id: number | string): Promise<Plan>;
|
|
10
|
-
validate(
|
|
10
|
+
validate(planSlug: string, quantity: number): Promise<Record<string, any>>;
|
|
11
11
|
byCountry(code: string, perPage?: number): Promise<Collection<Plan>>;
|
|
12
12
|
byRegion(slug: string, perPage?: number): Promise<Collection<Plan>>;
|
|
13
13
|
global(perPage?: number): Promise<Collection<Plan>>;
|
package/dist/Resources/Plans.js
CHANGED
|
@@ -13,9 +13,9 @@ export class Plans extends Resource {
|
|
|
13
13
|
const response = await this.client.get(`/plans/${id}`);
|
|
14
14
|
return new Plan(response.data);
|
|
15
15
|
}
|
|
16
|
-
async validate(
|
|
16
|
+
async validate(planSlug, quantity) {
|
|
17
17
|
const response = await this.client.post('/plans/validate', {
|
|
18
|
-
|
|
18
|
+
plan_slug: planSlug,
|
|
19
19
|
quantity,
|
|
20
20
|
});
|
|
21
21
|
return response.data || {};
|
|
@@ -12,9 +12,8 @@ import { Order } from '../Models/Model.js';
|
|
|
12
12
|
import { Collection, PaginatedCollection } from '../Support/Collection.js';
|
|
13
13
|
export declare class Orders extends Resource {
|
|
14
14
|
all(filters?: Record<string, any>): Promise<PaginatedCollection<Order>>;
|
|
15
|
-
find(
|
|
15
|
+
find(orderNumber: string): Promise<Order>;
|
|
16
16
|
create(data: Record<string, any>): Promise<Order>;
|
|
17
|
-
cancel(id: number | string): Promise<boolean>;
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
20
19
|
* Esims Resource
|
package/dist/Resources/index.js
CHANGED
|
@@ -18,18 +18,14 @@ export class Orders extends Resource {
|
|
|
18
18
|
const response = await this.client.get('/orders', filters);
|
|
19
19
|
return new PaginatedCollection(Collection.make(response.data?.orders || [], Order).all(), response.data?.pagination || {});
|
|
20
20
|
}
|
|
21
|
-
async find(
|
|
22
|
-
const response = await this.client.get(`/orders/${
|
|
21
|
+
async find(orderNumber) {
|
|
22
|
+
const response = await this.client.get(`/orders/${orderNumber}`);
|
|
23
23
|
return new Order(response.data);
|
|
24
24
|
}
|
|
25
25
|
async create(data) {
|
|
26
26
|
const response = await this.client.post('/orders', data);
|
|
27
27
|
return new Order(response.data);
|
|
28
28
|
}
|
|
29
|
-
async cancel(id) {
|
|
30
|
-
await this.client.post(`/orders/${id}/cancel`, {});
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
29
|
}
|
|
34
30
|
/**
|
|
35
31
|
* Esims Resource
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tourist-esim/touristesim-nodejs-sdk",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Official Node.js SDK for Tourist eSIM Partner API - Easy integration for resellers and partners",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -50,4 +50,4 @@
|
|
|
50
50
|
"ts-jest": "^29.1.1",
|
|
51
51
|
"typescript": "^5.2.0"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|
package/src/Models/Model.ts
CHANGED
|
@@ -72,7 +72,6 @@ export class Model {
|
|
|
72
72
|
*/
|
|
73
73
|
export class Plan extends Model {
|
|
74
74
|
protected casts: Record<string, string> = {
|
|
75
|
-
id: 'integer',
|
|
76
75
|
price: 'float',
|
|
77
76
|
data: 'integer',
|
|
78
77
|
validity_days: 'integer',
|
|
@@ -80,6 +79,10 @@ export class Plan extends Model {
|
|
|
80
79
|
countries_count: 'integer',
|
|
81
80
|
};
|
|
82
81
|
|
|
82
|
+
getPlanSlug(): string {
|
|
83
|
+
return this.get('plan_slug', '');
|
|
84
|
+
}
|
|
85
|
+
|
|
83
86
|
getType(): string {
|
|
84
87
|
return this.get('type', 'local');
|
|
85
88
|
}
|
|
@@ -176,10 +179,9 @@ export class Country extends Model {
|
|
|
176
179
|
*/
|
|
177
180
|
export class Order extends Model {
|
|
178
181
|
protected casts: Record<string, string> = {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
total_price: 'float',
|
|
182
|
+
items_count: 'integer',
|
|
183
|
+
amount: 'float',
|
|
184
|
+
is_sandbox: 'boolean',
|
|
183
185
|
};
|
|
184
186
|
|
|
185
187
|
getStatus(): string {
|
|
@@ -202,12 +204,8 @@ export class Order extends Model {
|
|
|
202
204
|
return this.getStatus() === 'cancelled';
|
|
203
205
|
}
|
|
204
206
|
|
|
205
|
-
|
|
206
|
-
return this.get('
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
getQuantity(): number {
|
|
210
|
-
return this.get('quantity', 0);
|
|
207
|
+
getItemsCount(): number {
|
|
208
|
+
return this.get('items_count', 0);
|
|
211
209
|
}
|
|
212
210
|
}
|
|
213
211
|
|
|
@@ -250,4 +248,61 @@ export class Esim extends Model {
|
|
|
250
248
|
getValidityEnd(): string | null {
|
|
251
249
|
return this.get('validity_end', null);
|
|
252
250
|
}
|
|
251
|
+
|
|
252
|
+
getCoverage(): Record<string, unknown> | null {
|
|
253
|
+
return this.get('coverage', null);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
getCoverageType(): string | null {
|
|
257
|
+
const coverage = this.getCoverage();
|
|
258
|
+
return coverage?.type as string | null;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
getCoverageLabel(): string | null {
|
|
262
|
+
const coverage = this.getCoverage();
|
|
263
|
+
return coverage?.label as string | null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
getCoverageCountries(): Record<string, unknown>[] {
|
|
267
|
+
const coverage = this.getCoverage();
|
|
268
|
+
return (coverage?.countries as Record<string, unknown>[]) || [];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
getCoverageRegion(): Record<string, unknown> | null {
|
|
272
|
+
const coverage = this.getCoverage();
|
|
273
|
+
return (coverage?.region as Record<string, unknown>) || null;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
getNetworkOperators(): Record<string, unknown> | null {
|
|
277
|
+
return this.get('network_operators', null);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
getNetworkOperatorsCount(): number {
|
|
281
|
+
const operators = this.getNetworkOperators();
|
|
282
|
+
return (operators?.count as number) || 0;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
getNetworkOperatorNames(): string[] {
|
|
286
|
+
const operators = this.getNetworkOperators();
|
|
287
|
+
return (operators?.operators as string[]) || [];
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
getShareLink(): Record<string, unknown> | null {
|
|
291
|
+
return this.get('share_link', null);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
getShareLinkSlug(): string | null {
|
|
295
|
+
const shareLink = this.getShareLink();
|
|
296
|
+
return (shareLink?.slug as string) || null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
getShareLinkUrl(): string | null {
|
|
300
|
+
const shareLink = this.getShareLink();
|
|
301
|
+
return (shareLink?.url as string) || null;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
getShareLinkPin(): string | null {
|
|
305
|
+
const shareLink = this.getShareLink();
|
|
306
|
+
return (shareLink?.pin as string) || null;
|
|
307
|
+
}
|
|
253
308
|
}
|
package/src/Resources/Plans.ts
CHANGED
|
@@ -19,9 +19,9 @@ export class Plans extends Resource {
|
|
|
19
19
|
return new Plan(response.data);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
async validate(
|
|
22
|
+
async validate(planSlug: string, quantity: number): Promise<Record<string, any>> {
|
|
23
23
|
const response = await this.client.post('/plans/validate', {
|
|
24
|
-
|
|
24
|
+
plan_slug: planSlug,
|
|
25
25
|
quantity,
|
|
26
26
|
});
|
|
27
27
|
return response.data || {};
|
package/src/Resources/index.ts
CHANGED
|
@@ -25,8 +25,8 @@ export class Orders extends Resource {
|
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
async find(
|
|
29
|
-
const response = await this.client.get(`/orders/${
|
|
28
|
+
async find(orderNumber: string): Promise<Order> {
|
|
29
|
+
const response = await this.client.get(`/orders/${orderNumber}`);
|
|
30
30
|
return new Order(response.data);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -34,11 +34,6 @@ export class Orders extends Resource {
|
|
|
34
34
|
const response = await this.client.post('/orders', data);
|
|
35
35
|
return new Order(response.data);
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
async cancel(id: number | string): Promise<boolean> {
|
|
39
|
-
await this.client.post(`/orders/${id}/cancel`, {});
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
37
|
}
|
|
43
38
|
|
|
44
39
|
/**
|