@yoryoboy/bi-mcp 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.js +244 -0
- package/dist/index.js.map +2 -2
- package/dist/mcp-use.json +2 -2
- package/dist/src/config/mercadolibre-profile-store.js +106 -0
- package/dist/src/config/mercadolibre-profile-store.js.map +7 -0
- package/dist/src/config/mercadolibre.js +153 -0
- package/dist/src/config/mercadolibre.js.map +7 -0
- package/dist/src/services/mercadolibre/mercadolibre-api.js +204 -0
- package/dist/src/services/mercadolibre/mercadolibre-api.js.map +7 -0
- package/dist/src/services/mercadolibre/mercadolibre-items.js +156 -0
- package/dist/src/services/mercadolibre/mercadolibre-items.js.map +7 -0
- package/dist/src/services/mercadolibre/mercadolibre-orders.js +65 -0
- package/dist/src/services/mercadolibre/mercadolibre-orders.js.map +7 -0
- package/dist/src/services/mercadolibre/mercadolibre-questions.js +28 -0
- package/dist/src/services/mercadolibre/mercadolibre-questions.js.map +7 -0
- package/dist/src/tools/index.js +1 -0
- package/dist/src/tools/index.js.map +2 -2
- package/dist/src/tools/mercadolibre/answer-question.js +37 -0
- package/dist/src/tools/mercadolibre/answer-question.js.map +7 -0
- package/dist/src/tools/mercadolibre/create-item.js +82 -0
- package/dist/src/tools/mercadolibre/create-item.js.map +7 -0
- package/dist/src/tools/mercadolibre/estimate-listing-fee.js +60 -0
- package/dist/src/tools/mercadolibre/estimate-listing-fee.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-account-context.js +38 -0
- package/dist/src/tools/mercadolibre/get-account-context.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-category-requirements.js +57 -0
- package/dist/src/tools/mercadolibre/get-category-requirements.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-item-details.js +97 -0
- package/dist/src/tools/mercadolibre/get-item-details.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-item-visits.js +92 -0
- package/dist/src/tools/mercadolibre/get-item-visits.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-listing-quality.js +48 -0
- package/dist/src/tools/mercadolibre/get-listing-quality.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-order-details.js +115 -0
- package/dist/src/tools/mercadolibre/get-order-details.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-orders-summary.js +105 -0
- package/dist/src/tools/mercadolibre/get-orders-summary.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-sales-by-item.js +97 -0
- package/dist/src/tools/mercadolibre/get-sales-by-item.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-sales-trend.js +83 -0
- package/dist/src/tools/mercadolibre/get-sales-trend.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-shipping-summary.js +115 -0
- package/dist/src/tools/mercadolibre/get-shipping-summary.js.map +7 -0
- package/dist/src/tools/mercadolibre/get-store-performance.js +102 -0
- package/dist/src/tools/mercadolibre/get-store-performance.js.map +7 -0
- package/dist/src/tools/mercadolibre/helpers.js +43 -0
- package/dist/src/tools/mercadolibre/helpers.js.map +7 -0
- package/dist/src/tools/mercadolibre/index.js +24 -0
- package/dist/src/tools/mercadolibre/index.js.map +7 -0
- package/dist/src/tools/mercadolibre/pause-or-reactivate-item.js +44 -0
- package/dist/src/tools/mercadolibre/pause-or-reactivate-item.js.map +7 -0
- package/dist/src/tools/mercadolibre/predict-category.js +49 -0
- package/dist/src/tools/mercadolibre/predict-category.js.map +7 -0
- package/dist/src/tools/mercadolibre/profile-resolution.js +56 -0
- package/dist/src/tools/mercadolibre/profile-resolution.js.map +7 -0
- package/dist/src/tools/mercadolibre/search-items.js +91 -0
- package/dist/src/tools/mercadolibre/search-items.js.map +7 -0
- package/dist/src/tools/mercadolibre/search-questions.js +71 -0
- package/dist/src/tools/mercadolibre/search-questions.js.map +7 -0
- package/dist/src/tools/mercadolibre/update-item-basic-fields.js +71 -0
- package/dist/src/tools/mercadolibre/update-item-basic-fields.js.map +7 -0
- package/dist/src/tools/mercadolibre/update-item-description.js +49 -0
- package/dist/src/tools/mercadolibre/update-item-description.js.map +7 -0
- package/dist/src/tools/mercadolibre/update-item-pictures.js +58 -0
- package/dist/src/tools/mercadolibre/update-item-pictures.js.map +7 -0
- package/dist/src/tools/mercadolibre/validate-connection.js +44 -0
- package/dist/src/tools/mercadolibre/validate-connection.js.map +7 -0
- package/dist/src/tools/mercadolibre/write-helpers.js +46 -0
- package/dist/src/tools/mercadolibre/write-helpers.js.map +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { error, object } from "mcp-use/server";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { formatMercadoLibreError } from "../../services/mercadolibre/mercadolibre-api.js";
|
|
4
|
+
import { searchMercadoLibreDomainDiscovery } from "../../services/mercadolibre/mercadolibre-items.js";
|
|
5
|
+
import { stripNulls } from "../../utils/strip-payload.js";
|
|
6
|
+
import { asArray, normalizeString, toNumber } from "./helpers.js";
|
|
7
|
+
import { resolveMercadoLibreProfileOrSelection } from "./profile-resolution.js";
|
|
8
|
+
import { mercadolibreProfileIdSchemaField } from "./write-helpers.js";
|
|
9
|
+
const meliPredictCategorySchema = z.object({
|
|
10
|
+
profileId: mercadolibreProfileIdSchemaField,
|
|
11
|
+
query: z.string().trim().min(2).describe("Search phrase describing the product to categorize."),
|
|
12
|
+
siteId: z.string().trim().min(3).optional().describe("MercadoLibre site id. Defaults to MLA."),
|
|
13
|
+
limit: z.number().int().min(1).max(8).optional().describe("Maximum candidate categories to return. Defaults to 5.")
|
|
14
|
+
});
|
|
15
|
+
async function meliPredictCategoryHandler(params) {
|
|
16
|
+
try {
|
|
17
|
+
const profileResolution = await resolveMercadoLibreProfileOrSelection(params.profileId);
|
|
18
|
+
if (!profileResolution.ok) {
|
|
19
|
+
return profileResolution.response;
|
|
20
|
+
}
|
|
21
|
+
const candidates = await searchMercadoLibreDomainDiscovery(
|
|
22
|
+
profileResolution.value.profileId,
|
|
23
|
+
params.query,
|
|
24
|
+
params.limit ?? 5,
|
|
25
|
+
params.siteId ?? "MLA"
|
|
26
|
+
);
|
|
27
|
+
return object(
|
|
28
|
+
stripNulls({
|
|
29
|
+
profile_id: profileResolution.value.profileId,
|
|
30
|
+
query: params.query,
|
|
31
|
+
site_id: params.siteId ?? "MLA",
|
|
32
|
+
candidates: asArray(candidates).map((candidate) => ({
|
|
33
|
+
category_id: normalizeString(candidate.category_id),
|
|
34
|
+
category_name: normalizeString(candidate.category_name),
|
|
35
|
+
domain_id: normalizeString(candidate.domain_id),
|
|
36
|
+
domain_name: normalizeString(candidate.domain_name),
|
|
37
|
+
attributes_matched: toNumber(candidate.attributes_matched)
|
|
38
|
+
}))
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
return error(formatMercadoLibreError(err, "Failed to predict MercadoLibre category"));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
meliPredictCategoryHandler,
|
|
47
|
+
meliPredictCategorySchema
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=predict-category.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/tools/mercadolibre/predict-category.ts"],
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { formatMercadoLibreError } from \"../../services/mercadolibre/mercadolibre-api.js\";\nimport { searchMercadoLibreDomainDiscovery } from \"../../services/mercadolibre/mercadolibre-items.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\nimport { asArray, normalizeString, toNumber } from \"./helpers.js\";\nimport { resolveMercadoLibreProfileOrSelection } from \"./profile-resolution.js\";\nimport { mercadolibreProfileIdSchemaField } from \"./write-helpers.js\";\n\nexport const meliPredictCategorySchema = z.object({\n profileId: mercadolibreProfileIdSchemaField,\n query: z.string().trim().min(2).describe(\"Search phrase describing the product to categorize.\"),\n siteId: z.string().trim().min(3).optional().describe(\"MercadoLibre site id. Defaults to MLA.\"),\n limit: z.number().int().min(1).max(8).optional().describe(\"Maximum candidate categories to return. Defaults to 5.\"),\n});\n\nexport async function meliPredictCategoryHandler(params: z.infer<typeof meliPredictCategorySchema>) {\n try {\n const profileResolution = await resolveMercadoLibreProfileOrSelection(params.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const candidates = await searchMercadoLibreDomainDiscovery(\n profileResolution.value.profileId,\n params.query,\n params.limit ?? 5,\n params.siteId ?? \"MLA\"\n );\n\n return object(\n stripNulls({\n profile_id: profileResolution.value.profileId,\n query: params.query,\n site_id: params.siteId ?? \"MLA\",\n candidates: asArray<Record<string, unknown>>(candidates).map((candidate) => ({\n category_id: normalizeString(candidate.category_id),\n category_name: normalizeString(candidate.category_name),\n domain_id: normalizeString(candidate.domain_id),\n domain_name: normalizeString(candidate.domain_name),\n attributes_matched: toNumber(candidate.attributes_matched),\n })),\n })\n );\n } catch (err) {\n return error(formatMercadoLibreError(err, \"Failed to predict MercadoLibre category\"));\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,+BAA+B;AACxC,SAAS,yCAAyC;AAClD,SAAS,kBAAkB;AAC3B,SAAS,SAAS,iBAAiB,gBAAgB;AACnD,SAAS,6CAA6C;AACtD,SAAS,wCAAwC;AAE1C,MAAM,4BAA4B,EAAE,OAAO;AAAA,EAChD,WAAW;AAAA,EACX,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,qDAAqD;AAAA,EAC9F,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,wCAAwC;AAAA,EAC7F,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,wDAAwD;AACpH,CAAC;AAED,eAAsB,2BAA2B,QAAmD;AAClG,MAAI;AACF,UAAM,oBAAoB,MAAM,sCAAsC,OAAO,SAAS;AACtF,QAAI,CAAC,kBAAkB,IAAI;AACzB,aAAO,kBAAkB;AAAA,IAC3B;AAEA,UAAM,aAAa,MAAM;AAAA,MACvB,kBAAkB,MAAM;AAAA,MACxB,OAAO;AAAA,MACP,OAAO,SAAS;AAAA,MAChB,OAAO,UAAU;AAAA,IACnB;AAEA,WAAO;AAAA,MACL,WAAW;AAAA,QACT,YAAY,kBAAkB,MAAM;AAAA,QACpC,OAAO,OAAO;AAAA,QACd,SAAS,OAAO,UAAU;AAAA,QAC1B,YAAY,QAAiC,UAAU,EAAE,IAAI,CAAC,eAAe;AAAA,UAC3E,aAAa,gBAAgB,UAAU,WAAW;AAAA,UAClD,eAAe,gBAAgB,UAAU,aAAa;AAAA,UACtD,WAAW,gBAAgB,UAAU,SAAS;AAAA,UAC9C,aAAa,gBAAgB,UAAU,WAAW;AAAA,UAClD,oBAAoB,SAAS,UAAU,kBAAkB;AAAA,QAC3D,EAAE;AAAA,MACJ,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,wBAAwB,KAAK,yCAAyC,CAAC;AAAA,EACtF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { object } from "mcp-use/server";
|
|
2
|
+
import { getProfile, listProfiles } from "../../config/profile-store.js";
|
|
3
|
+
function buildSelectionMessage(reason, profileId) {
|
|
4
|
+
switch (reason) {
|
|
5
|
+
case "missing_profile":
|
|
6
|
+
return "MercadoLibre requiere seleccion explicita de profileId. Reenviar la misma tool con uno de los perfiles activos disponibles.";
|
|
7
|
+
case "profile_not_found":
|
|
8
|
+
return `El profileId "${profileId}" no existe. Reenviar la misma tool con uno de los perfiles activos disponibles.`;
|
|
9
|
+
case "profile_inactive":
|
|
10
|
+
return `El profileId "${profileId}" esta inactivo. Reenviar la misma tool con uno de los perfiles activos disponibles.`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function buildSelectionResponse(reason, profileId) {
|
|
14
|
+
const profiles = await listProfiles({ activeOnly: true });
|
|
15
|
+
return object({
|
|
16
|
+
selection_required: true,
|
|
17
|
+
reason,
|
|
18
|
+
message: buildSelectionMessage(reason, profileId),
|
|
19
|
+
available_profiles: profiles.map((profile) => ({
|
|
20
|
+
profile_id: profile.id,
|
|
21
|
+
name: profile.name
|
|
22
|
+
}))
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function resolveMercadoLibreProfileOrSelection(profileId) {
|
|
26
|
+
const requestedProfileId = profileId?.trim();
|
|
27
|
+
if (!requestedProfileId) {
|
|
28
|
+
return {
|
|
29
|
+
ok: false,
|
|
30
|
+
response: await buildSelectionResponse("missing_profile")
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const profile = await getProfile(requestedProfileId);
|
|
34
|
+
if (!profile) {
|
|
35
|
+
return {
|
|
36
|
+
ok: false,
|
|
37
|
+
response: await buildSelectionResponse("profile_not_found", requestedProfileId)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (!profile.isActive) {
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
response: await buildSelectionResponse("profile_inactive", requestedProfileId)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
ok: true,
|
|
48
|
+
value: {
|
|
49
|
+
profileId: profile.id
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
resolveMercadoLibreProfileOrSelection
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=profile-resolution.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/tools/mercadolibre/profile-resolution.ts"],
|
|
4
|
+
"sourcesContent": ["import { object } from \"mcp-use/server\";\n\nimport { getProfile, listProfiles } from \"../../config/profile-store.js\";\n\nexport type MercadoLibreProfileSelectionReason =\n | \"missing_profile\"\n | \"profile_not_found\"\n | \"profile_inactive\";\n\nexport interface ResolvedMercadoLibreProfile {\n profileId: string;\n}\n\nfunction buildSelectionMessage(\n reason: MercadoLibreProfileSelectionReason,\n profileId?: string\n): string {\n switch (reason) {\n case \"missing_profile\":\n return \"MercadoLibre requiere seleccion explicita de profileId. Reenviar la misma tool con uno de los perfiles activos disponibles.\";\n case \"profile_not_found\":\n return `El profileId \"${profileId}\" no existe. Reenviar la misma tool con uno de los perfiles activos disponibles.`;\n case \"profile_inactive\":\n return `El profileId \"${profileId}\" esta inactivo. Reenviar la misma tool con uno de los perfiles activos disponibles.`;\n }\n}\n\nasync function buildSelectionResponse(\n reason: MercadoLibreProfileSelectionReason,\n profileId?: string\n) {\n const profiles = await listProfiles({ activeOnly: true });\n return object({\n selection_required: true,\n reason,\n message: buildSelectionMessage(reason, profileId),\n available_profiles: profiles.map((profile) => ({\n profile_id: profile.id,\n name: profile.name,\n })),\n });\n}\n\nexport async function resolveMercadoLibreProfileOrSelection(\n profileId?: string\n): Promise<\n | { ok: true; value: ResolvedMercadoLibreProfile }\n | { ok: false; response: ReturnType<typeof object<Record<string, unknown>>> }\n> {\n const requestedProfileId = profileId?.trim();\n\n if (!requestedProfileId) {\n return {\n ok: false,\n response: await buildSelectionResponse(\"missing_profile\"),\n };\n }\n\n const profile = await getProfile(requestedProfileId);\n if (!profile) {\n return {\n ok: false,\n response: await buildSelectionResponse(\"profile_not_found\", requestedProfileId),\n };\n }\n\n if (!profile.isActive) {\n return {\n ok: false,\n response: await buildSelectionResponse(\"profile_inactive\", requestedProfileId),\n };\n }\n\n return {\n ok: true,\n value: {\n profileId: profile.id,\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc;AAEvB,SAAS,YAAY,oBAAoB;AAWzC,SAAS,sBACP,QACA,WACQ;AACR,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,iBAAiB,SAAS;AAAA,IACnC,KAAK;AACH,aAAO,iBAAiB,SAAS;AAAA,EACrC;AACF;AAEA,eAAe,uBACb,QACA,WACA;AACA,QAAM,WAAW,MAAM,aAAa,EAAE,YAAY,KAAK,CAAC;AACxD,SAAO,OAAO;AAAA,IACZ,oBAAoB;AAAA,IACpB;AAAA,IACA,SAAS,sBAAsB,QAAQ,SAAS;AAAA,IAChD,oBAAoB,SAAS,IAAI,CAAC,aAAa;AAAA,MAC7C,YAAY,QAAQ;AAAA,MACpB,MAAM,QAAQ;AAAA,IAChB,EAAE;AAAA,EACJ,CAAC;AACH;AAEA,eAAsB,sCACpB,WAIA;AACA,QAAM,qBAAqB,WAAW,KAAK;AAE3C,MAAI,CAAC,oBAAoB;AACvB,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,UAAU,MAAM,uBAAuB,iBAAiB;AAAA,IAC1D;AAAA,EACF;AAEA,QAAM,UAAU,MAAM,WAAW,kBAAkB;AACnD,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,UAAU,MAAM,uBAAuB,qBAAqB,kBAAkB;AAAA,IAChF;AAAA,EACF;AAEA,MAAI,CAAC,QAAQ,UAAU;AACrB,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,UAAU,MAAM,uBAAuB,oBAAoB,kBAAkB;AAAA,IAC/E;AAAA,EACF;AAEA,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,OAAO;AAAA,MACL,WAAW,QAAQ;AAAA,IACrB;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { error, object } from "mcp-use/server";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { getMercadoLibreAccessForProfile } from "../../config/mercadolibre.js";
|
|
4
|
+
import {
|
|
5
|
+
buildMercadoLibrePaginationMetadata,
|
|
6
|
+
formatMercadoLibreError,
|
|
7
|
+
normalizeMercadoLibrePaging
|
|
8
|
+
} from "../../services/mercadolibre/mercadolibre-api.js";
|
|
9
|
+
import {
|
|
10
|
+
getMercadoLibreItemDetailsBatch,
|
|
11
|
+
searchMercadoLibreItems
|
|
12
|
+
} from "../../services/mercadolibre/mercadolibre-items.js";
|
|
13
|
+
import { stripNulls } from "../../utils/strip-payload.js";
|
|
14
|
+
import { asArray, normalizeString, toNumber } from "./helpers.js";
|
|
15
|
+
import { resolveMercadoLibreProfileOrSelection } from "./profile-resolution.js";
|
|
16
|
+
import { mercadolibreProfileIdSchemaField } from "./write-helpers.js";
|
|
17
|
+
const meliSearchItemsSchema = z.object({
|
|
18
|
+
profileId: mercadolibreProfileIdSchemaField,
|
|
19
|
+
status: z.string().trim().min(1).optional().describe("Optional item status filter."),
|
|
20
|
+
category: z.string().trim().min(1).optional().describe("Optional category id filter."),
|
|
21
|
+
listingTypeId: z.string().trim().min(1).optional().describe("Optional listing type filter."),
|
|
22
|
+
orders: z.string().trim().min(1).optional().describe("Optional MercadoLibre sort expression for items search."),
|
|
23
|
+
includeDetails: z.boolean().optional().describe("Whether to multiget compact item details for returned item ids."),
|
|
24
|
+
limit: z.number().int().min(1).max(50).optional().describe("Results per page (1-50)."),
|
|
25
|
+
offset: z.number().int().min(0).max(5e3).optional().describe("Pagination offset.")
|
|
26
|
+
});
|
|
27
|
+
async function meliSearchItemsHandler(params) {
|
|
28
|
+
try {
|
|
29
|
+
const profileResolution = await resolveMercadoLibreProfileOrSelection(params.profileId);
|
|
30
|
+
if (!profileResolution.ok) {
|
|
31
|
+
return profileResolution.response;
|
|
32
|
+
}
|
|
33
|
+
const profileId = profileResolution.value.profileId;
|
|
34
|
+
const access = await getMercadoLibreAccessForProfile(profileId);
|
|
35
|
+
const searchResponse = await searchMercadoLibreItems(profileId, {
|
|
36
|
+
sellerId: access.sellerId,
|
|
37
|
+
status: params.status,
|
|
38
|
+
category: params.category,
|
|
39
|
+
listingTypeId: params.listingTypeId,
|
|
40
|
+
orders: params.orders,
|
|
41
|
+
limit: params.limit ?? 20,
|
|
42
|
+
offset: params.offset ?? 0
|
|
43
|
+
});
|
|
44
|
+
const itemIds = asArray(searchResponse.results).map((value) => normalizeString(value)).filter(Boolean);
|
|
45
|
+
const compactItems = params.includeDetails ? await getMercadoLibreItemDetailsBatch(profileId, itemIds.slice(0, 20), [
|
|
46
|
+
"id",
|
|
47
|
+
"title",
|
|
48
|
+
"status",
|
|
49
|
+
"price",
|
|
50
|
+
"currency_id",
|
|
51
|
+
"available_quantity",
|
|
52
|
+
"sold_quantity",
|
|
53
|
+
"listing_type_id",
|
|
54
|
+
"permalink",
|
|
55
|
+
"thumbnail"
|
|
56
|
+
]) : [];
|
|
57
|
+
const paging = normalizeMercadoLibrePaging(searchResponse.paging);
|
|
58
|
+
return object(
|
|
59
|
+
stripNulls({
|
|
60
|
+
profile_id: profileId,
|
|
61
|
+
metadata: buildMercadoLibrePaginationMetadata({
|
|
62
|
+
total: paging.total,
|
|
63
|
+
limit: paging.limit || params.limit || itemIds.length,
|
|
64
|
+
offset: paging.offset || params.offset || 0,
|
|
65
|
+
returned: itemIds.length,
|
|
66
|
+
nextField: "offset"
|
|
67
|
+
}),
|
|
68
|
+
item_ids: itemIds,
|
|
69
|
+
items: compactItems.map((item) => ({
|
|
70
|
+
item_id: normalizeString(item.id),
|
|
71
|
+
title: normalizeString(item.title),
|
|
72
|
+
status: normalizeString(item.status),
|
|
73
|
+
price: toNumber(item.price),
|
|
74
|
+
currency_id: normalizeString(item.currency_id, "UNKNOWN"),
|
|
75
|
+
available_quantity: toNumber(item.available_quantity),
|
|
76
|
+
sold_quantity: toNumber(item.sold_quantity),
|
|
77
|
+
listing_type_id: normalizeString(item.listing_type_id),
|
|
78
|
+
permalink: normalizeString(item.permalink),
|
|
79
|
+
thumbnail: normalizeString(item.thumbnail)
|
|
80
|
+
}))
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
} catch (err) {
|
|
84
|
+
return error(formatMercadoLibreError(err, "Failed to search MercadoLibre items"));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
meliSearchItemsHandler,
|
|
89
|
+
meliSearchItemsSchema
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=search-items.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/tools/mercadolibre/search-items.ts"],
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { getMercadoLibreAccessForProfile } from \"../../config/mercadolibre.js\";\nimport {\n buildMercadoLibrePaginationMetadata,\n formatMercadoLibreError,\n normalizeMercadoLibrePaging,\n} from \"../../services/mercadolibre/mercadolibre-api.js\";\nimport {\n getMercadoLibreItemDetailsBatch,\n searchMercadoLibreItems,\n} from \"../../services/mercadolibre/mercadolibre-items.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\nimport { asArray, normalizeString, toNumber } from \"./helpers.js\";\nimport { resolveMercadoLibreProfileOrSelection } from \"./profile-resolution.js\";\nimport { mercadolibreProfileIdSchemaField } from \"./write-helpers.js\";\n\nexport const meliSearchItemsSchema = z.object({\n profileId: mercadolibreProfileIdSchemaField,\n status: z.string().trim().min(1).optional().describe(\"Optional item status filter.\"),\n category: z.string().trim().min(1).optional().describe(\"Optional category id filter.\"),\n listingTypeId: z.string().trim().min(1).optional().describe(\"Optional listing type filter.\"),\n orders: z.string().trim().min(1).optional().describe(\"Optional MercadoLibre sort expression for items search.\"),\n includeDetails: z.boolean().optional().describe(\"Whether to multiget compact item details for returned item ids.\"),\n limit: z.number().int().min(1).max(50).optional().describe(\"Results per page (1-50).\"),\n offset: z.number().int().min(0).max(5000).optional().describe(\"Pagination offset.\"),\n});\n\nexport async function meliSearchItemsHandler(params: z.infer<typeof meliSearchItemsSchema>) {\n try {\n const profileResolution = await resolveMercadoLibreProfileOrSelection(params.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const profileId = profileResolution.value.profileId;\n const access = await getMercadoLibreAccessForProfile(profileId);\n const searchResponse = await searchMercadoLibreItems(profileId, {\n sellerId: access.sellerId,\n status: params.status,\n category: params.category,\n listingTypeId: params.listingTypeId,\n orders: params.orders,\n limit: params.limit ?? 20,\n offset: params.offset ?? 0,\n });\n\n const itemIds = asArray<string>(searchResponse.results).map((value) => normalizeString(value)).filter(Boolean);\n const compactItems = params.includeDetails\n ? await getMercadoLibreItemDetailsBatch(profileId, itemIds.slice(0, 20), [\n \"id\",\n \"title\",\n \"status\",\n \"price\",\n \"currency_id\",\n \"available_quantity\",\n \"sold_quantity\",\n \"listing_type_id\",\n \"permalink\",\n \"thumbnail\",\n ])\n : [];\n\n const paging = normalizeMercadoLibrePaging(searchResponse.paging as Record<string, unknown>);\n\n return object(\n stripNulls({\n profile_id: profileId,\n metadata: buildMercadoLibrePaginationMetadata({\n total: paging.total,\n limit: paging.limit || params.limit || itemIds.length,\n offset: paging.offset || params.offset || 0,\n returned: itemIds.length,\n nextField: \"offset\",\n }),\n item_ids: itemIds,\n items: compactItems.map((item) => ({\n item_id: normalizeString(item.id),\n title: normalizeString(item.title),\n status: normalizeString(item.status),\n price: toNumber(item.price),\n currency_id: normalizeString(item.currency_id, \"UNKNOWN\"),\n available_quantity: toNumber(item.available_quantity),\n sold_quantity: toNumber(item.sold_quantity),\n listing_type_id: normalizeString(item.listing_type_id),\n permalink: normalizeString(item.permalink),\n thumbnail: normalizeString(item.thumbnail),\n })),\n })\n );\n } catch (err) {\n return error(formatMercadoLibreError(err, \"Failed to search MercadoLibre items\"));\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,uCAAuC;AAChD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA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wB,KAAK,qCAAqC,CAAC;AAAA,EAClF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { error, object } from "mcp-use/server";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { getMercadoLibreAccessForProfile } from "../../config/mercadolibre.js";
|
|
4
|
+
import {
|
|
5
|
+
buildMercadoLibrePaginationMetadata,
|
|
6
|
+
formatMercadoLibreError,
|
|
7
|
+
normalizeMercadoLibrePaging
|
|
8
|
+
} from "../../services/mercadolibre/mercadolibre-api.js";
|
|
9
|
+
import { searchMercadoLibreQuestions } from "../../services/mercadolibre/mercadolibre-questions.js";
|
|
10
|
+
import { stripNulls } from "../../utils/strip-payload.js";
|
|
11
|
+
import { asArray, asRecord, compactDateTime, normalizeString } from "./helpers.js";
|
|
12
|
+
import { resolveMercadoLibreProfileOrSelection } from "./profile-resolution.js";
|
|
13
|
+
import { mercadolibreProfileIdSchemaField } from "./write-helpers.js";
|
|
14
|
+
const meliSearchQuestionsSchema = z.object({
|
|
15
|
+
profileId: mercadolibreProfileIdSchemaField,
|
|
16
|
+
itemId: z.string().trim().min(1).optional().describe("Optional MercadoLibre item id filter."),
|
|
17
|
+
status: z.string().trim().min(1).optional().describe("Optional question status filter."),
|
|
18
|
+
limit: z.number().int().min(1).max(50).optional().describe("Results per page (1-50)."),
|
|
19
|
+
offset: z.number().int().min(0).max(5e3).optional().describe("Pagination offset.")
|
|
20
|
+
});
|
|
21
|
+
async function meliSearchQuestionsHandler(params) {
|
|
22
|
+
try {
|
|
23
|
+
const profileResolution = await resolveMercadoLibreProfileOrSelection(params.profileId);
|
|
24
|
+
if (!profileResolution.ok) {
|
|
25
|
+
return profileResolution.response;
|
|
26
|
+
}
|
|
27
|
+
const profileId = profileResolution.value.profileId;
|
|
28
|
+
const access = await getMercadoLibreAccessForProfile(profileId);
|
|
29
|
+
const response = await searchMercadoLibreQuestions(profileId, {
|
|
30
|
+
sellerId: access.sellerId,
|
|
31
|
+
itemId: params.itemId,
|
|
32
|
+
status: params.status,
|
|
33
|
+
limit: params.limit ?? 20,
|
|
34
|
+
offset: params.offset ?? 0
|
|
35
|
+
});
|
|
36
|
+
const questions = asArray(response.questions ?? response.results);
|
|
37
|
+
const paging = normalizeMercadoLibrePaging(asRecord(response.paging));
|
|
38
|
+
return object(
|
|
39
|
+
stripNulls({
|
|
40
|
+
profile_id: profileId,
|
|
41
|
+
metadata: buildMercadoLibrePaginationMetadata({
|
|
42
|
+
total: paging.total || questions.length,
|
|
43
|
+
limit: paging.limit || params.limit || questions.length,
|
|
44
|
+
offset: paging.offset || params.offset || 0,
|
|
45
|
+
returned: questions.length,
|
|
46
|
+
nextField: "offset"
|
|
47
|
+
}),
|
|
48
|
+
questions: questions.map((question) => ({
|
|
49
|
+
question_id: question.id,
|
|
50
|
+
item_id: normalizeString(question.item_id),
|
|
51
|
+
item_title: normalizeString(asRecord(question.item).title),
|
|
52
|
+
status: normalizeString(question.status),
|
|
53
|
+
text: normalizeString(question.text),
|
|
54
|
+
date_created: compactDateTime(question.date_created),
|
|
55
|
+
from: stripNulls({
|
|
56
|
+
id: normalizeString(asRecord(question.from).id),
|
|
57
|
+
nickname: normalizeString(asRecord(question.from).nickname)
|
|
58
|
+
}),
|
|
59
|
+
answer_status: normalizeString(asRecord(question.answer).status)
|
|
60
|
+
}))
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
return error(formatMercadoLibreError(err, "Failed to search MercadoLibre questions"));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
meliSearchQuestionsHandler,
|
|
69
|
+
meliSearchQuestionsSchema
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=search-questions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/tools/mercadolibre/search-questions.ts"],
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { getMercadoLibreAccessForProfile } from \"../../config/mercadolibre.js\";\nimport {\n buildMercadoLibrePaginationMetadata,\n formatMercadoLibreError,\n normalizeMercadoLibrePaging,\n} from \"../../services/mercadolibre/mercadolibre-api.js\";\nimport { searchMercadoLibreQuestions } from \"../../services/mercadolibre/mercadolibre-questions.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\nimport { asArray, asRecord, compactDateTime, normalizeString } from \"./helpers.js\";\nimport { resolveMercadoLibreProfileOrSelection } from \"./profile-resolution.js\";\nimport { mercadolibreProfileIdSchemaField } from \"./write-helpers.js\";\n\nexport const meliSearchQuestionsSchema = z.object({\n profileId: mercadolibreProfileIdSchemaField,\n itemId: z.string().trim().min(1).optional().describe(\"Optional MercadoLibre item id filter.\"),\n status: z.string().trim().min(1).optional().describe(\"Optional question status filter.\"),\n limit: z.number().int().min(1).max(50).optional().describe(\"Results per page (1-50).\"),\n offset: z.number().int().min(0).max(5000).optional().describe(\"Pagination offset.\"),\n});\n\nexport async function meliSearchQuestionsHandler(\n params: z.infer<typeof meliSearchQuestionsSchema>\n) {\n try {\n const profileResolution = await resolveMercadoLibreProfileOrSelection(params.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const profileId = profileResolution.value.profileId;\n const access = await getMercadoLibreAccessForProfile(profileId);\n const response = await searchMercadoLibreQuestions(profileId, {\n sellerId: access.sellerId,\n itemId: params.itemId,\n status: params.status,\n limit: params.limit ?? 20,\n offset: params.offset ?? 0,\n });\n\n const questions = asArray<Record<string, unknown>>(response.questions ?? response.results);\n const paging = normalizeMercadoLibrePaging(asRecord(response.paging));\n\n return object(\n stripNulls({\n profile_id: profileId,\n metadata: buildMercadoLibrePaginationMetadata({\n total: paging.total || questions.length,\n limit: paging.limit || params.limit || questions.length,\n offset: paging.offset || params.offset || 0,\n returned: questions.length,\n nextField: \"offset\",\n }),\n questions: questions.map((question) => ({\n question_id: question.id,\n item_id: normalizeString(question.item_id),\n item_title: normalizeString(asRecord(question.item).title),\n status: normalizeString(question.status),\n text: normalizeString(question.text),\n date_created: compactDateTime(question.date_created),\n from: stripNulls({\n id: normalizeString(asRecord(question.from).id),\n nickname: normalizeString(asRecord(question.from).nickname),\n }),\n answer_status: normalizeString(asRecord(question.answer).status),\n })),\n })\n );\n } catch (err) {\n return error(formatMercadoLibreError(err, \"Failed to search MercadoLibre questions\"));\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,uCAAuC;AAChD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mCAAmC;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,SAAS,UAAU,iBAAiB,uBAAuB;AACpE,SAAS,6CAA6C;AACtD,SAAS,wCAAwC;AAE1C,MAAM,4BAA4B,EAAE,OAAO;AAAA,EAChD,WAAW;AAAA,EACX,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,uCAAuC;AAAA,EAC5F,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,kCAAkC;AAAA,EACvF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,SAAS,0BAA0B;AAAA,EACrF,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,GAAI,EAAE,SAAS,EAAE,SAAS,oBAAoB;AACpF,CAAC;AAED,eAAsB,2BACpB,QACA;AACA,MAAI;AACF,UAAM,oBAAoB,MAAM,sCAAsC,OAAO,SAAS;AACtF,QAAI,CAAC,kBAAkB,IAAI;AACzB,aAAO,kBAAkB;AAAA,IAC3B;AAEA,UAAM,YAAY,kBAAkB,MAAM;AAC1C,UAAM,SAAS,M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|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
getMercadoLibreItem,
|
|
4
|
+
updateMercadoLibreItem
|
|
5
|
+
} from "../../services/mercadolibre/mercadolibre-items.js";
|
|
6
|
+
import {
|
|
7
|
+
buildMercadoLibreWriteSuccessResponse,
|
|
8
|
+
handleMercadoLibreWriteError,
|
|
9
|
+
mercadolibreProfileIdSchemaField,
|
|
10
|
+
resolveMercadoLibreWriteProfile
|
|
11
|
+
} from "./write-helpers.js";
|
|
12
|
+
const attributeSchema = z.object({
|
|
13
|
+
id: z.string().trim().min(1).describe("MercadoLibre attribute id."),
|
|
14
|
+
value_name: z.string().trim().min(1).optional().describe("Human-readable attribute value."),
|
|
15
|
+
value_id: z.string().trim().min(1).optional().describe("MercadoLibre attribute value id when known.")
|
|
16
|
+
});
|
|
17
|
+
const meliUpdateItemBasicFieldsSchema = z.object({
|
|
18
|
+
profileId: mercadolibreProfileIdSchemaField,
|
|
19
|
+
itemId: z.string().trim().min(1).describe("MercadoLibre item id."),
|
|
20
|
+
title: z.string().trim().min(3).optional().describe("New listing title."),
|
|
21
|
+
price: z.number().positive().optional().describe("New listing price."),
|
|
22
|
+
availableQuantity: z.number().int().min(0).optional().describe("New available quantity."),
|
|
23
|
+
attributes: z.array(attributeSchema).optional().describe("Updated attributes array."),
|
|
24
|
+
saleTerms: z.array(z.record(z.string(), z.unknown())).optional().describe("Updated sale terms array."),
|
|
25
|
+
shipping: z.record(z.string(), z.unknown()).optional().describe("Updated shipping payload."),
|
|
26
|
+
status: z.enum(["active", "paused", "closed", "under_review"]).optional().describe("New listing status."),
|
|
27
|
+
listingTypeId: z.string().trim().min(1).optional().describe("Optional new listing type id if supported by MercadoLibre for the item."),
|
|
28
|
+
channels: z.array(z.string().trim().min(1)).optional().describe("Optional replacement channels array if supported.")
|
|
29
|
+
}).refine(
|
|
30
|
+
(value) => value.title !== void 0 || value.price !== void 0 || value.availableQuantity !== void 0 || value.attributes !== void 0 || value.saleTerms !== void 0 || value.shipping !== void 0 || value.status !== void 0 || value.listingTypeId !== void 0 || value.channels !== void 0,
|
|
31
|
+
{
|
|
32
|
+
message: "At least one item field must be provided.",
|
|
33
|
+
path: ["title"]
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
async function meliUpdateItemBasicFieldsHandler(params) {
|
|
37
|
+
try {
|
|
38
|
+
const profileResolution = await resolveMercadoLibreWriteProfile(params.profileId);
|
|
39
|
+
if (!profileResolution.ok) {
|
|
40
|
+
return profileResolution.response;
|
|
41
|
+
}
|
|
42
|
+
const profileId = profileResolution.value.profileId;
|
|
43
|
+
const before = await getMercadoLibreItem(profileId, params.itemId);
|
|
44
|
+
const after = await updateMercadoLibreItem(profileId, params.itemId, {
|
|
45
|
+
title: params.title,
|
|
46
|
+
price: params.price,
|
|
47
|
+
available_quantity: params.availableQuantity,
|
|
48
|
+
attributes: params.attributes,
|
|
49
|
+
sale_terms: params.saleTerms,
|
|
50
|
+
shipping: params.shipping,
|
|
51
|
+
status: params.status,
|
|
52
|
+
listing_type_id: params.listingTypeId,
|
|
53
|
+
channels: params.channels
|
|
54
|
+
});
|
|
55
|
+
return buildMercadoLibreWriteSuccessResponse({
|
|
56
|
+
profileId,
|
|
57
|
+
operation: "update_item_basic_fields",
|
|
58
|
+
resourceId: params.itemId,
|
|
59
|
+
message: "MercadoLibre item updated successfully.",
|
|
60
|
+
before,
|
|
61
|
+
after
|
|
62
|
+
});
|
|
63
|
+
} catch (err) {
|
|
64
|
+
return handleMercadoLibreWriteError(err, `Failed to update MercadoLibre item ${params.itemId}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
meliUpdateItemBasicFieldsHandler,
|
|
69
|
+
meliUpdateItemBasicFieldsSchema
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=update-item-basic-fields.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/tools/mercadolibre/update-item-basic-fields.ts"],
|
|
4
|
+
"sourcesContent": ["import { z } from \"zod\";\n\nimport {\n getMercadoLibreItem,\n updateMercadoLibreItem,\n} from \"../../services/mercadolibre/mercadolibre-items.js\";\nimport {\n buildMercadoLibreWriteSuccessResponse,\n handleMercadoLibreWriteError,\n mercadolibreProfileIdSchemaField,\n resolveMercadoLibreWriteProfile,\n} from \"./write-helpers.js\";\n\nconst attributeSchema = z.object({\n id: z.string().trim().min(1).describe(\"MercadoLibre attribute id.\"),\n value_name: z.string().trim().min(1).optional().describe(\"Human-readable attribute value.\"),\n value_id: z.string().trim().min(1).optional().describe(\"MercadoLibre attribute value id when known.\"),\n});\n\nexport const meliUpdateItemBasicFieldsSchema = z\n .object({\n profileId: mercadolibreProfileIdSchemaField,\n itemId: z.string().trim().min(1).describe(\"MercadoLibre item id.\"),\n title: z.string().trim().min(3).optional().describe(\"New listing title.\"),\n price: z.number().positive().optional().describe(\"New listing price.\"),\n availableQuantity: z.number().int().min(0).optional().describe(\"New available quantity.\"),\n attributes: z.array(attributeSchema).optional().describe(\"Updated attributes array.\"),\n saleTerms: z.array(z.record(z.string(), z.unknown())).optional().describe(\"Updated sale terms array.\"),\n shipping: z.record(z.string(), z.unknown()).optional().describe(\"Updated shipping payload.\"),\n status: z.enum([\"active\", \"paused\", \"closed\", \"under_review\"]).optional().describe(\"New listing status.\"),\n listingTypeId: z.string().trim().min(1).optional().describe(\"Optional new listing type id if supported by MercadoLibre for the item.\"),\n channels: z.array(z.string().trim().min(1)).optional().describe(\"Optional replacement channels array if supported.\"),\n })\n .refine(\n (value) =>\n value.title !== undefined ||\n value.price !== undefined ||\n value.availableQuantity !== undefined ||\n value.attributes !== undefined ||\n value.saleTerms !== undefined ||\n value.shipping !== undefined ||\n value.status !== undefined ||\n value.listingTypeId !== undefined ||\n value.channels !== undefined,\n {\n message: \"At least one item field must be provided.\",\n path: [\"title\"],\n }\n );\n\nexport async function meliUpdateItemBasicFieldsHandler(\n params: z.infer<typeof meliUpdateItemBasicFieldsSchema>\n) {\n try {\n const profileResolution = await resolveMercadoLibreWriteProfile(params.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const profileId = profileResolution.value.profileId;\n const before = await getMercadoLibreItem(profileId, params.itemId);\n const after = await updateMercadoLibreItem(profileId, params.itemId, {\n title: params.title,\n price: params.price,\n available_quantity: params.availableQuantity,\n attributes: params.attributes,\n sale_terms: params.saleTerms,\n shipping: params.shipping,\n status: params.status,\n listing_type_id: params.listingTypeId,\n channels: params.channels,\n });\n\n return buildMercadoLibreWriteSuccessResponse({\n profileId,\n operation: \"update_item_basic_fields\",\n resourceId: params.itemId,\n message: \"MercadoLibre item updated successfully.\",\n before,\n after,\n });\n } catch (err) {\n return handleMercadoLibreWriteError(err, `Failed to update MercadoLibre item ${params.itemId}`);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,kBAAkB,EAAE,OAAO;AAAA,EAC/B,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,4BAA4B;AAAA,EAClE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,iCAAiC;AAAA,EAC1F,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,6CAA6C;AACtG,CAAC;AAEM,MAAM,kCAAkC,EAC5C,OAAO;AAAA,EACN,WAAW;AAAA,EACX,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,uBAAuB;AAAA,EACjE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,oBA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M,SAAS,MAAM,oBAAoB,WAAW,OAAO,MAAM;AACjE,UAAM,QAAQ,MAAM,uBAAuB,WAAW,OAAO,QAAQ;AAAA,MACnE,OAAO,OAAO;AAAA,MACd,OAAO,OAAO;AAAA,MACd,oBAAoB,OAAO;AAAA,MAC3B,YAAY,OAAO;AAAA,MACnB,YAAY,OAAO;AAAA,MACnB,UAAU,OAAO;AAAA,MACjB,QAAQ,OAAO;AAAA,MACf,iBAAiB,OAAO;AAAA,MACxB,UAAU,OAAO;AAAA,IACnB,CAAC;AAED,WAAO,sCAAsC;AAAA,MAC3C;AAAA,MACA,WAAW;AAAA,MACX,YAAY,OAAO;AAAA,MACnB,SAAS;AAAA,MACT;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,WAAO,6BAA6B,KAAK,sCAAsC,OAAO,MAAM,EAAE;AAAA,EAChG;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
createMercadoLibreItemDescription,
|
|
4
|
+
getMercadoLibreItemDescription,
|
|
5
|
+
replaceMercadoLibreItemDescription
|
|
6
|
+
} from "../../services/mercadolibre/mercadolibre-items.js";
|
|
7
|
+
import {
|
|
8
|
+
buildMercadoLibreWriteSuccessResponse,
|
|
9
|
+
handleMercadoLibreWriteError,
|
|
10
|
+
mercadolibreProfileIdSchemaField,
|
|
11
|
+
resolveMercadoLibreWriteProfile
|
|
12
|
+
} from "./write-helpers.js";
|
|
13
|
+
const meliUpdateItemDescriptionSchema = z.object({
|
|
14
|
+
profileId: mercadolibreProfileIdSchemaField,
|
|
15
|
+
itemId: z.string().trim().min(1).describe("MercadoLibre item id."),
|
|
16
|
+
plainText: z.string().trim().min(1).describe("Plain-text description to publish.")
|
|
17
|
+
});
|
|
18
|
+
async function meliUpdateItemDescriptionHandler(params) {
|
|
19
|
+
try {
|
|
20
|
+
const profileResolution = await resolveMercadoLibreWriteProfile(params.profileId);
|
|
21
|
+
if (!profileResolution.ok) {
|
|
22
|
+
return profileResolution.response;
|
|
23
|
+
}
|
|
24
|
+
const profileId = profileResolution.value.profileId;
|
|
25
|
+
let before = null;
|
|
26
|
+
let after;
|
|
27
|
+
try {
|
|
28
|
+
before = await getMercadoLibreItemDescription(profileId, params.itemId);
|
|
29
|
+
after = await replaceMercadoLibreItemDescription(profileId, params.itemId, params.plainText);
|
|
30
|
+
} catch {
|
|
31
|
+
after = await createMercadoLibreItemDescription(profileId, params.itemId, params.plainText);
|
|
32
|
+
}
|
|
33
|
+
return buildMercadoLibreWriteSuccessResponse({
|
|
34
|
+
profileId,
|
|
35
|
+
operation: "update_item_description",
|
|
36
|
+
resourceId: params.itemId,
|
|
37
|
+
message: "MercadoLibre item description updated successfully.",
|
|
38
|
+
before,
|
|
39
|
+
after
|
|
40
|
+
});
|
|
41
|
+
} catch (err) {
|
|
42
|
+
return handleMercadoLibreWriteError(err, `Failed to update description for ${params.itemId}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
meliUpdateItemDescriptionHandler,
|
|
47
|
+
meliUpdateItemDescriptionSchema
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=update-item-description.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/tools/mercadolibre/update-item-description.ts"],
|
|
4
|
+
"sourcesContent": ["import { z } from \"zod\";\n\nimport {\n createMercadoLibreItemDescription,\n getMercadoLibreItemDescription,\n replaceMercadoLibreItemDescription,\n} from \"../../services/mercadolibre/mercadolibre-items.js\";\nimport {\n buildMercadoLibreWriteSuccessResponse,\n handleMercadoLibreWriteError,\n mercadolibreProfileIdSchemaField,\n resolveMercadoLibreWriteProfile,\n} from \"./write-helpers.js\";\n\nexport const meliUpdateItemDescriptionSchema = z.object({\n profileId: mercadolibreProfileIdSchemaField,\n itemId: z.string().trim().min(1).describe(\"MercadoLibre item id.\"),\n plainText: z.string().trim().min(1).describe(\"Plain-text description to publish.\"),\n});\n\nexport async function meliUpdateItemDescriptionHandler(\n params: z.infer<typeof meliUpdateItemDescriptionSchema>\n) {\n try {\n const profileResolution = await resolveMercadoLibreWriteProfile(params.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const profileId = profileResolution.value.profileId;\n let before: Record<string, unknown> | null = null;\n let after: Record<string, unknown>;\n\n try {\n before = await getMercadoLibreItemDescription(profileId, params.itemId);\n after = await replaceMercadoLibreItemDescription(profileId, params.itemId, params.plainText);\n } catch {\n after = await createMercadoLibreItemDescription(profileId, params.itemId, params.plainText);\n }\n\n return buildMercadoLibreWriteSuccessResponse({\n profileId,\n operation: \"update_item_description\",\n resourceId: params.itemId,\n message: \"MercadoLibre item description updated successfully.\",\n before,\n after,\n });\n } catch (err) {\n return handleMercadoLibreWriteError(err, `Failed to update description for ${params.itemId}`);\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,kCAAkC,EAAE,OAAO;AAAA,EACtD,WAAW;AAAA,EACX,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,uBAAuB;AAAA,EACjE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,oCAAoC;AACnF,CAAC;AAED,eAAsB,iCACpB,QACA;AACA,MAAI;AACF,UAAM,oBAAoB,MAAM,gCAAgC,OAAO,SAAS;AAChF,QAAI,CAAC,kBAAkB,IAAI;AACzB,aAAO,kBAAkB;AAAA,IAC3B;AAEA,UAAM,YAAY,kBAAkB,MAAM;AAC1C,QAAI,SAAyC;AAC7C,QAAI;AAEJ,QAAI;AACF,eAAS,MAAM,+BAA+B,WAAW,OAAO,MAAM;AACtE,cAAQ,MAAM,mCAAmC,WAAW,OAAO,QAAQ,OAAO,SAAS;AAAA,IAC7F,QAAQ;AACN,cAAQ,MAAM,kCAAkC,WAAW,OAAO,QAAQ,OAAO,SAAS;AAAA,IAC5F;AAEA,WAAO,sCAAsC;AAAA,MAC3C;AAAA,MACA,WAAW;AAAA,MACX,YAAY,OAAO;AAAA,MACnB,SAAS;AAAA,MACT;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,WAAO,6BAA6B,KAAK,oCAAoC,OAAO,MAAM,EAAE;AAAA,EAC9F;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
addMercadoLibreItemPicture,
|
|
4
|
+
getMercadoLibreItem,
|
|
5
|
+
updateMercadoLibreItem
|
|
6
|
+
} from "../../services/mercadolibre/mercadolibre-items.js";
|
|
7
|
+
import {
|
|
8
|
+
buildMercadoLibreWriteSuccessResponse,
|
|
9
|
+
handleMercadoLibreWriteError,
|
|
10
|
+
mercadolibreProfileIdSchemaField,
|
|
11
|
+
resolveMercadoLibreWriteProfile
|
|
12
|
+
} from "./write-helpers.js";
|
|
13
|
+
const meliUpdateItemPicturesSchema = z.object({
|
|
14
|
+
profileId: mercadolibreProfileIdSchemaField,
|
|
15
|
+
itemId: z.string().trim().min(1).describe("MercadoLibre item id."),
|
|
16
|
+
mode: z.enum(["add", "replace"]).describe("Whether to add new pictures or replace the full pictures array."),
|
|
17
|
+
pictures: z.array(z.object({ source: z.string().trim().url().describe("Public image URL.") })).min(1).max(12).describe("One or more public image URLs to attach.")
|
|
18
|
+
});
|
|
19
|
+
async function meliUpdateItemPicturesHandler(params) {
|
|
20
|
+
try {
|
|
21
|
+
const profileResolution = await resolveMercadoLibreWriteProfile(params.profileId);
|
|
22
|
+
if (!profileResolution.ok) {
|
|
23
|
+
return profileResolution.response;
|
|
24
|
+
}
|
|
25
|
+
const profileId = profileResolution.value.profileId;
|
|
26
|
+
const before = await getMercadoLibreItem(profileId, params.itemId);
|
|
27
|
+
let after;
|
|
28
|
+
if (params.mode === "replace") {
|
|
29
|
+
after = await updateMercadoLibreItem(profileId, params.itemId, {
|
|
30
|
+
pictures: params.pictures
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
for (const picture of params.pictures) {
|
|
34
|
+
await addMercadoLibreItemPicture(profileId, params.itemId, picture.source);
|
|
35
|
+
}
|
|
36
|
+
after = await getMercadoLibreItem(profileId, params.itemId);
|
|
37
|
+
}
|
|
38
|
+
return buildMercadoLibreWriteSuccessResponse({
|
|
39
|
+
profileId,
|
|
40
|
+
operation: "update_item_pictures",
|
|
41
|
+
resourceId: params.itemId,
|
|
42
|
+
message: `MercadoLibre item pictures ${params.mode === "replace" ? "replaced" : "updated"} successfully.`,
|
|
43
|
+
before,
|
|
44
|
+
after,
|
|
45
|
+
details: {
|
|
46
|
+
mode: params.mode,
|
|
47
|
+
pictures_count: params.pictures.length
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return handleMercadoLibreWriteError(err, `Failed to update pictures for ${params.itemId}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
meliUpdateItemPicturesHandler,
|
|
56
|
+
meliUpdateItemPicturesSchema
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=update-item-pictures.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/tools/mercadolibre/update-item-pictures.ts"],
|
|
4
|
+
"sourcesContent": ["import { z } from \"zod\";\n\nimport {\n addMercadoLibreItemPicture,\n getMercadoLibreItem,\n updateMercadoLibreItem,\n} from \"../../services/mercadolibre/mercadolibre-items.js\";\nimport {\n buildMercadoLibreWriteSuccessResponse,\n handleMercadoLibreWriteError,\n mercadolibreProfileIdSchemaField,\n resolveMercadoLibreWriteProfile,\n} from \"./write-helpers.js\";\n\nexport const meliUpdateItemPicturesSchema = z.object({\n profileId: mercadolibreProfileIdSchemaField,\n itemId: z.string().trim().min(1).describe(\"MercadoLibre item id.\"),\n mode: z.enum([\"add\", \"replace\"]).describe(\"Whether to add new pictures or replace the full pictures array.\"),\n pictures: z\n .array(z.object({ source: z.string().trim().url().describe(\"Public image URL.\") }))\n .min(1)\n .max(12)\n .describe(\"One or more public image URLs to attach.\"),\n});\n\nexport async function meliUpdateItemPicturesHandler(\n params: z.infer<typeof meliUpdateItemPicturesSchema>\n) {\n try {\n const profileResolution = await resolveMercadoLibreWriteProfile(params.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const profileId = profileResolution.value.profileId;\n const before = await getMercadoLibreItem(profileId, params.itemId);\n\n let after: Record<string, unknown>;\n if (params.mode === \"replace\") {\n after = await updateMercadoLibreItem(profileId, params.itemId, {\n pictures: params.pictures,\n });\n } else {\n for (const picture of params.pictures) {\n await addMercadoLibreItemPicture(profileId, params.itemId, picture.source);\n }\n after = await getMercadoLibreItem(profileId, params.itemId);\n }\n\n return buildMercadoLibreWriteSuccessResponse({\n profileId,\n operation: \"update_item_pictures\",\n resourceId: params.itemId,\n message: `MercadoLibre item pictures ${params.mode === \"replace\" ? \"replaced\" : \"updated\"} successfully.`,\n before,\n after,\n details: {\n mode: params.mode,\n pictures_count: params.pictures.length,\n },\n });\n } catch (err) {\n return handleMercadoLibreWriteError(err, `Failed to update pictures for ${params.itemId}`);\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,+BAA+B,EAAE,OAAO;AAAA,EACnD,WAAW;AAAA,EACX,QAAQ,EAAE,OAAO,EAAE,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
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { error, object } from "mcp-use/server";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { getMercadoLibreConnectionRow } from "../../config/mercadolibre-profile-store.js";
|
|
4
|
+
import { getMercadoLibreAccessForProfile } from "../../config/mercadolibre.js";
|
|
5
|
+
import { getMercadoLibreUsersMe, formatMercadoLibreError } from "../../services/mercadolibre/mercadolibre-api.js";
|
|
6
|
+
import { stripNulls } from "../../utils/strip-payload.js";
|
|
7
|
+
import { resolveMercadoLibreProfileOrSelection } from "./profile-resolution.js";
|
|
8
|
+
import { mercadolibreProfileIdSchemaField } from "./write-helpers.js";
|
|
9
|
+
const meliValidateConnectionSchema = z.object({
|
|
10
|
+
profileId: mercadolibreProfileIdSchemaField
|
|
11
|
+
});
|
|
12
|
+
async function meliValidateConnectionHandler(params) {
|
|
13
|
+
try {
|
|
14
|
+
const profileResolution = await resolveMercadoLibreProfileOrSelection(params.profileId);
|
|
15
|
+
if (!profileResolution.ok) {
|
|
16
|
+
return profileResolution.response;
|
|
17
|
+
}
|
|
18
|
+
const profileId = profileResolution.value.profileId;
|
|
19
|
+
const before = await getMercadoLibreConnectionRow(profileId);
|
|
20
|
+
const access = await getMercadoLibreAccessForProfile(profileId);
|
|
21
|
+
const account = await getMercadoLibreUsersMe(profileId);
|
|
22
|
+
const after = await getMercadoLibreConnectionRow(profileId);
|
|
23
|
+
const refreshed = before?.expiresAt?.toISOString() !== after?.expiresAt?.toISOString() || before?.encryptedAccessToken !== after?.encryptedAccessToken;
|
|
24
|
+
return object(
|
|
25
|
+
stripNulls({
|
|
26
|
+
profile_id: profileId,
|
|
27
|
+
validation_status: after?.status ?? "active",
|
|
28
|
+
refreshed,
|
|
29
|
+
seller_id: access.sellerId,
|
|
30
|
+
account_id: account.id,
|
|
31
|
+
nickname: account.nickname,
|
|
32
|
+
expires_at: access.expiresAt,
|
|
33
|
+
scopes: access.scopes
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
return error(formatMercadoLibreError(err, "Failed to validate MercadoLibre connection"));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
meliValidateConnectionHandler,
|
|
42
|
+
meliValidateConnectionSchema
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=validate-connection.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/tools/mercadolibre/validate-connection.ts"],
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { getMercadoLibreConnectionRow } from \"../../config/mercadolibre-profile-store.js\";\nimport { getMercadoLibreAccessForProfile } from \"../../config/mercadolibre.js\";\nimport { getMercadoLibreUsersMe, formatMercadoLibreError } from \"../../services/mercadolibre/mercadolibre-api.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\nimport { resolveMercadoLibreProfileOrSelection } from \"./profile-resolution.js\";\nimport { mercadolibreProfileIdSchemaField } from \"./write-helpers.js\";\n\nexport const meliValidateConnectionSchema = z.object({\n profileId: mercadolibreProfileIdSchemaField,\n});\n\nexport async function meliValidateConnectionHandler(\n params: z.infer<typeof meliValidateConnectionSchema>\n) {\n try {\n const profileResolution = await resolveMercadoLibreProfileOrSelection(params.profileId);\n if (!profileResolution.ok) {\n return profileResolution.response;\n }\n\n const profileId = profileResolution.value.profileId;\n const before = await getMercadoLibreConnectionRow(profileId);\n const access = await getMercadoLibreAccessForProfile(profileId);\n const account = await getMercadoLibreUsersMe(profileId);\n const after = await getMercadoLibreConnectionRow(profileId);\n\n const refreshed =\n before?.expiresAt?.toISOString() !== after?.expiresAt?.toISOString() ||\n before?.encryptedAccessToken !== after?.encryptedAccessToken;\n\n return object(\n stripNulls({\n profile_id: profileId,\n validation_status: after?.status ?? \"active\",\n refreshed,\n seller_id: access.sellerId,\n account_id: account.id,\n nickname: account.nickname,\n expires_at: access.expiresAt,\n scopes: access.scopes,\n })\n );\n } catch (err) {\n return error(formatMercadoLibreError(err, \"Failed to validate MercadoLibre connection\"));\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,oCAAoC;AAC7C,SAAS,uCAAuC;AAChD,SAAS,wBAAwB,+BAA+B;AAChE,SAAS,kBAAkB;AAC3B,SAAS,6CAA6C;AACtD,SAAS,wCAAwC;AAE1C,MAAM,+BAA+B,EAAE,OAAO;AAAA,EACnD,WAAW;AACb,CAAC;AAED,eAAsB,8BACpB,QACA;AACA,MAAI;AACF,UAAM,oBAAoB,MAAM,sCAAsC,OAAO,SAAS;AACtF,QAAI,CAAC,kBAAkB,IAAI;AACzB,aAAO,kBAAkB;AAAA,IAC3B;AAEA,UAAM,YAAY,kBAAkB,MAAM;AAC1C,UAAM,SAAS,MAAM,6BAA6B,SAAS;AAC3D,UAAM,SAAS,MAAM,gCAAgC,SAAS;AAC9D,UAAM,UAAU,MAAM,uBAAuB,SAAS;AACtD,UAAM,QAAQ,MAAM,6BAA6B,SAAS;AAE1D,UAAM,YACJ,QAAQ,WAAW,YAAY,MAAM,OAAO,WAAW,YAAY,KACnE,QAAQ,yBAAyB,OAAO;AAE1C,WAAO;AAAA,MACL,WAAW;AAAA,QACT,YAAY;AAAA,QACZ,mBAAmB,OAAO,UAAU;AAAA,QACpC;AAAA,QACA,WAAW,OAAO;AAAA,QAClB,YAAY,QAAQ;AAAA,QACpB,UAAU,QAAQ;AAAA,QAClB,YAAY,OAAO;AAAA,QACnB,QAAQ,OAAO;AAAA,MACjB,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,wBAAwB,KAAK,4CAA4C,CAAC;AAAA,EACzF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|