@01.software/cli 0.13.0 → 0.14.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 +581 -285
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
- package/dist/mcp/.01-cli-mcp-build.json +0 -14
- package/dist/mcp/chunk-Y5GYUAK3.js +0 -7524
- package/dist/mcp/chunk-Y5GYUAK3.js.map +0 -1
- package/dist/mcp/http.js +0 -470
- package/dist/mcp/http.js.map +0 -1
- package/dist/mcp/stdio.js +0 -20
- package/dist/mcp/stdio.js.map +0 -1
- package/dist/mcp/vercel.d.ts +0 -5
- package/dist/mcp/vercel.js +0 -7955
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Command } from "commander";
|
|
|
6
6
|
|
|
7
7
|
// src/lib/client.ts
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
ServerCollectionClient,
|
|
10
10
|
ServerCommerceClient,
|
|
11
11
|
TenantIntrospectionApi
|
|
12
12
|
} from "@01.software/sdk/server";
|
|
@@ -491,11 +491,7 @@ function resolveClientCredentials(apiKeyFlag) {
|
|
|
491
491
|
if (!publishableKey || !secretKey) {
|
|
492
492
|
throw credentialError({
|
|
493
493
|
message: t("AuthenticationRequired"),
|
|
494
|
-
steps: [
|
|
495
|
-
t("RunLoginToAuthenticate"),
|
|
496
|
-
t("PassApiKey"),
|
|
497
|
-
t("SetEnvVars")
|
|
498
|
-
]
|
|
494
|
+
steps: [t("RunLoginToAuthenticate"), t("PassApiKey"), t("SetEnvVars")]
|
|
499
495
|
});
|
|
500
496
|
}
|
|
501
497
|
if (!isValidBearerToken(secretKey)) {
|
|
@@ -510,7 +506,7 @@ function resolveClientOrThrow(apiKeyFlag) {
|
|
|
510
506
|
const { publishableKey, secretKey } = resolveClientCredentials(apiKeyFlag);
|
|
511
507
|
const serverOptions = { publishableKey, secretKey };
|
|
512
508
|
return {
|
|
513
|
-
collections: new
|
|
509
|
+
collections: new ServerCollectionClient(
|
|
514
510
|
publishableKey,
|
|
515
511
|
secretKey,
|
|
516
512
|
void 0,
|
|
@@ -536,13 +532,13 @@ import { readFileSync as readFileSync2 } from "fs";
|
|
|
536
532
|
import { basename } from "path";
|
|
537
533
|
|
|
538
534
|
// src/lib/collections.ts
|
|
539
|
-
import {
|
|
535
|
+
import { SERVER_COLLECTIONS } from "@01.software/sdk";
|
|
540
536
|
function validateCollection(name) {
|
|
541
|
-
if (
|
|
537
|
+
if (SERVER_COLLECTIONS.includes(name)) {
|
|
542
538
|
return name;
|
|
543
539
|
}
|
|
544
540
|
const normalized = name.replace(/-/g, "").toLowerCase();
|
|
545
|
-
const suggestions =
|
|
541
|
+
const suggestions = SERVER_COLLECTIONS.filter((collection) => {
|
|
546
542
|
const candidate = collection.replace(/-/g, "").toLowerCase();
|
|
547
543
|
return candidate.startsWith(normalized) || normalized.startsWith(candidate) || normalized.length >= 3 && candidate.includes(normalized);
|
|
548
544
|
}).slice(0, 5);
|
|
@@ -955,40 +951,203 @@ var collectionSchemaResponseSchema = z.object({
|
|
|
955
951
|
}).strict();
|
|
956
952
|
|
|
957
953
|
// ../contracts/src/ecommerce/index.ts
|
|
954
|
+
import { z as z3 } from "zod";
|
|
955
|
+
|
|
956
|
+
// ../contracts/src/ecommerce/product-upsert.ts
|
|
958
957
|
import { z as z2 } from "zod";
|
|
959
|
-
var
|
|
958
|
+
var IdSchema = z2.union([z2.string(), z2.number()]).transform(String);
|
|
959
|
+
var RemovedLegacyMediaFieldSchema = z2.unknown().optional();
|
|
960
|
+
var productFieldShape = {
|
|
961
|
+
id: IdSchema.optional(),
|
|
962
|
+
title: z2.string().min(1).optional(),
|
|
963
|
+
subtitle: z2.string().optional().nullable(),
|
|
964
|
+
description: z2.string().optional().nullable(),
|
|
965
|
+
status: z2.string().optional(),
|
|
966
|
+
slug: z2.string().optional(),
|
|
967
|
+
primaryMediaItemId: IdSchema.optional().nullable(),
|
|
968
|
+
thumbnail: IdSchema.optional().nullable(),
|
|
969
|
+
images: z2.array(IdSchema).optional(),
|
|
970
|
+
mediaSets: RemovedLegacyMediaFieldSchema,
|
|
971
|
+
vendor: z2.string().optional().nullable(),
|
|
972
|
+
productType: z2.string().optional().nullable(),
|
|
973
|
+
brand: IdSchema.optional().nullable(),
|
|
974
|
+
shippingPolicy: IdSchema.optional().nullable(),
|
|
975
|
+
weight: z2.number().int().min(0).optional().nullable(),
|
|
976
|
+
minOrderQuantity: z2.number().int().min(1).optional().nullable(),
|
|
977
|
+
maxOrderQuantity: z2.number().int().min(1).optional().nullable(),
|
|
978
|
+
isFeatured: z2.boolean().optional(),
|
|
979
|
+
publishedAt: z2.string().optional().nullable(),
|
|
980
|
+
categories: z2.array(IdSchema).optional(),
|
|
981
|
+
tags: z2.array(IdSchema).optional(),
|
|
982
|
+
metadata: z2.unknown().optional()
|
|
983
|
+
};
|
|
984
|
+
var PRODUCT_UPSERT_PRODUCT_FIELDS = Object.keys(
|
|
985
|
+
productFieldShape
|
|
986
|
+
);
|
|
987
|
+
var ProductFieldsSchema = z2.object(productFieldShape).passthrough();
|
|
988
|
+
var OptionValueObjectSchema = z2.object({
|
|
989
|
+
id: IdSchema.optional(),
|
|
990
|
+
value: z2.string().min(1, "Option value `value` is required"),
|
|
991
|
+
slug: z2.string().optional(),
|
|
992
|
+
swatch: z2.object({
|
|
993
|
+
type: z2.enum(["color", "media"]).optional().nullable(),
|
|
994
|
+
color: z2.string().optional().nullable(),
|
|
995
|
+
mediaItemId: IdSchema.optional().nullable()
|
|
996
|
+
}).optional().nullable(),
|
|
997
|
+
thumbnail: RemovedLegacyMediaFieldSchema,
|
|
998
|
+
images: RemovedLegacyMediaFieldSchema,
|
|
999
|
+
metadata: z2.unknown().optional()
|
|
1000
|
+
});
|
|
1001
|
+
var OptionValueInputSchema = OptionValueObjectSchema.passthrough().superRefine(
|
|
1002
|
+
(value, ctx) => {
|
|
1003
|
+
if (Object.prototype.hasOwnProperty.call(value, "swatchColor")) {
|
|
1004
|
+
ctx.addIssue({
|
|
1005
|
+
code: "custom",
|
|
1006
|
+
message: "Option value field `swatchColor` was removed. Use nested `swatch.color` instead.",
|
|
1007
|
+
path: ["swatchColor"]
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
);
|
|
1012
|
+
var OptionInputSchema = z2.object({
|
|
1013
|
+
id: IdSchema.optional(),
|
|
1014
|
+
title: z2.string().min(1, "Option `title` is required"),
|
|
1015
|
+
slug: z2.string().optional(),
|
|
1016
|
+
values: z2.array(OptionValueInputSchema).min(1, "Each option must have at least one value")
|
|
1017
|
+
});
|
|
1018
|
+
var VariantOptionValueObjectSchema = z2.object({
|
|
1019
|
+
valueSlug: z2.string().optional(),
|
|
1020
|
+
valueId: IdSchema.optional(),
|
|
1021
|
+
value: z2.string().optional()
|
|
1022
|
+
}).refine((data) => Boolean(data.valueSlug ?? data.valueId ?? data.value), {
|
|
1023
|
+
message: "Variant option value object requires valueSlug, valueId, or value"
|
|
1024
|
+
});
|
|
1025
|
+
var VariantInputSchema = z2.object({
|
|
1026
|
+
id: IdSchema.optional(),
|
|
1027
|
+
optionValues: z2.union([
|
|
1028
|
+
z2.record(
|
|
1029
|
+
z2.string(),
|
|
1030
|
+
z2.union([z2.string(), VariantOptionValueObjectSchema])
|
|
1031
|
+
),
|
|
1032
|
+
z2.array(IdSchema)
|
|
1033
|
+
]).optional(),
|
|
1034
|
+
sku: z2.string().optional().nullable(),
|
|
1035
|
+
title: z2.string().optional().nullable(),
|
|
1036
|
+
price: z2.number().min(0),
|
|
1037
|
+
compareAtPrice: z2.number().min(0).optional().nullable(),
|
|
1038
|
+
stock: z2.number().int().min(0).optional(),
|
|
1039
|
+
isUnlimited: z2.boolean().optional(),
|
|
1040
|
+
weight: z2.number().int().min(0).optional().nullable(),
|
|
1041
|
+
requiresShipping: z2.boolean().optional(),
|
|
1042
|
+
barcode: z2.string().optional().nullable(),
|
|
1043
|
+
externalId: z2.string().optional().nullable(),
|
|
1044
|
+
isActive: z2.boolean().optional(),
|
|
1045
|
+
images: z2.array(IdSchema).optional(),
|
|
1046
|
+
thumbnail: RemovedLegacyMediaFieldSchema,
|
|
1047
|
+
featuredMediaItemId: RemovedLegacyMediaFieldSchema,
|
|
1048
|
+
metadata: z2.unknown().optional()
|
|
1049
|
+
});
|
|
1050
|
+
var ProductUpsertObjectSchema = z2.object({
|
|
1051
|
+
/** Required on graph edit when the server graph is non-empty (`productId` set); optional for first seed on an empty graph. */
|
|
1052
|
+
graphRevision: z2.string().optional(),
|
|
1053
|
+
productId: IdSchema.optional(),
|
|
1054
|
+
product: ProductFieldsSchema.optional(),
|
|
1055
|
+
options: z2.array(OptionInputSchema).max(10).optional().default([]),
|
|
1056
|
+
variants: z2.array(VariantInputSchema).max(500).optional().default([])
|
|
1057
|
+
});
|
|
1058
|
+
var ProductUpsertSchema = ProductUpsertObjectSchema.superRefine(
|
|
1059
|
+
(data, ctx) => {
|
|
1060
|
+
const nestedProductId = data.product?.id;
|
|
1061
|
+
if (data.productId != null && nestedProductId != null && String(data.productId) !== String(nestedProductId)) {
|
|
1062
|
+
ctx.addIssue({
|
|
1063
|
+
code: "custom",
|
|
1064
|
+
message: "productId must match product.id when both are set on graph upsert.",
|
|
1065
|
+
path: ["productId"]
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
const productId = data.productId ?? nestedProductId;
|
|
1069
|
+
const isEdit = productId != null;
|
|
1070
|
+
if (!isEdit && data.productId != null) {
|
|
1071
|
+
ctx.addIssue({
|
|
1072
|
+
code: "custom",
|
|
1073
|
+
message: "productId is not allowed when creating a product.",
|
|
1074
|
+
path: ["productId"]
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
if (!isEdit && !data.product?.title) {
|
|
1078
|
+
ctx.addIssue({
|
|
1079
|
+
code: "custom",
|
|
1080
|
+
message: "Product `title` is required when creating a new product.",
|
|
1081
|
+
path: ["product", "title"]
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
if (isEdit && data.product) {
|
|
1085
|
+
for (const key of Object.keys(data.product)) {
|
|
1086
|
+
if (key !== "id") {
|
|
1087
|
+
ctx.addIssue({
|
|
1088
|
+
code: "custom",
|
|
1089
|
+
message: "Existing product graph upsert accepts only product identity. Save document fields through Payload.",
|
|
1090
|
+
path: ["product", key]
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
);
|
|
1097
|
+
|
|
1098
|
+
// ../contracts/src/ecommerce/index.ts
|
|
1099
|
+
var transactionStatusSchema = z3.enum([
|
|
960
1100
|
"pending",
|
|
961
1101
|
"paid",
|
|
962
1102
|
"failed",
|
|
963
1103
|
"canceled"
|
|
964
1104
|
]);
|
|
965
|
-
var financialStatusSchema =
|
|
1105
|
+
var financialStatusSchema = z3.enum([
|
|
966
1106
|
"pending",
|
|
967
1107
|
"paid",
|
|
968
|
-
"failed",
|
|
969
1108
|
"canceled",
|
|
970
1109
|
"partially_refunded",
|
|
971
1110
|
"refunded"
|
|
972
1111
|
]);
|
|
973
|
-
var
|
|
974
|
-
|
|
1112
|
+
var orderDisplayFinancialStatusSchema = z3.enum([
|
|
1113
|
+
"pending",
|
|
1114
|
+
"paid",
|
|
1115
|
+
"partially_refunded",
|
|
1116
|
+
"refunded",
|
|
1117
|
+
"voided"
|
|
1118
|
+
]);
|
|
1119
|
+
var confirmationStatusSchema = z3.enum(["unconfirmed", "confirmed"]);
|
|
1120
|
+
var fulfillmentOrderStatusSchema = z3.enum([
|
|
975
1121
|
"open",
|
|
976
1122
|
"in_progress",
|
|
977
1123
|
"on_hold",
|
|
978
1124
|
"canceled",
|
|
979
1125
|
"closed"
|
|
980
1126
|
]);
|
|
981
|
-
var shipmentStatusSchema =
|
|
1127
|
+
var shipmentStatusSchema = z3.enum([
|
|
982
1128
|
"pending",
|
|
983
1129
|
"shipped",
|
|
984
1130
|
"delivered",
|
|
985
1131
|
"canceled",
|
|
986
1132
|
"failed"
|
|
987
1133
|
]);
|
|
988
|
-
var
|
|
1134
|
+
var orderDisplayFulfillmentStatusSchema = z3.enum([
|
|
1135
|
+
"unfulfilled",
|
|
1136
|
+
"in_progress",
|
|
1137
|
+
"on_hold",
|
|
1138
|
+
"shipped",
|
|
1139
|
+
"fulfilled",
|
|
1140
|
+
"canceled"
|
|
1141
|
+
]);
|
|
1142
|
+
var orderReturnStatusSchema = z3.enum([
|
|
1143
|
+
"no_return",
|
|
1144
|
+
"return_requested",
|
|
1145
|
+
"in_progress",
|
|
1146
|
+
"returned"
|
|
1147
|
+
]);
|
|
1148
|
+
var orderStatusSchema = z3.enum([
|
|
989
1149
|
"pending",
|
|
990
1150
|
"paid",
|
|
991
|
-
"failed",
|
|
992
1151
|
"canceled",
|
|
993
1152
|
"refunded",
|
|
994
1153
|
"preparing",
|
|
@@ -999,119 +1158,122 @@ var orderStatusSchema = z2.enum([
|
|
|
999
1158
|
"return_processing",
|
|
1000
1159
|
"returned"
|
|
1001
1160
|
]);
|
|
1002
|
-
var entityIdSchema =
|
|
1003
|
-
var createOrderItemSchema =
|
|
1004
|
-
product:
|
|
1161
|
+
var entityIdSchema = z3.union([z3.string().min(1), z3.number()]).transform(String);
|
|
1162
|
+
var createOrderItemSchema = z3.object({
|
|
1163
|
+
// `product` and `option` are storefront-optional: the create-order
|
|
1164
|
+
// endpoint derives the product from the variant's parent and snapshots
|
|
1165
|
+
// option selection from the variant.
|
|
1166
|
+
product: entityIdSchema.optional(),
|
|
1005
1167
|
variant: entityIdSchema,
|
|
1006
|
-
option: entityIdSchema,
|
|
1007
|
-
quantity:
|
|
1008
|
-
unitPrice:
|
|
1009
|
-
totalPrice:
|
|
1168
|
+
option: entityIdSchema.optional(),
|
|
1169
|
+
quantity: z3.number().int().positive("quantity must be a positive integer"),
|
|
1170
|
+
unitPrice: z3.number().optional(),
|
|
1171
|
+
totalPrice: z3.number().optional()
|
|
1010
1172
|
}).strict();
|
|
1011
|
-
var createOrderSchema =
|
|
1012
|
-
pgPaymentId:
|
|
1013
|
-
orderNumber:
|
|
1173
|
+
var createOrderSchema = z3.object({
|
|
1174
|
+
pgPaymentId: z3.string().min(1).optional(),
|
|
1175
|
+
orderNumber: z3.string().min(1, "orderNumber is required"),
|
|
1014
1176
|
customer: entityIdSchema.optional(),
|
|
1015
|
-
customerSnapshot:
|
|
1016
|
-
name:
|
|
1017
|
-
email:
|
|
1018
|
-
phone:
|
|
1177
|
+
customerSnapshot: z3.object({
|
|
1178
|
+
name: z3.string().optional(),
|
|
1179
|
+
email: z3.string().email("Invalid email format"),
|
|
1180
|
+
phone: z3.string().optional()
|
|
1019
1181
|
}).strict(),
|
|
1020
|
-
shippingAddress:
|
|
1021
|
-
postalCode:
|
|
1022
|
-
address:
|
|
1023
|
-
detailAddress:
|
|
1024
|
-
deliveryMessage:
|
|
1025
|
-
recipientName:
|
|
1026
|
-
phone:
|
|
1182
|
+
shippingAddress: z3.object({
|
|
1183
|
+
postalCode: z3.string().optional(),
|
|
1184
|
+
address: z3.string().optional(),
|
|
1185
|
+
detailAddress: z3.string().optional(),
|
|
1186
|
+
deliveryMessage: z3.string().optional(),
|
|
1187
|
+
recipientName: z3.string().optional(),
|
|
1188
|
+
phone: z3.string().optional()
|
|
1027
1189
|
}).strict(),
|
|
1028
|
-
orderItems:
|
|
1029
|
-
totalAmount:
|
|
1030
|
-
shippingAmount:
|
|
1031
|
-
discountCode:
|
|
1190
|
+
orderItems: z3.array(createOrderItemSchema).min(1, "At least one order item is required").max(100, "Maximum 100 items per order"),
|
|
1191
|
+
totalAmount: z3.number().nonnegative("totalAmount must be non-negative"),
|
|
1192
|
+
shippingAmount: z3.number().min(0).optional(),
|
|
1193
|
+
discountCode: z3.string().optional()
|
|
1032
1194
|
}).strict();
|
|
1033
|
-
var updateTransactionSchema =
|
|
1034
|
-
pgPaymentId:
|
|
1195
|
+
var updateTransactionSchema = z3.object({
|
|
1196
|
+
pgPaymentId: z3.string().min(1, "pgPaymentId is required").describe("PG payment ID (required)"),
|
|
1035
1197
|
status: transactionStatusSchema.describe(
|
|
1036
1198
|
"New transaction status (required)"
|
|
1037
1199
|
),
|
|
1038
|
-
paymentMethod:
|
|
1039
|
-
receiptUrl:
|
|
1040
|
-
paymentKey:
|
|
1041
|
-
amount:
|
|
1200
|
+
paymentMethod: z3.string().optional().describe("Payment method (optional)"),
|
|
1201
|
+
receiptUrl: z3.string().optional().describe("Receipt URL (optional)"),
|
|
1202
|
+
paymentKey: z3.string().min(1).optional().describe("Provider payment key for verified paid confirmation"),
|
|
1203
|
+
amount: z3.number().int().positive().optional().describe("Provider-confirmed amount for verified paid confirmation")
|
|
1042
1204
|
}).strict();
|
|
1043
|
-
var providerSlugSchema =
|
|
1044
|
-
var confirmPaymentSchema =
|
|
1045
|
-
orderNumber:
|
|
1046
|
-
pgPaymentId:
|
|
1205
|
+
var providerSlugSchema = z3.string().trim().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/, "pgProvider must be lowercase slug");
|
|
1206
|
+
var confirmPaymentSchema = z3.object({
|
|
1207
|
+
orderNumber: z3.string().min(1).optional(),
|
|
1208
|
+
pgPaymentId: z3.string().min(1, "pgPaymentId is required").describe("Provider payment identifier stored on the transaction"),
|
|
1047
1209
|
pgProvider: providerSlugSchema.describe(
|
|
1048
1210
|
"Payment provider slug, e.g. toss, portone, stripe"
|
|
1049
1211
|
),
|
|
1050
|
-
pgOrderId:
|
|
1051
|
-
amount:
|
|
1052
|
-
currency:
|
|
1053
|
-
paymentMethod:
|
|
1054
|
-
receiptUrl:
|
|
1055
|
-
approvedAt:
|
|
1056
|
-
providerStatus:
|
|
1057
|
-
providerEventId:
|
|
1058
|
-
confirmationSource:
|
|
1212
|
+
pgOrderId: z3.string().min(1).optional(),
|
|
1213
|
+
amount: z3.number().int().nonnegative("amount must be non-negative").describe("Provider-confirmed amount in minor units"),
|
|
1214
|
+
currency: z3.string().min(1).optional(),
|
|
1215
|
+
paymentMethod: z3.string().optional(),
|
|
1216
|
+
receiptUrl: z3.string().url().optional(),
|
|
1217
|
+
approvedAt: z3.string().optional(),
|
|
1218
|
+
providerStatus: z3.string().optional(),
|
|
1219
|
+
providerEventId: z3.string().min(1).optional(),
|
|
1220
|
+
confirmationSource: z3.enum([
|
|
1059
1221
|
"provider_webhook",
|
|
1060
1222
|
"provider_lookup",
|
|
1061
1223
|
"provider_api_confirm",
|
|
1062
1224
|
"manual_server"
|
|
1063
1225
|
]).optional(),
|
|
1064
|
-
paymentKey:
|
|
1226
|
+
paymentKey: z3.string().min(1).optional().describe(
|
|
1065
1227
|
"Optional provider payment key from the client confirm handshake; stored for BFF/provider refund workflows (also accepted as metadata.tossPaymentKey). Local cancel does not read this field."
|
|
1066
1228
|
),
|
|
1067
|
-
metadata:
|
|
1229
|
+
metadata: z3.record(z3.string(), z3.unknown()).optional()
|
|
1068
1230
|
}).strict();
|
|
1069
|
-
var returnReasonSchema =
|
|
1231
|
+
var returnReasonSchema = z3.enum([
|
|
1070
1232
|
"change_of_mind",
|
|
1071
1233
|
"defective",
|
|
1072
1234
|
"wrong_delivery",
|
|
1073
1235
|
"damaged",
|
|
1074
1236
|
"other"
|
|
1075
1237
|
]);
|
|
1076
|
-
var restockActionSchema =
|
|
1077
|
-
var returnWithRefundItemSchema =
|
|
1078
|
-
orderItem:
|
|
1079
|
-
quantity:
|
|
1238
|
+
var restockActionSchema = z3.enum(["return_to_stock", "discard"]);
|
|
1239
|
+
var returnWithRefundItemSchema = z3.object({
|
|
1240
|
+
orderItem: z3.union([z3.string().min(1), z3.number()]).transform(String),
|
|
1241
|
+
quantity: z3.number().int().positive("quantity must be a positive integer"),
|
|
1080
1242
|
restockAction: restockActionSchema.default("return_to_stock"),
|
|
1081
|
-
restockingFee:
|
|
1243
|
+
restockingFee: z3.number().min(0, "restockingFee must be non-negative").optional().describe("Restocking fee charged for this line (ADR 0005 \xA7Gap 1)")
|
|
1082
1244
|
}).strict();
|
|
1083
|
-
var returnWithRefundSchema =
|
|
1084
|
-
orderNumber:
|
|
1245
|
+
var returnWithRefundSchema = z3.object({
|
|
1246
|
+
orderNumber: z3.string().min(1, "orderNumber is required").describe("Order number (required)"),
|
|
1085
1247
|
reason: returnReasonSchema.optional().describe("Return reason (optional)"),
|
|
1086
|
-
reasonDetail:
|
|
1087
|
-
returnItems:
|
|
1088
|
-
refundAmount:
|
|
1089
|
-
returnShippingFee:
|
|
1248
|
+
reasonDetail: z3.string().optional().describe("Detailed reason text (optional)"),
|
|
1249
|
+
returnItems: z3.array(returnWithRefundItemSchema).min(1, "At least one return item is required").max(100, "Too many return items").describe("Array of products to return (required)"),
|
|
1250
|
+
refundAmount: z3.number().min(0, "refundAmount must be non-negative").describe("Refund amount (required, min 0)"),
|
|
1251
|
+
returnShippingFee: z3.number().min(0, "returnShippingFee must be non-negative").optional().describe(
|
|
1090
1252
|
"Return shipping fee charged to the customer (ADR 0005 \xA7Gap 1)"
|
|
1091
1253
|
),
|
|
1092
|
-
initialShippingRefundAmount:
|
|
1093
|
-
initialShippingRefundOverrideNote:
|
|
1254
|
+
initialShippingRefundAmount: z3.number().min(0, "initialShippingRefundAmount must be non-negative").optional().describe("Initial order shipping amount refunded to the customer"),
|
|
1255
|
+
initialShippingRefundOverrideNote: z3.string().min(1).optional().describe(
|
|
1094
1256
|
"Operator audit note required when overriding policy suggestion"
|
|
1095
1257
|
),
|
|
1096
|
-
pgPaymentId:
|
|
1097
|
-
paymentKey:
|
|
1098
|
-
refundReceiptUrl:
|
|
1258
|
+
pgPaymentId: z3.string().min(1, "pgPaymentId is required").describe("PG payment ID for refund (required)"),
|
|
1259
|
+
paymentKey: z3.string().min(1).optional().describe("Provider payment key for verified refund"),
|
|
1260
|
+
refundReceiptUrl: z3.string().optional().describe("Refund receipt URL (optional)")
|
|
1099
1261
|
}).strict();
|
|
1100
|
-
var createReturnSchema =
|
|
1101
|
-
orderNumber:
|
|
1262
|
+
var createReturnSchema = z3.object({
|
|
1263
|
+
orderNumber: z3.string().min(1, "orderNumber is required").describe("Order number (required)"),
|
|
1102
1264
|
reason: returnReasonSchema.optional().describe("Return reason (optional)"),
|
|
1103
|
-
reasonDetail:
|
|
1104
|
-
returnItems:
|
|
1105
|
-
refundAmount:
|
|
1265
|
+
reasonDetail: z3.string().optional().describe("Detailed reason text (optional)"),
|
|
1266
|
+
returnItems: z3.array(returnWithRefundItemSchema).min(1, "At least one return item is required").max(100, "Too many return items").describe("Array of products to return (required)"),
|
|
1267
|
+
refundAmount: z3.number().min(0, "refundAmount must be non-negative").describe(
|
|
1106
1268
|
"Line refund amount before initial shipping refund (required, min 0)"
|
|
1107
1269
|
),
|
|
1108
|
-
returnShippingFee:
|
|
1109
|
-
initialShippingRefundAmount:
|
|
1110
|
-
initialShippingRefundOverrideNote:
|
|
1270
|
+
returnShippingFee: z3.number().min(0, "returnShippingFee must be non-negative").optional().describe("Return shipping fee charged to the customer"),
|
|
1271
|
+
initialShippingRefundAmount: z3.number().min(0, "initialShippingRefundAmount must be non-negative").optional().describe("Initial order shipping amount refunded to the customer"),
|
|
1272
|
+
initialShippingRefundOverrideNote: z3.string().min(1).optional().describe(
|
|
1111
1273
|
"Operator audit note required when overriding policy suggestion"
|
|
1112
1274
|
)
|
|
1113
1275
|
}).strict();
|
|
1114
|
-
var cancelReasonCodeSchema =
|
|
1276
|
+
var cancelReasonCodeSchema = z3.enum([
|
|
1115
1277
|
"customer",
|
|
1116
1278
|
"inventory",
|
|
1117
1279
|
"fraud",
|
|
@@ -1119,45 +1281,45 @@ var cancelReasonCodeSchema = z2.enum([
|
|
|
1119
1281
|
"staff",
|
|
1120
1282
|
"other"
|
|
1121
1283
|
]);
|
|
1122
|
-
var idempotencyKeySchema =
|
|
1284
|
+
var idempotencyKeySchema = z3.string().trim().min(1, "idempotencyKey is required").max(255, "idempotencyKey must be 255 characters or fewer").regex(
|
|
1123
1285
|
/^[\x21-\x7E]+$/,
|
|
1124
1286
|
"idempotencyKey must contain only printable header-safe characters"
|
|
1125
1287
|
);
|
|
1126
|
-
var cancelOrderSchema =
|
|
1127
|
-
orderNumber:
|
|
1288
|
+
var cancelOrderSchema = z3.object({
|
|
1289
|
+
orderNumber: z3.string().min(1, "orderNumber is required").describe("Order number to cancel"),
|
|
1128
1290
|
reasonCode: cancelReasonCodeSchema.default("other").describe("Operator-selected cancel reason code"),
|
|
1129
|
-
reasonDetail:
|
|
1291
|
+
reasonDetail: z3.string().trim().max(2e3, "reasonDetail must be 2000 characters or fewer").optional().describe("Internal cancellation detail stored on the order")
|
|
1130
1292
|
}).strict();
|
|
1131
1293
|
var cancelOrderResponseBaseSchema = {
|
|
1132
|
-
orderId:
|
|
1294
|
+
orderId: z3.string().min(1)
|
|
1133
1295
|
};
|
|
1134
1296
|
var unpaidLocalCancelCommittedResponseFields = {
|
|
1135
|
-
refundedAmount:
|
|
1136
|
-
providerRefunded:
|
|
1297
|
+
refundedAmount: z3.literal(0),
|
|
1298
|
+
providerRefunded: z3.literal(false)
|
|
1137
1299
|
};
|
|
1138
1300
|
var paidLocalCancelCommittedResponseFields = {
|
|
1139
|
-
transactionId:
|
|
1140
|
-
refundedAmount:
|
|
1141
|
-
providerRefunded:
|
|
1142
|
-
refundPending:
|
|
1301
|
+
transactionId: z3.string().min(1),
|
|
1302
|
+
refundedAmount: z3.literal(0),
|
|
1303
|
+
providerRefunded: z3.literal(false),
|
|
1304
|
+
refundPending: z3.literal(true)
|
|
1143
1305
|
};
|
|
1144
1306
|
var legacyProviderRefundResponseFields = {
|
|
1145
|
-
transactionId:
|
|
1146
|
-
refundedAmount:
|
|
1147
|
-
refundSeq:
|
|
1148
|
-
providerRefunded:
|
|
1307
|
+
transactionId: z3.string().min(1),
|
|
1308
|
+
refundedAmount: z3.number().int().positive(),
|
|
1309
|
+
refundSeq: z3.number().int().positive(),
|
|
1310
|
+
providerRefunded: z3.literal(true)
|
|
1149
1311
|
};
|
|
1150
1312
|
var alreadyCanceledResponseFields = {
|
|
1151
|
-
refundedAmount:
|
|
1152
|
-
providerRefunded:
|
|
1313
|
+
refundedAmount: z3.number().int().nonnegative(),
|
|
1314
|
+
providerRefunded: z3.literal(false)
|
|
1153
1315
|
};
|
|
1154
1316
|
var alreadyCanceledRefundPendingResponseFields = {
|
|
1155
|
-
transactionId:
|
|
1156
|
-
refundedAmount:
|
|
1157
|
-
providerRefunded:
|
|
1158
|
-
refundPending:
|
|
1317
|
+
transactionId: z3.string().min(1),
|
|
1318
|
+
refundedAmount: z3.number().int().nonnegative(),
|
|
1319
|
+
providerRefunded: z3.literal(false),
|
|
1320
|
+
refundPending: z3.literal(true)
|
|
1159
1321
|
};
|
|
1160
|
-
var cancelOrderReconciliationStatusSchema =
|
|
1322
|
+
var cancelOrderReconciliationStatusSchema = z3.enum([
|
|
1161
1323
|
"paid",
|
|
1162
1324
|
"preparing",
|
|
1163
1325
|
"shipped",
|
|
@@ -1168,123 +1330,123 @@ var cancelOrderReconciliationStatusSchema = z2.enum([
|
|
|
1168
1330
|
"returned",
|
|
1169
1331
|
"refunded"
|
|
1170
1332
|
]);
|
|
1171
|
-
var cancelOrderResponseSchema =
|
|
1172
|
-
|
|
1333
|
+
var cancelOrderResponseSchema = z3.union([
|
|
1334
|
+
z3.object({
|
|
1173
1335
|
...cancelOrderResponseBaseSchema,
|
|
1174
1336
|
...paidLocalCancelCommittedResponseFields,
|
|
1175
|
-
status:
|
|
1176
|
-
cancelCommitted:
|
|
1337
|
+
status: z3.literal("canceled"),
|
|
1338
|
+
cancelCommitted: z3.literal(true)
|
|
1177
1339
|
}).strict(),
|
|
1178
|
-
|
|
1340
|
+
z3.object({
|
|
1179
1341
|
...cancelOrderResponseBaseSchema,
|
|
1180
1342
|
...unpaidLocalCancelCommittedResponseFields,
|
|
1181
|
-
status:
|
|
1182
|
-
cancelCommitted:
|
|
1343
|
+
status: z3.literal("canceled"),
|
|
1344
|
+
cancelCommitted: z3.literal(true)
|
|
1183
1345
|
}).strict(),
|
|
1184
|
-
|
|
1346
|
+
z3.object({
|
|
1185
1347
|
...cancelOrderResponseBaseSchema,
|
|
1186
1348
|
...alreadyCanceledResponseFields,
|
|
1187
|
-
status:
|
|
1188
|
-
cancelCommitted:
|
|
1189
|
-
alreadyCanceled:
|
|
1349
|
+
status: z3.literal("canceled"),
|
|
1350
|
+
cancelCommitted: z3.literal(false),
|
|
1351
|
+
alreadyCanceled: z3.literal(true)
|
|
1190
1352
|
}).strict(),
|
|
1191
|
-
|
|
1353
|
+
z3.object({
|
|
1192
1354
|
...cancelOrderResponseBaseSchema,
|
|
1193
1355
|
...alreadyCanceledRefundPendingResponseFields,
|
|
1194
|
-
status:
|
|
1195
|
-
cancelCommitted:
|
|
1196
|
-
alreadyCanceled:
|
|
1356
|
+
status: z3.literal("canceled"),
|
|
1357
|
+
cancelCommitted: z3.literal(false),
|
|
1358
|
+
alreadyCanceled: z3.literal(true)
|
|
1197
1359
|
}).strict(),
|
|
1198
|
-
|
|
1360
|
+
z3.object({
|
|
1199
1361
|
...cancelOrderResponseBaseSchema,
|
|
1200
1362
|
...legacyProviderRefundResponseFields,
|
|
1201
1363
|
status: cancelOrderReconciliationStatusSchema,
|
|
1202
|
-
cancelCommitted:
|
|
1203
|
-
reconciliationRequired:
|
|
1364
|
+
cancelCommitted: z3.literal(false),
|
|
1365
|
+
reconciliationRequired: z3.literal(true)
|
|
1204
1366
|
}).strict()
|
|
1205
1367
|
]);
|
|
1206
|
-
var resolveCancelRefundOutcomeSchema =
|
|
1207
|
-
var resolveCancelRefundSchema =
|
|
1208
|
-
orderNumber:
|
|
1368
|
+
var resolveCancelRefundOutcomeSchema = z3.enum(["succeeded", "failed"]);
|
|
1369
|
+
var resolveCancelRefundSchema = z3.object({
|
|
1370
|
+
orderNumber: z3.string().min(1, "orderNumber is required").describe("Order number whose pending cancel refund is being resolved"),
|
|
1209
1371
|
idempotencyKey: idempotencyKeySchema.describe(
|
|
1210
1372
|
"Stable key for this PG refund result report"
|
|
1211
1373
|
),
|
|
1212
1374
|
outcome: resolveCancelRefundOutcomeSchema.describe(
|
|
1213
1375
|
"PG refund result reported by the storefront or BFF"
|
|
1214
1376
|
),
|
|
1215
|
-
refundedAmount:
|
|
1216
|
-
pgProvider:
|
|
1377
|
+
refundedAmount: z3.number().int("refundedAmount must be an integer minor-unit amount").nonnegative("refundedAmount must be nonnegative"),
|
|
1378
|
+
pgProvider: z3.string().trim().min(1, "pgProvider is required").regex(
|
|
1217
1379
|
/^[a-z0-9][a-z0-9_-]*$/,
|
|
1218
1380
|
"pgProvider must be a lowercase provider slug"
|
|
1219
1381
|
),
|
|
1220
|
-
pgRefundId:
|
|
1382
|
+
pgRefundId: z3.string().trim().min(1).optional()
|
|
1221
1383
|
}).strict().superRefine((value, ctx) => {
|
|
1222
1384
|
if (value.outcome === "succeeded" && value.refundedAmount <= 0) {
|
|
1223
1385
|
ctx.addIssue({
|
|
1224
|
-
code:
|
|
1386
|
+
code: z3.ZodIssueCode.custom,
|
|
1225
1387
|
path: ["refundedAmount"],
|
|
1226
1388
|
message: "refundedAmount must be positive when outcome is succeeded"
|
|
1227
1389
|
});
|
|
1228
1390
|
}
|
|
1229
1391
|
if (value.outcome === "succeeded" && !value.pgRefundId) {
|
|
1230
1392
|
ctx.addIssue({
|
|
1231
|
-
code:
|
|
1393
|
+
code: z3.ZodIssueCode.custom,
|
|
1232
1394
|
path: ["pgRefundId"],
|
|
1233
1395
|
message: "pgRefundId is required when outcome is succeeded"
|
|
1234
1396
|
});
|
|
1235
1397
|
}
|
|
1236
1398
|
if (value.outcome === "failed" && value.refundedAmount !== 0) {
|
|
1237
1399
|
ctx.addIssue({
|
|
1238
|
-
code:
|
|
1400
|
+
code: z3.ZodIssueCode.custom,
|
|
1239
1401
|
path: ["refundedAmount"],
|
|
1240
1402
|
message: "refundedAmount must be 0 when outcome is failed"
|
|
1241
1403
|
});
|
|
1242
1404
|
}
|
|
1243
1405
|
});
|
|
1244
|
-
var resolveCancelRefundResponseSchema =
|
|
1245
|
-
|
|
1246
|
-
orderId:
|
|
1247
|
-
transactionId:
|
|
1248
|
-
refundTransactionId:
|
|
1249
|
-
refundedAmount:
|
|
1250
|
-
refundStatus:
|
|
1251
|
-
transactionStatus:
|
|
1406
|
+
var resolveCancelRefundResponseSchema = z3.union([
|
|
1407
|
+
z3.object({
|
|
1408
|
+
orderId: z3.string().min(1),
|
|
1409
|
+
transactionId: z3.string().min(1),
|
|
1410
|
+
refundTransactionId: z3.string().min(1),
|
|
1411
|
+
refundedAmount: z3.number().int().positive(),
|
|
1412
|
+
refundStatus: z3.literal("succeeded"),
|
|
1413
|
+
transactionStatus: z3.literal("refunded")
|
|
1252
1414
|
}).strict(),
|
|
1253
|
-
|
|
1254
|
-
orderId:
|
|
1255
|
-
transactionId:
|
|
1256
|
-
refundTransactionId:
|
|
1257
|
-
refundedAmount:
|
|
1258
|
-
refundStatus:
|
|
1259
|
-
transactionStatus:
|
|
1415
|
+
z3.object({
|
|
1416
|
+
orderId: z3.string().min(1),
|
|
1417
|
+
transactionId: z3.string().min(1),
|
|
1418
|
+
refundTransactionId: z3.string().min(1),
|
|
1419
|
+
refundedAmount: z3.literal(0),
|
|
1420
|
+
refundStatus: z3.literal("failed"),
|
|
1421
|
+
transactionStatus: z3.literal("paid")
|
|
1260
1422
|
}).strict()
|
|
1261
1423
|
]);
|
|
1262
1424
|
|
|
1263
1425
|
// src/commands/order.ts
|
|
1264
|
-
import { z as
|
|
1265
|
-
var idSchema =
|
|
1266
|
-
var customerSnapshotSchema =
|
|
1267
|
-
email:
|
|
1268
|
-
name:
|
|
1269
|
-
phone:
|
|
1426
|
+
import { z as z4 } from "zod";
|
|
1427
|
+
var idSchema = z4.union([z4.string().min(1), z4.number()]).transform(String);
|
|
1428
|
+
var customerSnapshotSchema = z4.object({
|
|
1429
|
+
email: z4.string().email("Invalid email format"),
|
|
1430
|
+
name: z4.string().optional(),
|
|
1431
|
+
phone: z4.string().optional()
|
|
1270
1432
|
}).strict();
|
|
1271
|
-
var orderStatusSchema2 =
|
|
1272
|
-
var fulfillmentStatusSchema =
|
|
1273
|
-
var updateFulfillmentSchema =
|
|
1433
|
+
var orderStatusSchema2 = z4.enum(["confirmed"]);
|
|
1434
|
+
var fulfillmentStatusSchema = z4.enum(["shipped", "delivered", "failed"]);
|
|
1435
|
+
var updateFulfillmentSchema = z4.object({
|
|
1274
1436
|
fulfillmentId: idSchema,
|
|
1275
1437
|
status: fulfillmentStatusSchema.optional(),
|
|
1276
|
-
carrier:
|
|
1277
|
-
trackingNumber:
|
|
1438
|
+
carrier: z4.string().min(1).optional(),
|
|
1439
|
+
trackingNumber: z4.string().min(1).optional()
|
|
1278
1440
|
}).refine(
|
|
1279
1441
|
(value) => value.status !== void 0 || value.carrier !== void 0 || value.trackingNumber !== void 0,
|
|
1280
1442
|
{
|
|
1281
1443
|
message: "status, carrier, or trackingNumber is required"
|
|
1282
1444
|
}
|
|
1283
1445
|
);
|
|
1284
|
-
var fulfillmentItemsSchema =
|
|
1285
|
-
|
|
1446
|
+
var fulfillmentItemsSchema = z4.array(
|
|
1447
|
+
z4.object({
|
|
1286
1448
|
orderItem: idSchema,
|
|
1287
|
-
quantity:
|
|
1449
|
+
quantity: z4.number().int().positive("quantity must be a positive integer")
|
|
1288
1450
|
}).strict()
|
|
1289
1451
|
).min(1, "At least one fulfillment item is required").max(100, "Maximum 100 items per fulfillment");
|
|
1290
1452
|
function registerOrderCommands(program2, getClient2, getFormat2) {
|
|
@@ -1361,6 +1523,34 @@ function registerOrderCommands(program2, getClient2, getFormat2) {
|
|
|
1361
1523
|
exitWithError(e);
|
|
1362
1524
|
}
|
|
1363
1525
|
});
|
|
1526
|
+
order.command("cancel <orderNumber>").description("Cancel an eligible order").option(
|
|
1527
|
+
"--reason-code <code>",
|
|
1528
|
+
"Cancel reason (customer, inventory, fraud, declined, staff, other)"
|
|
1529
|
+
).option("--reason-detail <text>", "Internal cancellation detail").option("--dry-run", "Validate inputs without executing").action(async (orderNumber, opts) => {
|
|
1530
|
+
try {
|
|
1531
|
+
const data = parseWithSchema(
|
|
1532
|
+
{
|
|
1533
|
+
orderNumber,
|
|
1534
|
+
...opts.reasonCode ? { reasonCode: opts.reasonCode } : {},
|
|
1535
|
+
...opts.reasonDetail ? { reasonDetail: opts.reasonDetail } : {}
|
|
1536
|
+
},
|
|
1537
|
+
"cancel",
|
|
1538
|
+
cancelOrderSchema
|
|
1539
|
+
);
|
|
1540
|
+
if (opts.dryRun) {
|
|
1541
|
+
printResult(
|
|
1542
|
+
{ dryRun: true, valid: true, action: "order cancel", data },
|
|
1543
|
+
getFormat2()
|
|
1544
|
+
);
|
|
1545
|
+
return;
|
|
1546
|
+
}
|
|
1547
|
+
const client = getClient2();
|
|
1548
|
+
const result = await client.commerce.orders.cancelOrder(data);
|
|
1549
|
+
printResult(result, getFormat2());
|
|
1550
|
+
} catch (e) {
|
|
1551
|
+
exitWithError(e);
|
|
1552
|
+
}
|
|
1553
|
+
});
|
|
1364
1554
|
order.command("checkout").description("Convert a cart to an order").requiredOption("--cart-id <id>", "Cart ID").option("--payment-id <id>", "Payment ID (optional for free orders)").requiredOption("--order-number <num>", "Order number").requiredOption("--customer <json>", "Customer snapshot (JSON)").option("--dry-run", "Validate inputs without executing").action(async (opts) => {
|
|
1365
1555
|
try {
|
|
1366
1556
|
const customerSnapshot = parseWithSchema(
|
|
@@ -1474,8 +1664,8 @@ function registerOrderCommands(program2, getClient2, getFormat2) {
|
|
|
1474
1664
|
}
|
|
1475
1665
|
|
|
1476
1666
|
// src/commands/return.ts
|
|
1477
|
-
import { z as
|
|
1478
|
-
var returnStatusSchema =
|
|
1667
|
+
import { z as z5 } from "zod";
|
|
1668
|
+
var returnStatusSchema = z5.enum([
|
|
1479
1669
|
"processing",
|
|
1480
1670
|
"approved",
|
|
1481
1671
|
"rejected",
|
|
@@ -1676,6 +1866,60 @@ function registerCartCommands(program2, getClient2, getFormat2) {
|
|
|
1676
1866
|
exitWithError(e);
|
|
1677
1867
|
}
|
|
1678
1868
|
});
|
|
1869
|
+
cart.command("clear <cartId>").description("Remove all items from a cart").option("--dry-run", "Validate inputs without executing").action(async (cartId, opts) => {
|
|
1870
|
+
try {
|
|
1871
|
+
if (opts.dryRun) {
|
|
1872
|
+
printResult(
|
|
1873
|
+
{ dryRun: true, valid: true, action: "cart clear", data: { cartId } },
|
|
1874
|
+
getFormat2()
|
|
1875
|
+
);
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1878
|
+
const client = getClient2();
|
|
1879
|
+
const result = await client.commerce.cart.clear({ cartId });
|
|
1880
|
+
printResult(result, getFormat2());
|
|
1881
|
+
} catch (e) {
|
|
1882
|
+
exitWithError(e);
|
|
1883
|
+
}
|
|
1884
|
+
});
|
|
1885
|
+
cart.command("apply-discount <cartId>").description("Apply a discount code to a cart").requiredOption("--code <code>", "Discount code").option("--dry-run", "Validate inputs without executing").action(async (cartId, opts) => {
|
|
1886
|
+
try {
|
|
1887
|
+
const data = { cartId, discountCode: opts.code };
|
|
1888
|
+
if (opts.dryRun) {
|
|
1889
|
+
printResult(
|
|
1890
|
+
{ dryRun: true, valid: true, action: "cart apply-discount", data },
|
|
1891
|
+
getFormat2()
|
|
1892
|
+
);
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
const client = getClient2();
|
|
1896
|
+
const result = await client.commerce.cart.applyDiscount(data);
|
|
1897
|
+
printResult(result, getFormat2());
|
|
1898
|
+
} catch (e) {
|
|
1899
|
+
exitWithError(e);
|
|
1900
|
+
}
|
|
1901
|
+
});
|
|
1902
|
+
cart.command("remove-discount <cartId>").description("Remove the discount from a cart").option("--dry-run", "Validate inputs without executing").action(async (cartId, opts) => {
|
|
1903
|
+
try {
|
|
1904
|
+
if (opts.dryRun) {
|
|
1905
|
+
printResult(
|
|
1906
|
+
{
|
|
1907
|
+
dryRun: true,
|
|
1908
|
+
valid: true,
|
|
1909
|
+
action: "cart remove-discount",
|
|
1910
|
+
data: { cartId }
|
|
1911
|
+
},
|
|
1912
|
+
getFormat2()
|
|
1913
|
+
);
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1916
|
+
const client = getClient2();
|
|
1917
|
+
const result = await client.commerce.cart.removeDiscount({ cartId });
|
|
1918
|
+
printResult(result, getFormat2());
|
|
1919
|
+
} catch (e) {
|
|
1920
|
+
exitWithError(e);
|
|
1921
|
+
}
|
|
1922
|
+
});
|
|
1679
1923
|
}
|
|
1680
1924
|
|
|
1681
1925
|
// src/commands/stock.ts
|
|
@@ -1697,14 +1941,31 @@ function registerStockCommands(program2, getClient2, getFormat2) {
|
|
|
1697
1941
|
}
|
|
1698
1942
|
|
|
1699
1943
|
// src/commands/transaction.ts
|
|
1700
|
-
import { z as
|
|
1701
|
-
var transactionAmountSchema =
|
|
1702
|
-
amount:
|
|
1944
|
+
import { z as z6 } from "zod";
|
|
1945
|
+
var transactionAmountSchema = z6.object({
|
|
1946
|
+
amount: z6.string().regex(/^[1-9]\d*$/, "amount must be a positive integer").transform(Number)
|
|
1947
|
+
});
|
|
1948
|
+
var confirmPaymentAmountSchema = z6.object({
|
|
1949
|
+
amount: z6.string().regex(/^(0|[1-9]\d*)$/, "amount must be a non-negative integer").transform(Number)
|
|
1950
|
+
});
|
|
1951
|
+
var idempotencyKeyOptionSchema = z6.object({
|
|
1952
|
+
idempotencyKey: idempotencyKeySchema
|
|
1703
1953
|
});
|
|
1704
1954
|
function parseTransactionAmount(value) {
|
|
1705
1955
|
if (value === void 0) return void 0;
|
|
1706
1956
|
return parseWithSchema({ amount: value }, "amount", transactionAmountSchema).amount;
|
|
1707
1957
|
}
|
|
1958
|
+
function parseConfirmPaymentAmount(value) {
|
|
1959
|
+
return parseWithSchema({ amount: value }, "amount", confirmPaymentAmountSchema).amount;
|
|
1960
|
+
}
|
|
1961
|
+
function parseIdempotencyKey(value) {
|
|
1962
|
+
if (value === void 0) return void 0;
|
|
1963
|
+
return parseWithSchema(
|
|
1964
|
+
{ idempotencyKey: value },
|
|
1965
|
+
"idempotencyKey",
|
|
1966
|
+
idempotencyKeyOptionSchema
|
|
1967
|
+
).idempotencyKey;
|
|
1968
|
+
}
|
|
1708
1969
|
function registerTransactionCommands(program2, getClient2, getFormat2) {
|
|
1709
1970
|
const tx = program2.command("transaction").description("Transaction management");
|
|
1710
1971
|
tx.command("update").description("Update transaction status").requiredOption("--payment-id <id>", "Payment ID").requiredOption(
|
|
@@ -1738,6 +1999,132 @@ function registerTransactionCommands(program2, getClient2, getFormat2) {
|
|
|
1738
1999
|
exitWithError(e);
|
|
1739
2000
|
}
|
|
1740
2001
|
});
|
|
2002
|
+
tx.command("confirm-payment").description("Confirm a provider-verified payment for an order").requiredOption("--payment-id <id>", "Provider payment identifier (pgPaymentId)").requiredOption(
|
|
2003
|
+
"--provider <slug>",
|
|
2004
|
+
"Payment provider slug (toss, portone, stripe, ...)"
|
|
2005
|
+
).requiredOption(
|
|
2006
|
+
"--amount <n>",
|
|
2007
|
+
"Provider-confirmed amount in minor units"
|
|
2008
|
+
).option("--order-number <num>", "Order number").option("--pg-order-id <id>", "Provider order id").option("--currency <code>", "Currency code").option("--payment-method <method>", "Payment method").option("--receipt-url <url>", "Receipt URL").option("--approved-at <ts>", "Provider approval timestamp").option("--provider-status <status>", "Provider status").option("--provider-event-id <id>", "Provider event id (idempotency)").option("--idempotency-key <key>", "Idempotency key header override").option(
|
|
2009
|
+
"--confirmation-source <src>",
|
|
2010
|
+
"provider_webhook | provider_lookup | provider_api_confirm | manual_server"
|
|
2011
|
+
).option("--payment-key <key>", "Provider payment key").option("--dry-run", "Validate inputs without executing").action(async (opts) => {
|
|
2012
|
+
try {
|
|
2013
|
+
const data = parseWithSchema(
|
|
2014
|
+
{
|
|
2015
|
+
pgPaymentId: opts.paymentId,
|
|
2016
|
+
pgProvider: opts.provider,
|
|
2017
|
+
amount: parseConfirmPaymentAmount(opts.amount),
|
|
2018
|
+
...opts.orderNumber ? { orderNumber: opts.orderNumber } : {},
|
|
2019
|
+
...opts.pgOrderId ? { pgOrderId: opts.pgOrderId } : {},
|
|
2020
|
+
...opts.currency ? { currency: opts.currency } : {},
|
|
2021
|
+
...opts.paymentMethod ? { paymentMethod: opts.paymentMethod } : {},
|
|
2022
|
+
...opts.receiptUrl ? { receiptUrl: opts.receiptUrl } : {},
|
|
2023
|
+
...opts.approvedAt ? { approvedAt: opts.approvedAt } : {},
|
|
2024
|
+
...opts.providerStatus ? { providerStatus: opts.providerStatus } : {},
|
|
2025
|
+
...opts.providerEventId ? { providerEventId: opts.providerEventId } : {},
|
|
2026
|
+
...opts.confirmationSource ? { confirmationSource: opts.confirmationSource } : {},
|
|
2027
|
+
...opts.paymentKey ? { paymentKey: opts.paymentKey } : {}
|
|
2028
|
+
},
|
|
2029
|
+
"confirm-payment",
|
|
2030
|
+
confirmPaymentSchema
|
|
2031
|
+
);
|
|
2032
|
+
const sdkParams = {
|
|
2033
|
+
...data,
|
|
2034
|
+
...opts.idempotencyKey !== void 0 ? { idempotencyKey: parseIdempotencyKey(opts.idempotencyKey) } : {}
|
|
2035
|
+
};
|
|
2036
|
+
if (opts.dryRun) {
|
|
2037
|
+
printResult(
|
|
2038
|
+
{
|
|
2039
|
+
dryRun: true,
|
|
2040
|
+
valid: true,
|
|
2041
|
+
action: "transaction confirm-payment",
|
|
2042
|
+
data: sdkParams
|
|
2043
|
+
},
|
|
2044
|
+
getFormat2()
|
|
2045
|
+
);
|
|
2046
|
+
return;
|
|
2047
|
+
}
|
|
2048
|
+
const client = getClient2();
|
|
2049
|
+
const result = await client.commerce.orders.confirmPayment(
|
|
2050
|
+
sdkParams
|
|
2051
|
+
);
|
|
2052
|
+
printResult(result, getFormat2());
|
|
2053
|
+
} catch (e) {
|
|
2054
|
+
exitWithError(e);
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
// src/commands/product.ts
|
|
2060
|
+
function registerProductCommands(program2, getClient2, getFormat2) {
|
|
2061
|
+
const product = program2.command("product").description("Product management");
|
|
2062
|
+
product.command("upsert").description("Create or update a product graph (options, values, variants)").requiredOption("--input <json>", "Product upsert input (JSON)").option("--dry-run", "Validate inputs without executing").action(async (opts) => {
|
|
2063
|
+
try {
|
|
2064
|
+
const data = parseWithSchema(
|
|
2065
|
+
parseJson(opts.input, "input"),
|
|
2066
|
+
"input",
|
|
2067
|
+
ProductUpsertSchema
|
|
2068
|
+
);
|
|
2069
|
+
if (opts.dryRun) {
|
|
2070
|
+
printResult(
|
|
2071
|
+
{ dryRun: true, valid: true, action: "product upsert", data },
|
|
2072
|
+
getFormat2()
|
|
2073
|
+
);
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
const client = getClient2();
|
|
2077
|
+
const result = await client.commerce.product.upsert(
|
|
2078
|
+
data
|
|
2079
|
+
);
|
|
2080
|
+
printResult(result, getFormat2());
|
|
2081
|
+
} catch (e) {
|
|
2082
|
+
exitWithError(e);
|
|
2083
|
+
}
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
// src/commands/discount.ts
|
|
2088
|
+
function registerDiscountCommands(program2, getClient2, getFormat2) {
|
|
2089
|
+
const discount = program2.command("discount").description("Discount management");
|
|
2090
|
+
discount.command("validate").description("Validate a discount code against an order amount").requiredOption("--code <code>", "Discount code").requiredOption(
|
|
2091
|
+
"--order-amount <n>",
|
|
2092
|
+
"Order amount",
|
|
2093
|
+
(v) => parseInt(v, 10)
|
|
2094
|
+
).action(async (opts) => {
|
|
2095
|
+
try {
|
|
2096
|
+
const client = getClient2();
|
|
2097
|
+
const result = await client.commerce.discounts.validate({
|
|
2098
|
+
code: opts.code,
|
|
2099
|
+
orderAmount: opts.orderAmount
|
|
2100
|
+
});
|
|
2101
|
+
printResult(result, getFormat2());
|
|
2102
|
+
} catch (e) {
|
|
2103
|
+
exitWithError(e);
|
|
2104
|
+
}
|
|
2105
|
+
});
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
// src/commands/shipping.ts
|
|
2109
|
+
function registerShippingCommands(program2, getClient2, getFormat2) {
|
|
2110
|
+
const shipping = program2.command("shipping").description("Shipping calculation");
|
|
2111
|
+
shipping.command("calculate").description("Calculate shipping for an order amount").requiredOption(
|
|
2112
|
+
"--order-amount <n>",
|
|
2113
|
+
"Order amount",
|
|
2114
|
+
(v) => parseInt(v, 10)
|
|
2115
|
+
).option("--shipping-policy-id <id>", "Shipping policy ID").option("--postal-code <code>", "Destination postal code").action(async (opts) => {
|
|
2116
|
+
try {
|
|
2117
|
+
const client = getClient2();
|
|
2118
|
+
const result = await client.commerce.shipping.calculate({
|
|
2119
|
+
orderAmount: opts.orderAmount,
|
|
2120
|
+
...opts.shippingPolicyId ? { shippingPolicyId: opts.shippingPolicyId } : {},
|
|
2121
|
+
...opts.postalCode ? { postalCode: opts.postalCode } : {}
|
|
2122
|
+
});
|
|
2123
|
+
printResult(result, getFormat2());
|
|
2124
|
+
} catch (e) {
|
|
2125
|
+
exitWithError(e);
|
|
2126
|
+
}
|
|
2127
|
+
});
|
|
1741
2128
|
}
|
|
1742
2129
|
|
|
1743
2130
|
// src/commands/auth.ts
|
|
@@ -1832,7 +2219,7 @@ async function exchangeCode(code) {
|
|
|
1832
2219
|
}
|
|
1833
2220
|
}
|
|
1834
2221
|
function startAuthServer(options) {
|
|
1835
|
-
return new Promise((
|
|
2222
|
+
return new Promise((resolve2, reject) => {
|
|
1836
2223
|
const server = createServer((req, res) => {
|
|
1837
2224
|
if (!req.url) {
|
|
1838
2225
|
res.writeHead(400).end();
|
|
@@ -1907,7 +2294,7 @@ Logged in successfully!`));
|
|
|
1907
2294
|
);
|
|
1908
2295
|
cleanup(4);
|
|
1909
2296
|
}, TIMEOUT_MS);
|
|
1910
|
-
|
|
2297
|
+
resolve2({ port: addr.port, cleanup });
|
|
1911
2298
|
});
|
|
1912
2299
|
server.on("error", (err) => {
|
|
1913
2300
|
reject(err);
|
|
@@ -2046,25 +2433,17 @@ ${loginUrl}`));
|
|
|
2046
2433
|
}
|
|
2047
2434
|
|
|
2048
2435
|
// src/commands/schema.ts
|
|
2049
|
-
import {
|
|
2436
|
+
import { SERVER_COLLECTIONS as SERVER_COLLECTIONS2 } from "@01.software/sdk";
|
|
2050
2437
|
function registerSchemaCommands(program2, getClient2, getFormat2) {
|
|
2051
2438
|
const schema = program2.command("schema").description("Collection schema introspection");
|
|
2052
2439
|
schema.command("list").description("List available collections").action(() => {
|
|
2053
|
-
printResult(
|
|
2440
|
+
printResult(SERVER_COLLECTIONS2, getFormat2());
|
|
2054
2441
|
});
|
|
2055
2442
|
schema.command("show <collection>").description("Show collection field schema").action(async (collection) => {
|
|
2056
2443
|
try {
|
|
2057
|
-
|
|
2058
|
-
const normalized = collection.replace(/-/g, "").toLowerCase();
|
|
2059
|
-
const suggestions = COLLECTIONS2.filter((c) => {
|
|
2060
|
-
const cn = c.replace(/-/g, "").toLowerCase();
|
|
2061
|
-
return cn.startsWith(normalized) || normalized.startsWith(cn) || normalized.length >= 3 && cn.includes(normalized);
|
|
2062
|
-
}).slice(0, 5);
|
|
2063
|
-
const hint = suggestions.length > 0 ? `Did you mean: ${suggestions.join(", ")}?` : 'Run "01 schema list" for available collections.';
|
|
2064
|
-
throw new Error(`Unknown collection "${collection}". ${hint}`);
|
|
2065
|
-
}
|
|
2444
|
+
const col = validateCollection(collection);
|
|
2066
2445
|
const client = getClient2();
|
|
2067
|
-
const result = await client.tenant.collectionSchema(
|
|
2446
|
+
const result = await client.tenant.collectionSchema(col);
|
|
2068
2447
|
printResult(result, getFormat2());
|
|
2069
2448
|
} catch (e) {
|
|
2070
2449
|
exitWithError(e);
|
|
@@ -2111,98 +2490,8 @@ function registerFeatureCommands(program2, getClient2, getFormat2) {
|
|
|
2111
2490
|
});
|
|
2112
2491
|
}
|
|
2113
2492
|
|
|
2114
|
-
// src/commands/mcp.ts
|
|
2115
|
-
import { resolve, dirname } from "path";
|
|
2116
|
-
import { existsSync as existsSync2 } from "fs";
|
|
2117
|
-
import { spawn } from "child_process";
|
|
2118
|
-
import { fileURLToPath } from "url";
|
|
2119
|
-
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
2120
|
-
function getStdioEntryCandidates(baseDir = __dirname) {
|
|
2121
|
-
const candidates = [
|
|
2122
|
-
{
|
|
2123
|
-
label: "packaged CLI artifact",
|
|
2124
|
-
path: resolve(baseDir, "mcp/stdio.js")
|
|
2125
|
-
}
|
|
2126
|
-
];
|
|
2127
|
-
const roots = ["../../../..", "../../..", "../.."];
|
|
2128
|
-
const entries = [
|
|
2129
|
-
{
|
|
2130
|
-
label: "monorepo build output",
|
|
2131
|
-
path: "apps/mcp/dist/stdio.js"
|
|
2132
|
-
},
|
|
2133
|
-
{
|
|
2134
|
-
label: "xmcp build output",
|
|
2135
|
-
path: "apps/mcp/.xmcp/stdio.js"
|
|
2136
|
-
}
|
|
2137
|
-
];
|
|
2138
|
-
for (const entry of entries) {
|
|
2139
|
-
for (const root of roots) {
|
|
2140
|
-
candidates.push({
|
|
2141
|
-
label: entry.label,
|
|
2142
|
-
path: resolve(baseDir, root, entry.path)
|
|
2143
|
-
});
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
return candidates;
|
|
2147
|
-
}
|
|
2148
|
-
function findStdioEntry(baseDir = __dirname) {
|
|
2149
|
-
for (const candidate of getStdioEntryCandidates(baseDir)) {
|
|
2150
|
-
if (existsSync2(candidate.path)) return candidate.path;
|
|
2151
|
-
}
|
|
2152
|
-
return null;
|
|
2153
|
-
}
|
|
2154
|
-
function formatMissingStdioEntryMessage(baseDir = __dirname) {
|
|
2155
|
-
const checked = getStdioEntryCandidates(baseDir).map((candidate) => ` - ${candidate.label}: ${candidate.path}`).join("\n");
|
|
2156
|
-
return [
|
|
2157
|
-
"MCP stdio entry not found.",
|
|
2158
|
-
"Checked:",
|
|
2159
|
-
checked,
|
|
2160
|
-
"Fix:",
|
|
2161
|
-
" - Monorepo checkout: run pnpm --filter mcp build.",
|
|
2162
|
-
" - Published CLI: reinstall or update @01.software/cli so dist/mcp/stdio.js is included."
|
|
2163
|
-
].join("\n");
|
|
2164
|
-
}
|
|
2165
|
-
function createMcpEnv(baseEnv, client) {
|
|
2166
|
-
const env = {
|
|
2167
|
-
...baseEnv,
|
|
2168
|
-
SOFTWARE_PUBLISHABLE_KEY: client.publishableKey,
|
|
2169
|
-
SOFTWARE_SECRET_KEY: client.secretKey
|
|
2170
|
-
};
|
|
2171
|
-
delete env.SOFTWARE_TENANT_ID;
|
|
2172
|
-
return env;
|
|
2173
|
-
}
|
|
2174
|
-
function registerMcpCommands(program2) {
|
|
2175
|
-
program2.command("mcp").description("Start local MCP stdio server for trusted server-key workflows").addHelpText(
|
|
2176
|
-
"after",
|
|
2177
|
-
`
|
|
2178
|
-
Prerequisites:
|
|
2179
|
-
Run 01 login, or set SOFTWARE_PUBLISHABLE_KEY and SOFTWARE_SECRET_KEY.
|
|
2180
|
-
Local stdio exposes the full MCP tool surface; HTTP OAuth MCP uses the
|
|
2181
|
-
narrower remote surface documented in the web integration guide.
|
|
2182
|
-
In a monorepo checkout, build the stdio artifact first:
|
|
2183
|
-
pnpm --filter mcp build
|
|
2184
|
-
`
|
|
2185
|
-
).action(() => {
|
|
2186
|
-
const client = resolveClient(program2.opts().apiKey);
|
|
2187
|
-
const stdioEntry = findStdioEntry();
|
|
2188
|
-
if (!stdioEntry) {
|
|
2189
|
-
exitWithError(new Error(formatMissingStdioEntryMessage()));
|
|
2190
|
-
}
|
|
2191
|
-
const child = spawn(process.execPath, [stdioEntry], {
|
|
2192
|
-
env: createMcpEnv(process.env, client),
|
|
2193
|
-
stdio: ["inherit", "inherit", "inherit"]
|
|
2194
|
-
});
|
|
2195
|
-
child.on("error", (err) => {
|
|
2196
|
-
exitWithError(new Error(`Failed to start MCP server: ${err.message}`));
|
|
2197
|
-
});
|
|
2198
|
-
child.on("exit", (code) => {
|
|
2199
|
-
process.exit(code ?? 0);
|
|
2200
|
-
});
|
|
2201
|
-
});
|
|
2202
|
-
}
|
|
2203
|
-
|
|
2204
2493
|
// src/commands/agent.ts
|
|
2205
|
-
import {
|
|
2494
|
+
import { SERVER_COLLECTIONS as SERVER_COLLECTIONS3 } from "@01.software/sdk";
|
|
2206
2495
|
|
|
2207
2496
|
// src/lib/agent-output.ts
|
|
2208
2497
|
var PLAN_AGENT_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
@@ -2366,7 +2655,7 @@ function hashAgentPlanEnvelope(input) {
|
|
|
2366
2655
|
}
|
|
2367
2656
|
|
|
2368
2657
|
// src/lib/agent-plan-id.ts
|
|
2369
|
-
import { resolve
|
|
2658
|
+
import { resolve, sep } from "path";
|
|
2370
2659
|
var PLAN_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
2371
2660
|
function assertValidPlanId(planId) {
|
|
2372
2661
|
if (!PLAN_ID_PATTERN.test(planId)) {
|
|
@@ -2375,8 +2664,8 @@ function assertValidPlanId(planId) {
|
|
|
2375
2664
|
}
|
|
2376
2665
|
function safePlanPath(planDir, planId) {
|
|
2377
2666
|
assertValidPlanId(planId);
|
|
2378
|
-
const resolvedDir =
|
|
2379
|
-
const resolvedPath =
|
|
2667
|
+
const resolvedDir = resolve(planDir);
|
|
2668
|
+
const resolvedPath = resolve(resolvedDir, `${planId}.json`);
|
|
2380
2669
|
if (resolvedPath !== resolvedDir && !resolvedPath.startsWith(`${resolvedDir}${sep}`)) {
|
|
2381
2670
|
throw agentPlanError("INVALID_INPUT", "Invalid plan token.");
|
|
2382
2671
|
}
|
|
@@ -2987,7 +3276,10 @@ function parseWhere(value) {
|
|
|
2987
3276
|
}
|
|
2988
3277
|
throw invalidInput2("--where must be a JSON object", "where", value);
|
|
2989
3278
|
}
|
|
2990
|
-
var AGENT_READ_OPERATIONS = [
|
|
3279
|
+
var AGENT_READ_OPERATIONS = [
|
|
3280
|
+
"query",
|
|
3281
|
+
"get"
|
|
3282
|
+
];
|
|
2991
3283
|
var AGENT_PLAN_OPERATIONS = [
|
|
2992
3284
|
"plan:create",
|
|
2993
3285
|
"plan:update",
|
|
@@ -2995,7 +3287,7 @@ var AGENT_PLAN_OPERATIONS = [
|
|
|
2995
3287
|
];
|
|
2996
3288
|
function buildAgentManifest() {
|
|
2997
3289
|
const collections = {};
|
|
2998
|
-
for (const collection of
|
|
3290
|
+
for (const collection of SERVER_COLLECTIONS3) {
|
|
2999
3291
|
const operations = isAgentPlanCollection(collection) ? [...AGENT_READ_OPERATIONS, ...AGENT_PLAN_OPERATIONS] : [...AGENT_READ_OPERATIONS];
|
|
3000
3292
|
collections[collection] = {
|
|
3001
3293
|
operations,
|
|
@@ -3024,7 +3316,9 @@ function registerAgentCommands(program2, getClient2) {
|
|
|
3024
3316
|
);
|
|
3025
3317
|
configureAgentParser2(
|
|
3026
3318
|
agent.command("manifest").description("Print the Agent CLI protocol manifest").option("--pretty", "Print 2-space indented JSON").action((opts) => {
|
|
3027
|
-
printAgentSuccess(buildAgentManifest(), {
|
|
3319
|
+
printAgentSuccess(buildAgentManifest(), {
|
|
3320
|
+
pretty: Boolean(opts.pretty)
|
|
3321
|
+
});
|
|
3028
3322
|
})
|
|
3029
3323
|
);
|
|
3030
3324
|
configureAgentParser2(
|
|
@@ -3095,9 +3389,11 @@ registerReturnCommands(program, getClient, getFormat);
|
|
|
3095
3389
|
registerCartCommands(program, getClient, getFormat);
|
|
3096
3390
|
registerStockCommands(program, getClient, getFormat);
|
|
3097
3391
|
registerTransactionCommands(program, getClient, getFormat);
|
|
3392
|
+
registerProductCommands(program, getClient, getFormat);
|
|
3393
|
+
registerDiscountCommands(program, getClient, getFormat);
|
|
3394
|
+
registerShippingCommands(program, getClient, getFormat);
|
|
3098
3395
|
registerSchemaCommands(program, getClient, getFormat);
|
|
3099
3396
|
registerFeatureCommands(program, getClient, getFormat);
|
|
3100
|
-
registerMcpCommands(program);
|
|
3101
3397
|
registerAuthCommands(program);
|
|
3102
3398
|
program.parse();
|
|
3103
3399
|
//# sourceMappingURL=index.js.map
|