pathao-merchant-sdk 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/LICENSE +21 -0
- package/README.md +345 -0
- package/dist/index.d.mts +246 -0
- package/dist/index.d.ts +246 -0
- package/dist/index.js +285 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +276 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sifat Jasim
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
# Pathao Merchant API SDK
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/%40sifat07%2Fpathao-merchant-sdk)
|
|
4
|
+
[](https://www.typescriptlang.org/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
An **unofficial** TypeScript SDK for integrating with the Pathao Merchant API. This community package provides a clean, type-safe interface for all Pathao Merchant API operations including order management, store management, price calculation, and more.
|
|
8
|
+
|
|
9
|
+
> **Disclaimer**: This is not an official package from Pathao. It's a community-maintained SDK based on the public Pathao Merchant API documentation.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 🚀 **Full TypeScript Support** - Complete type definitions for all API responses
|
|
14
|
+
- 🔐 **Automatic Authentication** - Handles OAuth2 token management and refresh
|
|
15
|
+
- 📦 **Order Management** - Create, track, and manage delivery orders
|
|
16
|
+
- 🏪 **Store Management** - Create and manage pickup/service points
|
|
17
|
+
- 💰 **Price Calculation** - Get accurate delivery charges before creating orders
|
|
18
|
+
- 🌍 **Location Services** - Access cities, zones, and areas data
|
|
19
|
+
- ⚡ **Built with Axios** - Reliable HTTP client with request/response interceptors
|
|
20
|
+
- 🛡️ **Error Handling** - Comprehensive error handling with detailed error messages
|
|
21
|
+
- 📚 **Well Documented** - Extensive documentation and examples
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @sifat07/pathao-merchant-sdk
|
|
27
|
+
# or
|
|
28
|
+
yarn add @sifat07/pathao-merchant-sdk
|
|
29
|
+
# or
|
|
30
|
+
pnpm add @sifat07/pathao-merchant-sdk
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { PathaoApiService, DeliveryType, ItemType } from '@sifat07/pathao-merchant-sdk';
|
|
37
|
+
|
|
38
|
+
// Initialize the SDK
|
|
39
|
+
const pathao = new PathaoApiService({
|
|
40
|
+
clientId: 'your-client-id',
|
|
41
|
+
clientSecret: 'your-client-secret',
|
|
42
|
+
username: 'your-username',
|
|
43
|
+
password: 'your-password'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Create a delivery order
|
|
47
|
+
const order = await pathao.createOrder({
|
|
48
|
+
store_id: 123,
|
|
49
|
+
recipient_name: 'John Doe',
|
|
50
|
+
recipient_phone: '01712345678',
|
|
51
|
+
recipient_address: '123 Main Street, Dhanmondi, Dhaka',
|
|
52
|
+
delivery_type: DeliveryType.NORMAL,
|
|
53
|
+
item_type: ItemType.PARCEL,
|
|
54
|
+
item_quantity: 1,
|
|
55
|
+
item_weight: 1.0,
|
|
56
|
+
amount_to_collect: 500
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log('Order created:', order.data.consignment_id);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## API Reference
|
|
63
|
+
|
|
64
|
+
### Configuration
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
interface PathaoConfig {
|
|
68
|
+
clientId: string; // Your Pathao API client ID
|
|
69
|
+
clientSecret: string; // Your Pathao API client secret
|
|
70
|
+
username: string; // Your Pathao API username
|
|
71
|
+
password: string; // Your Pathao API password
|
|
72
|
+
baseURL?: string; // API base URL (default: https://api-hermes.pathao.com)
|
|
73
|
+
timeout?: number; // Request timeout in ms (default: 30000)
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Order Management
|
|
78
|
+
|
|
79
|
+
#### Create Order
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const order = await pathao.createOrder({
|
|
83
|
+
store_id: 123,
|
|
84
|
+
merchant_order_id: 'ORDER-123', // Optional: Your order tracking ID
|
|
85
|
+
recipient_name: 'John Doe',
|
|
86
|
+
recipient_phone: '01712345678',
|
|
87
|
+
recipient_secondary_phone: '01712345679', // Optional
|
|
88
|
+
recipient_address: '123 Main Street, Dhanmondi',
|
|
89
|
+
recipient_city: 1, // Optional: Auto-detected if not provided
|
|
90
|
+
recipient_zone: 1, // Optional: Auto-detected if not provided
|
|
91
|
+
recipient_area: 1, // Optional: Auto-detected if not provided
|
|
92
|
+
delivery_type: DeliveryType.NORMAL, // 48 for Normal, 12 for On Demand
|
|
93
|
+
item_type: ItemType.PARCEL, // 1 for Document, 2 for Parcel
|
|
94
|
+
special_instruction: 'Call before delivery', // Optional
|
|
95
|
+
item_quantity: 1,
|
|
96
|
+
item_weight: 1.0, // 0.5-10 kg
|
|
97
|
+
item_description: 'Electronics', // Optional
|
|
98
|
+
amount_to_collect: 500 // COD amount (0 for non-COD)
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Get Order Status
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const status = await pathao.getOrderStatus('consignment-id');
|
|
106
|
+
console.log('Order status:', status.data.status);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Store Management
|
|
110
|
+
|
|
111
|
+
#### Create Store
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const store = await pathao.createStore({
|
|
115
|
+
name: 'My Store',
|
|
116
|
+
contact_name: 'Store Manager',
|
|
117
|
+
contact_number: '01712345678',
|
|
118
|
+
address: '123 Store Street, Dhanmondi',
|
|
119
|
+
city_id: 1,
|
|
120
|
+
zone_id: 1,
|
|
121
|
+
area_id: 1,
|
|
122
|
+
store_type: StoreType.PICKUP_POINT // 1 for Pickup Point, 2 for Service Point
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Get Stores
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const stores = await pathao.getStores();
|
|
130
|
+
console.log('Available stores:', stores);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Price Calculation
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const price = await pathao.calculatePrice({
|
|
137
|
+
store_id: 123,
|
|
138
|
+
item_type: ItemType.PARCEL,
|
|
139
|
+
item_weight: 1.0,
|
|
140
|
+
delivery_type: DeliveryType.NORMAL,
|
|
141
|
+
recipient_city: 1,
|
|
142
|
+
recipient_zone: 1,
|
|
143
|
+
recipient_area: 1
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
console.log('Delivery charge:', price.data.delivery_charge);
|
|
147
|
+
console.log('COD charge:', price.data.cod_charge);
|
|
148
|
+
console.log('Total charge:', price.data.total_charge);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Location Services
|
|
152
|
+
|
|
153
|
+
#### Get Cities
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const cities = await pathao.getCities();
|
|
157
|
+
console.log('Available cities:', cities.data);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Get Areas
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const areas = await pathao.getAreas();
|
|
164
|
+
console.log('Available areas:', areas.data);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Validation Helpers
|
|
168
|
+
|
|
169
|
+
The SDK includes built-in validation helpers:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { PathaoApiService } from '@sifat07/pathao-merchant-sdk';
|
|
173
|
+
|
|
174
|
+
// Validate phone number
|
|
175
|
+
const isValidPhone = PathaoApiService.validatePhoneNumber('01712345678'); // true
|
|
176
|
+
|
|
177
|
+
// Format phone number
|
|
178
|
+
const formattedPhone = PathaoApiService.formatPhoneNumber('01712345678'); // '01712345678'
|
|
179
|
+
|
|
180
|
+
// Validate address
|
|
181
|
+
const isValidAddress = PathaoApiService.validateAddress('123 Main Street'); // true
|
|
182
|
+
|
|
183
|
+
// Validate weight
|
|
184
|
+
const isValidWeight = PathaoApiService.validateWeight(1.0); // true
|
|
185
|
+
|
|
186
|
+
// Validate recipient name
|
|
187
|
+
const isValidName = PathaoApiService.validateRecipientName('John Doe'); // true
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Enums
|
|
191
|
+
|
|
192
|
+
### DeliveryType
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
enum DeliveryType {
|
|
196
|
+
NORMAL = 48, // Normal delivery
|
|
197
|
+
ON_DEMAND = 12 // On-demand delivery
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### ItemType
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
enum ItemType {
|
|
205
|
+
DOCUMENT = 1, // Document
|
|
206
|
+
PARCEL = 2 // Parcel
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### StoreType
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
enum StoreType {
|
|
214
|
+
PICKUP_POINT = 1, // Pickup Point
|
|
215
|
+
SERVICE_POINT = 2 // Service Point
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Error Handling
|
|
220
|
+
|
|
221
|
+
The SDK provides comprehensive error handling with detailed error messages:
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
try {
|
|
225
|
+
const order = await pathao.createOrder(orderData);
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.error('Order creation failed:', error.message);
|
|
228
|
+
|
|
229
|
+
// Check if it's a Pathao API error
|
|
230
|
+
if (error.response?.data) {
|
|
231
|
+
console.error('API Error:', error.response.data);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Authentication
|
|
237
|
+
|
|
238
|
+
The SDK automatically handles OAuth2 authentication and token refresh. You only need to provide your credentials once during initialization:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
const pathao = new PathaoApiService({
|
|
242
|
+
clientId: process.env.PATHAO_CLIENT_ID,
|
|
243
|
+
clientSecret: process.env.PATHAO_CLIENT_SECRET,
|
|
244
|
+
username: process.env.PATHAO_USERNAME,
|
|
245
|
+
password: process.env.PATHAO_PASSWORD
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Environment Variables
|
|
250
|
+
|
|
251
|
+
Create a `.env` file with your Pathao API credentials:
|
|
252
|
+
|
|
253
|
+
```env
|
|
254
|
+
PATHAO_CLIENT_ID=your-client-id
|
|
255
|
+
PATHAO_CLIENT_SECRET=your-client-secret
|
|
256
|
+
PATHAO_USERNAME=your-username
|
|
257
|
+
PATHAO_PASSWORD=your-password
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Examples
|
|
261
|
+
|
|
262
|
+
### Complete Order Flow
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import { PathaoApiService, DeliveryType, ItemType } from '@sifat07/pathao-merchant-sdk';
|
|
266
|
+
|
|
267
|
+
async function createDeliveryOrder() {
|
|
268
|
+
const pathao = new PathaoApiService({
|
|
269
|
+
clientId: process.env.PATHAO_CLIENT_ID!,
|
|
270
|
+
clientSecret: process.env.PATHAO_CLIENT_SECRET!,
|
|
271
|
+
username: process.env.PATHAO_USERNAME!,
|
|
272
|
+
password: process.env.PATHAO_PASSWORD!
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
// 1. Calculate price first
|
|
277
|
+
const price = await pathao.calculatePrice({
|
|
278
|
+
store_id: 123,
|
|
279
|
+
item_type: ItemType.PARCEL,
|
|
280
|
+
item_weight: 1.0,
|
|
281
|
+
delivery_type: DeliveryType.NORMAL,
|
|
282
|
+
recipient_city: 1,
|
|
283
|
+
recipient_zone: 1,
|
|
284
|
+
recipient_area: 1
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
console.log('Estimated cost:', price.data.total_charge);
|
|
288
|
+
|
|
289
|
+
// 2. Create the order
|
|
290
|
+
const order = await pathao.createOrder({
|
|
291
|
+
store_id: 123,
|
|
292
|
+
merchant_order_id: `ORDER-${Date.now()}`,
|
|
293
|
+
recipient_name: 'John Doe',
|
|
294
|
+
recipient_phone: '01712345678',
|
|
295
|
+
recipient_address: '123 Main Street, Dhanmondi, Dhaka',
|
|
296
|
+
delivery_type: DeliveryType.NORMAL,
|
|
297
|
+
item_type: ItemType.PARCEL,
|
|
298
|
+
item_quantity: 1,
|
|
299
|
+
item_weight: 1.0,
|
|
300
|
+
amount_to_collect: 500
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
console.log('Order created successfully:', {
|
|
304
|
+
consignmentId: order.data.consignment_id,
|
|
305
|
+
invoiceId: order.data.invoice_id,
|
|
306
|
+
status: order.data.status
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// 3. Track the order
|
|
310
|
+
const status = await pathao.getOrderStatus(order.data.consignment_id);
|
|
311
|
+
console.log('Current status:', status.data.status);
|
|
312
|
+
|
|
313
|
+
} catch (error) {
|
|
314
|
+
console.error('Delivery order failed:', error.message);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Contributing
|
|
320
|
+
|
|
321
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
322
|
+
|
|
323
|
+
## License
|
|
324
|
+
|
|
325
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
326
|
+
|
|
327
|
+
## Support
|
|
328
|
+
|
|
329
|
+
For support, please open an issue on GitHub or contact me at sifatjasim@gmail.com.
|
|
330
|
+
|
|
331
|
+
## Disclaimer
|
|
332
|
+
|
|
333
|
+
This is an **unofficial** SDK and is not affiliated with or endorsed by Pathao. Use at your own risk. The maintainers are not responsible for any issues that may arise from using this package.
|
|
334
|
+
|
|
335
|
+
## Changelog
|
|
336
|
+
|
|
337
|
+
### 1.0.0
|
|
338
|
+
- Initial release
|
|
339
|
+
- Complete Pathao API integration
|
|
340
|
+
- TypeScript support
|
|
341
|
+
- Automatic authentication
|
|
342
|
+
- Order management
|
|
343
|
+
- Store management
|
|
344
|
+
- Price calculation
|
|
345
|
+
- Location services
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pathao Courier API Types
|
|
3
|
+
*
|
|
4
|
+
* Official API Details:
|
|
5
|
+
* - Authentication: OAuth2 with client_id, client_secret, username, password
|
|
6
|
+
* - Live URL: https://api-hermes.pathao.com
|
|
7
|
+
* - All endpoints use /aladdin/api/v1/ prefix
|
|
8
|
+
*/
|
|
9
|
+
interface PathaoAuthResponse {
|
|
10
|
+
token_type: string;
|
|
11
|
+
expires_in: number;
|
|
12
|
+
access_token: string;
|
|
13
|
+
refresh_token: string;
|
|
14
|
+
}
|
|
15
|
+
interface PathaoOrderRequest {
|
|
16
|
+
store_id: number;
|
|
17
|
+
merchant_order_id?: string;
|
|
18
|
+
recipient_name: string;
|
|
19
|
+
recipient_phone: string;
|
|
20
|
+
recipient_secondary_phone?: string;
|
|
21
|
+
recipient_address: string;
|
|
22
|
+
recipient_city?: number;
|
|
23
|
+
recipient_zone?: number;
|
|
24
|
+
recipient_area?: number;
|
|
25
|
+
delivery_type: number;
|
|
26
|
+
item_type: number;
|
|
27
|
+
special_instruction?: string;
|
|
28
|
+
item_quantity: number;
|
|
29
|
+
item_weight: number;
|
|
30
|
+
item_description?: string;
|
|
31
|
+
amount_to_collect: number;
|
|
32
|
+
}
|
|
33
|
+
interface PathaoStoreRequest {
|
|
34
|
+
name: string;
|
|
35
|
+
contact_name: string;
|
|
36
|
+
contact_number: string;
|
|
37
|
+
address: string;
|
|
38
|
+
city_id: number;
|
|
39
|
+
zone_id: number;
|
|
40
|
+
area_id: number;
|
|
41
|
+
store_type: number;
|
|
42
|
+
}
|
|
43
|
+
interface PathaoOrderResponse {
|
|
44
|
+
type: string;
|
|
45
|
+
code: number;
|
|
46
|
+
message: string;
|
|
47
|
+
data: {
|
|
48
|
+
consignment_id: string;
|
|
49
|
+
invoice_id: string;
|
|
50
|
+
merchant_order_id: string;
|
|
51
|
+
store_id: number;
|
|
52
|
+
recipient_name: string;
|
|
53
|
+
recipient_phone: string;
|
|
54
|
+
recipient_address: string;
|
|
55
|
+
recipient_city: string;
|
|
56
|
+
recipient_zone: string;
|
|
57
|
+
recipient_area: string;
|
|
58
|
+
delivery_type: string;
|
|
59
|
+
item_type: string;
|
|
60
|
+
item_quantity: number;
|
|
61
|
+
item_weight: number;
|
|
62
|
+
item_description: string;
|
|
63
|
+
amount_to_collect: number;
|
|
64
|
+
special_instruction: string;
|
|
65
|
+
status: string;
|
|
66
|
+
created_at: string;
|
|
67
|
+
updated_at: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
interface PathaoStoreResponse {
|
|
71
|
+
type: string;
|
|
72
|
+
code: number;
|
|
73
|
+
message: string;
|
|
74
|
+
data: {
|
|
75
|
+
store_id: number;
|
|
76
|
+
name: string;
|
|
77
|
+
contact_name: string;
|
|
78
|
+
contact_number: string;
|
|
79
|
+
address: string;
|
|
80
|
+
city_id: number;
|
|
81
|
+
zone_id: number;
|
|
82
|
+
area_id: number;
|
|
83
|
+
store_type: number;
|
|
84
|
+
status: string;
|
|
85
|
+
created_at: string;
|
|
86
|
+
updated_at: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
interface PathaoPriceRequest {
|
|
90
|
+
store_id: number;
|
|
91
|
+
item_type: number;
|
|
92
|
+
item_weight: number;
|
|
93
|
+
delivery_type: number;
|
|
94
|
+
recipient_city: number;
|
|
95
|
+
recipient_zone: number;
|
|
96
|
+
recipient_area: number;
|
|
97
|
+
}
|
|
98
|
+
interface PathaoPriceResponse {
|
|
99
|
+
type: string;
|
|
100
|
+
code: number;
|
|
101
|
+
message: string;
|
|
102
|
+
data: {
|
|
103
|
+
store_id: number;
|
|
104
|
+
item_type: string;
|
|
105
|
+
item_weight: number;
|
|
106
|
+
delivery_type: string;
|
|
107
|
+
recipient_city: string;
|
|
108
|
+
recipient_zone: string;
|
|
109
|
+
recipient_area: string;
|
|
110
|
+
delivery_charge: number;
|
|
111
|
+
cod_charge: number;
|
|
112
|
+
total_charge: number;
|
|
113
|
+
currency: string;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
interface PathaoCityResponse {
|
|
117
|
+
type: string;
|
|
118
|
+
code: number;
|
|
119
|
+
message: string;
|
|
120
|
+
data: Array<{
|
|
121
|
+
city_id: number;
|
|
122
|
+
city_name: string;
|
|
123
|
+
zone_list: Array<{
|
|
124
|
+
zone_id: number;
|
|
125
|
+
zone_name: string;
|
|
126
|
+
area_list: Array<{
|
|
127
|
+
area_id: number;
|
|
128
|
+
area_name: string;
|
|
129
|
+
}>;
|
|
130
|
+
}>;
|
|
131
|
+
}>;
|
|
132
|
+
}
|
|
133
|
+
interface PathaoOrderStatusResponse {
|
|
134
|
+
type: string;
|
|
135
|
+
code: number;
|
|
136
|
+
message: string;
|
|
137
|
+
data: {
|
|
138
|
+
consignment_id: string;
|
|
139
|
+
invoice_id: string;
|
|
140
|
+
merchant_order_id: string;
|
|
141
|
+
store_id: number;
|
|
142
|
+
recipient_name: string;
|
|
143
|
+
recipient_phone: string;
|
|
144
|
+
recipient_address: string;
|
|
145
|
+
recipient_city: string;
|
|
146
|
+
recipient_zone: string;
|
|
147
|
+
recipient_area: string;
|
|
148
|
+
delivery_type: string;
|
|
149
|
+
item_type: string;
|
|
150
|
+
item_quantity: number;
|
|
151
|
+
item_weight: number;
|
|
152
|
+
item_description: string;
|
|
153
|
+
amount_to_collect: number;
|
|
154
|
+
special_instruction: string;
|
|
155
|
+
status: string;
|
|
156
|
+
status_updated_at: string;
|
|
157
|
+
created_at: string;
|
|
158
|
+
updated_at: string;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
interface PathaoAreaResponse {
|
|
162
|
+
type: string;
|
|
163
|
+
code: number;
|
|
164
|
+
message: string;
|
|
165
|
+
data: Array<{
|
|
166
|
+
area_id: number;
|
|
167
|
+
area_name: string;
|
|
168
|
+
zone_id: number;
|
|
169
|
+
zone_name: string;
|
|
170
|
+
city_id: number;
|
|
171
|
+
city_name: string;
|
|
172
|
+
}>;
|
|
173
|
+
}
|
|
174
|
+
interface PathaoConfig {
|
|
175
|
+
clientId: string;
|
|
176
|
+
clientSecret: string;
|
|
177
|
+
username: string;
|
|
178
|
+
password: string;
|
|
179
|
+
baseURL?: string;
|
|
180
|
+
timeout?: number;
|
|
181
|
+
}
|
|
182
|
+
interface PathaoError {
|
|
183
|
+
type: string;
|
|
184
|
+
code: number;
|
|
185
|
+
message: string;
|
|
186
|
+
errors?: Record<string, string[]>;
|
|
187
|
+
validation?: Record<string, string[]>;
|
|
188
|
+
}
|
|
189
|
+
declare enum DeliveryType {
|
|
190
|
+
NORMAL = 48,
|
|
191
|
+
ON_DEMAND = 12
|
|
192
|
+
}
|
|
193
|
+
declare enum ItemType {
|
|
194
|
+
DOCUMENT = 1,
|
|
195
|
+
PARCEL = 2
|
|
196
|
+
}
|
|
197
|
+
declare enum StoreType {
|
|
198
|
+
PICKUP_POINT = 1,
|
|
199
|
+
SERVICE_POINT = 2
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Pathao Merchant API Service (Unofficial SDK)
|
|
204
|
+
*
|
|
205
|
+
* This is an unofficial SDK for the Pathao Merchant API.
|
|
206
|
+
*
|
|
207
|
+
* API Details (based on public documentation):
|
|
208
|
+
* - Authentication: OAuth2 with client_id, client_secret, username, password
|
|
209
|
+
* - Live URL: https://api-hermes.pathao.com
|
|
210
|
+
* - All endpoints use /aladdin/api/v1/ prefix
|
|
211
|
+
*
|
|
212
|
+
* Features implemented:
|
|
213
|
+
* - Token-based authentication with refresh token support
|
|
214
|
+
* - Store management (create, list stores)
|
|
215
|
+
* - Order creation (single and bulk)
|
|
216
|
+
* - Order tracking and status
|
|
217
|
+
* - Dynamic price calculation
|
|
218
|
+
* - City, zone, and area management
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
declare class PathaoApiService {
|
|
222
|
+
private pathaoClient;
|
|
223
|
+
private accessToken;
|
|
224
|
+
private refreshToken;
|
|
225
|
+
private tokenExpiry;
|
|
226
|
+
private config;
|
|
227
|
+
constructor(config: PathaoConfig);
|
|
228
|
+
private ensureAuthenticated;
|
|
229
|
+
private authenticate;
|
|
230
|
+
private refreshAccessToken;
|
|
231
|
+
private getErrorMessage;
|
|
232
|
+
createOrder(orderData: PathaoOrderRequest): Promise<PathaoOrderResponse>;
|
|
233
|
+
createStore(storeData: PathaoStoreRequest): Promise<PathaoStoreResponse>;
|
|
234
|
+
getStores(): Promise<PathaoStoreResponse[]>;
|
|
235
|
+
calculatePrice(priceData: PathaoPriceRequest): Promise<PathaoPriceResponse>;
|
|
236
|
+
getCities(): Promise<PathaoCityResponse>;
|
|
237
|
+
getAreas(): Promise<PathaoAreaResponse>;
|
|
238
|
+
getOrderStatus(consignmentId: string): Promise<PathaoOrderStatusResponse>;
|
|
239
|
+
static validatePhoneNumber(phone: string): boolean;
|
|
240
|
+
static formatPhoneNumber(phone: string): string;
|
|
241
|
+
static validateAddress(address: string): boolean;
|
|
242
|
+
static validateWeight(weight: number): boolean;
|
|
243
|
+
static validateRecipientName(name: string): boolean;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export { DeliveryType, ItemType, PathaoApiService, type PathaoAreaResponse, type PathaoAuthResponse, type PathaoCityResponse, type PathaoConfig, type PathaoError, type PathaoOrderRequest, type PathaoOrderResponse, type PathaoOrderStatusResponse, type PathaoPriceRequest, type PathaoPriceResponse, type PathaoStoreRequest, type PathaoStoreResponse, StoreType };
|