@01.software/cli 0.8.0 → 0.9.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/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/{chunk-45ZCPS57.js → chunk-GJOQ4SE2.js} +895 -657
- package/dist/mcp/chunk-GJOQ4SE2.js.map +1 -0
- package/dist/mcp/http.js +28 -23
- package/dist/mcp/http.js.map +1 -1
- package/dist/mcp/stdio.js +1 -1
- package/dist/mcp/vercel.js +911 -680
- package/package.json +3 -3
- package/dist/mcp/chunk-45ZCPS57.js.map +0 -1
package/dist/mcp/vercel.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
// src/handler.ts
|
|
2
2
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
|
|
4
|
+
// ../../packages/auth-contracts/dist/index.js
|
|
5
|
+
var MCP_RESOURCE_AUDIENCE = "https://mcp.01.software/mcp";
|
|
6
|
+
var MCP_OAUTH_ISSUER = "https://01.software";
|
|
7
|
+
var MCP_PROTECTED_RESOURCE_METADATA_PATH = "/.well-known/oauth-protected-resource/mcp";
|
|
8
|
+
var MCP_TENANT_CLAIM = "tenant_id";
|
|
9
|
+
var MCP_TENANT_ROLE_CLAIM = "tenant_role";
|
|
10
|
+
var MCP_SCOPES = {
|
|
11
|
+
read: "mcp:read",
|
|
12
|
+
write: "mcp:write"
|
|
13
|
+
};
|
|
14
|
+
var MCP_CONSOLE_SERVICE_AUDIENCE = "https://api.01.software/internal/mcp";
|
|
15
|
+
var MCP_CONSOLE_SERVICE_SCOPE = "console:mcp_proxy";
|
|
16
|
+
var MCP_SERVICE_TOKEN_LIFETIME_SECONDS = 60;
|
|
9
17
|
|
|
10
18
|
// src/server.ts
|
|
11
19
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
12
20
|
|
|
13
|
-
// src/tools/query-collection.ts
|
|
14
|
-
import { z } from "zod";
|
|
15
|
-
|
|
16
21
|
// src/lib/request-context.ts
|
|
17
22
|
import { AsyncLocalStorage } from "async_hooks";
|
|
18
23
|
var requestContext = new AsyncLocalStorage();
|
|
@@ -23,6 +28,346 @@ function hasRequestContext() {
|
|
|
23
28
|
return requestContext.getStore() !== void 0;
|
|
24
29
|
}
|
|
25
30
|
|
|
31
|
+
// src/lib/tool-utils.ts
|
|
32
|
+
function toolSuccess(data) {
|
|
33
|
+
return JSON.stringify({ success: true, ...data }, null, 2);
|
|
34
|
+
}
|
|
35
|
+
function toolError(error) {
|
|
36
|
+
const base = { success: false };
|
|
37
|
+
const isStructured = !!error && typeof error === "object" && ("code" in error || "reason" in error);
|
|
38
|
+
if (isStructured) {
|
|
39
|
+
const sdkErr = error;
|
|
40
|
+
base.error = sdkErr.message || "Unknown error";
|
|
41
|
+
if (sdkErr.status) base.status = sdkErr.status;
|
|
42
|
+
if (sdkErr.code) base.code = sdkErr.code;
|
|
43
|
+
if (sdkErr.reason) base.reason = sdkErr.reason;
|
|
44
|
+
if (sdkErr.requestId) base.requestId = sdkErr.requestId;
|
|
45
|
+
if (sdkErr.suggestion) base.suggestion = sdkErr.suggestion;
|
|
46
|
+
if (sdkErr.details?.errors) base.errors = sdkErr.details.errors;
|
|
47
|
+
} else {
|
|
48
|
+
base.error = error instanceof Error ? error.message : "Unknown error";
|
|
49
|
+
}
|
|
50
|
+
return JSON.stringify(base, null, 2);
|
|
51
|
+
}
|
|
52
|
+
var MAX_QUERY_DEPTH = 5;
|
|
53
|
+
function checkDepth(obj, depth = 0) {
|
|
54
|
+
if (depth > MAX_QUERY_DEPTH) return false;
|
|
55
|
+
if (obj && typeof obj === "object") {
|
|
56
|
+
for (const val of Object.values(obj)) {
|
|
57
|
+
if (!checkDepth(val, depth + 1)) return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
function parseJsonWhere(where) {
|
|
63
|
+
try {
|
|
64
|
+
const parsed = JSON.parse(where);
|
|
65
|
+
if (!checkDepth(parsed)) {
|
|
66
|
+
return {
|
|
67
|
+
success: false,
|
|
68
|
+
error: JSON.stringify(
|
|
69
|
+
{
|
|
70
|
+
success: false,
|
|
71
|
+
error: `Query exceeds maximum nesting depth of ${MAX_QUERY_DEPTH}`
|
|
72
|
+
},
|
|
73
|
+
null,
|
|
74
|
+
2
|
|
75
|
+
)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return { success: true, data: parsed };
|
|
79
|
+
} catch {
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
error: JSON.stringify(
|
|
83
|
+
{
|
|
84
|
+
success: false,
|
|
85
|
+
error: `Invalid JSON in "where" parameter: ${where.length > 100 ? where.substring(0, 100) + "..." : where}`
|
|
86
|
+
},
|
|
87
|
+
null,
|
|
88
|
+
2
|
|
89
|
+
)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/tool-policy.ts
|
|
95
|
+
var READ_ONLY_ANNOTATION = {
|
|
96
|
+
readOnly: true,
|
|
97
|
+
destructive: false,
|
|
98
|
+
idempotent: true,
|
|
99
|
+
openWorld: false
|
|
100
|
+
};
|
|
101
|
+
var NON_DESTRUCTIVE_MUTATION_ANNOTATION = {
|
|
102
|
+
readOnly: false,
|
|
103
|
+
destructive: false,
|
|
104
|
+
idempotent: false,
|
|
105
|
+
openWorld: false
|
|
106
|
+
};
|
|
107
|
+
var NON_DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION = {
|
|
108
|
+
readOnly: false,
|
|
109
|
+
destructive: false,
|
|
110
|
+
idempotent: true,
|
|
111
|
+
openWorld: false
|
|
112
|
+
};
|
|
113
|
+
var DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION = {
|
|
114
|
+
readOnly: false,
|
|
115
|
+
destructive: true,
|
|
116
|
+
idempotent: false,
|
|
117
|
+
openWorld: false
|
|
118
|
+
};
|
|
119
|
+
var DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION = {
|
|
120
|
+
readOnly: false,
|
|
121
|
+
destructive: true,
|
|
122
|
+
idempotent: true,
|
|
123
|
+
openWorld: false
|
|
124
|
+
};
|
|
125
|
+
var REASON_IDEMPOTENT_DESTRUCTIVE_UPDATE = "Update operations mutate persisted state but converge to the same end state under repeated identical input.";
|
|
126
|
+
var REASON_CART_EPHEMERAL = "Cart is pre-checkout ephemeral state; reversal is possible by reissuing the prior input. Console enforces tenant scope.";
|
|
127
|
+
var TOOL_POLICY_MANIFEST = {
|
|
128
|
+
// ── Read-only collection / validation (mcp:read, tenant-viewer) ──
|
|
129
|
+
"query-collection": {
|
|
130
|
+
category: "read-only-collection",
|
|
131
|
+
oauthScope: MCP_SCOPES.read,
|
|
132
|
+
consoleRole: "tenant-viewer",
|
|
133
|
+
consoleSurface: "GET /api/{collection}",
|
|
134
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
135
|
+
},
|
|
136
|
+
"get-collection-by-id": {
|
|
137
|
+
category: "read-only-collection",
|
|
138
|
+
oauthScope: MCP_SCOPES.read,
|
|
139
|
+
consoleRole: "tenant-viewer",
|
|
140
|
+
consoleSurface: "GET /api/{collection}/{id}",
|
|
141
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
142
|
+
},
|
|
143
|
+
"get-order": {
|
|
144
|
+
category: "read-only-collection",
|
|
145
|
+
oauthScope: MCP_SCOPES.read,
|
|
146
|
+
consoleRole: "tenant-viewer",
|
|
147
|
+
consoleSurface: "GET /api/orders/{id}",
|
|
148
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
149
|
+
},
|
|
150
|
+
"stock-check": {
|
|
151
|
+
category: "read-only-collection",
|
|
152
|
+
oauthScope: MCP_SCOPES.read,
|
|
153
|
+
consoleRole: "tenant-viewer",
|
|
154
|
+
consoleSurface: "GET /api/products/{id}/stock",
|
|
155
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
156
|
+
},
|
|
157
|
+
"validate-discount": {
|
|
158
|
+
category: "read-only-collection",
|
|
159
|
+
oauthScope: MCP_SCOPES.read,
|
|
160
|
+
consoleRole: "tenant-viewer",
|
|
161
|
+
consoleSurface: "POST /api/discounts/validate",
|
|
162
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
163
|
+
},
|
|
164
|
+
"calculate-shipping": {
|
|
165
|
+
category: "read-only-collection",
|
|
166
|
+
oauthScope: MCP_SCOPES.read,
|
|
167
|
+
consoleRole: "tenant-viewer",
|
|
168
|
+
consoleSurface: "POST /api/shipping/calculate",
|
|
169
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
170
|
+
},
|
|
171
|
+
"get-collection-schema": {
|
|
172
|
+
category: "read-only-collection",
|
|
173
|
+
oauthScope: MCP_SCOPES.read,
|
|
174
|
+
consoleRole: "tenant-viewer",
|
|
175
|
+
consoleSurface: "GET /api/tenants/schema/{collectionSlug}",
|
|
176
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
177
|
+
},
|
|
178
|
+
"list-configurable-fields": {
|
|
179
|
+
category: "read-only-collection",
|
|
180
|
+
oauthScope: MCP_SCOPES.read,
|
|
181
|
+
consoleRole: "tenant-viewer",
|
|
182
|
+
consoleSurface: "GET /api/tenants/field-config",
|
|
183
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
184
|
+
},
|
|
185
|
+
// ── Tenant context (mcp:read, tenant-viewer) ──
|
|
186
|
+
"get-tenant-context": {
|
|
187
|
+
category: "read-only-tenant",
|
|
188
|
+
oauthScope: MCP_SCOPES.read,
|
|
189
|
+
consoleRole: "tenant-viewer",
|
|
190
|
+
consoleSurface: "GET /api/tenants/context",
|
|
191
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
192
|
+
},
|
|
193
|
+
// ── Cart mutations (mcp:write, tenant-editor) ──
|
|
194
|
+
"add-cart-item": {
|
|
195
|
+
category: "mutation-cart",
|
|
196
|
+
oauthScope: MCP_SCOPES.write,
|
|
197
|
+
consoleRole: "tenant-editor",
|
|
198
|
+
consoleSurface: "POST /api/carts/{id}/items",
|
|
199
|
+
annotationPolicy: NON_DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION
|
|
200
|
+
},
|
|
201
|
+
"update-cart-item": {
|
|
202
|
+
category: "mutation-cart",
|
|
203
|
+
oauthScope: MCP_SCOPES.write,
|
|
204
|
+
consoleRole: "tenant-editor",
|
|
205
|
+
consoleSurface: "PATCH /api/carts/{id}/items/{itemId}",
|
|
206
|
+
annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
|
|
207
|
+
exemptionReason: REASON_CART_EPHEMERAL
|
|
208
|
+
},
|
|
209
|
+
"remove-cart-item": {
|
|
210
|
+
category: "mutation-cart",
|
|
211
|
+
oauthScope: MCP_SCOPES.write,
|
|
212
|
+
consoleRole: "tenant-editor",
|
|
213
|
+
consoleSurface: "DELETE /api/carts/{id}/items/{itemId}",
|
|
214
|
+
annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
|
|
215
|
+
exemptionReason: REASON_CART_EPHEMERAL
|
|
216
|
+
},
|
|
217
|
+
"clear-cart": {
|
|
218
|
+
category: "mutation-cart",
|
|
219
|
+
oauthScope: MCP_SCOPES.write,
|
|
220
|
+
consoleRole: "tenant-editor",
|
|
221
|
+
consoleSurface: "POST /api/carts/{id}/clear",
|
|
222
|
+
annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
|
|
223
|
+
exemptionReason: REASON_CART_EPHEMERAL
|
|
224
|
+
},
|
|
225
|
+
"apply-discount": {
|
|
226
|
+
category: "mutation-cart",
|
|
227
|
+
oauthScope: MCP_SCOPES.write,
|
|
228
|
+
consoleRole: "tenant-editor",
|
|
229
|
+
consoleSurface: "POST /api/carts/{id}/discount",
|
|
230
|
+
annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
|
|
231
|
+
exemptionReason: REASON_CART_EPHEMERAL
|
|
232
|
+
},
|
|
233
|
+
"remove-discount": {
|
|
234
|
+
category: "mutation-cart",
|
|
235
|
+
oauthScope: MCP_SCOPES.write,
|
|
236
|
+
consoleRole: "tenant-editor",
|
|
237
|
+
consoleSurface: "DELETE /api/carts/{id}/discount",
|
|
238
|
+
annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
|
|
239
|
+
exemptionReason: REASON_CART_EPHEMERAL
|
|
240
|
+
},
|
|
241
|
+
// ── Order mutations (mcp:write, tenant-admin) ──
|
|
242
|
+
"checkout": {
|
|
243
|
+
category: "mutation-order",
|
|
244
|
+
oauthScope: MCP_SCOPES.write,
|
|
245
|
+
consoleRole: "tenant-admin",
|
|
246
|
+
consoleSurface: "POST /api/checkout",
|
|
247
|
+
annotationPolicy: DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION
|
|
248
|
+
},
|
|
249
|
+
"create-order": {
|
|
250
|
+
category: "mutation-order",
|
|
251
|
+
oauthScope: MCP_SCOPES.write,
|
|
252
|
+
consoleRole: "tenant-admin",
|
|
253
|
+
consoleSurface: "POST /api/orders",
|
|
254
|
+
annotationPolicy: DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION
|
|
255
|
+
},
|
|
256
|
+
"update-order": {
|
|
257
|
+
category: "mutation-order",
|
|
258
|
+
oauthScope: MCP_SCOPES.write,
|
|
259
|
+
consoleRole: "tenant-admin",
|
|
260
|
+
consoleSurface: "PATCH /api/orders/{id}",
|
|
261
|
+
annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
|
|
262
|
+
exemptionReason: REASON_IDEMPOTENT_DESTRUCTIVE_UPDATE
|
|
263
|
+
},
|
|
264
|
+
// ── Fulfillment mutations (mcp:write, tenant-admin) ──
|
|
265
|
+
"create-fulfillment": {
|
|
266
|
+
category: "mutation-fulfillment",
|
|
267
|
+
oauthScope: MCP_SCOPES.write,
|
|
268
|
+
consoleRole: "tenant-admin",
|
|
269
|
+
consoleSurface: "POST /api/orders/{id}/fulfillments",
|
|
270
|
+
annotationPolicy: NON_DESTRUCTIVE_MUTATION_ANNOTATION
|
|
271
|
+
},
|
|
272
|
+
"update-fulfillment": {
|
|
273
|
+
category: "mutation-fulfillment",
|
|
274
|
+
oauthScope: MCP_SCOPES.write,
|
|
275
|
+
consoleRole: "tenant-admin",
|
|
276
|
+
consoleSurface: "PATCH /api/fulfillments/{id}",
|
|
277
|
+
annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
|
|
278
|
+
exemptionReason: REASON_IDEMPOTENT_DESTRUCTIVE_UPDATE
|
|
279
|
+
},
|
|
280
|
+
// ── Return mutations (mcp:write, tenant-admin) ──
|
|
281
|
+
"create-return": {
|
|
282
|
+
category: "mutation-return",
|
|
283
|
+
oauthScope: MCP_SCOPES.write,
|
|
284
|
+
consoleRole: "tenant-admin",
|
|
285
|
+
consoleSurface: "POST /api/returns",
|
|
286
|
+
annotationPolicy: DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION
|
|
287
|
+
},
|
|
288
|
+
"update-return": {
|
|
289
|
+
category: "mutation-return",
|
|
290
|
+
oauthScope: MCP_SCOPES.write,
|
|
291
|
+
consoleRole: "tenant-admin",
|
|
292
|
+
consoleSurface: "PATCH /api/returns/{id}",
|
|
293
|
+
annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
|
|
294
|
+
exemptionReason: REASON_IDEMPOTENT_DESTRUCTIVE_UPDATE
|
|
295
|
+
},
|
|
296
|
+
"return-with-refund": {
|
|
297
|
+
category: "mutation-return",
|
|
298
|
+
oauthScope: MCP_SCOPES.write,
|
|
299
|
+
consoleRole: "tenant-admin",
|
|
300
|
+
consoleSurface: "POST /api/returns/with-refund",
|
|
301
|
+
annotationPolicy: DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION
|
|
302
|
+
},
|
|
303
|
+
// ── Transaction mutations (mcp:write, tenant-admin) ──
|
|
304
|
+
"update-transaction": {
|
|
305
|
+
category: "mutation-transaction",
|
|
306
|
+
oauthScope: MCP_SCOPES.write,
|
|
307
|
+
consoleRole: "tenant-admin",
|
|
308
|
+
consoleSurface: "PATCH /api/transactions/{id}",
|
|
309
|
+
annotationPolicy: DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION
|
|
310
|
+
},
|
|
311
|
+
// ── Field-config mutations (mcp:write, tenant-admin) ──
|
|
312
|
+
"update-field-config": {
|
|
313
|
+
category: "mutation-field-config",
|
|
314
|
+
oauthScope: MCP_SCOPES.write,
|
|
315
|
+
consoleRole: "tenant-admin",
|
|
316
|
+
consoleSurface: "PATCH /api/tenants/field-config",
|
|
317
|
+
annotationPolicy: NON_DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION
|
|
318
|
+
},
|
|
319
|
+
// ── SDK doc tools (mcp:read, tenant-viewer, sdk-static surface) ──
|
|
320
|
+
"sdk-get-recipe": {
|
|
321
|
+
category: "sdk-doc",
|
|
322
|
+
oauthScope: MCP_SCOPES.read,
|
|
323
|
+
consoleRole: "tenant-viewer",
|
|
324
|
+
consoleSurface: "sdk-static",
|
|
325
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
326
|
+
},
|
|
327
|
+
"sdk-search-docs": {
|
|
328
|
+
category: "sdk-doc",
|
|
329
|
+
oauthScope: MCP_SCOPES.read,
|
|
330
|
+
consoleRole: "tenant-viewer",
|
|
331
|
+
consoleSurface: "sdk-static",
|
|
332
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
333
|
+
},
|
|
334
|
+
"sdk-get-auth-setup": {
|
|
335
|
+
category: "sdk-doc",
|
|
336
|
+
oauthScope: MCP_SCOPES.read,
|
|
337
|
+
consoleRole: "tenant-viewer",
|
|
338
|
+
consoleSurface: "sdk-static",
|
|
339
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
340
|
+
},
|
|
341
|
+
"sdk-get-collection-pattern": {
|
|
342
|
+
category: "sdk-doc",
|
|
343
|
+
oauthScope: MCP_SCOPES.read,
|
|
344
|
+
consoleRole: "tenant-viewer",
|
|
345
|
+
consoleSurface: "sdk-static",
|
|
346
|
+
annotationPolicy: READ_ONLY_ANNOTATION
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
function evaluateToolPolicy(toolName, scopes) {
|
|
350
|
+
const entry = TOOL_POLICY_MANIFEST[toolName];
|
|
351
|
+
if (!entry) {
|
|
352
|
+
return {
|
|
353
|
+
allowed: false,
|
|
354
|
+
reason: "tool_policy_missing",
|
|
355
|
+
message: `No tool-policy entry for ${toolName}`
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (!scopes.includes(entry.oauthScope)) {
|
|
359
|
+
return {
|
|
360
|
+
allowed: false,
|
|
361
|
+
reason: "insufficient_scope",
|
|
362
|
+
message: `Tool ${toolName} requires ${entry.oauthScope}`
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
return { allowed: true, entry };
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/tools/query-collection.ts
|
|
369
|
+
import { z } from "zod";
|
|
370
|
+
|
|
26
371
|
// src/lib/client.ts
|
|
27
372
|
import {
|
|
28
373
|
CollectionClient,
|
|
@@ -34,14 +379,6 @@ import {
|
|
|
34
379
|
|
|
35
380
|
// src/service-auth.ts
|
|
36
381
|
import { createPrivateKey, randomUUID, sign as signBytes } from "crypto";
|
|
37
|
-
import {
|
|
38
|
-
MCP_CONSOLE_SERVICE_AUDIENCE,
|
|
39
|
-
MCP_CONSOLE_SERVICE_SCOPE,
|
|
40
|
-
MCP_OAUTH_ISSUER,
|
|
41
|
-
MCP_SERVICE_TOKEN_LIFETIME_SECONDS,
|
|
42
|
-
MCP_TENANT_CLAIM,
|
|
43
|
-
MCP_TENANT_ROLE_CLAIM
|
|
44
|
-
} from "@01.software/auth-contracts";
|
|
45
382
|
var KEYSET_ENV = "MCP_SERVICE_KEYSET";
|
|
46
383
|
function assertProductionKeysetUse(source) {
|
|
47
384
|
const vercelEnv = process.env.VERCEL_ENV;
|
|
@@ -227,68 +564,6 @@ function getClient() {
|
|
|
227
564
|
|
|
228
565
|
// src/tools/query-collection.ts
|
|
229
566
|
import { COLLECTIONS } from "@01.software/sdk";
|
|
230
|
-
|
|
231
|
-
// src/lib/tool-utils.ts
|
|
232
|
-
function toolSuccess(data) {
|
|
233
|
-
return JSON.stringify({ success: true, ...data }, null, 2);
|
|
234
|
-
}
|
|
235
|
-
function toolError(error) {
|
|
236
|
-
const base = { success: false };
|
|
237
|
-
if (error && typeof error === "object" && "code" in error) {
|
|
238
|
-
const sdkErr = error;
|
|
239
|
-
base.error = sdkErr.message || "Unknown error";
|
|
240
|
-
if (sdkErr.status) base.status = sdkErr.status;
|
|
241
|
-
if (sdkErr.code) base.code = sdkErr.code;
|
|
242
|
-
if (sdkErr.suggestion) base.suggestion = sdkErr.suggestion;
|
|
243
|
-
if (sdkErr.details?.errors) base.errors = sdkErr.details.errors;
|
|
244
|
-
} else {
|
|
245
|
-
base.error = error instanceof Error ? error.message : "Unknown error";
|
|
246
|
-
}
|
|
247
|
-
return JSON.stringify(base, null, 2);
|
|
248
|
-
}
|
|
249
|
-
var MAX_QUERY_DEPTH = 5;
|
|
250
|
-
function checkDepth(obj, depth = 0) {
|
|
251
|
-
if (depth > MAX_QUERY_DEPTH) return false;
|
|
252
|
-
if (obj && typeof obj === "object") {
|
|
253
|
-
for (const val of Object.values(obj)) {
|
|
254
|
-
if (!checkDepth(val, depth + 1)) return false;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return true;
|
|
258
|
-
}
|
|
259
|
-
function parseJsonWhere(where) {
|
|
260
|
-
try {
|
|
261
|
-
const parsed = JSON.parse(where);
|
|
262
|
-
if (!checkDepth(parsed)) {
|
|
263
|
-
return {
|
|
264
|
-
success: false,
|
|
265
|
-
error: JSON.stringify(
|
|
266
|
-
{
|
|
267
|
-
success: false,
|
|
268
|
-
error: `Query exceeds maximum nesting depth of ${MAX_QUERY_DEPTH}`
|
|
269
|
-
},
|
|
270
|
-
null,
|
|
271
|
-
2
|
|
272
|
-
)
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
return { success: true, data: parsed };
|
|
276
|
-
} catch {
|
|
277
|
-
return {
|
|
278
|
-
success: false,
|
|
279
|
-
error: JSON.stringify(
|
|
280
|
-
{
|
|
281
|
-
success: false,
|
|
282
|
-
error: `Invalid JSON in "where" parameter: ${where.length > 100 ? where.substring(0, 100) + "..." : where}`
|
|
283
|
-
},
|
|
284
|
-
null,
|
|
285
|
-
2
|
|
286
|
-
)
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// src/tools/query-collection.ts
|
|
292
567
|
var schema = {
|
|
293
568
|
collection: z.enum(COLLECTIONS).describe("Collection name (required)"),
|
|
294
569
|
where: z.string().optional().describe(
|
|
@@ -361,219 +636,30 @@ var metadata2 = {
|
|
|
361
636
|
description: "Get a specific collection item by ID",
|
|
362
637
|
annotations: {
|
|
363
638
|
title: "Get collection item by ID",
|
|
364
|
-
readOnlyHint: true,
|
|
365
|
-
destructiveHint: false,
|
|
366
|
-
idempotentHint: true
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
async function getCollectionById({
|
|
370
|
-
collection,
|
|
371
|
-
id
|
|
372
|
-
}) {
|
|
373
|
-
try {
|
|
374
|
-
const client = getClient().collections;
|
|
375
|
-
const result = await client.from(collection).findById(id);
|
|
376
|
-
return toolSuccess({ data: result });
|
|
377
|
-
} catch (error) {
|
|
378
|
-
return toolError(error);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// src/tools/create-collection.ts
|
|
383
|
-
import { z as z3 } from "zod";
|
|
384
|
-
import { COLLECTIONS as COLLECTIONS3 } from "@01.software/sdk";
|
|
385
|
-
var schema3 = {
|
|
386
|
-
collection: z3.enum(COLLECTIONS3).describe("Collection name (required)"),
|
|
387
|
-
data: z3.record(z3.string(), z3.unknown()).describe(
|
|
388
|
-
"Data to create (required). Use get-collection-schema first to understand writable fields, hidden fields, and required metadata. Server will validate and reject invalid fields."
|
|
389
|
-
)
|
|
390
|
-
};
|
|
391
|
-
var metadata3 = {
|
|
392
|
-
name: "create-collection",
|
|
393
|
-
description: "Create a new collection item",
|
|
394
|
-
annotations: {
|
|
395
|
-
title: "Create collection item",
|
|
396
|
-
readOnlyHint: false,
|
|
397
|
-
destructiveHint: false,
|
|
398
|
-
idempotentHint: false
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
async function createCollection({
|
|
402
|
-
collection,
|
|
403
|
-
data
|
|
404
|
-
}) {
|
|
405
|
-
try {
|
|
406
|
-
const client = getClient().collections;
|
|
407
|
-
const result = await client.from(collection).create(data);
|
|
408
|
-
return toolSuccess({ data: result.doc, message: result.message });
|
|
409
|
-
} catch (error) {
|
|
410
|
-
return toolError(error);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// src/tools/update-collection.ts
|
|
415
|
-
import { z as z4 } from "zod";
|
|
416
|
-
import { COLLECTIONS as COLLECTIONS4 } from "@01.software/sdk";
|
|
417
|
-
var schema4 = {
|
|
418
|
-
collection: z4.enum(COLLECTIONS4).describe("Collection name (required)"),
|
|
419
|
-
id: z4.string().min(1).describe("Item ID (required)"),
|
|
420
|
-
data: z4.record(z4.string(), z4.unknown()).describe(
|
|
421
|
-
"Data to update (required). Use get-collection-by-id first to check current structure, then get-collection-schema to confirm writable fields and required metadata. Server will validate and reject invalid fields."
|
|
422
|
-
)
|
|
423
|
-
};
|
|
424
|
-
var metadata4 = {
|
|
425
|
-
name: "update-collection",
|
|
426
|
-
description: "Update an existing collection item",
|
|
427
|
-
annotations: {
|
|
428
|
-
title: "Update collection item",
|
|
429
|
-
readOnlyHint: false,
|
|
430
|
-
destructiveHint: true,
|
|
431
|
-
idempotentHint: true
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
async function updateCollection({
|
|
435
|
-
collection,
|
|
436
|
-
id,
|
|
437
|
-
data
|
|
438
|
-
}) {
|
|
439
|
-
try {
|
|
440
|
-
const client = getClient().collections;
|
|
441
|
-
const result = await client.from(collection).update(id, data);
|
|
442
|
-
return toolSuccess({ data: result.doc, message: result.message });
|
|
443
|
-
} catch (error) {
|
|
444
|
-
return toolError(error);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// src/tools/delete-collection.ts
|
|
449
|
-
import { z as z5 } from "zod";
|
|
450
|
-
import { COLLECTIONS as COLLECTIONS5 } from "@01.software/sdk";
|
|
451
|
-
var schema5 = {
|
|
452
|
-
collection: z5.enum(COLLECTIONS5).describe("Collection name (required)"),
|
|
453
|
-
id: z5.string().min(1).describe("Item ID (required)")
|
|
454
|
-
};
|
|
455
|
-
var metadata5 = {
|
|
456
|
-
name: "delete-collection",
|
|
457
|
-
description: "Delete a collection item",
|
|
458
|
-
annotations: {
|
|
459
|
-
title: "Delete collection item",
|
|
460
|
-
readOnlyHint: false,
|
|
461
|
-
destructiveHint: true,
|
|
462
|
-
idempotentHint: true
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
async function deleteCollection({
|
|
466
|
-
collection,
|
|
467
|
-
id
|
|
468
|
-
}) {
|
|
469
|
-
try {
|
|
470
|
-
const client = getClient();
|
|
471
|
-
await client.collections.from(collection).remove(id);
|
|
472
|
-
return toolSuccess({ message: "Deleted successfully." });
|
|
473
|
-
} catch (error) {
|
|
474
|
-
return toolError(error);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
// src/tools/delete-many-collection.ts
|
|
479
|
-
import { z as z6 } from "zod";
|
|
480
|
-
import { COLLECTIONS as COLLECTIONS6 } from "@01.software/sdk";
|
|
481
|
-
var schema6 = {
|
|
482
|
-
collection: z6.enum(COLLECTIONS6).describe("Collection name (required)"),
|
|
483
|
-
where: z6.string().describe(
|
|
484
|
-
`Filter conditions (JSON string, required). Determines which items to delete. Example: '{"status":{"equals":"archived"}}'`
|
|
485
|
-
)
|
|
486
|
-
};
|
|
487
|
-
var metadata6 = {
|
|
488
|
-
name: "delete-many-collection",
|
|
489
|
-
description: "Bulk delete collection items matching a filter. All matching items will be permanently deleted.",
|
|
490
|
-
annotations: {
|
|
491
|
-
title: "Bulk delete collection items",
|
|
492
|
-
readOnlyHint: false,
|
|
493
|
-
destructiveHint: true,
|
|
494
|
-
idempotentHint: true
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
async function deleteManyCollection({
|
|
498
|
-
collection,
|
|
499
|
-
where
|
|
500
|
-
}) {
|
|
501
|
-
try {
|
|
502
|
-
const client = getClient().collections;
|
|
503
|
-
const parsed = parseJsonWhere(where);
|
|
504
|
-
if (!parsed.success) return parsed.error;
|
|
505
|
-
if (!parsed.data || typeof parsed.data !== "object" || Object.keys(parsed.data).length === 0) {
|
|
506
|
-
return toolError(
|
|
507
|
-
new Error(
|
|
508
|
-
'Empty "where" filter is not allowed for bulk deletes. Provide at least one filter condition.'
|
|
509
|
-
)
|
|
510
|
-
);
|
|
511
|
-
}
|
|
512
|
-
const result = await client.from(collection).removeMany(parsed.data);
|
|
513
|
-
return toolSuccess({
|
|
514
|
-
totalDocs: result.totalDocs,
|
|
515
|
-
message: `Deleted ${result.totalDocs} item(s).`
|
|
516
|
-
});
|
|
517
|
-
} catch (error) {
|
|
518
|
-
return toolError(error);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// src/tools/update-many-collection.ts
|
|
523
|
-
import { z as z7 } from "zod";
|
|
524
|
-
import { COLLECTIONS as COLLECTIONS7 } from "@01.software/sdk";
|
|
525
|
-
var schema7 = {
|
|
526
|
-
collection: z7.enum(COLLECTIONS7).describe("Collection name (required)"),
|
|
527
|
-
where: z7.string().describe(
|
|
528
|
-
`Filter conditions (JSON string, required). Determines which items to update. Example: '{"status":{"equals":"draft"}}'`
|
|
529
|
-
),
|
|
530
|
-
data: z7.record(z7.string(), z7.unknown()).describe(
|
|
531
|
-
"Data to update (required). Partial updates supported. Server will validate and reject invalid fields."
|
|
532
|
-
)
|
|
533
|
-
};
|
|
534
|
-
var metadata7 = {
|
|
535
|
-
name: "update-many-collection",
|
|
536
|
-
description: "Bulk update collection items matching a filter. All matching items will be updated with the provided data.",
|
|
537
|
-
annotations: {
|
|
538
|
-
title: "Bulk update collection items",
|
|
539
|
-
readOnlyHint: false,
|
|
540
|
-
destructiveHint: true,
|
|
639
|
+
readOnlyHint: true,
|
|
640
|
+
destructiveHint: false,
|
|
541
641
|
idempotentHint: true
|
|
542
642
|
}
|
|
543
643
|
};
|
|
544
|
-
async function
|
|
644
|
+
async function getCollectionById({
|
|
545
645
|
collection,
|
|
546
|
-
|
|
547
|
-
data
|
|
646
|
+
id
|
|
548
647
|
}) {
|
|
549
648
|
try {
|
|
550
649
|
const client = getClient().collections;
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
if (!parsed.data || typeof parsed.data !== "object" || Object.keys(parsed.data).length === 0) {
|
|
554
|
-
return toolError(
|
|
555
|
-
new Error(
|
|
556
|
-
'Empty "where" filter is not allowed for bulk updates. Provide at least one filter condition.'
|
|
557
|
-
)
|
|
558
|
-
);
|
|
559
|
-
}
|
|
560
|
-
const result = await client.from(collection).updateMany(parsed.data, data);
|
|
561
|
-
return toolSuccess({
|
|
562
|
-
data: result.docs,
|
|
563
|
-
totalDocs: result.totalDocs,
|
|
564
|
-
message: `Updated ${result.totalDocs} item(s).`
|
|
565
|
-
});
|
|
650
|
+
const result = await client.from(collection).findById(id);
|
|
651
|
+
return toolSuccess({ data: result });
|
|
566
652
|
} catch (error) {
|
|
567
653
|
return toolError(error);
|
|
568
654
|
}
|
|
569
655
|
}
|
|
570
656
|
|
|
571
657
|
// src/tools/get-order.ts
|
|
572
|
-
import { z as
|
|
573
|
-
var
|
|
574
|
-
orderNumber:
|
|
658
|
+
import { z as z3 } from "zod";
|
|
659
|
+
var schema3 = {
|
|
660
|
+
orderNumber: z3.string().min(1).describe("Order number to look up (required)")
|
|
575
661
|
};
|
|
576
|
-
var
|
|
662
|
+
var metadata3 = {
|
|
577
663
|
name: "get-order",
|
|
578
664
|
description: "Get order details by order number. Returns order with related data (depth:1).",
|
|
579
665
|
annotations: {
|
|
@@ -601,26 +687,26 @@ async function getOrder({
|
|
|
601
687
|
}
|
|
602
688
|
|
|
603
689
|
// src/tools/create-order.ts
|
|
604
|
-
import { z as
|
|
605
|
-
var
|
|
606
|
-
pgPaymentId:
|
|
607
|
-
orderNumber:
|
|
608
|
-
customerSnapshot:
|
|
609
|
-
name:
|
|
610
|
-
email:
|
|
611
|
-
phone:
|
|
690
|
+
import { z as z4 } from "zod";
|
|
691
|
+
var schema4 = {
|
|
692
|
+
pgPaymentId: z4.string().optional().describe("PG payment ID (optional \u2014 omit for free orders)"),
|
|
693
|
+
orderNumber: z4.string().min(1).describe("Unique order number (required)"),
|
|
694
|
+
customerSnapshot: z4.object({
|
|
695
|
+
name: z4.string().optional().describe("Customer name"),
|
|
696
|
+
email: z4.string().describe("Customer email (required)"),
|
|
697
|
+
phone: z4.string().optional().describe("Customer phone")
|
|
612
698
|
}).describe("Customer snapshot at time of order (required)"),
|
|
613
|
-
shippingAddress:
|
|
699
|
+
shippingAddress: z4.record(z4.string(), z4.unknown()).describe(
|
|
614
700
|
"Shipping address object (required). Fields: postalCode, address1, address2, deliveryMessage, recipientName, phone"
|
|
615
701
|
),
|
|
616
|
-
orderItems:
|
|
702
|
+
orderItems: z4.array(z4.record(z4.string(), z4.unknown())).describe(
|
|
617
703
|
"Array of order item objects (required). Each: { product, variant, option, quantity, unitPrice?, totalPrice? }"
|
|
618
704
|
),
|
|
619
|
-
totalAmount:
|
|
620
|
-
shippingAmount:
|
|
621
|
-
discountCode:
|
|
705
|
+
totalAmount: z4.number().nonnegative().describe("Total order amount (required, min 0)"),
|
|
706
|
+
shippingAmount: z4.number().nonnegative().optional().describe("Shipping amount (optional, default 0)"),
|
|
707
|
+
discountCode: z4.string().optional().describe("Discount code to apply (optional)")
|
|
622
708
|
};
|
|
623
|
-
var
|
|
709
|
+
var metadata4 = {
|
|
624
710
|
name: "create-order",
|
|
625
711
|
description: "Create a new order with products and shipping information. Supports idempotency.",
|
|
626
712
|
annotations: {
|
|
@@ -643,10 +729,10 @@ async function createOrder(params) {
|
|
|
643
729
|
}
|
|
644
730
|
|
|
645
731
|
// src/tools/update-order.ts
|
|
646
|
-
import { z as
|
|
647
|
-
var
|
|
648
|
-
orderNumber:
|
|
649
|
-
status:
|
|
732
|
+
import { z as z5 } from "zod";
|
|
733
|
+
var schema5 = {
|
|
734
|
+
orderNumber: z5.string().min(1).describe("Order number (required)"),
|
|
735
|
+
status: z5.enum([
|
|
650
736
|
"pending",
|
|
651
737
|
"paid",
|
|
652
738
|
"failed",
|
|
@@ -659,7 +745,7 @@ var schema10 = {
|
|
|
659
745
|
"New order status. Return-related statuses (return_requested, return_processing, returned) must be set via Return endpoints."
|
|
660
746
|
)
|
|
661
747
|
};
|
|
662
|
-
var
|
|
748
|
+
var metadata5 = {
|
|
663
749
|
name: "update-order",
|
|
664
750
|
description: "Update order status. Automatically adjusts stock on status changes (e.g., canceled restores stock).",
|
|
665
751
|
annotations: {
|
|
@@ -683,17 +769,17 @@ async function updateOrder({
|
|
|
683
769
|
}
|
|
684
770
|
|
|
685
771
|
// src/tools/checkout.ts
|
|
686
|
-
import { z as
|
|
687
|
-
var
|
|
688
|
-
cartId:
|
|
689
|
-
pgPaymentId:
|
|
690
|
-
orderNumber:
|
|
691
|
-
customerSnapshot:
|
|
772
|
+
import { z as z6 } from "zod";
|
|
773
|
+
var schema6 = {
|
|
774
|
+
cartId: z6.string().min(1).describe("Cart ID to convert to order (required)"),
|
|
775
|
+
pgPaymentId: z6.string().optional().describe("PG payment ID (optional \u2014 omit for free orders)"),
|
|
776
|
+
orderNumber: z6.string().min(1).describe("Unique order number (required)"),
|
|
777
|
+
customerSnapshot: z6.record(z6.string(), z6.unknown()).describe(
|
|
692
778
|
"Customer snapshot object (required). Fields: { name?, email, phone? }"
|
|
693
779
|
),
|
|
694
|
-
discountCode:
|
|
780
|
+
discountCode: z6.string().optional().describe("Discount code to apply (optional)")
|
|
695
781
|
};
|
|
696
|
-
var
|
|
782
|
+
var metadata6 = {
|
|
697
783
|
name: "checkout",
|
|
698
784
|
description: "Convert a cart to an order. Validates stock, creates order and transaction, marks cart as completed. Supports idempotency.",
|
|
699
785
|
annotations: {
|
|
@@ -716,21 +802,21 @@ async function checkout(params) {
|
|
|
716
802
|
}
|
|
717
803
|
|
|
718
804
|
// src/tools/create-fulfillment.ts
|
|
719
|
-
import { z as
|
|
720
|
-
var
|
|
721
|
-
orderNumber:
|
|
722
|
-
carrier:
|
|
723
|
-
trackingNumber:
|
|
805
|
+
import { z as z7 } from "zod";
|
|
806
|
+
var schema7 = {
|
|
807
|
+
orderNumber: z7.string().min(1).describe("Order number (required)"),
|
|
808
|
+
carrier: z7.string().optional().describe("Shipping carrier name (optional)"),
|
|
809
|
+
trackingNumber: z7.string().optional().describe(
|
|
724
810
|
'Tracking number (optional). Setting carrier + tracking triggers "shipped" status'
|
|
725
811
|
),
|
|
726
|
-
items:
|
|
727
|
-
|
|
728
|
-
orderItem:
|
|
729
|
-
quantity:
|
|
812
|
+
items: z7.array(
|
|
813
|
+
z7.object({
|
|
814
|
+
orderItem: z7.string().min(1).describe("Order item ID"),
|
|
815
|
+
quantity: z7.number().int().positive().describe("Quantity to fulfill")
|
|
730
816
|
})
|
|
731
817
|
).describe("Array of items to fulfill (required)")
|
|
732
818
|
};
|
|
733
|
-
var
|
|
819
|
+
var metadata7 = {
|
|
734
820
|
name: "create-fulfillment",
|
|
735
821
|
description: "Create a shipment/fulfillment for order items. Auto-updates order status (paid \u2192 preparing \u2192 shipped).",
|
|
736
822
|
annotations: {
|
|
@@ -761,20 +847,20 @@ async function createFulfillment({
|
|
|
761
847
|
}
|
|
762
848
|
|
|
763
849
|
// src/tools/update-fulfillment.ts
|
|
764
|
-
import { z as
|
|
765
|
-
var
|
|
766
|
-
fulfillmentId:
|
|
767
|
-
status:
|
|
850
|
+
import { z as z8 } from "zod";
|
|
851
|
+
var schema8 = {
|
|
852
|
+
fulfillmentId: z8.string().min(1).describe("Fulfillment ID (required)"),
|
|
853
|
+
status: z8.enum(["packed", "shipped", "delivered", "failed"]).describe(
|
|
768
854
|
"New fulfillment status (required). FSM: pending\u2192packed/shipped/failed, packed\u2192shipped/failed, shipped\u2192delivered/failed"
|
|
769
855
|
),
|
|
770
|
-
carrier:
|
|
856
|
+
carrier: z8.string().optional().describe(
|
|
771
857
|
"Shipping carrier (optional, changeable only in pending/packed status)"
|
|
772
858
|
),
|
|
773
|
-
trackingNumber:
|
|
859
|
+
trackingNumber: z8.string().optional().describe(
|
|
774
860
|
"Tracking number (optional, changeable only in pending/packed status)"
|
|
775
861
|
)
|
|
776
862
|
};
|
|
777
|
-
var
|
|
863
|
+
var metadata8 = {
|
|
778
864
|
name: "update-fulfillment",
|
|
779
865
|
description: "Update fulfillment status, carrier, and tracking number. Auto-updates order status when all fulfillments are delivered.",
|
|
780
866
|
annotations: {
|
|
@@ -804,15 +890,134 @@ async function updateFulfillment({
|
|
|
804
890
|
}
|
|
805
891
|
}
|
|
806
892
|
|
|
893
|
+
// ../../packages/contracts/src/tenant/index.ts
|
|
894
|
+
import { z as z9 } from "zod";
|
|
895
|
+
var tenantFieldConfigStateSchema = z9.object({
|
|
896
|
+
hiddenFields: z9.array(z9.string()),
|
|
897
|
+
isHidden: z9.boolean()
|
|
898
|
+
}).strict();
|
|
899
|
+
var tenantContextQuerySchema = z9.object({
|
|
900
|
+
counts: z9.literal("true").optional()
|
|
901
|
+
}).strict();
|
|
902
|
+
var tenantContextToolInputSchema = z9.object({
|
|
903
|
+
includeCounts: z9.boolean().optional().default(false).describe(
|
|
904
|
+
"Include per-collection document counts and config status (bypasses cache, slower)"
|
|
905
|
+
)
|
|
906
|
+
}).strict();
|
|
907
|
+
var tenantContextResponseSchema = z9.object({
|
|
908
|
+
tenant: z9.object({
|
|
909
|
+
id: z9.string(),
|
|
910
|
+
name: z9.string(),
|
|
911
|
+
plan: z9.string(),
|
|
912
|
+
planSource: z9.string().optional(),
|
|
913
|
+
authoritative: z9.boolean().optional(),
|
|
914
|
+
capabilityVersion: z9.string().optional(),
|
|
915
|
+
isDevMode: z9.boolean()
|
|
916
|
+
}).strict(),
|
|
917
|
+
features: z9.array(z9.string()),
|
|
918
|
+
collections: z9.object({
|
|
919
|
+
active: z9.array(z9.string()),
|
|
920
|
+
inactive: z9.array(z9.string())
|
|
921
|
+
}).strict(),
|
|
922
|
+
fieldConfigs: z9.record(z9.string(), tenantFieldConfigStateSchema),
|
|
923
|
+
counts: z9.record(z9.string(), z9.number()).optional(),
|
|
924
|
+
config: z9.object({
|
|
925
|
+
webhookConfigured: z9.boolean()
|
|
926
|
+
}).strict().optional()
|
|
927
|
+
}).strict();
|
|
928
|
+
var COLLECTION_SCHEMA_CONTRACT_VERSION = 1;
|
|
929
|
+
var collectionSchemaEndpointParamsSchema = z9.object({
|
|
930
|
+
collectionSlug: z9.string().min(1, "collectionSlug is required")
|
|
931
|
+
}).strict();
|
|
932
|
+
function createCollectionSchemaToolInputSchema(collections) {
|
|
933
|
+
return z9.object({
|
|
934
|
+
collection: z9.enum(collections).describe("Collection name (required)")
|
|
935
|
+
}).strict();
|
|
936
|
+
}
|
|
937
|
+
var collectionFieldOptionSchema = z9.object({
|
|
938
|
+
label: z9.string(),
|
|
939
|
+
value: z9.string()
|
|
940
|
+
}).strict();
|
|
941
|
+
var collectionFieldSchema = z9.lazy(
|
|
942
|
+
() => z9.object({
|
|
943
|
+
name: z9.string(),
|
|
944
|
+
path: z9.string(),
|
|
945
|
+
type: z9.string(),
|
|
946
|
+
required: z9.literal(true).optional(),
|
|
947
|
+
unique: z9.literal(true).optional(),
|
|
948
|
+
hasMany: z9.literal(true).optional(),
|
|
949
|
+
relationTo: z9.union([z9.string(), z9.array(z9.string())]).optional(),
|
|
950
|
+
options: z9.array(collectionFieldOptionSchema).optional(),
|
|
951
|
+
hidden: z9.literal(true).optional(),
|
|
952
|
+
systemManaged: z9.literal(true).optional(),
|
|
953
|
+
writable: z9.boolean().optional(),
|
|
954
|
+
fields: z9.array(collectionFieldSchema).optional()
|
|
955
|
+
}).strict()
|
|
956
|
+
);
|
|
957
|
+
var collectionSchemaResponseSchema = z9.object({
|
|
958
|
+
contractVersion: z9.literal(COLLECTION_SCHEMA_CONTRACT_VERSION),
|
|
959
|
+
mode: z9.literal("effective"),
|
|
960
|
+
collection: z9.object({
|
|
961
|
+
slug: z9.string(),
|
|
962
|
+
timestamps: z9.boolean(),
|
|
963
|
+
alwaysActive: z9.boolean(),
|
|
964
|
+
feature: z9.string().nullable(),
|
|
965
|
+
systemFields: z9.array(z9.string()),
|
|
966
|
+
visibility: z9.object({
|
|
967
|
+
collectionHidden: z9.boolean(),
|
|
968
|
+
hiddenFields: z9.array(z9.string())
|
|
969
|
+
}).strict(),
|
|
970
|
+
fields: z9.array(collectionFieldSchema)
|
|
971
|
+
}).strict()
|
|
972
|
+
}).strict();
|
|
973
|
+
|
|
974
|
+
// ../../packages/contracts/src/ecommerce/index.ts
|
|
975
|
+
import { z as z10 } from "zod";
|
|
976
|
+
var transactionStatusSchema = z10.enum([
|
|
977
|
+
"pending",
|
|
978
|
+
"paid",
|
|
979
|
+
"failed",
|
|
980
|
+
"canceled"
|
|
981
|
+
]);
|
|
982
|
+
var updateTransactionSchema = z10.object({
|
|
983
|
+
pgPaymentId: z10.string().min(1, "pgPaymentId is required").describe("PG payment ID (required)"),
|
|
984
|
+
status: transactionStatusSchema.describe(
|
|
985
|
+
"New transaction status (required)"
|
|
986
|
+
),
|
|
987
|
+
paymentMethod: z10.string().optional().describe("Payment method (optional)"),
|
|
988
|
+
receiptUrl: z10.string().optional().describe("Receipt URL (optional)"),
|
|
989
|
+
paymentKey: z10.string().min(1).optional().describe("Provider payment key for verified paid confirmation"),
|
|
990
|
+
amount: z10.number().int().positive().optional().describe("Provider-confirmed amount for verified paid confirmation")
|
|
991
|
+
}).strict();
|
|
992
|
+
var UpdateTransactionSchema = updateTransactionSchema;
|
|
993
|
+
var returnReasonSchema = z10.enum([
|
|
994
|
+
"change_of_mind",
|
|
995
|
+
"defective",
|
|
996
|
+
"wrong_delivery",
|
|
997
|
+
"damaged",
|
|
998
|
+
"other"
|
|
999
|
+
]);
|
|
1000
|
+
var restockActionSchema = z10.enum(["return_to_stock", "discard"]);
|
|
1001
|
+
var returnWithRefundItemSchema = z10.object({
|
|
1002
|
+
orderItem: z10.union([z10.string(), z10.number()]).transform(String),
|
|
1003
|
+
quantity: z10.number().int().positive("quantity must be a positive integer"),
|
|
1004
|
+
restockAction: restockActionSchema.default("return_to_stock")
|
|
1005
|
+
}).strict();
|
|
1006
|
+
var returnWithRefundSchema = z10.object({
|
|
1007
|
+
orderNumber: z10.string().min(1, "orderNumber is required").describe("Order number (required)"),
|
|
1008
|
+
reason: returnReasonSchema.optional().describe("Return reason (optional)"),
|
|
1009
|
+
reasonDetail: z10.string().optional().describe("Detailed reason text (optional)"),
|
|
1010
|
+
returnItems: z10.array(returnWithRefundItemSchema).min(1, "At least one return item is required").max(100, "Too many return items").describe("Array of products to return (required)"),
|
|
1011
|
+
refundAmount: z10.number().min(0, "refundAmount must be non-negative").describe("Refund amount (required, min 0)"),
|
|
1012
|
+
pgPaymentId: z10.string().min(1, "pgPaymentId is required").describe("PG payment ID for refund (required)"),
|
|
1013
|
+
paymentKey: z10.string().min(1).optional().describe("Provider payment key for verified refund"),
|
|
1014
|
+
refundReceiptUrl: z10.string().optional().describe("Refund receipt URL (optional)")
|
|
1015
|
+
}).strict();
|
|
1016
|
+
var ReturnWithRefundSchema = returnWithRefundSchema;
|
|
1017
|
+
|
|
807
1018
|
// src/tools/update-transaction.ts
|
|
808
|
-
|
|
809
|
-
var
|
|
810
|
-
pgPaymentId: z14.string().min(1).describe("PG payment ID (required)"),
|
|
811
|
-
status: z14.enum(["pending", "paid", "failed", "canceled"]).describe("New transaction status (required)"),
|
|
812
|
-
paymentMethod: z14.string().optional().describe("Payment method (optional)"),
|
|
813
|
-
receiptUrl: z14.string().optional().describe("Receipt URL (optional)")
|
|
814
|
-
};
|
|
815
|
-
var metadata14 = {
|
|
1019
|
+
var schema9 = UpdateTransactionSchema.shape;
|
|
1020
|
+
var metadata9 = {
|
|
816
1021
|
name: "update-transaction",
|
|
817
1022
|
description: "Update transaction status, payment method, and receipt URL.",
|
|
818
1023
|
annotations: {
|
|
@@ -826,16 +1031,21 @@ async function updateTransaction({
|
|
|
826
1031
|
pgPaymentId,
|
|
827
1032
|
status,
|
|
828
1033
|
paymentMethod,
|
|
829
|
-
receiptUrl
|
|
1034
|
+
receiptUrl,
|
|
1035
|
+
paymentKey,
|
|
1036
|
+
amount
|
|
830
1037
|
}) {
|
|
831
1038
|
try {
|
|
832
1039
|
const client = getClient();
|
|
833
|
-
const
|
|
1040
|
+
const params = {
|
|
834
1041
|
pgPaymentId,
|
|
835
1042
|
status,
|
|
836
1043
|
paymentMethod,
|
|
837
|
-
receiptUrl
|
|
838
|
-
|
|
1044
|
+
receiptUrl,
|
|
1045
|
+
paymentKey,
|
|
1046
|
+
amount
|
|
1047
|
+
};
|
|
1048
|
+
const result = await client.commerce.orders.updateTransaction(params);
|
|
839
1049
|
return toolSuccess({ data: result });
|
|
840
1050
|
} catch (error) {
|
|
841
1051
|
return toolError(error);
|
|
@@ -843,20 +1053,20 @@ async function updateTransaction({
|
|
|
843
1053
|
}
|
|
844
1054
|
|
|
845
1055
|
// src/tools/create-return.ts
|
|
846
|
-
import { z as
|
|
847
|
-
var
|
|
848
|
-
orderNumber:
|
|
849
|
-
reason:
|
|
850
|
-
reasonDetail:
|
|
851
|
-
returnItems:
|
|
852
|
-
|
|
853
|
-
orderItem:
|
|
854
|
-
quantity:
|
|
1056
|
+
import { z as z11 } from "zod";
|
|
1057
|
+
var schema10 = {
|
|
1058
|
+
orderNumber: z11.string().min(1).describe("Order number (required)"),
|
|
1059
|
+
reason: z11.enum(["change_of_mind", "defective", "wrong_delivery", "damaged", "other"]).optional().describe("Return reason (optional)"),
|
|
1060
|
+
reasonDetail: z11.string().optional().describe("Detailed reason text (optional)"),
|
|
1061
|
+
returnItems: z11.array(
|
|
1062
|
+
z11.object({
|
|
1063
|
+
orderItem: z11.string().min(1).describe("Order item ID"),
|
|
1064
|
+
quantity: z11.number().int().positive().describe("Quantity to return")
|
|
855
1065
|
})
|
|
856
1066
|
).describe("Array of products to return (required)"),
|
|
857
|
-
refundAmount:
|
|
1067
|
+
refundAmount: z11.number().nonnegative().describe("Refund amount (required, min 0)")
|
|
858
1068
|
};
|
|
859
|
-
var
|
|
1069
|
+
var metadata10 = {
|
|
860
1070
|
name: "create-return",
|
|
861
1071
|
description: "Create a return request for an order. Only works for delivered/confirmed orders. Updates order status to return_requested.",
|
|
862
1072
|
annotations: {
|
|
@@ -889,14 +1099,14 @@ async function createReturn({
|
|
|
889
1099
|
}
|
|
890
1100
|
|
|
891
1101
|
// src/tools/update-return.ts
|
|
892
|
-
import { z as
|
|
893
|
-
var
|
|
894
|
-
returnId:
|
|
895
|
-
status:
|
|
1102
|
+
import { z as z12 } from "zod";
|
|
1103
|
+
var schema11 = {
|
|
1104
|
+
returnId: z12.string().min(1).describe("Return ID (required)"),
|
|
1105
|
+
status: z12.enum(["processing", "approved", "rejected", "completed"]).describe(
|
|
896
1106
|
"New return status (required). Valid transitions: requested\u2192processing/rejected, processing\u2192approved/rejected, approved\u2192completed"
|
|
897
1107
|
)
|
|
898
1108
|
};
|
|
899
|
-
var
|
|
1109
|
+
var metadata11 = {
|
|
900
1110
|
name: "update-return",
|
|
901
1111
|
description: "Update return status with FSM validation. Restores inventory on completion, reverts order status on rejection.",
|
|
902
1112
|
annotations: {
|
|
@@ -920,22 +1130,8 @@ async function updateReturn({
|
|
|
920
1130
|
}
|
|
921
1131
|
|
|
922
1132
|
// src/tools/return-with-refund.ts
|
|
923
|
-
|
|
924
|
-
var
|
|
925
|
-
orderNumber: z17.string().min(1).describe("Order number (required)"),
|
|
926
|
-
reason: z17.enum(["change_of_mind", "defective", "wrong_delivery", "damaged", "other"]).optional().describe("Return reason (optional)"),
|
|
927
|
-
reasonDetail: z17.string().optional().describe("Detailed reason text (optional)"),
|
|
928
|
-
returnItems: z17.array(
|
|
929
|
-
z17.object({
|
|
930
|
-
orderItem: z17.string().min(1).describe("Order item ID"),
|
|
931
|
-
quantity: z17.number().int().positive().describe("Quantity to return")
|
|
932
|
-
})
|
|
933
|
-
).describe("Array of products to return (required)"),
|
|
934
|
-
refundAmount: z17.number().nonnegative().describe("Refund amount (required, min 0)"),
|
|
935
|
-
pgPaymentId: z17.string().min(1).describe("PG payment ID for refund (required)"),
|
|
936
|
-
refundReceiptUrl: z17.string().optional().describe("Refund receipt URL (optional)")
|
|
937
|
-
};
|
|
938
|
-
var metadata17 = {
|
|
1133
|
+
var schema12 = ReturnWithRefundSchema.shape;
|
|
1134
|
+
var metadata12 = {
|
|
939
1135
|
name: "return-with-refund",
|
|
940
1136
|
description: "Combined return + refund operation. Creates return, restores stock, cancels transaction, updates order status.",
|
|
941
1137
|
annotations: {
|
|
@@ -952,19 +1148,22 @@ async function returnWithRefund({
|
|
|
952
1148
|
returnItems,
|
|
953
1149
|
refundAmount,
|
|
954
1150
|
pgPaymentId,
|
|
1151
|
+
paymentKey,
|
|
955
1152
|
refundReceiptUrl
|
|
956
1153
|
}) {
|
|
957
1154
|
try {
|
|
958
1155
|
const client = getClient();
|
|
959
|
-
const
|
|
1156
|
+
const params = {
|
|
960
1157
|
orderNumber,
|
|
961
1158
|
reason,
|
|
962
1159
|
reasonDetail,
|
|
963
1160
|
returnItems,
|
|
964
1161
|
refundAmount,
|
|
965
1162
|
pgPaymentId,
|
|
1163
|
+
paymentKey,
|
|
966
1164
|
refundReceiptUrl
|
|
967
|
-
}
|
|
1165
|
+
};
|
|
1166
|
+
const result = await client.commerce.orders.returnWithRefund(params);
|
|
968
1167
|
return toolSuccess({ data: result });
|
|
969
1168
|
} catch (error) {
|
|
970
1169
|
return toolError(error);
|
|
@@ -972,15 +1171,15 @@ async function returnWithRefund({
|
|
|
972
1171
|
}
|
|
973
1172
|
|
|
974
1173
|
// src/tools/add-cart-item.ts
|
|
975
|
-
import { z as
|
|
976
|
-
var
|
|
977
|
-
cartId:
|
|
978
|
-
product:
|
|
979
|
-
variant:
|
|
980
|
-
option:
|
|
981
|
-
quantity:
|
|
1174
|
+
import { z as z13 } from "zod";
|
|
1175
|
+
var schema13 = {
|
|
1176
|
+
cartId: z13.string().min(1).describe("Cart ID (required)"),
|
|
1177
|
+
product: z13.string().min(1).describe("Product ID (required)"),
|
|
1178
|
+
variant: z13.string().min(1).describe("Product variant ID (required)"),
|
|
1179
|
+
option: z13.string().min(1).describe("Product option ID (required)"),
|
|
1180
|
+
quantity: z13.number().int().positive().describe("Quantity to add (required, positive integer)")
|
|
982
1181
|
};
|
|
983
|
-
var
|
|
1182
|
+
var metadata13 = {
|
|
984
1183
|
name: "add-cart-item",
|
|
985
1184
|
description: "Add a product to cart. Validates stock, merges quantity if item already exists, recalculates totals.",
|
|
986
1185
|
annotations: {
|
|
@@ -1013,12 +1212,12 @@ async function addCartItem({
|
|
|
1013
1212
|
}
|
|
1014
1213
|
|
|
1015
1214
|
// src/tools/update-cart-item.ts
|
|
1016
|
-
import { z as
|
|
1017
|
-
var
|
|
1018
|
-
cartItemId:
|
|
1019
|
-
quantity:
|
|
1215
|
+
import { z as z14 } from "zod";
|
|
1216
|
+
var schema14 = {
|
|
1217
|
+
cartItemId: z14.string().min(1).describe("Cart item ID (required)"),
|
|
1218
|
+
quantity: z14.number().int().positive().describe("New quantity (required, positive integer)")
|
|
1020
1219
|
};
|
|
1021
|
-
var
|
|
1220
|
+
var metadata14 = {
|
|
1022
1221
|
name: "update-cart-item",
|
|
1023
1222
|
description: "Update cart item quantity. Validates stock availability, recalculates cart totals.",
|
|
1024
1223
|
annotations: {
|
|
@@ -1042,11 +1241,11 @@ async function updateCartItem({
|
|
|
1042
1241
|
}
|
|
1043
1242
|
|
|
1044
1243
|
// src/tools/remove-cart-item.ts
|
|
1045
|
-
import { z as
|
|
1046
|
-
var
|
|
1047
|
-
cartItemId:
|
|
1244
|
+
import { z as z15 } from "zod";
|
|
1245
|
+
var schema15 = {
|
|
1246
|
+
cartItemId: z15.string().min(1).describe("Cart item ID to remove (required)")
|
|
1048
1247
|
};
|
|
1049
|
-
var
|
|
1248
|
+
var metadata15 = {
|
|
1050
1249
|
name: "remove-cart-item",
|
|
1051
1250
|
description: "Remove an item from cart. Recalculates cart totals after removal.",
|
|
1052
1251
|
annotations: {
|
|
@@ -1069,12 +1268,12 @@ async function removeCartItem({
|
|
|
1069
1268
|
}
|
|
1070
1269
|
|
|
1071
1270
|
// src/tools/apply-discount.ts
|
|
1072
|
-
import { z as
|
|
1073
|
-
var
|
|
1074
|
-
cartId:
|
|
1075
|
-
discountCode:
|
|
1271
|
+
import { z as z16 } from "zod";
|
|
1272
|
+
var schema16 = {
|
|
1273
|
+
cartId: z16.string().min(1).describe("Cart ID (required)"),
|
|
1274
|
+
discountCode: z16.string().describe("Discount code to apply (required)")
|
|
1076
1275
|
};
|
|
1077
|
-
var
|
|
1276
|
+
var metadata16 = {
|
|
1078
1277
|
name: "apply-discount",
|
|
1079
1278
|
description: "Apply a discount code to a cart. Validates the code, updates cart totals, and sets free shipping if applicable.",
|
|
1080
1279
|
annotations: {
|
|
@@ -1098,11 +1297,11 @@ async function applyDiscount({
|
|
|
1098
1297
|
}
|
|
1099
1298
|
|
|
1100
1299
|
// src/tools/remove-discount.ts
|
|
1101
|
-
import { z as
|
|
1102
|
-
var
|
|
1103
|
-
cartId:
|
|
1300
|
+
import { z as z17 } from "zod";
|
|
1301
|
+
var schema17 = {
|
|
1302
|
+
cartId: z17.string().min(1).describe("Cart ID (required)")
|
|
1104
1303
|
};
|
|
1105
|
-
var
|
|
1304
|
+
var metadata17 = {
|
|
1106
1305
|
name: "remove-discount",
|
|
1107
1306
|
description: "Remove the applied discount code from a cart and recalculate totals.",
|
|
1108
1307
|
annotations: {
|
|
@@ -1125,11 +1324,11 @@ async function removeDiscount({
|
|
|
1125
1324
|
}
|
|
1126
1325
|
|
|
1127
1326
|
// src/tools/clear-cart.ts
|
|
1128
|
-
import { z as
|
|
1129
|
-
var
|
|
1130
|
-
cartId:
|
|
1327
|
+
import { z as z18 } from "zod";
|
|
1328
|
+
var schema18 = {
|
|
1329
|
+
cartId: z18.string().min(1).describe("Cart ID (required)")
|
|
1131
1330
|
};
|
|
1132
|
-
var
|
|
1331
|
+
var metadata18 = {
|
|
1133
1332
|
name: "clear-cart",
|
|
1134
1333
|
description: "Remove all items from a cart, reset discount and amounts. Shipping fee is preserved.",
|
|
1135
1334
|
annotations: {
|
|
@@ -1152,12 +1351,12 @@ async function clearCart({
|
|
|
1152
1351
|
}
|
|
1153
1352
|
|
|
1154
1353
|
// src/tools/validate-discount.ts
|
|
1155
|
-
import { z as
|
|
1156
|
-
var
|
|
1157
|
-
code:
|
|
1158
|
-
orderAmount:
|
|
1354
|
+
import { z as z19 } from "zod";
|
|
1355
|
+
var schema19 = {
|
|
1356
|
+
code: z19.string().describe("Discount code to validate (required)"),
|
|
1357
|
+
orderAmount: z19.number().describe("Order amount for validation (required)")
|
|
1159
1358
|
};
|
|
1160
|
-
var
|
|
1359
|
+
var metadata19 = {
|
|
1161
1360
|
name: "validate-discount",
|
|
1162
1361
|
description: "Validate a discount code. Checks active status, date range, usage limits, minimum order amount, and calculates discount.",
|
|
1163
1362
|
annotations: {
|
|
@@ -1184,13 +1383,13 @@ async function validateDiscount({
|
|
|
1184
1383
|
}
|
|
1185
1384
|
|
|
1186
1385
|
// src/tools/calculate-shipping.ts
|
|
1187
|
-
import { z as
|
|
1188
|
-
var
|
|
1189
|
-
shippingPolicyId:
|
|
1190
|
-
orderAmount:
|
|
1191
|
-
postalCode:
|
|
1386
|
+
import { z as z20 } from "zod";
|
|
1387
|
+
var schema20 = {
|
|
1388
|
+
shippingPolicyId: z20.string().optional().describe("Shipping policy ID (uses default policy if omitted)"),
|
|
1389
|
+
orderAmount: z20.number().describe("Order amount for fee calculation (required)"),
|
|
1390
|
+
postalCode: z20.string().optional().describe("Postal code for Jeju surcharge detection (63000-63644)")
|
|
1192
1391
|
};
|
|
1193
|
-
var
|
|
1392
|
+
var metadata20 = {
|
|
1194
1393
|
name: "calculate-shipping",
|
|
1195
1394
|
description: "Calculate shipping fee based on order amount and postal code. Supports free shipping threshold and Jeju surcharge.",
|
|
1196
1395
|
annotations: {
|
|
@@ -1219,18 +1418,18 @@ async function calculateShipping({
|
|
|
1219
1418
|
}
|
|
1220
1419
|
|
|
1221
1420
|
// src/tools/stock-check.ts
|
|
1222
|
-
import { z as
|
|
1223
|
-
var
|
|
1224
|
-
items:
|
|
1225
|
-
|
|
1226
|
-
variantId:
|
|
1227
|
-
quantity:
|
|
1421
|
+
import { z as z21 } from "zod";
|
|
1422
|
+
var schema21 = {
|
|
1423
|
+
items: z21.array(
|
|
1424
|
+
z21.object({
|
|
1425
|
+
variantId: z21.string().describe("Product variant ID"),
|
|
1426
|
+
quantity: z21.number().int().positive().describe("Requested quantity")
|
|
1228
1427
|
})
|
|
1229
1428
|
).describe(
|
|
1230
1429
|
"Array of items to check stock for (required, max 100). Each: { variantId, quantity }"
|
|
1231
1430
|
)
|
|
1232
1431
|
};
|
|
1233
|
-
var
|
|
1432
|
+
var metadata21 = {
|
|
1234
1433
|
name: "stock-check",
|
|
1235
1434
|
description: "Batch check product option stock availability. Returns per-item availability and an allAvailable flag.",
|
|
1236
1435
|
annotations: {
|
|
@@ -1253,8 +1452,7 @@ async function stockCheck({
|
|
|
1253
1452
|
}
|
|
1254
1453
|
|
|
1255
1454
|
// src/tools/get-collection-schema.ts
|
|
1256
|
-
import {
|
|
1257
|
-
import { COLLECTIONS as COLLECTIONS8 } from "@01.software/sdk";
|
|
1455
|
+
import { COLLECTIONS as COLLECTIONS3 } from "@01.software/sdk";
|
|
1258
1456
|
|
|
1259
1457
|
// src/lib/console-api.ts
|
|
1260
1458
|
import { createHash } from "crypto";
|
|
@@ -1349,17 +1547,16 @@ async function consolePost(path, body, apiKey) {
|
|
|
1349
1547
|
// src/lib/collection-schema.ts
|
|
1350
1548
|
async function getCollectionSchema(collection) {
|
|
1351
1549
|
const apiKey = resolveApiKey();
|
|
1352
|
-
|
|
1550
|
+
const data = await consoleGet(
|
|
1353
1551
|
`/api/tenants/schema/${encodeURIComponent(collection)}`,
|
|
1354
1552
|
apiKey
|
|
1355
1553
|
);
|
|
1554
|
+
return collectionSchemaResponseSchema.parse(data);
|
|
1356
1555
|
}
|
|
1357
1556
|
|
|
1358
1557
|
// src/tools/get-collection-schema.ts
|
|
1359
|
-
var
|
|
1360
|
-
|
|
1361
|
-
};
|
|
1362
|
-
var metadata27 = {
|
|
1558
|
+
var schema22 = createCollectionSchemaToolInputSchema(COLLECTIONS3).shape;
|
|
1559
|
+
var metadata22 = {
|
|
1363
1560
|
name: "get-collection-schema",
|
|
1364
1561
|
description: "Get the authoritative tenant-aware collection schema from console. Use this before create/update to understand writable fields, hidden fields, required metadata, and collection-level visibility.",
|
|
1365
1562
|
annotations: {
|
|
@@ -1383,9 +1580,6 @@ async function getCollectionSchemaTool({
|
|
|
1383
1580
|
}
|
|
1384
1581
|
}
|
|
1385
1582
|
|
|
1386
|
-
// src/tools/get-tenant-context.ts
|
|
1387
|
-
import { z as z28 } from "zod";
|
|
1388
|
-
|
|
1389
1583
|
// src/lib/tenant-context.ts
|
|
1390
1584
|
function getTenantContextPath(includeCounts) {
|
|
1391
1585
|
return includeCounts ? "/api/tenants/context?counts=true" : "/api/tenants/context";
|
|
@@ -1396,16 +1590,12 @@ async function getTenantContext(includeCounts = false) {
|
|
|
1396
1590
|
getTenantContextPath(includeCounts),
|
|
1397
1591
|
apiKey
|
|
1398
1592
|
);
|
|
1399
|
-
return data;
|
|
1400
|
-
}
|
|
1401
|
-
function invalidateTenantContextCache() {
|
|
1593
|
+
return tenantContextResponseSchema.parse(data);
|
|
1402
1594
|
}
|
|
1403
1595
|
|
|
1404
1596
|
// src/tools/get-tenant-context.ts
|
|
1405
|
-
var
|
|
1406
|
-
|
|
1407
|
-
};
|
|
1408
|
-
var metadata28 = {
|
|
1597
|
+
var schema23 = tenantContextToolInputSchema.shape;
|
|
1598
|
+
var metadata23 = {
|
|
1409
1599
|
name: "get-tenant-context",
|
|
1410
1600
|
description: "Get current tenant features, active collections, and field visibility. Call this at the start of every session. Use includeCounts=true to also get per-collection document counts for setup diagnostics.",
|
|
1411
1601
|
annotations: {
|
|
@@ -1415,7 +1605,9 @@ var metadata28 = {
|
|
|
1415
1605
|
idempotentHint: true
|
|
1416
1606
|
}
|
|
1417
1607
|
};
|
|
1418
|
-
async function handler({
|
|
1608
|
+
async function handler({
|
|
1609
|
+
includeCounts
|
|
1610
|
+
}) {
|
|
1419
1611
|
try {
|
|
1420
1612
|
const ctx = await getTenantContext(includeCounts);
|
|
1421
1613
|
const lines = [
|
|
@@ -1468,11 +1660,10 @@ async function handler({ includeCounts }) {
|
|
|
1468
1660
|
}
|
|
1469
1661
|
}
|
|
1470
1662
|
if (ctx.config) {
|
|
1663
|
+
lines.push("", "## Config Status");
|
|
1471
1664
|
lines.push(
|
|
1472
|
-
""
|
|
1473
|
-
"## Config Status"
|
|
1665
|
+
`- Webhook configured: ${ctx.config.webhookConfigured ? "Yes" : "No"}`
|
|
1474
1666
|
);
|
|
1475
|
-
lines.push(`- Webhook configured: ${ctx.config.webhookConfigured ? "Yes" : "No"}`);
|
|
1476
1667
|
}
|
|
1477
1668
|
return toolSuccess({ context: lines.join("\n") });
|
|
1478
1669
|
} catch (error) {
|
|
@@ -1481,7 +1672,7 @@ async function handler({ includeCounts }) {
|
|
|
1481
1672
|
}
|
|
1482
1673
|
|
|
1483
1674
|
// src/tools/list-configurable-fields.ts
|
|
1484
|
-
import { z as
|
|
1675
|
+
import { z as z22 } from "zod";
|
|
1485
1676
|
|
|
1486
1677
|
// src/lib/field-config.ts
|
|
1487
1678
|
async function fetchFieldConfigs() {
|
|
@@ -1504,12 +1695,12 @@ function invalidateFieldConfigCache() {
|
|
|
1504
1695
|
}
|
|
1505
1696
|
|
|
1506
1697
|
// src/tools/list-configurable-fields.ts
|
|
1507
|
-
var
|
|
1508
|
-
collection:
|
|
1698
|
+
var schema24 = {
|
|
1699
|
+
collection: z22.string().optional().describe(
|
|
1509
1700
|
"Filter by collection slug (optional \u2014 returns all if omitted). Use this filter to reduce response size when you know which collection to check."
|
|
1510
1701
|
)
|
|
1511
1702
|
};
|
|
1512
|
-
var
|
|
1703
|
+
var metadata24 = {
|
|
1513
1704
|
name: "list-configurable-fields",
|
|
1514
1705
|
description: "List all configurable fields for tenant collections with current visibility state. Shows which fields can be shown/hidden and their current status. Returns all collections including inactive features \u2014 cross-reference with get-tenant-context for active features. Response includes ~300 fields across 47 collections \u2014 use collection filter when possible.",
|
|
1515
1706
|
annotations: {
|
|
@@ -1540,17 +1731,17 @@ async function listConfigurableFields(params) {
|
|
|
1540
1731
|
}
|
|
1541
1732
|
|
|
1542
1733
|
// src/tools/update-field-config.ts
|
|
1543
|
-
import { z as
|
|
1544
|
-
var
|
|
1545
|
-
collection:
|
|
1546
|
-
hiddenFields:
|
|
1734
|
+
import { z as z23 } from "zod";
|
|
1735
|
+
var schema25 = {
|
|
1736
|
+
collection: z23.string().min(1).describe("Collection slug (required)"),
|
|
1737
|
+
hiddenFields: z23.array(z23.string().min(1).max(200)).max(300).describe(
|
|
1547
1738
|
"Fields to hide (required). This is a FULL REPLACE \u2014 fields NOT in this list will be shown. Pass [] to show all fields. Use list-configurable-fields first to see available field paths."
|
|
1548
1739
|
),
|
|
1549
|
-
isHidden:
|
|
1740
|
+
isHidden: z23.boolean().optional().describe(
|
|
1550
1741
|
"Hide the entire collection from Admin Panel (optional). When true, individual hiddenFields are irrelevant."
|
|
1551
1742
|
)
|
|
1552
1743
|
};
|
|
1553
|
-
var
|
|
1744
|
+
var metadata25 = {
|
|
1554
1745
|
name: "update-field-config",
|
|
1555
1746
|
description: "Update field visibility configuration for a tenant collection. Hidden fields are removed from the Admin Panel UI. IMPORTANT: hiddenFields is a full replace, not a merge. Always call list-configurable-fields first to see current state.",
|
|
1556
1747
|
annotations: {
|
|
@@ -1568,7 +1759,6 @@ async function updateFieldConfig(params) {
|
|
|
1568
1759
|
isHidden: params.isHidden
|
|
1569
1760
|
});
|
|
1570
1761
|
invalidateFieldConfigCache();
|
|
1571
|
-
invalidateTenantContextCache();
|
|
1572
1762
|
return toolSuccess({
|
|
1573
1763
|
message: `Field config updated for '${params.collection}'`,
|
|
1574
1764
|
data: result
|
|
@@ -1579,7 +1769,7 @@ async function updateFieldConfig(params) {
|
|
|
1579
1769
|
}
|
|
1580
1770
|
|
|
1581
1771
|
// src/tools/sdk-get-recipe.ts
|
|
1582
|
-
import { z as
|
|
1772
|
+
import { z as z24 } from "zod";
|
|
1583
1773
|
|
|
1584
1774
|
// src/lib/sdk-recipes.ts
|
|
1585
1775
|
var recipes = {
|
|
@@ -1731,7 +1921,7 @@ const result = await client.collections.from('products').create({
|
|
|
1731
1921
|
"Returns result.doc (not the document directly)"
|
|
1732
1922
|
],
|
|
1733
1923
|
relatedResources: ["docs://sdk/query-builder"],
|
|
1734
|
-
relatedTools: ["
|
|
1924
|
+
relatedTools: ["query-collection", "get-collection-schema"]
|
|
1735
1925
|
}
|
|
1736
1926
|
},
|
|
1737
1927
|
"update-item": {
|
|
@@ -1760,7 +1950,7 @@ const result = await client.collections.from('products').update('product-id', {
|
|
|
1760
1950
|
"Partial updates are supported \u2014 omitted fields retain their current value"
|
|
1761
1951
|
],
|
|
1762
1952
|
relatedResources: ["docs://sdk/query-builder"],
|
|
1763
|
-
relatedTools: ["
|
|
1953
|
+
relatedTools: ["get-collection-by-id", "get-collection-schema"]
|
|
1764
1954
|
}
|
|
1765
1955
|
},
|
|
1766
1956
|
"delete-item": {
|
|
@@ -1784,7 +1974,7 @@ console.log('Deleted:', deleted.title)`,
|
|
|
1784
1974
|
"Throws if the item does not exist"
|
|
1785
1975
|
],
|
|
1786
1976
|
relatedResources: ["docs://sdk/query-builder"],
|
|
1787
|
-
relatedTools: ["
|
|
1977
|
+
relatedTools: ["get-collection-by-id", "query-collection"]
|
|
1788
1978
|
}
|
|
1789
1979
|
},
|
|
1790
1980
|
"infinite-scroll": {
|
|
@@ -1961,7 +2151,7 @@ const result = await client.collections.from('images').create(formData as unknow
|
|
|
1961
2151
|
"Always set alt text for accessibility"
|
|
1962
2152
|
],
|
|
1963
2153
|
relatedResources: ["docs://sdk/query-builder"],
|
|
1964
|
-
relatedTools: ["
|
|
2154
|
+
relatedTools: ["query-collection", "get-collection-schema"]
|
|
1965
2155
|
}
|
|
1966
2156
|
},
|
|
1967
2157
|
"bulk-operations": {
|
|
@@ -1997,7 +2187,7 @@ const removed = await client.collections.from('products').removeMany(
|
|
|
1997
2187
|
"Very broad where clauses (or empty) will affect all documents in the collection"
|
|
1998
2188
|
],
|
|
1999
2189
|
relatedResources: ["docs://sdk/query-builder"],
|
|
2000
|
-
relatedTools: ["
|
|
2190
|
+
relatedTools: ["query-collection", "get-collection-schema"]
|
|
2001
2191
|
}
|
|
2002
2192
|
}
|
|
2003
2193
|
};
|
|
@@ -2011,8 +2201,8 @@ function getRecipe(goal, runtime = "both") {
|
|
|
2011
2201
|
}
|
|
2012
2202
|
|
|
2013
2203
|
// src/tools/sdk-get-recipe.ts
|
|
2014
|
-
var
|
|
2015
|
-
goal:
|
|
2204
|
+
var schema26 = {
|
|
2205
|
+
goal: z24.enum([
|
|
2016
2206
|
"fetch-list",
|
|
2017
2207
|
"fetch-by-id",
|
|
2018
2208
|
"create-item",
|
|
@@ -2024,11 +2214,11 @@ var schema31 = {
|
|
|
2024
2214
|
"file-upload",
|
|
2025
2215
|
"bulk-operations"
|
|
2026
2216
|
]).describe("What the user wants to accomplish"),
|
|
2027
|
-
runtime:
|
|
2028
|
-
collection:
|
|
2029
|
-
includeExample:
|
|
2217
|
+
runtime: z24.enum(["browser", "server", "both"]).default("both").describe("Target runtime environment"),
|
|
2218
|
+
collection: z24.string().optional().describe("Specific collection name if applicable"),
|
|
2219
|
+
includeExample: z24.boolean().default(true).describe("Whether to include a full code example")
|
|
2030
2220
|
};
|
|
2031
|
-
var
|
|
2221
|
+
var metadata26 = {
|
|
2032
2222
|
name: "sdk-get-recipe",
|
|
2033
2223
|
description: "Get a complete SDK code recipe for a specific task. Returns recommended approach, code example, and related documentation links. Use this FIRST when the user asks how to do something with the SDK.",
|
|
2034
2224
|
annotations: {
|
|
@@ -2071,7 +2261,7 @@ function handler2({
|
|
|
2071
2261
|
}
|
|
2072
2262
|
|
|
2073
2263
|
// src/tools/sdk-search-docs.ts
|
|
2074
|
-
import { z as
|
|
2264
|
+
import { z as z25 } from "zod";
|
|
2075
2265
|
|
|
2076
2266
|
// src/lib/sdk-doc-index.ts
|
|
2077
2267
|
var docIndex = [
|
|
@@ -2246,11 +2436,11 @@ function searchDocs(query, limit = 5) {
|
|
|
2246
2436
|
}
|
|
2247
2437
|
|
|
2248
2438
|
// src/tools/sdk-search-docs.ts
|
|
2249
|
-
var
|
|
2250
|
-
query:
|
|
2251
|
-
limit:
|
|
2439
|
+
var schema27 = {
|
|
2440
|
+
query: z25.string().min(2).describe('Search keyword or phrase (e.g. "infinite scroll", "webhook", "customer login")'),
|
|
2441
|
+
limit: z25.number().min(1).max(10).default(5).describe("Maximum results to return (1-10, default: 5)")
|
|
2252
2442
|
};
|
|
2253
|
-
var
|
|
2443
|
+
var metadata27 = {
|
|
2254
2444
|
name: "sdk-search-docs",
|
|
2255
2445
|
description: "Search SDK documentation by keyword. Returns matching topics with summaries and resource links. Use when looking for specific SDK features or patterns.",
|
|
2256
2446
|
annotations: {
|
|
@@ -2285,9 +2475,9 @@ function handler3({
|
|
|
2285
2475
|
}
|
|
2286
2476
|
|
|
2287
2477
|
// src/tools/sdk-get-auth-setup.ts
|
|
2288
|
-
import { z as
|
|
2289
|
-
var
|
|
2290
|
-
scenario:
|
|
2478
|
+
import { z as z26 } from "zod";
|
|
2479
|
+
var schema28 = {
|
|
2480
|
+
scenario: z26.enum([
|
|
2291
2481
|
"browser-client",
|
|
2292
2482
|
"server-client",
|
|
2293
2483
|
"customer-auth",
|
|
@@ -2296,7 +2486,7 @@ var schema33 = {
|
|
|
2296
2486
|
"webhook-verification"
|
|
2297
2487
|
]).describe("Authentication scenario")
|
|
2298
2488
|
};
|
|
2299
|
-
var
|
|
2489
|
+
var metadata28 = {
|
|
2300
2490
|
name: "sdk-get-auth-setup",
|
|
2301
2491
|
description: "Get the current authentication setup for a specific scenario. Returns env var names, code snippets, and security notes.",
|
|
2302
2492
|
annotations: {
|
|
@@ -2450,14 +2640,14 @@ function handler4({
|
|
|
2450
2640
|
}
|
|
2451
2641
|
|
|
2452
2642
|
// src/tools/sdk-get-collection-pattern.ts
|
|
2453
|
-
import { z as
|
|
2454
|
-
import { COLLECTIONS as
|
|
2455
|
-
var
|
|
2456
|
-
collection:
|
|
2457
|
-
operation:
|
|
2458
|
-
surface:
|
|
2643
|
+
import { z as z27 } from "zod";
|
|
2644
|
+
import { COLLECTIONS as COLLECTIONS4 } from "@01.software/sdk";
|
|
2645
|
+
var schema29 = {
|
|
2646
|
+
collection: z27.enum(COLLECTIONS4).describe("Collection name"),
|
|
2647
|
+
operation: z27.enum(["read", "write", "full-crud"]).default("read").describe("What operations are needed"),
|
|
2648
|
+
surface: z27.enum(["query-builder", "react-query", "server-api"]).default("query-builder").describe("Preferred API surface")
|
|
2459
2649
|
};
|
|
2460
|
-
var
|
|
2650
|
+
var metadata29 = {
|
|
2461
2651
|
name: "sdk-get-collection-pattern",
|
|
2462
2652
|
description: "Get the recommended CRUD pattern for a specific collection. Returns code examples for the chosen API surface and operation type.",
|
|
2463
2653
|
annotations: {
|
|
@@ -2624,7 +2814,6 @@ function handler5({
|
|
|
2624
2814
|
relatedTools: [
|
|
2625
2815
|
"query-collection",
|
|
2626
2816
|
"get-collection-by-id",
|
|
2627
|
-
...operation !== "read" ? ["create-collection", "update-collection", "delete-collection"] : [],
|
|
2628
2817
|
"get-collection-schema"
|
|
2629
2818
|
],
|
|
2630
2819
|
relatedResources: [
|
|
@@ -2638,14 +2827,14 @@ function handler5({
|
|
|
2638
2827
|
}
|
|
2639
2828
|
|
|
2640
2829
|
// src/prompts/sdk-usage-guide.ts
|
|
2641
|
-
import { z as
|
|
2642
|
-
var
|
|
2643
|
-
goal:
|
|
2644
|
-
runtime:
|
|
2645
|
-
surface:
|
|
2646
|
-
collection:
|
|
2830
|
+
import { z as z28 } from "zod";
|
|
2831
|
+
var schema30 = {
|
|
2832
|
+
goal: z28.string().describe('What the user wants to accomplish (e.g., "query product list", "create order")'),
|
|
2833
|
+
runtime: z28.enum(["browser", "server"]).optional().describe("Target runtime: browser (React/Next.js client) or server (Node.js)"),
|
|
2834
|
+
surface: z28.enum(["query-builder", "react-query", "customer-api", "server-api"]).optional().describe("Preferred API surface"),
|
|
2835
|
+
collection: z28.string().optional().describe("Specific collection if relevant")
|
|
2647
2836
|
};
|
|
2648
|
-
var
|
|
2837
|
+
var metadata30 = {
|
|
2649
2838
|
name: "sdk-usage-guide",
|
|
2650
2839
|
title: "SDK Usage Guide",
|
|
2651
2840
|
description: "Provides guidance on how to perform a specific task using the 01.software SDK",
|
|
@@ -2782,14 +2971,14 @@ You can perform the "${goal}" task by following the patterns above.`;
|
|
|
2782
2971
|
}
|
|
2783
2972
|
|
|
2784
2973
|
// src/prompts/collection-query-help.ts
|
|
2785
|
-
import { z as
|
|
2786
|
-
import { COLLECTIONS as
|
|
2787
|
-
var
|
|
2788
|
-
collection:
|
|
2789
|
-
operation:
|
|
2790
|
-
filters:
|
|
2974
|
+
import { z as z29 } from "zod";
|
|
2975
|
+
import { COLLECTIONS as COLLECTIONS5 } from "@01.software/sdk";
|
|
2976
|
+
var schema31 = {
|
|
2977
|
+
collection: z29.enum(COLLECTIONS5).describe("Collection name"),
|
|
2978
|
+
operation: z29.enum(["find", "create", "update", "delete"]).describe("Operation to perform (find, create, update, delete)"),
|
|
2979
|
+
filters: z29.string().optional().describe("Filter conditions (JSON string, optional)")
|
|
2791
2980
|
};
|
|
2792
|
-
var
|
|
2981
|
+
var metadata31 = {
|
|
2793
2982
|
name: "collection-query-help",
|
|
2794
2983
|
title: "Collection Query Help",
|
|
2795
2984
|
description: "Provides guidance on how to write queries for a specific collection",
|
|
@@ -2876,16 +3065,16 @@ ${operation === "find" ? `- Use \`where\` option for filtering (Payload query sy
|
|
|
2876
3065
|
}
|
|
2877
3066
|
|
|
2878
3067
|
// src/prompts/order-flow-guide.ts
|
|
2879
|
-
import { z as
|
|
2880
|
-
var
|
|
2881
|
-
scenario:
|
|
3068
|
+
import { z as z30 } from "zod";
|
|
3069
|
+
var schema32 = {
|
|
3070
|
+
scenario: z30.enum([
|
|
2882
3071
|
"simple-order",
|
|
2883
3072
|
"cart-checkout",
|
|
2884
3073
|
"return-refund",
|
|
2885
3074
|
"fulfillment-tracking"
|
|
2886
3075
|
]).describe("Order flow scenario")
|
|
2887
3076
|
};
|
|
2888
|
-
var
|
|
3077
|
+
var metadata32 = {
|
|
2889
3078
|
name: "order-flow-guide",
|
|
2890
3079
|
title: "Order Flow Guide",
|
|
2891
3080
|
description: "Provides step-by-step guidance for ecommerce order flows including creation, checkout, returns, and fulfillment.",
|
|
@@ -2900,8 +3089,8 @@ var SCENARIOS = {
|
|
|
2900
3089
|
- Provide: orderNumber, customerSnapshot (email required), shippingAddress, orderItems, totalAmount
|
|
2901
3090
|
- Optional: pgPaymentId (omit for free orders), shippingAmount, discountCode
|
|
2902
3091
|
|
|
2903
|
-
2. **Payment Confirmation** \u2192 \`update-
|
|
2904
|
-
-
|
|
3092
|
+
2. **Payment Confirmation** \u2192 \`update-transaction\` tool
|
|
3093
|
+
- Confirm provider payment with pgPaymentId, paymentKey, and amount
|
|
2905
3094
|
- Stock is automatically adjusted (stock -= qty, reservedStock += qty)
|
|
2906
3095
|
|
|
2907
3096
|
3. **Fulfillment** \u2192 \`create-fulfillment\` tool
|
|
@@ -2928,8 +3117,13 @@ const order = await client.commerce.orders.create({
|
|
|
2928
3117
|
pgPaymentId: 'pay_xxx' // omit for free orders
|
|
2929
3118
|
})
|
|
2930
3119
|
|
|
2931
|
-
// 2. After payment confirmed
|
|
2932
|
-
await client.commerce.orders.
|
|
3120
|
+
// 2. After payment confirmed by provider
|
|
3121
|
+
await client.commerce.orders.updateTransaction({
|
|
3122
|
+
pgPaymentId: 'pay_xxx',
|
|
3123
|
+
status: 'paid',
|
|
3124
|
+
paymentKey: 'payment_key_xxx',
|
|
3125
|
+
amount: 59800
|
|
3126
|
+
})
|
|
2933
3127
|
|
|
2934
3128
|
// 3. Ship items
|
|
2935
3129
|
await client.commerce.orders.createFulfillment({
|
|
@@ -2947,7 +3141,7 @@ await client.commerce.orders.createFulfillment({
|
|
|
2947
3141
|
2. **Apply Discount** (optional) \u2192 \`apply-discount\` tool
|
|
2948
3142
|
3. **Calculate Shipping** \u2192 \`calculate-shipping\` tool
|
|
2949
3143
|
4. **Checkout** \u2192 \`checkout\` tool (converts cart to order)
|
|
2950
|
-
5. **Payment** \u2192 \`update-
|
|
3144
|
+
5. **Payment** \u2192 \`update-transaction\` for provider-verified paid transitions
|
|
2951
3145
|
|
|
2952
3146
|
### Key Points
|
|
2953
3147
|
- Cart has a customer linked \u2014 auto-copied to order on checkout
|
|
@@ -2984,7 +3178,7 @@ const order = await client.commerce.orders.checkout({
|
|
|
2984
3178
|
1. **Return with Refund** \u2192 \`return-with-refund\` tool
|
|
2985
3179
|
- Handles return + stock restoration + transaction update in one call
|
|
2986
3180
|
- Return immediately completed (bypasses FSM)
|
|
2987
|
-
- Requires pgPaymentId
|
|
3181
|
+
- Requires pgPaymentId and paymentKey for provider-verified refund
|
|
2988
3182
|
|
|
2989
3183
|
### Key Points
|
|
2990
3184
|
- Full refund: original transaction \u2192 \`canceled\`
|
|
@@ -3001,7 +3195,8 @@ await client.commerce.orders.returnWithRefund({
|
|
|
3001
3195
|
reasonDetail: 'Product arrived damaged',
|
|
3002
3196
|
returnItems: [{ orderItem: 'oi-id', quantity: 1 }],
|
|
3003
3197
|
refundAmount: 29900,
|
|
3004
|
-
pgPaymentId: 'pay_xxx'
|
|
3198
|
+
pgPaymentId: 'pay_xxx',
|
|
3199
|
+
paymentKey: 'payment_key_xxx'
|
|
3005
3200
|
})
|
|
3006
3201
|
\`\`\``,
|
|
3007
3202
|
"fulfillment-tracking": `## Fulfillment & Tracking
|
|
@@ -3064,9 +3259,9 @@ ${SCENARIOS[scenario] || "Unknown scenario."}
|
|
|
3064
3259
|
}
|
|
3065
3260
|
|
|
3066
3261
|
// src/prompts/feature-setup-guide.ts
|
|
3067
|
-
import { z as
|
|
3068
|
-
var
|
|
3069
|
-
feature:
|
|
3262
|
+
import { z as z31 } from "zod";
|
|
3263
|
+
var schema33 = {
|
|
3264
|
+
feature: z31.enum([
|
|
3070
3265
|
"ecommerce",
|
|
3071
3266
|
"customers",
|
|
3072
3267
|
"articles",
|
|
@@ -3081,7 +3276,7 @@ var schema38 = {
|
|
|
3081
3276
|
"community"
|
|
3082
3277
|
]).describe("Feature to get setup guide for")
|
|
3083
3278
|
};
|
|
3084
|
-
var
|
|
3279
|
+
var metadata33 = {
|
|
3085
3280
|
name: "feature-setup-guide",
|
|
3086
3281
|
title: "Feature Setup Guide",
|
|
3087
3282
|
description: "Setup checklist and remediation guide for a tenant feature. Load before using get-tenant-context to diagnose setup gaps.",
|
|
@@ -3094,8 +3289,8 @@ var FEATURES = {
|
|
|
3094
3289
|
|
|
3095
3290
|
### Required Collections (count > 0)
|
|
3096
3291
|
|
|
3097
|
-
1. **products** \u2014
|
|
3098
|
-
- Minimum fields: \`{ title, slug, status: '
|
|
3292
|
+
1. **products** \u2014 Create via Console UI or SDK \`client.collections.from('products').create({ ... })\`
|
|
3293
|
+
- Minimum fields: \`{ title, slug, status: 'published', _status: 'published' }\`
|
|
3099
3294
|
|
|
3100
3295
|
2. **product-variants** \u2014 At least 1 sellable variant per product
|
|
3101
3296
|
- Minimum fields: \`{ product, title, price, stock }\`
|
|
@@ -3128,7 +3323,7 @@ customer-addresses
|
|
|
3128
3323
|
|
|
3129
3324
|
### Optional Collections
|
|
3130
3325
|
|
|
3131
|
-
customer-groups \u2014
|
|
3326
|
+
customer-groups \u2014 Create via Console UI or SDK \`client.collections.from('customer-groups').create({ title })\`
|
|
3132
3327
|
|
|
3133
3328
|
### Config
|
|
3134
3329
|
|
|
@@ -3167,10 +3362,10 @@ document-categories`,
|
|
|
3167
3362
|
### Required Collections (count > 0)
|
|
3168
3363
|
|
|
3169
3364
|
1. **playlists** \u2014 At least 1 playlist
|
|
3170
|
-
- Minimum fields: \`{ title, slug }\`
|
|
3365
|
+
- Minimum fields: \`{ title, slug, status: 'published', _status: 'published' }\`
|
|
3171
3366
|
|
|
3172
3367
|
2. **tracks** \u2014 At least 1 track
|
|
3173
|
-
- Minimum fields: \`{ title }\`
|
|
3368
|
+
- Minimum fields: \`{ title, sourceUrl, status: 'published', _status: 'published' }\`
|
|
3174
3369
|
|
|
3175
3370
|
3. **playlists.tracks** \u2014 Link at least 1 track from a playlist
|
|
3176
3371
|
- Minimum fields: \`{ tracks: [trackId] }\`
|
|
@@ -3183,11 +3378,11 @@ playlist-categories, playlist-tags, track-categories, track-tags, track-assets`,
|
|
|
3183
3378
|
### Required Collections (count > 0)
|
|
3184
3379
|
|
|
3185
3380
|
1. **galleries** \u2014 At least 1 gallery
|
|
3186
|
-
- Minimum fields: \`{ title, slug }\`
|
|
3381
|
+
- Minimum fields: \`{ title, slug, status: 'published', _status: 'published' }\`
|
|
3187
3382
|
|
|
3188
3383
|
2. **gallery-items** \u2014 At least 1 item per gallery
|
|
3189
3384
|
- References \`images\` collection (non-upload)
|
|
3190
|
-
- Minimum fields: \`{ gallery, image }\`
|
|
3385
|
+
- Minimum fields: \`{ gallery, image, _status: 'published' }\`
|
|
3191
3386
|
|
|
3192
3387
|
### Optional Collections
|
|
3193
3388
|
|
|
@@ -3197,7 +3392,7 @@ gallery-categories, gallery-tags`,
|
|
|
3197
3392
|
### Required Collections (count > 0)
|
|
3198
3393
|
|
|
3199
3394
|
1. **links** \u2014 At least 1 link
|
|
3200
|
-
- Minimum fields: \`{ title, slug, url }\`
|
|
3395
|
+
- Minimum fields: \`{ title, slug, url, status: 'published', _status: 'published' }\`
|
|
3201
3396
|
|
|
3202
3397
|
### Optional Collections
|
|
3203
3398
|
|
|
@@ -3278,12 +3473,12 @@ ${FEATURES[feature] || "Unknown feature."}
|
|
|
3278
3473
|
|
|
3279
3474
|
## Related MCP Tools
|
|
3280
3475
|
- \`get-tenant-context\` \u2014 check current collection counts and feature status
|
|
3281
|
-
- \`
|
|
3282
|
-
- \`
|
|
3476
|
+
- \`query-collection\` \u2014 verify existing documents in a collection
|
|
3477
|
+
- \`get-collection-schema\` \u2014 inspect tenant-aware fields before creating data via SDK or Console UI`;
|
|
3283
3478
|
}
|
|
3284
3479
|
|
|
3285
3480
|
// src/resources/(config)/app.ts
|
|
3286
|
-
var
|
|
3481
|
+
var metadata34 = {
|
|
3287
3482
|
name: "app-config",
|
|
3288
3483
|
title: "Application Config",
|
|
3289
3484
|
description: "01.software SDK and MCP server configuration information"
|
|
@@ -3305,16 +3500,13 @@ HTTP MCP uses OAuth discovery and Authorization Code + PKCE.
|
|
|
3305
3500
|
url = "https://mcp.01.software/mcp"
|
|
3306
3501
|
\`\`\`
|
|
3307
3502
|
|
|
3308
|
-
## Available Tools (
|
|
3503
|
+
## Available Tools (29)
|
|
3309
3504
|
|
|
3310
|
-
|
|
3505
|
+
> Generic write tools (create/update/delete/update-many/delete-many) are intentionally absent. Use the dedicated workflow tools below or the SDK (\`client.collections.from(slug).create()\` / \`update()\` / \`remove()\` / \`updateMany()\` / \`removeMany()\`) for stateful mutations.
|
|
3506
|
+
|
|
3507
|
+
### Generic Read (2)
|
|
3311
3508
|
- \`query-collection\` - Query collection with filters, pagination, sorting
|
|
3312
3509
|
- \`get-collection-by-id\` - Get single item by ID
|
|
3313
|
-
- \`create-collection\` - Create new item
|
|
3314
|
-
- \`update-collection\` - Update existing item
|
|
3315
|
-
- \`delete-collection\` - Delete item (destructive)
|
|
3316
|
-
- \`update-many-collection\` - Bulk update items matching filter
|
|
3317
|
-
- \`delete-many-collection\` - Bulk delete items matching filter (destructive)
|
|
3318
3510
|
|
|
3319
3511
|
### Orders (7)
|
|
3320
3512
|
- \`create-order\` - Create a new order with products and shipping
|
|
@@ -3372,80 +3564,86 @@ Rate limits depend on your tenant plan:
|
|
|
3372
3564
|
}
|
|
3373
3565
|
|
|
3374
3566
|
// src/resources/(collections)/schema.ts
|
|
3375
|
-
import { COLLECTIONS as
|
|
3376
|
-
var
|
|
3567
|
+
import { COLLECTIONS as COLLECTIONS6 } from "@01.software/sdk";
|
|
3568
|
+
var metadata35 = {
|
|
3377
3569
|
name: "collections-schema",
|
|
3378
3570
|
title: "Collection Schema Info",
|
|
3379
3571
|
description: "Available collections and their schema information"
|
|
3380
3572
|
};
|
|
3573
|
+
var COLLECTIONS_BY_CATEGORY = {
|
|
3574
|
+
"Tenant Management": ["tenants", "tenant-metadata", "tenant-logos"],
|
|
3575
|
+
Products: [
|
|
3576
|
+
"products",
|
|
3577
|
+
"product-variants",
|
|
3578
|
+
"product-options",
|
|
3579
|
+
"product-option-values",
|
|
3580
|
+
"product-categories",
|
|
3581
|
+
"product-tags",
|
|
3582
|
+
"product-collections"
|
|
3583
|
+
],
|
|
3584
|
+
Brands: ["brands", "brand-logos"],
|
|
3585
|
+
"Orders & Fulfillment": [
|
|
3586
|
+
"orders",
|
|
3587
|
+
"order-items",
|
|
3588
|
+
"transactions",
|
|
3589
|
+
"fulfillments",
|
|
3590
|
+
"fulfillment-items"
|
|
3591
|
+
],
|
|
3592
|
+
"Shipping & Returns": ["returns", "return-items", "shipping-policies"],
|
|
3593
|
+
Customers: [
|
|
3594
|
+
"customers",
|
|
3595
|
+
"customer-profiles",
|
|
3596
|
+
"customer-addresses",
|
|
3597
|
+
"customer-groups"
|
|
3598
|
+
],
|
|
3599
|
+
Carts: ["carts", "cart-items"],
|
|
3600
|
+
"Discounts & Promotions": ["discounts", "promotions"],
|
|
3601
|
+
Documents: ["documents", "document-categories", "document-types"],
|
|
3602
|
+
Articles: ["articles", "article-authors", "article-categories", "article-tags"],
|
|
3603
|
+
Community: [
|
|
3604
|
+
"posts",
|
|
3605
|
+
"comments",
|
|
3606
|
+
"reactions",
|
|
3607
|
+
"reaction-types",
|
|
3608
|
+
"bookmarks",
|
|
3609
|
+
"post-categories",
|
|
3610
|
+
"reports",
|
|
3611
|
+
"community-bans"
|
|
3612
|
+
],
|
|
3613
|
+
Playlists: [
|
|
3614
|
+
"playlists",
|
|
3615
|
+
"tracks",
|
|
3616
|
+
"playlist-categories",
|
|
3617
|
+
"playlist-tags",
|
|
3618
|
+
"track-categories",
|
|
3619
|
+
"track-tags"
|
|
3620
|
+
],
|
|
3621
|
+
Galleries: ["galleries", "gallery-items", "gallery-categories", "gallery-tags"],
|
|
3622
|
+
Links: ["links", "link-categories", "link-tags"],
|
|
3623
|
+
Canvas: [
|
|
3624
|
+
"canvases",
|
|
3625
|
+
"canvas-node-types",
|
|
3626
|
+
"canvas-edge-types",
|
|
3627
|
+
"canvas-categories",
|
|
3628
|
+
"canvas-tags",
|
|
3629
|
+
"canvas-nodes",
|
|
3630
|
+
"canvas-edges"
|
|
3631
|
+
],
|
|
3632
|
+
Videos: ["videos", "video-categories", "video-tags"],
|
|
3633
|
+
"Live Streams": ["live-streams"],
|
|
3634
|
+
Images: ["images"],
|
|
3635
|
+
Forms: ["forms", "form-submissions"],
|
|
3636
|
+
Events: [
|
|
3637
|
+
"event-calendars",
|
|
3638
|
+
"events",
|
|
3639
|
+
"event-categories",
|
|
3640
|
+
"event-occurrences",
|
|
3641
|
+
"event-tags"
|
|
3642
|
+
]
|
|
3643
|
+
};
|
|
3381
3644
|
function handler7() {
|
|
3382
|
-
const
|
|
3383
|
-
|
|
3384
|
-
Products: [
|
|
3385
|
-
"products",
|
|
3386
|
-
"product-variants",
|
|
3387
|
-
"product-options",
|
|
3388
|
-
"product-categories",
|
|
3389
|
-
"product-tags",
|
|
3390
|
-
"product-collections"
|
|
3391
|
-
],
|
|
3392
|
-
Brands: ["brands", "brand-logos"],
|
|
3393
|
-
"Orders & Fulfillment": [
|
|
3394
|
-
"orders",
|
|
3395
|
-
"order-items",
|
|
3396
|
-
"transactions",
|
|
3397
|
-
"fulfillments",
|
|
3398
|
-
"fulfillment-items"
|
|
3399
|
-
],
|
|
3400
|
-
"Shipping & Returns": [
|
|
3401
|
-
"returns",
|
|
3402
|
-
"return-items",
|
|
3403
|
-
"shipping-policies"
|
|
3404
|
-
],
|
|
3405
|
-
Customers: ["customers", "customer-addresses", "customer-groups"],
|
|
3406
|
-
Carts: ["carts", "cart-items"],
|
|
3407
|
-
Discounts: ["discounts"],
|
|
3408
|
-
Documents: ["documents", "document-categories", "document-types"],
|
|
3409
|
-
Articles: ["articles", "article-authors", "article-categories", "article-tags"],
|
|
3410
|
-
Community: [
|
|
3411
|
-
"posts",
|
|
3412
|
-
"comments",
|
|
3413
|
-
"reactions",
|
|
3414
|
-
"reaction-types",
|
|
3415
|
-
"bookmarks",
|
|
3416
|
-
"post-categories",
|
|
3417
|
-
"reports",
|
|
3418
|
-
"community-bans"
|
|
3419
|
-
],
|
|
3420
|
-
Playlists: [
|
|
3421
|
-
"playlists",
|
|
3422
|
-
"tracks",
|
|
3423
|
-
"track-assets",
|
|
3424
|
-
"playlist-categories",
|
|
3425
|
-
"playlist-tags",
|
|
3426
|
-
"track-categories",
|
|
3427
|
-
"track-tags"
|
|
3428
|
-
],
|
|
3429
|
-
Galleries: [
|
|
3430
|
-
"galleries",
|
|
3431
|
-
"gallery-items",
|
|
3432
|
-
"gallery-categories",
|
|
3433
|
-
"gallery-tags"
|
|
3434
|
-
],
|
|
3435
|
-
Canvas: [
|
|
3436
|
-
"canvases",
|
|
3437
|
-
"canvas-node-types",
|
|
3438
|
-
"canvas-edge-types",
|
|
3439
|
-
"canvas-categories",
|
|
3440
|
-
"canvas-tags"
|
|
3441
|
-
],
|
|
3442
|
-
Videos: ["videos", "video-categories", "video-tags"],
|
|
3443
|
-
"Live Streams": ["live-streams"],
|
|
3444
|
-
Images: ["images"],
|
|
3445
|
-
Forms: ["forms", "form-submissions"]
|
|
3446
|
-
};
|
|
3447
|
-
const categoryDocs = Object.entries(collectionsByCategory).map(([category, collections]) => {
|
|
3448
|
-
const collectionList = collections.filter((c) => COLLECTIONS11.includes(c)).map((c) => `- **${c}**`).join("\n");
|
|
3645
|
+
const categoryDocs = Object.entries(COLLECTIONS_BY_CATEGORY).map(([category, collections]) => {
|
|
3646
|
+
const collectionList = collections.filter((c) => COLLECTIONS6.includes(c)).map((c) => `- **${c}**`).join("\n");
|
|
3449
3647
|
return `## ${category}
|
|
3450
3648
|
${collectionList}`;
|
|
3451
3649
|
}).join("\n\n");
|
|
@@ -3466,6 +3664,9 @@ Each collection supports the following operations:
|
|
|
3466
3664
|
- \`updateMany(where, data)\` - Bulk update items matching filter
|
|
3467
3665
|
- \`removeMany(where)\` - Bulk delete items matching filter
|
|
3468
3666
|
|
|
3667
|
+
Draft-enabled public collections expose only \`_status: 'published'\` rows to
|
|
3668
|
+
publishable-key reads unless server-side access explicitly includes drafts.
|
|
3669
|
+
|
|
3469
3670
|
## Query Examples
|
|
3470
3671
|
|
|
3471
3672
|
### Filtering
|
|
@@ -3487,11 +3688,11 @@ Each collection supports the following operations:
|
|
|
3487
3688
|
}
|
|
3488
3689
|
\`\`\`
|
|
3489
3690
|
|
|
3490
|
-
Total available collections: ${
|
|
3691
|
+
Total available collections: ${COLLECTIONS6.length}`;
|
|
3491
3692
|
}
|
|
3492
3693
|
|
|
3493
3694
|
// src/resources/(docs)/getting-started.ts
|
|
3494
|
-
var
|
|
3695
|
+
var metadata36 = {
|
|
3495
3696
|
name: "docs-getting-started",
|
|
3496
3697
|
title: "Getting Started",
|
|
3497
3698
|
description: "01.software SDK getting started guide"
|
|
@@ -3536,7 +3737,7 @@ const result = await client.collections.from('products').find({
|
|
|
3536
3737
|
}
|
|
3537
3738
|
|
|
3538
3739
|
// src/resources/(docs)/guides.ts
|
|
3539
|
-
var
|
|
3740
|
+
var metadata37 = {
|
|
3540
3741
|
name: "docs-guides",
|
|
3541
3742
|
title: "Guides",
|
|
3542
3743
|
description: "01.software SDK usage guides"
|
|
@@ -3747,7 +3948,7 @@ For more detailed guides, see the [Guides page](/docs/guides).`;
|
|
|
3747
3948
|
}
|
|
3748
3949
|
|
|
3749
3950
|
// src/resources/(docs)/api.ts
|
|
3750
|
-
var
|
|
3951
|
+
var metadata38 = {
|
|
3751
3952
|
name: "docs-api",
|
|
3752
3953
|
title: "API Reference",
|
|
3753
3954
|
description: "01.software SDK API reference documentation"
|
|
@@ -4033,7 +4234,7 @@ For more details, see the [full API documentation](/docs/api).`;
|
|
|
4033
4234
|
}
|
|
4034
4235
|
|
|
4035
4236
|
// src/resources/(docs)/query-builder.ts
|
|
4036
|
-
var
|
|
4237
|
+
var metadata39 = {
|
|
4037
4238
|
name: "docs-query-builder",
|
|
4038
4239
|
title: "Query Builder",
|
|
4039
4240
|
description: "01.software SDK Query Builder API reference (client.collections.from)"
|
|
@@ -4227,7 +4428,7 @@ console.log(result.hasNextPage) // true
|
|
|
4227
4428
|
}
|
|
4228
4429
|
|
|
4229
4430
|
// src/resources/(docs)/react-query.ts
|
|
4230
|
-
var
|
|
4431
|
+
var metadata40 = {
|
|
4231
4432
|
name: "docs-react-query",
|
|
4232
4433
|
title: "React Query Hooks",
|
|
4233
4434
|
description: "01.software SDK React Query hooks reference (client.query)"
|
|
@@ -4475,7 +4676,7 @@ export function ProductList() {
|
|
|
4475
4676
|
}
|
|
4476
4677
|
|
|
4477
4678
|
// src/resources/(docs)/server-api.ts
|
|
4478
|
-
var
|
|
4679
|
+
var metadata41 = {
|
|
4479
4680
|
name: "docs-server-api",
|
|
4480
4681
|
title: "Server-side API",
|
|
4481
4682
|
description: "01.software SDK server-side API reference (client.commerce) for orders, fulfillments, returns, carts, and validation"
|
|
@@ -4616,7 +4817,7 @@ const ret = await client.commerce.orders.updateReturn({
|
|
|
4616
4817
|
\`\`\`
|
|
4617
4818
|
|
|
4618
4819
|
### returnWithRefund()
|
|
4619
|
-
Create a return and process refund in one atomic operation.
|
|
4820
|
+
Create a return and process a provider-verified refund in one atomic operation.
|
|
4620
4821
|
|
|
4621
4822
|
\`\`\`typescript
|
|
4622
4823
|
const result = await client.commerce.orders.returnWithRefund({
|
|
@@ -4628,6 +4829,7 @@ const result = await client.commerce.orders.returnWithRefund({
|
|
|
4628
4829
|
],
|
|
4629
4830
|
refundAmount: 29900,
|
|
4630
4831
|
pgPaymentId: 'toss-payment-id', // required
|
|
4832
|
+
paymentKey: 'toss-payment-key', // required for provider refund
|
|
4631
4833
|
refundReceiptUrl?: 'https://...',
|
|
4632
4834
|
})
|
|
4633
4835
|
\`\`\`
|
|
@@ -4635,12 +4837,15 @@ const result = await client.commerce.orders.returnWithRefund({
|
|
|
4635
4837
|
## Transaction API
|
|
4636
4838
|
|
|
4637
4839
|
### updateTransaction()
|
|
4638
|
-
|
|
4840
|
+
Confirm or annotate a transaction. Paid transitions require provider
|
|
4841
|
+
verification; non-financial annotations can still update pending transactions.
|
|
4639
4842
|
|
|
4640
4843
|
\`\`\`typescript
|
|
4641
4844
|
const tx = await client.commerce.orders.updateTransaction({
|
|
4642
4845
|
pgPaymentId: 'toss-payment-id',
|
|
4643
|
-
status: 'paid', // paid | failed | canceled
|
|
4846
|
+
status: 'paid', // pending | paid | failed | canceled
|
|
4847
|
+
paymentKey: 'toss-payment-key', // required when status is paid
|
|
4848
|
+
amount: 29900, // required when status is paid
|
|
4644
4849
|
})
|
|
4645
4850
|
\`\`\`
|
|
4646
4851
|
|
|
@@ -4733,7 +4938,7 @@ const result = await client.commerce.shipping.calculate({
|
|
|
4733
4938
|
}
|
|
4734
4939
|
|
|
4735
4940
|
// src/resources/(docs)/customer-auth.ts
|
|
4736
|
-
var
|
|
4941
|
+
var metadata42 = {
|
|
4737
4942
|
name: "docs-customer-auth",
|
|
4738
4943
|
title: "Customer Auth API",
|
|
4739
4944
|
description: "01.software SDK Customer Auth API reference (client.customer)"
|
|
@@ -4911,7 +5116,7 @@ async function loadProfile() {
|
|
|
4911
5116
|
}
|
|
4912
5117
|
|
|
4913
5118
|
// src/resources/(docs)/browser-vs-server.ts
|
|
4914
|
-
var
|
|
5119
|
+
var metadata43 = {
|
|
4915
5120
|
name: "docs-browser-vs-server",
|
|
4916
5121
|
title: "Client vs ServerClient",
|
|
4917
5122
|
description: "When to use Client (createClient) vs ServerClient (createServerClient) in the 01.software SDK"
|
|
@@ -5070,7 +5275,7 @@ export function ProductList() {
|
|
|
5070
5275
|
}
|
|
5071
5276
|
|
|
5072
5277
|
// src/resources/(docs)/file-upload.ts
|
|
5073
|
-
var
|
|
5278
|
+
var metadata44 = {
|
|
5074
5279
|
name: "docs-file-upload",
|
|
5075
5280
|
title: "File Upload",
|
|
5076
5281
|
description: "01.software SDK file upload patterns using the images collection"
|
|
@@ -5221,7 +5426,7 @@ The platform stores files in Cloudflare R2 and serves via CDN (\`cdn.01.software
|
|
|
5221
5426
|
}
|
|
5222
5427
|
|
|
5223
5428
|
// src/resources/(docs)/webhook.ts
|
|
5224
|
-
var
|
|
5429
|
+
var metadata45 = {
|
|
5225
5430
|
name: "docs-webhook",
|
|
5226
5431
|
title: "Webhooks",
|
|
5227
5432
|
description: "01.software SDK webhook verification and event handling"
|
|
@@ -5335,28 +5540,54 @@ Configure webhook URLs in the 01.software console under Tenant Settings > Webhoo
|
|
|
5335
5540
|
}
|
|
5336
5541
|
|
|
5337
5542
|
// src/server.ts
|
|
5338
|
-
|
|
5543
|
+
var REGISTERED_TOOLS_BY_SERVER = /* @__PURE__ */ new WeakMap();
|
|
5544
|
+
function registerTool(server, schema34, meta, handler19) {
|
|
5545
|
+
let registered = REGISTERED_TOOLS_BY_SERVER.get(server);
|
|
5546
|
+
if (!registered) {
|
|
5547
|
+
registered = /* @__PURE__ */ new Set();
|
|
5548
|
+
REGISTERED_TOOLS_BY_SERVER.set(server, registered);
|
|
5549
|
+
}
|
|
5550
|
+
registered.add(meta.name);
|
|
5339
5551
|
server.registerTool(
|
|
5340
5552
|
meta.name,
|
|
5341
5553
|
{
|
|
5342
5554
|
description: meta.description,
|
|
5343
|
-
inputSchema:
|
|
5555
|
+
inputSchema: schema34,
|
|
5344
5556
|
annotations: meta.annotations
|
|
5345
5557
|
},
|
|
5346
5558
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5347
5559
|
async (params) => {
|
|
5560
|
+
const ctx = tenantAuthContext();
|
|
5561
|
+
if (ctx) {
|
|
5562
|
+
const decision = evaluateToolPolicy(meta.name, ctx.scopes);
|
|
5563
|
+
if (!decision.allowed) {
|
|
5564
|
+
const status = decision.reason === "insufficient_scope" ? 403 : 500;
|
|
5565
|
+
return {
|
|
5566
|
+
content: [
|
|
5567
|
+
{
|
|
5568
|
+
type: "text",
|
|
5569
|
+
text: toolError({
|
|
5570
|
+
status,
|
|
5571
|
+
reason: decision.reason,
|
|
5572
|
+
message: decision.message
|
|
5573
|
+
})
|
|
5574
|
+
}
|
|
5575
|
+
]
|
|
5576
|
+
};
|
|
5577
|
+
}
|
|
5578
|
+
}
|
|
5348
5579
|
const result = await handler19(params);
|
|
5349
5580
|
return { content: [{ type: "text", text: result }] };
|
|
5350
5581
|
}
|
|
5351
5582
|
);
|
|
5352
5583
|
}
|
|
5353
|
-
function registerPrompt(server,
|
|
5584
|
+
function registerPrompt(server, schema34, meta, handler19) {
|
|
5354
5585
|
server.registerPrompt(
|
|
5355
5586
|
meta.name,
|
|
5356
5587
|
{
|
|
5357
5588
|
title: meta.title,
|
|
5358
5589
|
description: meta.description,
|
|
5359
|
-
argsSchema:
|
|
5590
|
+
argsSchema: schema34
|
|
5360
5591
|
},
|
|
5361
5592
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5362
5593
|
(params) => ({
|
|
@@ -5392,70 +5623,58 @@ function createServer(options = {}) {
|
|
|
5392
5623
|
if (toolSurface === "full") {
|
|
5393
5624
|
registerTool(server, schema, metadata, queryCollection);
|
|
5394
5625
|
registerTool(server, schema2, metadata2, getCollectionById);
|
|
5395
|
-
registerTool(server, schema3, metadata3,
|
|
5396
|
-
registerTool(server, schema4, metadata4,
|
|
5397
|
-
registerTool(server, schema5, metadata5,
|
|
5398
|
-
registerTool(server, schema6, metadata6,
|
|
5399
|
-
registerTool(server, schema7, metadata7,
|
|
5400
|
-
registerTool(server, schema8, metadata8,
|
|
5401
|
-
registerTool(server, schema9, metadata9,
|
|
5402
|
-
registerTool(server, schema10, metadata10,
|
|
5403
|
-
registerTool(server, schema11, metadata11,
|
|
5404
|
-
registerTool(server, schema12, metadata12,
|
|
5405
|
-
registerTool(server, schema13, metadata13,
|
|
5406
|
-
registerTool(server, schema14, metadata14,
|
|
5407
|
-
registerTool(server, schema15, metadata15,
|
|
5408
|
-
registerTool(server, schema16, metadata16,
|
|
5409
|
-
registerTool(server, schema17, metadata17,
|
|
5410
|
-
registerTool(server, schema18, metadata18,
|
|
5411
|
-
registerTool(server, schema19, metadata19,
|
|
5412
|
-
registerTool(server, schema20, metadata20,
|
|
5413
|
-
registerTool(server, schema21, metadata21,
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
registerTool(server, schema27, metadata27,
|
|
5421
|
-
registerTool(server, schema28, metadata28,
|
|
5422
|
-
registerTool(server, schema29, metadata29,
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
registerStaticResource(server, "
|
|
5433
|
-
registerStaticResource(server, "
|
|
5434
|
-
registerStaticResource(server, "docs://sdk/
|
|
5435
|
-
registerStaticResource(server, "docs://sdk/
|
|
5436
|
-
registerStaticResource(server, "docs://sdk/
|
|
5437
|
-
registerStaticResource(server, "docs://sdk/
|
|
5438
|
-
registerStaticResource(server, "docs://sdk/
|
|
5439
|
-
registerStaticResource(server, "docs://sdk/server-api", metadata46, handler13);
|
|
5440
|
-
registerStaticResource(server, "docs://sdk/customer-auth", metadata47, handler14);
|
|
5441
|
-
registerStaticResource(server, "docs://sdk/browser-vs-server", metadata48, handler15);
|
|
5442
|
-
registerStaticResource(server, "docs://sdk/file-upload", metadata49, handler16);
|
|
5443
|
-
registerStaticResource(server, "docs://sdk/webhook", metadata50, handler17);
|
|
5626
|
+
registerTool(server, schema3, metadata3, getOrder);
|
|
5627
|
+
registerTool(server, schema4, metadata4, createOrder);
|
|
5628
|
+
registerTool(server, schema5, metadata5, updateOrder);
|
|
5629
|
+
registerTool(server, schema6, metadata6, checkout);
|
|
5630
|
+
registerTool(server, schema7, metadata7, createFulfillment);
|
|
5631
|
+
registerTool(server, schema8, metadata8, updateFulfillment);
|
|
5632
|
+
registerTool(server, schema9, metadata9, updateTransaction);
|
|
5633
|
+
registerTool(server, schema10, metadata10, createReturn);
|
|
5634
|
+
registerTool(server, schema11, metadata11, updateReturn);
|
|
5635
|
+
registerTool(server, schema12, metadata12, returnWithRefund);
|
|
5636
|
+
registerTool(server, schema13, metadata13, addCartItem);
|
|
5637
|
+
registerTool(server, schema14, metadata14, updateCartItem);
|
|
5638
|
+
registerTool(server, schema15, metadata15, removeCartItem);
|
|
5639
|
+
registerTool(server, schema16, metadata16, applyDiscount);
|
|
5640
|
+
registerTool(server, schema17, metadata17, removeDiscount);
|
|
5641
|
+
registerTool(server, schema18, metadata18, clearCart);
|
|
5642
|
+
registerTool(server, schema19, metadata19, validateDiscount);
|
|
5643
|
+
registerTool(server, schema20, metadata20, calculateShipping);
|
|
5644
|
+
registerTool(server, schema21, metadata21, stockCheck);
|
|
5645
|
+
}
|
|
5646
|
+
registerTool(server, schema22, metadata22, getCollectionSchemaTool);
|
|
5647
|
+
registerTool(server, schema23, metadata23, handler);
|
|
5648
|
+
registerTool(server, schema24, metadata24, listConfigurableFields);
|
|
5649
|
+
registerTool(server, schema25, metadata25, updateFieldConfig);
|
|
5650
|
+
registerTool(server, schema26, metadata26, handler2);
|
|
5651
|
+
registerTool(server, schema27, metadata27, handler3);
|
|
5652
|
+
registerTool(server, schema28, metadata28, handler4);
|
|
5653
|
+
registerTool(server, schema29, metadata29, handler5);
|
|
5654
|
+
registerPrompt(server, schema30, metadata30, sdkUsageGuide);
|
|
5655
|
+
registerPrompt(server, schema31, metadata31, collectionQueryHelp);
|
|
5656
|
+
registerPrompt(server, schema32, metadata32, orderFlowGuide);
|
|
5657
|
+
registerPrompt(server, schema33, metadata33, featureSetupGuide);
|
|
5658
|
+
registerStaticResource(server, "config://app", metadata34, handler6);
|
|
5659
|
+
registerStaticResource(server, "collections://schema", metadata35, handler7);
|
|
5660
|
+
registerStaticResource(server, "docs://sdk/getting-started", metadata36, handler8);
|
|
5661
|
+
registerStaticResource(server, "docs://sdk/guides", metadata37, handler9);
|
|
5662
|
+
registerStaticResource(server, "docs://sdk/api", metadata38, handler10);
|
|
5663
|
+
registerStaticResource(server, "docs://sdk/query-builder", metadata39, handler11);
|
|
5664
|
+
registerStaticResource(server, "docs://sdk/react-query", metadata40, handler12);
|
|
5665
|
+
registerStaticResource(server, "docs://sdk/server-api", metadata41, handler13);
|
|
5666
|
+
registerStaticResource(server, "docs://sdk/customer-auth", metadata42, handler14);
|
|
5667
|
+
registerStaticResource(server, "docs://sdk/browser-vs-server", metadata43, handler15);
|
|
5668
|
+
registerStaticResource(server, "docs://sdk/file-upload", metadata44, handler16);
|
|
5669
|
+
registerStaticResource(server, "docs://sdk/webhook", metadata45, handler17);
|
|
5444
5670
|
return server;
|
|
5445
5671
|
}
|
|
5446
5672
|
|
|
5447
5673
|
// src/auth.ts
|
|
5448
5674
|
import { createPublicKey, verify as verifySignature } from "crypto";
|
|
5449
|
-
import {
|
|
5450
|
-
MCP_OAUTH_ISSUER as MCP_OAUTH_ISSUER2,
|
|
5451
|
-
MCP_RESOURCE_AUDIENCE,
|
|
5452
|
-
MCP_SCOPES,
|
|
5453
|
-
MCP_TENANT_CLAIM as MCP_TENANT_CLAIM2,
|
|
5454
|
-
MCP_TENANT_ROLE_CLAIM as MCP_TENANT_ROLE_CLAIM2
|
|
5455
|
-
} from "@01.software/auth-contracts";
|
|
5456
5675
|
var ALLOWED_ALGORITHMS = /* @__PURE__ */ new Set(["RS256", "ES256"]);
|
|
5457
5676
|
var DEFAULT_CLOCK_SKEW_SECONDS = 30;
|
|
5458
|
-
var DEFAULT_JWKS_URI = `${
|
|
5677
|
+
var DEFAULT_JWKS_URI = `${MCP_OAUTH_ISSUER}/.well-known/jwks.json`;
|
|
5459
5678
|
var MAX_ACCESS_TOKEN_LIFETIME_SECONDS = 300;
|
|
5460
5679
|
function invalid(errorDescription) {
|
|
5461
5680
|
return { valid: false, error: "invalid_token", errorDescription };
|
|
@@ -5558,7 +5777,7 @@ function validateAccessToken(token, options = {}) {
|
|
|
5558
5777
|
if (!verifyJwtSignature(header.alg, jwk, signingInput, signature)) {
|
|
5559
5778
|
return invalid("Bearer token signature is invalid");
|
|
5560
5779
|
}
|
|
5561
|
-
const issuer = options.issuer ??
|
|
5780
|
+
const issuer = options.issuer ?? MCP_OAUTH_ISSUER;
|
|
5562
5781
|
if (payload.iss !== issuer) return invalid("Bearer token issuer is invalid");
|
|
5563
5782
|
const audience = options.audience ?? MCP_RESOURCE_AUDIENCE;
|
|
5564
5783
|
if (!audienceMatches(payload.aud, audience)) {
|
|
@@ -5581,11 +5800,11 @@ function validateAccessToken(token, options = {}) {
|
|
|
5581
5800
|
return invalid("Bearer token is not yet valid");
|
|
5582
5801
|
}
|
|
5583
5802
|
if (payload.exp < nowSeconds - leeway) return invalid("Bearer token is expired");
|
|
5584
|
-
const tenantId = payload[
|
|
5803
|
+
const tenantId = payload[MCP_TENANT_CLAIM];
|
|
5585
5804
|
if (typeof tenantId !== "string" || tenantId.length === 0) {
|
|
5586
5805
|
return invalid("Bearer token tenant_id claim is invalid");
|
|
5587
5806
|
}
|
|
5588
|
-
const tenantRole = payload[
|
|
5807
|
+
const tenantRole = payload[MCP_TENANT_ROLE_CLAIM];
|
|
5589
5808
|
if (tenantRole !== "tenant-admin" && tenantRole !== "tenant-editor" && tenantRole !== "tenant-viewer") {
|
|
5590
5809
|
return invalid("Bearer token tenant_role claim is invalid");
|
|
5591
5810
|
}
|
|
@@ -5757,9 +5976,9 @@ API Reference https://01.software/docs/api/rest-api
|
|
|
5757
5976
|
Console https://console.01.software
|
|
5758
5977
|
`;
|
|
5759
5978
|
var PROTECTED_RESOURCE_METADATA = JSON.stringify({
|
|
5760
|
-
resource:
|
|
5761
|
-
authorization_servers: [
|
|
5762
|
-
scopes_supported: [
|
|
5979
|
+
resource: MCP_RESOURCE_AUDIENCE,
|
|
5980
|
+
authorization_servers: [MCP_OAUTH_ISSUER],
|
|
5981
|
+
scopes_supported: [MCP_SCOPES.read, MCP_SCOPES.write]
|
|
5763
5982
|
});
|
|
5764
5983
|
var SERVICE_JWKS_PATH = "/.well-known/service-jwks.json";
|
|
5765
5984
|
function writeOAuthError(res, status, error, description) {
|
|
@@ -5777,7 +5996,7 @@ async function handler18(req, res) {
|
|
|
5777
5996
|
return;
|
|
5778
5997
|
}
|
|
5779
5998
|
if (req.method === "GET") {
|
|
5780
|
-
const pathname = new URL(req.url ?? "/",
|
|
5999
|
+
const pathname = new URL(req.url ?? "/", MCP_RESOURCE_AUDIENCE).pathname;
|
|
5781
6000
|
if (pathname === MCP_PROTECTED_RESOURCE_METADATA_PATH) {
|
|
5782
6001
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
5783
6002
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
@@ -5841,16 +6060,28 @@ async function handler18(req, res) {
|
|
|
5841
6060
|
try {
|
|
5842
6061
|
const body = req.body ?? JSON.parse(await readBody(req));
|
|
5843
6062
|
await transport.handleRequest(req, res, body);
|
|
5844
|
-
} catch {
|
|
5845
|
-
|
|
5846
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
5847
|
-
res.end(JSON.stringify({ error: "Internal server error" }));
|
|
5848
|
-
}
|
|
6063
|
+
} catch (err) {
|
|
6064
|
+
writeRequestError(res, err);
|
|
5849
6065
|
} finally {
|
|
5850
6066
|
await close();
|
|
5851
6067
|
}
|
|
5852
6068
|
});
|
|
5853
6069
|
}
|
|
6070
|
+
function writeRequestError(res, err) {
|
|
6071
|
+
if (res.headersSent) return;
|
|
6072
|
+
if (err instanceof SyntaxError) {
|
|
6073
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
6074
|
+
res.end(JSON.stringify({ error: "Invalid JSON body" }));
|
|
6075
|
+
return;
|
|
6076
|
+
}
|
|
6077
|
+
if (err instanceof Error && err.message === "Request body too large") {
|
|
6078
|
+
res.writeHead(413, { "Content-Type": "application/json" });
|
|
6079
|
+
res.end(JSON.stringify({ error: "Request body too large" }));
|
|
6080
|
+
return;
|
|
6081
|
+
}
|
|
6082
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
6083
|
+
res.end(JSON.stringify({ error: "Internal server error" }));
|
|
6084
|
+
}
|
|
5854
6085
|
export {
|
|
5855
6086
|
handler18 as default
|
|
5856
6087
|
};
|