@yoryoboy/bi-mcp 1.13.0 → 1.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/.tsbuildinfo +1 -1
- package/dist/index.js +30 -0
- package/dist/index.js.map +2 -2
- package/dist/mcp-use.json +2 -2
- package/dist/src/services/vtex/__tests__/vtex-payments.test.js +95 -0
- package/dist/src/services/vtex/__tests__/vtex-payments.test.js.map +7 -0
- package/dist/src/services/vtex/vtex-payments-write.js +64 -0
- package/dist/src/services/vtex/vtex-payments-write.js.map +7 -0
- package/dist/src/services/vtex/vtex-payments.js +43 -0
- package/dist/src/services/vtex/vtex-payments.js.map +7 -0
- package/dist/src/tools/vtex/__tests__/commercial-condition-references.test.js +14 -0
- package/dist/src/tools/vtex/__tests__/commercial-condition-references.test.js.map +7 -0
- package/dist/src/tools/vtex/__tests__/commercial-conditions.test.js +276 -0
- package/dist/src/tools/vtex/__tests__/commercial-conditions.test.js.map +7 -0
- package/dist/src/tools/vtex/__tests__/payment-rules.test.js +253 -0
- package/dist/src/tools/vtex/__tests__/payment-rules.test.js.map +7 -0
- package/dist/src/tools/vtex/catalog-admin-products-skus.js +3 -1
- package/dist/src/tools/vtex/catalog-admin-products-skus.js.map +2 -2
- package/dist/src/tools/vtex/commercial-conditions.js +220 -0
- package/dist/src/tools/vtex/commercial-conditions.js.map +7 -0
- package/dist/src/tools/vtex/create-sku.js +3 -1
- package/dist/src/tools/vtex/create-sku.js.map +2 -2
- package/dist/src/tools/vtex/index.js +2 -0
- package/dist/src/tools/vtex/index.js.map +2 -2
- package/dist/src/tools/vtex/payment-rules.js +229 -0
- package/dist/src/tools/vtex/payment-rules.js.map +7 -0
- package/dist/tests/vtex/vtex-commercial-conditions-docs.test.js +26 -0
- package/dist/tests/vtex/vtex-commercial-conditions-docs.test.js.map +7 -0
- package/dist/tests/vtex/vtex-commercial-conditions-surface.test.js +42 -0
- package/dist/tests/vtex/vtex-commercial-conditions-surface.test.js.map +7 -0
- package/dist/tests/vtex/vtex-commercial-conditions-workflow.test.js +190 -0
- package/dist/tests/vtex/vtex-commercial-conditions-workflow.test.js.map +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { error, object } from "mcp-use/server";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { formatVtexError } from "../../services/vtex/vtex-api.js";
|
|
4
|
+
import {
|
|
5
|
+
getCommercialCondition,
|
|
6
|
+
listCommercialConditions
|
|
7
|
+
} from "../../services/vtex/vtex-payments.js";
|
|
8
|
+
import {
|
|
9
|
+
createCommercialCondition,
|
|
10
|
+
deleteCommercialCondition,
|
|
11
|
+
updateCommercialCondition
|
|
12
|
+
} from "../../services/vtex/vtex-payments-write.js";
|
|
13
|
+
import { toSnakeCaseKeys } from "../../utils/case-conversion.js";
|
|
14
|
+
import { stripNulls } from "../../utils/strip-payload.js";
|
|
15
|
+
import {
|
|
16
|
+
buildWriteSuccessResponse,
|
|
17
|
+
confirmationSchemaField,
|
|
18
|
+
handleVtexWriteError,
|
|
19
|
+
requireExplicitConfirmation,
|
|
20
|
+
resolveVtexWriteProfile
|
|
21
|
+
} from "./write-helpers.js";
|
|
22
|
+
const commercialConditionWarnings = {
|
|
23
|
+
delete: "Deleting a commercial condition can break linked payment rules and installment visibility until dependent rules are updated."
|
|
24
|
+
};
|
|
25
|
+
const requiredProfileIdSchemaField = z.string().trim().min(1).describe("Explicit VTEX profile id to use for this operation.");
|
|
26
|
+
const commercialConditionIdSchemaField = z.number().int().positive().describe("Positive VTEX commercial condition identifier.");
|
|
27
|
+
const conditionRowsSchema = ["id", "name", "is_active"];
|
|
28
|
+
function readValue(record, ...keys) {
|
|
29
|
+
for (const key of keys) {
|
|
30
|
+
if (key in record) {
|
|
31
|
+
return record[key];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
const listActionSchema = z.object({
|
|
37
|
+
action: z.literal("list"),
|
|
38
|
+
profileId: requiredProfileIdSchemaField,
|
|
39
|
+
search: z.string().trim().min(1).optional().describe("Optional text filter for condition name lookup.")
|
|
40
|
+
});
|
|
41
|
+
const getActionSchema = z.object({
|
|
42
|
+
action: z.literal("get"),
|
|
43
|
+
profileId: requiredProfileIdSchemaField,
|
|
44
|
+
commercialConditionId: commercialConditionIdSchemaField
|
|
45
|
+
});
|
|
46
|
+
const createActionSchema = z.object({
|
|
47
|
+
action: z.literal("create"),
|
|
48
|
+
profileId: requiredProfileIdSchemaField,
|
|
49
|
+
name: z.string().trim().min(1).describe("Commercial condition name."),
|
|
50
|
+
description: z.string().trim().min(1).optional().describe("Optional internal description."),
|
|
51
|
+
isActive: z.boolean().optional().describe("Whether the condition should remain active.")
|
|
52
|
+
});
|
|
53
|
+
const updateActionSchema = z.object({
|
|
54
|
+
action: z.literal("update"),
|
|
55
|
+
profileId: requiredProfileIdSchemaField,
|
|
56
|
+
commercialConditionId: commercialConditionIdSchemaField,
|
|
57
|
+
name: z.string().trim().min(1).optional().describe("Updated commercial condition name."),
|
|
58
|
+
description: z.string().trim().min(1).optional().describe("Updated internal description."),
|
|
59
|
+
isActive: z.boolean().optional().describe("Updated condition active flag.")
|
|
60
|
+
}).refine((value) => value.name !== void 0 || value.description !== void 0 || value.isActive !== void 0, {
|
|
61
|
+
message: "At least one commercial condition field must be provided.",
|
|
62
|
+
path: ["name"]
|
|
63
|
+
});
|
|
64
|
+
const deleteActionSchema = z.object({
|
|
65
|
+
action: z.literal("delete"),
|
|
66
|
+
profileId: requiredProfileIdSchemaField,
|
|
67
|
+
commercialConditionId: commercialConditionIdSchemaField,
|
|
68
|
+
confirmed: confirmationSchemaField
|
|
69
|
+
});
|
|
70
|
+
const commercialConditionsSchema = z.discriminatedUnion("action", [
|
|
71
|
+
listActionSchema,
|
|
72
|
+
getActionSchema,
|
|
73
|
+
createActionSchema,
|
|
74
|
+
updateActionSchema,
|
|
75
|
+
deleteActionSchema
|
|
76
|
+
]);
|
|
77
|
+
async function commercialConditionsHandler(params) {
|
|
78
|
+
switch (params.action) {
|
|
79
|
+
case "list": {
|
|
80
|
+
try {
|
|
81
|
+
const conditions = await listCommercialConditions(params.profileId, params.search);
|
|
82
|
+
return object({
|
|
83
|
+
metadata: stripNulls({
|
|
84
|
+
total: conditions.length,
|
|
85
|
+
profile_id: params.profileId,
|
|
86
|
+
search: params.search
|
|
87
|
+
}),
|
|
88
|
+
conditions_schema: conditionRowsSchema,
|
|
89
|
+
conditions: conditions.map((condition) => [
|
|
90
|
+
readValue(condition, "id", "Id"),
|
|
91
|
+
readValue(condition, "name", "Name"),
|
|
92
|
+
readValue(condition, "isActive", "IsActive", "is_active")
|
|
93
|
+
])
|
|
94
|
+
});
|
|
95
|
+
} catch (err) {
|
|
96
|
+
return error(formatVtexError(err, "Failed to list VTEX commercial conditions"));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
case "get": {
|
|
100
|
+
try {
|
|
101
|
+
const condition = await getCommercialCondition(params.profileId, params.commercialConditionId);
|
|
102
|
+
return object({
|
|
103
|
+
profile_id: params.profileId,
|
|
104
|
+
commercial_condition_id: params.commercialConditionId,
|
|
105
|
+
condition: toSnakeCaseKeys(condition)
|
|
106
|
+
});
|
|
107
|
+
} catch (err) {
|
|
108
|
+
return error(
|
|
109
|
+
formatVtexError(
|
|
110
|
+
err,
|
|
111
|
+
`Failed to fetch VTEX commercial condition ${params.commercialConditionId}`
|
|
112
|
+
)
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
case "create": {
|
|
117
|
+
try {
|
|
118
|
+
const profileResolution = await resolveVtexWriteProfile(params.profileId);
|
|
119
|
+
if (!profileResolution.ok) {
|
|
120
|
+
return profileResolution.response;
|
|
121
|
+
}
|
|
122
|
+
const created = await createCommercialCondition(profileResolution.value.profileId, {
|
|
123
|
+
Name: params.name,
|
|
124
|
+
...params.description !== void 0 ? { Description: params.description } : {},
|
|
125
|
+
...params.isActive !== void 0 ? { IsActive: params.isActive } : {}
|
|
126
|
+
});
|
|
127
|
+
return buildWriteSuccessResponse({
|
|
128
|
+
profileId: profileResolution.value.profileId,
|
|
129
|
+
operation: "commercial_conditions_create",
|
|
130
|
+
resourceId: created.id == null ? void 0 : String(created.id),
|
|
131
|
+
riskLevel: "low",
|
|
132
|
+
message: "Commercial condition created. You can now link it to payment rules or SKU assignments as needed.",
|
|
133
|
+
before: null,
|
|
134
|
+
after: created
|
|
135
|
+
});
|
|
136
|
+
} catch (err) {
|
|
137
|
+
return handleVtexWriteError(err, "Failed to create VTEX commercial condition");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
case "update": {
|
|
141
|
+
try {
|
|
142
|
+
const profileResolution = await resolveVtexWriteProfile(params.profileId);
|
|
143
|
+
if (!profileResolution.ok) {
|
|
144
|
+
return profileResolution.response;
|
|
145
|
+
}
|
|
146
|
+
const before = await getCommercialCondition(
|
|
147
|
+
profileResolution.value.profileId,
|
|
148
|
+
params.commercialConditionId
|
|
149
|
+
);
|
|
150
|
+
const updated = await updateCommercialCondition(
|
|
151
|
+
profileResolution.value.profileId,
|
|
152
|
+
params.commercialConditionId,
|
|
153
|
+
{
|
|
154
|
+
...params.name !== void 0 ? { Name: params.name } : {},
|
|
155
|
+
...params.description !== void 0 ? { Description: params.description } : {},
|
|
156
|
+
...params.isActive !== void 0 ? { IsActive: params.isActive } : {}
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
return buildWriteSuccessResponse({
|
|
160
|
+
profileId: profileResolution.value.profileId,
|
|
161
|
+
operation: "commercial_conditions_update",
|
|
162
|
+
resourceId: String(params.commercialConditionId),
|
|
163
|
+
riskLevel: "medium",
|
|
164
|
+
message: "Commercial condition updated. Review linked payment rules and checkout behavior to confirm the intended installment strategy.",
|
|
165
|
+
before,
|
|
166
|
+
after: updated
|
|
167
|
+
});
|
|
168
|
+
} catch (err) {
|
|
169
|
+
return handleVtexWriteError(
|
|
170
|
+
err,
|
|
171
|
+
`Failed to update VTEX commercial condition ${params.commercialConditionId}`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
case "delete": {
|
|
176
|
+
const confirmationResponse = requireExplicitConfirmation(
|
|
177
|
+
params.confirmed,
|
|
178
|
+
"commercial_conditions_delete",
|
|
179
|
+
{
|
|
180
|
+
commercial_condition_id: params.commercialConditionId,
|
|
181
|
+
warnings: [commercialConditionWarnings.delete]
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
if (confirmationResponse) {
|
|
185
|
+
return confirmationResponse;
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
const profileResolution = await resolveVtexWriteProfile(params.profileId);
|
|
189
|
+
if (!profileResolution.ok) {
|
|
190
|
+
return profileResolution.response;
|
|
191
|
+
}
|
|
192
|
+
await deleteCommercialCondition(
|
|
193
|
+
profileResolution.value.profileId,
|
|
194
|
+
params.commercialConditionId
|
|
195
|
+
);
|
|
196
|
+
return buildWriteSuccessResponse({
|
|
197
|
+
profileId: profileResolution.value.profileId,
|
|
198
|
+
operation: "commercial_conditions_delete",
|
|
199
|
+
resourceId: String(params.commercialConditionId),
|
|
200
|
+
riskLevel: "high",
|
|
201
|
+
confirmed: true,
|
|
202
|
+
message: "Commercial condition deleted. Confirm linked payment rules and SKU assignments still reflect the intended installment strategy.",
|
|
203
|
+
warnings: [commercialConditionWarnings.delete],
|
|
204
|
+
before: null,
|
|
205
|
+
after: null
|
|
206
|
+
});
|
|
207
|
+
} catch (err) {
|
|
208
|
+
return handleVtexWriteError(
|
|
209
|
+
err,
|
|
210
|
+
`Failed to delete VTEX commercial condition ${params.commercialConditionId}`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
export {
|
|
217
|
+
commercialConditionsHandler,
|
|
218
|
+
commercialConditionsSchema
|
|
219
|
+
};
|
|
220
|
+
//# sourceMappingURL=commercial-conditions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 {\n createCommercialCondition,\n deleteCommercialCondition,\n updateCommercialCondition,\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 commercialConditionWarnings = {\n delete:\n \"Deleting a commercial condition can break linked payment rules and installment visibility until dependent rules are updated.\",\n} as const;\n\nconst requiredProfileIdSchemaField = z\n .string()\n .trim()\n .min(1)\n .describe(\"Explicit VTEX profile id to use for this operation.\");\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\nconst createActionSchema = z.object({\n action: z.literal(\"create\"),\n profileId: requiredProfileIdSchemaField,\n name: z.string().trim().min(1).describe(\"Commercial condition name.\"),\n description: z.string().trim().min(1).optional().describe(\"Optional internal description.\"),\n isActive: z.boolean().optional().describe(\"Whether the condition should remain active.\"),\n});\n\nconst updateActionSchema = z\n .object({\n action: z.literal(\"update\"),\n profileId: requiredProfileIdSchemaField,\n commercialConditionId: commercialConditionIdSchemaField,\n name: z.string().trim().min(1).optional().describe(\"Updated commercial condition name.\"),\n description: z.string().trim().min(1).optional().describe(\"Updated internal description.\"),\n isActive: z.boolean().optional().describe(\"Updated condition active flag.\"),\n })\n .refine((value) => value.name !== undefined || value.description !== undefined || value.isActive !== undefined, {\n message: \"At least one commercial condition field must be provided.\",\n path: [\"name\"],\n });\n\nconst deleteActionSchema = z.object({\n action: z.literal(\"delete\"),\n profileId: requiredProfileIdSchemaField,\n commercialConditionId: commercialConditionIdSchemaField,\n confirmed: confirmationSchemaField,\n});\n\nexport const commercialConditionsSchema = z.discriminatedUnion(\"action\", [\n listActionSchema,\n getActionSchema,\n createActionSchema,\n updateActionSchema,\n deleteActionSchema,\n]);\n\nexport async function commercialConditionsHandler(\n params: z.infer<typeof commercialConditionsSchema>\n) {\n switch (params.action) {\n case \"list\": {\n try {\n const conditions = await listCommercialConditions(params.profileId, params.search);\n\n return object({\n metadata: stripNulls({\n total: conditions.length,\n profile_id: params.profileId,\n search: params.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 try {\n const condition = await getCommercialCondition(params.profileId, params.commercialConditionId);\n\n return object({\n profile_id: params.profileId,\n commercial_condition_id: params.commercialConditionId,\n condition: toSnakeCaseKeys(condition),\n });\n } catch (err) {\n return error(\n formatVtexError(\n err,\n `Failed to fetch VTEX commercial condition ${params.commercialConditionId}`\n )\n );\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 createCommercialCondition(profileResolution.value.profileId, {\n Name: params.name,\n ...(params.description !== undefined ? { Description: params.description } : {}),\n ...(params.isActive !== undefined ? { IsActive: params.isActive } : {}),\n });\n\n return buildWriteSuccessResponse({\n profileId: profileResolution.value.profileId,\n operation: \"commercial_conditions_create\",\n resourceId: created.id == null ? undefined : String(created.id),\n riskLevel: \"low\",\n message:\n \"Commercial condition created. You can now link it to payment rules or SKU assignments as needed.\",\n before: null,\n after: created,\n });\n } catch (err) {\n return handleVtexWriteError(err, \"Failed to create VTEX commercial condition\");\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 before = await getCommercialCondition(\n profileResolution.value.profileId,\n params.commercialConditionId\n );\n\n const updated = await updateCommercialCondition(\n profileResolution.value.profileId,\n params.commercialConditionId,\n {\n ...(params.name !== undefined ? { Name: params.name } : {}),\n ...(params.description !== undefined ? { Description: params.description } : {}),\n ...(params.isActive !== undefined ? { IsActive: params.isActive } : {}),\n }\n );\n\n return buildWriteSuccessResponse({\n profileId: profileResolution.value.profileId,\n operation: \"commercial_conditions_update\",\n resourceId: String(params.commercialConditionId),\n riskLevel: \"medium\",\n message:\n \"Commercial condition updated. Review linked payment rules and checkout behavior to confirm the intended installment strategy.\",\n before,\n after: updated,\n });\n } catch (err) {\n return handleVtexWriteError(\n err,\n `Failed to update VTEX commercial condition ${params.commercialConditionId}`\n );\n }\n }\n\n case \"delete\": {\n const confirmationResponse = requireExplicitConfirmation(\n params.confirmed,\n \"commercial_conditions_delete\",\n {\n commercial_condition_id: params.commercialConditionId,\n warnings: [commercialConditionWarnings.delete],\n }\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 deleteCommercialCondition(\n profileResolution.value.profileId,\n params.commercialConditionId\n );\n\n return buildWriteSuccessResponse({\n profileId: profileResolution.value.profileId,\n operation: \"commercial_conditions_delete\",\n resourceId: String(params.commercialConditionId),\n riskLevel: \"high\",\n confirmed: true,\n message:\n \"Commercial condition deleted. Confirm linked payment rules and SKU assignments still reflect the intended installment strategy.\",\n warnings: [commercialConditionWarnings.delete],\n before: null,\n after: null,\n });\n } catch (err) {\n return handleVtexWriteError(\n err,\n `Failed to delete VTEX commercial condition ${params.commercialConditionId}`\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;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,8BAA8B;AAAA,EAClC,QACE;AACJ;AAEA,MAAM,+BAA+B,EAClC,OAAO,EACP,KAAK,EACL,IAAI,CAAC,EACL,SAAS,qDAAqD;AAEjE,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,CAA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,IAEA,KAAK,UAAU;AACb,YAAM,uBAAuB;AAAA,QAC3B,OAAO;AAAA,QACP;AAAA,QACA;AAAA,UACE,yBAAyB,OAAO;AAAA,UAChC,UAAU,CAAC,4BAA4B,MAAM;AAAA,QAC/C;AAAA,MACF;AACA,UAAI,sBAAsB;AACxB,eAAO;AAAA,MACT;AAEA,UAAI;AACF,cAAM,oBAAoB,MAAM,wBAAwB,OAAO,SAAS;AACxE,YAAI,CAAC,kBAAkB,IAAI;AACzB,iBAAO,kBAAkB;AAAA,QAC3B;AAEA,cAAM;AAAA,UACJ,kBAAkB,MAAM;AAAA,UACxB,OAAO;AAAA,QACT;AAEA,eAAO,0BAA0B;AAAA,UAC/B,WAAW,kBAAkB,MAAM;AAAA,UACnC,WAAW;AAAA,UACX,YAAY,OAAO,OAAO,qBAAqB;AAAA,UAC/C,WAAW;AAAA,UACX,WAAW;AAAA,UACX,SACE;AAAA,UACF,UAAU,CAAC,4BAA4B,MAAM;AAAA,UAC7C,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH,SAAS,KAAK;AACZ,eAAO;AAAA,UACL;AAAA,UACA,8CAA8C,OAAO,qBAAqB;AAAA,QAC5E;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -25,7 +25,9 @@ const createSkuSchema = z.object({
|
|
|
25
25
|
measurementUnit: z.string().optional().describe("Measurement unit, for example `un`."),
|
|
26
26
|
unitMultiplier: z.number().positive().optional().describe("Unit multiplier."),
|
|
27
27
|
manufacturerCode: z.string().optional().describe("Manufacturer code."),
|
|
28
|
-
commercialConditionId: z.number().int().positive().optional().describe(
|
|
28
|
+
commercialConditionId: z.number().int().positive().optional().describe(
|
|
29
|
+
"Commercial condition ID. Use vtex_commercial_conditions to manage condition records and vtex_payment_rules to configure linked installment/payment behavior."
|
|
30
|
+
)
|
|
29
31
|
});
|
|
30
32
|
async function createSkuHandler({
|
|
31
33
|
profileId,
|
|
@@ -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.number().int().positive().optional().describe(\"Commercial condition ID.\"),\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
|
-
"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,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SkuEan } 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 manage condition records 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
|
+
"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,O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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
|
}
|
|
@@ -31,6 +31,8 @@ export * from "./update-product-basic-fields.js";
|
|
|
31
31
|
export * from "./update-sku-basic-fields.js";
|
|
32
32
|
export * from "./create-product.js";
|
|
33
33
|
export * from "./create-sku.js";
|
|
34
|
+
export * from "./commercial-conditions.js";
|
|
35
|
+
export * from "./payment-rules.js";
|
|
34
36
|
export * from "./create-brand.js";
|
|
35
37
|
export * from "./update-brand.js";
|
|
36
38
|
export * from "./create-category.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/vtex/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from \"./orders-summary.js\";\nexport * from \"./order-details.js\";\nexport * from \"./inventory-check.js\";\nexport * from \"./warehouse-inventory.js\";\nexport * from \"./update-inventory.js\";\nexport * from \"./update-lead-time.js\";\nexport * from \"./toggle-unlimited-quantity.js\";\nexport * from \"./sku-price.js\";\nexport * from \"./computed-price.js\";\nexport * from \"./product-offers.js\";\nexport * from \"./sku-offers.js\";\nexport * from \"./get-category-tree.js\";\nexport * from \"./list-categories.js\";\nexport * from \"./get-category.js\";\nexport * from \"./get-brand.js\";\nexport * from \"./list-brands.js\";\nexport * from \"./list-specification-groups.js\";\nexport * from \"./get-product.js\";\nexport * from \"./get-product-specifications.js\";\nexport * from \"./list-products.js\";\nexport * from \"./list-products-by-category.js\";\nexport * from \"./get-sku.js\";\nexport * from \"./list-skus-by-product.js\";\nexport * from \"./update-sku-price.js\";\nexport * from \"./delete-sku-price.js\";\nexport * from \"./upsert-fixed-price.js\";\nexport * from \"./delete-fixed-price.js\";\nexport * from \"./activate-sku.js\";\nexport * from \"./deactivate-sku.js\";\nexport * from \"./update-product-basic-fields.js\";\nexport * from \"./update-sku-basic-fields.js\";\nexport * from \"./create-product.js\";\nexport * from \"./create-sku.js\";\n// Helper-only flow: create-product-with-sku stays internal until dedicated\n// product/SKU admin wrappers complete full rationalization.\nexport * from \"./create-brand.js\";\nexport * from \"./update-brand.js\";\nexport * from \"./create-category.js\";\nexport * from \"./update-category.js\";\nexport * from \"./move-category.js\";\nexport * from \"./create-specification.js\";\nexport * from \"./create-specification-value.js\";\nexport * from \"./associate-specification.js\";\nexport * from \"./delete-product-specification.js\";\nexport * from \"./delete-all-product-specifications.js\";\nexport * from \"./delete-brand.js\";\nexport * from \"./delete-catalog-image.js\";\nexport * from \"./delete-sku-specification.js\";\nexport * from \"./delete-all-sku-specifications.js\";\nexport * from \"./attach-catalog-image.js\";\nexport * from \"./catalog-admin-products-skus.js\";\nexport * from \"./cancel-order.js\";\nexport * from \"./invoice-order.js\";\nexport * from \"./add-order-tracking.js\";\nexport * from \"./profile-resolution.js\";\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export * from \"./orders-summary.js\";\nexport * from \"./order-details.js\";\nexport * from \"./inventory-check.js\";\nexport * from \"./warehouse-inventory.js\";\nexport * from \"./update-inventory.js\";\nexport * from \"./update-lead-time.js\";\nexport * from \"./toggle-unlimited-quantity.js\";\nexport * from \"./sku-price.js\";\nexport * from \"./computed-price.js\";\nexport * from \"./product-offers.js\";\nexport * from \"./sku-offers.js\";\nexport * from \"./get-category-tree.js\";\nexport * from \"./list-categories.js\";\nexport * from \"./get-category.js\";\nexport * from \"./get-brand.js\";\nexport * from \"./list-brands.js\";\nexport * from \"./list-specification-groups.js\";\nexport * from \"./get-product.js\";\nexport * from \"./get-product-specifications.js\";\nexport * from \"./list-products.js\";\nexport * from \"./list-products-by-category.js\";\nexport * from \"./get-sku.js\";\nexport * from \"./list-skus-by-product.js\";\nexport * from \"./update-sku-price.js\";\nexport * from \"./delete-sku-price.js\";\nexport * from \"./upsert-fixed-price.js\";\nexport * from \"./delete-fixed-price.js\";\nexport * from \"./activate-sku.js\";\nexport * from \"./deactivate-sku.js\";\nexport * from \"./update-product-basic-fields.js\";\nexport * from \"./update-sku-basic-fields.js\";\nexport * from \"./create-product.js\";\nexport * from \"./create-sku.js\";\nexport * from \"./commercial-conditions.js\";\nexport * from \"./payment-rules.js\";\n// Helper-only flow: create-product-with-sku stays internal until dedicated\n// product/SKU admin wrappers complete full rationalization.\nexport * from \"./create-brand.js\";\nexport * from \"./update-brand.js\";\nexport * from \"./create-category.js\";\nexport * from \"./update-category.js\";\nexport * from \"./move-category.js\";\nexport * from \"./create-specification.js\";\nexport * from \"./create-specification-value.js\";\nexport * from \"./associate-specification.js\";\nexport * from \"./delete-product-specification.js\";\nexport * from \"./delete-all-product-specifications.js\";\nexport * from \"./delete-brand.js\";\nexport * from \"./delete-catalog-image.js\";\nexport * from \"./delete-sku-specification.js\";\nexport * from \"./delete-all-sku-specifications.js\";\nexport * from \"./attach-catalog-image.js\";\nexport * from \"./catalog-admin-products-skus.js\";\nexport * from \"./cancel-order.js\";\nexport * from \"./invoice-order.js\";\nexport * from \"./add-order-tracking.js\";\nexport * from \"./profile-resolution.js\";\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { error, object } from "mcp-use/server";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { formatVtexError } from "../../services/vtex/vtex-api.js";
|
|
4
|
+
import { getPaymentRule, listPaymentRules } from "../../services/vtex/vtex-payments.js";
|
|
5
|
+
import {
|
|
6
|
+
createPaymentRule,
|
|
7
|
+
deletePaymentRule,
|
|
8
|
+
updatePaymentRule
|
|
9
|
+
} from "../../services/vtex/vtex-payments-write.js";
|
|
10
|
+
import { toSnakeCaseKeys } from "../../utils/case-conversion.js";
|
|
11
|
+
import { stripNulls } from "../../utils/strip-payload.js";
|
|
12
|
+
import {
|
|
13
|
+
buildWriteSuccessResponse,
|
|
14
|
+
confirmationSchemaField,
|
|
15
|
+
handleVtexWriteError,
|
|
16
|
+
requireExplicitConfirmation,
|
|
17
|
+
resolveVtexWriteProfile
|
|
18
|
+
} from "./write-helpers.js";
|
|
19
|
+
const requiredProfileIdSchemaField = z.string().trim().min(1).describe("Explicit VTEX profile id to use for this operation.");
|
|
20
|
+
const positiveIntegerSchemaField = (description) => z.number().int().positive().describe(description);
|
|
21
|
+
const installmentsSchemaField = z.array(
|
|
22
|
+
z.object({
|
|
23
|
+
count: positiveIntegerSchemaField("Installment count."),
|
|
24
|
+
interest: z.boolean().describe("Whether this installment carries interest.")
|
|
25
|
+
})
|
|
26
|
+
).min(1).describe("Installment configuration rows for the payment rule.");
|
|
27
|
+
const paymentRuleWarnings = {
|
|
28
|
+
delete: "Deleting a payment rule can immediately remove installment options from checkout for affected shoppers."
|
|
29
|
+
};
|
|
30
|
+
const paymentRuleRowsSchema = [
|
|
31
|
+
"id",
|
|
32
|
+
"commercial_condition_id",
|
|
33
|
+
"payment_system",
|
|
34
|
+
"sales_channel",
|
|
35
|
+
"restricted_by_condition"
|
|
36
|
+
];
|
|
37
|
+
function readValue(record, ...keys) {
|
|
38
|
+
for (const key of keys) {
|
|
39
|
+
if (key in record) {
|
|
40
|
+
return record[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
const listActionSchema = z.object({
|
|
46
|
+
action: z.literal("list"),
|
|
47
|
+
profileId: requiredProfileIdSchemaField,
|
|
48
|
+
commercialConditionId: positiveIntegerSchemaField(
|
|
49
|
+
"Optional commercial condition filter for payment rules."
|
|
50
|
+
).optional()
|
|
51
|
+
});
|
|
52
|
+
const getActionSchema = z.object({
|
|
53
|
+
action: z.literal("get"),
|
|
54
|
+
profileId: requiredProfileIdSchemaField,
|
|
55
|
+
ruleId: positiveIntegerSchemaField("Positive VTEX payment rule identifier.")
|
|
56
|
+
});
|
|
57
|
+
const createActionSchema = z.object({
|
|
58
|
+
action: z.literal("create"),
|
|
59
|
+
profileId: requiredProfileIdSchemaField,
|
|
60
|
+
commercialConditionId: positiveIntegerSchemaField(
|
|
61
|
+
"Commercial condition identifier linked to this payment rule."
|
|
62
|
+
),
|
|
63
|
+
paymentSystem: z.string().trim().min(1).describe("VTEX payment system identifier."),
|
|
64
|
+
salesChannel: z.string().trim().min(1).optional().describe("Optional VTEX sales channel identifier."),
|
|
65
|
+
restrictedByCondition: z.boolean().optional().describe("Whether checkout should restrict this rule to the linked commercial condition."),
|
|
66
|
+
installments: installmentsSchemaField
|
|
67
|
+
});
|
|
68
|
+
const updateActionSchema = z.object({
|
|
69
|
+
action: z.literal("update"),
|
|
70
|
+
profileId: requiredProfileIdSchemaField,
|
|
71
|
+
ruleId: positiveIntegerSchemaField("Positive VTEX payment rule identifier."),
|
|
72
|
+
commercialConditionId: positiveIntegerSchemaField(
|
|
73
|
+
"Commercial condition identifier linked to this payment rule."
|
|
74
|
+
).optional(),
|
|
75
|
+
paymentSystem: z.string().trim().min(1).optional().describe("Updated VTEX payment system identifier."),
|
|
76
|
+
salesChannel: z.string().trim().min(1).optional().describe("Updated VTEX sales channel identifier."),
|
|
77
|
+
restrictedByCondition: z.boolean().optional().describe("Updated restricted-by-condition flag."),
|
|
78
|
+
installments: installmentsSchemaField.optional()
|
|
79
|
+
}).refine(
|
|
80
|
+
(value) => value.commercialConditionId !== void 0 || value.paymentSystem !== void 0 || value.salesChannel !== void 0 || value.restrictedByCondition !== void 0 || value.installments !== void 0,
|
|
81
|
+
{
|
|
82
|
+
message: "At least one payment rule field must be provided.",
|
|
83
|
+
path: ["paymentSystem"]
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
const deleteActionSchema = z.object({
|
|
87
|
+
action: z.literal("delete"),
|
|
88
|
+
profileId: requiredProfileIdSchemaField,
|
|
89
|
+
ruleId: positiveIntegerSchemaField("Positive VTEX payment rule identifier."),
|
|
90
|
+
confirmed: confirmationSchemaField
|
|
91
|
+
});
|
|
92
|
+
const paymentRulesSchema = z.discriminatedUnion("action", [
|
|
93
|
+
listActionSchema,
|
|
94
|
+
getActionSchema,
|
|
95
|
+
createActionSchema,
|
|
96
|
+
updateActionSchema,
|
|
97
|
+
deleteActionSchema
|
|
98
|
+
]);
|
|
99
|
+
async function paymentRulesHandler(params) {
|
|
100
|
+
switch (params.action) {
|
|
101
|
+
case "list": {
|
|
102
|
+
try {
|
|
103
|
+
const rules = await listPaymentRules(params.profileId, {
|
|
104
|
+
commercialConditionId: params.commercialConditionId
|
|
105
|
+
});
|
|
106
|
+
return object({
|
|
107
|
+
metadata: stripNulls({
|
|
108
|
+
total: rules.length,
|
|
109
|
+
profile_id: params.profileId,
|
|
110
|
+
filters: params.commercialConditionId === void 0 ? void 0 : { commercial_condition_id: params.commercialConditionId }
|
|
111
|
+
}),
|
|
112
|
+
payment_rules_schema: paymentRuleRowsSchema,
|
|
113
|
+
payment_rules: rules.map((rule) => [
|
|
114
|
+
readValue(rule, "id", "Id"),
|
|
115
|
+
readValue(rule, "commercialConditionId", "CommercialConditionId", "commercial_condition_id"),
|
|
116
|
+
readValue(rule, "paymentSystem", "PaymentSystem", "payment_system"),
|
|
117
|
+
readValue(rule, "salesChannel", "SalesChannel", "sales_channel"),
|
|
118
|
+
readValue(
|
|
119
|
+
rule,
|
|
120
|
+
"restrictedByCondition",
|
|
121
|
+
"RestrictedByCondition",
|
|
122
|
+
"restricted_by_condition"
|
|
123
|
+
)
|
|
124
|
+
])
|
|
125
|
+
});
|
|
126
|
+
} catch (err) {
|
|
127
|
+
return error(formatVtexError(err, "Failed to list VTEX payment rules"));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
case "get": {
|
|
131
|
+
try {
|
|
132
|
+
const rule = await getPaymentRule(params.profileId, params.ruleId);
|
|
133
|
+
return object({
|
|
134
|
+
profile_id: params.profileId,
|
|
135
|
+
rule_id: params.ruleId,
|
|
136
|
+
payment_rule: toSnakeCaseKeys(rule)
|
|
137
|
+
});
|
|
138
|
+
} catch (err) {
|
|
139
|
+
return error(formatVtexError(err, `Failed to fetch VTEX payment rule ${params.ruleId}`));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
case "create": {
|
|
143
|
+
try {
|
|
144
|
+
const profileResolution = await resolveVtexWriteProfile(params.profileId);
|
|
145
|
+
if (!profileResolution.ok) {
|
|
146
|
+
return profileResolution.response;
|
|
147
|
+
}
|
|
148
|
+
const created = await createPaymentRule(profileResolution.value.profileId, {
|
|
149
|
+
commercialConditionId: params.commercialConditionId,
|
|
150
|
+
paymentSystem: params.paymentSystem,
|
|
151
|
+
...params.salesChannel !== void 0 ? { salesChannel: params.salesChannel } : {},
|
|
152
|
+
...params.restrictedByCondition !== void 0 ? { restrictedByCondition: params.restrictedByCondition } : {},
|
|
153
|
+
installments: params.installments
|
|
154
|
+
});
|
|
155
|
+
return buildWriteSuccessResponse({
|
|
156
|
+
profileId: profileResolution.value.profileId,
|
|
157
|
+
operation: "payment_rules_create",
|
|
158
|
+
resourceId: created.id == null ? void 0 : String(created.id),
|
|
159
|
+
riskLevel: "medium",
|
|
160
|
+
message: "Payment rule created. Review checkout installments and condition targeting to confirm the expected shopper experience.",
|
|
161
|
+
before: null,
|
|
162
|
+
after: created
|
|
163
|
+
});
|
|
164
|
+
} catch (err) {
|
|
165
|
+
return handleVtexWriteError(err, "Failed to create VTEX payment rule");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
case "update": {
|
|
169
|
+
try {
|
|
170
|
+
const profileResolution = await resolveVtexWriteProfile(params.profileId);
|
|
171
|
+
if (!profileResolution.ok) {
|
|
172
|
+
return profileResolution.response;
|
|
173
|
+
}
|
|
174
|
+
const updated = await updatePaymentRule(profileResolution.value.profileId, params.ruleId, {
|
|
175
|
+
...params.commercialConditionId !== void 0 ? { commercialConditionId: params.commercialConditionId } : {},
|
|
176
|
+
...params.paymentSystem !== void 0 ? { paymentSystem: params.paymentSystem } : {},
|
|
177
|
+
...params.salesChannel !== void 0 ? { salesChannel: params.salesChannel } : {},
|
|
178
|
+
...params.restrictedByCondition !== void 0 ? { restrictedByCondition: params.restrictedByCondition } : {},
|
|
179
|
+
...params.installments !== void 0 ? { installments: params.installments } : {}
|
|
180
|
+
});
|
|
181
|
+
return buildWriteSuccessResponse({
|
|
182
|
+
profileId: profileResolution.value.profileId,
|
|
183
|
+
operation: "payment_rules_update",
|
|
184
|
+
resourceId: String(params.ruleId),
|
|
185
|
+
riskLevel: "medium",
|
|
186
|
+
message: "Payment rule updated. Review checkout installments to confirm the expected payment options.",
|
|
187
|
+
before: null,
|
|
188
|
+
after: updated
|
|
189
|
+
});
|
|
190
|
+
} catch (err) {
|
|
191
|
+
return handleVtexWriteError(err, `Failed to update VTEX payment rule ${params.ruleId}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
case "delete": {
|
|
195
|
+
const confirmationResponse = requireExplicitConfirmation(params.confirmed, "payment_rules_delete", {
|
|
196
|
+
rule_id: params.ruleId,
|
|
197
|
+
warnings: [paymentRuleWarnings.delete]
|
|
198
|
+
});
|
|
199
|
+
if (confirmationResponse) {
|
|
200
|
+
return confirmationResponse;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
const profileResolution = await resolveVtexWriteProfile(params.profileId);
|
|
204
|
+
if (!profileResolution.ok) {
|
|
205
|
+
return profileResolution.response;
|
|
206
|
+
}
|
|
207
|
+
await deletePaymentRule(profileResolution.value.profileId, params.ruleId);
|
|
208
|
+
return buildWriteSuccessResponse({
|
|
209
|
+
profileId: profileResolution.value.profileId,
|
|
210
|
+
operation: "payment_rules_delete",
|
|
211
|
+
resourceId: String(params.ruleId),
|
|
212
|
+
riskLevel: "high",
|
|
213
|
+
confirmed: true,
|
|
214
|
+
message: "Payment rule deleted. Verify checkout no longer exposes the removed installment option to affected shoppers.",
|
|
215
|
+
warnings: [paymentRuleWarnings.delete],
|
|
216
|
+
before: null,
|
|
217
|
+
after: null
|
|
218
|
+
});
|
|
219
|
+
} catch (err) {
|
|
220
|
+
return handleVtexWriteError(err, `Failed to delete VTEX payment rule ${params.ruleId}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
export {
|
|
226
|
+
paymentRulesHandler,
|
|
227
|
+
paymentRulesSchema
|
|
228
|
+
};
|
|
229
|
+
//# sourceMappingURL=payment-rules.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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,EAClC,OAAO,EACP,KAAK,EACL,IAAI,CAAC,EACL,SAAS,qDAAqD;AAEjE,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,UAAU,EAAE,QAAQ,EAAE,SAAS,4CAA4C;AAAA,EAC7E,CAAC;AACH,EACC,IAAI,CAAC,EACL,SAAS,sDAAsD;AAElE,MAAM,sBAAsB;AAAA,EAC1B,QACE;AACJ;AAEA,MAAM,wBAAwB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,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,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AK;AACZ,eAAO,qBAAqB,KAAK,sCAAsC,OAAO,MAAM,EAAE;AAAA,MACxF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
describe("VTEX commercial conditions documentation", () => {
|
|
4
|
+
it("documents the new VTEX payments capability across project docs", async () => {
|
|
5
|
+
const projectStatus = await readFile(new URL("../../docs/PROJECT_STATUS.md", import.meta.url), "utf8");
|
|
6
|
+
const keyEndpoints = await readFile(
|
|
7
|
+
new URL("../../src/services/vtex/docs/vtex-key-endpoints.md", import.meta.url),
|
|
8
|
+
"utf8"
|
|
9
|
+
);
|
|
10
|
+
const dashboardCapabilities = await readFile(
|
|
11
|
+
new URL("../../../bi-mcp-dashboard/docs/content/CAPACIDADES_MCP.md", import.meta.url),
|
|
12
|
+
"utf8"
|
|
13
|
+
);
|
|
14
|
+
expect(projectStatus).toContain("`35` tools VTEX.");
|
|
15
|
+
expect(projectStatus).toContain("condiciones comerciales y reglas de pago");
|
|
16
|
+
expect(keyEndpoints).toContain("Legacy payments endpoints exposed with sandbox caveat");
|
|
17
|
+
expect(keyEndpoints).toContain("`vtex_commercial_conditions`");
|
|
18
|
+
expect(keyEndpoints).toContain("`vtex_payment_rules`");
|
|
19
|
+
expect(dashboardCapabilities).toContain(
|
|
20
|
+
"Gesti\xF3n de Condiciones Comerciales y Reglas de Pago"
|
|
21
|
+
);
|
|
22
|
+
expect(dashboardCapabilities).toContain("`vtex_commercial_conditions`");
|
|
23
|
+
expect(dashboardCapabilities).toContain("`vtex_payment_rules`");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=vtex-commercial-conditions-docs.test.js.map
|