@sales-planner/http-client 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -363
- package/dist/clients/api-keys-client.d.ts +3 -3
- package/dist/clients/api-keys-client.d.ts.map +1 -1
- package/dist/clients/api-keys-client.js +3 -3
- package/dist/clients/brands-client.d.ts +18 -16
- package/dist/clients/brands-client.d.ts.map +1 -1
- package/dist/clients/brands-client.js +4 -37
- package/dist/clients/categories-client.d.ts +18 -16
- package/dist/clients/categories-client.d.ts.map +1 -1
- package/dist/clients/categories-client.js +4 -38
- package/dist/clients/coded-entity-client.d.ts +30 -0
- package/dist/clients/coded-entity-client.d.ts.map +1 -0
- package/dist/clients/coded-entity-client.js +60 -0
- package/dist/clients/crud-client.d.ts +14 -0
- package/dist/clients/crud-client.d.ts.map +1 -0
- package/dist/clients/crud-client.js +26 -0
- package/dist/clients/groups-client.d.ts +18 -16
- package/dist/clients/groups-client.d.ts.map +1 -1
- package/dist/clients/groups-client.js +4 -38
- package/dist/clients/marketplaces-client.d.ts +18 -16
- package/dist/clients/marketplaces-client.d.ts.map +1 -1
- package/dist/clients/marketplaces-client.js +4 -37
- package/dist/clients/roles-client.d.ts +6 -6
- package/dist/clients/sales-history-client.d.ts +29 -13
- package/dist/clients/sales-history-client.d.ts.map +1 -1
- package/dist/clients/sales-history-client.js +5 -5
- package/dist/clients/sales-planner-client.d.ts +12 -16
- package/dist/clients/sales-planner-client.d.ts.map +1 -1
- package/dist/clients/sales-planner-client.js +12 -17
- package/dist/clients/shop-scoped-client.d.ts +30 -0
- package/dist/clients/shop-scoped-client.d.ts.map +1 -0
- package/dist/clients/shop-scoped-client.js +58 -0
- package/dist/clients/shops-client.d.ts +6 -6
- package/dist/clients/shops-client.d.ts.map +1 -1
- package/dist/clients/shops-client.js +6 -6
- package/dist/clients/skus-client.d.ts +7 -7
- package/dist/clients/skus-client.d.ts.map +1 -1
- package/dist/clients/skus-client.js +7 -7
- package/dist/clients/statuses-client.d.ts +18 -16
- package/dist/clients/statuses-client.d.ts.map +1 -1
- package/dist/clients/statuses-client.js +4 -38
- package/dist/clients/suppliers-client.d.ts +18 -16
- package/dist/clients/suppliers-client.d.ts.map +1 -1
- package/dist/clients/suppliers-client.js +4 -37
- package/dist/clients/tenants-client.d.ts +6 -6
- package/dist/clients/tenants-client.d.ts.map +1 -1
- package/dist/clients/tenants-client.js +6 -6
- package/dist/clients/user-roles-client.d.ts +4 -4
- package/dist/clients/user-roles-client.d.ts.map +1 -1
- package/dist/clients/user-roles-client.js +4 -4
- package/dist/clients/users-client.d.ts +4 -4
- package/dist/clients/users-client.d.ts.map +1 -1
- package/dist/clients/users-client.js +4 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,411 +8,92 @@ TypeScript HTTP client for the Sales Planner API with full type safety.
|
|
|
8
8
|
pnpm add @sales-planner/http-client
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
### Quick Start
|
|
11
|
+
## Quick Start
|
|
14
12
|
|
|
15
13
|
```typescript
|
|
16
|
-
import { SalesPlannerClient } from '@sales-planner/http-client';
|
|
14
|
+
import { SalesPlannerClient, ApiError } from '@sales-planner/http-client';
|
|
17
15
|
|
|
18
16
|
const client = new SalesPlannerClient({
|
|
19
17
|
baseUrl: 'https://sales-planner-back.vercel.app',
|
|
20
18
|
apiKey: 'your-api-key',
|
|
21
19
|
});
|
|
22
20
|
|
|
23
|
-
// Check if API is healthy
|
|
24
|
-
const health = await client.getHealth();
|
|
25
|
-
console.log(health); // { status: 'ok', version: '1.0.0' }
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### Shop Context
|
|
29
|
-
|
|
30
|
-
Most operations require a shop context (`ctx`) as the **first argument**:
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
21
|
const ctx = { tenant_id: 1, shop_id: 1 };
|
|
34
22
|
|
|
35
|
-
//
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const brand = await client.brands.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Access resources through domain-specific sub-clients:
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
// Users (system-level, no ctx)
|
|
47
|
-
const users = await client.users.getUsers();
|
|
48
|
-
const user = await client.users.getUser(1);
|
|
49
|
-
|
|
50
|
-
// Tenants (system-level, no ctx)
|
|
51
|
-
const tenants = await client.tenants.getTenants();
|
|
52
|
-
|
|
53
|
-
// Shops (tenant-level)
|
|
54
|
-
const shops = await client.shops.getShops(tenantId);
|
|
55
|
-
|
|
56
|
-
// Shop-scoped entities (require ctx)
|
|
57
|
-
const ctx = { tenant_id: 1, shop_id: 1 };
|
|
58
|
-
|
|
59
|
-
// SKUs
|
|
60
|
-
const skus = await client.skus.getSkus(ctx);
|
|
61
|
-
await client.skus.createSku(ctx, { code: 'SKU-001', title: 'Product 1' });
|
|
62
|
-
await client.skus.importJson(ctx, items);
|
|
63
|
-
const csv = await client.skus.exportCsv(ctx);
|
|
64
|
-
|
|
65
|
-
// Brands
|
|
66
|
-
const brands = await client.brands.getBrands(ctx);
|
|
67
|
-
await client.brands.importJson(ctx, [{ code: 'apple', title: 'Apple' }]);
|
|
68
|
-
|
|
69
|
-
// Categories, Groups, Statuses, Suppliers - same pattern
|
|
70
|
-
const categories = await client.categories.getCategories(ctx);
|
|
71
|
-
const groups = await client.groups.getGroups(ctx);
|
|
72
|
-
const statuses = await client.statuses.getStatuses(ctx);
|
|
73
|
-
const suppliers = await client.suppliers.getSuppliers(ctx);
|
|
74
|
-
|
|
75
|
-
// Marketplaces
|
|
76
|
-
const marketplaces = await client.marketplaces.getMarketplaces(ctx);
|
|
77
|
-
|
|
78
|
-
// Sales History (with optional period filter)
|
|
79
|
-
const history = await client.salesHistory.getSalesHistory(ctx, {
|
|
80
|
-
start: '2024-01',
|
|
81
|
-
end: '2024-12',
|
|
82
|
-
});
|
|
23
|
+
// CRUD (all list endpoints return paginated responses)
|
|
24
|
+
const { items: brands, total } = await client.brands.getAll(ctx);
|
|
25
|
+
const { items: paginatedBrands } = await client.brands.getAll(ctx, { limit: 10, offset: 20 });
|
|
26
|
+
const brand = await client.brands.getByCode(ctx, 'apple');
|
|
27
|
+
await client.brands.create(ctx, { code: 'apple', title: 'Apple' });
|
|
28
|
+
await client.brands.update(ctx, 1, { title: 'Apple Inc.' });
|
|
29
|
+
await client.brands.delete(ctx, 1);
|
|
83
30
|
|
|
84
|
-
//
|
|
85
|
-
|
|
31
|
+
// Import/Export (uses string codes, auto-resolved)
|
|
32
|
+
await client.skus.importJson(ctx, [{ code: 'SKU-001', title: 'Product' }]);
|
|
33
|
+
const items = await client.skus.exportJson(ctx);
|
|
86
34
|
```
|
|
87
35
|
|
|
88
|
-
##
|
|
89
|
-
|
|
90
|
-
### Argument Order
|
|
36
|
+
## Pagination
|
|
91
37
|
|
|
92
|
-
All methods
|
|
38
|
+
All `getAll` methods return paginated responses:
|
|
93
39
|
|
|
94
40
|
```typescript
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
await client.brands.getBrandByCode(ctx, code);
|
|
102
|
-
|
|
103
|
-
// Create
|
|
104
|
-
await client.skus.createSku(ctx, request);
|
|
105
|
-
await client.brands.createBrand(ctx, request);
|
|
106
|
-
|
|
107
|
-
// Update
|
|
108
|
-
await client.skus.updateSku(ctx, id, request);
|
|
109
|
-
await client.brands.updateBrand(ctx, id, request);
|
|
110
|
-
|
|
111
|
-
// Delete
|
|
112
|
-
await client.skus.deleteSku(ctx, id);
|
|
113
|
-
await client.brands.deleteBrand(ctx, id);
|
|
114
|
-
|
|
115
|
-
// Import
|
|
116
|
-
await client.skus.importJson(ctx, items);
|
|
117
|
-
await client.skus.importCsv(ctx, csvContent);
|
|
118
|
-
|
|
119
|
-
// Export
|
|
120
|
-
await client.skus.exportJson(ctx);
|
|
121
|
-
await client.skus.exportCsv(ctx);
|
|
41
|
+
interface PaginatedResponse<T> {
|
|
42
|
+
items: T[]; // The page of items
|
|
43
|
+
total: number; // Total count of all items
|
|
44
|
+
limit: number; // Items per page
|
|
45
|
+
offset: number; // Current offset
|
|
46
|
+
}
|
|
122
47
|
```
|
|
123
48
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
-
|
|
127
|
-
- **Import/Export operations** use string codes for human readability (e.g., `marketplace: 'amazon'`)
|
|
49
|
+
Query parameters:
|
|
50
|
+
- `limit` - Number of items per page (1-1000, default: 100)
|
|
51
|
+
- `offset` - Number of items to skip (default: 0)
|
|
128
52
|
|
|
53
|
+
Sales history also supports period filtering:
|
|
129
54
|
```typescript
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
quantity: 100,
|
|
55
|
+
const { items, total } = await client.salesHistory.getAll(ctx, {
|
|
56
|
+
period_from: '2024-01',
|
|
57
|
+
period_to: '2024-12',
|
|
58
|
+
limit: 50,
|
|
59
|
+
offset: 0,
|
|
136
60
|
});
|
|
137
|
-
|
|
138
|
-
// Import uses codes (auto-resolves to IDs)
|
|
139
|
-
await client.salesHistory.importJson(ctx, [
|
|
140
|
-
{ sku: 'SKU-001', marketplace: 'amazon', period: '2026-01', quantity: 100 },
|
|
141
|
-
]);
|
|
142
|
-
|
|
143
|
-
// Export returns codes
|
|
144
|
-
const exported = await client.salesHistory.exportJson(ctx);
|
|
145
|
-
// [{ sku: 'SKU-001', marketplace: 'amazon', period: '2026-01', quantity: 100 }]
|
|
146
61
|
```
|
|
147
62
|
|
|
148
|
-
##
|
|
149
|
-
|
|
150
|
-
All shop-scoped entities support bulk import/export:
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
const ctx = { tenant_id: 1, shop_id: 1 };
|
|
154
|
-
|
|
155
|
-
// Import from JSON array
|
|
156
|
-
const result = await client.skus.importJson(ctx, [
|
|
157
|
-
{ code: 'SKU-001', title: 'Product 1' },
|
|
158
|
-
{ code: 'SKU-002', title: 'Product 2' },
|
|
159
|
-
]);
|
|
160
|
-
console.log(result); // { created: 2, updated: 0, errors: [] }
|
|
63
|
+
## API
|
|
161
64
|
|
|
162
|
-
|
|
163
|
-
const csvContent = `code,title
|
|
164
|
-
SKU-001,Product 1
|
|
165
|
-
SKU-002,Product 2`;
|
|
166
|
-
const result = await client.skus.importCsv(ctx, csvContent);
|
|
65
|
+
All shop-scoped clients (`skus`, `brands`, `categories`, `groups`, `statuses`, `suppliers`, `marketplaces`, `salesHistory`) share these methods:
|
|
167
66
|
|
|
168
|
-
|
|
169
|
-
|
|
67
|
+
- `getAll(ctx, query?)` → `PaginatedResponse<T>`
|
|
68
|
+
- `getById(ctx, id)`, `getByCode(ctx, code)`
|
|
69
|
+
- `create(ctx, req)`, `update(ctx, id, req)`, `delete(ctx, id)`
|
|
70
|
+
- `importJson(ctx, items)`, `importCsv(ctx, csv)`, `exportJson(ctx)`, `exportCsv(ctx)`
|
|
71
|
+
- `getExampleJson()`, `getExampleCsv()` (no auth)
|
|
170
72
|
|
|
171
|
-
|
|
172
|
-
const csv = await client.skus.exportCsv(ctx);
|
|
173
|
-
|
|
174
|
-
// Get example templates (no auth required)
|
|
175
|
-
const exampleJson = await client.skus.getExampleJson();
|
|
176
|
-
const exampleCsv = await client.skus.getExampleCsv();
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
**Supported entities:** SKUs, Brands, Categories, Groups, Statuses, Suppliers, Marketplaces, Sales History
|
|
180
|
-
|
|
181
|
-
## Data Requirements
|
|
182
|
-
|
|
183
|
-
### SKUs
|
|
184
|
-
|
|
185
|
-
| Field | Create/Import | Update | Export |
|
|
186
|
-
|-------|---------------|--------|--------|
|
|
187
|
-
| `code` | Required, unique per shop | Optional | ✓ |
|
|
188
|
-
| `title` | Required | Optional | ✓ |
|
|
189
|
-
| `title2` | Optional | Optional | ✓ |
|
|
190
|
-
| `category` | Optional (code) | - | code |
|
|
191
|
-
| `group` | Optional (code) | - | code |
|
|
192
|
-
| `status` | Optional (code) | - | code |
|
|
193
|
-
| `supplier` | Optional (code) | - | code |
|
|
194
|
-
|
|
195
|
-
### Brands, Categories, Groups, Statuses, Suppliers
|
|
196
|
-
|
|
197
|
-
| Field | Create/Import | Update | Export |
|
|
198
|
-
|-------|---------------|--------|--------|
|
|
199
|
-
| `code` | Required, unique per shop | Optional | ✓ |
|
|
200
|
-
| `title` | Required | Optional | ✓ |
|
|
201
|
-
|
|
202
|
-
### Marketplaces
|
|
203
|
-
|
|
204
|
-
| Field | Create/Import | Update | Export |
|
|
205
|
-
|-------|---------------|--------|--------|
|
|
206
|
-
| `code` | Required, unique per shop | Optional | ✓ |
|
|
207
|
-
| `title` | Required | Optional | ✓ |
|
|
208
|
-
|
|
209
|
-
### Sales History
|
|
210
|
-
|
|
211
|
-
| Field | Create | Import | Update | Export |
|
|
212
|
-
|-------|--------|--------|--------|--------|
|
|
213
|
-
| `sku_id` | Required | - | Optional | - |
|
|
214
|
-
| `sku` | - | Required (code) | - | code |
|
|
215
|
-
| `marketplace_id` | Required | - | Optional | - |
|
|
216
|
-
| `marketplace` | - | Required (code) | - | code |
|
|
217
|
-
| `period` | Required (YYYY-MM) | Required | Optional | ✓ |
|
|
218
|
-
| `quantity` | Required | Required | Optional | ✓ |
|
|
219
|
-
|
|
220
|
-
### Users
|
|
221
|
-
|
|
222
|
-
| Field | Create | Update |
|
|
223
|
-
|-------|--------|--------|
|
|
224
|
-
| `email` | Required, unique | Optional |
|
|
225
|
-
| `name` | Required | Optional |
|
|
226
|
-
| `default_shop_id` | Optional | Optional (null to clear) |
|
|
227
|
-
|
|
228
|
-
### Tenants
|
|
229
|
-
|
|
230
|
-
| Field | Create | Update |
|
|
231
|
-
|-------|--------|--------|
|
|
232
|
-
| `title` | Required | Optional |
|
|
233
|
-
| `owner_id` | Optional | Optional (null to clear) |
|
|
234
|
-
|
|
235
|
-
### Shops
|
|
236
|
-
|
|
237
|
-
| Field | Create | Update |
|
|
238
|
-
|-------|--------|--------|
|
|
239
|
-
| `title` | Required | Optional |
|
|
240
|
-
| `tenant_id` | Required | - |
|
|
241
|
-
|
|
242
|
-
## Available Sub-Clients
|
|
243
|
-
|
|
244
|
-
### System-Level (no context required)
|
|
245
|
-
|
|
246
|
-
#### `client.me`
|
|
247
|
-
- `getMe()` - Get current user with roles and tenants
|
|
248
|
-
|
|
249
|
-
#### `client.users`
|
|
250
|
-
- `getUsers()` - List users (system admin sees all, tenant admin sees their tenants)
|
|
251
|
-
- `getUser(id)` - Get user by ID
|
|
252
|
-
- `createUser(request)` - Create user
|
|
253
|
-
- `updateUser(id, request)` - Update user
|
|
254
|
-
- `deleteUser(id)` - Delete user
|
|
255
|
-
|
|
256
|
-
#### `client.tenants`
|
|
257
|
-
- `getTenants()` - List tenants
|
|
258
|
-
- `getTenant(id)` - Get tenant by ID
|
|
259
|
-
- `createTenant(request)` - Create tenant (system admin only)
|
|
260
|
-
- `updateTenant(id, request)` - Update tenant
|
|
261
|
-
- `deleteTenant(id)` - Delete tenant
|
|
262
|
-
- `createTenantWithShopAndUser(request)` - Create tenant with initial shop and user
|
|
263
|
-
|
|
264
|
-
#### `client.shops`
|
|
265
|
-
- `getShops(tenantId?)` - List shops (optionally filtered by tenant)
|
|
266
|
-
- `getShop(id)` - Get shop by ID
|
|
267
|
-
- `createShop(request)` - Create shop
|
|
268
|
-
- `updateShop(id, request)` - Update shop
|
|
269
|
-
- `deleteShop(id)` - Delete shop
|
|
270
|
-
- `deleteShopData(id)` - Delete all data (SKUs, sales history) for a shop
|
|
271
|
-
|
|
272
|
-
#### `client.roles`
|
|
273
|
-
- `getRoles()` - List roles (system admin only)
|
|
274
|
-
- `getRole(id)` - Get role by ID
|
|
275
|
-
|
|
276
|
-
#### `client.userRoles`
|
|
277
|
-
- `getUserRoles(query)` - List user roles
|
|
278
|
-
- `getUserRole(id)` - Get user role by ID
|
|
279
|
-
- `createUserRole(request)` - Create user role
|
|
280
|
-
- `deleteUserRole(id)` - Delete user role
|
|
281
|
-
|
|
282
|
-
#### `client.apiKeys`
|
|
283
|
-
- `getApiKeys()` - List API keys (system admin only)
|
|
284
|
-
- `createApiKey(request)` - Create API key
|
|
285
|
-
- `deleteApiKey(id)` - Delete API key
|
|
286
|
-
|
|
287
|
-
#### `client.metadata`
|
|
288
|
-
- `getEntitiesMetadata()` - Get field definitions for all entities (no auth)
|
|
289
|
-
|
|
290
|
-
### Shop-Scoped (context required)
|
|
291
|
-
|
|
292
|
-
All shop-scoped clients follow the same pattern:
|
|
293
|
-
|
|
294
|
-
#### `client.skus`
|
|
295
|
-
- `getSkus(ctx)` - List SKUs
|
|
296
|
-
- `getSku(ctx, id)` - Get SKU by ID
|
|
297
|
-
- `getSkuByCode(ctx, code)` - Get SKU by code
|
|
298
|
-
- `createSku(ctx, request)` - Create SKU
|
|
299
|
-
- `updateSku(ctx, id, request)` - Update SKU
|
|
300
|
-
- `deleteSku(ctx, id)` - Delete SKU
|
|
301
|
-
- `importJson(ctx, items)` - Import from JSON array
|
|
302
|
-
- `importCsv(ctx, csvContent)` - Import from CSV string
|
|
303
|
-
- `exportJson(ctx)` - Export to JSON
|
|
304
|
-
- `exportCsv(ctx)` - Export to CSV
|
|
305
|
-
- `getExampleJson()` - Get JSON import example (no auth)
|
|
306
|
-
- `getExampleCsv()` - Get CSV import example (no auth)
|
|
307
|
-
|
|
308
|
-
#### `client.brands`, `client.categories`, `client.groups`, `client.statuses`, `client.suppliers`
|
|
309
|
-
|
|
310
|
-
Same methods as `client.skus`:
|
|
311
|
-
- `get<Entity>s(ctx)`, `get<Entity>(ctx, id)`, `get<Entity>ByCode(ctx, code)`
|
|
312
|
-
- `create<Entity>(ctx, request)`, `update<Entity>(ctx, id, request)`, `delete<Entity>(ctx, id)`
|
|
313
|
-
- `importJson(ctx, items)`, `importCsv(ctx, csvContent)`
|
|
314
|
-
- `exportJson(ctx)`, `exportCsv(ctx)`
|
|
315
|
-
- `getExampleJson()`, `getExampleCsv()`
|
|
316
|
-
|
|
317
|
-
#### `client.marketplaces`
|
|
318
|
-
- `getMarketplaces(ctx)` - List marketplaces
|
|
319
|
-
- `getMarketplace(ctx, id)` - Get marketplace by ID
|
|
320
|
-
- `getMarketplaceByCode(ctx, code)` - Get marketplace by code
|
|
321
|
-
- `createMarketplace(ctx, request)` - Create marketplace
|
|
322
|
-
- `updateMarketplace(ctx, id, request)` - Update marketplace
|
|
323
|
-
- `deleteMarketplace(ctx, id)` - Delete marketplace
|
|
324
|
-
- `importJson(ctx, items)`, `importCsv(ctx, csvContent)` - Import
|
|
325
|
-
- `exportJson(ctx)`, `exportCsv(ctx)` - Export
|
|
326
|
-
|
|
327
|
-
#### `client.salesHistory`
|
|
328
|
-
- `getSalesHistory(ctx, query?)` - List sales history (optional period filter)
|
|
329
|
-
- `getSalesHistoryItem(ctx, id)` - Get sales history item by ID
|
|
330
|
-
- `createSalesHistory(ctx, request)` - Create sales history
|
|
331
|
-
- `updateSalesHistory(ctx, id, request)` - Update sales history
|
|
332
|
-
- `deleteSalesHistory(ctx, id)` - Delete sales history
|
|
333
|
-
- `importJson(ctx, items)`, `importCsv(ctx, csvContent)` - Import
|
|
334
|
-
- `exportJson(ctx, query?)`, `exportCsv(ctx, query?)` - Export (optional period filter)
|
|
335
|
-
- `getExampleJson()`, `getExampleCsv()` - Examples (no auth)
|
|
73
|
+
System clients: `me`, `users`, `tenants`, `shops`, `roles`, `userRoles`, `apiKeys`, `metadata`
|
|
336
74
|
|
|
337
75
|
## Error Handling
|
|
338
76
|
|
|
339
77
|
```typescript
|
|
340
|
-
import { SalesPlannerClient, ApiError } from '@sales-planner/http-client';
|
|
341
|
-
|
|
342
78
|
try {
|
|
343
|
-
|
|
79
|
+
await client.users.getById(999);
|
|
344
80
|
} catch (error) {
|
|
345
81
|
if (error instanceof ApiError) {
|
|
346
|
-
console.log(error.status); // 404
|
|
347
|
-
console.log(error.message); // "User not found"
|
|
82
|
+
console.log(error.status, error.message); // 404, "User not found"
|
|
348
83
|
}
|
|
349
84
|
}
|
|
350
85
|
```
|
|
351
86
|
|
|
352
|
-
**Common HTTP status codes:**
|
|
353
|
-
- `400 Bad Request` - Validation error
|
|
354
|
-
- `401 Unauthorized` - Missing or invalid API key
|
|
355
|
-
- `403 Forbidden` - Insufficient permissions
|
|
356
|
-
- `404 Not Found` - Resource not found
|
|
357
|
-
- `409 Conflict` - Duplicate resource (email, code, period)
|
|
358
|
-
|
|
359
87
|
## Types
|
|
360
88
|
|
|
361
|
-
|
|
89
|
+
All types re-exported from `@sales-planner/shared`:
|
|
362
90
|
|
|
363
91
|
```typescript
|
|
364
92
|
import type {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
// Entities
|
|
370
|
-
User,
|
|
371
|
-
Tenant,
|
|
372
|
-
Shop,
|
|
373
|
-
Sku,
|
|
374
|
-
Brand,
|
|
375
|
-
Category,
|
|
376
|
-
Group,
|
|
377
|
-
Status,
|
|
378
|
-
Supplier,
|
|
379
|
-
Marketplace,
|
|
380
|
-
SalesHistory,
|
|
381
|
-
Role,
|
|
382
|
-
UserRole,
|
|
383
|
-
ApiKey,
|
|
384
|
-
|
|
385
|
-
// Request types (for create/update)
|
|
386
|
-
CreateUserRequest,
|
|
387
|
-
UpdateUserRequest,
|
|
388
|
-
CreateTenantRequest,
|
|
389
|
-
UpdateTenantRequest,
|
|
390
|
-
CreateShopRequest,
|
|
391
|
-
UpdateShopRequest,
|
|
392
|
-
CreateSkuRequest,
|
|
393
|
-
UpdateSkuRequest,
|
|
394
|
-
CreateBrandRequest,
|
|
395
|
-
UpdateBrandRequest,
|
|
396
|
-
CreateSalesHistoryRequest,
|
|
397
|
-
UpdateSalesHistoryRequest,
|
|
398
|
-
// ... etc
|
|
399
|
-
|
|
400
|
-
// Import types (for import operations)
|
|
401
|
-
ImportSkuItem,
|
|
402
|
-
ImportBrandItem,
|
|
403
|
-
ImportSalesHistoryItem,
|
|
404
|
-
// ... etc
|
|
405
|
-
|
|
406
|
-
// Response types
|
|
407
|
-
UserWithRolesAndTenants,
|
|
408
|
-
TenantWithShopAndApiKey,
|
|
409
|
-
ImportResult,
|
|
410
|
-
SkuImportResult,
|
|
411
|
-
DeleteDataResult,
|
|
412
|
-
|
|
413
|
-
// Export types
|
|
414
|
-
SkuExportItem,
|
|
415
|
-
SalesHistoryExportItem,
|
|
93
|
+
ShopContextParams, PaginationQuery, PaginatedResponse, PeriodQuery, SalesHistoryQuery,
|
|
94
|
+
User, Tenant, Shop, Sku, Brand, Category, Group, Status, Supplier, Marketplace, SalesHistory,
|
|
95
|
+
CreateSkuRequest, UpdateSkuRequest, ImportSkuItem, SkuExportItem,
|
|
96
|
+
ImportResult, SkuImportResult,
|
|
416
97
|
} from '@sales-planner/http-client';
|
|
417
98
|
```
|
|
418
99
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ApiKey, CreateApiKeyRequest } from '@sales-planner/shared';
|
|
2
2
|
import { BaseClient } from './base-client.js';
|
|
3
3
|
export declare class ApiKeysClient extends BaseClient {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
getAll(userId?: number): Promise<ApiKey[]>;
|
|
5
|
+
create(request: CreateApiKeyRequest): Promise<ApiKey>;
|
|
6
|
+
delete(id: number): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=api-keys-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-keys-client.d.ts","sourceRoot":"","sources":["../../src/clients/api-keys-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,qBAAa,aAAc,SAAQ,UAAU;IACrC,
|
|
1
|
+
{"version":3,"file":"api-keys-client.d.ts","sourceRoot":"","sources":["../../src/clients/api-keys-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,qBAAa,aAAc,SAAQ,UAAU;IACrC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAI1C,MAAM,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIrD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGxC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BaseClient } from './base-client.js';
|
|
2
2
|
export class ApiKeysClient extends BaseClient {
|
|
3
|
-
async
|
|
3
|
+
async getAll(userId) {
|
|
4
4
|
return this.request('GET', '/api-keys', { params: { user_id: userId } });
|
|
5
5
|
}
|
|
6
|
-
async
|
|
6
|
+
async create(request) {
|
|
7
7
|
return this.request('POST', '/api-keys', { body: request });
|
|
8
8
|
}
|
|
9
|
-
async
|
|
9
|
+
async delete(id) {
|
|
10
10
|
return this.request('DELETE', `/api-keys/${id}`);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Brand,
|
|
3
|
+
CreateBrandRequest,
|
|
4
|
+
UpdateBrandRequest,
|
|
5
|
+
ImportBrandItem,
|
|
6
|
+
BrandExportItem,
|
|
7
|
+
} from '@sales-planner/shared';
|
|
8
|
+
import type { ClientConfig } from './base-client.js';
|
|
9
|
+
import { CodedEntityClient } from './coded-entity-client.js';
|
|
10
|
+
export declare class BrandsClient extends CodedEntityClient<
|
|
11
|
+
Brand,
|
|
12
|
+
CreateBrandRequest,
|
|
13
|
+
UpdateBrandRequest,
|
|
14
|
+
ImportBrandItem,
|
|
15
|
+
BrandExportItem
|
|
16
|
+
> {
|
|
17
|
+
constructor(config: ClientConfig);
|
|
16
18
|
}
|
|
17
|
-
//# sourceMappingURL=brands-client.d.ts.map
|
|
19
|
+
//# sourceMappingURL=brands-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brands-client.d.ts","sourceRoot":"","sources":["../../src/clients/brands-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,eAAe,
|
|
1
|
+
{"version":3,"file":"brands-client.d.ts","sourceRoot":"","sources":["../../src/clients/brands-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,qBAAa,YAAa,SAAQ,iBAAiB,CACjD,KAAK,EACL,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,eAAe,CAChB;gBACa,MAAM,EAAE,YAAY;CAGjC"}
|
|
@@ -1,39 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export class BrandsClient extends
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
async getBrand(ctx, id) {
|
|
7
|
-
return this.request('GET', `/brands/${id}`, { params: ctx });
|
|
8
|
-
}
|
|
9
|
-
async getBrandByCode(ctx, code) {
|
|
10
|
-
return this.request('GET', `/brands/code/${encodeURIComponent(code)}`, { params: ctx });
|
|
11
|
-
}
|
|
12
|
-
async createBrand(ctx, request) {
|
|
13
|
-
return this.request('POST', '/brands', { body: request, params: ctx });
|
|
14
|
-
}
|
|
15
|
-
async updateBrand(ctx, id, request) {
|
|
16
|
-
return this.request('PUT', `/brands/${id}`, { body: request, params: ctx });
|
|
17
|
-
}
|
|
18
|
-
async deleteBrand(ctx, id) {
|
|
19
|
-
return this.request('DELETE', `/brands/${id}`, { params: ctx });
|
|
20
|
-
}
|
|
21
|
-
async importJson(ctx, items) {
|
|
22
|
-
return this.request('POST', '/brands/import/json', { body: items, params: ctx });
|
|
23
|
-
}
|
|
24
|
-
async importCsv(ctx, csvContent) {
|
|
25
|
-
return this.uploadCsv('/brands/import/csv', csvContent, ctx);
|
|
26
|
-
}
|
|
27
|
-
async exportJson(ctx) {
|
|
28
|
-
return this.request('GET', '/brands/export/json', { params: ctx });
|
|
29
|
-
}
|
|
30
|
-
async exportCsv(ctx) {
|
|
31
|
-
return this.requestText('GET', '/brands/export/csv', { params: ctx });
|
|
32
|
-
}
|
|
33
|
-
async getExampleJson() {
|
|
34
|
-
return this.requestPublic('GET', '/brands/examples/json');
|
|
35
|
-
}
|
|
36
|
-
async getExampleCsv() {
|
|
37
|
-
return this.requestTextPublic('GET', '/brands/examples/csv');
|
|
1
|
+
import { CodedEntityClient } from './coded-entity-client.js';
|
|
2
|
+
export class BrandsClient extends CodedEntityClient {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
super(config, 'brands');
|
|
38
5
|
}
|
|
39
6
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Category,
|
|
3
|
+
CreateCategoryRequest,
|
|
4
|
+
UpdateCategoryRequest,
|
|
5
|
+
ImportCategoryItem,
|
|
6
|
+
CategoryExportItem,
|
|
7
|
+
} from '@sales-planner/shared';
|
|
8
|
+
import type { ClientConfig } from './base-client.js';
|
|
9
|
+
import { CodedEntityClient } from './coded-entity-client.js';
|
|
10
|
+
export declare class CategoriesClient extends CodedEntityClient<
|
|
11
|
+
Category,
|
|
12
|
+
CreateCategoryRequest,
|
|
13
|
+
UpdateCategoryRequest,
|
|
14
|
+
ImportCategoryItem,
|
|
15
|
+
CategoryExportItem
|
|
16
|
+
> {
|
|
17
|
+
constructor(config: ClientConfig);
|
|
16
18
|
}
|
|
17
|
-
//# sourceMappingURL=categories-client.d.ts.map
|
|
19
|
+
//# sourceMappingURL=categories-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"categories-client.d.ts","sourceRoot":"","sources":["../../src/clients/categories-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"categories-client.d.ts","sourceRoot":"","sources":["../../src/clients/categories-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,qBAAa,gBAAiB,SAAQ,iBAAiB,CACrD,QAAQ,EACR,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,CACnB;gBACa,MAAM,EAAE,YAAY;CAGjC"}
|
|
@@ -1,40 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export class CategoriesClient extends
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
async getCategory(ctx, id) {
|
|
7
|
-
return this.request('GET', `/categories/${id}`, { params: ctx });
|
|
8
|
-
}
|
|
9
|
-
async getCategoryByCode(ctx, code) {
|
|
10
|
-
return this.request('GET', `/categories/code/${encodeURIComponent(code)}`, { params: ctx });
|
|
11
|
-
}
|
|
12
|
-
async createCategory(ctx, request) {
|
|
13
|
-
return this.request('POST', '/categories', { body: request, params: ctx });
|
|
14
|
-
}
|
|
15
|
-
async updateCategory(ctx, id, request) {
|
|
16
|
-
return this.request('PUT', `/categories/${id}`, { body: request, params: ctx });
|
|
17
|
-
}
|
|
18
|
-
async deleteCategory(ctx, id) {
|
|
19
|
-
return this.request('DELETE', `/categories/${id}`, { params: ctx });
|
|
20
|
-
}
|
|
21
|
-
// Import/Export methods
|
|
22
|
-
async importJson(ctx, items) {
|
|
23
|
-
return this.request('POST', '/categories/import/json', { body: items, params: ctx });
|
|
24
|
-
}
|
|
25
|
-
async importCsv(ctx, csvContent) {
|
|
26
|
-
return this.uploadCsv('/categories/import/csv', csvContent, ctx);
|
|
27
|
-
}
|
|
28
|
-
async exportJson(ctx) {
|
|
29
|
-
return this.request('GET', '/categories/export/json', { params: ctx });
|
|
30
|
-
}
|
|
31
|
-
async exportCsv(ctx) {
|
|
32
|
-
return this.requestText('GET', '/categories/export/csv', { params: ctx });
|
|
33
|
-
}
|
|
34
|
-
async getExampleJson() {
|
|
35
|
-
return this.requestPublic('GET', '/categories/examples/json');
|
|
36
|
-
}
|
|
37
|
-
async getExampleCsv() {
|
|
38
|
-
return this.requestTextPublic('GET', '/categories/examples/csv');
|
|
1
|
+
import { CodedEntityClient } from './coded-entity-client.js';
|
|
2
|
+
export class CategoriesClient extends CodedEntityClient {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
super(config, 'categories');
|
|
39
5
|
}
|
|
40
6
|
}
|