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.
@@ -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 };
package/dist/index.js ADDED
@@ -0,0 +1,285 @@
1
+ 'use strict';
2
+
3
+ var axios = require('axios');
4
+
5
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
+
7
+ var axios__default = /*#__PURE__*/_interopDefault(axios);
8
+
9
+ // src/pathao-api.ts
10
+ var PathaoApiService = class {
11
+ constructor(config) {
12
+ this.accessToken = null;
13
+ this.refreshToken = null;
14
+ this.tokenExpiry = null;
15
+ this.config = {
16
+ baseURL: "https://api-hermes.pathao.com",
17
+ timeout: 3e4,
18
+ ...config
19
+ };
20
+ this.pathaoClient = axios__default.default.create({
21
+ baseURL: this.config.baseURL || "https://api-hermes.pathao.com",
22
+ timeout: this.config.timeout || 3e4,
23
+ headers: {
24
+ "Content-Type": "application/json",
25
+ "Accept": "application/json"
26
+ }
27
+ });
28
+ if (!this.config.clientId || !this.config.clientSecret || !this.config.username || !this.config.password) {
29
+ throw new Error("Pathao API credentials are required: clientId, clientSecret, username, password");
30
+ }
31
+ this.pathaoClient.interceptors.request.use(async (config2) => {
32
+ await this.ensureAuthenticated();
33
+ if (this.accessToken) {
34
+ config2.headers.Authorization = `Bearer ${this.accessToken}`;
35
+ }
36
+ return config2;
37
+ });
38
+ }
39
+ async ensureAuthenticated() {
40
+ if (this.accessToken && this.tokenExpiry && Date.now() < this.tokenExpiry) {
41
+ return;
42
+ }
43
+ if (this.refreshToken) {
44
+ try {
45
+ await this.refreshAccessToken();
46
+ return;
47
+ } catch (error) {
48
+ console.warn("Token refresh failed, attempting fresh authentication");
49
+ }
50
+ }
51
+ await this.authenticate();
52
+ }
53
+ async authenticate() {
54
+ try {
55
+ const response = await this.pathaoClient.post("/aladdin/api/v1/issue-token", {
56
+ client_id: this.config.clientId,
57
+ client_secret: this.config.clientSecret,
58
+ username: this.config.username,
59
+ password: this.config.password,
60
+ grant_type: "password"
61
+ });
62
+ this.accessToken = response.data.access_token;
63
+ this.refreshToken = response.data.refresh_token;
64
+ this.tokenExpiry = Date.now() + response.data.expires_in * 1e3 - 6e4;
65
+ console.log("Pathao authentication successful");
66
+ } catch (error) {
67
+ console.error("Pathao authentication failed:", error);
68
+ throw new Error(`Authentication failed: ${this.getErrorMessage(error)}`);
69
+ }
70
+ }
71
+ async refreshAccessToken() {
72
+ if (!this.refreshToken) {
73
+ throw new Error("No refresh token available");
74
+ }
75
+ try {
76
+ const response = await this.pathaoClient.post("/aladdin/api/v1/issue-token", {
77
+ client_id: this.config.clientId,
78
+ client_secret: this.config.clientSecret,
79
+ refresh_token: this.refreshToken,
80
+ grant_type: "refresh_token"
81
+ });
82
+ this.accessToken = response.data.access_token;
83
+ this.refreshToken = response.data.refresh_token;
84
+ this.tokenExpiry = Date.now() + response.data.expires_in * 1e3 - 6e4;
85
+ console.log("Pathao token refresh successful");
86
+ } catch (error) {
87
+ console.error("Pathao token refresh failed:", error);
88
+ throw new Error(`Token refresh failed: ${this.getErrorMessage(error)}`);
89
+ }
90
+ }
91
+ getErrorMessage(error) {
92
+ if (error instanceof axios.AxiosError) {
93
+ const pathaoError = error.response?.data;
94
+ if (pathaoError?.message) {
95
+ return pathaoError.message;
96
+ }
97
+ return error.message;
98
+ }
99
+ return error.message || "Unknown error";
100
+ }
101
+ // Official Pathao API: Create Order
102
+ async createOrder(orderData) {
103
+ try {
104
+ console.log("Creating Pathao order:", {
105
+ store_id: orderData.store_id,
106
+ merchant_order_id: orderData.merchant_order_id,
107
+ recipient_name: orderData.recipient_name,
108
+ recipient_phone: orderData.recipient_phone,
109
+ delivery_type: orderData.delivery_type,
110
+ item_type: orderData.item_type,
111
+ item_weight: orderData.item_weight,
112
+ amount_to_collect: orderData.amount_to_collect
113
+ });
114
+ const response = await this.pathaoClient.post("/aladdin/api/v1/orders", orderData);
115
+ console.log("Pathao order created successfully:", {
116
+ consignment_id: response.data.data?.consignment_id,
117
+ invoice_id: response.data.data?.invoice_id,
118
+ status: response.data.data?.status
119
+ });
120
+ return response.data;
121
+ } catch (error) {
122
+ console.error("Pathao order creation failed:", {
123
+ error: error.message,
124
+ response: error.response?.data,
125
+ status: error.response?.status,
126
+ orderData
127
+ });
128
+ const errorMessage = this.getErrorMessage(error);
129
+ throw new Error(`Failed to create Pathao order: ${errorMessage}`);
130
+ }
131
+ }
132
+ // Official Pathao API: Create Store
133
+ async createStore(storeData) {
134
+ try {
135
+ console.log("Creating Pathao store:", {
136
+ name: storeData.name,
137
+ contact_name: storeData.contact_name,
138
+ city_id: storeData.city_id,
139
+ zone_id: storeData.zone_id,
140
+ area_id: storeData.area_id
141
+ });
142
+ const response = await this.pathaoClient.post("/aladdin/api/v1/stores", storeData);
143
+ console.log("Pathao store created successfully:", {
144
+ store_id: response.data.data?.store_id,
145
+ name: response.data.data?.name,
146
+ status: response.data.data?.status
147
+ });
148
+ return response.data;
149
+ } catch (error) {
150
+ console.error("Pathao store creation failed:", {
151
+ error: error.message,
152
+ response: error.response?.data,
153
+ status: error.response?.status,
154
+ storeData
155
+ });
156
+ const errorMessage = this.getErrorMessage(error);
157
+ throw new Error(`Failed to create Pathao store: ${errorMessage}`);
158
+ }
159
+ }
160
+ // Official Pathao API: Get Store List
161
+ async getStores() {
162
+ try {
163
+ const response = await this.pathaoClient.get("/aladdin/api/v1/stores");
164
+ return response.data.data || [];
165
+ } catch (error) {
166
+ console.error("Failed to fetch Pathao stores:", error);
167
+ const errorMessage = this.getErrorMessage(error);
168
+ throw new Error(`Failed to fetch Pathao stores: ${errorMessage}`);
169
+ }
170
+ }
171
+ // Official Pathao API: Calculate Price
172
+ async calculatePrice(priceData) {
173
+ try {
174
+ console.log("Calculating Pathao price:", {
175
+ store_id: priceData.store_id,
176
+ item_type: priceData.item_type,
177
+ item_weight: priceData.item_weight,
178
+ delivery_type: priceData.delivery_type,
179
+ recipient_city: priceData.recipient_city,
180
+ recipient_zone: priceData.recipient_zone,
181
+ recipient_area: priceData.recipient_area
182
+ });
183
+ const response = await this.pathaoClient.post("/aladdin/api/v1/merchant/price-check", priceData);
184
+ console.log("Pathao price calculated:", {
185
+ delivery_charge: response.data.data?.delivery_charge,
186
+ cod_charge: response.data.data?.cod_charge,
187
+ total_charge: response.data.data?.total_charge
188
+ });
189
+ return response.data;
190
+ } catch (error) {
191
+ console.error("Pathao price calculation failed:", {
192
+ error: error.message,
193
+ response: error.response?.data,
194
+ status: error.response?.status,
195
+ priceData
196
+ });
197
+ const errorMessage = this.getErrorMessage(error);
198
+ throw new Error(`Failed to calculate Pathao price: ${errorMessage}`);
199
+ }
200
+ }
201
+ // Official Pathao API: Get Cities
202
+ async getCities() {
203
+ try {
204
+ const response = await this.pathaoClient.get("/aladdin/api/v1/cities");
205
+ return response.data;
206
+ } catch (error) {
207
+ console.error("Failed to fetch Pathao cities:", error);
208
+ const errorMessage = this.getErrorMessage(error);
209
+ throw new Error(`Failed to fetch Pathao cities: ${errorMessage}`);
210
+ }
211
+ }
212
+ // Official Pathao API: Get Areas
213
+ async getAreas() {
214
+ try {
215
+ const response = await this.pathaoClient.get("/aladdin/api/v1/areas");
216
+ return response.data;
217
+ } catch (error) {
218
+ console.error("Failed to fetch Pathao areas:", error);
219
+ const errorMessage = this.getErrorMessage(error);
220
+ throw new Error(`Failed to fetch Pathao areas: ${errorMessage}`);
221
+ }
222
+ }
223
+ // Official Pathao API: Get Order Status
224
+ async getOrderStatus(consignmentId) {
225
+ try {
226
+ const response = await this.pathaoClient.get(`/aladdin/api/v1/orders/${consignmentId}`);
227
+ return response.data;
228
+ } catch (error) {
229
+ console.error("Failed to fetch Pathao order status:", error);
230
+ const errorMessage = this.getErrorMessage(error);
231
+ throw new Error(`Failed to fetch Pathao order status: ${errorMessage}`);
232
+ }
233
+ }
234
+ // Helper method to validate phone number
235
+ static validatePhoneNumber(phone) {
236
+ const cleanPhone = phone.replace(/\D/g, "");
237
+ return cleanPhone.length === 11 && cleanPhone.startsWith("01");
238
+ }
239
+ // Helper method to format phone number
240
+ static formatPhoneNumber(phone) {
241
+ const cleanPhone = phone.replace(/\D/g, "");
242
+ if (cleanPhone.length === 11 && cleanPhone.startsWith("01")) {
243
+ return cleanPhone;
244
+ }
245
+ throw new Error("Invalid phone number format. Must be 11 digits starting with 01");
246
+ }
247
+ // Helper method to validate address
248
+ static validateAddress(address) {
249
+ const trimmed = address.trim();
250
+ return trimmed.length >= 10 && trimmed.length <= 220;
251
+ }
252
+ // Helper method to validate weight
253
+ static validateWeight(weight) {
254
+ return weight >= 0.5 && weight <= 10;
255
+ }
256
+ // Helper method to validate recipient name
257
+ static validateRecipientName(name) {
258
+ const trimmed = name.trim();
259
+ return trimmed.length >= 3 && trimmed.length <= 100;
260
+ }
261
+ };
262
+
263
+ // src/types.ts
264
+ var DeliveryType = /* @__PURE__ */ ((DeliveryType2) => {
265
+ DeliveryType2[DeliveryType2["NORMAL"] = 48] = "NORMAL";
266
+ DeliveryType2[DeliveryType2["ON_DEMAND"] = 12] = "ON_DEMAND";
267
+ return DeliveryType2;
268
+ })(DeliveryType || {});
269
+ var ItemType = /* @__PURE__ */ ((ItemType2) => {
270
+ ItemType2[ItemType2["DOCUMENT"] = 1] = "DOCUMENT";
271
+ ItemType2[ItemType2["PARCEL"] = 2] = "PARCEL";
272
+ return ItemType2;
273
+ })(ItemType || {});
274
+ var StoreType = /* @__PURE__ */ ((StoreType2) => {
275
+ StoreType2[StoreType2["PICKUP_POINT"] = 1] = "PICKUP_POINT";
276
+ StoreType2[StoreType2["SERVICE_POINT"] = 2] = "SERVICE_POINT";
277
+ return StoreType2;
278
+ })(StoreType || {});
279
+
280
+ exports.DeliveryType = DeliveryType;
281
+ exports.ItemType = ItemType;
282
+ exports.PathaoApiService = PathaoApiService;
283
+ exports.StoreType = StoreType;
284
+ //# sourceMappingURL=index.js.map
285
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/pathao-api.ts","../src/types.ts"],"names":["axios","config","AxiosError","DeliveryType","ItemType","StoreType"],"mappings":";;;;;;;;;AAmCO,IAAM,mBAAN,MAAuB;AAAA,EAO5B,YAAY,MAAA,EAAsB;AALlC,IAAA,IAAA,CAAQ,WAAA,GAA6B,IAAA;AACrC,IAAA,IAAA,CAAQ,YAAA,GAA8B,IAAA;AACtC,IAAA,IAAA,CAAQ,WAAA,GAA6B,IAAA;AAInC,IAAA,IAAA,CAAK,MAAA,GAAS;AAAA,MACZ,OAAA,EAAS,+BAAA;AAAA,MACT,OAAA,EAAS,GAAA;AAAA,MACT,GAAG;AAAA,KACL;AAEA,IAAA,IAAA,CAAK,YAAA,GAAeA,uBAAM,MAAA,CAAO;AAAA,MAC/B,OAAA,EAAS,IAAA,CAAK,MAAA,CAAO,OAAA,IAAW,+BAAA;AAAA,MAChC,OAAA,EAAS,IAAA,CAAK,MAAA,CAAO,OAAA,IAAW,GAAA;AAAA,MAChC,OAAA,EAAS;AAAA,QACP,cAAA,EAAgB,kBAAA;AAAA,QAChB,QAAA,EAAU;AAAA;AACZ,KACD,CAAA;AAGD,IAAA,IAAI,CAAC,IAAA,CAAK,MAAA,CAAO,QAAA,IAAY,CAAC,IAAA,CAAK,MAAA,CAAO,YAAA,IAAgB,CAAC,KAAK,MAAA,CAAO,QAAA,IAAY,CAAC,IAAA,CAAK,OAAO,QAAA,EAAU;AACxG,MAAA,MAAM,IAAI,MAAM,iFAAiF,CAAA;A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","file":"index.js","sourcesContent":["/**\n * Pathao Merchant API Service (Unofficial SDK)\n * \n * This is an unofficial SDK for the Pathao Merchant API.\n * \n * API Details (based on public documentation):\n * - Authentication: OAuth2 with client_id, client_secret, username, password\n * - Live URL: https://api-hermes.pathao.com\n * - All endpoints use /aladdin/api/v1/ prefix\n * \n * Features implemented:\n * - Token-based authentication with refresh token support\n * - Store management (create, list stores)\n * - Order creation (single and bulk)\n * - Order tracking and status\n * - Dynamic price calculation\n * - City, zone, and area management\n */\n\nimport axios, { AxiosInstance, AxiosError } from 'axios';\nimport {\n PathaoConfig,\n PathaoAuthResponse,\n PathaoOrderRequest,\n PathaoOrderResponse,\n PathaoStoreRequest,\n PathaoStoreResponse,\n PathaoPriceRequest,\n PathaoPriceResponse,\n PathaoCityResponse,\n PathaoOrderStatusResponse,\n PathaoAreaResponse,\n PathaoError\n} from './types';\n\nexport class PathaoApiService {\n private pathaoClient: AxiosInstance;\n private accessToken: string | null = null;\n private refreshToken: string | null = null;\n private tokenExpiry: number | null = null;\n private config: PathaoConfig;\n\n constructor(config: PathaoConfig) {\n this.config = {\n baseURL: 'https://api-hermes.pathao.com',\n timeout: 30000,\n ...config\n };\n\n this.pathaoClient = axios.create({\n baseURL: this.config.baseURL || 'https://api-hermes.pathao.com',\n timeout: this.config.timeout || 30000,\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': 'application/json',\n },\n });\n\n // Validate required credentials\n if (!this.config.clientId || !this.config.clientSecret || !this.config.username || !this.config.password) {\n throw new Error('Pathao API credentials are required: clientId, clientSecret, username, password');\n }\n\n // Add request interceptor for authentication\n this.pathaoClient.interceptors.request.use(async (config) => {\n await this.ensureAuthenticated();\n if (this.accessToken) {\n config.headers.Authorization = `Bearer ${this.accessToken}`;\n }\n return config;\n });\n }\n\n private async ensureAuthenticated(): Promise<void> {\n if (this.accessToken && this.tokenExpiry && Date.now() < this.tokenExpiry) {\n return; // Token is still valid\n }\n\n if (this.refreshToken) {\n try {\n await this.refreshAccessToken();\n return;\n } catch (error) {\n console.warn('Token refresh failed, attempting fresh authentication');\n }\n }\n\n await this.authenticate();\n }\n\n private async authenticate(): Promise<void> {\n try {\n const response = await this.pathaoClient.post<PathaoAuthResponse>('/aladdin/api/v1/issue-token', {\n client_id: this.config.clientId,\n client_secret: this.config.clientSecret,\n username: this.config.username,\n password: this.config.password,\n grant_type: 'password'\n });\n\n this.accessToken = response.data.access_token;\n this.refreshToken = response.data.refresh_token;\n this.tokenExpiry = Date.now() + (response.data.expires_in * 1000) - 60000; // 1 minute buffer\n\n console.log('Pathao authentication successful');\n } catch (error) {\n console.error('Pathao authentication failed:', error);\n throw new Error(`Authentication failed: ${this.getErrorMessage(error)}`);\n }\n }\n\n private async refreshAccessToken(): Promise<void> {\n if (!this.refreshToken) {\n throw new Error('No refresh token available');\n }\n\n try {\n const response = await this.pathaoClient.post<PathaoAuthResponse>('/aladdin/api/v1/issue-token', {\n client_id: this.config.clientId,\n client_secret: this.config.clientSecret,\n refresh_token: this.refreshToken,\n grant_type: 'refresh_token'\n });\n\n this.accessToken = response.data.access_token;\n this.refreshToken = response.data.refresh_token;\n this.tokenExpiry = Date.now() + (response.data.expires_in * 1000) - 60000; // 1 minute buffer\n\n console.log('Pathao token refresh successful');\n } catch (error) {\n console.error('Pathao token refresh failed:', error);\n throw new Error(`Token refresh failed: ${this.getErrorMessage(error)}`);\n }\n }\n\n private getErrorMessage(error: any): string {\n if (error instanceof AxiosError) {\n const pathaoError = error.response?.data as PathaoError;\n if (pathaoError?.message) {\n return pathaoError.message;\n }\n return error.message;\n }\n return error.message || 'Unknown error';\n }\n\n // Official Pathao API: Create Order\n async createOrder(orderData: PathaoOrderRequest): Promise<PathaoOrderResponse> {\n try {\n console.log('Creating Pathao order:', {\n store_id: orderData.store_id,\n merchant_order_id: orderData.merchant_order_id,\n recipient_name: orderData.recipient_name,\n recipient_phone: orderData.recipient_phone,\n delivery_type: orderData.delivery_type,\n item_type: orderData.item_type,\n item_weight: orderData.item_weight,\n amount_to_collect: orderData.amount_to_collect\n });\n \n const response = await this.pathaoClient.post<PathaoOrderResponse>('/aladdin/api/v1/orders', orderData);\n \n console.log('Pathao order created successfully:', {\n consignment_id: response.data.data?.consignment_id,\n invoice_id: response.data.data?.invoice_id,\n status: response.data.data?.status\n });\n \n return response.data;\n } catch (error: any) {\n console.error('Pathao order creation failed:', {\n error: error.message,\n response: error.response?.data,\n status: error.response?.status,\n orderData: orderData\n });\n \n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to create Pathao order: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Create Store\n async createStore(storeData: PathaoStoreRequest): Promise<PathaoStoreResponse> {\n try {\n console.log('Creating Pathao store:', {\n name: storeData.name,\n contact_name: storeData.contact_name,\n city_id: storeData.city_id,\n zone_id: storeData.zone_id,\n area_id: storeData.area_id\n });\n \n const response = await this.pathaoClient.post<PathaoStoreResponse>('/aladdin/api/v1/stores', storeData);\n \n console.log('Pathao store created successfully:', {\n store_id: response.data.data?.store_id,\n name: response.data.data?.name,\n status: response.data.data?.status\n });\n \n return response.data;\n } catch (error: any) {\n console.error('Pathao store creation failed:', {\n error: error.message,\n response: error.response?.data,\n status: error.response?.status,\n storeData: storeData\n });\n \n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to create Pathao store: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Get Store List\n async getStores(): Promise<PathaoStoreResponse[]> {\n try {\n const response = await this.pathaoClient.get<{ data: PathaoStoreResponse[] }>('/aladdin/api/v1/stores');\n return response.data.data || [];\n } catch (error: any) {\n console.error('Failed to fetch Pathao stores:', error);\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to fetch Pathao stores: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Calculate Price\n async calculatePrice(priceData: PathaoPriceRequest): Promise<PathaoPriceResponse> {\n try {\n console.log('Calculating Pathao price:', {\n store_id: priceData.store_id,\n item_type: priceData.item_type,\n item_weight: priceData.item_weight,\n delivery_type: priceData.delivery_type,\n recipient_city: priceData.recipient_city,\n recipient_zone: priceData.recipient_zone,\n recipient_area: priceData.recipient_area\n });\n \n const response = await this.pathaoClient.post<PathaoPriceResponse>('/aladdin/api/v1/merchant/price-check', priceData);\n \n console.log('Pathao price calculated:', {\n delivery_charge: response.data.data?.delivery_charge,\n cod_charge: response.data.data?.cod_charge,\n total_charge: response.data.data?.total_charge\n });\n \n return response.data;\n } catch (error: any) {\n console.error('Pathao price calculation failed:', {\n error: error.message,\n response: error.response?.data,\n status: error.response?.status,\n priceData: priceData\n });\n \n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to calculate Pathao price: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Get Cities\n async getCities(): Promise<PathaoCityResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoCityResponse>('/aladdin/api/v1/cities');\n return response.data;\n } catch (error: any) {\n console.error('Failed to fetch Pathao cities:', error);\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to fetch Pathao cities: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Get Areas\n async getAreas(): Promise<PathaoAreaResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoAreaResponse>('/aladdin/api/v1/areas');\n return response.data;\n } catch (error: any) {\n console.error('Failed to fetch Pathao areas:', error);\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to fetch Pathao areas: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Get Order Status\n async getOrderStatus(consignmentId: string): Promise<PathaoOrderStatusResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoOrderStatusResponse>(`/aladdin/api/v1/orders/${consignmentId}`);\n return response.data;\n } catch (error: any) {\n console.error('Failed to fetch Pathao order status:', error);\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to fetch Pathao order status: ${errorMessage}`);\n }\n }\n\n // Helper method to validate phone number\n static validatePhoneNumber(phone: string): boolean {\n const cleanPhone = phone.replace(/\\D/g, '');\n return cleanPhone.length === 11 && cleanPhone.startsWith('01');\n }\n\n // Helper method to format phone number\n static formatPhoneNumber(phone: string): string {\n const cleanPhone = phone.replace(/\\D/g, '');\n if (cleanPhone.length === 11 && cleanPhone.startsWith('01')) {\n return cleanPhone;\n }\n throw new Error('Invalid phone number format. Must be 11 digits starting with 01');\n }\n\n // Helper method to validate address\n static validateAddress(address: string): boolean {\n const trimmed = address.trim();\n return trimmed.length >= 10 && trimmed.length <= 220;\n }\n\n // Helper method to validate weight\n static validateWeight(weight: number): boolean {\n return weight >= 0.5 && weight <= 10;\n }\n\n // Helper method to validate recipient name\n static validateRecipientName(name: string): boolean {\n const trimmed = name.trim();\n return trimmed.length >= 3 && trimmed.length <= 100;\n }\n}\n","/**\n * Pathao Courier API Types\n * \n * Official API Details:\n * - Authentication: OAuth2 with client_id, client_secret, username, password\n * - Live URL: https://api-hermes.pathao.com\n * - All endpoints use /aladdin/api/v1/ prefix\n */\n\n// Official Pathao API Authentication Response\nexport interface PathaoAuthResponse {\n token_type: string;\n expires_in: number;\n access_token: string;\n refresh_token: string;\n}\n\n// Official Pathao Order Creation Request\nexport interface PathaoOrderRequest {\n store_id: number;\n merchant_order_id?: string; // Optional - Your order tracking ID\n recipient_name: string; // Required - 3-100 characters\n recipient_phone: string; // Required - 11 characters\n recipient_secondary_phone?: string; // Optional - 11 characters\n recipient_address: string; // Required - 10-220 characters\n recipient_city?: number; // Optional - Auto-detected if not provided\n recipient_zone?: number; // Optional - Auto-detected if not provided\n recipient_area?: number; // Optional - Auto-detected if not provided\n delivery_type: number; // Required - 48 (Normal), 12 (On Demand)\n item_type: number; // Required - 1 (Document), 2 (Parcel)\n special_instruction?: string; // Optional\n item_quantity: number; // Required\n item_weight: number; // Required - 0.5-10 kg\n item_description?: string; // Optional\n amount_to_collect: number; // Required - COD amount (0 for non-COD)\n}\n\n// Official Pathao Store Creation Request\nexport interface PathaoStoreRequest {\n name: string;\n contact_name: string;\n contact_number: string;\n address: string;\n city_id: number;\n zone_id: number;\n area_id: number;\n store_type: number; // 1 (Pickup Point), 2 (Service Point)\n}\n\n// Official Pathao Order Response\nexport interface PathaoOrderResponse {\n type: string;\n code: number;\n message: string;\n data: {\n consignment_id: string;\n invoice_id: string;\n merchant_order_id: string;\n store_id: number;\n recipient_name: string;\n recipient_phone: string;\n recipient_address: string;\n recipient_city: string;\n recipient_zone: string;\n recipient_area: string;\n delivery_type: string;\n item_type: string;\n item_quantity: number;\n item_weight: number;\n item_description: string;\n amount_to_collect: number;\n special_instruction: string;\n status: string;\n created_at: string;\n updated_at: string;\n };\n}\n\n// Official Pathao Store Response\nexport interface PathaoStoreResponse {\n type: string;\n code: number;\n message: string;\n data: {\n store_id: number;\n name: string;\n contact_name: string;\n contact_number: string;\n address: string;\n city_id: number;\n zone_id: number;\n area_id: number;\n store_type: number;\n status: string;\n created_at: string;\n updated_at: string;\n };\n}\n\n// Official Pathao Price Calculation Request\nexport interface PathaoPriceRequest {\n store_id: number;\n item_type: number;\n item_weight: number;\n delivery_type: number;\n recipient_city: number;\n recipient_zone: number;\n recipient_area: number;\n}\n\n// Official Pathao Price Response\nexport interface PathaoPriceResponse {\n type: string;\n code: number;\n message: string;\n data: {\n store_id: number;\n item_type: string;\n item_weight: number;\n delivery_type: string;\n recipient_city: string;\n recipient_zone: string;\n recipient_area: string;\n delivery_charge: number;\n cod_charge: number;\n total_charge: number;\n currency: string;\n };\n}\n\n// Official Pathao City Response\nexport interface PathaoCityResponse {\n type: string;\n code: number;\n message: string;\n data: Array<{\n city_id: number;\n city_name: string;\n zone_list: Array<{\n zone_id: number;\n zone_name: string;\n area_list: Array<{\n area_id: number;\n area_name: string;\n }>;\n }>;\n }>;\n}\n\n// Official Pathao Order Status Response\nexport interface PathaoOrderStatusResponse {\n type: string;\n code: number;\n message: string;\n data: {\n consignment_id: string;\n invoice_id: string;\n merchant_order_id: string;\n store_id: number;\n recipient_name: string;\n recipient_phone: string;\n recipient_address: string;\n recipient_city: string;\n recipient_zone: string;\n recipient_area: string;\n delivery_type: string;\n item_type: string;\n item_quantity: number;\n item_weight: number;\n item_description: string;\n amount_to_collect: number;\n special_instruction: string;\n status: string;\n status_updated_at: string;\n created_at: string;\n updated_at: string;\n };\n}\n\n// Official Pathao Area Response\nexport interface PathaoAreaResponse {\n type: string;\n code: number;\n message: string;\n data: Array<{\n area_id: number;\n area_name: string;\n zone_id: number;\n zone_name: string;\n city_id: number;\n city_name: string;\n }>;\n}\n\n// Configuration options for PathaoApiService\nexport interface PathaoConfig {\n clientId: string;\n clientSecret: string;\n username: string;\n password: string;\n baseURL?: string;\n timeout?: number;\n}\n\n// Error response from Pathao API\nexport interface PathaoError {\n type: string;\n code: number;\n message: string;\n errors?: Record<string, string[]>;\n validation?: Record<string, string[]>;\n}\n\n// Delivery types enum\nexport enum DeliveryType {\n NORMAL = 48,\n ON_DEMAND = 12\n}\n\n// Item types enum\nexport enum ItemType {\n DOCUMENT = 1,\n PARCEL = 2\n}\n\n// Store types enum\nexport enum StoreType {\n PICKUP_POINT = 1,\n SERVICE_POINT = 2\n}\n"]}