pathao-merchant-sdk 1.0.0 → 1.1.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 +10 -7
- package/dist/index.js.map +1 -1
- 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,17 +26,17 @@ 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({
|
|
@@ -169,7 +172,7 @@ console.log('Available areas:', areas.data);
|
|
|
169
172
|
The SDK includes built-in validation helpers:
|
|
170
173
|
|
|
171
174
|
```typescript
|
|
172
|
-
import { PathaoApiService } from '
|
|
175
|
+
import { PathaoApiService } from 'pathao-merchant-sdk';
|
|
173
176
|
|
|
174
177
|
// Validate phone number
|
|
175
178
|
const isValidPhone = PathaoApiService.validatePhoneNumber('01712345678'); // true
|
|
@@ -262,7 +265,7 @@ PATHAO_PASSWORD=your-password
|
|
|
262
265
|
### Complete Order Flow
|
|
263
266
|
|
|
264
267
|
```typescript
|
|
265
|
-
import { PathaoApiService, DeliveryType, ItemType } from '
|
|
268
|
+
import { PathaoApiService, DeliveryType, ItemType } from 'pathao-merchant-sdk';
|
|
266
269
|
|
|
267
270
|
async function createDeliveryOrder() {
|
|
268
271
|
const pathao = new PathaoApiService({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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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EAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAML,IAAK,SAAA,qBAAAC,UAAAA,KAAL;AACL,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,kBAAe,CAAA,CAAA,GAAf,cAAA;AACA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,mBAAgB,CAAA,CAAA,GAAhB,eAAA;AAFU,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","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"]}
|
|
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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AAA,YAAS,EAAA,CAAA,GAAT,QAAA;AACA,EAAAA,aAAAA,CAAAA,aAAAA,CAAA,eAAY,EAAA,CAAA,GAAZ,WAAA;AAFU,EAAA,OAAAA,aAAAA;AAAA,CAAA,EAAA,YAAA,IAAA,EAAA;AAML,IAAK,QAAA,qBAAAC,SAAAA,KAAL;AACL,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,cAAW,CAAA,CAAA,GAAX,UAAA;AACA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,YAAS,CAAA,CAAA,GAAT,QAAA;AAFU,EAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAML,IAAK,SAAA,qBAAAC,UAAAA,KAAL;AACL,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,kBAAe,CAAA,CAAA,GAAf,cAAA;AACA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,mBAAgB,CAAA,CAAA,GAAhB,eAAA;AAFU,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","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, { AxiosError, AxiosInstance } from 'axios';\nimport {\n PathaoAreaResponse,\n PathaoAuthResponse,\n PathaoCityResponse,\n PathaoConfig,\n PathaoError,\n PathaoOrderRequest,\n PathaoOrderResponse,\n PathaoOrderStatusResponse,\n PathaoPriceRequest,\n PathaoPriceResponse,\n PathaoStoreRequest,\n PathaoStoreResponse,\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,\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,\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,\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"]}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pathao-api.ts","../src/types.ts"],"names":["config","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,GAAe,MAAM,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;AAAA,IACnG;AAGA,IAAA,IAAA,CAAK,YAAA,CAAa,YAAA,CAAa,OAAA,CAAQ,GAAA,CAAI,OAAOA,OAAAA,KAAW;AAC3D,MAAA,MAAM,KAAK,mBAAA,EAAoB;AAC/B,MAAA,IAAI,KAAK,WAAA,EAAa;AACpB,QAAAA,OAAAA,C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GA,OAAO,eAAe,MAAA,EAAyB;AAC7C,IAAA,OAAO,MAAA,IAAU,OAAO,MAAA,IAAU,EAAA;AAAA,EACpC;AAAA;AAAA,EAGA,OAAO,sBAAsB,IAAA,EAAuB;AAClD,IAAA,MAAM,OAAA,GAAU,KAAK,IAAA,EAAK;AAC1B,IAAA,OAAO,OAAA,CAAQ,MAAA,IAAU,CAAA,IAAK,OAAA,CAAQ,MAAA,IAAU,GAAA;AAAA,EAClD;AACF;;;ACnHO,IAAK,YAAA,qBAAAC,aAAAA,KAAL;AACL,EAAAA,aAAAA,CAAAA,aAAAA,CAAA,YAAS,EAAA,CAAA,GAAT,QAAA;AACA,EAAAA,aAAAA,CAAAA,aAAAA,CAAA,eAAY,EAAA,CAAA,GAAZ,WAAA;AAFU,EAAA,OAAAA,aAAAA;AAAA,CAAA,EAAA,YAAA,IAAA,EAAA;AAML,IAAK,QAAA,qBAAAC,SAAAA,KAAL;AACL,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,cAAW,CAAA,CAAA,GAAX,UAAA;AACA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,YAAS,CAAA,CAAA,GAAT,QAAA;AAFU,EAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAML,IAAK,SAAA,qBAAAC,UAAAA,KAAL;AACL,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,kBAAe,CAAA,CAAA,GAAf,cAAA;AACA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,mBAAgB,CAAA,CAAA,GAAhB,eAAA;AAFU,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","file":"index.mjs","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"]}
|
|
1
|
+
{"version":3,"sources":["../src/pathao-api.ts","../src/types.ts"],"names":["config","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,GAAe,MAAM,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,YA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AA,UAAAA,CAAAA,UAAAA,CAAA,mBAAgB,CAAA,CAAA,GAAhB,eAAA;AAFU,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","file":"index.mjs","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, { AxiosError, AxiosInstance } from 'axios';\nimport {\n PathaoAreaResponse,\n PathaoAuthResponse,\n PathaoCityResponse,\n PathaoConfig,\n PathaoError,\n PathaoOrderRequest,\n PathaoOrderResponse,\n PathaoOrderStatusResponse,\n PathaoPriceRequest,\n PathaoPriceResponse,\n PathaoStoreRequest,\n PathaoStoreResponse,\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,\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,\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,\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pathao-merchant-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Unofficial Pathao Merchant API SDK for Node.js and TypeScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -18,7 +18,13 @@
|
|
|
18
18
|
"lint": "eslint src/**/*.ts",
|
|
19
19
|
"lint:fix": "eslint src/**/*.ts --fix",
|
|
20
20
|
"type-check": "tsc --noEmit",
|
|
21
|
-
"prepublishOnly": "pnpm run build && pnpm run test"
|
|
21
|
+
"prepublishOnly": "pnpm run build && pnpm run test",
|
|
22
|
+
"release": "node scripts/release.js",
|
|
23
|
+
"release:dry-run": "node scripts/release.js --dry-run",
|
|
24
|
+
"changelog": "node scripts/release.js --changelog-only",
|
|
25
|
+
"version:patch": "npm version patch --no-git-tag-version",
|
|
26
|
+
"version:minor": "npm version minor --no-git-tag-version",
|
|
27
|
+
"version:major": "npm version major --no-git-tag-version"
|
|
22
28
|
},
|
|
23
29
|
"keywords": [
|
|
24
30
|
"pathao",
|
|
@@ -51,6 +57,8 @@
|
|
|
51
57
|
"devDependencies": {
|
|
52
58
|
"@types/jest": "^29.5.0",
|
|
53
59
|
"@types/node": "^20.0.0",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
61
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
54
62
|
"eslint": "^8.0.0",
|
|
55
63
|
"jest": "^29.0.0",
|
|
56
64
|
"ts-jest": "^29.0.0",
|