@pelygo/janus 0.2.0 → 0.4.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 +621 -166
- package/USAGE.md +393 -0
- package/dist/index.d.ts +77 -6
- package/dist/index.js +84 -60
- package/package.json +3 -2
package/USAGE.md
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
# @pelygo/janus — Quick Usage Reference
|
|
2
|
+
|
|
3
|
+
This file ships inside the npm package for AI tools to reference.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { createJanusApi } from '@pelygo/janus';
|
|
9
|
+
import { configure } from '@pelygo/auth/core';
|
|
10
|
+
|
|
11
|
+
// Auth and API are separate servers — both URLs required
|
|
12
|
+
configure({
|
|
13
|
+
apiBaseUrl: 'https://api.janus.dev.pelygo.com',
|
|
14
|
+
authBaseUrl: 'https://api.auth.dev.pelygo.com',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const janus = createJanusApi({
|
|
18
|
+
baseUrl: 'https://api.janus.dev.pelygo.com',
|
|
19
|
+
onUnauthorized: () => {
|
|
20
|
+
setTimeout(() => { window.location.href = '/SignIn'; }, 100);
|
|
21
|
+
},
|
|
22
|
+
// allowWrites: true, // uncomment to enable create/update/delete operations
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Read-only mode (default)
|
|
27
|
+
|
|
28
|
+
The client is **read-only by default**. All GET requests and query-style POSTs work. Create, update, and delete operations throw an error unless `allowWrites: true` is set.
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
// Read-only (default) — safe for dashboards and analytics
|
|
32
|
+
const janus = createJanusApi({ baseUrl: '...' });
|
|
33
|
+
|
|
34
|
+
// Full access — required for apps that create/update/delete data
|
|
35
|
+
const janus = createJanusApi({ baseUrl: '...', allowWrites: true });
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Always allowed** (even in read-only mode): `getAll`, `getById`, `query`, `queryPost`, `getStats`, `getFilterOptions`, `auth.login`, `auth.verify`, all report methods, all CSV exports.
|
|
39
|
+
|
|
40
|
+
**Blocked in read-only mode**: `create`, `update`, `replace`, `delete`, `addItem`, `addComment`, `addStatus`, and all other write operations.
|
|
41
|
+
|
|
42
|
+
## Rules
|
|
43
|
+
|
|
44
|
+
1. **Always pass `clientId`** to every query. Get it from `useClient()`:
|
|
45
|
+
```js
|
|
46
|
+
const { clientId } = useClient();
|
|
47
|
+
```
|
|
48
|
+
New endpoints reject without it (400). Older endpoints return ALL clients' data without it.
|
|
49
|
+
|
|
50
|
+
2. **Use exact field names** from the tables below. Do not guess field names.
|
|
51
|
+
|
|
52
|
+
3. **Navigation in callbacks** (onSuccess, onSelect, logout) must use:
|
|
53
|
+
```js
|
|
54
|
+
setTimeout(() => { window.location.href = '/path'; }, 100);
|
|
55
|
+
```
|
|
56
|
+
This is required for Base44 and other iframe-based environments.
|
|
57
|
+
|
|
58
|
+
4. **Use `Object.entries(data)`** for dynamic response shapes (like `getStats`).
|
|
59
|
+
|
|
60
|
+
## Query Filter Reference
|
|
61
|
+
|
|
62
|
+
### PaginatedQueryFilters (v2 endpoints: products, stocks, locations, etc.)
|
|
63
|
+
|
|
64
|
+
| Param | Type | Description |
|
|
65
|
+
|-------|------|-------------|
|
|
66
|
+
| `clientId` | `number` | **Required.** Client ID from `useClient()` |
|
|
67
|
+
| `pageSize` | `number` | Results per page (default: 25) |
|
|
68
|
+
| `pageNumber` | `number` | Page number, 1-based (default: 1) |
|
|
69
|
+
| `orderColumn` | `string` | Column to sort by (e.g. `'id'`, `'created'`) |
|
|
70
|
+
| `orderDirection` | `'ASC' \| 'DESC'` | Sort direction (default: DESC) |
|
|
71
|
+
| `query` | `string` | Free-text search across key fields |
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
const { data, meta } = await janus.products.getAll({
|
|
75
|
+
clientId, pageSize: 25, pageNumber: 1, orderDirection: 'DESC', query: 'widget',
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### ReturnsQueryFilters (janus.returns.query)
|
|
80
|
+
|
|
81
|
+
| Param | Type | Description |
|
|
82
|
+
|-------|------|-------------|
|
|
83
|
+
| `clientId` | `number` | Client ID |
|
|
84
|
+
| `page` | `number` | Page number |
|
|
85
|
+
| `pageSize` | `number` | Results per page |
|
|
86
|
+
| `created_at` | `string` | Start date (ISO, e.g. `'2025-01-01'`) |
|
|
87
|
+
| `created_to` | `string` | End date (ISO) |
|
|
88
|
+
| `last_status_ids` | `string` | Comma-separated status IDs to match current status |
|
|
89
|
+
| `include_status_ids` | `string` | Include returns with any of these status IDs |
|
|
90
|
+
| `exclude_status_ids` | `string` | Exclude returns with these status IDs |
|
|
91
|
+
| `include_associations` | `string` | Include nested data: `'return_items'`, `'return_comments'`, or both comma-separated |
|
|
92
|
+
| `csv` | `boolean` | Export as CSV instead of JSON |
|
|
93
|
+
| `group_by` | `string` | Group results by field |
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
const returns = await janus.returns.query({
|
|
97
|
+
clientId, page: 1, pageSize: 25,
|
|
98
|
+
created_at: '2025-01-01', created_to: '2025-12-31',
|
|
99
|
+
last_status_ids: '1,2', include_associations: 'return_items',
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### OrdersQueryFilters (janus.orders.getAll)
|
|
104
|
+
|
|
105
|
+
| Param | Type | Description |
|
|
106
|
+
|-------|------|-------------|
|
|
107
|
+
| `clientId` | `number` | Client ID |
|
|
108
|
+
| `page` | `number` | Page number |
|
|
109
|
+
| `pageSize` | `number` | Results per page |
|
|
110
|
+
| `order_column` | `string` | Sort column |
|
|
111
|
+
| `order_direction` | `'ASC' \| 'DESC'` | Sort direction |
|
|
112
|
+
| `created_at` | `string` | Start date (ISO) |
|
|
113
|
+
| `created_to` | `string` | End date (ISO) |
|
|
114
|
+
| `channel` | `string` | Filter by sales channel |
|
|
115
|
+
| `courier` | `string` | Filter by courier name |
|
|
116
|
+
| `status` | `string` | Filter by order status |
|
|
117
|
+
| `query` | `string` | Free-text search |
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
const orders = await janus.orders.getAll({
|
|
121
|
+
clientId, page: 1, pageSize: 25, order_direction: 'DESC',
|
|
122
|
+
created_at: '2025-01-01', created_to: '2025-12-31', query: 'ORD-123',
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### ReturnsSummaryFilters (janus.reports.returnsSummary)
|
|
127
|
+
|
|
128
|
+
| Param | Type | Description |
|
|
129
|
+
|-------|------|-------------|
|
|
130
|
+
| `clientId` | `number` | Client ID |
|
|
131
|
+
| `createdFrom` | `string` | Start date (ISO) |
|
|
132
|
+
| `createdTo` | `string` | End date (ISO) |
|
|
133
|
+
| `approvedFrom` | `string` | Approval start date |
|
|
134
|
+
| `approvedTo` | `string` | Approval end date |
|
|
135
|
+
| `courierServiceId` | `number` | Filter by courier service |
|
|
136
|
+
| `approved` | `boolean` | Only approved returns |
|
|
137
|
+
| `page` | `number` | Page number |
|
|
138
|
+
| `pageSize` | `number` | Results per page |
|
|
139
|
+
| `csv` | `boolean` | Set true for CSV export (use `returnsSummaryCsv` instead) |
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
const summary = await janus.reports.returnsSummary({
|
|
143
|
+
clientId, createdFrom: '2025-01-01', createdTo: '2025-12-31',
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Resource-specific extra filters
|
|
148
|
+
|
|
149
|
+
| Resource | Extra param | Type | Description |
|
|
150
|
+
|----------|-----------|------|-------------|
|
|
151
|
+
| `janus.stockTransactions.getAll` | `stockId` | `number` | Filter by stock record |
|
|
152
|
+
| `janus.stockAllocations.getAll` | `orderId` | `number` | Filter by order |
|
|
153
|
+
| `janus.dispatches.getAll` | `orderId` | `number` | Filter by order |
|
|
154
|
+
| `janus.audits.getAll` | `filter` | `string` | Additional filter |
|
|
155
|
+
| `janus.users.getAll` | `filterRole` | `string` | Filter by role |
|
|
156
|
+
| `janus.users.getAll` | `filterType` | `string` | Filter by user type |
|
|
157
|
+
| `janus.users.getAll` | `filterClientId` | `number` | Filter by assigned client |
|
|
158
|
+
|
|
159
|
+
## All Resources
|
|
160
|
+
|
|
161
|
+
| Resource | Access | Description |
|
|
162
|
+
|----------|--------|-------------|
|
|
163
|
+
| `janus.clients` | Auth | Client CRUD, courier services, return reasons, integrations, files |
|
|
164
|
+
| `janus.returns` | Auth | Returns CRUD, items, comments, statuses, reasons, categories, sources |
|
|
165
|
+
| `janus.orders` | Auth | Order queries, stats, returns, filter options, CRUD |
|
|
166
|
+
| `janus.reports` | Auth | Returns summary/reasons/overview/stats + CSV exports |
|
|
167
|
+
| `janus.products` | Auth | Product CRUD (preferred over legacy.queryProducts) |
|
|
168
|
+
| `janus.productCategories` | Auth | Product category CRUD |
|
|
169
|
+
| `janus.stocks` | Auth | Stock record CRUD |
|
|
170
|
+
| `janus.stockTransactions` | Auth | Stock movement CRUD |
|
|
171
|
+
| `janus.stockAllocations` | Auth | Stock allocation CRUD (no delete) |
|
|
172
|
+
| `janus.locations` | Auth | Warehouse location CRUD |
|
|
173
|
+
| `janus.audits` | Auth | Audit trail (read-only) |
|
|
174
|
+
| `janus.asns` | Auth | ASNs with nested lines and receipts |
|
|
175
|
+
| `janus.dispatches` | Auth | Dispatch CRUD |
|
|
176
|
+
| `janus.consignments` | Auth | Consignment tracking |
|
|
177
|
+
| `janus.invoices` | Auth | Invoices with nested line items |
|
|
178
|
+
| `janus.users` | Auth | User CRUD, password management |
|
|
179
|
+
| `janus.couriers` | Auth | Courier and service management |
|
|
180
|
+
| `janus.integrations` | Auth | Integration management |
|
|
181
|
+
| `janus.logs` | Auth | Activity and issue logging |
|
|
182
|
+
| `janus.tasks` | Auth | Task history |
|
|
183
|
+
| `janus.legacy` | Auth | Legacy couriers, post services, products (deprecated) |
|
|
184
|
+
| `janus.helpers` | Public | Client settings, notifications |
|
|
185
|
+
| `janus.customer` | Public | Customer tracking and login |
|
|
186
|
+
|
|
187
|
+
## Return Entity Fields
|
|
188
|
+
|
|
189
|
+
| Field | Type | Description |
|
|
190
|
+
|-------|------|-------------|
|
|
191
|
+
| `id` | `number` | Unique ID |
|
|
192
|
+
| `return_reference` | `string` | Return reference number |
|
|
193
|
+
| `wms_order_ref` | `string` | Original order reference |
|
|
194
|
+
| `customername` | `string` | Full customer name |
|
|
195
|
+
| `forename` | `string` | First name |
|
|
196
|
+
| `surname` | `string` | Last name |
|
|
197
|
+
| `email` | `string` | Customer email |
|
|
198
|
+
| `approval_status` | `string` | "pending", "approved", or "rejected" |
|
|
199
|
+
| `tracking_number` | `string` | Courier tracking number |
|
|
200
|
+
| `latestStatus` | `object` | `{ name: string }` — current status |
|
|
201
|
+
| `return_items` | `array` | Line items (when include_associations set) |
|
|
202
|
+
| `created_ts` | `string` | ISO timestamp |
|
|
203
|
+
| `updated_ts` | `string` | ISO timestamp |
|
|
204
|
+
|
|
205
|
+
## Order Entity Fields
|
|
206
|
+
|
|
207
|
+
| Field | Type | Description |
|
|
208
|
+
|-------|------|-------------|
|
|
209
|
+
| `id` | `number` | Order ID |
|
|
210
|
+
| `reference` | `string` | Order reference number |
|
|
211
|
+
| `channel` | `string` | Sales channel ("shopify", "amazon", etc.) |
|
|
212
|
+
| `transaction_type` | `string` | "b2c", "b2b", "internal_transfer", "damage", "expiry" |
|
|
213
|
+
| `orderDate` | `string` | ISO date when order was placed |
|
|
214
|
+
| `orderStatus` | `number` | Numeric status code |
|
|
215
|
+
| `notes` | `string` | Order notes |
|
|
216
|
+
| `hold` | `number` | 0 = not on hold, 1 = on hold |
|
|
217
|
+
| `draft` | `number` | 0 = confirmed, 1 = draft |
|
|
218
|
+
| `created` | `string` | ISO date when created |
|
|
219
|
+
| `modified` | `string` | ISO date when last modified |
|
|
220
|
+
| `orderItems` | `array` | Order line items |
|
|
221
|
+
| `dispatches` | `array` | Dispatch records |
|
|
222
|
+
|
|
223
|
+
## Product Entity Fields (from /products endpoint)
|
|
224
|
+
|
|
225
|
+
| Field | Type | Description |
|
|
226
|
+
|-------|------|-------------|
|
|
227
|
+
| `product_id` | `number` | Product ID |
|
|
228
|
+
| `client_id` | `number` | Client ID |
|
|
229
|
+
| `sku_code` | `string` | Product SKU |
|
|
230
|
+
| `product_name` | `string` | Product name |
|
|
231
|
+
| `description` | `string` | Product description |
|
|
232
|
+
| `barcode` | `string` | Barcode (EAN/UPC) |
|
|
233
|
+
| `price` | `number` | Unit price |
|
|
234
|
+
| `currency` | `string` | Currency code ("GBP", "USD") |
|
|
235
|
+
| `weight_grams` | `number` | Weight in grams |
|
|
236
|
+
| `product_status` | `string` | "active", "discontinued", "inactive", "archived" |
|
|
237
|
+
| `product_type` | `string` | "sellable_unit", "packaging", "component", "consumables" |
|
|
238
|
+
| `stock` | `number` | Current stock level |
|
|
239
|
+
| `image_url` | `string` | Product image URL |
|
|
240
|
+
| `low_stock_threshold` | `number` | Low stock alert threshold |
|
|
241
|
+
| `created_date` | `string` | ISO date |
|
|
242
|
+
| `updated_date` | `string` | ISO date |
|
|
243
|
+
|
|
244
|
+
## Stock Entity Fields
|
|
245
|
+
|
|
246
|
+
| Field | Type | Description |
|
|
247
|
+
|-------|------|-------------|
|
|
248
|
+
| `id` | `number` | Stock record ID |
|
|
249
|
+
| `clientId` | `number` | Client ID |
|
|
250
|
+
| `sku_code` | `string` | Product SKU |
|
|
251
|
+
| `location` | `string` | Storage location |
|
|
252
|
+
| `quantity` | `number` | Current quantity |
|
|
253
|
+
| `batch_number` | `string` | Batch/lot number |
|
|
254
|
+
| `serial_number` | `string` | Serial number |
|
|
255
|
+
| `best_before_date` | `string` | ISO date |
|
|
256
|
+
| `stock_status` | `string` | "available", "quarantined", "expired", "damaged", "reserved" |
|
|
257
|
+
| `fulfilment_location_name` | `string` | Warehouse name |
|
|
258
|
+
| `notes` | `string` | Notes |
|
|
259
|
+
|
|
260
|
+
## Invoice Entity Fields
|
|
261
|
+
|
|
262
|
+
| Field | Type | Description |
|
|
263
|
+
|-------|------|-------------|
|
|
264
|
+
| `id` | `number` | Invoice ID |
|
|
265
|
+
| `clientId` | `number` | Client ID |
|
|
266
|
+
| `invoice_date` | `string` | ISO date |
|
|
267
|
+
| `xero_reference` | `string` | Xero accounting reference |
|
|
268
|
+
| `total` | `number` | Total amount |
|
|
269
|
+
| `emailed` | `number` | 0 = not emailed, 1 = emailed |
|
|
270
|
+
| `paid` | `number` | 0 = unpaid, 1 = paid |
|
|
271
|
+
| `invoiceLines` | `array` | Line items |
|
|
272
|
+
|
|
273
|
+
## ReturnsStatsResponse Fields
|
|
274
|
+
|
|
275
|
+
```js
|
|
276
|
+
const stats = await janus.reports.returnsStats(clientId);
|
|
277
|
+
// stats = {
|
|
278
|
+
// total: 150,
|
|
279
|
+
// awaiting_processing: 12,
|
|
280
|
+
// in_progress: 25,
|
|
281
|
+
// completed: 100,
|
|
282
|
+
// awaiting_approval: 5,
|
|
283
|
+
// approved: 90,
|
|
284
|
+
// rejected: 8,
|
|
285
|
+
// by_status: { "Processing": 25, "Complete": 100, ... },
|
|
286
|
+
// by_reason: { "Faulty": 30, "Wrong item": 20, ... }
|
|
287
|
+
// }
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## OrdersStatsResponse Fields
|
|
291
|
+
|
|
292
|
+
```js
|
|
293
|
+
const stats = await janus.orders.getStats({ clientId, dashboard: true });
|
|
294
|
+
// Returns a flat object with numeric counts — keys vary by data.
|
|
295
|
+
// Use Object.entries(stats) to iterate. Do NOT hardcode field names.
|
|
296
|
+
// Example: { total_orders: 150, dispatched: 120, processing: 15, ... }
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## API Behaviour Notes
|
|
300
|
+
|
|
301
|
+
### Error response format
|
|
302
|
+
All errors follow this shape:
|
|
303
|
+
```json
|
|
304
|
+
{ "statusCode": 400, "message": "Error description" }
|
|
305
|
+
```
|
|
306
|
+
Common codes: 400 (bad request/validation), 401 (unauthorized), 404 (not found).
|
|
307
|
+
|
|
308
|
+
### Date formats
|
|
309
|
+
- **Query params:** ISO 8601 (`'2025-01-01'` or `'2025-01-01 12:00:00'`)
|
|
310
|
+
- **Response fields:** ISO 8601 timestamps (e.g. `created_ts`, `orderDate`, `created`)
|
|
311
|
+
- **CSV exports:** formatted as `DD-MM-YYYY HH:mm`
|
|
312
|
+
|
|
313
|
+
### Pagination defaults
|
|
314
|
+
- Default `pageSize`: 50 (v2 endpoints), varies for legacy
|
|
315
|
+
- Default `pageNumber`: 1 (1-based indexing)
|
|
316
|
+
- Default sort: DESC (newest first)
|
|
317
|
+
|
|
318
|
+
### Search behaviour (`query` param)
|
|
319
|
+
Free-text search is case-insensitive LIKE matching across key text columns:
|
|
320
|
+
- Products: searches `sku`, `name`, `description`
|
|
321
|
+
- Returns: searches order references, tracking numbers
|
|
322
|
+
- Clients: searches client names
|
|
323
|
+
|
|
324
|
+
### Returns default behaviour
|
|
325
|
+
- Archived returns (status 10) are **excluded by default** — pass `include_archived: true` to include them
|
|
326
|
+
- Returns with `return_type: 0` are regular returns, `return_type: 1` are exchanges
|
|
327
|
+
- `include_associations: 'return_items'` eagerly loads line items; `'return_items,return_comments'` loads both
|
|
328
|
+
|
|
329
|
+
### Stats responses
|
|
330
|
+
`getStats` endpoints return flat objects with numeric values. The keys vary based on the client's data. **Always use `Object.entries(stats)` to iterate — never hardcode expected keys.**
|
|
331
|
+
|
|
332
|
+
## Common Patterns
|
|
333
|
+
|
|
334
|
+
### Paginated list query
|
|
335
|
+
```js
|
|
336
|
+
const { data, meta } = await janus.products.getAll({
|
|
337
|
+
clientId,
|
|
338
|
+
pageSize: 25,
|
|
339
|
+
pageNumber: 1,
|
|
340
|
+
orderDirection: 'DESC',
|
|
341
|
+
query: searchText,
|
|
342
|
+
});
|
|
343
|
+
// meta = { total_items, total_pages, current_page, page_size }
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### CSV export
|
|
347
|
+
```js
|
|
348
|
+
const csv = await janus.reports.returnsSummaryCsv({ clientId, createdFrom, createdTo });
|
|
349
|
+
const blob = new Blob([csv], { type: 'text/csv' });
|
|
350
|
+
const url = URL.createObjectURL(blob);
|
|
351
|
+
const a = document.createElement('a');
|
|
352
|
+
a.href = url;
|
|
353
|
+
a.download = 'export.csv';
|
|
354
|
+
a.click();
|
|
355
|
+
URL.revokeObjectURL(url);
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Login page
|
|
359
|
+
```jsx
|
|
360
|
+
import { LoginForm } from '@pelygo/auth/react';
|
|
361
|
+
|
|
362
|
+
<LoginForm
|
|
363
|
+
onSuccess={() => setTimeout(() => { window.location.href = '/clients'; }, 100)}
|
|
364
|
+
onError={(error) => console.log('Login error:', error)}
|
|
365
|
+
/>
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Client selection
|
|
369
|
+
```jsx
|
|
370
|
+
import { SelectClientForm } from '@pelygo/auth/react';
|
|
371
|
+
|
|
372
|
+
<SelectClientForm
|
|
373
|
+
onSelect={() => setTimeout(() => { window.location.href = '/dashboard'; }, 100)}
|
|
374
|
+
/>
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Route guard (must check isLoading)
|
|
378
|
+
```jsx
|
|
379
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
380
|
+
const { requiresClientSelection, hasSelectedClient } = useClient();
|
|
381
|
+
|
|
382
|
+
if (isLoading) return <LoadingSpinner />;
|
|
383
|
+
if (!isAuthenticated) return <Navigate to="/SignIn" replace />;
|
|
384
|
+
if (requiresClientSelection && !hasSelectedClient) return <Navigate to="/clients" replace />;
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### Logout
|
|
388
|
+
```jsx
|
|
389
|
+
onClick={() => {
|
|
390
|
+
logout();
|
|
391
|
+
setTimeout(() => { window.location.href = '/SignIn'; }, 100);
|
|
392
|
+
}}
|
|
393
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1897,6 +1897,29 @@ export declare interface JanusApiOptions {
|
|
|
1897
1897
|
onLoginSuccess?: (token: string) => void;
|
|
1898
1898
|
/** Called on login failure */
|
|
1899
1899
|
onLoginError?: (error: Error) => void;
|
|
1900
|
+
/**
|
|
1901
|
+
* Allow write operations (POST, PUT, PATCH, DELETE).
|
|
1902
|
+
*
|
|
1903
|
+
* By default the client is **read-only** — any attempt to create, update,
|
|
1904
|
+
* or delete data will throw an error. Set this to `true` to enable write
|
|
1905
|
+
* operations.
|
|
1906
|
+
*
|
|
1907
|
+
* Query-style POST endpoints (e.g. `/returns/query`, `/legacy/products/query`)
|
|
1908
|
+
* and authentication endpoints (e.g. `/auth/login`) are always allowed
|
|
1909
|
+
* regardless of this setting.
|
|
1910
|
+
*
|
|
1911
|
+
* @default false
|
|
1912
|
+
*
|
|
1913
|
+
* @example
|
|
1914
|
+
* ```typescript
|
|
1915
|
+
* // Read-only (default) — getAll, query, getById work; create, update, delete throw
|
|
1916
|
+
* const janus = createJanusApi({ baseUrl: '...' });
|
|
1917
|
+
*
|
|
1918
|
+
* // Full access — all operations allowed
|
|
1919
|
+
* const janus = createJanusApi({ baseUrl: '...', allowWrites: true });
|
|
1920
|
+
* ```
|
|
1921
|
+
*/
|
|
1922
|
+
allowWrites?: boolean;
|
|
1900
1923
|
}
|
|
1901
1924
|
|
|
1902
1925
|
/**
|
|
@@ -2461,9 +2484,24 @@ export declare interface OrdersQueryFilters extends BaseFilters {
|
|
|
2461
2484
|
* Orders resource interface
|
|
2462
2485
|
*/
|
|
2463
2486
|
export declare interface OrdersResource {
|
|
2464
|
-
/**
|
|
2487
|
+
/**
|
|
2488
|
+
* Get all orders with optional query filters (client, date range, status, etc.)
|
|
2489
|
+
*
|
|
2490
|
+
* @example
|
|
2491
|
+
* const orders = await janus.orders.getAll({ clientId, pageSize: 25 });
|
|
2492
|
+
* // Each order has: id, reference, channel, transaction_type, orderDate,
|
|
2493
|
+
* // orderStatus, notes, hold, draft, created, modified,
|
|
2494
|
+
* // orderItems (array), dispatches (array)
|
|
2495
|
+
*/
|
|
2465
2496
|
getAll(filters?: OrdersQueryFilters): Promise<unknown[]>;
|
|
2466
|
-
/**
|
|
2497
|
+
/**
|
|
2498
|
+
* Get aggregated order statistics (counts, totals) with optional filters
|
|
2499
|
+
*
|
|
2500
|
+
* @example
|
|
2501
|
+
* const stats = await janus.orders.getStats({ clientId, dashboard: true });
|
|
2502
|
+
* // Returns a flat object with numeric counts — keys vary by data.
|
|
2503
|
+
* // Use Object.entries(stats) to iterate. Do NOT hardcode field names.
|
|
2504
|
+
*/
|
|
2467
2505
|
getStats(filters?: OrdersStatsFilters): Promise<OrdersStatsResponse>;
|
|
2468
2506
|
/** Get orders that have associated returns, with optional return-specific filters */
|
|
2469
2507
|
getReturns(filters?: OrderReturnsFilters): Promise<unknown[]>;
|
|
@@ -2606,7 +2644,16 @@ export declare interface ProductCategory extends BaseEntity_2 {
|
|
|
2606
2644
|
* Products resource interface
|
|
2607
2645
|
*/
|
|
2608
2646
|
export declare interface ProductsResource {
|
|
2609
|
-
/**
|
|
2647
|
+
/**
|
|
2648
|
+
* Get all products with optional filters
|
|
2649
|
+
*
|
|
2650
|
+
* @example
|
|
2651
|
+
* const { data, meta } = await janus.products.getAll({ clientId, pageSize: 25 });
|
|
2652
|
+
* // Each product has: product_id, client_id, sku_code, product_name,
|
|
2653
|
+
* // description, barcode, price, currency, product_status, stock,
|
|
2654
|
+
* // weight_grams, image_url, product_category_id, created_date, updated_date
|
|
2655
|
+
* // meta has: total_items, total_pages, current_page, page_size
|
|
2656
|
+
*/
|
|
2610
2657
|
getAll(filters: ClientScopedPaginatedQueryFilters): Promise<PaginatedListResponse<FormattedProduct>>;
|
|
2611
2658
|
/** Get a product by ID */
|
|
2612
2659
|
getById(id: number): Promise<FormattedProduct>;
|
|
@@ -2634,7 +2681,14 @@ export declare interface ReportsResource {
|
|
|
2634
2681
|
returnsOverview(filters?: ReturnsOverviewFilters): Promise<unknown>;
|
|
2635
2682
|
/** Get returns overview as CSV */
|
|
2636
2683
|
returnsOverviewCsv(filters?: ReturnsOverviewFilters): Promise<string>;
|
|
2637
|
-
/**
|
|
2684
|
+
/**
|
|
2685
|
+
* Get returns statistics for a client
|
|
2686
|
+
*
|
|
2687
|
+
* @example
|
|
2688
|
+
* const stats = await janus.reports.returnsStats(clientId);
|
|
2689
|
+
* // Returns: { total, awaiting_processing, in_progress, completed,
|
|
2690
|
+
* // awaiting_approval, approved, rejected, by_status, by_reason }
|
|
2691
|
+
*/
|
|
2638
2692
|
returnsStats(clientId: number): Promise<ReturnsStatsResponse>;
|
|
2639
2693
|
}
|
|
2640
2694
|
|
|
@@ -2873,7 +2927,16 @@ export declare interface ReturnsReasonsFilters extends BaseFilters {
|
|
|
2873
2927
|
* Returns resource interface
|
|
2874
2928
|
*/
|
|
2875
2929
|
export declare interface ReturnsResource {
|
|
2876
|
-
/**
|
|
2930
|
+
/**
|
|
2931
|
+
* Query returns with filters
|
|
2932
|
+
*
|
|
2933
|
+
* @example
|
|
2934
|
+
* const returns = await janus.returns.query({ clientId, page: 1, pageSize: 25 });
|
|
2935
|
+
* // Each return has: id, return_reference, wms_order_ref, customername,
|
|
2936
|
+
* // forename, surname, email, approval_status, tracking_number,
|
|
2937
|
+
* // created_ts, updated_ts, latestStatus (object with .name),
|
|
2938
|
+
* // return_items (array, when include_associations set)
|
|
2939
|
+
*/
|
|
2877
2940
|
query(filters?: ReturnsQueryFilters): Promise<Return[]>;
|
|
2878
2941
|
/** Query returns with HTTP query body */
|
|
2879
2942
|
queryPost(query: HttpQueryRequest): Promise<Return[]>;
|
|
@@ -3175,7 +3238,15 @@ export declare interface StockAllocationsResource {
|
|
|
3175
3238
|
* Stocks resource interface
|
|
3176
3239
|
*/
|
|
3177
3240
|
export declare interface StocksResource {
|
|
3178
|
-
/**
|
|
3241
|
+
/**
|
|
3242
|
+
* Get all stock records with optional filters
|
|
3243
|
+
*
|
|
3244
|
+
* @example
|
|
3245
|
+
* const { data, meta } = await janus.stocks.getAll({ clientId, pageSize: 25 });
|
|
3246
|
+
* // Each stock record has: id, clientId, sku_code, location, quantity,
|
|
3247
|
+
* // batch_number, serial_number, best_before_date, stock_status,
|
|
3248
|
+
* // fulfilment_location_id, fulfilment_location_name, notes
|
|
3249
|
+
*/
|
|
3179
3250
|
getAll(filters: ClientScopedPaginatedQueryFilters): Promise<PaginatedListResponse<Stock>>;
|
|
3180
3251
|
/** Get a stock record by ID */
|
|
3181
3252
|
getById(id: number): Promise<Stock>;
|