@pelygo/janus 0.1.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 +264 -0
- package/dist/index.d.ts +1037 -0
- package/dist/index.js +257 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# @pelygo/janus
|
|
2
|
+
|
|
3
|
+
TypeScript API client for JANUS (VCOMSUITE backend) endpoints with full type safety.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @pelygo/janus @pelygo/auth
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createJanusApi } from '@pelygo/janus';
|
|
15
|
+
|
|
16
|
+
// Create API instance
|
|
17
|
+
const janus = createJanusApi({
|
|
18
|
+
baseUrl: 'https://api.janus.pelygo.com',
|
|
19
|
+
onUnauthorized: () => {
|
|
20
|
+
// Handle session expiry (redirect to login, etc.)
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Authenticate
|
|
25
|
+
await janus.auth.login('username', 'password');
|
|
26
|
+
|
|
27
|
+
// Use typed resources
|
|
28
|
+
const clients = await janus.clients.getAll();
|
|
29
|
+
const returns = await janus.returns.query({ clientId: 5, pageSize: 50 });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API Reference
|
|
33
|
+
|
|
34
|
+
### Creating the Client
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const janus = createJanusApi({
|
|
38
|
+
baseUrl: string; // JANUS API base URL
|
|
39
|
+
onUnauthorized?: () => void; // Called on 401 responses
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Authentication
|
|
44
|
+
|
|
45
|
+
The client wraps `@pelygo/auth` for authentication:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// Login
|
|
49
|
+
await janus.auth.login(username, password);
|
|
50
|
+
|
|
51
|
+
// Get current user
|
|
52
|
+
const user = await janus.auth.getUser();
|
|
53
|
+
|
|
54
|
+
// Logout
|
|
55
|
+
await janus.auth.logout();
|
|
56
|
+
|
|
57
|
+
// Check if authenticated
|
|
58
|
+
const isLoggedIn = janus.auth.isAuthenticated();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Clients Resource
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// Get all clients
|
|
65
|
+
const clients = await janus.clients.getAll();
|
|
66
|
+
|
|
67
|
+
// Get single client
|
|
68
|
+
const client = await janus.clients.getById(5);
|
|
69
|
+
|
|
70
|
+
// Update client
|
|
71
|
+
const updated = await janus.clients.update(5, { name: 'New Name' });
|
|
72
|
+
|
|
73
|
+
// Get courier services for client
|
|
74
|
+
const services = await janus.clients.getCourierServices(5);
|
|
75
|
+
const service = await janus.clients.getCourierServiceById(5, serviceId);
|
|
76
|
+
await janus.clients.updateCourierService(5, serviceId, { active: true });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Returns Resource
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Query returns with filters
|
|
83
|
+
const returns = await janus.returns.query({
|
|
84
|
+
clientId: 5,
|
|
85
|
+
last_status_ids: '1,2,3',
|
|
86
|
+
created_at: '2024-01-01',
|
|
87
|
+
created_to: '2024-12-31',
|
|
88
|
+
pageSize: 100,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Get single return with items
|
|
92
|
+
const ret = await janus.returns.getById(123, { includeAssociations: true });
|
|
93
|
+
|
|
94
|
+
// Create a return
|
|
95
|
+
const newReturn = await janus.returns.create({
|
|
96
|
+
client_id: 5,
|
|
97
|
+
customer_name: 'John Doe',
|
|
98
|
+
// ...
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Update a return
|
|
102
|
+
await janus.returns.update(123, { customer_name: 'Jane Doe' });
|
|
103
|
+
|
|
104
|
+
// Delete a return
|
|
105
|
+
await janus.returns.delete(123);
|
|
106
|
+
|
|
107
|
+
// Manage statuses
|
|
108
|
+
await janus.returns.addStatus(123, statusId);
|
|
109
|
+
await janus.returns.removeStatus(123, statusId);
|
|
110
|
+
const statuses = await janus.returns.getStatuses(123);
|
|
111
|
+
|
|
112
|
+
// Manage comments
|
|
113
|
+
await janus.returns.addComment(123, 'Comment text');
|
|
114
|
+
await janus.returns.removeComment(123, commentId);
|
|
115
|
+
const comments = await janus.returns.getComments(123);
|
|
116
|
+
|
|
117
|
+
// Manage items
|
|
118
|
+
const items = await janus.returns.getItems(123);
|
|
119
|
+
await janus.returns.addItem(123, { wms_product_sku: 'SKU123', qty: 2 });
|
|
120
|
+
await janus.returns.updateItem(123, itemId, { qty: 3 });
|
|
121
|
+
|
|
122
|
+
// Approval workflow
|
|
123
|
+
await janus.returns.setApproval(123, true); // Approve
|
|
124
|
+
await janus.returns.setApproval(123, false); // Reject
|
|
125
|
+
|
|
126
|
+
// Reference data
|
|
127
|
+
const reasons = await janus.returns.getReasons();
|
|
128
|
+
const allStatuses = await janus.returns.getAllStatuses();
|
|
129
|
+
const filterOptions = await janus.returns.getFilterOptions(5);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Reports Resource
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// Returns summary report
|
|
136
|
+
const summary = await janus.reports.returnsSummary({
|
|
137
|
+
clientId: 5,
|
|
138
|
+
created_at: '2024-01-01',
|
|
139
|
+
created_to: '2024-12-31',
|
|
140
|
+
groupBy: 'month',
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// CSV export
|
|
144
|
+
const csvData = await janus.reports.returnsSummaryCsv({ clientId: 5 });
|
|
145
|
+
|
|
146
|
+
// Returns by reason
|
|
147
|
+
const reasonReport = await janus.reports.returnsReasons({ clientId: 5 });
|
|
148
|
+
const reasonCsv = await janus.reports.returnsReasonsCsv({ clientId: 5 });
|
|
149
|
+
|
|
150
|
+
// Returns overview
|
|
151
|
+
const overview = await janus.reports.returnsOverview({ clientId: 5 });
|
|
152
|
+
const overviewCsv = await janus.reports.returnsOverviewCsv({ clientId: 5 });
|
|
153
|
+
|
|
154
|
+
// Statistics
|
|
155
|
+
const stats = await janus.reports.returnsStats(5);
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Helpers Resource (Public Endpoints)
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// Submit return portal form (no auth required)
|
|
162
|
+
const result = await janus.helpers.submitReturnPortalForm(formData);
|
|
163
|
+
|
|
164
|
+
// Get notification settings
|
|
165
|
+
const settings = await janus.helpers.getNotificationSettings(clientId);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Types
|
|
169
|
+
|
|
170
|
+
All entity types are exported and can be imported:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import type {
|
|
174
|
+
Client,
|
|
175
|
+
Return,
|
|
176
|
+
ReturnItem,
|
|
177
|
+
ReturnStatus,
|
|
178
|
+
ReturnReason,
|
|
179
|
+
User,
|
|
180
|
+
// ... more types
|
|
181
|
+
} from '@pelygo/janus';
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Filter Types
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import type { ReturnsQueryParams, ReportFilters } from '@pelygo/janus';
|
|
188
|
+
|
|
189
|
+
const filters: ReturnsQueryParams = {
|
|
190
|
+
clientId: 5,
|
|
191
|
+
last_status_ids: '1,2',
|
|
192
|
+
pageSize: 50,
|
|
193
|
+
};
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Install dependencies
|
|
200
|
+
npm install
|
|
201
|
+
|
|
202
|
+
# Run tests
|
|
203
|
+
npm run test
|
|
204
|
+
|
|
205
|
+
# Run tests once
|
|
206
|
+
npm run test:run
|
|
207
|
+
|
|
208
|
+
# Type check
|
|
209
|
+
npm run typecheck
|
|
210
|
+
|
|
211
|
+
# Build
|
|
212
|
+
npm run build
|
|
213
|
+
|
|
214
|
+
# Generate entity types from v2 TypeORM entities
|
|
215
|
+
npm run generate-types
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Integration Tests
|
|
219
|
+
|
|
220
|
+
To run integration tests against a real JANUS API, set environment variables:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
export JANUS_API_URL="https://api.janus.dev.pelygo.com"
|
|
224
|
+
export JANUS_TEST_USERNAME="testuser"
|
|
225
|
+
export JANUS_TEST_PASSWORD="testpass"
|
|
226
|
+
export JANUS_TEST_CLIENT_ID="5"
|
|
227
|
+
|
|
228
|
+
npm run test:integration
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Architecture
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
src/
|
|
235
|
+
├── index.ts # Main exports
|
|
236
|
+
├── client.ts # createJanusApi() factory
|
|
237
|
+
├── types/
|
|
238
|
+
│ ├── entities/ # Generated entity interfaces
|
|
239
|
+
│ ├── filters.ts # Query filter types
|
|
240
|
+
│ └── responses.ts # API response types
|
|
241
|
+
├── resources/
|
|
242
|
+
│ ├── clients.ts # Clients API
|
|
243
|
+
│ ├── returns.ts # Returns API
|
|
244
|
+
│ ├── reports.ts # Reports API
|
|
245
|
+
│ └── helpers.ts # Public endpoints
|
|
246
|
+
└── utils/
|
|
247
|
+
└── query-builder.ts # URL query string builder
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Base44 Integration
|
|
251
|
+
|
|
252
|
+
For Base44 applications, see the **[Base44 Integration Guide](docs/BASE44_GUIDE.md)** which includes:
|
|
253
|
+
|
|
254
|
+
- Installation and setup for Base44
|
|
255
|
+
- AI prompt examples for generating pages
|
|
256
|
+
- Common patterns and code snippets
|
|
257
|
+
|
|
258
|
+
## Related Packages
|
|
259
|
+
|
|
260
|
+
- [@pelygo/auth](https://www.npmjs.com/package/@pelygo/auth) - Authentication client (peer dependency)
|
|
261
|
+
|
|
262
|
+
## License
|
|
263
|
+
|
|
264
|
+
See LICENSE file.
|