@yoryoboy/bi-mcp 1.1.0 → 1.3.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.
Files changed (126) hide show
  1. package/README.md +126 -9
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/index.js +332 -2
  4. package/dist/index.js.map +2 -2
  5. package/dist/mcp-use.json +2 -2
  6. package/dist/scripts/_helpers.js +44 -0
  7. package/dist/scripts/_helpers.js.map +7 -0
  8. package/dist/scripts/admin-profile-delete.js +72 -0
  9. package/dist/scripts/admin-profile-delete.js.map +7 -0
  10. package/dist/scripts/admin-profile-list.js +24 -0
  11. package/dist/scripts/admin-profile-list.js.map +7 -0
  12. package/dist/scripts/admin-profile-upsert.js +25 -0
  13. package/dist/scripts/admin-profile-upsert.js.map +7 -0
  14. package/dist/scripts/admin-vtex-list.js +28 -0
  15. package/dist/scripts/admin-vtex-list.js.map +7 -0
  16. package/dist/scripts/admin-vtex-upsert.js +73 -0
  17. package/dist/scripts/admin-vtex-upsert.js.map +7 -0
  18. package/dist/scripts/admin-vtex-validate.js +55 -0
  19. package/dist/scripts/admin-vtex-validate.js.map +7 -0
  20. package/dist/scripts/run-migrations.js +50 -0
  21. package/dist/scripts/run-migrations.js.map +7 -0
  22. package/dist/scripts/test-db-connection.js +19 -0
  23. package/dist/scripts/test-db-connection.js.map +7 -0
  24. package/dist/src/config/profile-store.js +86 -0
  25. package/dist/src/config/profile-store.js.map +7 -0
  26. package/dist/src/config/vtex-crypto.js +43 -0
  27. package/dist/src/config/vtex-crypto.js.map +7 -0
  28. package/dist/src/config/vtex-profile-store.js +132 -0
  29. package/dist/src/config/vtex-profile-store.js.map +7 -0
  30. package/dist/src/config/vtex.js +27 -21
  31. package/dist/src/config/vtex.js.map +2 -2
  32. package/dist/src/db/client.js +58 -0
  33. package/dist/src/db/client.js.map +7 -0
  34. package/dist/src/services/vtex/vtex-api.js +24 -8
  35. package/dist/src/services/vtex/vtex-api.js.map +2 -2
  36. package/dist/src/services/vtex/vtex-catalog-write.js +233 -0
  37. package/dist/src/services/vtex/vtex-catalog-write.js.map +7 -0
  38. package/dist/src/services/vtex/vtex-catalog.js +5 -3
  39. package/dist/src/services/vtex/vtex-catalog.js.map +2 -2
  40. package/dist/src/services/vtex/vtex-logistics.js +18 -9
  41. package/dist/src/services/vtex/vtex-logistics.js.map +2 -2
  42. package/dist/src/services/vtex/vtex-orders-write.js +152 -0
  43. package/dist/src/services/vtex/vtex-orders-write.js.map +7 -0
  44. package/dist/src/services/vtex/vtex-orders.js +13 -7
  45. package/dist/src/services/vtex/vtex-orders.js.map +2 -2
  46. package/dist/src/services/vtex/vtex-pricing-write.js +24 -0
  47. package/dist/src/services/vtex/vtex-pricing-write.js.map +7 -0
  48. package/dist/src/services/vtex/vtex-pricing.js +5 -3
  49. package/dist/src/services/vtex/vtex-pricing.js.map +2 -2
  50. package/dist/src/services/vtex/vtex-write.js +38 -0
  51. package/dist/src/services/vtex/vtex-write.js.map +7 -0
  52. package/dist/src/tools/config/check-database-connection.js +59 -0
  53. package/dist/src/tools/config/check-database-connection.js.map +7 -0
  54. package/dist/src/tools/config/index.js +3 -0
  55. package/dist/src/tools/config/index.js.map +7 -0
  56. package/dist/src/tools/config/list-profiles.js +26 -0
  57. package/dist/src/tools/config/list-profiles.js.map +7 -0
  58. package/dist/src/tools/index.js +1 -0
  59. package/dist/src/tools/index.js.map +2 -2
  60. package/dist/src/tools/vtex/activate-sku.js +53 -0
  61. package/dist/src/tools/vtex/activate-sku.js.map +7 -0
  62. package/dist/src/tools/vtex/add-order-tracking.js +103 -0
  63. package/dist/src/tools/vtex/add-order-tracking.js.map +7 -0
  64. package/dist/src/tools/vtex/associate-specification.js +60 -0
  65. package/dist/src/tools/vtex/associate-specification.js.map +7 -0
  66. package/dist/src/tools/vtex/attach-catalog-image.js +63 -0
  67. package/dist/src/tools/vtex/attach-catalog-image.js.map +7 -0
  68. package/dist/src/tools/vtex/cancel-order.js +67 -0
  69. package/dist/src/tools/vtex/cancel-order.js.map +7 -0
  70. package/dist/src/tools/vtex/computed-price.js +12 -1
  71. package/dist/src/tools/vtex/computed-price.js.map +2 -2
  72. package/dist/src/tools/vtex/create-brand.js +69 -0
  73. package/dist/src/tools/vtex/create-brand.js.map +7 -0
  74. package/dist/src/tools/vtex/create-category.js +81 -0
  75. package/dist/src/tools/vtex/create-category.js.map +7 -0
  76. package/dist/src/tools/vtex/create-product-with-sku.js +120 -0
  77. package/dist/src/tools/vtex/create-product-with-sku.js.map +7 -0
  78. package/dist/src/tools/vtex/create-product.js +111 -0
  79. package/dist/src/tools/vtex/create-product.js.map +7 -0
  80. package/dist/src/tools/vtex/create-sku.js +103 -0
  81. package/dist/src/tools/vtex/create-sku.js.map +7 -0
  82. package/dist/src/tools/vtex/create-specification-value.js +53 -0
  83. package/dist/src/tools/vtex/create-specification-value.js.map +7 -0
  84. package/dist/src/tools/vtex/create-specification.js +85 -0
  85. package/dist/src/tools/vtex/create-specification.js.map +7 -0
  86. package/dist/src/tools/vtex/deactivate-sku.js +53 -0
  87. package/dist/src/tools/vtex/deactivate-sku.js.map +7 -0
  88. package/dist/src/tools/vtex/delete-fixed-price.js +53 -0
  89. package/dist/src/tools/vtex/delete-fixed-price.js.map +7 -0
  90. package/dist/src/tools/vtex/index.js +21 -0
  91. package/dist/src/tools/vtex/index.js.map +2 -2
  92. package/dist/src/tools/vtex/inventory-check.js +15 -2
  93. package/dist/src/tools/vtex/inventory-check.js.map +2 -2
  94. package/dist/src/tools/vtex/invoice-order.js +84 -0
  95. package/dist/src/tools/vtex/invoice-order.js.map +7 -0
  96. package/dist/src/tools/vtex/order-details.js +16 -2
  97. package/dist/src/tools/vtex/order-details.js.map +2 -2
  98. package/dist/src/tools/vtex/orders-summary.js +11 -1
  99. package/dist/src/tools/vtex/orders-summary.js.map +2 -2
  100. package/dist/src/tools/vtex/product-offers.js +15 -2
  101. package/dist/src/tools/vtex/product-offers.js.map +2 -2
  102. package/dist/src/tools/vtex/profile-resolution.js +57 -0
  103. package/dist/src/tools/vtex/profile-resolution.js.map +7 -0
  104. package/dist/src/tools/vtex/sku-offers.js +16 -2
  105. package/dist/src/tools/vtex/sku-offers.js.map +2 -2
  106. package/dist/src/tools/vtex/sku-price.js +12 -2
  107. package/dist/src/tools/vtex/sku-price.js.map +2 -2
  108. package/dist/src/tools/vtex/toggle-unlimited-quantity.js +65 -0
  109. package/dist/src/tools/vtex/toggle-unlimited-quantity.js.map +7 -0
  110. package/dist/src/tools/vtex/update-inventory.js +40 -14
  111. package/dist/src/tools/vtex/update-inventory.js.map +2 -2
  112. package/dist/src/tools/vtex/update-lead-time.js +40 -12
  113. package/dist/src/tools/vtex/update-lead-time.js.map +2 -2
  114. package/dist/src/tools/vtex/update-product-basic-fields.js +71 -0
  115. package/dist/src/tools/vtex/update-product-basic-fields.js.map +7 -0
  116. package/dist/src/tools/vtex/update-sku-basic-fields.js +92 -0
  117. package/dist/src/tools/vtex/update-sku-basic-fields.js.map +7 -0
  118. package/dist/src/tools/vtex/update-sku-price.js +81 -0
  119. package/dist/src/tools/vtex/update-sku-price.js.map +7 -0
  120. package/dist/src/tools/vtex/upsert-fixed-price.js +69 -0
  121. package/dist/src/tools/vtex/upsert-fixed-price.js.map +7 -0
  122. package/dist/src/tools/vtex/warehouse-inventory.js +12 -1
  123. package/dist/src/tools/vtex/warehouse-inventory.js.map +2 -2
  124. package/dist/src/tools/vtex/write-helpers.js +73 -0
  125. package/dist/src/tools/vtex/write-helpers.js.map +7 -0
  126. package/package.json +12 -2
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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,EACX,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,oBAAoB;AAAA,EACpE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,WAAW;AAAA,EAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,8BAA8B;AAAA,EAChE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,4CAA4C;AAAA,EAChF,gBAAgB,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,kBA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od";
2
+ import { createSpecificationValue } from "../../services/vtex/vtex-catalog-write.js";
3
+ import {
4
+ buildWriteSuccessResponse,
5
+ handleVtexWriteError,
6
+ resolveVtexWriteProfile,
7
+ vtexProfileIdSchemaField
8
+ } from "./write-helpers.js";
9
+ const createSpecificationValueSchema = z.object({
10
+ profileId: vtexProfileIdSchemaField,
11
+ fieldId: z.number().int().positive().describe("Specification field ID."),
12
+ name: z.string().min(1).describe("Specification value name."),
13
+ isActive: z.boolean().optional().describe("Whether the value should be active."),
14
+ position: z.number().int().nonnegative().optional().describe("Display position.")
15
+ });
16
+ async function createSpecificationValueHandler({
17
+ profileId,
18
+ fieldId,
19
+ name,
20
+ isActive,
21
+ position
22
+ }) {
23
+ try {
24
+ const profileResolution = await resolveVtexWriteProfile(profileId);
25
+ if (!profileResolution.ok) {
26
+ return profileResolution.response;
27
+ }
28
+ const resolvedProfileId = profileResolution.value.profileId;
29
+ const createdValue = await createSpecificationValue(resolvedProfileId, {
30
+ FieldId: fieldId,
31
+ Name: name,
32
+ IsActive: isActive ?? true,
33
+ Position: position ?? 0,
34
+ Text: null
35
+ });
36
+ return buildWriteSuccessResponse({
37
+ profileId: resolvedProfileId,
38
+ operation: "create_specification_value",
39
+ resourceId: String(createdValue.FieldValueId ?? ""),
40
+ riskLevel: "low",
41
+ message: "Specification value created successfully.",
42
+ before: null,
43
+ after: createdValue
44
+ });
45
+ } catch (err) {
46
+ return handleVtexWriteError(err, "Failed to create specification value in VTEX");
47
+ }
48
+ }
49
+ export {
50
+ createSpecificationValueHandler,
51
+ createSpecificationValueSchema
52
+ };
53
+ //# sourceMappingURL=create-specification-value.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/tools/vtex/create-specification-value.ts"],
4
+ "sourcesContent": ["import { z } from \"zod\";\n\nimport { createSpecificationValue } from \"../../services/vtex/vtex-catalog-write.js\";\nimport {\n buildWriteSuccessResponse,\n handleVtexWriteError,\n resolveVtexWriteProfile,\n vtexProfileIdSchemaField,\n} from \"./write-helpers.js\";\n\nexport const createSpecificationValueSchema = z.object({\n profileId: vtexProfileIdSchemaField,\n fieldId: z.number().int().positive().describe(\"Specification field ID.\"),\n name: z.string().min(1).describe(\"Specification value name.\"),\n isActive: z.boolean().optional().describe(\"Whether the value should be active.\"),\n position: z.number().int().nonnegative().optional().describe(\"Display position.\"),\n});\n\nexport async function createSpecificationValueHandler({\n profileId,\n fieldId,\n name,\n isActive,\n position,\n}: z.infer<typeof createSpecificationValueSchema>) {\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 createdValue = await createSpecificationValue(resolvedProfileId, {\n FieldId: fieldId,\n Name: name,\n IsActive: isActive ?? true,\n Position: position ?? 0,\n Text: null,\n });\n\n return buildWriteSuccessResponse({\n profileId: resolvedProfileId,\n operation: \"create_specification_value\",\n resourceId: String(createdValue.FieldValueId ?? \"\"),\n riskLevel: \"low\",\n message: \"Specification value created successfully.\",\n before: null,\n after: createdValue,\n });\n } catch (err) {\n return handleVtexWriteError(err, \"Failed to create specification value in VTEX\");\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAElB,SAAS,gCAAgC;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM,iCAAiC,EAAE,OAAO;AAAA,EACrD,WAAW;AAAA,EACX,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,yBAAyB;AAAA,EACvE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,2BAA2B;AAAA,EAC5D,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,qCAAqC;AAAA,EAC/E,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,mBAAmB;AAClF,CAAC;AAED,eAAsB,gCAAgC;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAmD;AACjD,MAAI;AACF,UAAM,oBAAoB,MAAM,wBAAwB,SAAS;AACjE,QAAI,CAAC,kBAAkB,IAAI;AACzB,aAAO,kBAAkB;AAAA,IAC3B;AAEA,UAAM,oBAAoB,kBAAkB,MAAM;AAClD,UAAM,eAAe,MAAM,yBAAyB,mBAAmB;AAAA,MACrE,SAAS;AAAA,MACT,MAAM;AAAA,MACN,UAAU,YAAY;AAAA,MACtB,UAAU,YAAY;AAAA,MACtB,MAAM;AAAA,IACR,CAAC;AAED,WAAO,0BAA0B;AAAA,MAC/B,WAAW;AAAA,MACX,WAAW;AAAA,MACX,YAAY,OAAO,aAAa,gBAAgB,EAAE;AAAA,MAClD,WAAW;AAAA,MACX,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,OAAO;AAAA,IACT,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,WAAO,qBAAqB,KAAK,8CAA8C;AAAA,EACjF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,85 @@
1
+ import { z } from "zod";
2
+ import { createSpecification } from "../../services/vtex/vtex-catalog-write.js";
3
+ import {
4
+ buildWriteSuccessResponse,
5
+ handleVtexWriteError,
6
+ resolveVtexWriteProfile,
7
+ vtexProfileIdSchemaField
8
+ } from "./write-helpers.js";
9
+ const createSpecificationSchema = z.object({
10
+ profileId: vtexProfileIdSchemaField,
11
+ fieldTypeId: z.enum(["1", "2", "4", "5", "6", "7", "8", "9"]).transform((value) => Number(value)).describe("Specification field type ID."),
12
+ fieldGroupId: z.number().int().positive().describe("Specification group ID."),
13
+ name: z.string().min(1).describe("Specification name."),
14
+ categoryId: z.number().int().positive().optional().describe("Optional category ID."),
15
+ description: z.string().optional().describe("Specification description."),
16
+ position: z.number().int().nonnegative().optional().describe("Display position."),
17
+ isFilter: z.boolean().optional().describe("Whether the specification should act as a filter."),
18
+ isRequired: z.boolean().optional().describe("Whether the specification is required."),
19
+ isOnProductDetails: z.boolean().optional().describe("Whether the specification should appear on product details."),
20
+ isStockKeepingUnit: z.boolean().optional().describe("Whether this is an SKU specification."),
21
+ isWizard: z.boolean().optional().describe("Wizard flag from VTEX."),
22
+ isActive: z.boolean().optional().describe("Whether the specification is active."),
23
+ isTopMenuLinkActive: z.boolean().optional().describe("Top menu link flag."),
24
+ isSideMenuLinkActive: z.boolean().optional().describe("Side menu link flag."),
25
+ defaultValue: z.string().optional().describe("Default value.")
26
+ });
27
+ async function createSpecificationHandler({
28
+ profileId,
29
+ fieldTypeId,
30
+ fieldGroupId,
31
+ name,
32
+ categoryId,
33
+ description,
34
+ position,
35
+ isFilter,
36
+ isRequired,
37
+ isOnProductDetails,
38
+ isStockKeepingUnit,
39
+ isWizard,
40
+ isActive,
41
+ isTopMenuLinkActive,
42
+ isSideMenuLinkActive,
43
+ defaultValue
44
+ }) {
45
+ try {
46
+ const profileResolution = await resolveVtexWriteProfile(profileId);
47
+ if (!profileResolution.ok) {
48
+ return profileResolution.response;
49
+ }
50
+ const resolvedProfileId = profileResolution.value.profileId;
51
+ const createdSpecification = await createSpecification(resolvedProfileId, {
52
+ FieldTypeId: fieldTypeId,
53
+ FieldGroupId: fieldGroupId,
54
+ Name: name,
55
+ CategoryId: categoryId,
56
+ Description: description ?? null,
57
+ Position: position ?? 0,
58
+ IsFilter: isFilter ?? false,
59
+ IsRequired: isRequired ?? false,
60
+ IsOnProductDetails: isOnProductDetails ?? true,
61
+ IsStockKeepingUnit: isStockKeepingUnit ?? false,
62
+ IsWizard: isWizard ?? false,
63
+ IsActive: isActive ?? true,
64
+ IsTopMenuLinkActive: isTopMenuLinkActive ?? false,
65
+ IsSideMenuLinkActive: isSideMenuLinkActive ?? false,
66
+ DefaultValue: defaultValue ?? ""
67
+ });
68
+ return buildWriteSuccessResponse({
69
+ profileId: resolvedProfileId,
70
+ operation: "create_specification",
71
+ resourceId: String(createdSpecification.Id ?? ""),
72
+ riskLevel: "low",
73
+ message: "Specification created successfully.",
74
+ before: null,
75
+ after: createdSpecification
76
+ });
77
+ } catch (err) {
78
+ return handleVtexWriteError(err, "Failed to create specification in VTEX");
79
+ }
80
+ }
81
+ export {
82
+ createSpecificationHandler,
83
+ createSpecificationSchema
84
+ };
85
+ //# sourceMappingURL=create-specification.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/tools/vtex/create-specification.ts"],
4
+ "sourcesContent": ["import { z } from \"zod\";\n\nimport { createSpecification } from \"../../services/vtex/vtex-catalog-write.js\";\nimport {\n buildWriteSuccessResponse,\n handleVtexWriteError,\n resolveVtexWriteProfile,\n vtexProfileIdSchemaField,\n} from \"./write-helpers.js\";\n\nexport const createSpecificationSchema = z.object({\n profileId: vtexProfileIdSchemaField,\n fieldTypeId: z\n .enum([\"1\", \"2\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"])\n .transform((value) => Number(value))\n .describe(\"Specification field type ID.\"),\n fieldGroupId: z.number().int().positive().describe(\"Specification group ID.\"),\n name: z.string().min(1).describe(\"Specification name.\"),\n categoryId: z.number().int().positive().optional().describe(\"Optional category ID.\"),\n description: z.string().optional().describe(\"Specification description.\"),\n position: z.number().int().nonnegative().optional().describe(\"Display position.\"),\n isFilter: z.boolean().optional().describe(\"Whether the specification should act as a filter.\"),\n isRequired: z.boolean().optional().describe(\"Whether the specification is required.\"),\n isOnProductDetails: z.boolean().optional().describe(\"Whether the specification should appear on product details.\"),\n isStockKeepingUnit: z.boolean().optional().describe(\"Whether this is an SKU specification.\"),\n isWizard: z.boolean().optional().describe(\"Wizard flag from VTEX.\"),\n isActive: z.boolean().optional().describe(\"Whether the specification is active.\"),\n isTopMenuLinkActive: z.boolean().optional().describe(\"Top menu link flag.\"),\n isSideMenuLinkActive: z.boolean().optional().describe(\"Side menu link flag.\"),\n defaultValue: z.string().optional().describe(\"Default value.\"),\n});\n\nexport async function createSpecificationHandler({\n profileId,\n fieldTypeId,\n fieldGroupId,\n name,\n categoryId,\n description,\n position,\n isFilter,\n isRequired,\n isOnProductDetails,\n isStockKeepingUnit,\n isWizard,\n isActive,\n isTopMenuLinkActive,\n isSideMenuLinkActive,\n defaultValue,\n}: z.infer<typeof createSpecificationSchema>) {\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 createdSpecification = await createSpecification(resolvedProfileId, {\n FieldTypeId: fieldTypeId,\n FieldGroupId: fieldGroupId,\n Name: name,\n CategoryId: categoryId,\n Description: description ?? null,\n Position: position ?? 0,\n IsFilter: isFilter ?? false,\n IsRequired: isRequired ?? false,\n IsOnProductDetails: isOnProductDetails ?? true,\n IsStockKeepingUnit: isStockKeepingUnit ?? false,\n IsWizard: isWizard ?? false,\n IsActive: isActive ?? true,\n IsTopMenuLinkActive: isTopMenuLinkActive ?? false,\n IsSideMenuLinkActive: isSideMenuLinkActive ?? false,\n DefaultValue: defaultValue ?? \"\",\n });\n\n return buildWriteSuccessResponse({\n profileId: resolvedProfileId,\n operation: \"create_specification\",\n resourceId: String(createdSpecification.Id ?? \"\"),\n riskLevel: \"low\",\n message: \"Specification created successfully.\",\n before: null,\n after: createdSpecification,\n });\n } catch (err) {\n return handleVtexWriteError(err, \"Failed to create specification in VTEX\");\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAElB,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM,4BAA4B,EAAE,OAAO;AAAA,EAChD,WAAW;AAAA,EACX,aAAa,EACV,KAAK,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG,CAAC,EAC7C,UAAU,CAAC,UAAU,OAAO,KAAK,CAAC,EAClC,SAAS,8BAA8B;AAAA,EAC1C,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,yBAAyB;AAAA,E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UAAM,oBAAoB,kBAAkB,MAAM;AAClD,UAAM,uBAAuB,MAAM,oBAAoB,mBAAmB;AAAA,MACxE,aAAa;AAAA,MACb,cAAc;AAAA,MACd,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,aAAa,eAAe;AAAA,MAC5B,UAAU,YAAY;AAAA,MACtB,UAAU,YAAY;AAAA,MACtB,YAAY,cAAc;AAAA,MAC1B,oBAAoB,sBAAsB;AAAA,MAC1C,oBAAoB,sBAAsB;AAAA,MAC1C,UAAU,YAAY;AAAA,MACtB,UAAU,YAAY;AAAA,MACtB,qBAAqB,uBAAuB;AAAA,MAC5C,sBAAsB,wBAAwB;AAAA,MAC9C,cAAc,gBAAgB;AAAA,IAChC,CAAC;AAED,WAAO,0BAA0B;AAAA,MAC/B,WAAW;AAAA,MACX,WAAW;AAAA,MACX,YAAY,OAAO,qBAAqB,MAAM,EAAE;AAAA,MAChD,WAAW;AAAA,MACX,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,OAAO;AAAA,IACT,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,WAAO,qBAAqB,KAAK,wCAAwC;AAAA,EAC3E;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+ import {
3
+ buildSkuUpdatePayload,
4
+ getSku,
5
+ updateSku
6
+ } from "../../services/vtex/vtex-catalog-write.js";
7
+ import {
8
+ buildWriteSuccessResponse,
9
+ handleVtexWriteError,
10
+ resolveVtexWriteProfile,
11
+ vtexProfileIdSchemaField
12
+ } from "./write-helpers.js";
13
+ const deactivateSkuSchema = z.object({
14
+ profileId: vtexProfileIdSchemaField,
15
+ skuId: z.string().min(1).describe("VTEX SKU identifier to deactivate.")
16
+ });
17
+ async function deactivateSkuHandler({
18
+ profileId,
19
+ skuId
20
+ }) {
21
+ try {
22
+ const profileResolution = await resolveVtexWriteProfile(profileId);
23
+ if (!profileResolution.ok) {
24
+ return profileResolution.response;
25
+ }
26
+ const resolvedProfileId = profileResolution.value.profileId;
27
+ const beforeSku = await getSku(resolvedProfileId, skuId);
28
+ const afterSku = await updateSku(
29
+ resolvedProfileId,
30
+ skuId,
31
+ buildSkuUpdatePayload(beforeSku, { isActive: false })
32
+ );
33
+ return buildWriteSuccessResponse({
34
+ profileId: resolvedProfileId,
35
+ operation: "deactivate_sku",
36
+ resourceId: skuId,
37
+ riskLevel: "low",
38
+ message: "SKU deactivated successfully.",
39
+ before: beforeSku,
40
+ after: afterSku,
41
+ details: {
42
+ sku_id: skuId
43
+ }
44
+ });
45
+ } catch (err) {
46
+ return handleVtexWriteError(err, `Failed to deactivate SKU ${skuId}`);
47
+ }
48
+ }
49
+ export {
50
+ deactivateSkuHandler,
51
+ deactivateSkuSchema
52
+ };
53
+ //# sourceMappingURL=deactivate-sku.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/tools/vtex/deactivate-sku.ts"],
4
+ "sourcesContent": ["import { z } from \"zod\";\n\nimport {\n buildSkuUpdatePayload,\n getSku,\n updateSku,\n} from \"../../services/vtex/vtex-catalog-write.js\";\nimport {\n buildWriteSuccessResponse,\n handleVtexWriteError,\n resolveVtexWriteProfile,\n vtexProfileIdSchemaField,\n} from \"./write-helpers.js\";\n\nexport const deactivateSkuSchema = z.object({\n profileId: vtexProfileIdSchemaField,\n skuId: z.string().min(1).describe(\"VTEX SKU identifier to deactivate.\"),\n});\n\nexport async function deactivateSkuHandler({\n profileId,\n skuId,\n}: z.infer<typeof deactivateSkuSchema>) {\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 beforeSku = await getSku(resolvedProfileId, skuId);\n const afterSku = await updateSku(\n resolvedProfileId,\n skuId,\n buildSkuUpdatePayload(beforeSku, { isActive: false })\n );\n\n return buildWriteSuccessResponse({\n profileId: resolvedProfileId,\n operation: \"deactivate_sku\",\n resourceId: skuId,\n riskLevel: \"low\",\n message: \"SKU deactivated successfully.\",\n before: beforeSku,\n after: afterSku,\n details: {\n sku_id: skuId,\n },\n });\n } catch (err) {\n return handleVtexWriteError(err, `Failed to deactivate SKU ${skuId}`);\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM,sBAAsB,EAAE,OAAO;AAAA,EAC1C,WAAW;AAAA,EACX,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,oCAAoC;AACxE,CAAC;AAED,eAAsB,qBAAqB;AAAA,EACzC;AAAA,EACA;AACF,GAAwC;AACtC,MAAI;AACF,UAAM,oBAAoB,MAAM,wBAAwB,SAAS;AACjE,QAAI,CAAC,kBAAkB,IAAI;AACzB,aAAO,kBAAkB;AAAA,IAC3B;AAEA,UAAM,oBAAoB,kBAAkB,MAAM;AAClD,UAAM,YAAY,MAAM,OAAO,mBAAmB,KAAK;AACvD,UAAM,WAAW,MAAM;AAAA,MACrB;AAAA,MACA;AAAA,MACA,sBAAsB,WAAW,EAAE,UAAU,MAAM,CAAC;AAAA,IACtD;AAEA,WAAO,0BAA0B;AAAA,MAC/B,WAAW;AAAA,MACX,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,SAAS;AAAA,QACP,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,WAAO,qBAAqB,KAAK,4BAA4B,KAAK,EAAE;AAAA,EACtE;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+ import { getSkuPrice } from "../../services/vtex/vtex-pricing.js";
3
+ import { deleteFixedPricesForPriceTable } from "../../services/vtex/vtex-pricing-write.js";
4
+ import {
5
+ buildWriteSuccessResponse,
6
+ handleVtexWriteError,
7
+ resolveVtexWriteProfile,
8
+ vtexProfileIdSchemaField
9
+ } from "./write-helpers.js";
10
+ const deleteFixedPriceSchema = z.object({
11
+ profileId: vtexProfileIdSchemaField,
12
+ skuId: z.string().min(1).describe("SKU item identifier used by VTEX Pricing."),
13
+ priceTableId: z.string().min(1).describe("Trade policy or price table identifier to clear.")
14
+ });
15
+ async function deleteFixedPriceHandler({
16
+ profileId,
17
+ skuId,
18
+ priceTableId
19
+ }) {
20
+ try {
21
+ const profileResolution = await resolveVtexWriteProfile(profileId);
22
+ if (!profileResolution.ok) {
23
+ return profileResolution.response;
24
+ }
25
+ const resolvedProfileId = profileResolution.value.profileId;
26
+ const beforePrice = await getSkuPrice(resolvedProfileId, skuId);
27
+ await deleteFixedPricesForPriceTable(resolvedProfileId, skuId, priceTableId);
28
+ const afterPrice = await getSkuPrice(resolvedProfileId, skuId);
29
+ return buildWriteSuccessResponse({
30
+ profileId: resolvedProfileId,
31
+ operation: "delete_fixed_price",
32
+ resourceId: skuId,
33
+ riskLevel: "low",
34
+ message: "Fixed prices deleted successfully for the selected price table.",
35
+ before: beforePrice,
36
+ after: afterPrice,
37
+ details: {
38
+ sku_id: skuId,
39
+ price_table_id: priceTableId
40
+ }
41
+ });
42
+ } catch (err) {
43
+ return handleVtexWriteError(
44
+ err,
45
+ `Failed to delete fixed prices for SKU ${skuId} on price table ${priceTableId}`
46
+ );
47
+ }
48
+ }
49
+ export {
50
+ deleteFixedPriceHandler,
51
+ deleteFixedPriceSchema
52
+ };
53
+ //# sourceMappingURL=delete-fixed-price.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/tools/vtex/delete-fixed-price.ts"],
4
+ "sourcesContent": ["import { z } from \"zod\";\n\nimport { getSkuPrice } from \"../../services/vtex/vtex-pricing.js\";\nimport { deleteFixedPricesForPriceTable } from \"../../services/vtex/vtex-pricing-write.js\";\nimport {\n buildWriteSuccessResponse,\n handleVtexWriteError,\n resolveVtexWriteProfile,\n vtexProfileIdSchemaField,\n} from \"./write-helpers.js\";\n\nexport const deleteFixedPriceSchema = z.object({\n profileId: vtexProfileIdSchemaField,\n skuId: z.string().min(1).describe(\"SKU item identifier used by VTEX Pricing.\"),\n priceTableId: z.string().min(1).describe(\"Trade policy or price table identifier to clear.\"),\n});\n\nexport async function deleteFixedPriceHandler({\n profileId,\n skuId,\n priceTableId,\n}: z.infer<typeof deleteFixedPriceSchema>) {\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 beforePrice = await getSkuPrice(resolvedProfileId, skuId);\n\n await deleteFixedPricesForPriceTable(resolvedProfileId, skuId, priceTableId);\n\n const afterPrice = await getSkuPrice(resolvedProfileId, skuId);\n\n return buildWriteSuccessResponse({\n profileId: resolvedProfileId,\n operation: \"delete_fixed_price\",\n resourceId: skuId,\n riskLevel: \"low\",\n message: \"Fixed prices deleted successfully for the selected price table.\",\n before: beforePrice as unknown as Record<string, unknown>,\n after: afterPrice as unknown as Record<string, unknown>,\n details: {\n sku_id: skuId,\n price_table_id: priceTableId,\n },\n });\n } catch (err) {\n return handleVtexWriteError(\n err,\n `Failed to delete fixed prices for SKU ${skuId} on price table ${priceTableId}`\n );\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAElB,SAAS,mBAAmB;AAC5B,SAAS,sCAAsC;AAC/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM,yBAAyB,EAAE,OAAO;AAAA,EAC7C,WAAW;AAAA,EACX,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,2CAA2C;AAAA,EAC7E,cAAc,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,kDAAkD;AAC7F,CAAC;AAED,eAAsB,wBAAwB;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AACF,GAA2C;AACzC,MAAI;AACF,UAAM,oBAAoB,MAAM,wBAAwB,SAAS;AACjE,QAAI,CAAC,kBAAkB,IAAI;AACzB,aAAO,kBAAkB;AAAA,IAC3B;AAEA,UAAM,oBAAoB,kBAAkB,MAAM;AAClD,UAAM,cAAc,MAAM,YAAY,mBAAmB,KAAK;AAE9D,UAAM,+BAA+B,mBAAmB,OAAO,YAAY;AAE3E,UAAM,aAAa,MAAM,YAAY,mBAAmB,KAAK;AAE7D,WAAO,0BAA0B;AAAA,MAC/B,WAAW;AAAA,MACX,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,SAAS;AAAA,QACP,QAAQ;AAAA,QACR,gBAAgB;AAAA,MAClB;AAAA,IACF,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,WAAO;AAAA,MACL;AAAA,MACA,yCAAyC,KAAK,mBAAmB,YAAY;AAAA,IAC/E;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -4,8 +4,29 @@ export * from "./inventory-check.js";
4
4
  export * from "./warehouse-inventory.js";
5
5
  export * from "./update-inventory.js";
6
6
  export * from "./update-lead-time.js";
7
+ export * from "./toggle-unlimited-quantity.js";
7
8
  export * from "./sku-price.js";
8
9
  export * from "./computed-price.js";
9
10
  export * from "./product-offers.js";
10
11
  export * from "./sku-offers.js";
12
+ export * from "./update-sku-price.js";
13
+ export * from "./upsert-fixed-price.js";
14
+ export * from "./delete-fixed-price.js";
15
+ export * from "./activate-sku.js";
16
+ export * from "./deactivate-sku.js";
17
+ export * from "./update-product-basic-fields.js";
18
+ export * from "./update-sku-basic-fields.js";
19
+ export * from "./create-product.js";
20
+ export * from "./create-sku.js";
21
+ export * from "./create-product-with-sku.js";
22
+ export * from "./create-brand.js";
23
+ export * from "./create-category.js";
24
+ export * from "./create-specification.js";
25
+ export * from "./create-specification-value.js";
26
+ export * from "./associate-specification.js";
27
+ export * from "./attach-catalog-image.js";
28
+ export * from "./cancel-order.js";
29
+ export * from "./invoice-order.js";
30
+ export * from "./add-order-tracking.js";
31
+ export * from "./profile-resolution.js";
11
32
  //# sourceMappingURL=index.js.map
@@ -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 \"./sku-price.js\";\nexport * from \"./computed-price.js\";\nexport * from \"./product-offers.js\";\nexport * from \"./sku-offers.js\";\n"],
5
- "mappings": "AAAA,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 \"./update-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 \"./create-product-with-sku.js\";\nexport * from \"./create-brand.js\";\nexport * from \"./create-category.js\";\nexport * from \"./create-specification.js\";\nexport * from \"./create-specification-value.js\";\nexport * from \"./associate-specification.js\";\nexport * from \"./attach-catalog-image.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;",
6
6
  "names": []
7
7
  }
@@ -3,6 +3,7 @@ import { z } from "zod";
3
3
  import { formatVtexError } from "../../services/vtex/vtex-api.js";
4
4
  import { getInventoryBySkuBatch } from "../../services/vtex/vtex-logistics.js";
5
5
  import { stripNulls } from "../../utils/strip-payload.js";
6
+ import { resolveVtexProfileOrSelection } from "./profile-resolution.js";
6
7
  const MAX_SKU_IDS = 50;
7
8
  const MAX_CONCURRENT_REQUESTS = 10;
8
9
  const MAX_RETRIES_PER_SKU = 2;
@@ -36,12 +37,23 @@ function formatCompactUtcDate(dateTime) {
36
37
  return `${match[1]} ${match[2]}`;
37
38
  }
38
39
  const inventoryCheckSchema = z.object({
40
+ profileId: z.string().trim().min(1).optional().describe(
41
+ "Explicit VTEX profile id to use. If omitted, the tool returns a guided selection payload with available active profiles."
42
+ ),
39
43
  skuIds: z.array(z.string().trim().min(1).describe("SKU identifier")).min(1).max(MAX_SKU_IDS).describe("List of SKU identifiers to fetch (up to 50 IDs)")
40
44
  });
41
- async function inventoryCheckHandler({ skuIds }) {
45
+ async function inventoryCheckHandler({
46
+ profileId,
47
+ skuIds
48
+ }) {
42
49
  try {
50
+ const profileResolution = await resolveVtexProfileOrSelection(profileId);
51
+ if (!profileResolution.ok) {
52
+ return profileResolution.response;
53
+ }
54
+ const resolvedProfileId = profileResolution.value.profileId;
43
55
  const uniqueSkuIds = Array.from(new Set(skuIds));
44
- const batchResult = await getInventoryBySkuBatch(uniqueSkuIds, {
56
+ const batchResult = await getInventoryBySkuBatch(resolvedProfileId, uniqueSkuIds, {
45
57
  maxConcurrency: MAX_CONCURRENT_REQUESTS,
46
58
  maxRetries: MAX_RETRIES_PER_SKU
47
59
  });
@@ -116,6 +128,7 @@ async function inventoryCheckHandler({ skuIds }) {
116
128
  return object(
117
129
  stripNulls({
118
130
  metadata: {
131
+ profile_id: resolvedProfileId,
119
132
  requested_ids: skuIds.length,
120
133
  unique_ids: uniqueSkuIds.length,
121
134
  max_parallel_requests: MAX_CONCURRENT_REQUESTS,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/tools/vtex/inventory-check.ts"],
4
- "sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { formatVtexError } from \"../../services/vtex/vtex-api.js\";\nimport { getInventoryBySkuBatch } from \"../../services/vtex/vtex-logistics.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\ntype HealthStatus = \"HEALTHY\" | \"LOW_STOCK\" | \"CRITICAL_LOW_STOCK\" | \"OUT_OF_STOCK\";\ntype SkuInventoryRow = [string, number, HealthStatus];\ntype WarehouseBalanceBaseRow = [string, number, number, boolean];\ntype WarehouseBalanceWithRefillRow = [...WarehouseBalanceBaseRow, string];\ntype WarehouseBalanceWithDateRow = [...WarehouseBalanceBaseRow, string];\ntype WarehouseBalanceFullRow = [...WarehouseBalanceBaseRow, string, string];\ntype WarehouseBalanceRow =\n | WarehouseBalanceBaseRow\n | WarehouseBalanceWithRefillRow\n | WarehouseBalanceWithDateRow\n | WarehouseBalanceFullRow;\n\nconst MAX_SKU_IDS = 50;\nconst MAX_CONCURRENT_REQUESTS = 10;\nconst MAX_RETRIES_PER_SKU = 2;\n\nfunction inferHealthStatus(globalAvailableQuantity: number, hasUnlimitedQuantity: boolean): HealthStatus {\n if (hasUnlimitedQuantity) {\n return \"HEALTHY\";\n }\n\n if (globalAvailableQuantity <= 0) {\n return \"OUT_OF_STOCK\";\n }\n\n if (globalAvailableQuantity < 5) {\n return \"CRITICAL_LOW_STOCK\";\n }\n\n if (globalAvailableQuantity < 20) {\n return \"LOW_STOCK\";\n }\n\n return \"HEALTHY\";\n}\n\nfunction toNumber(value: unknown): number {\n const parsedValue = Number(value);\n return Number.isFinite(parsedValue) ? parsedValue : 0;\n}\n\nfunction formatCompactUtcDate(dateTime?: string): string {\n if (!dateTime) {\n return \"\";\n }\n\n const match = dateTime.match(/^(\\d{4}-\\d{2}-\\d{2})T(\\d{2}:\\d{2})/);\n if (!match) {\n return dateTime;\n }\n\n return `${match[1]} ${match[2]}`;\n}\n\nexport const inventoryCheckSchema = z.object({\n skuIds: z\n .array(z.string().trim().min(1).describe(\"SKU identifier\"))\n .min(1)\n .max(MAX_SKU_IDS)\n .describe(\"List of SKU identifiers to fetch (up to 50 IDs)\"),\n});\n\nexport async function inventoryCheckHandler({ skuIds }: z.infer<typeof inventoryCheckSchema>) {\n try {\n const uniqueSkuIds = Array.from(new Set(skuIds));\n const batchResult = await getInventoryBySkuBatch(uniqueSkuIds, {\n maxConcurrency: MAX_CONCURRENT_REQUESTS,\n maxRetries: MAX_RETRIES_PER_SKU,\n });\n\n const hasAnyTimeToRefill = batchResult.successful.some(({ document }) =>\n (Array.isArray(document.balance) ? document.balance : []).some(\n (balance) => typeof balance.timeToRefill === \"string\" && balance.timeToRefill.trim().length > 0\n )\n );\n const hasAnyDateOfSupplyUtc = batchResult.successful.some(({ document }) =>\n (Array.isArray(document.balance) ? document.balance : []).some(\n (balance) =>\n typeof balance.dateOfSupplyUtc === \"string\" && balance.dateOfSupplyUtc.trim().length > 0\n )\n );\n\n const warehouseBalanceSchema = [\"warehouseName\", \"totalQuantity\", \"reservedQuantity\", \"hasUnlimitedQuantity\"];\n if (hasAnyTimeToRefill) {\n warehouseBalanceSchema.push(\"timeToRefill\");\n }\n if (hasAnyDateOfSupplyUtc) {\n warehouseBalanceSchema.push(\"dateOfSupplyUtc\");\n }\n\n const inventory = batchResult.successful.map(({ skuId, document }) => {\n const balances = Array.isArray(document.balance) ? document.balance : [];\n const warehouses: WarehouseBalanceRow[] = balances.map((balance) => {\n const totalQuantity = toNumber(balance.totalQuantity);\n const reservedQuantity = toNumber(balance.reservedQuantity);\n const availableQuantityRaw = balance.availableQuantity;\n const availableQuantity =\n availableQuantityRaw === undefined\n ? Math.max(0, totalQuantity - reservedQuantity)\n : toNumber(availableQuantityRaw);\n const hasUnlimitedQuantity = Boolean(\n balance.hasUnlimitedQuantity ?? balance.isUnlimited ?? false\n );\n\n const warehouseBase: WarehouseBalanceBaseRow = [\n balance.warehouseName ?? balance.warehouseId ?? \"unknown\",\n totalQuantity,\n reservedQuantity,\n hasUnlimitedQuantity,\n ];\n\n if (hasAnyTimeToRefill && hasAnyDateOfSupplyUtc) {\n return [\n ...warehouseBase,\n balance.timeToRefill ?? \"\",\n formatCompactUtcDate(balance.dateOfSupplyUtc),\n ];\n }\n\n if (hasAnyTimeToRefill) {\n return [...warehouseBase, balance.timeToRefill ?? \"\"];\n }\n\n if (hasAnyDateOfSupplyUtc) {\n return [...warehouseBase, formatCompactUtcDate(balance.dateOfSupplyUtc)];\n }\n\n return warehouseBase;\n });\n\n const globalAvailableQuantity = balances.reduce((accumulator, balance) => {\n const totalQuantity = toNumber(balance.totalQuantity);\n const reservedQuantity = toNumber(balance.reservedQuantity);\n const availableQuantityRaw = balance.availableQuantity;\n const availableQuantity =\n availableQuantityRaw === undefined\n ? Math.max(0, totalQuantity - reservedQuantity)\n : toNumber(availableQuantityRaw);\n return accumulator + availableQuantity;\n }, 0);\n const hasUnlimitedQuantity = balances.some((balance) =>\n Boolean(balance.hasUnlimitedQuantity ?? balance.isUnlimited ?? false)\n );\n const skuRow: SkuInventoryRow = [\n document.skuId ?? skuId,\n globalAvailableQuantity,\n inferHealthStatus(globalAvailableQuantity, hasUnlimitedQuantity),\n ];\n\n return {\n sku: skuRow,\n warehouses,\n };\n });\n\n return object(\n stripNulls({\n metadata: {\n requested_ids: skuIds.length,\n unique_ids: uniqueSkuIds.length,\n max_parallel_requests: MAX_CONCURRENT_REQUESTS,\n successful_items: batchResult.successful.length,\n failed_items: batchResult.failed.length,\n has_failures: batchResult.failed.length > 0,\n },\n inventory_schema: {\n sku: [\"sku_id\", \"global_available_quantity\", \"health_status\"],\n warehouse_balance: warehouseBalanceSchema,\n },\n inventory,\n failures: batchResult.failed.map((failure) => ({\n sku_id: failure.skuId,\n message: failure.message,\n status_code: failure.statusCode,\n attempts: failure.attempts,\n retryable: failure.retryable,\n })),\n })\n );\n } catch (err) {\n return error(formatVtexError(err, \"Failed to check inventory batch\"));\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AACvC,SAAS,kBAAkB;AAc3B,MAAM,cAAc;AACpB,MAAM,0BAA0B;AAChC,MAAM,sBAAsB;AAE5B,SAAS,kBAAkB,yBAAiC,sBAA6C;AACvG,MAAI,sBAAsB;AACxB,WAAO;AAAA,EACT;AAEA,MAAI,2BAA2B,GAAG;AAChC,WAAO;AAAA,EACT;AAEA,MAAI,0BAA0B,GAAG;AAC/B,WAAO;AAAA,EACT;AAEA,MAAI,0BAA0B,IAAI;AAChC,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEA,SAAS,SAAS,OAAwB;AACxC,QAAM,cAAc,OAAO,KAAK;AAChC,SAAO,OAAO,SAAS,WAAW,IAAI,cAAc;AACtD;AAEA,SAAS,qBAAqB,UAA2B;AACvD,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,SAAS,MAAM,oCAAoC;AACjE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,MAAM,CAAC,CAAC,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yB,oBAAoB;AAAA,MACjE;AAEA,aAAO;AAAA,QACL,KAAK;AAAA,QACL;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,WAAW;AAAA,QACT,UAAU;AAAA,UACR,eAAe,OAAO;AAAA,UACtB,YAAY,aAAa;AAAA,UACzB,uBAAuB;AAAA,UACvB,kBAAkB,YAAY,WAAW;AAAA,UACzC,cAAc,YAAY,OAAO;AAAA,UACjC,cAAc,YAAY,OAAO,SAAS;AAAA,QAC5C;AAAA,QACA,kBAAkB;AAAA,UAChB,KAAK,CAAC,UAAU,6BAA6B,eAAe;AAAA,UAC5D,mBAAmB;AAAA,QACrB;AAAA,QACA;AAAA,QACA,UAAU,YAAY,OAAO,IAAI,CAAC,aAAa;AAAA,UAC7C,QAAQ,QAAQ;AAAA,UAChB,SAAS,QAAQ;AAAA,UACjB,aAAa,QAAQ;AAAA,UACrB,UAAU,QAAQ;AAAA,UAClB,WAAW,QAAQ;AAAA,QACrB,EAAE;AAAA,MACJ,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,gBAAgB,KAAK,iCAAiC,CAAC;AAAA,EACtE;AACF;",
4
+ "sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { formatVtexError } from \"../../services/vtex/vtex-api.js\";\nimport { getInventoryBySkuBatch } from \"../../services/vtex/vtex-logistics.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\nimport { resolveVtexProfileOrSelection } from \"./profile-resolution.js\";\n\ntype HealthStatus = \"HEALTHY\" | \"LOW_STOCK\" | \"CRITICAL_LOW_STOCK\" | \"OUT_OF_STOCK\";\ntype SkuInventoryRow = [string, number, HealthStatus];\ntype WarehouseBalanceBaseRow = [string, number, number, boolean];\ntype WarehouseBalanceWithRefillRow = [...WarehouseBalanceBaseRow, string];\ntype WarehouseBalanceWithDateRow = [...WarehouseBalanceBaseRow, string];\ntype WarehouseBalanceFullRow = [...WarehouseBalanceBaseRow, string, string];\ntype WarehouseBalanceRow =\n | WarehouseBalanceBaseRow\n | WarehouseBalanceWithRefillRow\n | WarehouseBalanceWithDateRow\n | WarehouseBalanceFullRow;\n\nconst MAX_SKU_IDS = 50;\nconst MAX_CONCURRENT_REQUESTS = 10;\nconst MAX_RETRIES_PER_SKU = 2;\n\nfunction inferHealthStatus(globalAvailableQuantity: number, hasUnlimitedQuantity: boolean): HealthStatus {\n if (hasUnlimitedQuantity) {\n return \"HEALTHY\";\n }\n\n if (globalAvailableQuantity <= 0) {\n return \"OUT_OF_STOCK\";\n }\n\n if (globalAvailableQuantity < 5) {\n return \"CRITICAL_LOW_STOCK\";\n }\n\n if (globalAvailableQuantity < 20) {\n return \"LOW_STOCK\";\n }\n\n return \"HEALTHY\";\n}\n\nfunction toNumber(value: unknown): number {\n const parsedValue = Number(value);\n return Number.isFinite(parsedValue) ? parsedValue : 0;\n}\n\nfunction formatCompactUtcDate(dateTime?: string): string {\n if (!dateTime) {\n return \"\";\n }\n\n const match = dateTime.match(/^(\\d{4}-\\d{2}-\\d{2})T(\\d{2}:\\d{2})/);\n if (!match) {\n return dateTime;\n }\n\n return `${match[1]} ${match[2]}`;\n}\n\nexport const inventoryCheckSchema = z.object({\n profileId: z\n .string()\n .trim()\n .min(1)\n .optional()\n .describe(\n \"Explicit VTEX profile id to use. If omitted, the tool returns a guided selection payload with available active profiles.\"\n ),\n skuIds: z\n .array(z.string().trim().min(1).describe(\"SKU identifier\"))\n .min(1)\n .max(MAX_SKU_IDS)\n .describe(\"List of SKU identifiers to fetch (up to 50 IDs)\"),\n});\n\nexport async function inventoryCheckHandler({\n profileId,\n skuIds,\n}: z.infer<typeof inventoryCheckSchema>) {\n try {\n const profileResolution = await resolveVtexProfileOrSelection(profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const resolvedProfileId = profileResolution.value.profileId;\n const uniqueSkuIds = Array.from(new Set(skuIds));\n const batchResult = await getInventoryBySkuBatch(resolvedProfileId, uniqueSkuIds, {\n maxConcurrency: MAX_CONCURRENT_REQUESTS,\n maxRetries: MAX_RETRIES_PER_SKU,\n });\n\n const hasAnyTimeToRefill = batchResult.successful.some(({ document }) =>\n (Array.isArray(document.balance) ? document.balance : []).some(\n (balance) => typeof balance.timeToRefill === \"string\" && balance.timeToRefill.trim().length > 0\n )\n );\n const hasAnyDateOfSupplyUtc = batchResult.successful.some(({ document }) =>\n (Array.isArray(document.balance) ? document.balance : []).some(\n (balance) =>\n typeof balance.dateOfSupplyUtc === \"string\" && balance.dateOfSupplyUtc.trim().length > 0\n )\n );\n\n const warehouseBalanceSchema = [\"warehouseName\", \"totalQuantity\", \"reservedQuantity\", \"hasUnlimitedQuantity\"];\n if (hasAnyTimeToRefill) {\n warehouseBalanceSchema.push(\"timeToRefill\");\n }\n if (hasAnyDateOfSupplyUtc) {\n warehouseBalanceSchema.push(\"dateOfSupplyUtc\");\n }\n\n const inventory = batchResult.successful.map(({ skuId, document }) => {\n const balances = Array.isArray(document.balance) ? document.balance : [];\n const warehouses: WarehouseBalanceRow[] = balances.map((balance) => {\n const totalQuantity = toNumber(balance.totalQuantity);\n const reservedQuantity = toNumber(balance.reservedQuantity);\n const availableQuantityRaw = balance.availableQuantity;\n const availableQuantity =\n availableQuantityRaw === undefined\n ? Math.max(0, totalQuantity - reservedQuantity)\n : toNumber(availableQuantityRaw);\n const hasUnlimitedQuantity = Boolean(\n balance.hasUnlimitedQuantity ?? balance.isUnlimited ?? false\n );\n\n const warehouseBase: WarehouseBalanceBaseRow = [\n balance.warehouseName ?? balance.warehouseId ?? \"unknown\",\n totalQuantity,\n reservedQuantity,\n hasUnlimitedQuantity,\n ];\n\n if (hasAnyTimeToRefill && hasAnyDateOfSupplyUtc) {\n return [\n ...warehouseBase,\n balance.timeToRefill ?? \"\",\n formatCompactUtcDate(balance.dateOfSupplyUtc),\n ];\n }\n\n if (hasAnyTimeToRefill) {\n return [...warehouseBase, balance.timeToRefill ?? \"\"];\n }\n\n if (hasAnyDateOfSupplyUtc) {\n return [...warehouseBase, formatCompactUtcDate(balance.dateOfSupplyUtc)];\n }\n\n return warehouseBase;\n });\n\n const globalAvailableQuantity = balances.reduce((accumulator, balance) => {\n const totalQuantity = toNumber(balance.totalQuantity);\n const reservedQuantity = toNumber(balance.reservedQuantity);\n const availableQuantityRaw = balance.availableQuantity;\n const availableQuantity =\n availableQuantityRaw === undefined\n ? Math.max(0, totalQuantity - reservedQuantity)\n : toNumber(availableQuantityRaw);\n return accumulator + availableQuantity;\n }, 0);\n const hasUnlimitedQuantity = balances.some((balance) =>\n Boolean(balance.hasUnlimitedQuantity ?? balance.isUnlimited ?? false)\n );\n const skuRow: SkuInventoryRow = [\n document.skuId ?? skuId,\n globalAvailableQuantity,\n inferHealthStatus(globalAvailableQuantity, hasUnlimitedQuantity),\n ];\n\n return {\n sku: skuRow,\n warehouses,\n };\n });\n\n return object(\n stripNulls({\n metadata: {\n profile_id: resolvedProfileId,\n requested_ids: skuIds.length,\n unique_ids: uniqueSkuIds.length,\n max_parallel_requests: MAX_CONCURRENT_REQUESTS,\n successful_items: batchResult.successful.length,\n failed_items: batchResult.failed.length,\n has_failures: batchResult.failed.length > 0,\n },\n inventory_schema: {\n sku: [\"sku_id\", \"global_available_quantity\", \"health_status\"],\n warehouse_balance: warehouseBalanceSchema,\n },\n inventory,\n failures: batchResult.failed.map((failure) => ({\n sku_id: failure.skuId,\n message: failure.message,\n status_code: failure.statusCode,\n attempts: failure.attempts,\n retryable: failure.retryable,\n })),\n })\n );\n } catch (err) {\n return error(formatVtexError(err, \"Failed to check inventory batch\"));\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AACvC,SAAS,kBAAkB;AAC3B,SAAS,qCAAqC;AAc9C,MAAM,cAAc;AACpB,MAAM,0BAA0B;AAChC,MAAM,sBAAsB;AAE5B,SAAS,kBAAkB,yBAAiC,sB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AY,OAAO,IAAI,CAAC,aAAa;AAAA,UAC7C,QAAQ,QAAQ;AAAA,UAChB,SAAS,QAAQ;AAAA,UACjB,aAAa,QAAQ;AAAA,UACrB,UAAU,QAAQ;AAAA,UAClB,WAAW,QAAQ;AAAA,QACrB,EAAE;AAAA,MACJ,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,gBAAgB,KAAK,iCAAiC,CAAC;AAAA,EACtE;AACF;",
6
6
  "names": ["hasUnlimitedQuantity"]
7
7
  }
@@ -0,0 +1,84 @@
1
+ import { z } from "zod";
2
+ import {
3
+ getOrderStateSnapshot,
4
+ invoiceOrder,
5
+ validateOrderForInvoice
6
+ } from "../../services/vtex/vtex-orders-write.js";
7
+ import {
8
+ buildWriteSuccessResponse,
9
+ confirmationNoteSchemaField,
10
+ confirmationSchemaField,
11
+ handleVtexWriteError,
12
+ requireExplicitConfirmation,
13
+ resolveVtexWriteProfile,
14
+ vtexProfileIdSchemaField
15
+ } from "./write-helpers.js";
16
+ const invoiceItemSchema = z.object({
17
+ id: z.string().min(1).describe("SKU ID being invoiced."),
18
+ price: z.number().int().positive().describe("Unit price in cents, without decimal separator."),
19
+ quantity: z.number().int().positive().describe("Quantity being invoiced."),
20
+ description: z.string().optional().describe("Optional extra description for this line.")
21
+ });
22
+ const invoiceOrderSchema = z.object({
23
+ profileId: vtexProfileIdSchemaField,
24
+ orderId: z.string().min(1).describe("VTEX order identifier to invoice."),
25
+ confirmed: confirmationSchemaField,
26
+ confirmationNote: confirmationNoteSchemaField,
27
+ type: z.enum(["Output", "Input"]).describe("Invoice type."),
28
+ issuanceDate: z.string().min(1).describe("Invoice issuance timestamp."),
29
+ invoiceNumber: z.string().min(1).describe("Invoice number."),
30
+ invoiceValue: z.string().min(1).describe("Invoice total in cents, represented as a string without decimal separator."),
31
+ items: z.array(invoiceItemSchema).min(1).describe("Items being invoiced."),
32
+ invoiceKey: z.string().optional().describe("Optional invoice key."),
33
+ invoiceUrl: z.string().url().optional().describe("Optional invoice URL."),
34
+ invoiceOrderNumber: z.string().optional().describe("Optional order number from merchant ERP."),
35
+ courier: z.string().optional().describe("Optional carrier name."),
36
+ trackingNumber: z.string().optional().describe("Optional tracking number."),
37
+ trackingUrl: z.string().url().optional().describe("Optional tracking URL.")
38
+ });
39
+ async function invoiceOrderHandler({
40
+ profileId,
41
+ orderId,
42
+ confirmed,
43
+ confirmationNote,
44
+ ...payload
45
+ }) {
46
+ const confirmationResponse = requireExplicitConfirmation(confirmed, "invoice_order", {
47
+ order_id: orderId
48
+ });
49
+ if (confirmationResponse) {
50
+ return confirmationResponse;
51
+ }
52
+ try {
53
+ const profileResolution = await resolveVtexWriteProfile(profileId);
54
+ if (!profileResolution.ok) {
55
+ return profileResolution.response;
56
+ }
57
+ const resolvedProfileId = profileResolution.value.profileId;
58
+ const beforeOrder = await validateOrderForInvoice(resolvedProfileId, orderId);
59
+ await invoiceOrder(resolvedProfileId, orderId, payload);
60
+ const afterOrder = await getOrderStateSnapshot(resolvedProfileId, orderId);
61
+ return buildWriteSuccessResponse({
62
+ profileId: resolvedProfileId,
63
+ operation: "invoice_order",
64
+ resourceId: orderId,
65
+ riskLevel: "high",
66
+ confirmed: true,
67
+ confirmationNote,
68
+ message: "Order invoiced successfully.",
69
+ before: beforeOrder,
70
+ after: afterOrder,
71
+ details: {
72
+ order_id: orderId,
73
+ invoice_number: payload.invoiceNumber
74
+ }
75
+ });
76
+ } catch (err) {
77
+ return handleVtexWriteError(err, `Failed to invoice order ${orderId}`);
78
+ }
79
+ }
80
+ export {
81
+ invoiceOrderHandler,
82
+ invoiceOrderSchema
83
+ };
84
+ //# sourceMappingURL=invoice-order.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/tools/vtex/invoice-order.ts"],
4
+ "sourcesContent": ["import { z } from \"zod\";\n\nimport {\n getOrderStateSnapshot,\n invoiceOrder,\n validateOrderForInvoice,\n} from \"../../services/vtex/vtex-orders-write.js\";\nimport {\n buildWriteSuccessResponse,\n confirmationNoteSchemaField,\n confirmationSchemaField,\n handleVtexWriteError,\n requireExplicitConfirmation,\n resolveVtexWriteProfile,\n vtexProfileIdSchemaField,\n} from \"./write-helpers.js\";\n\nconst invoiceItemSchema = z.object({\n id: z.string().min(1).describe(\"SKU ID being invoiced.\"),\n price: z\n .number()\n .int()\n .positive()\n .describe(\"Unit price in cents, without decimal separator.\"),\n quantity: z.number().int().positive().describe(\"Quantity being invoiced.\"),\n description: z.string().optional().describe(\"Optional extra description for this line.\"),\n});\n\nexport const invoiceOrderSchema = z.object({\n profileId: vtexProfileIdSchemaField,\n orderId: z.string().min(1).describe(\"VTEX order identifier to invoice.\"),\n confirmed: confirmationSchemaField,\n confirmationNote: confirmationNoteSchemaField,\n type: z.enum([\"Output\", \"Input\"]).describe(\"Invoice type.\"),\n issuanceDate: z.string().min(1).describe(\"Invoice issuance timestamp.\"),\n invoiceNumber: z.string().min(1).describe(\"Invoice number.\"),\n invoiceValue: z\n .string()\n .min(1)\n .describe(\"Invoice total in cents, represented as a string without decimal separator.\"),\n items: z.array(invoiceItemSchema).min(1).describe(\"Items being invoiced.\"),\n invoiceKey: z.string().optional().describe(\"Optional invoice key.\"),\n invoiceUrl: z.string().url().optional().describe(\"Optional invoice URL.\"),\n invoiceOrderNumber: z.string().optional().describe(\"Optional order number from merchant ERP.\"),\n courier: z.string().optional().describe(\"Optional carrier name.\"),\n trackingNumber: z.string().optional().describe(\"Optional tracking number.\"),\n trackingUrl: z.string().url().optional().describe(\"Optional tracking URL.\"),\n});\n\nexport async function invoiceOrderHandler({\n profileId,\n orderId,\n confirmed,\n confirmationNote,\n ...payload\n}: z.infer<typeof invoiceOrderSchema>) {\n const confirmationResponse = requireExplicitConfirmation(confirmed, \"invoice_order\", {\n order_id: orderId,\n });\n if (confirmationResponse) {\n return confirmationResponse;\n }\n\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 beforeOrder = await validateOrderForInvoice(resolvedProfileId, orderId);\n await invoiceOrder(resolvedProfileId, orderId, payload);\n const afterOrder = await getOrderStateSnapshot(resolvedProfileId, orderId);\n\n return buildWriteSuccessResponse({\n profileId: resolvedProfileId,\n operation: \"invoice_order\",\n resourceId: orderId,\n riskLevel: \"high\",\n confirmed: true,\n confirmationNote,\n message: \"Order invoiced successfully.\",\n before: beforeOrder as unknown as Record<string, unknown>,\n after: afterOrder as unknown as Record<string, unknown>,\n details: {\n order_id: orderId,\n invoice_number: payload.invoiceNumber,\n },\n });\n } catch (err) {\n return handleVtexWriteError(err, `Failed to invoice order ${orderId}`);\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,oBAAoB,EAAE,OAAO;AAAA,EACjC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,wBAAwB;AAAA,EACvD,OAAO,EACJ,OAAO,EACP,IAAI,EACJ,SAAS,EACT,SAAS,iDAAiD;AAAA,EAC7D,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,0BAA0B;AAAA,EACzE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,2CAA2C;AACzF,CAAC;AAEM,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,WAAW;AAAA,EACX,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,mCAAmC;AAAA,EACvE,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,MAAM,EAAE,KAAK,CAAC,UAAU,OAAO,CAAC,EAAE,SAAS,eAAe;AAAA,EAC1D,cAAc,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,S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,WAAW;AAAA,MACX,WAAW;AAAA,MACX;AAAA,MACA,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,SAAS;AAAA,QACP,UAAU;AAAA,QACV,gBAAgB,QAAQ;AAAA,MAC1B;AAAA,IACF,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,WAAO,qBAAqB,KAAK,2BAA2B,OAAO,EAAE;AAAA,EACvE;AACF;",
6
+ "names": []
7
+ }
@@ -4,17 +4,30 @@ import { getOrderDocumentsBatch } from "../../services/vtex/vtex-orders.js";
4
4
  import { formatVtexError } from "../../services/vtex/vtex-api.js";
5
5
  import { formatOrderDetails } from "../../utils/format-order-details.js";
6
6
  import { stripNulls } from "../../utils/strip-payload.js";
7
+ import { resolveVtexProfileOrSelection } from "./profile-resolution.js";
7
8
  const MAX_ORDER_IDS = 50;
8
9
  const MAX_CONCURRENT_REQUESTS = 10;
9
10
  const MAX_RETRIES_PER_ORDER = 2;
10
11
  const orderDetailsSchema = z.object({
12
+ profileId: z.string().trim().min(1).optional().describe(
13
+ "Explicit VTEX profile id to use. If omitted, the tool returns a guided selection payload with available active profiles."
14
+ ),
11
15
  orderIds: z.array(z.string().trim().min(3).describe("VTEX order identifier")).min(1).max(MAX_ORDER_IDS).describe("List of VTEX order identifiers to fetch (up to 50 IDs)"),
12
16
  reason: z.string().trim().min(1).optional().describe("Optional reason for requesting unmasked PII data when required")
13
17
  });
14
- async function orderDetailsHandler({ orderIds, reason }) {
18
+ async function orderDetailsHandler({
19
+ profileId,
20
+ orderIds,
21
+ reason
22
+ }) {
15
23
  try {
24
+ const profileResolution = await resolveVtexProfileOrSelection(profileId);
25
+ if (!profileResolution.ok) {
26
+ return profileResolution.response;
27
+ }
28
+ const resolvedProfileId = profileResolution.value.profileId;
16
29
  const uniqueOrderIds = Array.from(new Set(orderIds));
17
- const batchResult = await getOrderDocumentsBatch(uniqueOrderIds, {
30
+ const batchResult = await getOrderDocumentsBatch(resolvedProfileId, uniqueOrderIds, {
18
31
  reason,
19
32
  maxConcurrency: MAX_CONCURRENT_REQUESTS,
20
33
  maxRetries: MAX_RETRIES_PER_ORDER
@@ -23,6 +36,7 @@ async function orderDetailsHandler({ orderIds, reason }) {
23
36
  return object(
24
37
  stripNulls({
25
38
  metadata: {
39
+ profile_id: resolvedProfileId,
26
40
  requested: uniqueOrderIds.length,
27
41
  successful: batchResult.successful.length,
28
42
  failed: batchResult.failed.length