pathao-merchant-sdk 2.0.0 → 2.0.1
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/CHANGELOG.md +8 -0
- package/dist/index.d.mts +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +43 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
13
13
|
|
|
14
14
|
## [Unreleased]
|
|
15
15
|
|
|
16
|
+
## [2.0.1] - 2025-12-05
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- Added `PathaoApiError` with structured fields (`status`, `code`, `type`, `errors`, `validation`, `responseData`) and updated all SDK methods to throw it.
|
|
20
|
+
|
|
21
|
+
### Verified
|
|
22
|
+
- `npm test` (jest) passes.
|
|
23
|
+
|
|
16
24
|
## [1.2.0] - 2024-12-05
|
|
17
25
|
|
|
18
26
|
### Fixed
|
package/dist/index.d.mts
CHANGED
|
@@ -205,6 +205,22 @@ declare enum ItemType {
|
|
|
205
205
|
* - City, zone, and area management
|
|
206
206
|
*/
|
|
207
207
|
|
|
208
|
+
declare class PathaoApiError extends Error {
|
|
209
|
+
status: number | undefined;
|
|
210
|
+
code: number | undefined;
|
|
211
|
+
type: string | undefined;
|
|
212
|
+
errors: Record<string, string[]> | undefined;
|
|
213
|
+
validation: Record<string, string[]> | undefined;
|
|
214
|
+
responseData: unknown;
|
|
215
|
+
constructor(message: string, options?: {
|
|
216
|
+
status?: number | undefined;
|
|
217
|
+
code?: number | undefined;
|
|
218
|
+
type?: string | undefined;
|
|
219
|
+
errors?: Record<string, string[]> | undefined;
|
|
220
|
+
validation?: Record<string, string[]> | undefined;
|
|
221
|
+
responseData?: unknown;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
208
224
|
declare class PathaoApiService {
|
|
209
225
|
private pathaoClient;
|
|
210
226
|
private accessToken;
|
|
@@ -222,6 +238,7 @@ declare class PathaoApiService {
|
|
|
222
238
|
private authenticate;
|
|
223
239
|
private refreshAccessToken;
|
|
224
240
|
private getErrorMessage;
|
|
241
|
+
private toPathaoApiError;
|
|
225
242
|
private handleCircuitBreaker;
|
|
226
243
|
createOrder(orderData: PathaoOrderRequest): Promise<PathaoOrderResponse>;
|
|
227
244
|
createStore(storeData: PathaoStoreRequest): Promise<PathaoStoreCreateResponse>;
|
|
@@ -249,4 +266,4 @@ declare class PathaoApiService {
|
|
|
249
266
|
clearAuth(): void;
|
|
250
267
|
}
|
|
251
268
|
|
|
252
|
-
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 PathaoStore, type PathaoStoreCreateResponse, type PathaoStoreListResponse, type PathaoStoreRequest, type PathaoZoneResponse };
|
|
269
|
+
export { DeliveryType, ItemType, PathaoApiError, PathaoApiService, type PathaoAreaResponse, type PathaoAuthResponse, type PathaoCityResponse, type PathaoConfig, type PathaoError, type PathaoOrderRequest, type PathaoOrderResponse, type PathaoOrderStatusResponse, type PathaoPriceRequest, type PathaoPriceResponse, type PathaoStore, type PathaoStoreCreateResponse, type PathaoStoreListResponse, type PathaoStoreRequest, type PathaoZoneResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -205,6 +205,22 @@ declare enum ItemType {
|
|
|
205
205
|
* - City, zone, and area management
|
|
206
206
|
*/
|
|
207
207
|
|
|
208
|
+
declare class PathaoApiError extends Error {
|
|
209
|
+
status: number | undefined;
|
|
210
|
+
code: number | undefined;
|
|
211
|
+
type: string | undefined;
|
|
212
|
+
errors: Record<string, string[]> | undefined;
|
|
213
|
+
validation: Record<string, string[]> | undefined;
|
|
214
|
+
responseData: unknown;
|
|
215
|
+
constructor(message: string, options?: {
|
|
216
|
+
status?: number | undefined;
|
|
217
|
+
code?: number | undefined;
|
|
218
|
+
type?: string | undefined;
|
|
219
|
+
errors?: Record<string, string[]> | undefined;
|
|
220
|
+
validation?: Record<string, string[]> | undefined;
|
|
221
|
+
responseData?: unknown;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
208
224
|
declare class PathaoApiService {
|
|
209
225
|
private pathaoClient;
|
|
210
226
|
private accessToken;
|
|
@@ -222,6 +238,7 @@ declare class PathaoApiService {
|
|
|
222
238
|
private authenticate;
|
|
223
239
|
private refreshAccessToken;
|
|
224
240
|
private getErrorMessage;
|
|
241
|
+
private toPathaoApiError;
|
|
225
242
|
private handleCircuitBreaker;
|
|
226
243
|
createOrder(orderData: PathaoOrderRequest): Promise<PathaoOrderResponse>;
|
|
227
244
|
createStore(storeData: PathaoStoreRequest): Promise<PathaoStoreCreateResponse>;
|
|
@@ -249,4 +266,4 @@ declare class PathaoApiService {
|
|
|
249
266
|
clearAuth(): void;
|
|
250
267
|
}
|
|
251
268
|
|
|
252
|
-
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 PathaoStore, type PathaoStoreCreateResponse, type PathaoStoreListResponse, type PathaoStoreRequest, type PathaoZoneResponse };
|
|
269
|
+
export { DeliveryType, ItemType, PathaoApiError, PathaoApiService, type PathaoAreaResponse, type PathaoAuthResponse, type PathaoCityResponse, type PathaoConfig, type PathaoError, type PathaoOrderRequest, type PathaoOrderResponse, type PathaoOrderStatusResponse, type PathaoPriceRequest, type PathaoPriceResponse, type PathaoStore, type PathaoStoreCreateResponse, type PathaoStoreListResponse, type PathaoStoreRequest, type PathaoZoneResponse };
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,18 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
7
7
|
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
8
8
|
|
|
9
9
|
// src/pathao-api.ts
|
|
10
|
+
var PathaoApiError = class extends Error {
|
|
11
|
+
constructor(message, options = {}) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "PathaoApiError";
|
|
14
|
+
this.status = options.status;
|
|
15
|
+
this.code = options.code;
|
|
16
|
+
this.type = options.type;
|
|
17
|
+
this.errors = options.errors;
|
|
18
|
+
this.validation = options.validation;
|
|
19
|
+
this.responseData = options.responseData;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
10
22
|
var PathaoApiService = class {
|
|
11
23
|
constructor(config) {
|
|
12
24
|
this.accessToken = null;
|
|
@@ -142,7 +154,7 @@ var PathaoApiService = class {
|
|
|
142
154
|
this.circuitBreaker.isOpen = false;
|
|
143
155
|
} catch (error) {
|
|
144
156
|
this.handleCircuitBreaker();
|
|
145
|
-
throw
|
|
157
|
+
throw this.toPathaoApiError(error, "Authentication failed");
|
|
146
158
|
}
|
|
147
159
|
}
|
|
148
160
|
async refreshAccessToken() {
|
|
@@ -163,7 +175,7 @@ var PathaoApiService = class {
|
|
|
163
175
|
this.circuitBreaker.isOpen = false;
|
|
164
176
|
} catch (error) {
|
|
165
177
|
this.handleCircuitBreaker();
|
|
166
|
-
throw
|
|
178
|
+
throw this.toPathaoApiError(error, "Token refresh failed");
|
|
167
179
|
}
|
|
168
180
|
}
|
|
169
181
|
getErrorMessage(error) {
|
|
@@ -176,6 +188,25 @@ var PathaoApiService = class {
|
|
|
176
188
|
}
|
|
177
189
|
return error.message || "Unknown error";
|
|
178
190
|
}
|
|
191
|
+
toPathaoApiError(error, context) {
|
|
192
|
+
if (error instanceof PathaoApiError) {
|
|
193
|
+
return error;
|
|
194
|
+
}
|
|
195
|
+
const messageFallback = this.getErrorMessage(error);
|
|
196
|
+
const axiosLike = error instanceof axios.AxiosError ? error : typeof error === "object" && error && "response" in error ? error : null;
|
|
197
|
+
if (axiosLike) {
|
|
198
|
+
const pathaoError = axiosLike.response?.data;
|
|
199
|
+
return new PathaoApiError(`${context}: ${pathaoError?.message || messageFallback}`, {
|
|
200
|
+
status: axiosLike.response?.status,
|
|
201
|
+
code: pathaoError?.code ?? axiosLike.response?.status,
|
|
202
|
+
type: pathaoError?.type,
|
|
203
|
+
errors: pathaoError?.errors,
|
|
204
|
+
validation: pathaoError?.validation,
|
|
205
|
+
responseData: pathaoError ?? axiosLike.response?.data
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return new PathaoApiError(`${context}: ${messageFallback}`);
|
|
209
|
+
}
|
|
179
210
|
handleCircuitBreaker() {
|
|
180
211
|
this.circuitBreaker.failures++;
|
|
181
212
|
this.circuitBreaker.lastFailureTime = Date.now();
|
|
@@ -189,8 +220,7 @@ var PathaoApiService = class {
|
|
|
189
220
|
const response = await this.pathaoClient.post("/aladdin/api/v1/orders", orderData);
|
|
190
221
|
return response.data;
|
|
191
222
|
} catch (error) {
|
|
192
|
-
|
|
193
|
-
throw new Error(`Failed to create Pathao order: ${errorMessage}`);
|
|
223
|
+
throw this.toPathaoApiError(error, "Failed to create Pathao order");
|
|
194
224
|
}
|
|
195
225
|
}
|
|
196
226
|
// Official Pathao API: Create Store
|
|
@@ -199,8 +229,7 @@ var PathaoApiService = class {
|
|
|
199
229
|
const response = await this.pathaoClient.post("/aladdin/api/v1/stores", storeData);
|
|
200
230
|
return response.data;
|
|
201
231
|
} catch (error) {
|
|
202
|
-
|
|
203
|
-
throw new Error(`Failed to create Pathao store: ${errorMessage}`);
|
|
232
|
+
throw this.toPathaoApiError(error, "Failed to create Pathao store");
|
|
204
233
|
}
|
|
205
234
|
}
|
|
206
235
|
// Official Pathao API: Get Store List
|
|
@@ -209,8 +238,7 @@ var PathaoApiService = class {
|
|
|
209
238
|
const response = await this.pathaoClient.get("/aladdin/api/v1/stores");
|
|
210
239
|
return response.data;
|
|
211
240
|
} catch (error) {
|
|
212
|
-
|
|
213
|
-
throw new Error(`Failed to fetch Pathao stores: ${errorMessage}`);
|
|
241
|
+
throw this.toPathaoApiError(error, "Failed to fetch Pathao stores");
|
|
214
242
|
}
|
|
215
243
|
}
|
|
216
244
|
// Official Pathao API: Calculate Price
|
|
@@ -219,8 +247,7 @@ var PathaoApiService = class {
|
|
|
219
247
|
const response = await this.pathaoClient.post("/aladdin/api/v1/merchant/price-plan", priceData);
|
|
220
248
|
return response.data;
|
|
221
249
|
} catch (error) {
|
|
222
|
-
|
|
223
|
-
throw new Error(`Failed to calculate Pathao price: ${errorMessage}`);
|
|
250
|
+
throw this.toPathaoApiError(error, "Failed to calculate Pathao price");
|
|
224
251
|
}
|
|
225
252
|
}
|
|
226
253
|
// Official Pathao API: Get Cities
|
|
@@ -229,8 +256,7 @@ var PathaoApiService = class {
|
|
|
229
256
|
const response = await this.pathaoClient.get("/aladdin/api/v1/city-list");
|
|
230
257
|
return response.data;
|
|
231
258
|
} catch (error) {
|
|
232
|
-
|
|
233
|
-
throw new Error(`Failed to fetch Pathao cities: ${errorMessage}`);
|
|
259
|
+
throw this.toPathaoApiError(error, "Failed to fetch Pathao cities");
|
|
234
260
|
}
|
|
235
261
|
}
|
|
236
262
|
// Official Pathao API: Get Zones for a City
|
|
@@ -239,8 +265,7 @@ var PathaoApiService = class {
|
|
|
239
265
|
const response = await this.pathaoClient.get(`/aladdin/api/v1/cities/${cityId}/zone-list`);
|
|
240
266
|
return response.data;
|
|
241
267
|
} catch (error) {
|
|
242
|
-
|
|
243
|
-
throw new Error(`Failed to fetch Pathao zones: ${errorMessage}`);
|
|
268
|
+
throw this.toPathaoApiError(error, "Failed to fetch Pathao zones");
|
|
244
269
|
}
|
|
245
270
|
}
|
|
246
271
|
// Official Pathao API: Get Areas for a Zone
|
|
@@ -249,8 +274,7 @@ var PathaoApiService = class {
|
|
|
249
274
|
const response = await this.pathaoClient.get(`/aladdin/api/v1/zones/${zoneId}/area-list`);
|
|
250
275
|
return response.data;
|
|
251
276
|
} catch (error) {
|
|
252
|
-
|
|
253
|
-
throw new Error(`Failed to fetch Pathao areas: ${errorMessage}`);
|
|
277
|
+
throw this.toPathaoApiError(error, "Failed to fetch Pathao areas");
|
|
254
278
|
}
|
|
255
279
|
}
|
|
256
280
|
// Official Pathao API: Get Order Status
|
|
@@ -259,8 +283,7 @@ var PathaoApiService = class {
|
|
|
259
283
|
const response = await this.pathaoClient.get(`/aladdin/api/v1/orders/${consignmentId}/info`);
|
|
260
284
|
return response.data;
|
|
261
285
|
} catch (error) {
|
|
262
|
-
|
|
263
|
-
throw new Error(`Failed to fetch Pathao order status: ${errorMessage}`);
|
|
286
|
+
throw this.toPathaoApiError(error, "Failed to fetch Pathao order status");
|
|
264
287
|
}
|
|
265
288
|
}
|
|
266
289
|
// Official Pathao API: Create Bulk Order
|
|
@@ -269,8 +292,7 @@ var PathaoApiService = class {
|
|
|
269
292
|
const response = await this.pathaoClient.post("/aladdin/api/v1/orders/bulk", { orders });
|
|
270
293
|
return response.data;
|
|
271
294
|
} catch (error) {
|
|
272
|
-
|
|
273
|
-
throw new Error(`Failed to create bulk Pathao orders: ${errorMessage}`);
|
|
295
|
+
throw this.toPathaoApiError(error, "Failed to create bulk Pathao orders");
|
|
274
296
|
}
|
|
275
297
|
}
|
|
276
298
|
// Helper method to validate phone number
|
|
@@ -352,6 +374,7 @@ var ItemType = /* @__PURE__ */ ((ItemType2) => {
|
|
|
352
374
|
|
|
353
375
|
exports.DeliveryType = DeliveryType;
|
|
354
376
|
exports.ItemType = ItemType;
|
|
377
|
+
exports.PathaoApiError = PathaoApiError;
|
|
355
378
|
exports.PathaoApiService = PathaoApiService;
|
|
356
379
|
//# sourceMappingURL=index.js.map
|
|
357
380
|
//# sourceMappingURL=index.js.map
|
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"],"mappings":";;;;;;;;;AA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A;AAAA,CAAA,EAAA,QAAA,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 * - All endpoints use /aladdin/api/v1/ prefix\n * - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config\n * - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config\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 PathaoStoreCreateResponse,\n PathaoStoreListResponse,\n PathaoStoreRequest,\n PathaoZoneResponse,\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 private isAuthenticating: boolean = false;\n private authPromise: Promise<void> | null = null;\n private requestQueue: Array<{ resolve: () => void; reject: (error: Error) => void }> = [];\n private circuitBreaker = {\n failures: 0,\n lastFailureTime: 0,\n threshold: 5,\n timeout: 60000, // 1 minute\n isOpen: false,\n };\n\n constructor(config: PathaoConfig) {\n this.config = {\n baseURL: config.baseURL || process.env.PATHAO_BASE_URL || '',\n timeout: config.timeout || parseInt(process.env.PATHAO_TIMEOUT || '30000', 10),\n clientId: config.clientId || process.env.PATHAO_CLIENT_ID || '',\n clientSecret: config.clientSecret || process.env.PATHAO_CLIENT_SECRET || '',\n username: config.username || process.env.PATHAO_USERNAME || '',\n password: config.password || process.env.PATHAO_PASSWORD || '',\n };\n\n this.pathaoClient = axios.create({\n baseURL: this.config.baseURL || process.env.PATHAO_BASE_URL || '',\n timeout: this.config.timeout || parseInt(process.env.PATHAO_TIMEOUT || '30000', 10),\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': 'application/json',\n },\n });\n\n // Validate required configuration\n if (!this.config.baseURL) {\n throw new Error('Pathao API baseURL is required. You can provide it via constructor config or PATHAO_BASE_URL environment variable');\n }\n \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. You can provide them via constructor config or environment variables (PATHAO_CLIENT_ID, PATHAO_CLIENT_SECRET, PATHAO_USERNAME, PATHAO_PASSWORD)');\n }\n\n // Add request interceptor for authentication\n this.pathaoClient.interceptors.request.use(async (config) => {\n // Skip auth for token requests to prevent infinite loops\n if (config.url?.includes('/issue-token')) {\n return config;\n }\n \n await this.ensureAuthenticated();\n if (this.accessToken) {\n config.headers.Authorization = `Bearer ${this.accessToken}`;\n }\n return config;\n });\n\n // Add response interceptor for error handling\n this.pathaoClient.interceptors.response.use(\n (response) => {\n // Reset circuit breaker on successful request\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n return response;\n },\n async (error) => {\n if (error.response?.status === 401) {\n // Token expired, clear tokens and retry\n this.accessToken = null;\n this.refreshToken = null;\n this.tokenExpiry = null;\n \n // Retry the request once\n if (error.config && !error.config._retry) {\n error.config._retry = true;\n await this.ensureAuthenticated();\n if (this.accessToken) {\n error.config.headers.Authorization = `Bearer ${this.accessToken}`;\n }\n return this.pathaoClient.request(error.config);\n }\n }\n \n // Handle circuit breaker\n this.handleCircuitBreaker();\n return Promise.reject(error);\n },\n );\n }\n\n private async ensureAuthenticated(): Promise<void> {\n // Check circuit breaker\n if (this.circuitBreaker.isOpen) {\n if (Date.now() - this.circuitBreaker.lastFailureTime > this.circuitBreaker.timeout) {\n this.circuitBreaker.isOpen = false;\n this.circuitBreaker.failures = 0;\n } else {\n throw new Error('Circuit breaker is open. Too many authentication failures.');\n }\n }\n\n if (this.accessToken && this.tokenExpiry && Date.now() < this.tokenExpiry) {\n return; // Token is still valid\n }\n\n // If already authenticating, wait for it to complete\n if (this.isAuthenticating && this.authPromise) {\n return this.authPromise;\n }\n\n // Start authentication process\n this.isAuthenticating = true;\n this.authPromise = this.performAuthentication();\n\n try {\n await this.authPromise;\n } finally {\n this.isAuthenticating = false;\n this.authPromise = null;\n // Process queued requests\n this.processRequestQueue();\n }\n }\n\n private async performAuthentication(): Promise<void> {\n if (this.refreshToken) {\n try {\n await this.refreshAccessToken();\n return;\n } catch (error) {\n // Refresh failed, try fresh authentication\n this.refreshToken = null;\n }\n }\n\n await this.authenticate();\n }\n\n private processRequestQueue(): void {\n const queue = [...this.requestQueue];\n this.requestQueue = [];\n \n queue.forEach(({ resolve }) => {\n try {\n resolve();\n } catch (error) {\n // Ignore errors in queued requests\n }\n });\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 // Reset circuit breaker on successful auth\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n } catch (error) {\n this.handleCircuitBreaker();\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 // Reset circuit breaker on successful refresh\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n } catch (error) {\n this.handleCircuitBreaker();\n throw new Error(`Token refresh failed: ${this.getErrorMessage(error)}`);\n }\n }\n\n private getErrorMessage(error: unknown): 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 as Error).message || 'Unknown error';\n }\n\n private handleCircuitBreaker(): void {\n this.circuitBreaker.failures++;\n this.circuitBreaker.lastFailureTime = Date.now();\n \n if (this.circuitBreaker.failures >= this.circuitBreaker.threshold) {\n this.circuitBreaker.isOpen = true;\n }\n }\n\n // Official Pathao API: Create Order\n async createOrder(orderData: PathaoOrderRequest): Promise<PathaoOrderResponse> {\n try {\n const response = await this.pathaoClient.post<PathaoOrderResponse>('/aladdin/api/v1/orders', orderData);\n return response.data;\n } catch (error: unknown) {\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<PathaoStoreCreateResponse> {\n try {\n const response = await this.pathaoClient.post<PathaoStoreCreateResponse>('/aladdin/api/v1/stores', storeData);\n return response.data;\n } catch (error: unknown) {\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<PathaoStoreListResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoStoreListResponse>('/aladdin/api/v1/stores');\n return response.data;\n } catch (error: unknown) {\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 const response = await this.pathaoClient.post<PathaoPriceResponse>('/aladdin/api/v1/merchant/price-plan', priceData);\n return response.data;\n } catch (error: unknown) {\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/city-list');\n return response.data;\n } catch (error: unknown) {\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to fetch Pathao cities: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Get Zones for a City\n async getZones(cityId: number): Promise<PathaoZoneResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoZoneResponse>(`/aladdin/api/v1/cities/${cityId}/zone-list`);\n return response.data;\n } catch (error: unknown) {\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to fetch Pathao zones: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Get Areas for a Zone\n async getAreas(zoneId: number): Promise<PathaoAreaResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoAreaResponse>(`/aladdin/api/v1/zones/${zoneId}/area-list`);\n return response.data;\n } catch (error: unknown) {\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}/info`);\n return response.data;\n } catch (error: unknown) {\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to fetch Pathao order status: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Create Bulk Order\n async createBulkOrder(\n orders: PathaoOrderRequest[],\n ): Promise<{ message: string; type: string; code: number; data: boolean }> {\n try {\n const response = await this.pathaoClient.post<{\n message: string;\n type: string;\n code: number;\n data: boolean;\n }>('/aladdin/api/v1/orders/bulk', { orders });\n return response.data;\n } catch (error: unknown) {\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to create bulk Pathao orders: ${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 // Helper method to validate store name\n static validateStoreName(name: string): boolean {\n const trimmed = name.trim();\n return trimmed.length >= 3 && trimmed.length <= 50;\n }\n\n // Helper method to validate contact name\n static validateContactName(name: string): boolean {\n const trimmed = name.trim();\n return trimmed.length >= 3 && trimmed.length <= 50;\n }\n\n // Helper method to validate contact number\n static validateContactNumber(phone: string): boolean {\n const cleanPhone = phone.replace(/\\D/g, '');\n return cleanPhone.length === 11;\n }\n\n // Helper method to validate store address\n static validateStoreAddress(address: string): boolean {\n const trimmed = address.trim();\n return trimmed.length >= 15 && trimmed.length <= 120;\n }\n\n // Method to clear authentication state (useful for testing)\n clearAuth(): void {\n this.accessToken = null;\n this.refreshToken = null;\n this.tokenExpiry = null;\n this.isAuthenticating = false;\n this.authPromise = null;\n this.requestQueue = [];\n this.circuitBreaker = {\n failures: 0,\n lastFailureTime: 0,\n threshold: 5,\n timeout: 60000,\n isOpen: false,\n };\n }\n}\n","/**\n * Pathao Courier API Types\n * \n * Official API Details:\n * - Authentication: OAuth2 with client_id, client_secret, username, password\n * - All endpoints use /aladdin/api/v1/ prefix\n * - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config\n * - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config\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; // 3-50 characters\n contact_name: string; // 3-50 characters\n contact_number: string; // 11 characters\n secondary_contact?: string; // Optional - 11 characters\n otp_number?: string; // Optional - OTP for orders\n address: string; // 15-120 characters\n city_id: number;\n zone_id: number;\n area_id: number;\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 merchant_order_id: string;\n order_status: string;\n delivery_fee: number;\n };\n}\n\n// Official Pathao Store Creation Response\nexport interface PathaoStoreCreateResponse {\n type: string;\n code: number;\n message: string;\n data: {\n store_name: string; // Only store_name returned on creation\n };\n}\n\n// Official Pathao Store List Item (from GET /stores)\nexport interface PathaoStore {\n store_id: number;\n store_name: string;\n store_address: string;\n is_active: number; // 1 for active, 0 for deactivated\n city_id: number;\n zone_id: number;\n hub_id: number;\n is_default_store: boolean;\n is_default_return_store: boolean;\n}\n\n// Official Pathao Store List Response\nexport interface PathaoStoreListResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: PathaoStore[];\n total: number;\n current_page: number;\n per_page: number;\n total_in_page: number;\n last_page: number;\n path: string;\n to: number;\n from: number;\n last_page_url: string;\n first_page_url: 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}\n\n// Official Pathao Price Response\nexport interface PathaoPriceResponse {\n type: string;\n code: number;\n message: string;\n data: {\n price: number; // Calculated price for given item\n discount: number; // Discount for the given item\n promo_discount: number; // Promo discount for the given item\n plan_id: number; // Price plan id for the given item\n cod_enabled: number; // 1 if COD enabled, 0 if not\n cod_percentage: number; // Cash on delivery percentage\n additional_charge: number; // If there is any additional charge\n final_price: number; // Your final price for the given item\n };\n}\n\n// Official Pathao City Response\nexport interface PathaoCityResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n city_id: number;\n city_name: string;\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 merchant_order_id: string;\n order_status: string;\n order_status_slug: string;\n updated_at: string;\n invoice_id: string | null;\n };\n}\n\n// Official Pathao Zone Response\nexport interface PathaoZoneResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n zone_id: number;\n zone_name: string;\n }>;\n };\n}\n\n// Official Pathao Area Response\nexport interface PathaoAreaResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n area_id: number;\n area_name: string;\n home_delivery_available: boolean;\n pickup_available: boolean;\n }>;\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 (removed as not used in official API)\n// export 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"],"mappings":";;;;;;;;;AAsCO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EAQxC,WAAA,CAAY,OAAA,EAAiB,OAAA,GAOzB,EAAC,EAAG;AACN,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,gBAAA;AACZ,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,OAAO,OAAA,CAAQ,IAAA;AACpB,IAAA,IAAA,CAAK,OAAO,OAAA,CAAQ,IAAA;AACpB,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,aAAa,OAAA,CAAQ,UAAA;AAC1B,IAAA,IAAA,CAAK,eAAe,OAAA,CAAQ,YAAA;AAAA,EAC9B;AACF;AAEO,IAAM,mBAAN,MAAuB;AAAA,EAiB5B,YAAY,MAAA,EAAsB;AAflC,IAAA,IAAA,CAAQ,WAAA,GAA6B,IAAA;AACrC,IAAA,IAAA,CAAQ,YAAA,GAA8B,IAAA;AACtC,IAAA,IAAA,CAAQ,WAAA,GAA6B,IAAA;AAErC,IAAA,IAAA,CAAQ,gBAAA,GAA4B,KAAA;AACpC,IAAA,IAAA,CAAQ,WAAA,GAAoC,IAAA;AAC5C,IAAA,IAAA,CAAQ,eAA+E,EA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.\n * \n * API Details (based on public documentation):\n * - Authentication: OAuth2 with client_id, client_secret, username, password\n * - All endpoints use /aladdin/api/v1/ prefix\n * - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config\n * - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config\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 PathaoStoreCreateResponse,\n PathaoStoreListResponse,\n PathaoStoreRequest,\n PathaoZoneResponse,\n} from './types';\n\nexport class PathaoApiError extends Error {\n status: number | undefined;\n code: number | undefined;\n type: string | undefined;\n errors: Record<string, string[]> | undefined;\n validation: Record<string, string[]> | undefined;\n responseData: unknown;\n\n constructor(message: string, options: {\n status?: number | undefined;\n code?: number | undefined;\n type?: string | undefined;\n errors?: Record<string, string[]> | undefined;\n validation?: Record<string, string[]> | undefined;\n responseData?: unknown;\n } = {}) {\n super(message);\n this.name = 'PathaoApiError';\n this.status = options.status;\n this.code = options.code;\n this.type = options.type;\n this.errors = options.errors;\n this.validation = options.validation;\n this.responseData = options.responseData;\n }\n}\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 private isAuthenticating: boolean = false;\n private authPromise: Promise<void> | null = null;\n private requestQueue: Array<{ resolve: () => void; reject: (error: Error) => void }> = [];\n private circuitBreaker = {\n failures: 0,\n lastFailureTime: 0,\n threshold: 5,\n timeout: 60000, // 1 minute\n isOpen: false,\n };\n\n constructor(config: PathaoConfig) {\n this.config = {\n baseURL: config.baseURL || process.env.PATHAO_BASE_URL || '',\n timeout: config.timeout || parseInt(process.env.PATHAO_TIMEOUT || '30000', 10),\n clientId: config.clientId || process.env.PATHAO_CLIENT_ID || '',\n clientSecret: config.clientSecret || process.env.PATHAO_CLIENT_SECRET || '',\n username: config.username || process.env.PATHAO_USERNAME || '',\n password: config.password || process.env.PATHAO_PASSWORD || '',\n };\n\n this.pathaoClient = axios.create({\n baseURL: this.config.baseURL || process.env.PATHAO_BASE_URL || '',\n timeout: this.config.timeout || parseInt(process.env.PATHAO_TIMEOUT || '30000', 10),\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': 'application/json',\n },\n });\n\n // Validate required configuration\n if (!this.config.baseURL) {\n throw new Error('Pathao API baseURL is required. You can provide it via constructor config or PATHAO_BASE_URL environment variable');\n }\n \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. You can provide them via constructor config or environment variables (PATHAO_CLIENT_ID, PATHAO_CLIENT_SECRET, PATHAO_USERNAME, PATHAO_PASSWORD)');\n }\n\n // Add request interceptor for authentication\n this.pathaoClient.interceptors.request.use(async (config) => {\n // Skip auth for token requests to prevent infinite loops\n if (config.url?.includes('/issue-token')) {\n return config;\n }\n \n await this.ensureAuthenticated();\n if (this.accessToken) {\n config.headers.Authorization = `Bearer ${this.accessToken}`;\n }\n return config;\n });\n\n // Add response interceptor for error handling\n this.pathaoClient.interceptors.response.use(\n (response) => {\n // Reset circuit breaker on successful request\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n return response;\n },\n async (error) => {\n if (error.response?.status === 401) {\n // Token expired, clear tokens and retry\n this.accessToken = null;\n this.refreshToken = null;\n this.tokenExpiry = null;\n \n // Retry the request once\n if (error.config && !error.config._retry) {\n error.config._retry = true;\n await this.ensureAuthenticated();\n if (this.accessToken) {\n error.config.headers.Authorization = `Bearer ${this.accessToken}`;\n }\n return this.pathaoClient.request(error.config);\n }\n }\n \n // Handle circuit breaker\n this.handleCircuitBreaker();\n return Promise.reject(error);\n },\n );\n }\n\n private async ensureAuthenticated(): Promise<void> {\n // Check circuit breaker\n if (this.circuitBreaker.isOpen) {\n if (Date.now() - this.circuitBreaker.lastFailureTime > this.circuitBreaker.timeout) {\n this.circuitBreaker.isOpen = false;\n this.circuitBreaker.failures = 0;\n } else {\n throw new Error('Circuit breaker is open. Too many authentication failures.');\n }\n }\n\n if (this.accessToken && this.tokenExpiry && Date.now() < this.tokenExpiry) {\n return; // Token is still valid\n }\n\n // If already authenticating, wait for it to complete\n if (this.isAuthenticating && this.authPromise) {\n return this.authPromise;\n }\n\n // Start authentication process\n this.isAuthenticating = true;\n this.authPromise = this.performAuthentication();\n\n try {\n await this.authPromise;\n } finally {\n this.isAuthenticating = false;\n this.authPromise = null;\n // Process queued requests\n this.processRequestQueue();\n }\n }\n\n private async performAuthentication(): Promise<void> {\n if (this.refreshToken) {\n try {\n await this.refreshAccessToken();\n return;\n } catch (error) {\n // Refresh failed, try fresh authentication\n this.refreshToken = null;\n }\n }\n\n await this.authenticate();\n }\n\n private processRequestQueue(): void {\n const queue = [...this.requestQueue];\n this.requestQueue = [];\n \n queue.forEach(({ resolve }) => {\n try {\n resolve();\n } catch (error) {\n // Ignore errors in queued requests\n }\n });\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 // Reset circuit breaker on successful auth\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n } catch (error) {\n this.handleCircuitBreaker();\n throw this.toPathaoApiError(error, 'Authentication failed');\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 // Reset circuit breaker on successful refresh\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n } catch (error) {\n this.handleCircuitBreaker();\n throw this.toPathaoApiError(error, 'Token refresh failed');\n }\n }\n\n private getErrorMessage(error: unknown): 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 as Error).message || 'Unknown error';\n }\n\n private toPathaoApiError(error: unknown, context: string): PathaoApiError {\n if (error instanceof PathaoApiError) {\n return error;\n }\n\n const messageFallback = this.getErrorMessage(error);\n const axiosLike = (error instanceof AxiosError) ? error : (typeof error === 'object' && error && 'response' in (error as any) ? error as AxiosError : null);\n if (axiosLike) {\n const pathaoError = axiosLike.response?.data as PathaoError | undefined;\n return new PathaoApiError(`${context}: ${pathaoError?.message || messageFallback}`, {\n status: axiosLike.response?.status,\n code: pathaoError?.code ?? axiosLike.response?.status,\n type: pathaoError?.type,\n errors: pathaoError?.errors,\n validation: pathaoError?.validation,\n responseData: pathaoError ?? axiosLike.response?.data,\n });\n }\n\n return new PathaoApiError(`${context}: ${messageFallback}`);\n }\n\n private handleCircuitBreaker(): void {\n this.circuitBreaker.failures++;\n this.circuitBreaker.lastFailureTime = Date.now();\n \n if (this.circuitBreaker.failures >= this.circuitBreaker.threshold) {\n this.circuitBreaker.isOpen = true;\n }\n }\n\n // Official Pathao API: Create Order\n async createOrder(orderData: PathaoOrderRequest): Promise<PathaoOrderResponse> {\n try {\n const response = await this.pathaoClient.post<PathaoOrderResponse>('/aladdin/api/v1/orders', orderData);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to create Pathao order');\n }\n }\n\n // Official Pathao API: Create Store\n async createStore(storeData: PathaoStoreRequest): Promise<PathaoStoreCreateResponse> {\n try {\n const response = await this.pathaoClient.post<PathaoStoreCreateResponse>('/aladdin/api/v1/stores', storeData);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to create Pathao store');\n }\n }\n\n // Official Pathao API: Get Store List\n async getStores(): Promise<PathaoStoreListResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoStoreListResponse>('/aladdin/api/v1/stores');\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to fetch Pathao stores');\n }\n }\n\n // Official Pathao API: Calculate Price\n async calculatePrice(priceData: PathaoPriceRequest): Promise<PathaoPriceResponse> {\n try {\n const response = await this.pathaoClient.post<PathaoPriceResponse>('/aladdin/api/v1/merchant/price-plan', priceData);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to calculate Pathao price');\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/city-list');\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to fetch Pathao cities');\n }\n }\n\n // Official Pathao API: Get Zones for a City\n async getZones(cityId: number): Promise<PathaoZoneResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoZoneResponse>(`/aladdin/api/v1/cities/${cityId}/zone-list`);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to fetch Pathao zones');\n }\n }\n\n // Official Pathao API: Get Areas for a Zone\n async getAreas(zoneId: number): Promise<PathaoAreaResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoAreaResponse>(`/aladdin/api/v1/zones/${zoneId}/area-list`);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to fetch Pathao areas');\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}/info`);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to fetch Pathao order status');\n }\n }\n\n // Official Pathao API: Create Bulk Order\n async createBulkOrder(\n orders: PathaoOrderRequest[],\n ): Promise<{ message: string; type: string; code: number; data: boolean }> {\n try {\n const response = await this.pathaoClient.post<{\n message: string;\n type: string;\n code: number;\n data: boolean;\n }>('/aladdin/api/v1/orders/bulk', { orders });\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to create bulk Pathao orders');\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 // Helper method to validate store name\n static validateStoreName(name: string): boolean {\n const trimmed = name.trim();\n return trimmed.length >= 3 && trimmed.length <= 50;\n }\n\n // Helper method to validate contact name\n static validateContactName(name: string): boolean {\n const trimmed = name.trim();\n return trimmed.length >= 3 && trimmed.length <= 50;\n }\n\n // Helper method to validate contact number\n static validateContactNumber(phone: string): boolean {\n const cleanPhone = phone.replace(/\\D/g, '');\n return cleanPhone.length === 11;\n }\n\n // Helper method to validate store address\n static validateStoreAddress(address: string): boolean {\n const trimmed = address.trim();\n return trimmed.length >= 15 && trimmed.length <= 120;\n }\n\n // Method to clear authentication state (useful for testing)\n clearAuth(): void {\n this.accessToken = null;\n this.refreshToken = null;\n this.tokenExpiry = null;\n this.isAuthenticating = false;\n this.authPromise = null;\n this.requestQueue = [];\n this.circuitBreaker = {\n failures: 0,\n lastFailureTime: 0,\n threshold: 5,\n timeout: 60000,\n isOpen: false,\n };\n }\n}\n","/**\n * Pathao Courier API Types\n * \n * Official API Details:\n * - Authentication: OAuth2 with client_id, client_secret, username, password\n * - All endpoints use /aladdin/api/v1/ prefix\n * - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config\n * - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config\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; // 3-50 characters\n contact_name: string; // 3-50 characters\n contact_number: string; // 11 characters\n secondary_contact?: string; // Optional - 11 characters\n otp_number?: string; // Optional - OTP for orders\n address: string; // 15-120 characters\n city_id: number;\n zone_id: number;\n area_id: number;\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 merchant_order_id: string;\n order_status: string;\n delivery_fee: number;\n };\n}\n\n// Official Pathao Store Creation Response\nexport interface PathaoStoreCreateResponse {\n type: string;\n code: number;\n message: string;\n data: {\n store_name: string; // Only store_name returned on creation\n };\n}\n\n// Official Pathao Store List Item (from GET /stores)\nexport interface PathaoStore {\n store_id: number;\n store_name: string;\n store_address: string;\n is_active: number; // 1 for active, 0 for deactivated\n city_id: number;\n zone_id: number;\n hub_id: number;\n is_default_store: boolean;\n is_default_return_store: boolean;\n}\n\n// Official Pathao Store List Response\nexport interface PathaoStoreListResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: PathaoStore[];\n total: number;\n current_page: number;\n per_page: number;\n total_in_page: number;\n last_page: number;\n path: string;\n to: number;\n from: number;\n last_page_url: string;\n first_page_url: 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}\n\n// Official Pathao Price Response\nexport interface PathaoPriceResponse {\n type: string;\n code: number;\n message: string;\n data: {\n price: number; // Calculated price for given item\n discount: number; // Discount for the given item\n promo_discount: number; // Promo discount for the given item\n plan_id: number; // Price plan id for the given item\n cod_enabled: number; // 1 if COD enabled, 0 if not\n cod_percentage: number; // Cash on delivery percentage\n additional_charge: number; // If there is any additional charge\n final_price: number; // Your final price for the given item\n };\n}\n\n// Official Pathao City Response\nexport interface PathaoCityResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n city_id: number;\n city_name: string;\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 merchant_order_id: string;\n order_status: string;\n order_status_slug: string;\n updated_at: string;\n invoice_id: string | null;\n };\n}\n\n// Official Pathao Zone Response\nexport interface PathaoZoneResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n zone_id: number;\n zone_name: string;\n }>;\n };\n}\n\n// Official Pathao Area Response\nexport interface PathaoAreaResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n area_id: number;\n area_name: string;\n home_delivery_available: boolean;\n pickup_available: boolean;\n }>;\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 (removed as not used in official API)\n// export enum StoreType {\n// PICKUP_POINT = 1,\n// SERVICE_POINT = 2\n// }\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import axios, { AxiosError } from 'axios';
|
|
2
2
|
|
|
3
3
|
// src/pathao-api.ts
|
|
4
|
+
var PathaoApiError = class extends Error {
|
|
5
|
+
constructor(message, options = {}) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "PathaoApiError";
|
|
8
|
+
this.status = options.status;
|
|
9
|
+
this.code = options.code;
|
|
10
|
+
this.type = options.type;
|
|
11
|
+
this.errors = options.errors;
|
|
12
|
+
this.validation = options.validation;
|
|
13
|
+
this.responseData = options.responseData;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
4
16
|
var PathaoApiService = class {
|
|
5
17
|
constructor(config) {
|
|
6
18
|
this.accessToken = null;
|
|
@@ -136,7 +148,7 @@ var PathaoApiService = class {
|
|
|
136
148
|
this.circuitBreaker.isOpen = false;
|
|
137
149
|
} catch (error) {
|
|
138
150
|
this.handleCircuitBreaker();
|
|
139
|
-
throw
|
|
151
|
+
throw this.toPathaoApiError(error, "Authentication failed");
|
|
140
152
|
}
|
|
141
153
|
}
|
|
142
154
|
async refreshAccessToken() {
|
|
@@ -157,7 +169,7 @@ var PathaoApiService = class {
|
|
|
157
169
|
this.circuitBreaker.isOpen = false;
|
|
158
170
|
} catch (error) {
|
|
159
171
|
this.handleCircuitBreaker();
|
|
160
|
-
throw
|
|
172
|
+
throw this.toPathaoApiError(error, "Token refresh failed");
|
|
161
173
|
}
|
|
162
174
|
}
|
|
163
175
|
getErrorMessage(error) {
|
|
@@ -170,6 +182,25 @@ var PathaoApiService = class {
|
|
|
170
182
|
}
|
|
171
183
|
return error.message || "Unknown error";
|
|
172
184
|
}
|
|
185
|
+
toPathaoApiError(error, context) {
|
|
186
|
+
if (error instanceof PathaoApiError) {
|
|
187
|
+
return error;
|
|
188
|
+
}
|
|
189
|
+
const messageFallback = this.getErrorMessage(error);
|
|
190
|
+
const axiosLike = error instanceof AxiosError ? error : typeof error === "object" && error && "response" in error ? error : null;
|
|
191
|
+
if (axiosLike) {
|
|
192
|
+
const pathaoError = axiosLike.response?.data;
|
|
193
|
+
return new PathaoApiError(`${context}: ${pathaoError?.message || messageFallback}`, {
|
|
194
|
+
status: axiosLike.response?.status,
|
|
195
|
+
code: pathaoError?.code ?? axiosLike.response?.status,
|
|
196
|
+
type: pathaoError?.type,
|
|
197
|
+
errors: pathaoError?.errors,
|
|
198
|
+
validation: pathaoError?.validation,
|
|
199
|
+
responseData: pathaoError ?? axiosLike.response?.data
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return new PathaoApiError(`${context}: ${messageFallback}`);
|
|
203
|
+
}
|
|
173
204
|
handleCircuitBreaker() {
|
|
174
205
|
this.circuitBreaker.failures++;
|
|
175
206
|
this.circuitBreaker.lastFailureTime = Date.now();
|
|
@@ -183,8 +214,7 @@ var PathaoApiService = class {
|
|
|
183
214
|
const response = await this.pathaoClient.post("/aladdin/api/v1/orders", orderData);
|
|
184
215
|
return response.data;
|
|
185
216
|
} catch (error) {
|
|
186
|
-
|
|
187
|
-
throw new Error(`Failed to create Pathao order: ${errorMessage}`);
|
|
217
|
+
throw this.toPathaoApiError(error, "Failed to create Pathao order");
|
|
188
218
|
}
|
|
189
219
|
}
|
|
190
220
|
// Official Pathao API: Create Store
|
|
@@ -193,8 +223,7 @@ var PathaoApiService = class {
|
|
|
193
223
|
const response = await this.pathaoClient.post("/aladdin/api/v1/stores", storeData);
|
|
194
224
|
return response.data;
|
|
195
225
|
} catch (error) {
|
|
196
|
-
|
|
197
|
-
throw new Error(`Failed to create Pathao store: ${errorMessage}`);
|
|
226
|
+
throw this.toPathaoApiError(error, "Failed to create Pathao store");
|
|
198
227
|
}
|
|
199
228
|
}
|
|
200
229
|
// Official Pathao API: Get Store List
|
|
@@ -203,8 +232,7 @@ var PathaoApiService = class {
|
|
|
203
232
|
const response = await this.pathaoClient.get("/aladdin/api/v1/stores");
|
|
204
233
|
return response.data;
|
|
205
234
|
} catch (error) {
|
|
206
|
-
|
|
207
|
-
throw new Error(`Failed to fetch Pathao stores: ${errorMessage}`);
|
|
235
|
+
throw this.toPathaoApiError(error, "Failed to fetch Pathao stores");
|
|
208
236
|
}
|
|
209
237
|
}
|
|
210
238
|
// Official Pathao API: Calculate Price
|
|
@@ -213,8 +241,7 @@ var PathaoApiService = class {
|
|
|
213
241
|
const response = await this.pathaoClient.post("/aladdin/api/v1/merchant/price-plan", priceData);
|
|
214
242
|
return response.data;
|
|
215
243
|
} catch (error) {
|
|
216
|
-
|
|
217
|
-
throw new Error(`Failed to calculate Pathao price: ${errorMessage}`);
|
|
244
|
+
throw this.toPathaoApiError(error, "Failed to calculate Pathao price");
|
|
218
245
|
}
|
|
219
246
|
}
|
|
220
247
|
// Official Pathao API: Get Cities
|
|
@@ -223,8 +250,7 @@ var PathaoApiService = class {
|
|
|
223
250
|
const response = await this.pathaoClient.get("/aladdin/api/v1/city-list");
|
|
224
251
|
return response.data;
|
|
225
252
|
} catch (error) {
|
|
226
|
-
|
|
227
|
-
throw new Error(`Failed to fetch Pathao cities: ${errorMessage}`);
|
|
253
|
+
throw this.toPathaoApiError(error, "Failed to fetch Pathao cities");
|
|
228
254
|
}
|
|
229
255
|
}
|
|
230
256
|
// Official Pathao API: Get Zones for a City
|
|
@@ -233,8 +259,7 @@ var PathaoApiService = class {
|
|
|
233
259
|
const response = await this.pathaoClient.get(`/aladdin/api/v1/cities/${cityId}/zone-list`);
|
|
234
260
|
return response.data;
|
|
235
261
|
} catch (error) {
|
|
236
|
-
|
|
237
|
-
throw new Error(`Failed to fetch Pathao zones: ${errorMessage}`);
|
|
262
|
+
throw this.toPathaoApiError(error, "Failed to fetch Pathao zones");
|
|
238
263
|
}
|
|
239
264
|
}
|
|
240
265
|
// Official Pathao API: Get Areas for a Zone
|
|
@@ -243,8 +268,7 @@ var PathaoApiService = class {
|
|
|
243
268
|
const response = await this.pathaoClient.get(`/aladdin/api/v1/zones/${zoneId}/area-list`);
|
|
244
269
|
return response.data;
|
|
245
270
|
} catch (error) {
|
|
246
|
-
|
|
247
|
-
throw new Error(`Failed to fetch Pathao areas: ${errorMessage}`);
|
|
271
|
+
throw this.toPathaoApiError(error, "Failed to fetch Pathao areas");
|
|
248
272
|
}
|
|
249
273
|
}
|
|
250
274
|
// Official Pathao API: Get Order Status
|
|
@@ -253,8 +277,7 @@ var PathaoApiService = class {
|
|
|
253
277
|
const response = await this.pathaoClient.get(`/aladdin/api/v1/orders/${consignmentId}/info`);
|
|
254
278
|
return response.data;
|
|
255
279
|
} catch (error) {
|
|
256
|
-
|
|
257
|
-
throw new Error(`Failed to fetch Pathao order status: ${errorMessage}`);
|
|
280
|
+
throw this.toPathaoApiError(error, "Failed to fetch Pathao order status");
|
|
258
281
|
}
|
|
259
282
|
}
|
|
260
283
|
// Official Pathao API: Create Bulk Order
|
|
@@ -263,8 +286,7 @@ var PathaoApiService = class {
|
|
|
263
286
|
const response = await this.pathaoClient.post("/aladdin/api/v1/orders/bulk", { orders });
|
|
264
287
|
return response.data;
|
|
265
288
|
} catch (error) {
|
|
266
|
-
|
|
267
|
-
throw new Error(`Failed to create bulk Pathao orders: ${errorMessage}`);
|
|
289
|
+
throw this.toPathaoApiError(error, "Failed to create bulk Pathao orders");
|
|
268
290
|
}
|
|
269
291
|
}
|
|
270
292
|
// Helper method to validate phone number
|
|
@@ -344,6 +366,6 @@ var ItemType = /* @__PURE__ */ ((ItemType2) => {
|
|
|
344
366
|
return ItemType2;
|
|
345
367
|
})(ItemType || {});
|
|
346
368
|
|
|
347
|
-
export { DeliveryType, ItemType, PathaoApiService };
|
|
369
|
+
export { DeliveryType, ItemType, PathaoApiError, PathaoApiService };
|
|
348
370
|
//# sourceMappingURL=index.mjs.map
|
|
349
371
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pathao-api.ts","../src/types.ts"],"names":["config","DeliveryType","ItemType"],"mappings":";;;AAsCO,IAAM,mBAAN,MAAuB;AAAA,EAiB5B,YAAY,MAAA,EAAsB;AAflC,IAAA,IAAA,CAAQ,WAAA,GAA6B,IAAA;AACrC,IAAA,IAAA,CAAQ,YAAA,GAA8B,IAAA;AACtC,IAAA,IAAA,CAAQ,WAAA,GAA6B,IAAA;AAErC,IAAA,IAAA,CAAQ,gBAAA,GAA4B,KAAA;AACpC,IAAA,IAAA,CAAQ,WAAA,GAAoC,IAAA;AAC5C,IAAA,IAAA,CAAQ,eAA+E,EAAC;AACxF,IAAA,IAAA,CAAQ,cAAA,GAAiB;AAAA,MACvB,QAAA,EAAU,CAAA;AAAA,MACV,eAAA,EAAiB,CAAA;AAAA,MACjB,SAAA,EAAW,CAAA;AAAA,MACX,OAAA,EAAS,GAAA;AAAA;AAA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AA;AACxB,IAAA,IAAA,CAAK,WAAA,GAAc,IAAA;AACnB,IAAA,IAAA,CAAK,eAAe,EAAC;AACrB,IAAA,IAAA,CAAK,cAAA,GAAiB;AAAA,MACpB,QAAA,EAAU,CAAA;AAAA,MACV,eAAA,EAAiB,CAAA;AAAA,MACjB,SAAA,EAAW,CAAA;AAAA,MACX,OAAA,EAAS,GAAA;AAAA,MACT,MAAA,EAAQ;AAAA,KACV;AAAA,EACF;AACF;;;ACpOO,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","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 * - All endpoints use /aladdin/api/v1/ prefix\n * - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config\n * - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config\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 PathaoStoreCreateResponse,\n PathaoStoreListResponse,\n PathaoStoreRequest,\n PathaoZoneResponse,\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 private isAuthenticating: boolean = false;\n private authPromise: Promise<void> | null = null;\n private requestQueue: Array<{ resolve: () => void; reject: (error: Error) => void }> = [];\n private circuitBreaker = {\n failures: 0,\n lastFailureTime: 0,\n threshold: 5,\n timeout: 60000, // 1 minute\n isOpen: false,\n };\n\n constructor(config: PathaoConfig) {\n this.config = {\n baseURL: config.baseURL || process.env.PATHAO_BASE_URL || '',\n timeout: config.timeout || parseInt(process.env.PATHAO_TIMEOUT || '30000', 10),\n clientId: config.clientId || process.env.PATHAO_CLIENT_ID || '',\n clientSecret: config.clientSecret || process.env.PATHAO_CLIENT_SECRET || '',\n username: config.username || process.env.PATHAO_USERNAME || '',\n password: config.password || process.env.PATHAO_PASSWORD || '',\n };\n\n this.pathaoClient = axios.create({\n baseURL: this.config.baseURL || process.env.PATHAO_BASE_URL || '',\n timeout: this.config.timeout || parseInt(process.env.PATHAO_TIMEOUT || '30000', 10),\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': 'application/json',\n },\n });\n\n // Validate required configuration\n if (!this.config.baseURL) {\n throw new Error('Pathao API baseURL is required. You can provide it via constructor config or PATHAO_BASE_URL environment variable');\n }\n \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. You can provide them via constructor config or environment variables (PATHAO_CLIENT_ID, PATHAO_CLIENT_SECRET, PATHAO_USERNAME, PATHAO_PASSWORD)');\n }\n\n // Add request interceptor for authentication\n this.pathaoClient.interceptors.request.use(async (config) => {\n // Skip auth for token requests to prevent infinite loops\n if (config.url?.includes('/issue-token')) {\n return config;\n }\n \n await this.ensureAuthenticated();\n if (this.accessToken) {\n config.headers.Authorization = `Bearer ${this.accessToken}`;\n }\n return config;\n });\n\n // Add response interceptor for error handling\n this.pathaoClient.interceptors.response.use(\n (response) => {\n // Reset circuit breaker on successful request\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n return response;\n },\n async (error) => {\n if (error.response?.status === 401) {\n // Token expired, clear tokens and retry\n this.accessToken = null;\n this.refreshToken = null;\n this.tokenExpiry = null;\n \n // Retry the request once\n if (error.config && !error.config._retry) {\n error.config._retry = true;\n await this.ensureAuthenticated();\n if (this.accessToken) {\n error.config.headers.Authorization = `Bearer ${this.accessToken}`;\n }\n return this.pathaoClient.request(error.config);\n }\n }\n \n // Handle circuit breaker\n this.handleCircuitBreaker();\n return Promise.reject(error);\n },\n );\n }\n\n private async ensureAuthenticated(): Promise<void> {\n // Check circuit breaker\n if (this.circuitBreaker.isOpen) {\n if (Date.now() - this.circuitBreaker.lastFailureTime > this.circuitBreaker.timeout) {\n this.circuitBreaker.isOpen = false;\n this.circuitBreaker.failures = 0;\n } else {\n throw new Error('Circuit breaker is open. Too many authentication failures.');\n }\n }\n\n if (this.accessToken && this.tokenExpiry && Date.now() < this.tokenExpiry) {\n return; // Token is still valid\n }\n\n // If already authenticating, wait for it to complete\n if (this.isAuthenticating && this.authPromise) {\n return this.authPromise;\n }\n\n // Start authentication process\n this.isAuthenticating = true;\n this.authPromise = this.performAuthentication();\n\n try {\n await this.authPromise;\n } finally {\n this.isAuthenticating = false;\n this.authPromise = null;\n // Process queued requests\n this.processRequestQueue();\n }\n }\n\n private async performAuthentication(): Promise<void> {\n if (this.refreshToken) {\n try {\n await this.refreshAccessToken();\n return;\n } catch (error) {\n // Refresh failed, try fresh authentication\n this.refreshToken = null;\n }\n }\n\n await this.authenticate();\n }\n\n private processRequestQueue(): void {\n const queue = [...this.requestQueue];\n this.requestQueue = [];\n \n queue.forEach(({ resolve }) => {\n try {\n resolve();\n } catch (error) {\n // Ignore errors in queued requests\n }\n });\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 // Reset circuit breaker on successful auth\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n } catch (error) {\n this.handleCircuitBreaker();\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 // Reset circuit breaker on successful refresh\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n } catch (error) {\n this.handleCircuitBreaker();\n throw new Error(`Token refresh failed: ${this.getErrorMessage(error)}`);\n }\n }\n\n private getErrorMessage(error: unknown): 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 as Error).message || 'Unknown error';\n }\n\n private handleCircuitBreaker(): void {\n this.circuitBreaker.failures++;\n this.circuitBreaker.lastFailureTime = Date.now();\n \n if (this.circuitBreaker.failures >= this.circuitBreaker.threshold) {\n this.circuitBreaker.isOpen = true;\n }\n }\n\n // Official Pathao API: Create Order\n async createOrder(orderData: PathaoOrderRequest): Promise<PathaoOrderResponse> {\n try {\n const response = await this.pathaoClient.post<PathaoOrderResponse>('/aladdin/api/v1/orders', orderData);\n return response.data;\n } catch (error: unknown) {\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<PathaoStoreCreateResponse> {\n try {\n const response = await this.pathaoClient.post<PathaoStoreCreateResponse>('/aladdin/api/v1/stores', storeData);\n return response.data;\n } catch (error: unknown) {\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<PathaoStoreListResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoStoreListResponse>('/aladdin/api/v1/stores');\n return response.data;\n } catch (error: unknown) {\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 const response = await this.pathaoClient.post<PathaoPriceResponse>('/aladdin/api/v1/merchant/price-plan', priceData);\n return response.data;\n } catch (error: unknown) {\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/city-list');\n return response.data;\n } catch (error: unknown) {\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to fetch Pathao cities: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Get Zones for a City\n async getZones(cityId: number): Promise<PathaoZoneResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoZoneResponse>(`/aladdin/api/v1/cities/${cityId}/zone-list`);\n return response.data;\n } catch (error: unknown) {\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to fetch Pathao zones: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Get Areas for a Zone\n async getAreas(zoneId: number): Promise<PathaoAreaResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoAreaResponse>(`/aladdin/api/v1/zones/${zoneId}/area-list`);\n return response.data;\n } catch (error: unknown) {\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}/info`);\n return response.data;\n } catch (error: unknown) {\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to fetch Pathao order status: ${errorMessage}`);\n }\n }\n\n // Official Pathao API: Create Bulk Order\n async createBulkOrder(\n orders: PathaoOrderRequest[],\n ): Promise<{ message: string; type: string; code: number; data: boolean }> {\n try {\n const response = await this.pathaoClient.post<{\n message: string;\n type: string;\n code: number;\n data: boolean;\n }>('/aladdin/api/v1/orders/bulk', { orders });\n return response.data;\n } catch (error: unknown) {\n const errorMessage = this.getErrorMessage(error);\n throw new Error(`Failed to create bulk Pathao orders: ${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 // Helper method to validate store name\n static validateStoreName(name: string): boolean {\n const trimmed = name.trim();\n return trimmed.length >= 3 && trimmed.length <= 50;\n }\n\n // Helper method to validate contact name\n static validateContactName(name: string): boolean {\n const trimmed = name.trim();\n return trimmed.length >= 3 && trimmed.length <= 50;\n }\n\n // Helper method to validate contact number\n static validateContactNumber(phone: string): boolean {\n const cleanPhone = phone.replace(/\\D/g, '');\n return cleanPhone.length === 11;\n }\n\n // Helper method to validate store address\n static validateStoreAddress(address: string): boolean {\n const trimmed = address.trim();\n return trimmed.length >= 15 && trimmed.length <= 120;\n }\n\n // Method to clear authentication state (useful for testing)\n clearAuth(): void {\n this.accessToken = null;\n this.refreshToken = null;\n this.tokenExpiry = null;\n this.isAuthenticating = false;\n this.authPromise = null;\n this.requestQueue = [];\n this.circuitBreaker = {\n failures: 0,\n lastFailureTime: 0,\n threshold: 5,\n timeout: 60000,\n isOpen: false,\n };\n }\n}\n","/**\n * Pathao Courier API Types\n * \n * Official API Details:\n * - Authentication: OAuth2 with client_id, client_secret, username, password\n * - All endpoints use /aladdin/api/v1/ prefix\n * - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config\n * - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config\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; // 3-50 characters\n contact_name: string; // 3-50 characters\n contact_number: string; // 11 characters\n secondary_contact?: string; // Optional - 11 characters\n otp_number?: string; // Optional - OTP for orders\n address: string; // 15-120 characters\n city_id: number;\n zone_id: number;\n area_id: number;\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 merchant_order_id: string;\n order_status: string;\n delivery_fee: number;\n };\n}\n\n// Official Pathao Store Creation Response\nexport interface PathaoStoreCreateResponse {\n type: string;\n code: number;\n message: string;\n data: {\n store_name: string; // Only store_name returned on creation\n };\n}\n\n// Official Pathao Store List Item (from GET /stores)\nexport interface PathaoStore {\n store_id: number;\n store_name: string;\n store_address: string;\n is_active: number; // 1 for active, 0 for deactivated\n city_id: number;\n zone_id: number;\n hub_id: number;\n is_default_store: boolean;\n is_default_return_store: boolean;\n}\n\n// Official Pathao Store List Response\nexport interface PathaoStoreListResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: PathaoStore[];\n total: number;\n current_page: number;\n per_page: number;\n total_in_page: number;\n last_page: number;\n path: string;\n to: number;\n from: number;\n last_page_url: string;\n first_page_url: 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}\n\n// Official Pathao Price Response\nexport interface PathaoPriceResponse {\n type: string;\n code: number;\n message: string;\n data: {\n price: number; // Calculated price for given item\n discount: number; // Discount for the given item\n promo_discount: number; // Promo discount for the given item\n plan_id: number; // Price plan id for the given item\n cod_enabled: number; // 1 if COD enabled, 0 if not\n cod_percentage: number; // Cash on delivery percentage\n additional_charge: number; // If there is any additional charge\n final_price: number; // Your final price for the given item\n };\n}\n\n// Official Pathao City Response\nexport interface PathaoCityResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n city_id: number;\n city_name: string;\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 merchant_order_id: string;\n order_status: string;\n order_status_slug: string;\n updated_at: string;\n invoice_id: string | null;\n };\n}\n\n// Official Pathao Zone Response\nexport interface PathaoZoneResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n zone_id: number;\n zone_name: string;\n }>;\n };\n}\n\n// Official Pathao Area Response\nexport interface PathaoAreaResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n area_id: number;\n area_name: string;\n home_delivery_available: boolean;\n pickup_available: boolean;\n }>;\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 (removed as not used in official API)\n// export 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"],"mappings":";;;AAsCO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EAQxC,WAAA,CAAY,OAAA,EAAiB,OAAA,GAOzB,EA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CAAA;AAAA,MACV,eAAA,EAAiB,CAAA;AAAA,MACjB,SAAA,EAAW,CAAA;AAAA,MACX,OAAA,EAAS,GAAA;AAAA,MACT,MAAA,EAAQ;AAAA,KACV;AAAA,EACF;AACF;;;AC5QO,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","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 * - All endpoints use /aladdin/api/v1/ prefix\n * - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config\n * - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config\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 PathaoStoreCreateResponse,\n PathaoStoreListResponse,\n PathaoStoreRequest,\n PathaoZoneResponse,\n} from './types';\n\nexport class PathaoApiError extends Error {\n status: number | undefined;\n code: number | undefined;\n type: string | undefined;\n errors: Record<string, string[]> | undefined;\n validation: Record<string, string[]> | undefined;\n responseData: unknown;\n\n constructor(message: string, options: {\n status?: number | undefined;\n code?: number | undefined;\n type?: string | undefined;\n errors?: Record<string, string[]> | undefined;\n validation?: Record<string, string[]> | undefined;\n responseData?: unknown;\n } = {}) {\n super(message);\n this.name = 'PathaoApiError';\n this.status = options.status;\n this.code = options.code;\n this.type = options.type;\n this.errors = options.errors;\n this.validation = options.validation;\n this.responseData = options.responseData;\n }\n}\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 private isAuthenticating: boolean = false;\n private authPromise: Promise<void> | null = null;\n private requestQueue: Array<{ resolve: () => void; reject: (error: Error) => void }> = [];\n private circuitBreaker = {\n failures: 0,\n lastFailureTime: 0,\n threshold: 5,\n timeout: 60000, // 1 minute\n isOpen: false,\n };\n\n constructor(config: PathaoConfig) {\n this.config = {\n baseURL: config.baseURL || process.env.PATHAO_BASE_URL || '',\n timeout: config.timeout || parseInt(process.env.PATHAO_TIMEOUT || '30000', 10),\n clientId: config.clientId || process.env.PATHAO_CLIENT_ID || '',\n clientSecret: config.clientSecret || process.env.PATHAO_CLIENT_SECRET || '',\n username: config.username || process.env.PATHAO_USERNAME || '',\n password: config.password || process.env.PATHAO_PASSWORD || '',\n };\n\n this.pathaoClient = axios.create({\n baseURL: this.config.baseURL || process.env.PATHAO_BASE_URL || '',\n timeout: this.config.timeout || parseInt(process.env.PATHAO_TIMEOUT || '30000', 10),\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': 'application/json',\n },\n });\n\n // Validate required configuration\n if (!this.config.baseURL) {\n throw new Error('Pathao API baseURL is required. You can provide it via constructor config or PATHAO_BASE_URL environment variable');\n }\n \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. You can provide them via constructor config or environment variables (PATHAO_CLIENT_ID, PATHAO_CLIENT_SECRET, PATHAO_USERNAME, PATHAO_PASSWORD)');\n }\n\n // Add request interceptor for authentication\n this.pathaoClient.interceptors.request.use(async (config) => {\n // Skip auth for token requests to prevent infinite loops\n if (config.url?.includes('/issue-token')) {\n return config;\n }\n \n await this.ensureAuthenticated();\n if (this.accessToken) {\n config.headers.Authorization = `Bearer ${this.accessToken}`;\n }\n return config;\n });\n\n // Add response interceptor for error handling\n this.pathaoClient.interceptors.response.use(\n (response) => {\n // Reset circuit breaker on successful request\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n return response;\n },\n async (error) => {\n if (error.response?.status === 401) {\n // Token expired, clear tokens and retry\n this.accessToken = null;\n this.refreshToken = null;\n this.tokenExpiry = null;\n \n // Retry the request once\n if (error.config && !error.config._retry) {\n error.config._retry = true;\n await this.ensureAuthenticated();\n if (this.accessToken) {\n error.config.headers.Authorization = `Bearer ${this.accessToken}`;\n }\n return this.pathaoClient.request(error.config);\n }\n }\n \n // Handle circuit breaker\n this.handleCircuitBreaker();\n return Promise.reject(error);\n },\n );\n }\n\n private async ensureAuthenticated(): Promise<void> {\n // Check circuit breaker\n if (this.circuitBreaker.isOpen) {\n if (Date.now() - this.circuitBreaker.lastFailureTime > this.circuitBreaker.timeout) {\n this.circuitBreaker.isOpen = false;\n this.circuitBreaker.failures = 0;\n } else {\n throw new Error('Circuit breaker is open. Too many authentication failures.');\n }\n }\n\n if (this.accessToken && this.tokenExpiry && Date.now() < this.tokenExpiry) {\n return; // Token is still valid\n }\n\n // If already authenticating, wait for it to complete\n if (this.isAuthenticating && this.authPromise) {\n return this.authPromise;\n }\n\n // Start authentication process\n this.isAuthenticating = true;\n this.authPromise = this.performAuthentication();\n\n try {\n await this.authPromise;\n } finally {\n this.isAuthenticating = false;\n this.authPromise = null;\n // Process queued requests\n this.processRequestQueue();\n }\n }\n\n private async performAuthentication(): Promise<void> {\n if (this.refreshToken) {\n try {\n await this.refreshAccessToken();\n return;\n } catch (error) {\n // Refresh failed, try fresh authentication\n this.refreshToken = null;\n }\n }\n\n await this.authenticate();\n }\n\n private processRequestQueue(): void {\n const queue = [...this.requestQueue];\n this.requestQueue = [];\n \n queue.forEach(({ resolve }) => {\n try {\n resolve();\n } catch (error) {\n // Ignore errors in queued requests\n }\n });\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 // Reset circuit breaker on successful auth\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n } catch (error) {\n this.handleCircuitBreaker();\n throw this.toPathaoApiError(error, 'Authentication failed');\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 // Reset circuit breaker on successful refresh\n this.circuitBreaker.failures = 0;\n this.circuitBreaker.isOpen = false;\n } catch (error) {\n this.handleCircuitBreaker();\n throw this.toPathaoApiError(error, 'Token refresh failed');\n }\n }\n\n private getErrorMessage(error: unknown): 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 as Error).message || 'Unknown error';\n }\n\n private toPathaoApiError(error: unknown, context: string): PathaoApiError {\n if (error instanceof PathaoApiError) {\n return error;\n }\n\n const messageFallback = this.getErrorMessage(error);\n const axiosLike = (error instanceof AxiosError) ? error : (typeof error === 'object' && error && 'response' in (error as any) ? error as AxiosError : null);\n if (axiosLike) {\n const pathaoError = axiosLike.response?.data as PathaoError | undefined;\n return new PathaoApiError(`${context}: ${pathaoError?.message || messageFallback}`, {\n status: axiosLike.response?.status,\n code: pathaoError?.code ?? axiosLike.response?.status,\n type: pathaoError?.type,\n errors: pathaoError?.errors,\n validation: pathaoError?.validation,\n responseData: pathaoError ?? axiosLike.response?.data,\n });\n }\n\n return new PathaoApiError(`${context}: ${messageFallback}`);\n }\n\n private handleCircuitBreaker(): void {\n this.circuitBreaker.failures++;\n this.circuitBreaker.lastFailureTime = Date.now();\n \n if (this.circuitBreaker.failures >= this.circuitBreaker.threshold) {\n this.circuitBreaker.isOpen = true;\n }\n }\n\n // Official Pathao API: Create Order\n async createOrder(orderData: PathaoOrderRequest): Promise<PathaoOrderResponse> {\n try {\n const response = await this.pathaoClient.post<PathaoOrderResponse>('/aladdin/api/v1/orders', orderData);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to create Pathao order');\n }\n }\n\n // Official Pathao API: Create Store\n async createStore(storeData: PathaoStoreRequest): Promise<PathaoStoreCreateResponse> {\n try {\n const response = await this.pathaoClient.post<PathaoStoreCreateResponse>('/aladdin/api/v1/stores', storeData);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to create Pathao store');\n }\n }\n\n // Official Pathao API: Get Store List\n async getStores(): Promise<PathaoStoreListResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoStoreListResponse>('/aladdin/api/v1/stores');\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to fetch Pathao stores');\n }\n }\n\n // Official Pathao API: Calculate Price\n async calculatePrice(priceData: PathaoPriceRequest): Promise<PathaoPriceResponse> {\n try {\n const response = await this.pathaoClient.post<PathaoPriceResponse>('/aladdin/api/v1/merchant/price-plan', priceData);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to calculate Pathao price');\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/city-list');\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to fetch Pathao cities');\n }\n }\n\n // Official Pathao API: Get Zones for a City\n async getZones(cityId: number): Promise<PathaoZoneResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoZoneResponse>(`/aladdin/api/v1/cities/${cityId}/zone-list`);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to fetch Pathao zones');\n }\n }\n\n // Official Pathao API: Get Areas for a Zone\n async getAreas(zoneId: number): Promise<PathaoAreaResponse> {\n try {\n const response = await this.pathaoClient.get<PathaoAreaResponse>(`/aladdin/api/v1/zones/${zoneId}/area-list`);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to fetch Pathao areas');\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}/info`);\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to fetch Pathao order status');\n }\n }\n\n // Official Pathao API: Create Bulk Order\n async createBulkOrder(\n orders: PathaoOrderRequest[],\n ): Promise<{ message: string; type: string; code: number; data: boolean }> {\n try {\n const response = await this.pathaoClient.post<{\n message: string;\n type: string;\n code: number;\n data: boolean;\n }>('/aladdin/api/v1/orders/bulk', { orders });\n return response.data;\n } catch (error: unknown) {\n throw this.toPathaoApiError(error, 'Failed to create bulk Pathao orders');\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 // Helper method to validate store name\n static validateStoreName(name: string): boolean {\n const trimmed = name.trim();\n return trimmed.length >= 3 && trimmed.length <= 50;\n }\n\n // Helper method to validate contact name\n static validateContactName(name: string): boolean {\n const trimmed = name.trim();\n return trimmed.length >= 3 && trimmed.length <= 50;\n }\n\n // Helper method to validate contact number\n static validateContactNumber(phone: string): boolean {\n const cleanPhone = phone.replace(/\\D/g, '');\n return cleanPhone.length === 11;\n }\n\n // Helper method to validate store address\n static validateStoreAddress(address: string): boolean {\n const trimmed = address.trim();\n return trimmed.length >= 15 && trimmed.length <= 120;\n }\n\n // Method to clear authentication state (useful for testing)\n clearAuth(): void {\n this.accessToken = null;\n this.refreshToken = null;\n this.tokenExpiry = null;\n this.isAuthenticating = false;\n this.authPromise = null;\n this.requestQueue = [];\n this.circuitBreaker = {\n failures: 0,\n lastFailureTime: 0,\n threshold: 5,\n timeout: 60000,\n isOpen: false,\n };\n }\n}\n","/**\n * Pathao Courier API Types\n * \n * Official API Details:\n * - Authentication: OAuth2 with client_id, client_secret, username, password\n * - All endpoints use /aladdin/api/v1/ prefix\n * - Base URL can be set via PATHAO_BASE_URL environment variable or constructor config\n * - Timeout can be set via PATHAO_TIMEOUT environment variable or constructor config\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; // 3-50 characters\n contact_name: string; // 3-50 characters\n contact_number: string; // 11 characters\n secondary_contact?: string; // Optional - 11 characters\n otp_number?: string; // Optional - OTP for orders\n address: string; // 15-120 characters\n city_id: number;\n zone_id: number;\n area_id: number;\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 merchant_order_id: string;\n order_status: string;\n delivery_fee: number;\n };\n}\n\n// Official Pathao Store Creation Response\nexport interface PathaoStoreCreateResponse {\n type: string;\n code: number;\n message: string;\n data: {\n store_name: string; // Only store_name returned on creation\n };\n}\n\n// Official Pathao Store List Item (from GET /stores)\nexport interface PathaoStore {\n store_id: number;\n store_name: string;\n store_address: string;\n is_active: number; // 1 for active, 0 for deactivated\n city_id: number;\n zone_id: number;\n hub_id: number;\n is_default_store: boolean;\n is_default_return_store: boolean;\n}\n\n// Official Pathao Store List Response\nexport interface PathaoStoreListResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: PathaoStore[];\n total: number;\n current_page: number;\n per_page: number;\n total_in_page: number;\n last_page: number;\n path: string;\n to: number;\n from: number;\n last_page_url: string;\n first_page_url: 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}\n\n// Official Pathao Price Response\nexport interface PathaoPriceResponse {\n type: string;\n code: number;\n message: string;\n data: {\n price: number; // Calculated price for given item\n discount: number; // Discount for the given item\n promo_discount: number; // Promo discount for the given item\n plan_id: number; // Price plan id for the given item\n cod_enabled: number; // 1 if COD enabled, 0 if not\n cod_percentage: number; // Cash on delivery percentage\n additional_charge: number; // If there is any additional charge\n final_price: number; // Your final price for the given item\n };\n}\n\n// Official Pathao City Response\nexport interface PathaoCityResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n city_id: number;\n city_name: string;\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 merchant_order_id: string;\n order_status: string;\n order_status_slug: string;\n updated_at: string;\n invoice_id: string | null;\n };\n}\n\n// Official Pathao Zone Response\nexport interface PathaoZoneResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n zone_id: number;\n zone_name: string;\n }>;\n };\n}\n\n// Official Pathao Area Response\nexport interface PathaoAreaResponse {\n type: string;\n code: number;\n message: string;\n data: {\n data: Array<{\n area_id: number;\n area_name: string;\n home_delivery_available: boolean;\n pickup_available: boolean;\n }>;\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 (removed as not used in official API)\n// export enum StoreType {\n// PICKUP_POINT = 1,\n// SERVICE_POINT = 2\n// }\n"]}
|