@proveanything/smartlinks 2.1.17 → 2.1.19
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/dist/adminViews.d.ts +104 -0
- package/dist/adminViews.js +275 -0
- package/dist/api/ai.d.ts +15 -5
- package/dist/api/ai.js +15 -9
- package/dist/api/aiGuide.d.ts +108 -0
- package/dist/api/aiGuide.js +161 -0
- package/dist/api/appObjects.d.ts +21 -0
- package/dist/api/appObjects.js +33 -1
- package/dist/api/authKit.d.ts +37 -1
- package/dist/api/authKit.js +51 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/api/operations.d.ts +36 -0
- package/dist/api/operations.js +56 -0
- package/dist/api/order.d.ts +12 -1
- package/dist/api/order.js +15 -0
- package/dist/api/userGroups.d.ts +78 -0
- package/dist/api/userGroups.js +124 -0
- package/dist/docs/API_SUMMARY.md +1111 -80
- package/dist/docs/admin-lists-and-pickers.md +140 -0
- package/dist/docs/admin-views.md +147 -0
- package/dist/docs/app-data-storage.md +277 -276
- package/dist/docs/app-manifest.md +2 -0
- package/dist/docs/auth-kit.md +872 -741
- package/dist/docs/comms.md +686 -644
- package/dist/docs/customer-guide.md +70 -0
- package/dist/docs/headless-providers.md +112 -112
- package/dist/docs/operations.md +281 -0
- package/dist/docs/overview.md +3 -0
- package/dist/docs/server-functions.md +87 -1
- package/dist/docs/ui-utils.md +123 -121
- package/dist/docs/user-groups.md +175 -0
- package/dist/docs/utils.md +17 -0
- package/dist/headless.js +38 -2
- package/dist/http.js +8 -0
- package/dist/iframeResponder.d.ts +15 -0
- package/dist/iframeResponder.js +39 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/live.d.ts +80 -0
- package/dist/live.js +315 -0
- package/dist/openapi.yaml +1864 -48
- package/dist/testing/index.d.ts +35 -0
- package/dist/testing/index.js +86 -0
- package/dist/types/appManifest.d.ts +297 -1
- package/dist/types/appOptions.d.ts +32 -0
- package/dist/types/appOptions.js +3 -0
- package/dist/types/authKit.d.ts +193 -4
- package/dist/types/comms.d.ts +41 -2
- package/dist/types/containers.d.ts +8 -0
- package/dist/types/headless.d.ts +49 -1
- package/dist/types/iframeResponder.d.ts +16 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/operations.d.ts +598 -0
- package/dist/types/operations.js +8 -0
- package/dist/types/order.d.ts +35 -6
- package/dist/types/userGroups.d.ts +103 -0
- package/dist/types/userGroups.js +5 -0
- package/dist/utils/conditions.d.ts +7 -0
- package/dist/utils/conditions.js +16 -9
- package/docs/API_SUMMARY.md +1111 -80
- package/docs/admin-lists-and-pickers.md +140 -0
- package/docs/admin-views.md +147 -0
- package/docs/app-data-storage.md +277 -276
- package/docs/app-manifest.md +2 -0
- package/docs/auth-kit.md +872 -741
- package/docs/comms.md +686 -644
- package/docs/customer-guide.md +70 -0
- package/docs/headless-providers.md +112 -112
- package/docs/operations.md +281 -0
- package/docs/overview.md +3 -0
- package/docs/server-functions.md +87 -1
- package/docs/ui-utils.md +123 -121
- package/docs/user-groups.md +175 -0
- package/docs/utils.md +17 -0
- package/openapi.yaml +1864 -48
- package/package.json +1 -1
- package/scripts/doctor.mjs +454 -428
- package/scripts/lib/keyed-app-data.mjs +21 -0
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operations: work orders, stock, bills of materials and made-from. See docs/operations.md.
|
|
3
|
+
*
|
|
4
|
+
* The same calls are reached two ways, with the same shapes:
|
|
5
|
+
* - in a server function: ctx.sl.workOrders / ctx.sl.stock / ctx.sl.boms / ctx.sl.madeFrom / ctx.sl.operations
|
|
6
|
+
* - from an admin screen: operations.admin(collectionId) → { workOrders, stock, boms, madeFrom, transaction }
|
|
7
|
+
*/
|
|
8
|
+
export type WorkOrderStatus = 'open' | 'on-hold' | 'blocked' | 'done' | 'cancelled';
|
|
9
|
+
export type WorkOrderStageStatus = 'pending' | 'active' | 'done' | 'skipped';
|
|
10
|
+
export interface WorkOrderStage {
|
|
11
|
+
/** The app's name for the stage: `'filling'`. Lowercase letters, digits and `. _ -`. */
|
|
12
|
+
key: string;
|
|
13
|
+
position: number;
|
|
14
|
+
status: WorkOrderStageStatus;
|
|
15
|
+
plannedStart: string | null;
|
|
16
|
+
plannedEnd: string | null;
|
|
17
|
+
startedAt: string | null;
|
|
18
|
+
doneAt: string | null;
|
|
19
|
+
quantityDone: number;
|
|
20
|
+
quantityScrapped: number;
|
|
21
|
+
data: Record<string, any>;
|
|
22
|
+
}
|
|
23
|
+
/** The shared skeleton of a "job": what is being made, how many, by when, and where it has got to. */
|
|
24
|
+
export interface WorkOrder {
|
|
25
|
+
id: string;
|
|
26
|
+
collectionId: string;
|
|
27
|
+
/** The app that owns its rules. Any app may read it; only this one (or an admin) may change it. */
|
|
28
|
+
appId: string;
|
|
29
|
+
/** The number people use. Unique among the collection's live work orders, whatever the case. */
|
|
30
|
+
ref: string;
|
|
31
|
+
kind: string | null;
|
|
32
|
+
productId: string | null;
|
|
33
|
+
variantId: string | null;
|
|
34
|
+
quantity: number;
|
|
35
|
+
unit: string;
|
|
36
|
+
dueAt: string | null;
|
|
37
|
+
priority: number;
|
|
38
|
+
status: WorkOrderStatus;
|
|
39
|
+
statusReason: string | null;
|
|
40
|
+
/** The order, and the line, it fulfils. */
|
|
41
|
+
orderId: string | null;
|
|
42
|
+
orderItemId: string | null;
|
|
43
|
+
/** The work order it was split from. */
|
|
44
|
+
parentId: string | null;
|
|
45
|
+
/** The batch it makes. */
|
|
46
|
+
outputBatchId: string | null;
|
|
47
|
+
stages: WorkOrderStage[];
|
|
48
|
+
/** The stage in hand: the active one, else the next pending one, else null. */
|
|
49
|
+
currentStage: string | null;
|
|
50
|
+
/** Past its due date and not finished or cancelled. */
|
|
51
|
+
late: boolean;
|
|
52
|
+
/** Whatever else the app keeps on it. */
|
|
53
|
+
data: Record<string, any>;
|
|
54
|
+
createdBy: string | null;
|
|
55
|
+
createdAt: string;
|
|
56
|
+
updatedAt: string;
|
|
57
|
+
closedAt: string | null;
|
|
58
|
+
}
|
|
59
|
+
export type WorkOrderStageInput = string | {
|
|
60
|
+
key: string;
|
|
61
|
+
plannedStart?: string | null;
|
|
62
|
+
plannedEnd?: string | null;
|
|
63
|
+
data?: Record<string, any>;
|
|
64
|
+
};
|
|
65
|
+
export interface CreateWorkOrderInput {
|
|
66
|
+
ref: string;
|
|
67
|
+
kind?: string;
|
|
68
|
+
productId?: string;
|
|
69
|
+
variantId?: string;
|
|
70
|
+
quantity?: number;
|
|
71
|
+
unit?: string;
|
|
72
|
+
dueAt?: string | null;
|
|
73
|
+
priority?: number;
|
|
74
|
+
orderId?: string;
|
|
75
|
+
orderItemId?: string;
|
|
76
|
+
parentId?: string;
|
|
77
|
+
outputBatchId?: string;
|
|
78
|
+
data?: Record<string, any>;
|
|
79
|
+
/** In order. Nothing starts by itself: the app starts a stage when its own rule says so. */
|
|
80
|
+
stages?: WorkOrderStageInput[];
|
|
81
|
+
}
|
|
82
|
+
/** `data` is merged into what is there. A change of `quantity` needs `{ reason }`. */
|
|
83
|
+
export type UpdateWorkOrderInput = Partial<Omit<CreateWorkOrderInput, 'ref' | 'stages' | 'parentId'>>;
|
|
84
|
+
export interface WorkOrderListParams {
|
|
85
|
+
status?: WorkOrderStatus | WorkOrderStatus[];
|
|
86
|
+
appId?: string;
|
|
87
|
+
productId?: string;
|
|
88
|
+
orderId?: string;
|
|
89
|
+
parentId?: string;
|
|
90
|
+
kind?: string;
|
|
91
|
+
/** Past due and still open, on hold or blocked. */
|
|
92
|
+
late?: boolean;
|
|
93
|
+
dueFrom?: string;
|
|
94
|
+
dueTo?: string;
|
|
95
|
+
/** Text in the ref. */
|
|
96
|
+
q?: string;
|
|
97
|
+
sort?: 'due' | 'priority' | 'created' | 'ref';
|
|
98
|
+
limit?: number;
|
|
99
|
+
offset?: number;
|
|
100
|
+
}
|
|
101
|
+
export interface WorkOrdersApi {
|
|
102
|
+
/** By id or by ref. → null when there is none. */
|
|
103
|
+
get(idOrRef: string): Promise<WorkOrder | null>;
|
|
104
|
+
list(params?: WorkOrderListParams): Promise<{
|
|
105
|
+
items: WorkOrder[];
|
|
106
|
+
total: number;
|
|
107
|
+
limit: number;
|
|
108
|
+
offset: number;
|
|
109
|
+
}>;
|
|
110
|
+
/** @throws `REF_TAKEN` (409) */
|
|
111
|
+
create(input: CreateWorkOrderInput): Promise<WorkOrder>;
|
|
112
|
+
/** @throws `REASON_REQUIRED` when the quantity changes without a reason */
|
|
113
|
+
update(idOrRef: string, patch: UpdateWorkOrderInput, opts?: {
|
|
114
|
+
reason?: string;
|
|
115
|
+
}): Promise<WorkOrder>;
|
|
116
|
+
/**
|
|
117
|
+
* Hold it, block it, finish it, cancel it, or open it again. `on-hold`, `blocked` and `cancelled` need
|
|
118
|
+
* a reason. While it isn't `open` it is FROZEN: no stage can start, progress or finish, and no stock
|
|
119
|
+
* can be moved for it (`WORK_ORDER_FROZEN`, 409).
|
|
120
|
+
*/
|
|
121
|
+
setStatus(idOrRef: string, status: WorkOrderStatus, opts?: {
|
|
122
|
+
reason?: string;
|
|
123
|
+
}): Promise<WorkOrder>;
|
|
124
|
+
remove(idOrRef: string): Promise<{
|
|
125
|
+
id: string;
|
|
126
|
+
deleted: true;
|
|
127
|
+
}>;
|
|
128
|
+
startStage(idOrRef: string, stage: string): Promise<WorkOrder>;
|
|
129
|
+
/**
|
|
130
|
+
* Add to (or, with a reason, take from) what a stage has done and scrapped. Atomic: two people logging
|
|
131
|
+
* at once both count, and neither figure goes below zero (`BELOW_ZERO`). It doesn't finish the stage.
|
|
132
|
+
*/
|
|
133
|
+
progress(idOrRef: string, stage: string, by: {
|
|
134
|
+
done?: number;
|
|
135
|
+
scrapped?: number;
|
|
136
|
+
}, opts?: {
|
|
137
|
+
reason?: string;
|
|
138
|
+
note?: string;
|
|
139
|
+
}): Promise<WorkOrder>;
|
|
140
|
+
completeStage(idOrRef: string, stage: string, opts?: {
|
|
141
|
+
closeWorkOrder?: boolean;
|
|
142
|
+
}): Promise<WorkOrder>;
|
|
143
|
+
skipStage(idOrRef: string, stage: string, opts: {
|
|
144
|
+
reason: string;
|
|
145
|
+
}): Promise<WorkOrder>;
|
|
146
|
+
/** Allowed while on hold (you can reschedule something that's waiting). */
|
|
147
|
+
planStage(idOrRef: string, stage: string, plan: {
|
|
148
|
+
plannedStart?: string | null;
|
|
149
|
+
plannedEnd?: string | null;
|
|
150
|
+
data?: Record<string, any>;
|
|
151
|
+
}): Promise<WorkOrder>;
|
|
152
|
+
/** Replace the list. A stage that has started, finished or been skipped can't be dropped (`STAGE_IN_USE`). */
|
|
153
|
+
setStages(idOrRef: string, stages: WorkOrderStageInput[]): Promise<WorkOrder>;
|
|
154
|
+
}
|
|
155
|
+
export type StockState = 'available' | 'allocated' | 'held' | 'quarantine';
|
|
156
|
+
/** What stock is set aside for: `{ type: 'workOrder', id }`, `{ type: 'orderItem', id }`, or an app's own. */
|
|
157
|
+
export interface StockTarget {
|
|
158
|
+
type: string;
|
|
159
|
+
id: string;
|
|
160
|
+
}
|
|
161
|
+
/** A quantity of one product, in one container, in one state. */
|
|
162
|
+
export interface StockLine {
|
|
163
|
+
id: string;
|
|
164
|
+
containerId: string;
|
|
165
|
+
productId: string;
|
|
166
|
+
variantId: string | null;
|
|
167
|
+
batchId: string | null;
|
|
168
|
+
state: StockState;
|
|
169
|
+
allocatedTo: StockTarget | null;
|
|
170
|
+
quantity: number;
|
|
171
|
+
unit: string;
|
|
172
|
+
updatedAt: string;
|
|
173
|
+
}
|
|
174
|
+
export interface StockTotals {
|
|
175
|
+
available: number;
|
|
176
|
+
allocated: number;
|
|
177
|
+
held: number;
|
|
178
|
+
quarantine: number;
|
|
179
|
+
total: number;
|
|
180
|
+
unit: string | null;
|
|
181
|
+
}
|
|
182
|
+
/** What is being moved. A product is held in ONE unit across the collection (`UNIT_MISMATCH`). */
|
|
183
|
+
export interface StockItem {
|
|
184
|
+
productId: string;
|
|
185
|
+
variantId?: string;
|
|
186
|
+
batchId?: string;
|
|
187
|
+
quantity: number;
|
|
188
|
+
unit?: string;
|
|
189
|
+
}
|
|
190
|
+
/** Common to every movement. `workOrderId`: refused while that work order isn't open. */
|
|
191
|
+
export interface StockMovementExtras {
|
|
192
|
+
workOrderId?: string;
|
|
193
|
+
reason?: string;
|
|
194
|
+
note?: string;
|
|
195
|
+
}
|
|
196
|
+
/** `idempotencyKey`: the same movement sent twice (a scanner retrying) happens once. */
|
|
197
|
+
export interface StockMovementOptions {
|
|
198
|
+
idempotencyKey?: string;
|
|
199
|
+
}
|
|
200
|
+
export interface StockMovement {
|
|
201
|
+
movementId: string;
|
|
202
|
+
kind: 'receive' | 'produce' | 'consume' | 'move' | 'allocate' | 'release' | 'hold' | 'unhold' | 'adjust';
|
|
203
|
+
productId: string;
|
|
204
|
+
quantity: number;
|
|
205
|
+
unit: string;
|
|
206
|
+
/** The line it came off, as it is now (`emptied: true` when it reached zero and was removed). */
|
|
207
|
+
from?: (StockLine & {
|
|
208
|
+
emptied?: boolean;
|
|
209
|
+
}) | null;
|
|
210
|
+
/** The line it went onto, as it is now. */
|
|
211
|
+
to?: StockLine | null;
|
|
212
|
+
/** True when this key was already used: nothing moved this time. */
|
|
213
|
+
replayed: boolean;
|
|
214
|
+
}
|
|
215
|
+
export interface StockWhereLine extends StockLine {
|
|
216
|
+
container: {
|
|
217
|
+
id: string;
|
|
218
|
+
name: string | null;
|
|
219
|
+
ref: string | null;
|
|
220
|
+
type: string;
|
|
221
|
+
fixed: boolean;
|
|
222
|
+
} | null;
|
|
223
|
+
/** Names from the outermost container in: `['Warehouse A', 'Rack 3', 'Bin 12']`. */
|
|
224
|
+
path: string[];
|
|
225
|
+
/** The first fixed container on that path: the place it sits in. */
|
|
226
|
+
place: {
|
|
227
|
+
id: string;
|
|
228
|
+
name: string | null;
|
|
229
|
+
ref: string | null;
|
|
230
|
+
type: string;
|
|
231
|
+
fixed: boolean;
|
|
232
|
+
} | null;
|
|
233
|
+
}
|
|
234
|
+
/** One defined answer about a product: what there is, what is coming, what is needed, and when it runs short. */
|
|
235
|
+
export interface StockPosition {
|
|
236
|
+
product: {
|
|
237
|
+
id: string;
|
|
238
|
+
variantId: string | null;
|
|
239
|
+
name: string | null;
|
|
240
|
+
unit: string | null;
|
|
241
|
+
};
|
|
242
|
+
onHand: StockTotals;
|
|
243
|
+
where: Array<{
|
|
244
|
+
containerId: string;
|
|
245
|
+
container: StockWhereLine['container'];
|
|
246
|
+
path: string;
|
|
247
|
+
place: StockWhereLine['place'];
|
|
248
|
+
quantity: number;
|
|
249
|
+
batchId: string | null;
|
|
250
|
+
state: StockState;
|
|
251
|
+
allocatedTo: StockTarget | null;
|
|
252
|
+
}>;
|
|
253
|
+
/** Open purchase order lines. */
|
|
254
|
+
onOrder: {
|
|
255
|
+
total: number;
|
|
256
|
+
lines: Array<{
|
|
257
|
+
orderId: string;
|
|
258
|
+
orderRef: string | null;
|
|
259
|
+
supplier: string | null;
|
|
260
|
+
quantity: number;
|
|
261
|
+
dueAt: string | null;
|
|
262
|
+
}>;
|
|
263
|
+
};
|
|
264
|
+
/** Open work orders that make this product, and how many each still has to finish. */
|
|
265
|
+
beingMade: {
|
|
266
|
+
total: number;
|
|
267
|
+
lines: Array<{
|
|
268
|
+
workOrderId: string;
|
|
269
|
+
ref: string;
|
|
270
|
+
quantity: number;
|
|
271
|
+
stage: string | null;
|
|
272
|
+
status: WorkOrderStatus;
|
|
273
|
+
dueAt: string | null;
|
|
274
|
+
}>;
|
|
275
|
+
};
|
|
276
|
+
/** Wanted itself by customers, and as a component by work orders and by orders not yet in production. */
|
|
277
|
+
needed: {
|
|
278
|
+
total: number;
|
|
279
|
+
lines: Array<{
|
|
280
|
+
orderId?: string;
|
|
281
|
+
orderRef?: string | null;
|
|
282
|
+
workOrderId?: string;
|
|
283
|
+
ref?: string;
|
|
284
|
+
forProductId: string;
|
|
285
|
+
quantity: number;
|
|
286
|
+
neededBy: string | null;
|
|
287
|
+
why: 'ordered' | 'work order' | 'order, not yet in production';
|
|
288
|
+
}>;
|
|
289
|
+
};
|
|
290
|
+
/** Available now, then the balance after each day on which something arrives or is needed. */
|
|
291
|
+
projected: Array<{
|
|
292
|
+
date: string;
|
|
293
|
+
balance: number;
|
|
294
|
+
}>;
|
|
295
|
+
/** The worst it gets within the horizon, and the first day it goes below zero. null = it doesn't. */
|
|
296
|
+
shortfall: {
|
|
297
|
+
quantity: number;
|
|
298
|
+
firstShortOn: string;
|
|
299
|
+
} | null;
|
|
300
|
+
horizonDays: number;
|
|
301
|
+
/** Lines with no date: counted in the totals, but they can't be placed in the projection. */
|
|
302
|
+
undatedLines?: number;
|
|
303
|
+
asOf: string;
|
|
304
|
+
sources: {
|
|
305
|
+
stock: string;
|
|
306
|
+
orders: string;
|
|
307
|
+
workOrders: string;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
export interface StockApi {
|
|
311
|
+
lines(params?: {
|
|
312
|
+
containerId?: string;
|
|
313
|
+
productId?: string;
|
|
314
|
+
variantId?: string;
|
|
315
|
+
batchId?: string;
|
|
316
|
+
state?: StockState;
|
|
317
|
+
allocatedTo?: StockTarget;
|
|
318
|
+
limit?: number;
|
|
319
|
+
offset?: number;
|
|
320
|
+
}): Promise<{
|
|
321
|
+
items: StockLine[];
|
|
322
|
+
total: number;
|
|
323
|
+
limit: number;
|
|
324
|
+
offset: number;
|
|
325
|
+
}>;
|
|
326
|
+
/** A sum, worked out now. Nothing stores a product's total. */
|
|
327
|
+
totals(params: {
|
|
328
|
+
productId: string;
|
|
329
|
+
variantId?: string;
|
|
330
|
+
batchId?: string;
|
|
331
|
+
}): Promise<StockTotals>;
|
|
332
|
+
where(params: {
|
|
333
|
+
productId: string;
|
|
334
|
+
variantId?: string;
|
|
335
|
+
batchId?: string;
|
|
336
|
+
state?: StockState;
|
|
337
|
+
}): Promise<StockWhereLine[]>;
|
|
338
|
+
position(params: {
|
|
339
|
+
productId: string;
|
|
340
|
+
variantId?: string;
|
|
341
|
+
horizonDays?: number;
|
|
342
|
+
includeWhere?: boolean;
|
|
343
|
+
}): Promise<StockPosition>;
|
|
344
|
+
/** Everything that will run short within the horizon, soonest first. */
|
|
345
|
+
short(params?: {
|
|
346
|
+
horizonDays?: number;
|
|
347
|
+
limit?: number;
|
|
348
|
+
}): Promise<{
|
|
349
|
+
horizonDays: number;
|
|
350
|
+
items: Array<{
|
|
351
|
+
product: StockPosition['product'];
|
|
352
|
+
shortfall: NonNullable<StockPosition['shortfall']>;
|
|
353
|
+
onHand: StockTotals;
|
|
354
|
+
onOrder: number;
|
|
355
|
+
beingMade: number;
|
|
356
|
+
needed: number;
|
|
357
|
+
}>;
|
|
358
|
+
checked: number;
|
|
359
|
+
asOf: string;
|
|
360
|
+
}>;
|
|
361
|
+
/** Stock arrives. */
|
|
362
|
+
receive(input: StockItem & StockMovementExtras & {
|
|
363
|
+
containerId: string;
|
|
364
|
+
state?: 'available' | 'held' | 'quarantine';
|
|
365
|
+
}, opts?: StockMovementOptions): Promise<StockMovement>;
|
|
366
|
+
/** Stock is made (usually with the `workOrderId` that made it). */
|
|
367
|
+
produce(input: StockItem & StockMovementExtras & {
|
|
368
|
+
containerId: string;
|
|
369
|
+
state?: 'available' | 'held' | 'quarantine';
|
|
370
|
+
}, opts?: StockMovementOptions): Promise<StockMovement>;
|
|
371
|
+
/** Stock is used up: out of what was allocated to `allocatedTo`, else out of what is available. @throws `INSUFFICIENT_STOCK` (409) */
|
|
372
|
+
consume(input: StockItem & StockMovementExtras & {
|
|
373
|
+
containerId: string;
|
|
374
|
+
allocatedTo?: StockTarget;
|
|
375
|
+
}, opts?: StockMovementOptions): Promise<StockMovement>;
|
|
376
|
+
/** Between containers. It keeps its state: allocated stock stays allocated to the same thing. */
|
|
377
|
+
move(input: StockItem & StockMovementExtras & {
|
|
378
|
+
from: string;
|
|
379
|
+
to: string;
|
|
380
|
+
state?: StockState;
|
|
381
|
+
allocatedTo?: StockTarget;
|
|
382
|
+
}, opts?: StockMovementOptions): Promise<StockMovement>;
|
|
383
|
+
/** Set available stock aside for something. */
|
|
384
|
+
allocate(input: StockItem & StockMovementExtras & {
|
|
385
|
+
containerId: string;
|
|
386
|
+
to: StockTarget;
|
|
387
|
+
}, opts?: StockMovementOptions): Promise<StockMovement>;
|
|
388
|
+
/** Give allocated stock back. */
|
|
389
|
+
release(input: StockItem & StockMovementExtras & {
|
|
390
|
+
containerId: string;
|
|
391
|
+
from: StockTarget;
|
|
392
|
+
}, opts?: StockMovementOptions): Promise<StockMovement>;
|
|
393
|
+
/** Take available stock out of use. Needs a reason. */
|
|
394
|
+
hold(input: StockItem & StockMovementExtras & {
|
|
395
|
+
containerId: string;
|
|
396
|
+
state?: 'held' | 'quarantine';
|
|
397
|
+
reason: string;
|
|
398
|
+
}, opts?: StockMovementOptions): Promise<StockMovement>;
|
|
399
|
+
/** Put held stock back in use. Needs a reason. */
|
|
400
|
+
unhold(input: StockItem & StockMovementExtras & {
|
|
401
|
+
containerId: string;
|
|
402
|
+
state?: 'held' | 'quarantine';
|
|
403
|
+
reason: string;
|
|
404
|
+
}, opts?: StockMovementOptions): Promise<StockMovement>;
|
|
405
|
+
/** Correct a line after a count: `by` is + or −. Needs a reason. */
|
|
406
|
+
adjust(input: Omit<StockItem, 'quantity'> & StockMovementExtras & {
|
|
407
|
+
containerId: string;
|
|
408
|
+
by: number;
|
|
409
|
+
state?: 'available' | 'held' | 'quarantine';
|
|
410
|
+
reason: string;
|
|
411
|
+
}, opts?: StockMovementOptions): Promise<StockMovement>;
|
|
412
|
+
}
|
|
413
|
+
export interface BomLine {
|
|
414
|
+
componentProductId: string;
|
|
415
|
+
componentVariantId?: string | null;
|
|
416
|
+
quantity: number;
|
|
417
|
+
unit?: string;
|
|
418
|
+
optional?: boolean;
|
|
419
|
+
note?: string | null;
|
|
420
|
+
}
|
|
421
|
+
/** What a product is made of: one version of the recipe. Never edited; a new version takes over. */
|
|
422
|
+
export interface Bom {
|
|
423
|
+
id: string;
|
|
424
|
+
productId: string;
|
|
425
|
+
variantId: string | null;
|
|
426
|
+
version: number;
|
|
427
|
+
validFrom: string;
|
|
428
|
+
/** null = still in force. */
|
|
429
|
+
validTo: string | null;
|
|
430
|
+
/** How many the recipe makes (1 by default; 100 for a batch recipe). */
|
|
431
|
+
yields: number;
|
|
432
|
+
note: string | null;
|
|
433
|
+
lines: Array<{
|
|
434
|
+
componentProductId: string;
|
|
435
|
+
componentVariantId: string | null;
|
|
436
|
+
quantity: number;
|
|
437
|
+
unit: string;
|
|
438
|
+
optional: boolean;
|
|
439
|
+
note: string | null;
|
|
440
|
+
}>;
|
|
441
|
+
data: Record<string, any>;
|
|
442
|
+
createdBy: string | null;
|
|
443
|
+
createdAt: string;
|
|
444
|
+
}
|
|
445
|
+
export interface BomTreeNode {
|
|
446
|
+
productId: string;
|
|
447
|
+
variantId: string | null;
|
|
448
|
+
quantity: number;
|
|
449
|
+
unit: string;
|
|
450
|
+
optional: boolean;
|
|
451
|
+
components: BomTreeNode[];
|
|
452
|
+
}
|
|
453
|
+
export interface BomExplosion {
|
|
454
|
+
productId: string;
|
|
455
|
+
variantId: string | null;
|
|
456
|
+
quantity: number;
|
|
457
|
+
/** false = it has no recipe: it is its own material. */
|
|
458
|
+
hasBom: boolean;
|
|
459
|
+
tree: BomTreeNode[];
|
|
460
|
+
/** The leaves, summed: things with no recipe of their own. */
|
|
461
|
+
materials: Array<{
|
|
462
|
+
productId: string;
|
|
463
|
+
variantId: string | null;
|
|
464
|
+
quantity: number;
|
|
465
|
+
unit: string;
|
|
466
|
+
}>;
|
|
467
|
+
}
|
|
468
|
+
export interface BomsApi {
|
|
469
|
+
/** The recipe in force now, or at a date. A variant's own wins; otherwise the product's. */
|
|
470
|
+
current(params: {
|
|
471
|
+
productId: string;
|
|
472
|
+
variantId?: string;
|
|
473
|
+
at?: string;
|
|
474
|
+
}): Promise<Bom | null>;
|
|
475
|
+
versions(params: {
|
|
476
|
+
productId: string;
|
|
477
|
+
variantId?: string;
|
|
478
|
+
}): Promise<Bom[]>;
|
|
479
|
+
whereUsed(params: {
|
|
480
|
+
componentProductId: string;
|
|
481
|
+
}): Promise<Array<{
|
|
482
|
+
productId: string;
|
|
483
|
+
variantId: string | null;
|
|
484
|
+
quantity: number;
|
|
485
|
+
unit: string;
|
|
486
|
+
yields: number;
|
|
487
|
+
optional: boolean;
|
|
488
|
+
}>>;
|
|
489
|
+
/** Everything needed to make a quantity, all the way down. */
|
|
490
|
+
explode(params: {
|
|
491
|
+
productId: string;
|
|
492
|
+
variantId?: string;
|
|
493
|
+
quantity?: number;
|
|
494
|
+
at?: string;
|
|
495
|
+
includeOptional?: boolean;
|
|
496
|
+
}): Promise<BomExplosion>;
|
|
497
|
+
/** A new version, in force from `validFrom` (now by default). @throws `BOM_LOOP` (409) */
|
|
498
|
+
set(input: {
|
|
499
|
+
productId: string;
|
|
500
|
+
variantId?: string;
|
|
501
|
+
lines: BomLine[];
|
|
502
|
+
yields?: number;
|
|
503
|
+
note?: string;
|
|
504
|
+
validFrom?: string;
|
|
505
|
+
data?: Record<string, any>;
|
|
506
|
+
}): Promise<Bom>;
|
|
507
|
+
/** The product stops having a recipe from now. */
|
|
508
|
+
end(params: {
|
|
509
|
+
productId: string;
|
|
510
|
+
variantId?: string;
|
|
511
|
+
}): Promise<Bom | null>;
|
|
512
|
+
}
|
|
513
|
+
export interface MadeFromSubject {
|
|
514
|
+
type: 'batch' | 'proof';
|
|
515
|
+
id: string;
|
|
516
|
+
}
|
|
517
|
+
export interface MadeFromSource {
|
|
518
|
+
type: 'batch' | 'proof' | 'product';
|
|
519
|
+
id: string;
|
|
520
|
+
}
|
|
521
|
+
export interface MadeFromEntry {
|
|
522
|
+
id: string;
|
|
523
|
+
subject: MadeFromSubject;
|
|
524
|
+
source: MadeFromSource;
|
|
525
|
+
productId: string | null;
|
|
526
|
+
quantity: number | null;
|
|
527
|
+
unit: string | null;
|
|
528
|
+
workOrderId: string | null;
|
|
529
|
+
at: string;
|
|
530
|
+
by: string | null;
|
|
531
|
+
/** Set when the part was taken out. Entries are never edited or deleted. */
|
|
532
|
+
endedAt: string | null;
|
|
533
|
+
data: Record<string, any>;
|
|
534
|
+
}
|
|
535
|
+
export interface MadeFromTraceNode {
|
|
536
|
+
source: MadeFromSource;
|
|
537
|
+
productId: string | null;
|
|
538
|
+
quantity: number | null;
|
|
539
|
+
unit: string | null;
|
|
540
|
+
at: string;
|
|
541
|
+
workOrderId: string | null;
|
|
542
|
+
madeFrom: MadeFromTraceNode[];
|
|
543
|
+
}
|
|
544
|
+
export interface MadeFromApi {
|
|
545
|
+
/** What this was made from: in force now, at a date, or all of them. */
|
|
546
|
+
of(subject: MadeFromSubject, opts?: {
|
|
547
|
+
at?: string;
|
|
548
|
+
includeEnded?: boolean;
|
|
549
|
+
}): Promise<MadeFromEntry[]>;
|
|
550
|
+
/** Everything that used this batch or item. */
|
|
551
|
+
usedIn(source: MadeFromSource, opts?: {
|
|
552
|
+
includeEnded?: boolean;
|
|
553
|
+
}): Promise<MadeFromEntry[]>;
|
|
554
|
+
/** The whole trace back, level by level. */
|
|
555
|
+
trace(subject: MadeFromSubject, opts?: {
|
|
556
|
+
depth?: number;
|
|
557
|
+
}): Promise<{
|
|
558
|
+
subject: MadeFromSubject;
|
|
559
|
+
madeFrom: MadeFromTraceNode[];
|
|
560
|
+
}>;
|
|
561
|
+
record(input: {
|
|
562
|
+
subject: MadeFromSubject;
|
|
563
|
+
sources: Array<MadeFromSource & {
|
|
564
|
+
productId?: string;
|
|
565
|
+
quantity?: number;
|
|
566
|
+
unit?: string;
|
|
567
|
+
data?: Record<string, any>;
|
|
568
|
+
}>;
|
|
569
|
+
workOrderId?: string;
|
|
570
|
+
at?: string;
|
|
571
|
+
}): Promise<MadeFromEntry[]>;
|
|
572
|
+
/** The part was taken out. Needs a reason. */
|
|
573
|
+
end(id: string, opts: {
|
|
574
|
+
reason: string;
|
|
575
|
+
}): Promise<MadeFromEntry>;
|
|
576
|
+
}
|
|
577
|
+
/** One write: `{ op: 'stock.move', args: [{ … }] }` or `{ op: 'workOrders.progress', args: [id, 'picking', { done: 12 }] }`. */
|
|
578
|
+
export interface OperationStep {
|
|
579
|
+
op: string;
|
|
580
|
+
args: any[];
|
|
581
|
+
}
|
|
582
|
+
export interface OperationsApi {
|
|
583
|
+
/**
|
|
584
|
+
* Several writes, all or nothing (at most 50; reads don't belong). A failing step undoes them all,
|
|
585
|
+
* and the error's `details.step` says which.
|
|
586
|
+
*/
|
|
587
|
+
transaction(steps: OperationStep[]): Promise<{
|
|
588
|
+
results: any[];
|
|
589
|
+
}>;
|
|
590
|
+
}
|
|
591
|
+
/** What `operations.admin(collectionId)` gives an admin screen. */
|
|
592
|
+
export interface OperationsAdmin {
|
|
593
|
+
workOrders: WorkOrdersApi;
|
|
594
|
+
stock: StockApi;
|
|
595
|
+
boms: BomsApi;
|
|
596
|
+
madeFrom: MadeFromApi;
|
|
597
|
+
transaction: OperationsApi['transaction'];
|
|
598
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operations: work orders, stock, bills of materials and made-from. See docs/operations.md.
|
|
3
|
+
*
|
|
4
|
+
* The same calls are reached two ways, with the same shapes:
|
|
5
|
+
* - in a server function: ctx.sl.workOrders / ctx.sl.stock / ctx.sl.boms / ctx.sl.madeFrom / ctx.sl.operations
|
|
6
|
+
* - from an admin screen: operations.admin(collectionId) → { workOrders, stock, boms, madeFrom, transaction }
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
package/dist/types/order.d.ts
CHANGED
|
@@ -10,16 +10,38 @@
|
|
|
10
10
|
export interface OrderItem {
|
|
11
11
|
id: string;
|
|
12
12
|
orderId: string;
|
|
13
|
-
itemType: 'tag' | 'proof' | 'serial';
|
|
13
|
+
itemType: 'tag' | 'proof' | 'serial' | 'product';
|
|
14
14
|
itemId: string;
|
|
15
15
|
collectionId?: string;
|
|
16
16
|
productId?: string;
|
|
17
17
|
variantId?: string | null;
|
|
18
18
|
batchId?: string | null;
|
|
19
|
+
quantity: number;
|
|
20
|
+
unit?: string | null;
|
|
21
|
+
quantityDone: number;
|
|
22
|
+
dueAt?: string | null;
|
|
19
23
|
metadata: Record<string, any>;
|
|
20
24
|
createdAt: string;
|
|
21
25
|
order?: OrderSummary;
|
|
22
26
|
}
|
|
27
|
+
/** Which way an order goes: 'sales' = someone wants it from us; 'purchase' = we want it from a supplier. */
|
|
28
|
+
export type OrderDirection = 'sales' | 'purchase';
|
|
29
|
+
/** One identified thing on an order. */
|
|
30
|
+
export interface OrderItemInput {
|
|
31
|
+
itemType: 'tag' | 'proof' | 'serial';
|
|
32
|
+
itemId: string;
|
|
33
|
+
metadata?: Record<string, any>;
|
|
34
|
+
}
|
|
35
|
+
/** A line of quantity: so many of a product. */
|
|
36
|
+
export interface OrderQuantityLineInput {
|
|
37
|
+
itemType?: 'product';
|
|
38
|
+
productId: string;
|
|
39
|
+
variantId?: string;
|
|
40
|
+
quantity: number;
|
|
41
|
+
unit?: string;
|
|
42
|
+
dueAt?: string;
|
|
43
|
+
metadata?: Record<string, any>;
|
|
44
|
+
}
|
|
23
45
|
/**
|
|
24
46
|
* Summary of order details (included with items when requested).
|
|
25
47
|
*/
|
|
@@ -40,6 +62,9 @@ export interface Order {
|
|
|
40
62
|
orderRef?: string;
|
|
41
63
|
customerId?: string;
|
|
42
64
|
status: string;
|
|
65
|
+
direction: OrderDirection;
|
|
66
|
+
partyId?: string | null;
|
|
67
|
+
dueAt?: string | null;
|
|
43
68
|
itemCount: number;
|
|
44
69
|
metadata: {
|
|
45
70
|
productSummary?: Record<string, number>;
|
|
@@ -53,11 +78,10 @@ export interface Order {
|
|
|
53
78
|
* Request to create a new order with items.
|
|
54
79
|
*/
|
|
55
80
|
export interface CreateOrderRequest {
|
|
56
|
-
items: Array<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}>;
|
|
81
|
+
items: Array<OrderItemInput | OrderQuantityLineInput>;
|
|
82
|
+
direction?: OrderDirection;
|
|
83
|
+
partyId?: string;
|
|
84
|
+
dueAt?: string;
|
|
61
85
|
orderRef?: string;
|
|
62
86
|
customerId?: string;
|
|
63
87
|
status?: string;
|
|
@@ -84,6 +108,9 @@ export interface GetOrderResponse extends Order {
|
|
|
84
108
|
* Items are managed separately via add/remove endpoints.
|
|
85
109
|
*/
|
|
86
110
|
export interface UpdateOrderRequest {
|
|
111
|
+
direction?: OrderDirection;
|
|
112
|
+
partyId?: string | null;
|
|
113
|
+
dueAt?: string | null;
|
|
87
114
|
orderRef?: string;
|
|
88
115
|
customerId?: string;
|
|
89
116
|
status?: string;
|
|
@@ -109,6 +136,8 @@ export interface ListOrdersRequest {
|
|
|
109
136
|
status?: string;
|
|
110
137
|
orderRef?: string;
|
|
111
138
|
customerId?: string;
|
|
139
|
+
direction?: OrderDirection;
|
|
140
|
+
partyId?: string;
|
|
112
141
|
includeItems?: boolean;
|
|
113
142
|
}
|
|
114
143
|
/**
|