@buiducnhat/ritel-sdk 0.2.0 → 0.2.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/README.md +111 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
# @ritel
|
|
1
|
+
# @buiducnhat/ritel-sdk
|
|
2
2
|
|
|
3
3
|
TypeScript SDK for Ritel Mini ERP external APIs.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @ritel
|
|
8
|
+
npm install @buiducnhat/ritel-sdk
|
|
9
9
|
# or
|
|
10
|
-
bun add @ritel
|
|
10
|
+
bun add @buiducnhat/ritel-sdk
|
|
11
11
|
# or
|
|
12
|
-
pnpm add @ritel
|
|
12
|
+
pnpm add @buiducnhat/ritel-sdk
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Quick Start
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
|
-
import { RitelClient } from "@ritel
|
|
18
|
+
import { RitelClient } from "@buiducnhat/ritel-sdk";
|
|
19
19
|
|
|
20
20
|
const client = new RitelClient({
|
|
21
21
|
baseUrl: "https://your-ritel-server.com",
|
|
@@ -32,9 +32,7 @@ const products = await client.products.list({
|
|
|
32
32
|
const order = await client.orders.create({
|
|
33
33
|
customerName: "John Doe",
|
|
34
34
|
customerPhone: "+84901234567",
|
|
35
|
-
items: [
|
|
36
|
-
{ productId: "prod_123", quantity: 2, unitPrice: 50000 },
|
|
37
|
-
],
|
|
35
|
+
items: [{ productId: "prod_123", quantity: 2, unitPrice: 50000 }],
|
|
38
36
|
paymentMethod: "bank_transfer",
|
|
39
37
|
});
|
|
40
38
|
|
|
@@ -79,6 +77,57 @@ const response = await client.products.list({
|
|
|
79
77
|
}
|
|
80
78
|
```
|
|
81
79
|
|
|
80
|
+
#### `client.products.get(id)`
|
|
81
|
+
|
|
82
|
+
Get a single product by ID.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const product = await client.products.get("prod_123");
|
|
86
|
+
|
|
87
|
+
// Product interface
|
|
88
|
+
{
|
|
89
|
+
id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
sku: string | null;
|
|
92
|
+
salePrice: number;
|
|
93
|
+
currentSalePrice: number | null; // Discounted price if applicable
|
|
94
|
+
imageUrl: string | null;
|
|
95
|
+
description: string | null;
|
|
96
|
+
unit: string | null; // e.g., "pcs", "kg"
|
|
97
|
+
category: { id: string; name: string } | null;
|
|
98
|
+
customProperties: Record<string, unknown> | null;
|
|
99
|
+
stockQuantity: number;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Categories
|
|
104
|
+
|
|
105
|
+
#### `client.categories.list(params?)`
|
|
106
|
+
|
|
107
|
+
List product categories with optional filters.
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const response = await client.categories.list({
|
|
111
|
+
limit: 20, // Pagination limit
|
|
112
|
+
offset: 0, // Pagination offset
|
|
113
|
+
search: "cloth", // Search by name
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Response
|
|
117
|
+
{
|
|
118
|
+
data: Category[],
|
|
119
|
+
pagination: { total, limit, offset, hasMore }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Category interface
|
|
123
|
+
{
|
|
124
|
+
id: string;
|
|
125
|
+
name: string;
|
|
126
|
+
slug: string;
|
|
127
|
+
description: string | null;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
82
131
|
### Orders
|
|
83
132
|
|
|
84
133
|
#### `client.orders.create(input)`
|
|
@@ -99,7 +148,20 @@ const order = await client.orders.create({
|
|
|
99
148
|
expectedDeliveryDate: "2024-01-20", // Optional
|
|
100
149
|
});
|
|
101
150
|
|
|
102
|
-
// Response includes vietQrUrl for bank_transfer
|
|
151
|
+
// Response includes vietQrUrl and bankInfo for bank_transfer
|
|
152
|
+
{
|
|
153
|
+
id: string;
|
|
154
|
+
orderNumber: string;
|
|
155
|
+
total: number;
|
|
156
|
+
paymentMethod: string;
|
|
157
|
+
paymentStatus: string;
|
|
158
|
+
vietQrUrl: string | null; // QR code URL for payment
|
|
159
|
+
bankInfo: { // Bank details for manual transfer
|
|
160
|
+
bankBin: string | null;
|
|
161
|
+
bankAccountNumber: string | null;
|
|
162
|
+
bankAccountName: string | null;
|
|
163
|
+
} | null;
|
|
164
|
+
}
|
|
103
165
|
```
|
|
104
166
|
|
|
105
167
|
#### `client.orders.list(params?)`
|
|
@@ -110,9 +172,9 @@ List orders with optional filters.
|
|
|
110
172
|
const response = await client.orders.list({
|
|
111
173
|
limit: 20,
|
|
112
174
|
offset: 0,
|
|
113
|
-
status: "pending",
|
|
175
|
+
status: "pending", // "pending" | "completed" | "cancelled"
|
|
114
176
|
paymentStatus: "pending", // "pending" | "paid" | "failed"
|
|
115
|
-
orderNumber: "ORD-001",
|
|
177
|
+
orderNumber: "ORD-001", // Exact match
|
|
116
178
|
});
|
|
117
179
|
```
|
|
118
180
|
|
|
@@ -150,7 +212,11 @@ const order = await client.orders.cancel("order_abc123");
|
|
|
150
212
|
## Error Handling
|
|
151
213
|
|
|
152
214
|
```typescript
|
|
153
|
-
import {
|
|
215
|
+
import {
|
|
216
|
+
RitelApiError,
|
|
217
|
+
RitelNetworkError,
|
|
218
|
+
RitelError,
|
|
219
|
+
} from "@buiducnhat/ritel-sdk";
|
|
154
220
|
|
|
155
221
|
try {
|
|
156
222
|
await client.orders.create(input);
|
|
@@ -172,12 +238,42 @@ All types are exported:
|
|
|
172
238
|
|
|
173
239
|
```typescript
|
|
174
240
|
import type {
|
|
241
|
+
// Client config
|
|
242
|
+
RitelClientConfig,
|
|
243
|
+
|
|
244
|
+
// Products
|
|
175
245
|
Product,
|
|
246
|
+
ProductCategory,
|
|
247
|
+
GetProductsParams,
|
|
248
|
+
ProductsListResponse,
|
|
249
|
+
|
|
250
|
+
// Categories
|
|
251
|
+
Category,
|
|
252
|
+
GetCategoriesParams,
|
|
253
|
+
CategoriesListResponse,
|
|
254
|
+
|
|
255
|
+
// Orders
|
|
176
256
|
Order,
|
|
257
|
+
OrderItem,
|
|
258
|
+
OrderItemInput,
|
|
177
259
|
CreateOrderInput,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
260
|
+
UpdateOrderInput,
|
|
261
|
+
ListOrdersParams,
|
|
262
|
+
OrderCreateResponse,
|
|
263
|
+
OrdersListResponse,
|
|
264
|
+
DeliveryInfo,
|
|
265
|
+
|
|
266
|
+
// Common
|
|
267
|
+
Pagination,
|
|
268
|
+
ApiErrorResponse,
|
|
269
|
+
} from "@buiducnhat/ritel-sdk";
|
|
270
|
+
|
|
271
|
+
// Resource classes (for advanced usage)
|
|
272
|
+
import {
|
|
273
|
+
ProductsResource,
|
|
274
|
+
CategoriesResource,
|
|
275
|
+
OrdersResource,
|
|
276
|
+
} from "@buiducnhat/ritel-sdk";
|
|
181
277
|
```
|
|
182
278
|
|
|
183
279
|
## License
|