@unifiedcommerce/core 0.3.4 → 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/dist/interfaces/mcp/tools/webhooks.d.ts +1 -1
- package/dist/interfaces/rest/index.d.ts.map +1 -1
- package/dist/interfaces/rest/index.js +14 -3
- package/dist/interfaces/rest/routes/customers.d.ts +5 -0
- package/dist/interfaces/rest/routes/customers.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/customers.js +74 -0
- package/dist/interfaces/rest/routes/inventory.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/inventory.js +14 -1
- package/dist/interfaces/rest/schemas/customers.d.ts +422 -0
- package/dist/interfaces/rest/schemas/customers.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/customers.js +150 -0
- package/dist/interfaces/rest/schemas/inventory.d.ts +92 -0
- package/dist/interfaces/rest/schemas/inventory.d.ts.map +1 -1
- package/dist/interfaces/rest/schemas/inventory.js +20 -0
- package/dist/modules/customers/service.d.ts +2 -0
- package/dist/modules/customers/service.d.ts.map +1 -1
- package/dist/modules/customers/service.js +15 -0
- package/dist/modules/inventory/service.d.ts +4 -0
- package/dist/modules/inventory/service.d.ts.map +1 -1
- package/dist/modules/inventory/service.js +12 -0
- package/dist/runtime/server.d.ts.map +1 -1
- package/dist/runtime/server.js +29 -0
- package/package.json +2 -2
- package/src/interfaces/rest/index.ts +17 -3
- package/src/interfaces/rest/routes/customers.ts +94 -0
- package/src/interfaces/rest/routes/inventory.ts +17 -0
- package/src/interfaces/rest/schemas/customers.ts +155 -0
- package/src/interfaces/rest/schemas/inventory.ts +21 -0
- package/src/modules/customers/service.ts +25 -0
- package/src/modules/inventory/service.ts +17 -0
- package/src/runtime/server.ts +30 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { z, createRoute } from "@hono/zod-openapi";
|
|
2
|
+
import { errorResponses } from "./shared.js";
|
|
3
|
+
export const listCustomersRoute = createRoute({
|
|
4
|
+
method: "get",
|
|
5
|
+
path: "/",
|
|
6
|
+
tags: ["Customers"],
|
|
7
|
+
summary: "List customers",
|
|
8
|
+
request: {
|
|
9
|
+
query: z.object({
|
|
10
|
+
page: z.string().optional().openapi({ example: "1" }),
|
|
11
|
+
limit: z.string().optional().openapi({ example: "20" }),
|
|
12
|
+
}),
|
|
13
|
+
},
|
|
14
|
+
responses: {
|
|
15
|
+
200: {
|
|
16
|
+
content: {
|
|
17
|
+
"application/json": {
|
|
18
|
+
schema: z.object({
|
|
19
|
+
data: z.array(z.record(z.string(), z.unknown())),
|
|
20
|
+
meta: z.object({
|
|
21
|
+
pagination: z.object({
|
|
22
|
+
page: z.number(),
|
|
23
|
+
limit: z.number(),
|
|
24
|
+
total: z.number(),
|
|
25
|
+
totalPages: z.number(),
|
|
26
|
+
}),
|
|
27
|
+
}),
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
description: "Customer list",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
export const getCustomerRoute = createRoute({
|
|
36
|
+
method: "get",
|
|
37
|
+
path: "/{id}",
|
|
38
|
+
tags: ["Customers"],
|
|
39
|
+
summary: "Get customer by ID",
|
|
40
|
+
request: {
|
|
41
|
+
params: z.object({
|
|
42
|
+
id: z.string().uuid().openapi({ example: "b482a588-..." }),
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
responses: {
|
|
46
|
+
200: {
|
|
47
|
+
content: {
|
|
48
|
+
"application/json": {
|
|
49
|
+
schema: z.object({ data: z.record(z.string(), z.unknown()) }),
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
description: "Customer detail",
|
|
53
|
+
},
|
|
54
|
+
...errorResponses,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
export const updateCustomerRoute = createRoute({
|
|
58
|
+
method: "patch",
|
|
59
|
+
path: "/{id}",
|
|
60
|
+
tags: ["Customers"],
|
|
61
|
+
summary: "Update a customer",
|
|
62
|
+
request: {
|
|
63
|
+
params: z.object({
|
|
64
|
+
id: z.string().uuid(),
|
|
65
|
+
}),
|
|
66
|
+
body: {
|
|
67
|
+
content: {
|
|
68
|
+
"application/json": {
|
|
69
|
+
schema: z.object({
|
|
70
|
+
firstName: z.string().optional(),
|
|
71
|
+
lastName: z.string().optional(),
|
|
72
|
+
email: z.string().email().optional(),
|
|
73
|
+
phone: z.string().optional(),
|
|
74
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
75
|
+
}).openapi("UpdateCustomerRequest"),
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
responses: {
|
|
81
|
+
200: {
|
|
82
|
+
content: {
|
|
83
|
+
"application/json": {
|
|
84
|
+
schema: z.object({ data: z.record(z.string(), z.unknown()) }),
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
description: "Customer updated",
|
|
88
|
+
},
|
|
89
|
+
...errorResponses,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
export const getCustomerOrdersRoute = createRoute({
|
|
93
|
+
method: "get",
|
|
94
|
+
path: "/{id}/orders",
|
|
95
|
+
tags: ["Customers"],
|
|
96
|
+
summary: "List orders for a customer",
|
|
97
|
+
request: {
|
|
98
|
+
params: z.object({
|
|
99
|
+
id: z.string().uuid(),
|
|
100
|
+
}),
|
|
101
|
+
query: z.object({
|
|
102
|
+
status: z.string().optional(),
|
|
103
|
+
page: z.string().optional().openapi({ example: "1" }),
|
|
104
|
+
limit: z.string().optional().openapi({ example: "20" }),
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
responses: {
|
|
108
|
+
200: {
|
|
109
|
+
content: {
|
|
110
|
+
"application/json": {
|
|
111
|
+
schema: z.object({
|
|
112
|
+
data: z.array(z.record(z.string(), z.unknown())),
|
|
113
|
+
meta: z.object({
|
|
114
|
+
pagination: z.object({
|
|
115
|
+
page: z.number(),
|
|
116
|
+
limit: z.number(),
|
|
117
|
+
total: z.number(),
|
|
118
|
+
totalPages: z.number(),
|
|
119
|
+
}),
|
|
120
|
+
}),
|
|
121
|
+
}),
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
description: "Customer orders",
|
|
125
|
+
},
|
|
126
|
+
...errorResponses,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
export const getCustomerAddressesRoute = createRoute({
|
|
130
|
+
method: "get",
|
|
131
|
+
path: "/{id}/addresses",
|
|
132
|
+
tags: ["Customers"],
|
|
133
|
+
summary: "List addresses for a customer",
|
|
134
|
+
request: {
|
|
135
|
+
params: z.object({
|
|
136
|
+
id: z.string().uuid(),
|
|
137
|
+
}),
|
|
138
|
+
},
|
|
139
|
+
responses: {
|
|
140
|
+
200: {
|
|
141
|
+
content: {
|
|
142
|
+
"application/json": {
|
|
143
|
+
schema: z.object({ data: z.array(z.record(z.string(), z.unknown())) }),
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
description: "Customer addresses",
|
|
147
|
+
},
|
|
148
|
+
...errorResponses,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
@@ -6,6 +6,98 @@ export declare const CreateWarehouseBodySchema: z.ZodObject<{
|
|
|
6
6
|
code: z.ZodOptional<z.ZodString>;
|
|
7
7
|
address: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
8
8
|
}, z.core.$strip>;
|
|
9
|
+
export declare const listInventoryLevelsRoute: {
|
|
10
|
+
method: "get";
|
|
11
|
+
path: "/levels";
|
|
12
|
+
tags: string[];
|
|
13
|
+
summary: string;
|
|
14
|
+
description: string;
|
|
15
|
+
request: {
|
|
16
|
+
query: z.ZodObject<{
|
|
17
|
+
warehouseId: z.ZodOptional<z.ZodString>;
|
|
18
|
+
entityId: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
};
|
|
21
|
+
responses: {
|
|
22
|
+
400: {
|
|
23
|
+
readonly content: {
|
|
24
|
+
readonly "application/json": {
|
|
25
|
+
readonly schema: z.ZodObject<{
|
|
26
|
+
error: z.ZodObject<{
|
|
27
|
+
code: z.ZodString;
|
|
28
|
+
message: z.ZodString;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
readonly description: "Business logic error.";
|
|
34
|
+
};
|
|
35
|
+
401: {
|
|
36
|
+
readonly content: {
|
|
37
|
+
readonly "application/json": {
|
|
38
|
+
readonly schema: z.ZodObject<{
|
|
39
|
+
error: z.ZodObject<{
|
|
40
|
+
code: z.ZodString;
|
|
41
|
+
message: z.ZodString;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
readonly description: "Authentication required.";
|
|
47
|
+
};
|
|
48
|
+
403: {
|
|
49
|
+
readonly content: {
|
|
50
|
+
readonly "application/json": {
|
|
51
|
+
readonly schema: z.ZodObject<{
|
|
52
|
+
error: z.ZodObject<{
|
|
53
|
+
code: z.ZodString;
|
|
54
|
+
message: z.ZodString;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
readonly description: "Insufficient permissions.";
|
|
60
|
+
};
|
|
61
|
+
404: {
|
|
62
|
+
readonly content: {
|
|
63
|
+
readonly "application/json": {
|
|
64
|
+
readonly schema: z.ZodObject<{
|
|
65
|
+
error: z.ZodObject<{
|
|
66
|
+
code: z.ZodString;
|
|
67
|
+
message: z.ZodString;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
readonly description: "Resource not found.";
|
|
73
|
+
};
|
|
74
|
+
422: {
|
|
75
|
+
readonly content: {
|
|
76
|
+
readonly "application/json": {
|
|
77
|
+
readonly schema: z.ZodObject<{
|
|
78
|
+
error: z.ZodObject<{
|
|
79
|
+
code: z.ZodString;
|
|
80
|
+
message: z.ZodString;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
readonly description: "Validation error.";
|
|
86
|
+
};
|
|
87
|
+
200: {
|
|
88
|
+
content: {
|
|
89
|
+
"application/json": {
|
|
90
|
+
schema: z.ZodObject<{
|
|
91
|
+
data: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
description: string;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
} & {
|
|
99
|
+
getRoutingPath(): "/levels";
|
|
100
|
+
};
|
|
9
101
|
export declare const inventoryCheckRoute: {
|
|
10
102
|
method: "get";
|
|
11
103
|
path: "/check";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/schemas/inventory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAe,MAAM,mBAAmB,CAAC;AAKnD,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAC1I,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,CAAC;AAE7F,eAAO,MAAM,yBAAyB;;;;iBAIF,CAAC;AAIrC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;CAgB9B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;CAW9B,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqB/B,CAAC;A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;;;;;;;;;;;;;;;;;;;;;;;;;CAqB/B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqBhC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqBhC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqB/B,CAAC"}
|
|
@@ -9,6 +9,26 @@ export const CreateWarehouseBodySchema = z.object({
|
|
|
9
9
|
address: z.record(z.string(), z.unknown()).optional(),
|
|
10
10
|
}).openapi("CreateWarehouseRequest");
|
|
11
11
|
// ─── Route Definitions ──────────────────────────────────────────────────────
|
|
12
|
+
export const listInventoryLevelsRoute = createRoute({
|
|
13
|
+
method: "get",
|
|
14
|
+
path: "/levels",
|
|
15
|
+
tags: ["Inventory"],
|
|
16
|
+
summary: "List inventory levels",
|
|
17
|
+
description: "Lists all inventory levels, optionally filtered by warehouse or entity.",
|
|
18
|
+
request: {
|
|
19
|
+
query: z.object({
|
|
20
|
+
warehouseId: z.string().uuid().optional().openapi({ example: "uuid" }),
|
|
21
|
+
entityId: z.string().uuid().optional().openapi({ example: "uuid" }),
|
|
22
|
+
}),
|
|
23
|
+
},
|
|
24
|
+
responses: {
|
|
25
|
+
200: {
|
|
26
|
+
content: { "application/json": { schema: z.object({ data: z.array(z.record(z.string(), z.unknown())) }) } },
|
|
27
|
+
description: "Inventory levels",
|
|
28
|
+
},
|
|
29
|
+
...errorResponses,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
12
32
|
export const inventoryCheckRoute = createRoute({
|
|
13
33
|
method: "get",
|
|
14
34
|
path: "/check",
|
|
@@ -10,8 +10,10 @@ export declare class CustomerService {
|
|
|
10
10
|
private readonly repo;
|
|
11
11
|
constructor(deps: CustomerServiceDeps);
|
|
12
12
|
private getOrCreateByUserId;
|
|
13
|
+
list(actor?: Actor | null, ctx?: TxContext): Promise<Result<Customer[]>>;
|
|
13
14
|
getById(id: string, actor?: Actor | null, ctx?: TxContext): Promise<Result<Customer>>;
|
|
14
15
|
getByUserId(userId: string, actor?: Actor | null, ctx?: TxContext): Promise<Result<Customer>>;
|
|
16
|
+
update(id: string, updates: Partial<Omit<Customer, "id" | "userId" | "createdAt" | "updatedAt">>, actor?: Actor | null, ctx?: TxContext): Promise<Result<Customer>>;
|
|
15
17
|
updateByUserId(userId: string, updates: Partial<Omit<Customer, "id" | "userId" | "createdAt" | "updatedAt">>, actor?: Actor | null, ctx?: TxContext): Promise<Result<Customer>>;
|
|
16
18
|
getAddresses(userId: string, actor?: Actor | null, ctx?: TxContext): Promise<Result<CustomerAddress[]>>;
|
|
17
19
|
addAddress(userId: string, input: Omit<CustomerAddressInsert, "id" | "customerId">, actor?: Actor | null, ctx?: TxContext): Promise<Result<CustomerAddress>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/customers/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,KAAK,EACV,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,qBAAqB,EACtB,MAAM,uBAAuB,CAAC;AAE/B,UAAU,mBAAmB;IAC3B,UAAU,EAAE,mBAAmB,CAAC;CACjC;AAED,qBAA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,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CAYhD"}
|
|
@@ -20,6 +20,11 @@ export class CustomerService {
|
|
|
20
20
|
}, ctx);
|
|
21
21
|
return customer;
|
|
22
22
|
}
|
|
23
|
+
async list(actor, ctx) {
|
|
24
|
+
const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
|
|
25
|
+
const customers = await this.repo.findAll(orgId, ctx);
|
|
26
|
+
return Ok(customers);
|
|
27
|
+
}
|
|
23
28
|
async getById(id, actor, ctx) {
|
|
24
29
|
const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
|
|
25
30
|
const customer = await this.repo.findById(orgId, id, ctx);
|
|
@@ -32,6 +37,16 @@ export class CustomerService {
|
|
|
32
37
|
const customer = await this.getOrCreateByUserId(orgId, userId, ctx);
|
|
33
38
|
return Ok(customer);
|
|
34
39
|
}
|
|
40
|
+
async update(id, updates, actor, ctx) {
|
|
41
|
+
const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
|
|
42
|
+
const existing = await this.repo.findById(orgId, id, ctx);
|
|
43
|
+
if (!existing)
|
|
44
|
+
return Err(new CommerceNotFoundError("Customer not found."));
|
|
45
|
+
const updated = await this.repo.update(id, updates, ctx);
|
|
46
|
+
if (!updated)
|
|
47
|
+
return Err(new CommerceNotFoundError("Customer not found."));
|
|
48
|
+
return Ok(updated);
|
|
49
|
+
}
|
|
35
50
|
async updateByUserId(userId, updates, actor, ctx) {
|
|
36
51
|
const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
|
|
37
52
|
const customer = await this.getOrCreateByUserId(orgId, userId, ctx);
|
|
@@ -22,6 +22,10 @@ export declare class InventoryService {
|
|
|
22
22
|
createWarehouse(input: Partial<Warehouse>, actor?: Actor | null, ctx?: TxContext): Promise<Result<Warehouse>>;
|
|
23
23
|
listWarehouses(actor?: Actor | null, ctx?: TxContext): Promise<Result<Warehouse[]>>;
|
|
24
24
|
getAvailable(entityId: string, variantId?: string, ctx?: TxContext): Promise<Result<number>>;
|
|
25
|
+
listLevels(params?: {
|
|
26
|
+
warehouseId?: string;
|
|
27
|
+
entityId?: string;
|
|
28
|
+
}, actor?: Actor | null, ctx?: TxContext): Promise<Result<InventoryLevel[]>>;
|
|
25
29
|
checkMultiple(entityIds: string[], ctx?: TxContext): Promise<Result<Record<string, number>>>;
|
|
26
30
|
getLevelsByEntityId(entityId: string, ctx?: TxContext): Promise<Result<InventoryLevel[]>>;
|
|
27
31
|
reserve(input: InventoryReserveInput, actor?: Actor | null, ctx?: TxContext): Promise<Result<void>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/inventory/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAS5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EACL,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACvG,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEvG,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,mBAAmB,CAAC;IAChC,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,EAA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AAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,EACD,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,EACpB,GAAG,CAAC,EAAE,SAAS,GACd,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IA2BlC;;;;;;;;;;OAUG;IACG,oBAAoB,CACxB,KAAK,EAAE;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,EACD,GAAG,CAAC,EAAE,SAAS,GACd,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAwClB,WAAW,CACf,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,GAAG,CAAC,EAAE,SAAS,GACd,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;CAiBnC"}
|
|
@@ -56,6 +56,18 @@ export class InventoryService {
|
|
|
56
56
|
const available = await this.repo.getAvailableQuantity(entityId, variantId, ctx);
|
|
57
57
|
return Ok(available);
|
|
58
58
|
}
|
|
59
|
+
async listLevels(params, actor, ctx) {
|
|
60
|
+
if (params?.entityId) {
|
|
61
|
+
const levels = await this.repo.findLevelsByEntityId(params.entityId, ctx);
|
|
62
|
+
return Ok(levels);
|
|
63
|
+
}
|
|
64
|
+
if (params?.warehouseId) {
|
|
65
|
+
const levels = await this.repo.findLevelsByWarehouseId(params.warehouseId, ctx);
|
|
66
|
+
return Ok(levels);
|
|
67
|
+
}
|
|
68
|
+
const levels = await this.repo.findAllLevels(ctx);
|
|
69
|
+
return Ok(levels);
|
|
70
|
+
}
|
|
59
71
|
async checkMultiple(entityIds, ctx) {
|
|
60
72
|
const data = await this.repo.getAvailableQuantities(entityIds, ctx);
|
|
61
73
|
return Ok(data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/runtime/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKhD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAOzD,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtE,KAAK,SAAS,GAAG;IACf,SAAS,EAAE;QACT,IAAI,EAAE,YAAY,CAAC;QACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,cAAc;;;;;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/runtime/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKhD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAOzD,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtE,KAAK,SAAS,GAAG;IACf,SAAS,EAAE;QACT,IAAI,EAAE,YAAY,CAAC;QACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,cAAc;;;;;GA4VxD"}
|
package/dist/runtime/server.js
CHANGED
|
@@ -207,6 +207,35 @@ export async function createServer(config) {
|
|
|
207
207
|
version: config.version ?? "0.0.1",
|
|
208
208
|
description: "Headless commerce engine REST API. Includes core and plugin endpoints.",
|
|
209
209
|
},
|
|
210
|
+
tags: [
|
|
211
|
+
// ── Storefront ──
|
|
212
|
+
{ name: "Catalog", description: "Products, categories, brands, variants, and option types" },
|
|
213
|
+
{ name: "Search", description: "Full-text search and typeahead suggestions" },
|
|
214
|
+
{ name: "Pricing", description: "Base prices, price modifiers, and customer group pricing" },
|
|
215
|
+
{ name: "Carts", description: "Shopping cart lifecycle — create, add items, update quantities" },
|
|
216
|
+
{ name: "Checkout", description: "Convert a cart into a paid order" },
|
|
217
|
+
{ name: "Promotions", description: "Discount codes, validation, and usage tracking" },
|
|
218
|
+
// ── Admin ──
|
|
219
|
+
{ name: "Orders", description: "Order management — list, detail, status transitions, fulfillments" },
|
|
220
|
+
{ name: "Customers", description: "Customer profiles, addresses, groups, and order history" },
|
|
221
|
+
{ name: "Inventory", description: "Stock levels, warehouse management, adjustments, and reservations" },
|
|
222
|
+
{ name: "Media", description: "File uploads, entity attachments, and signed URLs" },
|
|
223
|
+
{ name: "Payments", description: "Payment provider webhooks and event processing" },
|
|
224
|
+
// ── Operations ──
|
|
225
|
+
{ name: "Webhooks", description: "Outbound webhook endpoint registration and management" },
|
|
226
|
+
{ name: "Audit", description: "Immutable audit log — who changed what and when" },
|
|
227
|
+
{ name: "Admin Jobs", description: "Background job queue — view failed jobs and retry" },
|
|
228
|
+
],
|
|
229
|
+
});
|
|
230
|
+
// Serve enriched spec with x-tagGroups vendor extension (Scalar/Redocly sidebar grouping)
|
|
231
|
+
const tagGroups = [
|
|
232
|
+
{ name: "Storefront", tags: ["Catalog", "Search", "Pricing", "Carts", "Checkout", "Promotions"] },
|
|
233
|
+
{ name: "Admin", tags: ["Orders", "Customers", "Inventory", "Media", "Payments"] },
|
|
234
|
+
{ name: "Operations", tags: ["Webhooks", "Audit", "Admin Jobs"] },
|
|
235
|
+
];
|
|
236
|
+
app.get("/api/doc-ext", (c) => {
|
|
237
|
+
const spec = app.getOpenAPIDocument({ openapi: "3.0.0", info: { title: "UnifiedCommerce API", version: config.version ?? "0.0.1" } });
|
|
238
|
+
return c.json({ ...spec, "x-tagGroups": tagGroups });
|
|
210
239
|
});
|
|
211
240
|
}
|
|
212
241
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unifiedcommerce/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@better-auth/drizzle-adapter": "^1.3.8",
|
|
47
|
-
"@hono/swagger-ui": "^0.6.1",
|
|
48
47
|
"@hono/zod-openapi": "^1.2.2",
|
|
49
48
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
49
|
+
"@scalar/hono-api-reference": "^0.10.5",
|
|
50
50
|
"better-auth": "^1.3.8",
|
|
51
51
|
"drizzle-orm": "^0.45.1",
|
|
52
52
|
"drizzle-zod": "^0.8.3",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
-
import {
|
|
2
|
+
import { Scalar } from "@scalar/hono-api-reference";
|
|
3
3
|
import { sql } from "drizzle-orm";
|
|
4
4
|
import type { Kernel } from "../../runtime/kernel.js";
|
|
5
5
|
import type { AppEnv } from "./utils.js";
|
|
@@ -16,6 +16,7 @@ import { promotionRoutes } from "./routes/promotions.js";
|
|
|
16
16
|
import { searchRoutes } from "./routes/search.js";
|
|
17
17
|
import { auditRoutes } from "./routes/audit.js";
|
|
18
18
|
import { adminJobRoutes } from "./routes/admin-jobs.js";
|
|
19
|
+
import { customerRoutes } from "./routes/customers.js";
|
|
19
20
|
|
|
20
21
|
export function createRestRoutes(kernel: Kernel) {
|
|
21
22
|
const router = new OpenAPIHono<AppEnv>({
|
|
@@ -61,13 +62,26 @@ export function createRestRoutes(kernel: Kernel) {
|
|
|
61
62
|
router.route("/pricing", pricingRoutes(kernel));
|
|
62
63
|
router.route("/promotions", promotionRoutes(kernel));
|
|
63
64
|
router.route("/search", searchRoutes(kernel));
|
|
65
|
+
router.route("/customers", customerRoutes(kernel));
|
|
64
66
|
router.route("/audit", auditRoutes(kernel));
|
|
65
67
|
router.route("/admin", adminJobRoutes(kernel));
|
|
66
68
|
|
|
67
|
-
//
|
|
69
|
+
// API Reference (Scalar) — disabled in production unless config.exposeOpenApiSpec is true
|
|
68
70
|
const exposeSpec = kernel.config.exposeOpenApiSpec ?? (process.env.NODE_ENV !== "production");
|
|
69
71
|
if (exposeSpec) {
|
|
70
|
-
router.get(
|
|
72
|
+
router.get(
|
|
73
|
+
"/reference",
|
|
74
|
+
Scalar({
|
|
75
|
+
url: "/api/doc-ext",
|
|
76
|
+
theme: "kepler",
|
|
77
|
+
layout: "modern",
|
|
78
|
+
darkMode: true,
|
|
79
|
+
hideModels: true,
|
|
80
|
+
tagsSorter: "alpha",
|
|
81
|
+
defaultHttpClient: { targetKey: "js", clientKey: "fetch" },
|
|
82
|
+
metaData: { title: "UnifiedCommerce API Reference" },
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
71
85
|
}
|
|
72
86
|
|
|
73
87
|
return router;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import type { Kernel } from "../../../runtime/kernel.js";
|
|
3
|
+
import {
|
|
4
|
+
listCustomersRoute,
|
|
5
|
+
getCustomerRoute,
|
|
6
|
+
updateCustomerRoute,
|
|
7
|
+
getCustomerOrdersRoute,
|
|
8
|
+
getCustomerAddressesRoute,
|
|
9
|
+
} from "../schemas/customers.js";
|
|
10
|
+
import { type AppEnv, mapErrorToResponse, mapErrorToStatus, parsePagination } from "../utils.js";
|
|
11
|
+
|
|
12
|
+
export function customerRoutes(kernel: Kernel) {
|
|
13
|
+
const router = new OpenAPIHono<AppEnv>();
|
|
14
|
+
|
|
15
|
+
// @ts-expect-error -- openapi handler union return type
|
|
16
|
+
router.openapi(listCustomersRoute, async (c) => {
|
|
17
|
+
const actor = c.get("actor");
|
|
18
|
+
const { page, limit } = parsePagination(c.req.query());
|
|
19
|
+
|
|
20
|
+
const result = await kernel.services.customers.list(actor);
|
|
21
|
+
if (!result.ok) return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
22
|
+
|
|
23
|
+
const all = result.value;
|
|
24
|
+
const total = all.length;
|
|
25
|
+
const start = (page - 1) * limit;
|
|
26
|
+
const paged = all.slice(start, start + limit);
|
|
27
|
+
|
|
28
|
+
return c.json({
|
|
29
|
+
data: paged,
|
|
30
|
+
meta: {
|
|
31
|
+
pagination: { page, limit, total, totalPages: Math.ceil(total / limit) },
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// @ts-expect-error -- openapi handler union return type
|
|
37
|
+
router.openapi(getCustomerRoute, async (c) => {
|
|
38
|
+
const { id } = c.req.valid("param");
|
|
39
|
+
const actor = c.get("actor");
|
|
40
|
+
const result = await kernel.services.customers.getById(id, actor);
|
|
41
|
+
if (!result.ok) return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
42
|
+
return c.json({ data: result.value });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// @ts-expect-error -- openapi handler union return type
|
|
46
|
+
router.openapi(updateCustomerRoute, async (c) => {
|
|
47
|
+
const { id } = c.req.valid("param");
|
|
48
|
+
const body = c.req.valid("json");
|
|
49
|
+
const actor = c.get("actor");
|
|
50
|
+
// Strip undefined values — exactOptionalPropertyTypes requires omission, not undefined
|
|
51
|
+
const updates: Record<string, unknown> = {};
|
|
52
|
+
for (const [k, v] of Object.entries(body)) {
|
|
53
|
+
if (v !== undefined) updates[k] = v;
|
|
54
|
+
}
|
|
55
|
+
const result = await kernel.services.customers.update(id, updates, actor);
|
|
56
|
+
if (!result.ok) return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
57
|
+
return c.json({ data: result.value });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// @ts-expect-error -- openapi handler union return type
|
|
61
|
+
router.openapi(getCustomerOrdersRoute, async (c) => {
|
|
62
|
+
const { id } = c.req.valid("param");
|
|
63
|
+
const actor = c.get("actor");
|
|
64
|
+
const { page, limit } = parsePagination(c.req.query());
|
|
65
|
+
const status = c.req.query("status") || undefined;
|
|
66
|
+
|
|
67
|
+
const result = await kernel.services.orders.listByCustomer(
|
|
68
|
+
id,
|
|
69
|
+
{ page, limit, ...(status ? { status } : {}) },
|
|
70
|
+
actor,
|
|
71
|
+
);
|
|
72
|
+
if (!result.ok) return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
73
|
+
return c.json({ data: result.value.items, meta: { pagination: result.value.pagination } });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// @ts-expect-error -- openapi handler union return type
|
|
77
|
+
router.openapi(getCustomerAddressesRoute, async (c) => {
|
|
78
|
+
const { id } = c.req.valid("param");
|
|
79
|
+
const actor = c.get("actor");
|
|
80
|
+
|
|
81
|
+
// Get customer first, then use their userId for address lookup
|
|
82
|
+
const customerResult = await kernel.services.customers.getById(id, actor);
|
|
83
|
+
if (!customerResult.ok) return c.json(mapErrorToResponse(customerResult.error), mapErrorToStatus(customerResult.error));
|
|
84
|
+
|
|
85
|
+
const addressResult = await kernel.services.customers.getAddresses(
|
|
86
|
+
customerResult.value.userId,
|
|
87
|
+
actor,
|
|
88
|
+
);
|
|
89
|
+
if (!addressResult.ok) return c.json(mapErrorToResponse(addressResult.error), mapErrorToStatus(addressResult.error));
|
|
90
|
+
return c.json({ data: addressResult.value });
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return router;
|
|
94
|
+
}
|
|
@@ -7,12 +7,29 @@ import {
|
|
|
7
7
|
createWarehouseRoute,
|
|
8
8
|
inventoryCheckRoute,
|
|
9
9
|
listWarehousesRoute,
|
|
10
|
+
listInventoryLevelsRoute,
|
|
10
11
|
} from "../schemas/inventory.js";
|
|
11
12
|
import { type AppEnv, mapErrorToResponse, mapErrorToStatus } from "../utils.js";
|
|
12
13
|
|
|
13
14
|
export function inventoryRoutes(kernel: Kernel) {
|
|
14
15
|
const router = new OpenAPIHono<AppEnv>();
|
|
15
16
|
|
|
17
|
+
// @ts-expect-error -- openapi handler union return type
|
|
18
|
+
router.openapi(listInventoryLevelsRoute, async (c) => {
|
|
19
|
+
const actor = c.get("actor");
|
|
20
|
+
const warehouseId = c.req.query("warehouseId");
|
|
21
|
+
const entityId = c.req.query("entityId");
|
|
22
|
+
const result = await kernel.services.inventory.listLevels(
|
|
23
|
+
{
|
|
24
|
+
...(warehouseId ? { warehouseId } : {}),
|
|
25
|
+
...(entityId ? { entityId } : {}),
|
|
26
|
+
},
|
|
27
|
+
actor,
|
|
28
|
+
);
|
|
29
|
+
if (!result.ok) return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
30
|
+
return c.json({ data: result.value });
|
|
31
|
+
});
|
|
32
|
+
|
|
16
33
|
// @ts-expect-error -- openapi handler union return type
|
|
17
34
|
router.openapi(inventoryCheckRoute, async (c) => {
|
|
18
35
|
const entityIds = (c.req.query("entityIds") ?? "")
|