@yoryoboy/bi-mcp 1.14.0 → 1.14.2
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-payments.test.js +12 -9
- package/dist/src/services/vtex/__tests__/vtex-payments.test.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__/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/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/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,uBAAu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gBAAgB,MAAM;AAAA,UACzC,WAAW;AAAA,UACX,SACE;AAAA,UACF,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,IAEA,KAAK,UAAU;AACb,YAAM,kBAAkB,mBAAmB,MAAM,MAAM;AAEvD,YAAM,uBAAuB,4BAA4B,gBAAgB,WAAW,wBAAwB;AAAA,QAC1G,SAAS,gBAAgB;AAAA,QACzB,UAAU,CAAC,oBAAoB,MAAM;AAAA,MACvC,CAAC;AACD,UAAI,sBAAsB;AACxB,eAAO;AAAA,MACT;AAEA,UAAI;AACF,cAAM,oBAAoB,MAAM,wBAAwB,gBAAgB,SAAS;AACjF,YAAI,CAAC,kBAAkB,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
|
}
|
|
@@ -1,19 +1,128 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
describe("VTEX commercial conditions server surface", () => {
|
|
4
|
+
it("registers and lists both tools through the MCP layer without schema compatibility failures", async () => {
|
|
5
|
+
const previousNodeEnv = process.env.NODE_ENV;
|
|
6
|
+
const previousTelemetry = process.env.MCP_USE_ANONYMIZED_TELEMETRY;
|
|
7
|
+
process.env.NODE_ENV = "production";
|
|
8
|
+
process.env.MCP_USE_ANONYMIZED_TELEMETRY = "false";
|
|
9
|
+
try {
|
|
10
|
+
const [
|
|
11
|
+
{ MCPServer, object },
|
|
12
|
+
{ MCPClient },
|
|
13
|
+
commercialConditionsModule,
|
|
14
|
+
paymentRulesModule
|
|
15
|
+
] = await Promise.all([
|
|
16
|
+
import("mcp-use/server"),
|
|
17
|
+
import("mcp-use"),
|
|
18
|
+
import("../../src/tools/vtex/commercial-conditions.js"),
|
|
19
|
+
import("../../src/tools/vtex/payment-rules.js")
|
|
20
|
+
]);
|
|
21
|
+
const server = new MCPServer({
|
|
22
|
+
name: "test-vtex-payments-server",
|
|
23
|
+
version: "1.0.0",
|
|
24
|
+
baseUrl: "http://localhost:3000"
|
|
25
|
+
});
|
|
26
|
+
server.tool(
|
|
27
|
+
{
|
|
28
|
+
name: "vtex_commercial_conditions",
|
|
29
|
+
description: "Read VTEX commercial conditions.",
|
|
30
|
+
schema: commercialConditionsModule.commercialConditionsSchema,
|
|
31
|
+
annotations: {
|
|
32
|
+
readOnlyHint: true,
|
|
33
|
+
destructiveHint: false,
|
|
34
|
+
openWorldHint: true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
async (params) => commercialConditionsModule.commercialConditionsHandler(params)
|
|
38
|
+
);
|
|
39
|
+
server.tool(
|
|
40
|
+
{
|
|
41
|
+
name: "vtex_payment_rules",
|
|
42
|
+
description: "Manage VTEX payment rules.",
|
|
43
|
+
schema: paymentRulesModule.paymentRulesSchema,
|
|
44
|
+
annotations: {
|
|
45
|
+
readOnlyHint: false,
|
|
46
|
+
destructiveHint: true,
|
|
47
|
+
openWorldHint: true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
async (params) => paymentRulesModule.paymentRulesHandler(params)
|
|
51
|
+
);
|
|
52
|
+
const handler = await server.getHandler();
|
|
53
|
+
const client = new MCPClient({
|
|
54
|
+
mcpServers: {
|
|
55
|
+
local: {
|
|
56
|
+
url: "http://localhost:3000/mcp",
|
|
57
|
+
transport: "http",
|
|
58
|
+
fetch: (input, init) => {
|
|
59
|
+
if (input instanceof Request) {
|
|
60
|
+
return handler(init === void 0 ? input : new Request(input, init));
|
|
61
|
+
}
|
|
62
|
+
return handler(new Request(input, init));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
const session = await client.createSession("local");
|
|
69
|
+
const tools = await session.listTools();
|
|
70
|
+
expect(tools).toEqual(
|
|
71
|
+
expect.arrayContaining([
|
|
72
|
+
expect.objectContaining({
|
|
73
|
+
name: "vtex_commercial_conditions",
|
|
74
|
+
inputSchema: expect.objectContaining({
|
|
75
|
+
properties: expect.objectContaining({
|
|
76
|
+
action: expect.any(Object),
|
|
77
|
+
profileId: expect.any(Object)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
}),
|
|
81
|
+
expect.objectContaining({
|
|
82
|
+
name: "vtex_payment_rules",
|
|
83
|
+
inputSchema: expect.objectContaining({
|
|
84
|
+
properties: expect.objectContaining({
|
|
85
|
+
action: expect.any(Object),
|
|
86
|
+
profileId: expect.any(Object)
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
])
|
|
91
|
+
);
|
|
92
|
+
} finally {
|
|
93
|
+
await client.closeAllSessions();
|
|
94
|
+
await server.close();
|
|
95
|
+
}
|
|
96
|
+
} finally {
|
|
97
|
+
if (previousNodeEnv === void 0) {
|
|
98
|
+
delete process.env.NODE_ENV;
|
|
99
|
+
} else {
|
|
100
|
+
process.env.NODE_ENV = previousNodeEnv;
|
|
101
|
+
}
|
|
102
|
+
if (previousTelemetry === void 0) {
|
|
103
|
+
delete process.env.MCP_USE_ANONYMIZED_TELEMETRY;
|
|
104
|
+
} else {
|
|
105
|
+
process.env.MCP_USE_ANONYMIZED_TELEMETRY = previousTelemetry;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
4
109
|
it("exports and registers both action-based payments tools", async () => {
|
|
5
110
|
const serverSource = await readFile(new URL("../../index.ts", import.meta.url), "utf8");
|
|
6
111
|
const exportsSource = await readFile(new URL("../../src/tools/vtex/index.ts", import.meta.url), "utf8");
|
|
7
112
|
expect(exportsSource).toContain('export * from "./commercial-conditions.js"');
|
|
8
113
|
expect(exportsSource).toContain('export * from "./payment-rules.js"');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
114
|
+
const commercialConditionsStart = serverSource.indexOf('name: "vtex_commercial_conditions"');
|
|
115
|
+
const paymentRulesStart = serverSource.indexOf('name: "vtex_payment_rules"');
|
|
116
|
+
expect(commercialConditionsStart, "vtex_commercial_conditions registration exists").toBeGreaterThan(-1);
|
|
117
|
+
expect(paymentRulesStart, "vtex_payment_rules registration exists").toBeGreaterThan(-1);
|
|
118
|
+
const commercialConditionsBlock = serverSource.slice(commercialConditionsStart, commercialConditionsStart + 900);
|
|
119
|
+
const paymentRulesBlock = serverSource.slice(paymentRulesStart, paymentRulesStart + 900);
|
|
120
|
+
expect(commercialConditionsBlock).toContain("readOnlyHint: true");
|
|
121
|
+
expect(commercialConditionsBlock).toContain("destructiveHint: false");
|
|
122
|
+
expect(commercialConditionsBlock).toContain("openWorldHint: true");
|
|
123
|
+
expect(paymentRulesBlock).toContain("readOnlyHint: false");
|
|
124
|
+
expect(paymentRulesBlock).toContain("destructiveHint: true");
|
|
125
|
+
expect(paymentRulesBlock).toContain("openWorldHint: true");
|
|
17
126
|
});
|
|
18
127
|
it("keeps both tool descriptions business-safe and action-focused", async () => {
|
|
19
128
|
const serverSource = await readFile(new URL("../../index.ts", import.meta.url), "utf8");
|
|
@@ -24,12 +133,12 @@ describe("VTEX commercial conditions server surface", () => {
|
|
|
24
133
|
const commercialConditionsBlock = serverSource.slice(commercialConditionsStart, commercialConditionsStart + 900);
|
|
25
134
|
const paymentRulesBlock = serverSource.slice(paymentRulesStart, paymentRulesStart + 900);
|
|
26
135
|
expect(commercialConditionsBlock).toContain(
|
|
27
|
-
"condition records
|
|
136
|
+
"list available condition records or get a specific condition"
|
|
28
137
|
);
|
|
29
|
-
expect(commercialConditionsBlock).toContain("
|
|
138
|
+
expect(commercialConditionsBlock).toContain("cannot be created or modified through this API");
|
|
139
|
+
expect(commercialConditionsBlock).toContain("created manually in the VTEX admin panel");
|
|
30
140
|
expect(commercialConditionsBlock).not.toContain("sandbox");
|
|
31
|
-
expect(commercialConditionsBlock).not.toContain("
|
|
32
|
-
expect(commercialConditionsBlock).not.toContain("legacy VTEX Payments endpoints");
|
|
141
|
+
expect(commercialConditionsBlock).not.toContain("Delete operations require confirmed=true");
|
|
33
142
|
expect(paymentRulesBlock).toContain(
|
|
34
143
|
"rules that map installments, payment systems, and optional commercial-condition restrictions"
|
|
35
144
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../tests/vtex/vtex-commercial-conditions-surface.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { readFile } from \"node:fs/promises\";\nimport { describe, expect, it } from \"vitest\";\n\ndescribe(\"VTEX commercial conditions server surface\", () => {\n it(\"exports and registers both action-based payments tools\", async () => {\n const serverSource = await readFile(new URL(\"../../index.ts\", import.meta.url), \"utf8\");\n const exportsSource = await readFile(new URL(\"../../src/tools/vtex/index.ts\", import.meta.url), \"utf8\");\n\n expect(exportsSource).toContain('export * from \"./commercial-conditions.js\"');\n expect(exportsSource).toContain('export * from \"./payment-rules.js\"');\n\n
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,6CAA6C,MAAM;AAC1D,KAAG,0DAA0D,YAAY;AACvE,UAAM,eAAe,MAAM,SAAS,IAAI,IAAI,kBAAkB,YAAY,GAAG,GAAG,MAAM;AACtF,UAAM,gBAAgB,MAAM,SAAS,IAAI,IAAI,iCAAiC,YAAY,GAAG,GAAG,MAAM;AAEtG,WAAO,aAAa,EAAE,UAAU,4CAA4C;AAC5E,WAAO,aAAa,EAAE,UAAU,oCAAoC;AAEpE,
|
|
4
|
+
"sourcesContent": ["import { readFile } from \"node:fs/promises\";\nimport { describe, expect, it } from \"vitest\";\n\ndescribe(\"VTEX commercial conditions server surface\", () => {\n it(\"registers and lists both tools through the MCP layer without schema compatibility failures\", async () => {\n const previousNodeEnv = process.env.NODE_ENV;\n const previousTelemetry = process.env.MCP_USE_ANONYMIZED_TELEMETRY;\n\n process.env.NODE_ENV = \"production\";\n process.env.MCP_USE_ANONYMIZED_TELEMETRY = \"false\";\n\n try {\n const [\n { MCPServer, object },\n { MCPClient },\n commercialConditionsModule,\n paymentRulesModule,\n ] = await Promise.all([\n import(\"mcp-use/server\"),\n import(\"mcp-use\"),\n import(\"../../src/tools/vtex/commercial-conditions.js\"),\n import(\"../../src/tools/vtex/payment-rules.js\"),\n ]);\n\n const server = new MCPServer({\n name: \"test-vtex-payments-server\",\n version: \"1.0.0\",\n baseUrl: \"http://localhost:3000\",\n });\n\n server.tool(\n {\n name: \"vtex_commercial_conditions\",\n description: \"Read VTEX commercial conditions.\",\n schema: commercialConditionsModule.commercialConditionsSchema,\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n },\n async (params) => commercialConditionsModule.commercialConditionsHandler(params)\n );\n\n server.tool(\n {\n name: \"vtex_payment_rules\",\n description: \"Manage VTEX payment rules.\",\n schema: paymentRulesModule.paymentRulesSchema,\n annotations: {\n readOnlyHint: false,\n destructiveHint: true,\n openWorldHint: true,\n },\n },\n async (params) => paymentRulesModule.paymentRulesHandler(params)\n );\n\n const handler = await server.getHandler();\n const client = new MCPClient({\n mcpServers: {\n local: {\n url: \"http://localhost:3000/mcp\",\n transport: \"http\",\n fetch: (input: Request | URL | string, init?: RequestInit) => {\n if (input instanceof Request) {\n return handler(init === undefined ? input : new Request(input, init));\n }\n\n return handler(new Request(input, init));\n },\n },\n },\n });\n\n try {\n const session = await client.createSession(\"local\");\n const tools = await session.listTools();\n\n expect(tools).toEqual(\n expect.arrayContaining([\n expect.objectContaining({\n name: \"vtex_commercial_conditions\",\n inputSchema: expect.objectContaining({\n properties: expect.objectContaining({\n action: expect.any(Object),\n profileId: expect.any(Object),\n }),\n }),\n }),\n expect.objectContaining({\n name: \"vtex_payment_rules\",\n inputSchema: expect.objectContaining({\n properties: expect.objectContaining({\n action: expect.any(Object),\n profileId: expect.any(Object),\n }),\n }),\n }),\n ])\n );\n } finally {\n await client.closeAllSessions();\n await server.close();\n }\n } finally {\n if (previousNodeEnv === undefined) {\n delete process.env.NODE_ENV;\n } else {\n process.env.NODE_ENV = previousNodeEnv;\n }\n\n if (previousTelemetry === undefined) {\n delete process.env.MCP_USE_ANONYMIZED_TELEMETRY;\n } else {\n process.env.MCP_USE_ANONYMIZED_TELEMETRY = previousTelemetry;\n }\n }\n });\n\n it(\"exports and registers both action-based payments tools\", async () => {\n const serverSource = await readFile(new URL(\"../../index.ts\", import.meta.url), \"utf8\");\n const exportsSource = await readFile(new URL(\"../../src/tools/vtex/index.ts\", import.meta.url), \"utf8\");\n\n expect(exportsSource).toContain('export * from \"./commercial-conditions.js\"');\n expect(exportsSource).toContain('export * from \"./payment-rules.js\"');\n\n const commercialConditionsStart = serverSource.indexOf('name: \"vtex_commercial_conditions\"');\n const paymentRulesStart = serverSource.indexOf('name: \"vtex_payment_rules\"');\n\n expect(commercialConditionsStart, \"vtex_commercial_conditions registration exists\").toBeGreaterThan(-1);\n expect(paymentRulesStart, \"vtex_payment_rules registration exists\").toBeGreaterThan(-1);\n\n const commercialConditionsBlock = serverSource.slice(commercialConditionsStart, commercialConditionsStart + 900);\n const paymentRulesBlock = serverSource.slice(paymentRulesStart, paymentRulesStart + 900);\n\n expect(commercialConditionsBlock).toContain(\"readOnlyHint: true\");\n expect(commercialConditionsBlock).toContain(\"destructiveHint: false\");\n expect(commercialConditionsBlock).toContain(\"openWorldHint: true\");\n\n expect(paymentRulesBlock).toContain(\"readOnlyHint: false\");\n expect(paymentRulesBlock).toContain(\"destructiveHint: true\");\n expect(paymentRulesBlock).toContain(\"openWorldHint: true\");\n });\n\n it(\"keeps both tool descriptions business-safe and action-focused\", async () => {\n const serverSource = await readFile(new URL(\"../../index.ts\", import.meta.url), \"utf8\");\n\n const commercialConditionsStart = serverSource.indexOf('name: \"vtex_commercial_conditions\"');\n const paymentRulesStart = serverSource.indexOf('name: \"vtex_payment_rules\"');\n\n expect(commercialConditionsStart).toBeGreaterThan(-1);\n expect(paymentRulesStart).toBeGreaterThan(-1);\n\n const commercialConditionsBlock = serverSource.slice(commercialConditionsStart, commercialConditionsStart + 900);\n const paymentRulesBlock = serverSource.slice(paymentRulesStart, paymentRulesStart + 900);\n\n expect(commercialConditionsBlock).toContain(\n \"list available condition records or get a specific condition\"\n );\n expect(commercialConditionsBlock).toContain(\"cannot be created or modified through this API\");\n expect(commercialConditionsBlock).toContain(\"created manually in the VTEX admin panel\");\n expect(commercialConditionsBlock).not.toContain(\"sandbox\");\n expect(commercialConditionsBlock).not.toContain(\"Delete operations require confirmed=true\");\n\n expect(paymentRulesBlock).toContain(\n \"rules that map installments, payment systems, and optional commercial-condition restrictions\"\n );\n expect(paymentRulesBlock).toContain(\"Delete operations require confirmed=true\");\n expect(paymentRulesBlock).not.toContain(\"sandbox\");\n expect(paymentRulesBlock).not.toContain(\"production writes\");\n expect(paymentRulesBlock).not.toContain(\"legacy VTEX Payments endpoint\");\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,6CAA6C,MAAM;AAC1D,KAAG,8FAA8F,YAAY;AAC3G,UA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,SAAS;AACzD,WAAO,yBAAyB,EAAE,IAAI,UAAU,0CAA0C;AAE1F,WAAO,iBAAiB,EAAE;AAAA,MACxB;AAAA,IACF;AACA,WAAO,iBAAiB,EAAE,UAAU,0CAA0C;AAC9E,WAAO,iBAAiB,EAAE,IAAI,UAAU,SAAS;AACjD,WAAO,iBAAiB,EAAE,IAAI,UAAU,mBAAmB;AAC3D,WAAO,iBAAiB,EAAE,IAAI,UAAU,+BAA+B;AAAA,EACzE,CAAC;AACH,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,7 +2,6 @@ import { z } from "zod";
|
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
3
|
const objectMock = vi.fn((value) => ({ kind: "object", value }));
|
|
4
4
|
const errorMock = vi.fn((message) => ({ kind: "error", message }));
|
|
5
|
-
const createCommercialConditionMock = vi.fn();
|
|
6
5
|
const getCommercialConditionMock = vi.fn();
|
|
7
6
|
const createPaymentRuleMock = vi.fn();
|
|
8
7
|
const getPaymentRuleMock = vi.fn();
|
|
@@ -10,7 +9,6 @@ const updateSkuBasicFieldsServiceMock = vi.fn();
|
|
|
10
9
|
const resolveVtexWriteProfileMock = vi.fn();
|
|
11
10
|
const buildWriteSuccessResponseMock = vi.fn((value) => ({ kind: "write", value }));
|
|
12
11
|
const handleVtexWriteErrorMock = vi.fn((_err, fallback) => ({ kind: "error", message: fallback }));
|
|
13
|
-
const requireExplicitConfirmationMock = vi.fn();
|
|
14
12
|
vi.mock("mcp-use/server", () => ({
|
|
15
13
|
object: objectMock,
|
|
16
14
|
error: errorMock
|
|
@@ -22,7 +20,7 @@ vi.mock("../../src/services/vtex/vtex-payments.js", () => ({
|
|
|
22
20
|
listPaymentRules: vi.fn()
|
|
23
21
|
}));
|
|
24
22
|
vi.mock("../../src/services/vtex/vtex-payments-write.js", () => ({
|
|
25
|
-
createCommercialCondition:
|
|
23
|
+
createCommercialCondition: vi.fn(),
|
|
26
24
|
updateCommercialCondition: vi.fn(),
|
|
27
25
|
deleteCommercialCondition: vi.fn(),
|
|
28
26
|
createPaymentRule: createPaymentRuleMock,
|
|
@@ -45,7 +43,7 @@ vi.mock("../../src/tools/vtex/write-helpers.js", () => ({
|
|
|
45
43
|
resolveVtexWriteProfile: resolveVtexWriteProfileMock,
|
|
46
44
|
buildWriteSuccessResponse: buildWriteSuccessResponseMock,
|
|
47
45
|
handleVtexWriteError: handleVtexWriteErrorMock,
|
|
48
|
-
requireExplicitConfirmation:
|
|
46
|
+
requireExplicitConfirmation: vi.fn()
|
|
49
47
|
}));
|
|
50
48
|
const commercialConditionsModule = await import("../../src/tools/vtex/commercial-conditions.js");
|
|
51
49
|
const paymentRulesModule = await import("../../src/tools/vtex/payment-rules.js");
|
|
@@ -57,14 +55,8 @@ describe("VTEX commercial conditions business workflow", () => {
|
|
|
57
55
|
ok: true,
|
|
58
56
|
value: { profileId: "profile-1" }
|
|
59
57
|
});
|
|
60
|
-
requireExplicitConfirmationMock.mockReturnValue(null);
|
|
61
58
|
});
|
|
62
|
-
it("supports a selective installments workflow
|
|
63
|
-
createCommercialConditionMock.mockResolvedValue({
|
|
64
|
-
id: 901,
|
|
65
|
-
Name: "9-cuotas-sin-interes",
|
|
66
|
-
IsActive: true
|
|
67
|
-
});
|
|
59
|
+
it("supports a selective installments workflow after a condition is created manually in VTEX Admin", async () => {
|
|
68
60
|
createPaymentRuleMock.mockResolvedValue({
|
|
69
61
|
id: 902,
|
|
70
62
|
commercialConditionId: 901,
|
|
@@ -94,11 +86,10 @@ describe("VTEX commercial conditions business workflow", () => {
|
|
|
94
86
|
restrictedByCondition: true,
|
|
95
87
|
installments: [{ count: 9, interest: false }]
|
|
96
88
|
});
|
|
97
|
-
const
|
|
98
|
-
action: "
|
|
89
|
+
const inspectedCondition = await commercialConditionsModule.commercialConditionsHandler({
|
|
90
|
+
action: "get",
|
|
99
91
|
profileId: "profile-1",
|
|
100
|
-
|
|
101
|
-
isActive: true
|
|
92
|
+
commercialConditionId: 901
|
|
102
93
|
});
|
|
103
94
|
const createdRule = await paymentRulesModule.paymentRulesHandler({
|
|
104
95
|
action: "create",
|
|
@@ -123,10 +114,7 @@ describe("VTEX commercial conditions business workflow", () => {
|
|
|
123
114
|
profileId: "profile-1",
|
|
124
115
|
ruleId: 902
|
|
125
116
|
});
|
|
126
|
-
expect(
|
|
127
|
-
Name: "9-cuotas-sin-interes",
|
|
128
|
-
IsActive: true
|
|
129
|
-
});
|
|
117
|
+
expect(getCommercialConditionMock).toHaveBeenCalledWith("profile-1", 901);
|
|
130
118
|
expect(createPaymentRuleMock).toHaveBeenCalledWith("profile-1", {
|
|
131
119
|
commercialConditionId: 901,
|
|
132
120
|
paymentSystem: "2",
|
|
@@ -136,11 +124,15 @@ describe("VTEX commercial conditions business workflow", () => {
|
|
|
136
124
|
expect(updateSkuBasicFieldsServiceMock).toHaveBeenCalledWith("profile-1", "333", {
|
|
137
125
|
commercialConditionId: 901
|
|
138
126
|
});
|
|
139
|
-
expect(
|
|
140
|
-
kind: "
|
|
127
|
+
expect(inspectedCondition).toMatchObject({
|
|
128
|
+
kind: "object",
|
|
141
129
|
value: {
|
|
142
|
-
|
|
143
|
-
|
|
130
|
+
commercial_condition_id: 901,
|
|
131
|
+
condition: {
|
|
132
|
+
id: 901,
|
|
133
|
+
name: "9-cuotas-sin-interes",
|
|
134
|
+
is_active: true
|
|
135
|
+
}
|
|
144
136
|
}
|
|
145
137
|
});
|
|
146
138
|
expect(createdRule).toMatchObject({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../tests/vtex/vtex-commercial-conditions-workflow.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { z } from \"zod\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nconst objectMock = vi.fn((value) => ({ kind: \"object\", value }));\nconst errorMock = vi.fn((message) => ({ kind: \"error\", message }));\n\nconst
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,YAAY,UAAU,QAAQ,IAAI,UAAU;AAErD,MAAM,aAAa,GAAG,GAAG,CAAC,WAAW,EAAE,MAAM,UAAU,MAAM,EAAE;AAC/D,MAAM,YAAY,GAAG,GAAG,CAAC,aAAa,EAAE,MAAM,SAAS,QAAQ,EAAE;AAEjE,MAAM,
|
|
4
|
+
"sourcesContent": ["import { z } from \"zod\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nconst objectMock = vi.fn((value) => ({ kind: \"object\", value }));\nconst errorMock = vi.fn((message) => ({ kind: \"error\", message }));\n\nconst getCommercialConditionMock = vi.fn();\nconst createPaymentRuleMock = vi.fn();\nconst getPaymentRuleMock = vi.fn();\nconst updateSkuBasicFieldsServiceMock = vi.fn();\n\nconst resolveVtexWriteProfileMock = vi.fn();\nconst buildWriteSuccessResponseMock = vi.fn((value) => ({ kind: \"write\", value }));\nconst handleVtexWriteErrorMock = vi.fn((_err, fallback) => ({ kind: \"error\", message: fallback }));\n\nvi.mock(\"mcp-use/server\", () => ({\n object: objectMock,\n error: errorMock,\n}));\n\nvi.mock(\"../../src/services/vtex/vtex-payments.js\", () => ({\n getCommercialCondition: getCommercialConditionMock,\n listCommercialConditions: vi.fn(),\n getPaymentRule: getPaymentRuleMock,\n listPaymentRules: vi.fn(),\n}));\n\nvi.mock(\"../../src/services/vtex/vtex-payments-write.js\", () => ({\n createCommercialCondition: vi.fn(),\n updateCommercialCondition: vi.fn(),\n deleteCommercialCondition: vi.fn(),\n createPaymentRule: createPaymentRuleMock,\n updatePaymentRule: vi.fn(),\n deletePaymentRule: vi.fn(),\n}));\n\nvi.mock(\"../../src/services/vtex/vtex-catalog-write.js\", () => ({\n updateSkuBasicFields: updateSkuBasicFieldsServiceMock,\n replaceSkuEans: vi.fn(),\n createProduct: vi.fn(),\n createSku: vi.fn(),\n addSkuEan: vi.fn(),\n getSkuImages: vi.fn(),\n attachSkuImage: vi.fn(),\n updateSkuImage: vi.fn(),\n}));\n\nvi.mock(\"../../src/tools/vtex/write-helpers.js\", () => ({\n vtexProfileIdSchemaField: z.string().trim().min(1).optional().describe(\"profile\"),\n confirmationSchemaField: z.boolean().optional().describe(\"confirmed\"),\n resolveVtexWriteProfile: resolveVtexWriteProfileMock,\n buildWriteSuccessResponse: buildWriteSuccessResponseMock,\n handleVtexWriteError: handleVtexWriteErrorMock,\n requireExplicitConfirmation: vi.fn(),\n}));\n\nconst commercialConditionsModule = await import(\"../../src/tools/vtex/commercial-conditions.js\");\nconst paymentRulesModule = await import(\"../../src/tools/vtex/payment-rules.js\");\nconst skuModule = await import(\"../../src/tools/vtex/update-sku-basic-fields.js\");\n\ndescribe(\"VTEX commercial conditions business workflow\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n resolveVtexWriteProfileMock.mockResolvedValue({\n ok: true,\n value: { profileId: \"profile-1\" },\n });\n });\n\n it(\"supports a selective installments workflow after a condition is created manually in VTEX Admin\", async () => {\n createPaymentRuleMock.mockResolvedValue({\n id: 902,\n commercialConditionId: 901,\n paymentSystem: \"2\",\n restrictedByCondition: true,\n installments: [{ count: 9, interest: false }],\n });\n updateSkuBasicFieldsServiceMock.mockResolvedValue({\n before: { Id: 333, CommercialConditionId: 0 },\n after: { Id: 333, CommercialConditionId: 901 },\n });\n getCommercialConditionMock.mockResolvedValue({\n id: 901,\n name: \"9-cuotas-sin-interes\",\n isActive: true,\n });\n getPaymentRuleMock\n .mockResolvedValueOnce({\n id: 100,\n commercialConditionId: 0,\n paymentSystem: \"2\",\n restrictedByCondition: false,\n installments: [{ count: 6, interest: false }],\n })\n .mockResolvedValueOnce({\n id: 902,\n commercialConditionId: 901,\n paymentSystem: \"2\",\n restrictedByCondition: true,\n installments: [{ count: 9, interest: false }],\n });\n\n const inspectedCondition = await commercialConditionsModule.commercialConditionsHandler({\n action: \"get\",\n profileId: \"profile-1\",\n commercialConditionId: 901,\n });\n\n const createdRule = await paymentRulesModule.paymentRulesHandler({\n action: \"create\",\n profileId: \"profile-1\",\n commercialConditionId: 901,\n paymentSystem: \"2\",\n restrictedByCondition: true,\n installments: [{ count: 9, interest: false }],\n });\n\n const assignedSku = await skuModule.updateSkuBasicFieldsHandler({\n profileId: \"profile-1\",\n skuId: \"333\",\n commercialConditionId: 901,\n });\n\n const defaultRule = await paymentRulesModule.paymentRulesHandler({\n action: \"get\",\n profileId: \"profile-1\",\n ruleId: 100,\n });\n\n const targetedRule = await paymentRulesModule.paymentRulesHandler({\n action: \"get\",\n profileId: \"profile-1\",\n ruleId: 902,\n });\n\n expect(getCommercialConditionMock).toHaveBeenCalledWith(\"profile-1\", 901);\n expect(createPaymentRuleMock).toHaveBeenCalledWith(\"profile-1\", {\n commercialConditionId: 901,\n paymentSystem: \"2\",\n restrictedByCondition: true,\n installments: [{ count: 9, interest: false }],\n });\n expect(updateSkuBasicFieldsServiceMock).toHaveBeenCalledWith(\"profile-1\", \"333\", {\n commercialConditionId: 901,\n });\n\n expect(inspectedCondition).toMatchObject({\n kind: \"object\",\n value: {\n commercial_condition_id: 901,\n condition: {\n id: 901,\n name: \"9-cuotas-sin-interes\",\n is_active: true,\n },\n },\n });\n expect(createdRule).toMatchObject({\n kind: \"write\",\n value: {\n operation: \"payment_rules_create\",\n resourceId: \"902\",\n },\n });\n expect(assignedSku).toMatchObject({\n kind: \"write\",\n value: {\n operation: \"update_sku_basic_fields\",\n resourceId: \"333\",\n },\n });\n\n expect(defaultRule).toEqual({\n kind: \"object\",\n value: {\n profile_id: \"profile-1\",\n rule_id: 100,\n payment_rule: {\n id: 100,\n commercial_condition_id: 0,\n payment_system: \"2\",\n restricted_by_condition: false,\n installments: [{ count: 6, interest: false }],\n },\n },\n });\n expect(targetedRule).toEqual({\n kind: \"object\",\n value: {\n profile_id: \"profile-1\",\n rule_id: 902,\n payment_rule: {\n id: 902,\n commercial_condition_id: 901,\n payment_system: \"2\",\n restricted_by_condition: true,\n installments: [{ count: 9, interest: false }],\n },\n },\n });\n });\n});\n"],
|
|
5
|
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