@yoryoboy/bi-mcp 1.14.0 → 1.14.3
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/.tsbuildinfo +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp-use.json +2 -2
- package/dist/src/services/vtex/__tests__/vtex-catalog.test.js +2 -5
- package/dist/src/services/vtex/__tests__/vtex-catalog.test.js.map +2 -2
- package/dist/src/services/vtex/__tests__/vtex-payments.test.js +12 -9
- package/dist/src/services/vtex/__tests__/vtex-payments.test.js.map +2 -2
- package/dist/src/services/vtex/vtex-catalog.js +1 -1
- package/dist/src/services/vtex/vtex-catalog.js.map +2 -2
- package/dist/src/services/vtex/vtex-payments.js +11 -5
- package/dist/src/services/vtex/vtex-payments.js.map +2 -2
- package/dist/src/tools/vtex/__tests__/catalog-navigation-reads.test.js +21 -2
- package/dist/src/tools/vtex/__tests__/catalog-navigation-reads.test.js.map +2 -2
- package/dist/src/tools/vtex/__tests__/commercial-conditions.test.js +4 -173
- package/dist/src/tools/vtex/__tests__/commercial-conditions.test.js.map +2 -2
- package/dist/src/tools/vtex/__tests__/payment-rules.test.js +1 -0
- package/dist/src/tools/vtex/__tests__/payment-rules.test.js.map +2 -2
- package/dist/src/tools/vtex/catalog-admin-products-skus.js +1 -1
- package/dist/src/tools/vtex/catalog-admin-products-skus.js.map +1 -1
- package/dist/src/tools/vtex/catalog-navigation-reads.js +1 -1
- package/dist/src/tools/vtex/catalog-navigation-reads.js.map +2 -2
- package/dist/src/tools/vtex/commercial-conditions.js +35 -150
- package/dist/src/tools/vtex/commercial-conditions.js.map +2 -2
- package/dist/src/tools/vtex/create-sku.js +1 -1
- package/dist/src/tools/vtex/create-sku.js.map +1 -1
- package/dist/src/tools/vtex/payment-rules.js +81 -38
- package/dist/src/tools/vtex/payment-rules.js.map +2 -2
- package/dist/tests/vtex/vtex-commercial-conditions-docs.test.js +12 -4
- package/dist/tests/vtex/vtex-commercial-conditions-docs.test.js.map +2 -2
- package/dist/tests/vtex/vtex-commercial-conditions-surface.test.js +121 -12
- package/dist/tests/vtex/vtex-commercial-conditions-surface.test.js.map +2 -2
- package/dist/tests/vtex/vtex-commercial-conditions-workflow.test.js +15 -23
- package/dist/tests/vtex/vtex-commercial-conditions-workflow.test.js.map +2 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/vtex/commercial-conditions.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { formatVtexError } from \"../../services/vtex/vtex-api.js\";\nimport {\n getCommercialCondition,\n listCommercialConditions,\n} from \"../../services/vtex/vtex-payments.js\";\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { formatVtexError } from \"../../services/vtex/vtex-api.js\";\nimport {\n getCommercialCondition,\n listCommercialConditions,\n} from \"../../services/vtex/vtex-payments.js\";\nimport { toSnakeCaseKeys } from \"../../utils/case-conversion.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\nimport { vtexProfileIdSchemaField } from \"./write-helpers.js\";\n\nconst requiredProfileIdSchemaField = vtexProfileIdSchemaField\n .unwrap()\n .describe(\"Explicit VTEX profile id to use for this operation.\");\n\nconst commercialConditionActionSchema = z\n .enum([\"list\", \"get\"])\n .describe(\"Action to perform for VTEX commercial conditions.\");\n\nconst commercialConditionIdSchemaField = z\n .number()\n .int()\n .positive()\n .describe(\"Positive VTEX commercial condition identifier.\");\n\nconst conditionRowsSchema = [\"id\", \"name\", \"is_active\"] as const;\n\nfunction readValue(record: Record<string, unknown>, ...keys: string[]): unknown {\n for (const key of keys) {\n if (key in record) {\n return record[key];\n }\n }\n\n return undefined;\n}\n\nconst listActionSchema = z.object({\n action: z.literal(\"list\"),\n profileId: requiredProfileIdSchemaField,\n search: z.string().trim().min(1).optional().describe(\"Optional text filter for condition name lookup.\"),\n});\n\nconst getActionSchema = z.object({\n action: z.literal(\"get\"),\n profileId: requiredProfileIdSchemaField,\n commercialConditionId: commercialConditionIdSchemaField,\n});\n\nfunction getCommercialConditionsActionSchema(\n action: z.infer<typeof commercialConditionActionSchema>\n) {\n switch (action) {\n case \"list\":\n return listActionSchema;\n case \"get\":\n return getActionSchema;\n }\n}\n\nexport const commercialConditionsSchema = z\n .object({\n action: commercialConditionActionSchema,\n profileId: requiredProfileIdSchemaField,\n search: z.string().trim().min(1).optional().describe(\"Optional text filter for condition name lookup.\"),\n commercialConditionId: commercialConditionIdSchemaField.optional(),\n })\n .superRefine((value, ctx) => {\n const validation = getCommercialConditionsActionSchema(value.action).safeParse(value);\n if (validation.success) {\n return;\n }\n\n for (const issue of validation.error.issues) {\n ctx.addIssue(issue as Parameters<typeof ctx.addIssue>[0]);\n }\n });\n\nexport async function commercialConditionsHandler(params: z.infer<typeof commercialConditionsSchema>) {\n switch (params.action) {\n case \"list\": {\n const validatedParams = listActionSchema.parse(params);\n\n try {\n const conditions = await listCommercialConditions(validatedParams.profileId, validatedParams.search);\n\n return object({\n metadata: stripNulls({\n total: conditions.length,\n profile_id: validatedParams.profileId,\n search: validatedParams.search,\n }),\n conditions_schema: conditionRowsSchema,\n conditions: conditions.map((condition) => [\n readValue(condition, \"id\", \"Id\"),\n readValue(condition, \"name\", \"Name\"),\n readValue(condition, \"isActive\", \"IsActive\", \"is_active\"),\n ]),\n });\n } catch (err) {\n return error(formatVtexError(err, \"Failed to list VTEX commercial conditions\"));\n }\n }\n\n case \"get\": {\n const validatedParams = getActionSchema.parse(params);\n\n try {\n const condition = await getCommercialCondition(\n validatedParams.profileId,\n validatedParams.commercialConditionId\n );\n\n return object({\n profile_id: validatedParams.profileId,\n commercial_condition_id: validatedParams.commercialConditionId,\n condition: toSnakeCaseKeys(condition),\n });\n } catch (err) {\n return error(\n formatVtexError(\n err,\n `Failed to fetch VTEX commercial condition ${validatedParams.commercialConditionId}`\n )\n );\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAC3B,SAAS,gCAAgC;AAEzC,MAAM,+BAA+B,yBAClC,OAAO,EACP,SAAS,qDAAqD;AAEjE,MAAM,kCAAkC,EACrC,KAAK,CAAC,QAAQ,KAAK,CAAC,EACpB,SAAS,mDAAmD;AAE/D,MAAM,mCAAmC,EACtC,OAAO,EACP,IAAI,EACJ,SAAS,EACT,SAAS,gDAAgD;AAE5D,MAAM,sBAAsB,CAAC,MAAM,QAAQ,WAAW;AAEtD,SAAS,UAAU,WAAoC,MAAyB;AAC9E,aAAW,OAAO,MAAM;AACtB,QAAI,OAAO,QAAQ;AACjB,aAAO,OAAO,GAAG;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,mBAAmB,EAAE,OAAO;AAAA,EAChC,QAAQ,EAAE,QAAQ,MAAM;AAAA,EACxB,WAAW;AAAA,EACX,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,iDAAiD;AACxG,CAAC;AAED,MAAM,kBAAkB,EAAE,OAAO;AAAA,EAC/B,QAAQ,EAAE,QAAQ,KAAK;AAAA,EACvB,WAAW;AAAA,EACX,uBAAuB;AACzB,CAAC;AAED,SAAS,oCACP,QACA;AACA,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;AAEO,MAAM,6BAA6B,EACvC,OAAO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AAA,UAC5B,yBAAyB,gBAAgB;AAAA,UACzC,WAAW,gBAAgB,SAAS;AAAA,QACtC,CAAC;AAAA,MACH,SAAS,KAAK;AACZ,eAAO;AAAA,UACL;AAAA,YACE;AAAA,YACA,6CAA6C,gBAAgB,qBAAqB;AAAA,UACpF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,7 +26,7 @@ const createSkuSchema = z.object({
|
|
|
26
26
|
unitMultiplier: z.number().positive().optional().describe("Unit multiplier."),
|
|
27
27
|
manufacturerCode: z.string().optional().describe("Manufacturer code."),
|
|
28
28
|
commercialConditionId: z.number().int().positive().optional().describe(
|
|
29
|
-
"Commercial condition ID. Use vtex_commercial_conditions to
|
|
29
|
+
"Commercial condition ID. Use vtex_commercial_conditions to inspect available condition IDs and vtex_payment_rules to configure linked installment/payment behavior."
|
|
30
30
|
)
|
|
31
31
|
});
|
|
32
32
|
async function createSkuHandler({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/vtex/create-sku.ts"],
|
|
4
|
-
"sourcesContent": ["import { z } from \"zod\";\n\nimport { createSku, createSkuEan } from \"../../services/vtex/vtex-catalog-write.js\";\nimport {\n buildWriteSuccessResponse,\n handleVtexWriteError,\n resolveVtexWriteProfile,\n vtexProfileIdSchemaField,\n} from \"./write-helpers.js\";\n\nexport const createSkuSchema = z.object({\n profileId: vtexProfileIdSchemaField,\n productId: z.number().int().positive().describe(\"Parent product ID.\"),\n name: z.string().min(1).describe(\"SKU name.\"),\n refId: z.string().min(1).describe(\"Internal SKU reference code.\"),\n ean: z.string().optional().describe(\"Optional EAN to attach after SKU creation.\"),\n packagedHeight: z.number().nonnegative().describe(\"Packaged height.\"),\n packagedLength: z.number().nonnegative().describe(\"Packaged length.\"),\n packagedWidth: z.number().nonnegative().describe(\"Packaged width.\"),\n packagedWeightKg: z.number().nonnegative().describe(\"Packaged weight in kg.\"),\n height: z.number().nonnegative().optional().describe(\"Physical height.\"),\n length: z.number().nonnegative().optional().describe(\"Physical length.\"),\n width: z.number().nonnegative().optional().describe(\"Physical width.\"),\n weightKg: z.number().nonnegative().optional().describe(\"Physical weight in kg.\"),\n isActive: z\n .boolean()\n .optional()\n .describe(\"Whether the SKU should be created as active. VTEX recommends false during creation.\"),\n activateIfPossible: z\n .boolean()\n .optional()\n .describe(\"Whether VTEX should auto-activate the SKU when an image or active component exists.\"),\n measurementUnit: z.string().optional().describe(\"Measurement unit, for example `un`.\"),\n unitMultiplier: z.number().positive().optional().describe(\"Unit multiplier.\"),\n manufacturerCode: z.string().optional().describe(\"Manufacturer code.\"),\n commercialConditionId: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\n \"Commercial condition ID. Use vtex_commercial_conditions to
|
|
4
|
+
"sourcesContent": ["import { z } from \"zod\";\n\nimport { createSku, createSkuEan } from \"../../services/vtex/vtex-catalog-write.js\";\nimport {\n buildWriteSuccessResponse,\n handleVtexWriteError,\n resolveVtexWriteProfile,\n vtexProfileIdSchemaField,\n} from \"./write-helpers.js\";\n\nexport const createSkuSchema = z.object({\n profileId: vtexProfileIdSchemaField,\n productId: z.number().int().positive().describe(\"Parent product ID.\"),\n name: z.string().min(1).describe(\"SKU name.\"),\n refId: z.string().min(1).describe(\"Internal SKU reference code.\"),\n ean: z.string().optional().describe(\"Optional EAN to attach after SKU creation.\"),\n packagedHeight: z.number().nonnegative().describe(\"Packaged height.\"),\n packagedLength: z.number().nonnegative().describe(\"Packaged length.\"),\n packagedWidth: z.number().nonnegative().describe(\"Packaged width.\"),\n packagedWeightKg: z.number().nonnegative().describe(\"Packaged weight in kg.\"),\n height: z.number().nonnegative().optional().describe(\"Physical height.\"),\n length: z.number().nonnegative().optional().describe(\"Physical length.\"),\n width: z.number().nonnegative().optional().describe(\"Physical width.\"),\n weightKg: z.number().nonnegative().optional().describe(\"Physical weight in kg.\"),\n isActive: z\n .boolean()\n .optional()\n .describe(\"Whether the SKU should be created as active. VTEX recommends false during creation.\"),\n activateIfPossible: z\n .boolean()\n .optional()\n .describe(\"Whether VTEX should auto-activate the SKU when an image or active component exists.\"),\n measurementUnit: z.string().optional().describe(\"Measurement unit, for example `un`.\"),\n unitMultiplier: z.number().positive().optional().describe(\"Unit multiplier.\"),\n manufacturerCode: z.string().optional().describe(\"Manufacturer code.\"),\n commercialConditionId: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\n \"Commercial condition ID. Use vtex_commercial_conditions to inspect available condition IDs and vtex_payment_rules to configure linked installment/payment behavior.\"\n ),\n});\n\nexport async function createSkuHandler({\n profileId,\n productId,\n name,\n refId,\n ean,\n packagedHeight,\n packagedLength,\n packagedWidth,\n packagedWeightKg,\n height,\n length,\n width,\n weightKg,\n isActive,\n activateIfPossible,\n measurementUnit,\n unitMultiplier,\n manufacturerCode,\n commercialConditionId,\n}: z.infer<typeof createSkuSchema>) {\n try {\n const profileResolution = await resolveVtexWriteProfile(profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const resolvedProfileId = profileResolution.value.profileId;\n const payload: Record<string, unknown> = {\n ProductId: productId,\n Name: name,\n RefId: refId,\n PackagedHeight: packagedHeight,\n PackagedLength: packagedLength,\n PackagedWidth: packagedWidth,\n PackagedWeightKg: packagedWeightKg,\n ActivateIfPossible: activateIfPossible ?? true,\n IsActive: isActive ?? false,\n };\n\n if (height !== undefined) payload.Height = height;\n if (length !== undefined) payload.Length = length;\n if (width !== undefined) payload.Width = width;\n if (weightKg !== undefined) payload.WeightKg = weightKg;\n if (measurementUnit !== undefined) payload.MeasurementUnit = measurementUnit;\n if (unitMultiplier !== undefined) payload.UnitMultiplier = unitMultiplier;\n if (manufacturerCode !== undefined) payload.ManufacturerCode = manufacturerCode;\n if (commercialConditionId !== undefined) payload.CommercialConditionId = commercialConditionId;\n\n const createdSku = await createSku(resolvedProfileId, payload);\n const resourceId = createdSku.Id == null ? undefined : String(createdSku.Id);\n\n if (resourceId && ean?.trim()) {\n await createSkuEan(resolvedProfileId, resourceId, ean.trim());\n createdSku.Eans = [ean.trim()];\n }\n\n return buildWriteSuccessResponse({\n profileId: resolvedProfileId,\n operation: \"create_sku\",\n resourceId,\n riskLevel: \"low\",\n message: \"SKU created successfully.\",\n before: null,\n after: createdSku,\n details: {\n product_id: productId,\n sku_id: resourceId,\n },\n });\n } catch (err) {\n return handleVtexWriteError(err, \"Failed to create SKU in VTEX\");\n }\n}\n"],
|
|
5
5
|
"mappings": "AAAA,SAAS,SAAS;AAElB,SAAS,WAAW,oBAAoB;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM,kBAAkB,EAAE,OAAO;AAAA,EACtC,WAAW;AAAA,EACX,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,oBAAoB;AAAA,EACpE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,WAAW;AAAA,EAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,8BAA8B;AAAA,EAChE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,4CAA4C;AAAA,EAChF,gBAAgB,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,kBAAkB;AAAA,EACpE,gBAAgB,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,kBAAkB;AAAA,EACpE,eAAe,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,iBAAiB;AAAA,EAClE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,wBAAwB;AAAA,EAC5E,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,kBAAkB;AAAA,EACvE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,kBAAkB;AAAA,EACvE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,S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,UAAU,OAAW,SAAQ,QAAQ;AACzC,QAAI,aAAa,OAAW,SAAQ,WAAW;AAC/C,QAAI,oBAAoB,OAAW,SAAQ,kBAAkB;AAC7D,QAAI,mBAAmB,OAAW,SAAQ,iBAAiB;AAC3D,QAAI,qBAAqB,OAAW,SAAQ,mBAAmB;AAC/D,QAAI,0BAA0B,OAAW,SAAQ,wBAAwB;AAEzE,UAAM,aAAa,MAAM,UAAU,mBAAmB,OAAO;AAC7D,UAAM,aAAa,WAAW,MAAM,OAAO,SAAY,OAAO,WAAW,EAAE;AAE3E,QAAI,cAAc,KAAK,KAAK,GAAG;AAC7B,YAAM,aAAa,mBAAmB,YAAY,IAAI,KAAK,CAAC;AAC5D,iBAAW,OAAO,CAAC,IAAI,KAAK,CAAC;AAAA,IAC/B;AAEA,WAAO,0BAA0B;AAAA,MAC/B,WAAW;AAAA,MACX,WAAW;AAAA,MACX;AAAA,MACA,WAAW;AAAA,MACX,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,SAAS;AAAA,QACP,YAAY;AAAA,QACZ,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,WAAO,qBAAqB,KAAK,8BAA8B;AAAA,EACjE;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -14,9 +14,11 @@ import {
|
|
|
14
14
|
confirmationSchemaField,
|
|
15
15
|
handleVtexWriteError,
|
|
16
16
|
requireExplicitConfirmation,
|
|
17
|
-
resolveVtexWriteProfile
|
|
17
|
+
resolveVtexWriteProfile,
|
|
18
|
+
vtexProfileIdSchemaField
|
|
18
19
|
} from "./write-helpers.js";
|
|
19
|
-
const requiredProfileIdSchemaField =
|
|
20
|
+
const requiredProfileIdSchemaField = vtexProfileIdSchemaField.unwrap().describe("Explicit VTEX profile id to use for this operation.");
|
|
21
|
+
const paymentRuleActionSchema = z.enum(["list", "get", "create", "update", "delete"]).describe("Action to perform for VTEX payment rules.");
|
|
20
22
|
const positiveIntegerSchemaField = (description) => z.number().int().positive().describe(description);
|
|
21
23
|
const installmentsSchemaField = z.array(
|
|
22
24
|
z.object({
|
|
@@ -89,25 +91,54 @@ const deleteActionSchema = z.object({
|
|
|
89
91
|
ruleId: positiveIntegerSchemaField("Positive VTEX payment rule identifier."),
|
|
90
92
|
confirmed: confirmationSchemaField
|
|
91
93
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
function getPaymentRulesActionSchema(action) {
|
|
95
|
+
switch (action) {
|
|
96
|
+
case "list":
|
|
97
|
+
return listActionSchema;
|
|
98
|
+
case "get":
|
|
99
|
+
return getActionSchema;
|
|
100
|
+
case "create":
|
|
101
|
+
return createActionSchema;
|
|
102
|
+
case "update":
|
|
103
|
+
return updateActionSchema;
|
|
104
|
+
case "delete":
|
|
105
|
+
return deleteActionSchema;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const paymentRulesSchema = z.object({
|
|
109
|
+
action: paymentRuleActionSchema,
|
|
110
|
+
profileId: requiredProfileIdSchemaField,
|
|
111
|
+
commercialConditionId: positiveIntegerSchemaField(
|
|
112
|
+
"Commercial condition identifier linked to this payment rule."
|
|
113
|
+
).optional(),
|
|
114
|
+
ruleId: positiveIntegerSchemaField("Positive VTEX payment rule identifier.").optional(),
|
|
115
|
+
paymentSystem: z.string().trim().min(1).optional().describe("VTEX payment system identifier."),
|
|
116
|
+
salesChannel: z.string().trim().min(1).optional().describe("Optional VTEX sales channel identifier."),
|
|
117
|
+
restrictedByCondition: z.boolean().optional().describe("Whether checkout should restrict this rule to the linked commercial condition."),
|
|
118
|
+
installments: installmentsSchemaField.optional(),
|
|
119
|
+
confirmed: confirmationSchemaField
|
|
120
|
+
}).superRefine((value, ctx) => {
|
|
121
|
+
const validation = getPaymentRulesActionSchema(value.action).safeParse(value);
|
|
122
|
+
if (validation.success) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
for (const issue of validation.error.issues) {
|
|
126
|
+
ctx.addIssue(issue);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
99
129
|
async function paymentRulesHandler(params) {
|
|
100
130
|
switch (params.action) {
|
|
101
131
|
case "list": {
|
|
132
|
+
const validatedParams = listActionSchema.parse(params);
|
|
102
133
|
try {
|
|
103
|
-
const rules = await listPaymentRules(
|
|
104
|
-
commercialConditionId:
|
|
134
|
+
const rules = await listPaymentRules(validatedParams.profileId, {
|
|
135
|
+
commercialConditionId: validatedParams.commercialConditionId
|
|
105
136
|
});
|
|
106
137
|
return object({
|
|
107
138
|
metadata: stripNulls({
|
|
108
139
|
total: rules.length,
|
|
109
|
-
profile_id:
|
|
110
|
-
filters:
|
|
140
|
+
profile_id: validatedParams.profileId,
|
|
141
|
+
filters: validatedParams.commercialConditionId === void 0 ? void 0 : { commercial_condition_id: validatedParams.commercialConditionId }
|
|
111
142
|
}),
|
|
112
143
|
payment_rules_schema: paymentRuleRowsSchema,
|
|
113
144
|
payment_rules: rules.map((rule) => [
|
|
@@ -128,29 +159,33 @@ async function paymentRulesHandler(params) {
|
|
|
128
159
|
}
|
|
129
160
|
}
|
|
130
161
|
case "get": {
|
|
162
|
+
const validatedParams = getActionSchema.parse(params);
|
|
131
163
|
try {
|
|
132
|
-
const rule = await getPaymentRule(
|
|
164
|
+
const rule = await getPaymentRule(validatedParams.profileId, validatedParams.ruleId);
|
|
133
165
|
return object({
|
|
134
|
-
profile_id:
|
|
135
|
-
rule_id:
|
|
166
|
+
profile_id: validatedParams.profileId,
|
|
167
|
+
rule_id: validatedParams.ruleId,
|
|
136
168
|
payment_rule: toSnakeCaseKeys(rule)
|
|
137
169
|
});
|
|
138
170
|
} catch (err) {
|
|
139
|
-
return error(
|
|
171
|
+
return error(
|
|
172
|
+
formatVtexError(err, `Failed to fetch VTEX payment rule ${validatedParams.ruleId}`)
|
|
173
|
+
);
|
|
140
174
|
}
|
|
141
175
|
}
|
|
142
176
|
case "create": {
|
|
177
|
+
const validatedParams = createActionSchema.parse(params);
|
|
143
178
|
try {
|
|
144
|
-
const profileResolution = await resolveVtexWriteProfile(
|
|
179
|
+
const profileResolution = await resolveVtexWriteProfile(validatedParams.profileId);
|
|
145
180
|
if (!profileResolution.ok) {
|
|
146
181
|
return profileResolution.response;
|
|
147
182
|
}
|
|
148
183
|
const created = await createPaymentRule(profileResolution.value.profileId, {
|
|
149
|
-
commercialConditionId:
|
|
150
|
-
paymentSystem:
|
|
151
|
-
...
|
|
152
|
-
...
|
|
153
|
-
installments:
|
|
184
|
+
commercialConditionId: validatedParams.commercialConditionId,
|
|
185
|
+
paymentSystem: validatedParams.paymentSystem,
|
|
186
|
+
...validatedParams.salesChannel !== void 0 ? { salesChannel: validatedParams.salesChannel } : {},
|
|
187
|
+
...validatedParams.restrictedByCondition !== void 0 ? { restrictedByCondition: validatedParams.restrictedByCondition } : {},
|
|
188
|
+
installments: validatedParams.installments
|
|
154
189
|
});
|
|
155
190
|
return buildWriteSuccessResponse({
|
|
156
191
|
profileId: profileResolution.value.profileId,
|
|
@@ -166,49 +201,54 @@ async function paymentRulesHandler(params) {
|
|
|
166
201
|
}
|
|
167
202
|
}
|
|
168
203
|
case "update": {
|
|
204
|
+
const validatedParams = updateActionSchema.parse(params);
|
|
169
205
|
try {
|
|
170
|
-
const profileResolution = await resolveVtexWriteProfile(
|
|
206
|
+
const profileResolution = await resolveVtexWriteProfile(validatedParams.profileId);
|
|
171
207
|
if (!profileResolution.ok) {
|
|
172
208
|
return profileResolution.response;
|
|
173
209
|
}
|
|
174
|
-
const updated = await updatePaymentRule(profileResolution.value.profileId,
|
|
175
|
-
...
|
|
176
|
-
...
|
|
177
|
-
...
|
|
178
|
-
...
|
|
179
|
-
...
|
|
210
|
+
const updated = await updatePaymentRule(profileResolution.value.profileId, validatedParams.ruleId, {
|
|
211
|
+
...validatedParams.commercialConditionId !== void 0 ? { commercialConditionId: validatedParams.commercialConditionId } : {},
|
|
212
|
+
...validatedParams.paymentSystem !== void 0 ? { paymentSystem: validatedParams.paymentSystem } : {},
|
|
213
|
+
...validatedParams.salesChannel !== void 0 ? { salesChannel: validatedParams.salesChannel } : {},
|
|
214
|
+
...validatedParams.restrictedByCondition !== void 0 ? { restrictedByCondition: validatedParams.restrictedByCondition } : {},
|
|
215
|
+
...validatedParams.installments !== void 0 ? { installments: validatedParams.installments } : {}
|
|
180
216
|
});
|
|
181
217
|
return buildWriteSuccessResponse({
|
|
182
218
|
profileId: profileResolution.value.profileId,
|
|
183
219
|
operation: "payment_rules_update",
|
|
184
|
-
resourceId: String(
|
|
220
|
+
resourceId: String(validatedParams.ruleId),
|
|
185
221
|
riskLevel: "medium",
|
|
186
222
|
message: "Payment rule updated. Review checkout installments to confirm the expected payment options.",
|
|
187
223
|
before: null,
|
|
188
224
|
after: updated
|
|
189
225
|
});
|
|
190
226
|
} catch (err) {
|
|
191
|
-
return handleVtexWriteError(
|
|
227
|
+
return handleVtexWriteError(
|
|
228
|
+
err,
|
|
229
|
+
`Failed to update VTEX payment rule ${validatedParams.ruleId}`
|
|
230
|
+
);
|
|
192
231
|
}
|
|
193
232
|
}
|
|
194
233
|
case "delete": {
|
|
195
|
-
const
|
|
196
|
-
|
|
234
|
+
const validatedParams = deleteActionSchema.parse(params);
|
|
235
|
+
const confirmationResponse = requireExplicitConfirmation(validatedParams.confirmed, "payment_rules_delete", {
|
|
236
|
+
rule_id: validatedParams.ruleId,
|
|
197
237
|
warnings: [paymentRuleWarnings.delete]
|
|
198
238
|
});
|
|
199
239
|
if (confirmationResponse) {
|
|
200
240
|
return confirmationResponse;
|
|
201
241
|
}
|
|
202
242
|
try {
|
|
203
|
-
const profileResolution = await resolveVtexWriteProfile(
|
|
243
|
+
const profileResolution = await resolveVtexWriteProfile(validatedParams.profileId);
|
|
204
244
|
if (!profileResolution.ok) {
|
|
205
245
|
return profileResolution.response;
|
|
206
246
|
}
|
|
207
|
-
await deletePaymentRule(profileResolution.value.profileId,
|
|
247
|
+
await deletePaymentRule(profileResolution.value.profileId, validatedParams.ruleId);
|
|
208
248
|
return buildWriteSuccessResponse({
|
|
209
249
|
profileId: profileResolution.value.profileId,
|
|
210
250
|
operation: "payment_rules_delete",
|
|
211
|
-
resourceId: String(
|
|
251
|
+
resourceId: String(validatedParams.ruleId),
|
|
212
252
|
riskLevel: "high",
|
|
213
253
|
confirmed: true,
|
|
214
254
|
message: "Payment rule deleted. Verify checkout no longer exposes the removed installment option to affected shoppers.",
|
|
@@ -217,7 +257,10 @@ async function paymentRulesHandler(params) {
|
|
|
217
257
|
after: null
|
|
218
258
|
});
|
|
219
259
|
} catch (err) {
|
|
220
|
-
return handleVtexWriteError(
|
|
260
|
+
return handleVtexWriteError(
|
|
261
|
+
err,
|
|
262
|
+
`Failed to delete VTEX payment rule ${validatedParams.ruleId}`
|
|
263
|
+
);
|
|
221
264
|
}
|
|
222
265
|
}
|
|
223
266
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/vtex/payment-rules.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { formatVtexError } from \"../../services/vtex/vtex-api.js\";\nimport { getPaymentRule, listPaymentRules } from \"../../services/vtex/vtex-payments.js\";\nimport {\n createPaymentRule,\n deletePaymentRule,\n updatePaymentRule,\n} from \"../../services/vtex/vtex-payments-write.js\";\nimport { toSnakeCaseKeys } from \"../../utils/case-conversion.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\nimport {\n buildWriteSuccessResponse,\n confirmationSchemaField,\n handleVtexWriteError,\n requireExplicitConfirmation,\n resolveVtexWriteProfile,\n} from \"./write-helpers.js\";\n\nconst requiredProfileIdSchemaField = z\n .string()\n .trim()\n .min(1)\n .describe(\"Explicit VTEX profile id to use for this operation.\");\n\nconst positiveIntegerSchemaField = (description: string) =>\n z.number().int().positive().describe(description);\n\nconst installmentsSchemaField = z\n .array(\n z.object({\n count: positiveIntegerSchemaField(\"Installment count.\"),\n interest: z.boolean().describe(\"Whether this installment carries interest.\"),\n })\n )\n .min(1)\n .describe(\"Installment configuration rows for the payment rule.\");\n\nconst paymentRuleWarnings = {\n delete:\n \"Deleting a payment rule can immediately remove installment options from checkout for affected shoppers.\",\n} as const;\n\nconst paymentRuleRowsSchema = [\n \"id\",\n \"commercial_condition_id\",\n \"payment_system\",\n \"sales_channel\",\n \"restricted_by_condition\",\n] as const;\n\nfunction readValue(record: Record<string, unknown>, ...keys: string[]): unknown {\n for (const key of keys) {\n if (key in record) {\n return record[key];\n }\n }\n\n return undefined;\n}\n\nconst listActionSchema = z.object({\n action: z.literal(\"list\"),\n profileId: requiredProfileIdSchemaField,\n commercialConditionId: positiveIntegerSchemaField(\n \"Optional commercial condition filter for payment rules.\"\n ).optional(),\n});\n\nconst getActionSchema = z.object({\n action: z.literal(\"get\"),\n profileId: requiredProfileIdSchemaField,\n ruleId: positiveIntegerSchemaField(\"Positive VTEX payment rule identifier.\"),\n});\n\nconst createActionSchema = z.object({\n action: z.literal(\"create\"),\n profileId: requiredProfileIdSchemaField,\n commercialConditionId: positiveIntegerSchemaField(\n \"Commercial condition identifier linked to this payment rule.\"\n ),\n paymentSystem: z.string().trim().min(1).describe(\"VTEX payment system identifier.\"),\n salesChannel: z.string().trim().min(1).optional().describe(\"Optional VTEX sales channel identifier.\"),\n restrictedByCondition: z\n .boolean()\n .optional()\n .describe(\"Whether checkout should restrict this rule to the linked commercial condition.\"),\n installments: installmentsSchemaField,\n});\n\nconst updateActionSchema = z\n .object({\n action: z.literal(\"update\"),\n profileId: requiredProfileIdSchemaField,\n ruleId: positiveIntegerSchemaField(\"Positive VTEX payment rule identifier.\"),\n commercialConditionId: positiveIntegerSchemaField(\n \"Commercial condition identifier linked to this payment rule.\"\n ).optional(),\n paymentSystem: z.string().trim().min(1).optional().describe(\"Updated VTEX payment system identifier.\"),\n salesChannel: z.string().trim().min(1).optional().describe(\"Updated VTEX sales channel identifier.\"),\n restrictedByCondition: z\n .boolean()\n .optional()\n .describe(\"Updated restricted-by-condition flag.\"),\n installments: installmentsSchemaField.optional(),\n })\n .refine(\n (value) =>\n value.commercialConditionId !== undefined ||\n value.paymentSystem !== undefined ||\n value.salesChannel !== undefined ||\n value.restrictedByCondition !== undefined ||\n value.installments !== undefined,\n {\n message: \"At least one payment rule field must be provided.\",\n path: [\"paymentSystem\"],\n }\n );\n\nconst deleteActionSchema = z.object({\n action: z.literal(\"delete\"),\n profileId: requiredProfileIdSchemaField,\n ruleId: positiveIntegerSchemaField(\"Positive VTEX payment rule identifier.\"),\n confirmed: confirmationSchemaField,\n});\n\nexport const paymentRulesSchema = z.discriminatedUnion(\"action\", [\n listActionSchema,\n getActionSchema,\n createActionSchema,\n updateActionSchema,\n deleteActionSchema,\n]);\n\nexport async function paymentRulesHandler(params: z.infer<typeof paymentRulesSchema>) {\n switch (params.action) {\n case \"list\": {\n try {\n const rules = await listPaymentRules(params.profileId, {\n commercialConditionId: params.commercialConditionId,\n });\n\n return object({\n metadata: stripNulls({\n total: rules.length,\n profile_id: params.profileId,\n filters:\n params.commercialConditionId === undefined\n ? undefined\n : { commercial_condition_id: params.commercialConditionId },\n }),\n payment_rules_schema: paymentRuleRowsSchema,\n payment_rules: rules.map((rule) => [\n readValue(rule, \"id\", \"Id\"),\n readValue(rule, \"commercialConditionId\", \"CommercialConditionId\", \"commercial_condition_id\"),\n readValue(rule, \"paymentSystem\", \"PaymentSystem\", \"payment_system\"),\n readValue(rule, \"salesChannel\", \"SalesChannel\", \"sales_channel\"),\n readValue(\n rule,\n \"restrictedByCondition\",\n \"RestrictedByCondition\",\n \"restricted_by_condition\"\n ),\n ]),\n });\n } catch (err) {\n return error(formatVtexError(err, \"Failed to list VTEX payment rules\"));\n }\n }\n\n case \"get\": {\n try {\n const rule = await getPaymentRule(params.profileId, params.ruleId);\n\n return object({\n profile_id: params.profileId,\n rule_id: params.ruleId,\n payment_rule: toSnakeCaseKeys(rule),\n });\n } catch (err) {\n return error(formatVtexError(err, `Failed to fetch VTEX payment rule ${params.ruleId}`));\n }\n }\n\n case \"create\": {\n try {\n const profileResolution = await resolveVtexWriteProfile(params.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const created = await createPaymentRule(profileResolution.value.profileId, {\n commercialConditionId: params.commercialConditionId,\n paymentSystem: params.paymentSystem,\n ...(params.salesChannel !== undefined ? { salesChannel: params.salesChannel } : {}),\n ...(params.restrictedByCondition !== undefined\n ? { restrictedByCondition: params.restrictedByCondition }\n : {}),\n installments: params.installments,\n });\n\n return buildWriteSuccessResponse({\n profileId: profileResolution.value.profileId,\n operation: \"payment_rules_create\",\n resourceId: created.id == null ? undefined : String(created.id),\n riskLevel: \"medium\",\n message:\n \"Payment rule created. Review checkout installments and condition targeting to confirm the expected shopper experience.\",\n before: null,\n after: created,\n });\n } catch (err) {\n return handleVtexWriteError(err, \"Failed to create VTEX payment rule\");\n }\n }\n\n case \"update\": {\n try {\n const profileResolution = await resolveVtexWriteProfile(params.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const updated = await updatePaymentRule(profileResolution.value.profileId, params.ruleId, {\n ...(params.commercialConditionId !== undefined\n ? { commercialConditionId: params.commercialConditionId }\n : {}),\n ...(params.paymentSystem !== undefined ? { paymentSystem: params.paymentSystem } : {}),\n ...(params.salesChannel !== undefined ? { salesChannel: params.salesChannel } : {}),\n ...(params.restrictedByCondition !== undefined\n ? { restrictedByCondition: params.restrictedByCondition }\n : {}),\n ...(params.installments !== undefined ? { installments: params.installments } : {}),\n });\n\n return buildWriteSuccessResponse({\n profileId: profileResolution.value.profileId,\n operation: \"payment_rules_update\",\n resourceId: String(params.ruleId),\n riskLevel: \"medium\",\n message:\n \"Payment rule updated. Review checkout installments to confirm the expected payment options.\",\n before: null,\n after: updated,\n });\n } catch (err) {\n return handleVtexWriteError(err, `Failed to update VTEX payment rule ${params.ruleId}`);\n }\n }\n\n case \"delete\": {\n const confirmationResponse = requireExplicitConfirmation(params.confirmed, \"payment_rules_delete\", {\n rule_id: params.ruleId,\n warnings: [paymentRuleWarnings.delete],\n });\n if (confirmationResponse) {\n return confirmationResponse;\n }\n\n try {\n const profileResolution = await resolveVtexWriteProfile(params.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n await deletePaymentRule(profileResolution.value.profileId, params.ruleId);\n\n return buildWriteSuccessResponse({\n profileId: profileResolution.value.profileId,\n operation: \"payment_rules_delete\",\n resourceId: String(params.ruleId),\n riskLevel: \"high\",\n confirmed: true,\n message:\n \"Payment rule deleted. Verify checkout no longer exposes the removed installment option to affected shoppers.\",\n warnings: [paymentRuleWarnings.delete],\n before: null,\n after: null,\n });\n } catch (err) {\n return handleVtexWriteError(err, `Failed to delete VTEX payment rule ${params.ruleId}`);\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,wBAAwB;AACjD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,+BAA+B,
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { formatVtexError } from \"../../services/vtex/vtex-api.js\";\nimport { getPaymentRule, listPaymentRules } from \"../../services/vtex/vtex-payments.js\";\nimport {\n createPaymentRule,\n deletePaymentRule,\n updatePaymentRule,\n} from \"../../services/vtex/vtex-payments-write.js\";\nimport { toSnakeCaseKeys } from \"../../utils/case-conversion.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\nimport {\n buildWriteSuccessResponse,\n confirmationSchemaField,\n handleVtexWriteError,\n requireExplicitConfirmation,\n resolveVtexWriteProfile,\n vtexProfileIdSchemaField,\n} from \"./write-helpers.js\";\n\nconst requiredProfileIdSchemaField = vtexProfileIdSchemaField\n .unwrap()\n .describe(\"Explicit VTEX profile id to use for this operation.\");\n\nconst paymentRuleActionSchema = z\n .enum([\"list\", \"get\", \"create\", \"update\", \"delete\"])\n .describe(\"Action to perform for VTEX payment rules.\");\n\nconst positiveIntegerSchemaField = (description: string) =>\n z.number().int().positive().describe(description);\n\nconst installmentsSchemaField = z\n .array(\n z.object({\n count: positiveIntegerSchemaField(\"Installment count.\"),\n interest: z.boolean().describe(\"Whether this installment carries interest.\"),\n })\n )\n .min(1)\n .describe(\"Installment configuration rows for the payment rule.\");\n\nconst paymentRuleWarnings = {\n delete:\n \"Deleting a payment rule can immediately remove installment options from checkout for affected shoppers.\",\n} as const;\n\nconst paymentRuleRowsSchema = [\n \"id\",\n \"commercial_condition_id\",\n \"payment_system\",\n \"sales_channel\",\n \"restricted_by_condition\",\n] as const;\n\nfunction readValue(record: Record<string, unknown>, ...keys: string[]): unknown {\n for (const key of keys) {\n if (key in record) {\n return record[key];\n }\n }\n\n return undefined;\n}\n\nconst listActionSchema = z.object({\n action: z.literal(\"list\"),\n profileId: requiredProfileIdSchemaField,\n commercialConditionId: positiveIntegerSchemaField(\n \"Optional commercial condition filter for payment rules.\"\n ).optional(),\n});\n\nconst getActionSchema = z.object({\n action: z.literal(\"get\"),\n profileId: requiredProfileIdSchemaField,\n ruleId: positiveIntegerSchemaField(\"Positive VTEX payment rule identifier.\"),\n});\n\nconst createActionSchema = z.object({\n action: z.literal(\"create\"),\n profileId: requiredProfileIdSchemaField,\n commercialConditionId: positiveIntegerSchemaField(\n \"Commercial condition identifier linked to this payment rule.\"\n ),\n paymentSystem: z.string().trim().min(1).describe(\"VTEX payment system identifier.\"),\n salesChannel: z.string().trim().min(1).optional().describe(\"Optional VTEX sales channel identifier.\"),\n restrictedByCondition: z\n .boolean()\n .optional()\n .describe(\"Whether checkout should restrict this rule to the linked commercial condition.\"),\n installments: installmentsSchemaField,\n});\n\nconst updateActionSchema = z\n .object({\n action: z.literal(\"update\"),\n profileId: requiredProfileIdSchemaField,\n ruleId: positiveIntegerSchemaField(\"Positive VTEX payment rule identifier.\"),\n commercialConditionId: positiveIntegerSchemaField(\n \"Commercial condition identifier linked to this payment rule.\"\n ).optional(),\n paymentSystem: z.string().trim().min(1).optional().describe(\"Updated VTEX payment system identifier.\"),\n salesChannel: z.string().trim().min(1).optional().describe(\"Updated VTEX sales channel identifier.\"),\n restrictedByCondition: z\n .boolean()\n .optional()\n .describe(\"Updated restricted-by-condition flag.\"),\n installments: installmentsSchemaField.optional(),\n })\n .refine(\n (value) =>\n value.commercialConditionId !== undefined ||\n value.paymentSystem !== undefined ||\n value.salesChannel !== undefined ||\n value.restrictedByCondition !== undefined ||\n value.installments !== undefined,\n {\n message: \"At least one payment rule field must be provided.\",\n path: [\"paymentSystem\"],\n }\n );\n\nconst deleteActionSchema = z.object({\n action: z.literal(\"delete\"),\n profileId: requiredProfileIdSchemaField,\n ruleId: positiveIntegerSchemaField(\"Positive VTEX payment rule identifier.\"),\n confirmed: confirmationSchemaField,\n});\n\nfunction getPaymentRulesActionSchema(action: z.infer<typeof paymentRuleActionSchema>) {\n switch (action) {\n case \"list\":\n return listActionSchema;\n case \"get\":\n return getActionSchema;\n case \"create\":\n return createActionSchema;\n case \"update\":\n return updateActionSchema;\n case \"delete\":\n return deleteActionSchema;\n }\n}\n\nexport const paymentRulesSchema = z\n .object({\n action: paymentRuleActionSchema,\n profileId: requiredProfileIdSchemaField,\n commercialConditionId: positiveIntegerSchemaField(\n \"Commercial condition identifier linked to this payment rule.\"\n ).optional(),\n ruleId: positiveIntegerSchemaField(\"Positive VTEX payment rule identifier.\").optional(),\n paymentSystem: z.string().trim().min(1).optional().describe(\"VTEX payment system identifier.\"),\n salesChannel: z.string().trim().min(1).optional().describe(\"Optional VTEX sales channel identifier.\"),\n restrictedByCondition: z\n .boolean()\n .optional()\n .describe(\"Whether checkout should restrict this rule to the linked commercial condition.\"),\n installments: installmentsSchemaField.optional(),\n confirmed: confirmationSchemaField,\n })\n .superRefine((value, ctx) => {\n const validation = getPaymentRulesActionSchema(value.action).safeParse(value);\n if (validation.success) {\n return;\n }\n\n for (const issue of validation.error.issues) {\n ctx.addIssue(issue as Parameters<typeof ctx.addIssue>[0]);\n }\n });\n\nexport async function paymentRulesHandler(params: z.infer<typeof paymentRulesSchema>) {\n switch (params.action) {\n case \"list\": {\n const validatedParams = listActionSchema.parse(params);\n\n try {\n const rules = await listPaymentRules(validatedParams.profileId, {\n commercialConditionId: validatedParams.commercialConditionId,\n });\n\n return object({\n metadata: stripNulls({\n total: rules.length,\n profile_id: validatedParams.profileId,\n filters:\n validatedParams.commercialConditionId === undefined\n ? undefined\n : { commercial_condition_id: validatedParams.commercialConditionId },\n }),\n payment_rules_schema: paymentRuleRowsSchema,\n payment_rules: rules.map((rule) => [\n readValue(rule, \"id\", \"Id\"),\n readValue(rule, \"commercialConditionId\", \"CommercialConditionId\", \"commercial_condition_id\"),\n readValue(rule, \"paymentSystem\", \"PaymentSystem\", \"payment_system\"),\n readValue(rule, \"salesChannel\", \"SalesChannel\", \"sales_channel\"),\n readValue(\n rule,\n \"restrictedByCondition\",\n \"RestrictedByCondition\",\n \"restricted_by_condition\"\n ),\n ]),\n });\n } catch (err) {\n return error(formatVtexError(err, \"Failed to list VTEX payment rules\"));\n }\n }\n\n case \"get\": {\n const validatedParams = getActionSchema.parse(params);\n\n try {\n const rule = await getPaymentRule(validatedParams.profileId, validatedParams.ruleId);\n\n return object({\n profile_id: validatedParams.profileId,\n rule_id: validatedParams.ruleId,\n payment_rule: toSnakeCaseKeys(rule),\n });\n } catch (err) {\n return error(\n formatVtexError(err, `Failed to fetch VTEX payment rule ${validatedParams.ruleId}`)\n );\n }\n }\n\n case \"create\": {\n const validatedParams = createActionSchema.parse(params);\n\n try {\n const profileResolution = await resolveVtexWriteProfile(validatedParams.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const created = await createPaymentRule(profileResolution.value.profileId, {\n commercialConditionId: validatedParams.commercialConditionId,\n paymentSystem: validatedParams.paymentSystem,\n ...(validatedParams.salesChannel !== undefined\n ? { salesChannel: validatedParams.salesChannel }\n : {}),\n ...(validatedParams.restrictedByCondition !== undefined\n ? { restrictedByCondition: validatedParams.restrictedByCondition }\n : {}),\n installments: validatedParams.installments,\n });\n\n return buildWriteSuccessResponse({\n profileId: profileResolution.value.profileId,\n operation: \"payment_rules_create\",\n resourceId: created.id == null ? undefined : String(created.id),\n riskLevel: \"medium\",\n message:\n \"Payment rule created. Review checkout installments and condition targeting to confirm the expected shopper experience.\",\n before: null,\n after: created,\n });\n } catch (err) {\n return handleVtexWriteError(err, \"Failed to create VTEX payment rule\");\n }\n }\n\n case \"update\": {\n const validatedParams = updateActionSchema.parse(params);\n\n try {\n const profileResolution = await resolveVtexWriteProfile(validatedParams.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const updated = await updatePaymentRule(profileResolution.value.profileId, validatedParams.ruleId, {\n ...(validatedParams.commercialConditionId !== undefined\n ? { commercialConditionId: validatedParams.commercialConditionId }\n : {}),\n ...(validatedParams.paymentSystem !== undefined\n ? { paymentSystem: validatedParams.paymentSystem }\n : {}),\n ...(validatedParams.salesChannel !== undefined\n ? { salesChannel: validatedParams.salesChannel }\n : {}),\n ...(validatedParams.restrictedByCondition !== undefined\n ? { restrictedByCondition: validatedParams.restrictedByCondition }\n : {}),\n ...(validatedParams.installments !== undefined\n ? { installments: validatedParams.installments }\n : {}),\n });\n\n return buildWriteSuccessResponse({\n profileId: profileResolution.value.profileId,\n operation: \"payment_rules_update\",\n resourceId: String(validatedParams.ruleId),\n riskLevel: \"medium\",\n message:\n \"Payment rule updated. Review checkout installments to confirm the expected payment options.\",\n before: null,\n after: updated,\n });\n } catch (err) {\n return handleVtexWriteError(\n err,\n `Failed to update VTEX payment rule ${validatedParams.ruleId}`\n );\n }\n }\n\n case \"delete\": {\n const validatedParams = deleteActionSchema.parse(params);\n\n const confirmationResponse = requireExplicitConfirmation(validatedParams.confirmed, \"payment_rules_delete\", {\n rule_id: validatedParams.ruleId,\n warnings: [paymentRuleWarnings.delete],\n });\n if (confirmationResponse) {\n return confirmationResponse;\n }\n\n try {\n const profileResolution = await resolveVtexWriteProfile(validatedParams.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n await deletePaymentRule(profileResolution.value.profileId, validatedParams.ruleId);\n\n return buildWriteSuccessResponse({\n profileId: profileResolution.value.profileId,\n operation: \"payment_rules_delete\",\n resourceId: String(validatedParams.ruleId),\n riskLevel: \"high\",\n confirmed: true,\n message:\n \"Payment rule deleted. Verify checkout no longer exposes the removed installment option to affected shoppers.\",\n warnings: [paymentRuleWarnings.delete],\n before: null,\n after: null,\n });\n } catch (err) {\n return handleVtexWriteError(\n err,\n `Failed to delete VTEX payment rule ${validatedParams.ruleId}`\n );\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,wBAAwB;AACjD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,+BAA+B,yBAClC,OAAO,EACP,SAAS,qDAAqD;AAEjE,MAAM,0BAA0B,EAC7B,KAAK,CAAC,QAAQ,OAAO,UAAU,UAAU,QAAQ,CAAC,EAClD,SAAS,2CAA2C;AAEvD,MAAM,6BAA6B,CAAC,gBAClC,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,WAAW;AAElD,MAAM,0BAA0B,EAC7B;AAAA,EACC,EAAE,OAAO;AAAA,IACP,OAAO,2BAA2B,oBAAoB;AAAA,IACtD,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B,IAAI;AACzB,iBAAO,kBAAkB;AAAA,QAC3B;AAEA,cAAM,kBAAkB,kBAAkB,MAAM,WAAW,gBAAgB,MAAM;AAEjF,eAAO,0BAA0B;AAAA,UAC/B,WAAW,kBAAkB,MAAM;AAAA,UACnC,WAAW;AAAA,UACX,YAAY,OAAO,gBAAgB,MAAM;AAAA,UACzC,WAAW;AAAA,UACX,WAAW;AAAA,UACX,SACE;AAAA,UACF,UAAU,CAAC,oBAAoB,MAAM;AAAA,UACrC,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH,SAAS,KAAK;AACZ,eAAO;AAAA,UACL;AAAA,UACA,sCAAsC,gBAAgB,MAAM;AAAA,QAC9D;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
describe("VTEX commercial conditions documentation", () => {
|
|
4
|
-
it("documents the
|
|
4
|
+
it("documents the corrected VTEX commercial conditions capability across project docs", async () => {
|
|
5
5
|
const projectStatus = await readFile(new URL("../../docs/PROJECT_STATUS.md", import.meta.url), "utf8");
|
|
6
6
|
const keyEndpoints = await readFile(
|
|
7
7
|
new URL("../../src/services/vtex/docs/vtex-key-endpoints.md", import.meta.url),
|
|
@@ -12,15 +12,23 @@ describe("VTEX commercial conditions documentation", () => {
|
|
|
12
12
|
"utf8"
|
|
13
13
|
);
|
|
14
14
|
expect(projectStatus).toContain("`35` tools VTEX.");
|
|
15
|
-
expect(projectStatus).toContain("condiciones comerciales
|
|
16
|
-
expect(keyEndpoints).toContain("
|
|
17
|
-
expect(keyEndpoints).toContain("
|
|
15
|
+
expect(projectStatus).toContain("condiciones comerciales solo lectura oficial");
|
|
16
|
+
expect(keyEndpoints).toContain("Commercial conditions Catalog reads and legacy payment rules writes");
|
|
17
|
+
expect(keyEndpoints).toContain("/api/catalog_system/pvt/commercialcondition/list");
|
|
18
|
+
expect(keyEndpoints).toContain("manually in VTEX Admin");
|
|
18
19
|
expect(keyEndpoints).toContain("`vtex_payment_rules`");
|
|
19
20
|
expect(dashboardCapabilities).toContain(
|
|
20
21
|
"Gesti\xF3n de Condiciones Comerciales y Reglas de Pago"
|
|
21
22
|
);
|
|
22
23
|
expect(dashboardCapabilities).toContain("`vtex_commercial_conditions`");
|
|
23
24
|
expect(dashboardCapabilities).toContain("`vtex_payment_rules`");
|
|
25
|
+
expect(dashboardCapabilities).toContain("solo permite listar y consultar condiciones comerciales");
|
|
26
|
+
expect(dashboardCapabilities).toContain(
|
|
27
|
+
"crear manualmente la condici\xF3n faltante en VTEX Admin"
|
|
28
|
+
);
|
|
29
|
+
expect(dashboardCapabilities).not.toContain(
|
|
30
|
+
"primero conviene administrar esa condici\xF3n y sus reglas desde `vtex_commercial_conditions`"
|
|
31
|
+
);
|
|
24
32
|
});
|
|
25
33
|
});
|
|
26
34
|
//# sourceMappingURL=vtex-commercial-conditions-docs.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../tests/vtex/vtex-commercial-conditions-docs.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { readFile } from \"node:fs/promises\";\nimport { describe, expect, it } from \"vitest\";\n\ndescribe(\"VTEX commercial conditions documentation\", () => {\n it(\"documents the
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,4CAA4C,MAAM;AACzD,KAAG,
|
|
4
|
+
"sourcesContent": ["import { readFile } from \"node:fs/promises\";\nimport { describe, expect, it } from \"vitest\";\n\ndescribe(\"VTEX commercial conditions documentation\", () => {\n it(\"documents the corrected VTEX commercial conditions capability across project docs\", async () => {\n const projectStatus = await readFile(new URL(\"../../docs/PROJECT_STATUS.md\", import.meta.url), \"utf8\");\n const keyEndpoints = await readFile(\n new URL(\"../../src/services/vtex/docs/vtex-key-endpoints.md\", import.meta.url),\n \"utf8\"\n );\n const dashboardCapabilities = await readFile(\n new URL(\"../../../bi-mcp-dashboard/docs/content/CAPACIDADES_MCP.md\", import.meta.url),\n \"utf8\"\n );\n\n expect(projectStatus).toContain(\"`35` tools VTEX.\");\n expect(projectStatus).toContain(\"condiciones comerciales solo lectura oficial\");\n\n expect(keyEndpoints).toContain(\"Commercial conditions Catalog reads and legacy payment rules writes\");\n expect(keyEndpoints).toContain(\"/api/catalog_system/pvt/commercialcondition/list\");\n expect(keyEndpoints).toContain(\"manually in VTEX Admin\");\n expect(keyEndpoints).toContain(\"`vtex_payment_rules`\");\n\n expect(dashboardCapabilities).toContain(\n \"Gesti\u00F3n de Condiciones Comerciales y Reglas de Pago\"\n );\n expect(dashboardCapabilities).toContain(\"`vtex_commercial_conditions`\");\n expect(dashboardCapabilities).toContain(\"`vtex_payment_rules`\");\n expect(dashboardCapabilities).toContain(\"solo permite listar y consultar condiciones comerciales\");\n expect(dashboardCapabilities).toContain(\n \"crear manualmente la condici\u00F3n faltante en VTEX Admin\"\n );\n expect(dashboardCapabilities).not.toContain(\n \"primero conviene administrar esa condici\u00F3n y sus reglas desde `vtex_commercial_conditions`\"\n );\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,4CAA4C,MAAM;AACzD,KAAG,qFAAqF,YAAY;AAClG,UAAM,gBAAgB,MAAM,SAAS,IAAI,IAAI,gCAAgC,YAAY,GAAG,GAAG,MAAM;AACrG,UAAM,eAAe,MAAM;AAAA,MACzB,IAAI,IAAI,sDAAsD,YAAY,GAAG;AAAA,MAC7E;AAAA,IACF;AACA,UAAM,wBAAwB,MAAM;AAAA,MAClC,IAAI,IAAI,6DAA6D,YAAY,GAAG;AAAA,MACpF;AAAA,IACF;AAEA,WAAO,aAAa,EAAE,UAAU,kBAAkB;AAClD,WAAO,aAAa,EAAE,UAAU,8CAA8C;AAE9E,WAAO,YAAY,EAAE,UAAU,qEAAqE;AACpG,WAAO,YAAY,EAAE,UAAU,kDAAkD;AACjF,WAAO,YAAY,EAAE,UAAU,wBAAwB;AACvD,WAAO,YAAY,EAAE,UAAU,sBAAsB;AAErD,WAAO,qBAAqB,EAAE;AAAA,MAC5B;AAAA,IACF;AACA,WAAO,qBAAqB,EAAE,UAAU,8BAA8B;AACtE,WAAO,qBAAqB,EAAE,UAAU,sBAAsB;AAC9D,WAAO,qBAAqB,EAAE,UAAU,yDAAyD;AACjG,WAAO,qBAAqB,EAAE;AAAA,MAC5B;AAAA,IACF;AACA,WAAO,qBAAqB,EAAE,IAAI;AAAA,MAChC;AAAA,IACF;AAAA,EACF,CAAC;AACH,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|