pathao-merchant-sdk 1.0.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 +54 -8
- package/dist/index.d.mts +84 -86
- package/dist/index.d.ts +84 -86
- package/dist/index.js +159 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +160 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
# Pathao Merchant API SDK
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/pathao-merchant-sdk)
|
|
4
4
|
[](https://www.typescriptlang.org/)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
7
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
8
|
|
|
9
|
+
[](https://www.npmjs.com/package/pathao-merchant-sdk)
|
|
10
|
+
[](https://www.npmjs.com/package/pathao-merchant-sdk)
|
|
11
|
+
|
|
9
12
|
> **Disclaimer**: This is not an official package from Pathao. It's a community-maintained SDK based on the public Pathao Merchant API documentation.
|
|
10
13
|
|
|
11
14
|
## Features
|
|
@@ -23,20 +26,21 @@ An **unofficial** TypeScript SDK for integrating with the Pathao Merchant API. T
|
|
|
23
26
|
## Installation
|
|
24
27
|
|
|
25
28
|
```bash
|
|
26
|
-
npm install
|
|
29
|
+
npm install pathao-merchant-sdk
|
|
27
30
|
# or
|
|
28
|
-
yarn add
|
|
31
|
+
yarn add pathao-merchant-sdk
|
|
29
32
|
# or
|
|
30
|
-
pnpm add
|
|
33
|
+
pnpm add pathao-merchant-sdk
|
|
31
34
|
```
|
|
32
35
|
|
|
33
36
|
## Quick Start
|
|
34
37
|
|
|
35
38
|
```typescript
|
|
36
|
-
import { PathaoApiService, DeliveryType, ItemType } from '
|
|
39
|
+
import { PathaoApiService, DeliveryType, ItemType } from 'pathao-merchant-sdk';
|
|
37
40
|
|
|
38
41
|
// Initialize the SDK
|
|
39
42
|
const pathao = new PathaoApiService({
|
|
43
|
+
baseURL: 'https://api-hermes.pathao.com', // or use PATHAO_BASE_URL env var
|
|
40
44
|
clientId: 'your-client-id',
|
|
41
45
|
clientSecret: 'your-client-secret',
|
|
42
46
|
username: 'your-username',
|
|
@@ -69,11 +73,53 @@ interface PathaoConfig {
|
|
|
69
73
|
clientSecret: string; // Your Pathao API client secret
|
|
70
74
|
username: string; // Your Pathao API username
|
|
71
75
|
password: string; // Your Pathao API password
|
|
72
|
-
baseURL
|
|
76
|
+
baseURL: string; // API base URL (required)
|
|
73
77
|
timeout?: number; // Request timeout in ms (default: 30000)
|
|
74
78
|
}
|
|
75
79
|
```
|
|
76
80
|
|
|
81
|
+
#### Environment Variables
|
|
82
|
+
|
|
83
|
+
You can use environment variables to configure the SDK, which is especially useful for different environments (sandbox vs production):
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Base URL (required)
|
|
87
|
+
PATHAO_BASE_URL=https://courier-api-sandbox.pathao.com # For sandbox
|
|
88
|
+
# PATHAO_BASE_URL=https://api-hermes.pathao.com # For live
|
|
89
|
+
|
|
90
|
+
# Authentication credentials (all required)
|
|
91
|
+
PATHAO_CLIENT_ID=your-client-id
|
|
92
|
+
PATHAO_CLIENT_SECRET=your-client-secret
|
|
93
|
+
PATHAO_USERNAME=your-username
|
|
94
|
+
PATHAO_PASSWORD=your-password
|
|
95
|
+
|
|
96
|
+
# Optional
|
|
97
|
+
PATHAO_TIMEOUT=30000 # Request timeout in milliseconds
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The SDK will automatically use these environment variables if they are set, falling back to the provided config values or defaults.
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// Option 1: All from environment variables
|
|
104
|
+
const pathao = new PathaoApiService({});
|
|
105
|
+
|
|
106
|
+
// Option 2: Mix of config and environment variables
|
|
107
|
+
const pathao = new PathaoApiService({
|
|
108
|
+
baseURL: 'https://api-hermes.pathao.com', // This overrides PATHAO_BASE_URL
|
|
109
|
+
clientId: 'your-client-id', // This overrides PATHAO_CLIENT_ID
|
|
110
|
+
// Other credentials will be taken from environment variables
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Option 3: All from config (environment variables as fallback)
|
|
114
|
+
const pathao = new PathaoApiService({
|
|
115
|
+
baseURL: process.env.PATHAO_BASE_URL || 'https://api-hermes.pathao.com',
|
|
116
|
+
clientId: process.env.PATHAO_CLIENT_ID || 'your-client-id',
|
|
117
|
+
clientSecret: process.env.PATHAO_CLIENT_SECRET || 'your-client-secret',
|
|
118
|
+
username: process.env.PATHAO_USERNAME || 'your-username',
|
|
119
|
+
password: process.env.PATHAO_PASSWORD || 'your-password',
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
77
123
|
### Order Management
|
|
78
124
|
|
|
79
125
|
#### Create Order
|
|
@@ -169,7 +215,7 @@ console.log('Available areas:', areas.data);
|
|
|
169
215
|
The SDK includes built-in validation helpers:
|
|
170
216
|
|
|
171
217
|
```typescript
|
|
172
|
-
import { PathaoApiService } from '
|
|
218
|
+
import { PathaoApiService } from 'pathao-merchant-sdk';
|
|
173
219
|
|
|
174
220
|
// Validate phone number
|
|
175
221
|
const isValidPhone = PathaoApiService.validatePhoneNumber('01712345678'); // true
|
|
@@ -262,7 +308,7 @@ PATHAO_PASSWORD=your-password
|
|
|
262
308
|
### Complete Order Flow
|
|
263
309
|
|
|
264
310
|
```typescript
|
|
265
|
-
import { PathaoApiService, DeliveryType, ItemType } from '
|
|
311
|
+
import { PathaoApiService, DeliveryType, ItemType } from 'pathao-merchant-sdk';
|
|
266
312
|
|
|
267
313
|
async function createDeliveryOrder() {
|
|
268
314
|
const pathao = new PathaoApiService({
|
package/dist/index.d.mts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Official API Details:
|
|
5
5
|
* - Authentication: OAuth2 with client_id, client_secret, username, password
|
|
6
|
-
* - Live URL: https://api-hermes.pathao.com
|
|
7
6
|
* - All endpoints use /aladdin/api/v1/ prefix
|
|
7
|
+
* - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config
|
|
8
|
+
* - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config
|
|
8
9
|
*/
|
|
9
10
|
interface PathaoAuthResponse {
|
|
10
11
|
token_type: string;
|
|
@@ -34,11 +35,12 @@ interface PathaoStoreRequest {
|
|
|
34
35
|
name: string;
|
|
35
36
|
contact_name: string;
|
|
36
37
|
contact_number: string;
|
|
38
|
+
secondary_contact?: string;
|
|
39
|
+
otp_number?: string;
|
|
37
40
|
address: string;
|
|
38
41
|
city_id: number;
|
|
39
42
|
zone_id: number;
|
|
40
43
|
area_id: number;
|
|
41
|
-
store_type: number;
|
|
42
44
|
}
|
|
43
45
|
interface PathaoOrderResponse {
|
|
44
46
|
type: string;
|
|
@@ -46,25 +48,9 @@ interface PathaoOrderResponse {
|
|
|
46
48
|
message: string;
|
|
47
49
|
data: {
|
|
48
50
|
consignment_id: string;
|
|
49
|
-
invoice_id: string;
|
|
50
51
|
merchant_order_id: string;
|
|
51
|
-
|
|
52
|
-
|
|
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;
|
|
52
|
+
order_status: string;
|
|
53
|
+
delivery_fee: number;
|
|
68
54
|
};
|
|
69
55
|
}
|
|
70
56
|
interface PathaoStoreResponse {
|
|
@@ -73,17 +59,14 @@ interface PathaoStoreResponse {
|
|
|
73
59
|
message: string;
|
|
74
60
|
data: {
|
|
75
61
|
store_id: number;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
address: string;
|
|
62
|
+
store_name: string;
|
|
63
|
+
store_address: string;
|
|
64
|
+
is_active: number;
|
|
80
65
|
city_id: number;
|
|
81
66
|
zone_id: number;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
created_at: string;
|
|
86
|
-
updated_at: string;
|
|
67
|
+
hub_id: number;
|
|
68
|
+
is_default_store: boolean;
|
|
69
|
+
is_default_return_store: boolean;
|
|
87
70
|
};
|
|
88
71
|
}
|
|
89
72
|
interface PathaoPriceRequest {
|
|
@@ -100,35 +83,26 @@ interface PathaoPriceResponse {
|
|
|
100
83
|
code: number;
|
|
101
84
|
message: string;
|
|
102
85
|
data: {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
cod_charge: number;
|
|
112
|
-
total_charge: number;
|
|
113
|
-
currency: string;
|
|
86
|
+
price: number;
|
|
87
|
+
discount: number;
|
|
88
|
+
promo_discount: number;
|
|
89
|
+
plan_id: number;
|
|
90
|
+
cod_enabled: number;
|
|
91
|
+
cod_percentage: number;
|
|
92
|
+
additional_charge: number;
|
|
93
|
+
final_price: number;
|
|
114
94
|
};
|
|
115
95
|
}
|
|
116
96
|
interface PathaoCityResponse {
|
|
117
97
|
type: string;
|
|
118
98
|
code: number;
|
|
119
99
|
message: string;
|
|
120
|
-
data:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
zone_id: number;
|
|
125
|
-
zone_name: string;
|
|
126
|
-
area_list: Array<{
|
|
127
|
-
area_id: number;
|
|
128
|
-
area_name: string;
|
|
129
|
-
}>;
|
|
100
|
+
data: {
|
|
101
|
+
data: Array<{
|
|
102
|
+
city_id: number;
|
|
103
|
+
city_name: string;
|
|
130
104
|
}>;
|
|
131
|
-
}
|
|
105
|
+
};
|
|
132
106
|
}
|
|
133
107
|
interface PathaoOrderStatusResponse {
|
|
134
108
|
type: string;
|
|
@@ -136,47 +110,43 @@ interface PathaoOrderStatusResponse {
|
|
|
136
110
|
message: string;
|
|
137
111
|
data: {
|
|
138
112
|
consignment_id: string;
|
|
139
|
-
invoice_id: string;
|
|
140
113
|
merchant_order_id: string;
|
|
141
|
-
|
|
142
|
-
|
|
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;
|
|
114
|
+
order_status: string;
|
|
115
|
+
order_status_slug: string;
|
|
158
116
|
updated_at: string;
|
|
117
|
+
invoice_id: string | null;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
interface PathaoZoneResponse {
|
|
121
|
+
type: string;
|
|
122
|
+
code: number;
|
|
123
|
+
message: string;
|
|
124
|
+
data: {
|
|
125
|
+
data: Array<{
|
|
126
|
+
zone_id: number;
|
|
127
|
+
zone_name: string;
|
|
128
|
+
}>;
|
|
159
129
|
};
|
|
160
130
|
}
|
|
161
131
|
interface PathaoAreaResponse {
|
|
162
132
|
type: string;
|
|
163
133
|
code: number;
|
|
164
134
|
message: string;
|
|
165
|
-
data:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
135
|
+
data: {
|
|
136
|
+
data: Array<{
|
|
137
|
+
area_id: number;
|
|
138
|
+
area_name: string;
|
|
139
|
+
home_delivery_available: boolean;
|
|
140
|
+
pickup_available: boolean;
|
|
141
|
+
}>;
|
|
142
|
+
};
|
|
173
143
|
}
|
|
174
144
|
interface PathaoConfig {
|
|
175
145
|
clientId: string;
|
|
176
146
|
clientSecret: string;
|
|
177
147
|
username: string;
|
|
178
148
|
password: string;
|
|
179
|
-
baseURL
|
|
149
|
+
baseURL: string;
|
|
180
150
|
timeout?: number;
|
|
181
151
|
}
|
|
182
152
|
interface PathaoError {
|
|
@@ -194,10 +164,6 @@ declare enum ItemType {
|
|
|
194
164
|
DOCUMENT = 1,
|
|
195
165
|
PARCEL = 2
|
|
196
166
|
}
|
|
197
|
-
declare enum StoreType {
|
|
198
|
-
PICKUP_POINT = 1,
|
|
199
|
-
SERVICE_POINT = 2
|
|
200
|
-
}
|
|
201
167
|
|
|
202
168
|
/**
|
|
203
169
|
* Pathao Merchant API Service (Unofficial SDK)
|
|
@@ -206,8 +172,9 @@ declare enum StoreType {
|
|
|
206
172
|
*
|
|
207
173
|
* API Details (based on public documentation):
|
|
208
174
|
* - Authentication: OAuth2 with client_id, client_secret, username, password
|
|
209
|
-
* - Live URL: https://api-hermes.pathao.com
|
|
210
175
|
* - All endpoints use /aladdin/api/v1/ prefix
|
|
176
|
+
* - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config
|
|
177
|
+
* - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config
|
|
211
178
|
*
|
|
212
179
|
* Features implemented:
|
|
213
180
|
* - Token-based authentication with refresh token support
|
|
@@ -224,23 +191,54 @@ declare class PathaoApiService {
|
|
|
224
191
|
private refreshToken;
|
|
225
192
|
private tokenExpiry;
|
|
226
193
|
private config;
|
|
194
|
+
private isAuthenticating;
|
|
195
|
+
private authPromise;
|
|
196
|
+
private requestQueue;
|
|
197
|
+
private circuitBreaker;
|
|
227
198
|
constructor(config: PathaoConfig);
|
|
228
199
|
private ensureAuthenticated;
|
|
200
|
+
private performAuthentication;
|
|
201
|
+
private processRequestQueue;
|
|
229
202
|
private authenticate;
|
|
230
203
|
private refreshAccessToken;
|
|
231
204
|
private getErrorMessage;
|
|
205
|
+
private handleCircuitBreaker;
|
|
232
206
|
createOrder(orderData: PathaoOrderRequest): Promise<PathaoOrderResponse>;
|
|
233
207
|
createStore(storeData: PathaoStoreRequest): Promise<PathaoStoreResponse>;
|
|
234
|
-
getStores(): Promise<
|
|
208
|
+
getStores(): Promise<{
|
|
209
|
+
data: PathaoStoreResponse[];
|
|
210
|
+
total: number;
|
|
211
|
+
current_page: number;
|
|
212
|
+
per_page: number;
|
|
213
|
+
total_in_page: number;
|
|
214
|
+
last_page: number;
|
|
215
|
+
path: string;
|
|
216
|
+
to: number;
|
|
217
|
+
from: number;
|
|
218
|
+
last_page_url: string;
|
|
219
|
+
first_page_url: string;
|
|
220
|
+
}>;
|
|
235
221
|
calculatePrice(priceData: PathaoPriceRequest): Promise<PathaoPriceResponse>;
|
|
236
222
|
getCities(): Promise<PathaoCityResponse>;
|
|
237
|
-
|
|
223
|
+
getZones(cityId: number): Promise<PathaoZoneResponse>;
|
|
224
|
+
getAreas(zoneId: number): Promise<PathaoAreaResponse>;
|
|
238
225
|
getOrderStatus(consignmentId: string): Promise<PathaoOrderStatusResponse>;
|
|
226
|
+
createBulkOrder(orders: PathaoOrderRequest[]): Promise<{
|
|
227
|
+
message: string;
|
|
228
|
+
type: string;
|
|
229
|
+
code: number;
|
|
230
|
+
data: boolean;
|
|
231
|
+
}>;
|
|
239
232
|
static validatePhoneNumber(phone: string): boolean;
|
|
240
233
|
static formatPhoneNumber(phone: string): string;
|
|
241
234
|
static validateAddress(address: string): boolean;
|
|
242
235
|
static validateWeight(weight: number): boolean;
|
|
243
236
|
static validateRecipientName(name: string): boolean;
|
|
237
|
+
static validateStoreName(name: string): boolean;
|
|
238
|
+
static validateContactName(name: string): boolean;
|
|
239
|
+
static validateContactNumber(phone: string): boolean;
|
|
240
|
+
static validateStoreAddress(address: string): boolean;
|
|
241
|
+
clearAuth(): void;
|
|
244
242
|
}
|
|
245
243
|
|
|
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,
|
|
244
|
+
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, type PathaoZoneResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Official API Details:
|
|
5
5
|
* - Authentication: OAuth2 with client_id, client_secret, username, password
|
|
6
|
-
* - Live URL: https://api-hermes.pathao.com
|
|
7
6
|
* - All endpoints use /aladdin/api/v1/ prefix
|
|
7
|
+
* - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config
|
|
8
|
+
* - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config
|
|
8
9
|
*/
|
|
9
10
|
interface PathaoAuthResponse {
|
|
10
11
|
token_type: string;
|
|
@@ -34,11 +35,12 @@ interface PathaoStoreRequest {
|
|
|
34
35
|
name: string;
|
|
35
36
|
contact_name: string;
|
|
36
37
|
contact_number: string;
|
|
38
|
+
secondary_contact?: string;
|
|
39
|
+
otp_number?: string;
|
|
37
40
|
address: string;
|
|
38
41
|
city_id: number;
|
|
39
42
|
zone_id: number;
|
|
40
43
|
area_id: number;
|
|
41
|
-
store_type: number;
|
|
42
44
|
}
|
|
43
45
|
interface PathaoOrderResponse {
|
|
44
46
|
type: string;
|
|
@@ -46,25 +48,9 @@ interface PathaoOrderResponse {
|
|
|
46
48
|
message: string;
|
|
47
49
|
data: {
|
|
48
50
|
consignment_id: string;
|
|
49
|
-
invoice_id: string;
|
|
50
51
|
merchant_order_id: string;
|
|
51
|
-
|
|
52
|
-
|
|
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;
|
|
52
|
+
order_status: string;
|
|
53
|
+
delivery_fee: number;
|
|
68
54
|
};
|
|
69
55
|
}
|
|
70
56
|
interface PathaoStoreResponse {
|
|
@@ -73,17 +59,14 @@ interface PathaoStoreResponse {
|
|
|
73
59
|
message: string;
|
|
74
60
|
data: {
|
|
75
61
|
store_id: number;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
address: string;
|
|
62
|
+
store_name: string;
|
|
63
|
+
store_address: string;
|
|
64
|
+
is_active: number;
|
|
80
65
|
city_id: number;
|
|
81
66
|
zone_id: number;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
created_at: string;
|
|
86
|
-
updated_at: string;
|
|
67
|
+
hub_id: number;
|
|
68
|
+
is_default_store: boolean;
|
|
69
|
+
is_default_return_store: boolean;
|
|
87
70
|
};
|
|
88
71
|
}
|
|
89
72
|
interface PathaoPriceRequest {
|
|
@@ -100,35 +83,26 @@ interface PathaoPriceResponse {
|
|
|
100
83
|
code: number;
|
|
101
84
|
message: string;
|
|
102
85
|
data: {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
cod_charge: number;
|
|
112
|
-
total_charge: number;
|
|
113
|
-
currency: string;
|
|
86
|
+
price: number;
|
|
87
|
+
discount: number;
|
|
88
|
+
promo_discount: number;
|
|
89
|
+
plan_id: number;
|
|
90
|
+
cod_enabled: number;
|
|
91
|
+
cod_percentage: number;
|
|
92
|
+
additional_charge: number;
|
|
93
|
+
final_price: number;
|
|
114
94
|
};
|
|
115
95
|
}
|
|
116
96
|
interface PathaoCityResponse {
|
|
117
97
|
type: string;
|
|
118
98
|
code: number;
|
|
119
99
|
message: string;
|
|
120
|
-
data:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
zone_id: number;
|
|
125
|
-
zone_name: string;
|
|
126
|
-
area_list: Array<{
|
|
127
|
-
area_id: number;
|
|
128
|
-
area_name: string;
|
|
129
|
-
}>;
|
|
100
|
+
data: {
|
|
101
|
+
data: Array<{
|
|
102
|
+
city_id: number;
|
|
103
|
+
city_name: string;
|
|
130
104
|
}>;
|
|
131
|
-
}
|
|
105
|
+
};
|
|
132
106
|
}
|
|
133
107
|
interface PathaoOrderStatusResponse {
|
|
134
108
|
type: string;
|
|
@@ -136,47 +110,43 @@ interface PathaoOrderStatusResponse {
|
|
|
136
110
|
message: string;
|
|
137
111
|
data: {
|
|
138
112
|
consignment_id: string;
|
|
139
|
-
invoice_id: string;
|
|
140
113
|
merchant_order_id: string;
|
|
141
|
-
|
|
142
|
-
|
|
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;
|
|
114
|
+
order_status: string;
|
|
115
|
+
order_status_slug: string;
|
|
158
116
|
updated_at: string;
|
|
117
|
+
invoice_id: string | null;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
interface PathaoZoneResponse {
|
|
121
|
+
type: string;
|
|
122
|
+
code: number;
|
|
123
|
+
message: string;
|
|
124
|
+
data: {
|
|
125
|
+
data: Array<{
|
|
126
|
+
zone_id: number;
|
|
127
|
+
zone_name: string;
|
|
128
|
+
}>;
|
|
159
129
|
};
|
|
160
130
|
}
|
|
161
131
|
interface PathaoAreaResponse {
|
|
162
132
|
type: string;
|
|
163
133
|
code: number;
|
|
164
134
|
message: string;
|
|
165
|
-
data:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
135
|
+
data: {
|
|
136
|
+
data: Array<{
|
|
137
|
+
area_id: number;
|
|
138
|
+
area_name: string;
|
|
139
|
+
home_delivery_available: boolean;
|
|
140
|
+
pickup_available: boolean;
|
|
141
|
+
}>;
|
|
142
|
+
};
|
|
173
143
|
}
|
|
174
144
|
interface PathaoConfig {
|
|
175
145
|
clientId: string;
|
|
176
146
|
clientSecret: string;
|
|
177
147
|
username: string;
|
|
178
148
|
password: string;
|
|
179
|
-
baseURL
|
|
149
|
+
baseURL: string;
|
|
180
150
|
timeout?: number;
|
|
181
151
|
}
|
|
182
152
|
interface PathaoError {
|
|
@@ -194,10 +164,6 @@ declare enum ItemType {
|
|
|
194
164
|
DOCUMENT = 1,
|
|
195
165
|
PARCEL = 2
|
|
196
166
|
}
|
|
197
|
-
declare enum StoreType {
|
|
198
|
-
PICKUP_POINT = 1,
|
|
199
|
-
SERVICE_POINT = 2
|
|
200
|
-
}
|
|
201
167
|
|
|
202
168
|
/**
|
|
203
169
|
* Pathao Merchant API Service (Unofficial SDK)
|
|
@@ -206,8 +172,9 @@ declare enum StoreType {
|
|
|
206
172
|
*
|
|
207
173
|
* API Details (based on public documentation):
|
|
208
174
|
* - Authentication: OAuth2 with client_id, client_secret, username, password
|
|
209
|
-
* - Live URL: https://api-hermes.pathao.com
|
|
210
175
|
* - All endpoints use /aladdin/api/v1/ prefix
|
|
176
|
+
* - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config
|
|
177
|
+
* - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config
|
|
211
178
|
*
|
|
212
179
|
* Features implemented:
|
|
213
180
|
* - Token-based authentication with refresh token support
|
|
@@ -224,23 +191,54 @@ declare class PathaoApiService {
|
|
|
224
191
|
private refreshToken;
|
|
225
192
|
private tokenExpiry;
|
|
226
193
|
private config;
|
|
194
|
+
private isAuthenticating;
|
|
195
|
+
private authPromise;
|
|
196
|
+
private requestQueue;
|
|
197
|
+
private circuitBreaker;
|
|
227
198
|
constructor(config: PathaoConfig);
|
|
228
199
|
private ensureAuthenticated;
|
|
200
|
+
private performAuthentication;
|
|
201
|
+
private processRequestQueue;
|
|
229
202
|
private authenticate;
|
|
230
203
|
private refreshAccessToken;
|
|
231
204
|
private getErrorMessage;
|
|
205
|
+
private handleCircuitBreaker;
|
|
232
206
|
createOrder(orderData: PathaoOrderRequest): Promise<PathaoOrderResponse>;
|
|
233
207
|
createStore(storeData: PathaoStoreRequest): Promise<PathaoStoreResponse>;
|
|
234
|
-
getStores(): Promise<
|
|
208
|
+
getStores(): Promise<{
|
|
209
|
+
data: PathaoStoreResponse[];
|
|
210
|
+
total: number;
|
|
211
|
+
current_page: number;
|
|
212
|
+
per_page: number;
|
|
213
|
+
total_in_page: number;
|
|
214
|
+
last_page: number;
|
|
215
|
+
path: string;
|
|
216
|
+
to: number;
|
|
217
|
+
from: number;
|
|
218
|
+
last_page_url: string;
|
|
219
|
+
first_page_url: string;
|
|
220
|
+
}>;
|
|
235
221
|
calculatePrice(priceData: PathaoPriceRequest): Promise<PathaoPriceResponse>;
|
|
236
222
|
getCities(): Promise<PathaoCityResponse>;
|
|
237
|
-
|
|
223
|
+
getZones(cityId: number): Promise<PathaoZoneResponse>;
|
|
224
|
+
getAreas(zoneId: number): Promise<PathaoAreaResponse>;
|
|
238
225
|
getOrderStatus(consignmentId: string): Promise<PathaoOrderStatusResponse>;
|
|
226
|
+
createBulkOrder(orders: PathaoOrderRequest[]): Promise<{
|
|
227
|
+
message: string;
|
|
228
|
+
type: string;
|
|
229
|
+
code: number;
|
|
230
|
+
data: boolean;
|
|
231
|
+
}>;
|
|
239
232
|
static validatePhoneNumber(phone: string): boolean;
|
|
240
233
|
static formatPhoneNumber(phone: string): string;
|
|
241
234
|
static validateAddress(address: string): boolean;
|
|
242
235
|
static validateWeight(weight: number): boolean;
|
|
243
236
|
static validateRecipientName(name: string): boolean;
|
|
237
|
+
static validateStoreName(name: string): boolean;
|
|
238
|
+
static validateContactName(name: string): boolean;
|
|
239
|
+
static validateContactNumber(phone: string): boolean;
|
|
240
|
+
static validateStoreAddress(address: string): boolean;
|
|
241
|
+
clearAuth(): void;
|
|
244
242
|
}
|
|
245
243
|
|
|
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,
|
|
244
|
+
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, type PathaoZoneResponse };
|