pathao-merchant-sdk 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,75 @@
1
+ ## [1.3.0] - 2025-12-04
2
+
3
+ ### ✨ New Features
4
+ - b4fa591 feat: enhance Pathao API SDK with environment variable support and improved error handling
5
+
6
+
7
+ # Changelog
8
+
9
+ All notable changes to this project will be documented in this file.
10
+
11
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
12
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
13
+
14
+ ## [Unreleased]
15
+
16
+ ## [1.2.0] - 2024-12-05
17
+
18
+ ### Fixed
19
+ - Fixed `PathaoPriceRequest` type - removed incorrect `recipient_area` field
20
+ - Split store response types into `PathaoStoreCreateResponse` and `PathaoStoreListResponse`
21
+ - Updated README examples to match official API response structures
22
+ - Removed deprecated `StoreType` enum references
23
+
24
+ ### Changed
25
+ - Enhanced package.json with ESM exports field and sideEffects flag
26
+ - Improved npm package structure with .npmignore
27
+ - Added CONTRIBUTING.md for contributors
28
+ - Reorganized documentation files into docs/ folder
29
+
30
+ ### Verified
31
+ - All endpoints tested against official Pathao sandbox API
32
+ - Type definitions verified against actual API responses
33
+
34
+ ## [1.1.0] - 2024-10-01
35
+
36
+ ### Added
37
+ - Comprehensive CI/CD pipeline and automatic release management
38
+
39
+ ## [1.0.0] - 2024-10-01
40
+
41
+ ### Added
42
+ - Initial release of Pathao Merchant API SDK
43
+ - Full TypeScript support with complete type definitions
44
+ - Automatic OAuth2 authentication and token refresh
45
+ - Order management (create, track, status)
46
+ - Store management (create, list stores)
47
+ - Price calculation for delivery charges
48
+ - Location services (cities, zones, areas)
49
+ - Comprehensive error handling
50
+ - Built-in validation helpers
51
+ - Support for both CommonJS and ESM
52
+ - Extensive documentation and examples
53
+
54
+ ### Features
55
+ - 🚀 Full TypeScript Support
56
+ - 🔐 Automatic Authentication
57
+ - 📦 Order Management
58
+ - 🏪 Store Management
59
+ - 💰 Price Calculation
60
+ - 🌍 Location Services
61
+ - ⚡ Built with Axios
62
+ - 🛡️ Error Handling
63
+ - 📚 Well Documented
64
+
65
+ ## [1.0.0] - 2025-01-01
66
+
67
+ ### Added
68
+ - Initial release
69
+ - Complete Pathao API integration
70
+ - TypeScript support
71
+ - Automatic authentication
72
+ - Order management
73
+ - Store management
74
+ - Price calculation
75
+ - Location services
@@ -0,0 +1,187 @@
1
+ # Contributing to Pathao Merchant SDK
2
+
3
+ Thank you for your interest in contributing to the Pathao Merchant SDK! This document provides guidelines for contributing to the project.
4
+
5
+ ## Getting Started
6
+
7
+ 1. **Fork the repository** on GitHub
8
+ 2. **Clone your fork** locally:
9
+ ```bash
10
+ git clone https://github.com/YOUR_USERNAME/pathao-merchant-sdk.git
11
+ cd pathao-merchant-sdk
12
+ ```
13
+ 3. **Install dependencies**:
14
+ ```bash
15
+ npm install
16
+ # or
17
+ pnpm install
18
+ ```
19
+
20
+ ## Development Workflow
21
+
22
+ ### 1. Create a Branch
23
+
24
+ ```bash
25
+ git checkout -b feature/your-feature-name
26
+ # or
27
+ git checkout -b fix/your-bug-fix
28
+ ```
29
+
30
+ ### 2. Make Your Changes
31
+
32
+ - Write clean, readable code
33
+ - Follow the existing code style
34
+ - Add tests for new features
35
+ - Update documentation as needed
36
+
37
+ ### 3. Run Tests
38
+
39
+ ```bash
40
+ npm test
41
+ npm run build
42
+ npm run type-check
43
+ ```
44
+
45
+ ### 4. Commit Your Changes
46
+
47
+ Use conventional commit messages:
48
+
49
+ ```bash
50
+ # For new features
51
+ git commit -m "feat: add support for webhook notifications"
52
+
53
+ # For bug fixes
54
+ git commit -m "fix: resolve token refresh issue"
55
+
56
+ # For documentation
57
+ git commit -m "docs: update API examples"
58
+
59
+ # For refactoring
60
+ git commit -m "refactor: improve error handling"
61
+ ```
62
+
63
+ ### 5. Push and Create Pull Request
64
+
65
+ ```bash
66
+ git push origin feature/your-feature-name
67
+ ```
68
+
69
+ Then create a Pull Request on GitHub.
70
+
71
+ ## Code Style
72
+
73
+ - Use TypeScript for all new code
74
+ - Follow existing code formatting (we use ESLint)
75
+ - Write meaningful variable and function names
76
+ - Add JSDoc comments for public APIs
77
+ - Keep functions small and focused
78
+
79
+ ## Testing
80
+
81
+ - Write unit tests for all new features
82
+ - Ensure all tests pass before submitting PR
83
+ - Aim for high test coverage
84
+ - Test against the sandbox API when possible
85
+
86
+ ## Documentation
87
+
88
+ - Update README.md if you change functionality
89
+ - Add JSDoc comments to new functions/methods
90
+ - Update CHANGELOG.md following [Keep a Changelog](https://keepachangelog.com/) format
91
+ - Include examples for new features
92
+
93
+ ## Pull Request Guidelines
94
+
95
+ ### Before Submitting
96
+
97
+ - [ ] All tests pass
98
+ - [ ] Code builds without errors
99
+ - [ ] Documentation is updated
100
+ - [ ] Commit messages follow convention
101
+ - [ ] No console.log or debugging code
102
+ - [ ] Code is formatted properly
103
+
104
+ ### PR Description Should Include
105
+
106
+ 1. **What** - What does this PR do?
107
+ 2. **Why** - Why is this change needed?
108
+ 3. **How** - How does it work?
109
+ 4. **Testing** - How was it tested?
110
+
111
+ ### Example PR Template
112
+
113
+ ```markdown
114
+ ## Description
115
+ Brief description of changes
116
+
117
+ ## Type of Change
118
+ - [ ] Bug fix
119
+ - [ ] New feature
120
+ - [ ] Breaking change
121
+ - [ ] Documentation update
122
+
123
+ ## Testing
124
+ - [ ] Unit tests added/updated
125
+ - [ ] Tested against sandbox API
126
+ - [ ] Manual testing performed
127
+
128
+ ## Checklist
129
+ - [ ] Code follows project style
130
+ - [ ] Documentation updated
131
+ - [ ] Tests pass
132
+ - [ ] CHANGELOG.md updated
133
+ ```
134
+
135
+ ## Reporting Bugs
136
+
137
+ ### Before Creating an Issue
138
+
139
+ 1. **Check existing issues** - Maybe it's already reported
140
+ 2. **Test with latest version** - Update to the latest release
141
+ 3. **Check documentation** - Ensure you're using the API correctly
142
+
143
+ ### Bug Report Template
144
+
145
+ ```markdown
146
+ **Description**
147
+ Clear description of the bug
148
+
149
+ **To Reproduce**
150
+ Steps to reproduce:
151
+ 1. Initialize SDK with...
152
+ 2. Call method...
153
+ 3. See error
154
+
155
+ **Expected Behavior**
156
+ What should happen
157
+
158
+ **Actual Behavior**
159
+ What actually happens
160
+
161
+ **Environment**
162
+ - SDK Version: 1.2.0
163
+ - Node Version: 18.0.0
164
+ - OS: macOS/Windows/Linux
165
+ ```
166
+
167
+ ## Feature Requests
168
+
169
+ We welcome feature requests! Please include:
170
+
171
+ 1. **Use Case** - Why do you need this feature?
172
+ 2. **Proposed Solution** - How do you envision it working?
173
+ 3. **Alternatives** - What alternatives have you considered?
174
+
175
+ ## Questions?
176
+
177
+ - Open a [GitHub Discussion](https://github.com/sifat07/pathao-merchant-sdk/discussions)
178
+ - Check existing [Issues](https://github.com/sifat07/pathao-merchant-sdk/issues)
179
+ - Email: sifatjasim@gmail.com
180
+
181
+ ## License
182
+
183
+ By contributing, you agree that your contributions will be licensed under the MIT License.
184
+
185
+ ## Code of Conduct
186
+
187
+ Be respectful and constructive in all interactions. We're here to build something useful together! 🚀
package/README.md CHANGED
@@ -1,16 +1,34 @@
1
1
  # Pathao Merchant API SDK
2
2
 
3
- [![npm version](https://badge.fury.io/js/pathao-merchant-sdk.svg)](https://badge.fury.io/js/pathao-merchant-sdk)
3
+ [![npm version](https://img.shields.io/npm/v/pathao-merchant-sdk.svg)](https://www.npmjs.com/package/pathao-merchant-sdk)
4
+ [![npm downloads](https://img.shields.io/npm/dm/pathao-merchant-sdk.svg)](https://www.npmjs.com/package/pathao-merchant-sdk)
4
5
  [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
5
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/sifat07/pathao-merchant-sdk/ci.yml?branch=main)](https://github.com/sifat07/pathao-merchant-sdk/actions)
6
8
 
7
9
  An **unofficial** TypeScript SDK for integrating with the Pathao Merchant API. This community package provides a clean, type-safe interface for all Pathao Merchant API operations including order management, store management, price calculation, and more.
8
10
 
9
- [![npm package](https://img.shields.io/npm/v/pathao-merchant-sdk?style=flat-square)](https://www.npmjs.com/package/pathao-merchant-sdk)
10
- [![npm downloads](https://img.shields.io/npm/dm/pathao-merchant-sdk?style=flat-square)](https://www.npmjs.com/package/pathao-merchant-sdk)
11
-
12
11
  > **Disclaimer**: This is not an official package from Pathao. It's a community-maintained SDK based on the public Pathao Merchant API documentation.
13
12
 
13
+ ## Table of Contents
14
+ - [Features](#features)
15
+ - [Requirements](#requirements)
16
+ - [Installation](#installation)
17
+ - [Quick Start](#quick-start)
18
+ - [Configuration](#configuration)
19
+ - [Environment Variables](#environment-variables)
20
+ - [What You Can Do](#what-you-can-do)
21
+ - [API Reference](#api-reference)
22
+ - [Examples](#examples)
23
+ - [Error Handling](#error-handling)
24
+ - [Authentication](#authentication)
25
+ - [Official Documentation](#official-documentation)
26
+ - [Contributing](#contributing)
27
+ - [Development](#development)
28
+ - [License](#license)
29
+ - [Support](#support)
30
+ - [Changelog](#changelog)
31
+
14
32
  ## Features
15
33
 
16
34
  - 🚀 **Full TypeScript Support** - Complete type definitions for all API responses
@@ -23,6 +41,11 @@ An **unofficial** TypeScript SDK for integrating with the Pathao Merchant API. T
23
41
  - 🛡️ **Error Handling** - Comprehensive error handling with detailed error messages
24
42
  - 📚 **Well Documented** - Extensive documentation and examples
25
43
 
44
+ ## Requirements
45
+
46
+ - Node.js >= 18 (see `engines` in `package.json`)
47
+ - TypeScript >= 4.9 (peer dependency; repository uses 5.x)
48
+
26
49
  ## Installation
27
50
 
28
51
  ```bash
@@ -40,6 +63,7 @@ import { PathaoApiService, DeliveryType, ItemType } from 'pathao-merchant-sdk';
40
63
 
41
64
  // Initialize the SDK
42
65
  const pathao = new PathaoApiService({
66
+ baseURL: 'https://api-hermes.pathao.com', // or use PATHAO_BASE_URL env var
43
67
  clientId: 'your-client-id',
44
68
  clientSecret: 'your-client-secret',
45
69
  username: 'your-username',
@@ -62,6 +86,44 @@ const order = await pathao.createOrder({
62
86
  console.log('Order created:', order.data.consignment_id);
63
87
  ```
64
88
 
89
+ ## Environment Variables
90
+
91
+ Copy `env.example` to `.env` and fill in your credentials. If your runtime does not auto-load environment files, install and load `dotenv`:
92
+
93
+ ```bash
94
+ cp env.example .env
95
+ npm install dotenv --save-dev # or yarn add -D dotenv / pnpm add -D dotenv
96
+ ```
97
+
98
+ ```typescript
99
+ import 'dotenv/config';
100
+ ```
101
+
102
+ Required and optional variables:
103
+
104
+ ```env
105
+ # Base URL (choose one)
106
+ PATHAO_BASE_URL=https://courier-api-sandbox.pathao.com # sandbox
107
+ # PATHAO_BASE_URL=https://api-hermes.pathao.com # production
108
+
109
+ # Authentication (required)
110
+ PATHAO_CLIENT_ID=your-client-id
111
+ PATHAO_CLIENT_SECRET=your-client-secret
112
+ PATHAO_USERNAME=your-username
113
+ PATHAO_PASSWORD=your-password
114
+
115
+ # Optional
116
+ PATHAO_TIMEOUT=30000
117
+ ```
118
+
119
+ ## What You Can Do
120
+
121
+ - Create, price, and track delivery orders
122
+ - Manage stores (pickup/service points)
123
+ - Look up cities, zones, and areas
124
+ - Validate phone, address, weight, and recipient inputs
125
+ - Automatically handle OAuth2 authentication and token refresh
126
+
65
127
  ## API Reference
66
128
 
67
129
  ### Configuration
@@ -72,11 +134,36 @@ interface PathaoConfig {
72
134
  clientSecret: string; // Your Pathao API client secret
73
135
  username: string; // Your Pathao API username
74
136
  password: string; // Your Pathao API password
75
- baseURL?: string; // API base URL (default: https://api-hermes.pathao.com)
137
+ baseURL: string; // API base URL (required)
76
138
  timeout?: number; // Request timeout in ms (default: 30000)
77
139
  }
78
140
  ```
79
141
 
142
+ #### Environment Variables
143
+
144
+ The SDK automatically reads the variables listed in the [Environment Variables](#environment-variables) section when present, and falls back to the values you pass in the config.
145
+
146
+ ```typescript
147
+ // Option 1: All from environment variables
148
+ const pathao = new PathaoApiService({});
149
+
150
+ // Option 2: Mix of config and environment variables
151
+ const pathao = new PathaoApiService({
152
+ baseURL: 'https://api-hermes.pathao.com', // This overrides PATHAO_BASE_URL
153
+ clientId: 'your-client-id', // This overrides PATHAO_CLIENT_ID
154
+ // Other credentials will be taken from environment variables
155
+ });
156
+
157
+ // Option 3: All from config (environment variables as fallback)
158
+ const pathao = new PathaoApiService({
159
+ baseURL: process.env.PATHAO_BASE_URL || 'https://api-hermes.pathao.com',
160
+ clientId: process.env.PATHAO_CLIENT_ID || 'your-client-id',
161
+ clientSecret: process.env.PATHAO_CLIENT_SECRET || 'your-client-secret',
162
+ username: process.env.PATHAO_USERNAME || 'your-username',
163
+ password: process.env.PATHAO_PASSWORD || 'your-password',
164
+ });
165
+ ```
166
+
80
167
  ### Order Management
81
168
 
82
169
  #### Create Order
@@ -106,7 +193,7 @@ const order = await pathao.createOrder({
106
193
 
107
194
  ```typescript
108
195
  const status = await pathao.getOrderStatus('consignment-id');
109
- console.log('Order status:', status.data.status);
196
+ console.log('Order status:', status.data.order_status);
110
197
  ```
111
198
 
112
199
  ### Store Management
@@ -121,8 +208,7 @@ const store = await pathao.createStore({
121
208
  address: '123 Store Street, Dhanmondi',
122
209
  city_id: 1,
123
210
  zone_id: 1,
124
- area_id: 1,
125
- store_type: StoreType.PICKUP_POINT // 1 for Pickup Point, 2 for Service Point
211
+ area_id: 1
126
212
  });
127
213
  ```
128
214
 
@@ -130,7 +216,7 @@ const store = await pathao.createStore({
130
216
 
131
217
  ```typescript
132
218
  const stores = await pathao.getStores();
133
- console.log('Available stores:', stores);
219
+ console.log('Available stores:', stores.data.data);
134
220
  ```
135
221
 
136
222
  ### Price Calculation
@@ -142,13 +228,12 @@ const price = await pathao.calculatePrice({
142
228
  item_weight: 1.0,
143
229
  delivery_type: DeliveryType.NORMAL,
144
230
  recipient_city: 1,
145
- recipient_zone: 1,
146
- recipient_area: 1
231
+ recipient_zone: 1
147
232
  });
148
233
 
149
- console.log('Delivery charge:', price.data.delivery_charge);
150
- console.log('COD charge:', price.data.cod_charge);
151
- console.log('Total charge:', price.data.total_charge);
234
+ console.log('Price:', price.data.price);
235
+ console.log('Final price:', price.data.final_price);
236
+ console.log('COD percentage:', price.data.cod_percentage);
152
237
  ```
153
238
 
154
239
  ### Location Services
@@ -210,15 +295,6 @@ enum ItemType {
210
295
  }
211
296
  ```
212
297
 
213
- ### StoreType
214
-
215
- ```typescript
216
- enum StoreType {
217
- PICKUP_POINT = 1, // Pickup Point
218
- SERVICE_POINT = 2 // Service Point
219
- }
220
- ```
221
-
222
298
  ## Error Handling
223
299
 
224
300
  The SDK provides comprehensive error handling with detailed error messages:
@@ -249,17 +325,6 @@ const pathao = new PathaoApiService({
249
325
  });
250
326
  ```
251
327
 
252
- ## Environment Variables
253
-
254
- Create a `.env` file with your Pathao API credentials:
255
-
256
- ```env
257
- PATHAO_CLIENT_ID=your-client-id
258
- PATHAO_CLIENT_SECRET=your-client-secret
259
- PATHAO_USERNAME=your-username
260
- PATHAO_PASSWORD=your-password
261
- ```
262
-
263
328
  ## Examples
264
329
 
265
330
  ### Complete Order Flow
@@ -319,10 +384,25 @@ async function createDeliveryOrder() {
319
384
  }
320
385
  ```
321
386
 
387
+ ## Official Documentation
388
+
389
+ This SDK is based on the official Pathao Courier Merchant API documentation. For complete API reference and details:
390
+
391
+ - **[Official API Documentation](./docs/official-pathao-api-documentation.md)** - Complete Pathao API guide
392
+ - **[API Reference](./docs/pathao-api-reference.txt)** - Original API reference document
393
+ - **[Pathao Merchant Portal](https://merchant.pathao.com)** - Official merchant dashboard
394
+
322
395
  ## Contributing
323
396
 
324
397
  Contributions are welcome! Please feel free to submit a Pull Request.
325
398
 
399
+ ## Development
400
+
401
+ - Build: `npm run build`
402
+ - Tests: `npm test`
403
+ - Lint: `npm run lint`
404
+ - Type check: `npm run type-check`
405
+
326
406
  ## License
327
407
 
328
408
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.