@unifiedcommerce/plugin-warehouse 0.0.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/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/routes/warehouse.d.ts +11 -0
- package/dist/routes/warehouse.d.ts.map +1 -0
- package/dist/routes/warehouse.js +125 -0
- package/dist/schema.d.ts +1361 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +111 -0
- package/dist/services/reconciliation-service.d.ts +27 -0
- package/dist/services/reconciliation-service.d.ts.map +1 -0
- package/dist/services/reconciliation-service.js +62 -0
- package/dist/services/transfer-service.d.ts +33 -0
- package/dist/services/transfer-service.d.ts.map +1 -0
- package/dist/services/transfer-service.js +69 -0
- package/dist/services/wastage-service.d.ts +25 -0
- package/dist/services/wastage-service.d.ts.map +1 -0
- package/dist/services/wastage-service.js +42 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +37 -0
- package/src/index.ts +31 -0
- package/src/routes/warehouse.ts +134 -0
- package/src/schema.ts +118 -0
- package/src/services/reconciliation-service.ts +69 -0
- package/src/services/transfer-service.ts +74 -0
- package/src/services/wastage-service.ts +50 -0
- package/src/types.ts +9 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { Db } from "./types";
|
|
2
|
+
export { TransferService } from "./services/transfer-service";
|
|
3
|
+
export { WastageService } from "./services/wastage-service";
|
|
4
|
+
export { ReconciliationService } from "./services/reconciliation-service";
|
|
5
|
+
export declare function warehousePlugin(): import("@unifiedcommerce/core").CommercePlugin;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,YAAY,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,wBAAgB,eAAe,mDAiB9B"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineCommercePlugin } from "@unifiedcommerce/core";
|
|
2
|
+
import { warehouseBins, stockTransfers, stockTransferItems, wastageNotes, wastageNoteItems, stockReconciliations, reconciliationItems } from "./schema";
|
|
3
|
+
import { TransferService } from "./services/transfer-service";
|
|
4
|
+
import { WastageService } from "./services/wastage-service";
|
|
5
|
+
import { ReconciliationService } from "./services/reconciliation-service";
|
|
6
|
+
import { buildWarehouseRoutes } from "./routes/warehouse";
|
|
7
|
+
export { TransferService } from "./services/transfer-service";
|
|
8
|
+
export { WastageService } from "./services/wastage-service";
|
|
9
|
+
export { ReconciliationService } from "./services/reconciliation-service";
|
|
10
|
+
export function warehousePlugin() {
|
|
11
|
+
return defineCommercePlugin({
|
|
12
|
+
id: "warehouse",
|
|
13
|
+
version: "1.0.0",
|
|
14
|
+
permissions: [
|
|
15
|
+
{ scope: "warehouse:admin", description: "Approve transfers, wastage, reconciliations." },
|
|
16
|
+
{ scope: "warehouse:operate", description: "Create transfers, wastage notes, reconciliations." },
|
|
17
|
+
{ scope: "warehouse:read", description: "View transfers, wastage, reconciliations." },
|
|
18
|
+
],
|
|
19
|
+
schema: () => ({ warehouseBins, stockTransfers, stockTransferItems, wastageNotes, wastageNoteItems, stockReconciliations, reconciliationItems }),
|
|
20
|
+
hooks: () => [],
|
|
21
|
+
routes: (ctx) => {
|
|
22
|
+
const db = ctx.database.db;
|
|
23
|
+
if (!db)
|
|
24
|
+
return [];
|
|
25
|
+
return buildWarehouseRoutes(new TransferService(db), new WastageService(db), new ReconciliationService(db), ctx);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TransferService } from "../services/transfer-service";
|
|
2
|
+
import type { WastageService } from "../services/wastage-service";
|
|
3
|
+
import type { ReconciliationService } from "../services/reconciliation-service";
|
|
4
|
+
import type { PluginRouteRegistration } from "@unifiedcommerce/core";
|
|
5
|
+
export declare function buildWarehouseRoutes(transferSvc: TransferService, wastageSvc: WastageService, recSvc: ReconciliationService, ctx: {
|
|
6
|
+
services?: Record<string, unknown>;
|
|
7
|
+
database?: {
|
|
8
|
+
db: unknown;
|
|
9
|
+
};
|
|
10
|
+
}): PluginRouteRegistration[];
|
|
11
|
+
//# sourceMappingURL=warehouse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warehouse.d.ts","sourceRoot":"","sources":["../../src/routes/warehouse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErE,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,qBAAqB,EACvF,GAAG,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GACtE,uBAAuB,EAAE,CA2H3B"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { router } from "@unifiedcommerce/core";
|
|
2
|
+
import { z } from "@hono/zod-openapi";
|
|
3
|
+
export function buildWarehouseRoutes(transferSvc, wastageSvc, recSvc, ctx) {
|
|
4
|
+
const r = router("Warehouse", "/warehouse", ctx);
|
|
5
|
+
// Transfers
|
|
6
|
+
r.post("/transfers").summary("Create stock transfer").permission("warehouse:operate")
|
|
7
|
+
.input(z.object({
|
|
8
|
+
fromWarehouseId: z.string().uuid(), toWarehouseId: z.string().uuid(), type: z.enum(["requisition", "direct", "return"]).optional(), notes: z.string().optional(),
|
|
9
|
+
items: z.array(z.object({ entityId: z.string().uuid(), variantId: z.string().uuid().optional(), itemName: z.string(), quantityRequested: z.number().int().positive(), batchNumber: z.string().optional() })).min(1),
|
|
10
|
+
}))
|
|
11
|
+
.handler(async ({ input, actor, orgId }) => {
|
|
12
|
+
const body = input;
|
|
13
|
+
const result = await transferSvc.create(orgId, { ...body, requestedBy: actor.userId });
|
|
14
|
+
if (!result.ok)
|
|
15
|
+
throw new Error(result.error);
|
|
16
|
+
return result.value;
|
|
17
|
+
});
|
|
18
|
+
r.get("/transfers").summary("List transfers").permission("warehouse:read")
|
|
19
|
+
.query(z.object({ status: z.string().optional() }))
|
|
20
|
+
.handler(async ({ query, orgId }) => {
|
|
21
|
+
const result = await transferSvc.list(orgId, query.status);
|
|
22
|
+
if (!result.ok)
|
|
23
|
+
throw new Error(result.error);
|
|
24
|
+
return result.value;
|
|
25
|
+
});
|
|
26
|
+
r.get("/transfers/{id}").summary("Get transfer with items").permission("warehouse:read")
|
|
27
|
+
.handler(async ({ params, orgId }) => {
|
|
28
|
+
const result = await transferSvc.getById(orgId, params.id);
|
|
29
|
+
if (!result.ok)
|
|
30
|
+
throw new Error(result.error);
|
|
31
|
+
return result.value;
|
|
32
|
+
});
|
|
33
|
+
r.post("/transfers/{id}/approve").summary("Approve transfer").permission("warehouse:admin")
|
|
34
|
+
.handler(async ({ params, actor, orgId }) => {
|
|
35
|
+
const result = await transferSvc.approve(orgId, params.id, actor.userId);
|
|
36
|
+
if (!result.ok)
|
|
37
|
+
throw new Error(result.error);
|
|
38
|
+
return result.value;
|
|
39
|
+
});
|
|
40
|
+
r.post("/transfers/{id}/dispatch").summary("Dispatch transfer").permission("warehouse:operate")
|
|
41
|
+
.handler(async ({ params, orgId }) => {
|
|
42
|
+
const result = await transferSvc.dispatch(orgId, params.id);
|
|
43
|
+
if (!result.ok)
|
|
44
|
+
throw new Error(result.error);
|
|
45
|
+
return result.value;
|
|
46
|
+
});
|
|
47
|
+
r.post("/transfers/{id}/receive").summary("Receive transfer").permission("warehouse:operate")
|
|
48
|
+
.input(z.object({ items: z.array(z.object({ itemId: z.string().uuid(), quantityReceived: z.number().int() })).min(1) }))
|
|
49
|
+
.handler(async ({ params, input, orgId }) => {
|
|
50
|
+
const body = input;
|
|
51
|
+
const result = await transferSvc.receive(orgId, params.id, body.items);
|
|
52
|
+
if (!result.ok)
|
|
53
|
+
throw new Error(result.error);
|
|
54
|
+
return result.value;
|
|
55
|
+
});
|
|
56
|
+
// Wastage
|
|
57
|
+
r.post("/wastage").summary("Create wastage note").permission("warehouse:operate")
|
|
58
|
+
.input(z.object({
|
|
59
|
+
warehouseId: z.string().uuid(), type: z.enum(["spoilage", "damage", "expiry", "theft", "prep_waste", "other"]), notes: z.string().optional(),
|
|
60
|
+
items: z.array(z.object({ entityId: z.string().uuid(), variantId: z.string().uuid().optional(), itemName: z.string(), quantity: z.number().int().positive(), unitCost: z.number().int(), reason: z.string().optional(), batchNumber: z.string().optional() })).min(1),
|
|
61
|
+
}))
|
|
62
|
+
.handler(async ({ input, actor, orgId }) => {
|
|
63
|
+
const body = input;
|
|
64
|
+
const result = await wastageSvc.create(orgId, { ...body, recordedBy: actor.userId });
|
|
65
|
+
if (!result.ok)
|
|
66
|
+
throw new Error(result.error);
|
|
67
|
+
return result.value;
|
|
68
|
+
});
|
|
69
|
+
r.get("/wastage").summary("List wastage notes").permission("warehouse:read")
|
|
70
|
+
.handler(async ({ orgId }) => {
|
|
71
|
+
const result = await wastageSvc.list(orgId);
|
|
72
|
+
if (!result.ok)
|
|
73
|
+
throw new Error(result.error);
|
|
74
|
+
return result.value;
|
|
75
|
+
});
|
|
76
|
+
r.post("/wastage/{id}/approve").summary("Approve wastage").permission("warehouse:admin")
|
|
77
|
+
.handler(async ({ params, actor, orgId }) => {
|
|
78
|
+
const result = await wastageSvc.approve(orgId, params.id, actor.userId);
|
|
79
|
+
if (!result.ok)
|
|
80
|
+
throw new Error(result.error);
|
|
81
|
+
return result.value;
|
|
82
|
+
});
|
|
83
|
+
// Reconciliation
|
|
84
|
+
r.post("/reconciliations").summary("Create stock reconciliation").permission("warehouse:operate")
|
|
85
|
+
.input(z.object({
|
|
86
|
+
warehouseId: z.string().uuid(),
|
|
87
|
+
items: z.array(z.object({ entityId: z.string().uuid(), variantId: z.string().uuid().optional(), itemName: z.string(), systemQuantity: z.number().int(), physicalQuantity: z.number().int(), notes: z.string().optional() })).min(1),
|
|
88
|
+
}))
|
|
89
|
+
.handler(async ({ input, actor, orgId }) => {
|
|
90
|
+
const body = input;
|
|
91
|
+
const result = await recSvc.create(orgId, { ...body, countedBy: actor.userId });
|
|
92
|
+
if (!result.ok)
|
|
93
|
+
throw new Error(result.error);
|
|
94
|
+
return result.value;
|
|
95
|
+
});
|
|
96
|
+
r.get("/reconciliations").summary("List reconciliations").permission("warehouse:read")
|
|
97
|
+
.handler(async ({ orgId }) => {
|
|
98
|
+
const result = await recSvc.list(orgId);
|
|
99
|
+
if (!result.ok)
|
|
100
|
+
throw new Error(result.error);
|
|
101
|
+
return result.value;
|
|
102
|
+
});
|
|
103
|
+
r.get("/reconciliations/{id}").summary("Get reconciliation with items").permission("warehouse:read")
|
|
104
|
+
.handler(async ({ params, orgId }) => {
|
|
105
|
+
const result = await recSvc.getById(orgId, params.id);
|
|
106
|
+
if (!result.ok)
|
|
107
|
+
throw new Error(result.error);
|
|
108
|
+
return result.value;
|
|
109
|
+
});
|
|
110
|
+
r.post("/reconciliations/{id}/submit").summary("Submit reconciliation").permission("warehouse:operate")
|
|
111
|
+
.handler(async ({ params, orgId }) => {
|
|
112
|
+
const result = await recSvc.submit(orgId, params.id);
|
|
113
|
+
if (!result.ok)
|
|
114
|
+
throw new Error(result.error);
|
|
115
|
+
return result.value;
|
|
116
|
+
});
|
|
117
|
+
r.post("/reconciliations/{id}/approve").summary("Approve reconciliation").permission("warehouse:admin")
|
|
118
|
+
.handler(async ({ params, actor, orgId }) => {
|
|
119
|
+
const result = await recSvc.approve(orgId, params.id, actor.userId);
|
|
120
|
+
if (!result.ok)
|
|
121
|
+
throw new Error(result.error);
|
|
122
|
+
return result.value;
|
|
123
|
+
});
|
|
124
|
+
return r.routes();
|
|
125
|
+
}
|