@tourist-esim/touristesim-nodejs-sdk 1.1.0 → 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 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(123);
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(123, 5);
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
- plan_id: 123,
97
- quantity: 2,
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(456);
103
+ // Get single order by order number
104
+ const order = await sdk.orders().find('PO-260519MKAUVE');
106
105
 
107
- // Cancel order
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(999);
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);
@@ -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
- getTotalPrice(): number;
63
- getQuantity(): number;
63
+ getItemsCount(): number;
64
64
  }
65
65
  /**
66
66
  * eSIM Model
@@ -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
- id: 'integer',
156
- plan_id: 'integer',
157
- quantity: 'integer',
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
- getTotalPrice() {
177
- return this.get('total_price', 0);
178
- }
179
- getQuantity() {
180
- return this.get('quantity', 0);
177
+ getItemsCount() {
178
+ return this.get('items_count', 0);
181
179
  }
182
180
  }
183
181
  /**
@@ -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(planId: number, quantity: number): Promise<Record<string, any>>;
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>>;
@@ -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(planId, quantity) {
16
+ async validate(planSlug, quantity) {
17
17
  const response = await this.client.post('/plans/validate', {
18
- plan_id: planId,
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(id: number | string): Promise<Order>;
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
@@ -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(id) {
22
- const response = await this.client.get(`/orders/${id}`);
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.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",
@@ -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
- id: 'integer',
180
- plan_id: 'integer',
181
- quantity: 'integer',
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
- getTotalPrice(): number {
206
- return this.get('total_price', 0);
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
 
@@ -19,9 +19,9 @@ export class Plans extends Resource {
19
19
  return new Plan(response.data);
20
20
  }
21
21
 
22
- async validate(planId: number, quantity: number): Promise<Record<string, any>> {
22
+ async validate(planSlug: string, quantity: number): Promise<Record<string, any>> {
23
23
  const response = await this.client.post('/plans/validate', {
24
- plan_id: planId,
24
+ plan_slug: planSlug,
25
25
  quantity,
26
26
  });
27
27
  return response.data || {};
@@ -25,8 +25,8 @@ export class Orders extends Resource {
25
25
  );
26
26
  }
27
27
 
28
- async find(id: number | string): Promise<Order> {
29
- const response = await this.client.get(`/orders/${id}`);
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
  /**