@5ss/ai-tools 2.11.1
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/CHANGELOG.md +112 -0
- package/LICENSE +21 -0
- package/README.md +221 -0
- package/dist/ai-sdk/index.d.ts +15 -0
- package/dist/ai-sdk/index.d.ts.map +1 -0
- package/dist/ai-sdk/index.js +24 -0
- package/dist/ai-sdk/index.js.map +1 -0
- package/dist/artifact-D064mHfK.js +44 -0
- package/dist/artifact-D064mHfK.js.map +1 -0
- package/dist/artifacts-O8g-40Pw.js +404 -0
- package/dist/artifacts-O8g-40Pw.js.map +1 -0
- package/dist/aws-json-CecFqzqX.js +23 -0
- package/dist/aws-json-CecFqzqX.js.map +1 -0
- package/dist/aws-service-msttbPrz.js +58 -0
- package/dist/aws-service-msttbPrz.js.map +1 -0
- package/dist/batch-BMM5dXqL.d.ts +22 -0
- package/dist/batch-BMM5dXqL.d.ts.map +1 -0
- package/dist/batch-Co1ujeAW.js +67 -0
- package/dist/batch-Co1ujeAW.js.map +1 -0
- package/dist/bedrock-agentcore-browser-a_qOs-NR.js +182 -0
- package/dist/bedrock-agentcore-browser-a_qOs-NR.js.map +1 -0
- package/dist/bedrock-agentcore-code-interpreter-MWK-8RhA.js +357 -0
- package/dist/bedrock-agentcore-code-interpreter-MWK-8RhA.js.map +1 -0
- package/dist/bytes-BxpimpQx.js +45 -0
- package/dist/bytes-BxpimpQx.js.map +1 -0
- package/dist/client-CCKGsTeI.js +743 -0
- package/dist/client-CCKGsTeI.js.map +1 -0
- package/dist/cloudflare/index.d.ts +37 -0
- package/dist/cloudflare/index.d.ts.map +1 -0
- package/dist/cloudflare/index.js +41 -0
- package/dist/cloudflare/index.js.map +1 -0
- package/dist/cloudflare-browser-B6Yolpin.js +428 -0
- package/dist/cloudflare-browser-B6Yolpin.js.map +1 -0
- package/dist/cloudflare-email-Dy0KHeDf.js +197 -0
- package/dist/cloudflare-email-Dy0KHeDf.js.map +1 -0
- package/dist/cloudflare-sandbox-Dp_uNaqW.js +982 -0
- package/dist/cloudflare-sandbox-Dp_uNaqW.js.map +1 -0
- package/dist/content-type-CORxaxcv.js +49 -0
- package/dist/content-type-CORxaxcv.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +204 -0
- package/dist/core/index.js.map +1 -0
- package/dist/define-CvpJ_pNP.js +115 -0
- package/dist/define-CvpJ_pNP.js.map +1 -0
- package/dist/errors-DoSpNHvs.js +20 -0
- package/dist/errors-DoSpNHvs.js.map +1 -0
- package/dist/errors-aKhko9T1.d.ts +18 -0
- package/dist/errors-aKhko9T1.d.ts.map +1 -0
- package/dist/eventbridge-scheduler-Bh6GqZY2.js +349 -0
- package/dist/eventbridge-scheduler-Bh6GqZY2.js.map +1 -0
- package/dist/framework-context-DVIIY8ZO.js +24 -0
- package/dist/framework-context-DVIIY8ZO.js.map +1 -0
- package/dist/gotenberg-NuJjxyln.js +291 -0
- package/dist/gotenberg-NuJjxyln.js.map +1 -0
- package/dist/http/index.d.ts +47 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +3 -0
- package/dist/http-service-DDNCO1s4.js +254 -0
- package/dist/http-service-DDNCO1s4.js.map +1 -0
- package/dist/http-service-T7E5UjP8.d.ts +80 -0
- package/dist/http-service-T7E5UjP8.d.ts.map +1 -0
- package/dist/imessage-BSAFOI8Z.js +154 -0
- package/dist/imessage-BSAFOI8Z.js.map +1 -0
- package/dist/index-BU4gmYO8.d.ts +254 -0
- package/dist/index-BU4gmYO8.d.ts.map +1 -0
- package/dist/index-CCivzmxO.d.ts +188 -0
- package/dist/index-CCivzmxO.d.ts.map +1 -0
- package/dist/index-CLmTrcu5.d.ts +22 -0
- package/dist/index-CLmTrcu5.d.ts.map +1 -0
- package/dist/index-CZX5OeOF.d.ts +235 -0
- package/dist/index-CZX5OeOF.d.ts.map +1 -0
- package/dist/index-CdFmEfZO.d.ts +359 -0
- package/dist/index-CdFmEfZO.d.ts.map +1 -0
- package/dist/index-Cuh6eMWc.d.ts +285 -0
- package/dist/index-Cuh6eMWc.d.ts.map +1 -0
- package/dist/index-DuOGj7vc.d.ts +107 -0
- package/dist/index-DuOGj7vc.d.ts.map +1 -0
- package/dist/index-ccZ1XOHw.d.ts +69 -0
- package/dist/index-ccZ1XOHw.d.ts.map +1 -0
- package/dist/index-n8JTpNf1.d.ts +247 -0
- package/dist/index-n8JTpNf1.d.ts.map +1 -0
- package/dist/index-pwW1OsOx.d.ts +134 -0
- package/dist/index-pwW1OsOx.d.ts.map +1 -0
- package/dist/index-zK1ZwS4m.d.ts +347 -0
- package/dist/index-zK1ZwS4m.d.ts.map +1 -0
- package/dist/limits-hjrO8zUG.js +80 -0
- package/dist/limits-hjrO8zUG.js.map +1 -0
- package/dist/mastra/index.d.ts +14 -0
- package/dist/mastra/index.d.ts.map +1 -0
- package/dist/mastra/index.js +26 -0
- package/dist/mastra/index.js.map +1 -0
- package/dist/mastra-vector-Dhc6XZ8l.js +234 -0
- package/dist/mastra-vector-Dhc6XZ8l.js.map +1 -0
- package/dist/mcp/index.d.ts +80 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +97 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/modules/artifacts/index.d.ts +337 -0
- package/dist/modules/artifacts/index.d.ts.map +1 -0
- package/dist/modules/artifacts/index.js +348 -0
- package/dist/modules/artifacts/index.js.map +1 -0
- package/dist/modules/browser/index.d.ts +516 -0
- package/dist/modules/browser/index.d.ts.map +1 -0
- package/dist/modules/browser/index.js +475 -0
- package/dist/modules/browser/index.js.map +1 -0
- package/dist/modules/calendar/index.d.ts +93 -0
- package/dist/modules/calendar/index.d.ts.map +1 -0
- package/dist/modules/calendar/index.js +131 -0
- package/dist/modules/calendar/index.js.map +1 -0
- package/dist/modules/code-sandbox/index.d.ts +317 -0
- package/dist/modules/code-sandbox/index.d.ts.map +1 -0
- package/dist/modules/code-sandbox/index.js +537 -0
- package/dist/modules/code-sandbox/index.js.map +1 -0
- package/dist/modules/content-type/index.d.ts +22 -0
- package/dist/modules/content-type/index.d.ts.map +1 -0
- package/dist/modules/content-type/index.js +66 -0
- package/dist/modules/content-type/index.js.map +1 -0
- package/dist/modules/crypto/index.d.ts +115 -0
- package/dist/modules/crypto/index.d.ts.map +1 -0
- package/dist/modules/crypto/index.js +139 -0
- package/dist/modules/crypto/index.js.map +1 -0
- package/dist/modules/document/index.d.ts +575 -0
- package/dist/modules/document/index.d.ts.map +1 -0
- package/dist/modules/document/index.js +444 -0
- package/dist/modules/document/index.js.map +1 -0
- package/dist/modules/document-extract/index.d.ts +438 -0
- package/dist/modules/document-extract/index.d.ts.map +1 -0
- package/dist/modules/document-extract/index.js +127 -0
- package/dist/modules/document-extract/index.js.map +1 -0
- package/dist/modules/document-render/index.d.ts +336 -0
- package/dist/modules/document-render/index.d.ts.map +1 -0
- package/dist/modules/document-render/index.js +155 -0
- package/dist/modules/document-render/index.js.map +1 -0
- package/dist/modules/email/index.d.ts +311 -0
- package/dist/modules/email/index.d.ts.map +1 -0
- package/dist/modules/email/index.js +167 -0
- package/dist/modules/email/index.js.map +1 -0
- package/dist/modules/email-message/index.d.ts +95 -0
- package/dist/modules/email-message/index.d.ts.map +1 -0
- package/dist/modules/email-message/index.js +264 -0
- package/dist/modules/email-message/index.js.map +1 -0
- package/dist/modules/file-convert/index.d.ts +273 -0
- package/dist/modules/file-convert/index.d.ts.map +1 -0
- package/dist/modules/file-convert/index.js +103 -0
- package/dist/modules/file-convert/index.js.map +1 -0
- package/dist/modules/files/index.d.ts +452 -0
- package/dist/modules/files/index.d.ts.map +1 -0
- package/dist/modules/files/index.js +733 -0
- package/dist/modules/files/index.js.map +1 -0
- package/dist/modules/image/index.d.ts +342 -0
- package/dist/modules/image/index.d.ts.map +1 -0
- package/dist/modules/image/index.js +281 -0
- package/dist/modules/image/index.js.map +1 -0
- package/dist/modules/messaging/index.d.ts +608 -0
- package/dist/modules/messaging/index.d.ts.map +1 -0
- package/dist/modules/messaging/index.js +1067 -0
- package/dist/modules/messaging/index.js.map +1 -0
- package/dist/modules/pdf/index.d.ts +287 -0
- package/dist/modules/pdf/index.d.ts.map +1 -0
- package/dist/modules/pdf/index.js +259 -0
- package/dist/modules/pdf/index.js.map +1 -0
- package/dist/modules/presentation/index.d.ts +247 -0
- package/dist/modules/presentation/index.d.ts.map +1 -0
- package/dist/modules/presentation/index.js +12657 -0
- package/dist/modules/presentation/index.js.map +1 -0
- package/dist/modules/queue/index.d.ts +129 -0
- package/dist/modules/queue/index.d.ts.map +1 -0
- package/dist/modules/queue/index.js +131 -0
- package/dist/modules/queue/index.js.map +1 -0
- package/dist/modules/rag/index.d.ts +250 -0
- package/dist/modules/rag/index.d.ts.map +1 -0
- package/dist/modules/rag/index.js +366 -0
- package/dist/modules/rag/index.js.map +1 -0
- package/dist/modules/scheduler/index.d.ts +216 -0
- package/dist/modules/scheduler/index.d.ts.map +1 -0
- package/dist/modules/scheduler/index.js +153 -0
- package/dist/modules/scheduler/index.js.map +1 -0
- package/dist/modules/skills/index.d.ts +205 -0
- package/dist/modules/skills/index.d.ts.map +1 -0
- package/dist/modules/skills/index.js +203 -0
- package/dist/modules/skills/index.js.map +1 -0
- package/dist/modules/tasks/index.d.ts +287 -0
- package/dist/modules/tasks/index.d.ts.map +1 -0
- package/dist/modules/tasks/index.js +207 -0
- package/dist/modules/tasks/index.js.map +1 -0
- package/dist/modules/vector-store/index.d.ts +3 -0
- package/dist/modules/vector-store/index.js +3 -0
- package/dist/modules/web-fetch/index.d.ts +99 -0
- package/dist/modules/web-fetch/index.d.ts.map +1 -0
- package/dist/modules/web-fetch/index.js +242 -0
- package/dist/modules/web-fetch/index.js.map +1 -0
- package/dist/object-artifact-store-CMTzCm_G.d.ts +7 -0
- package/dist/object-artifact-store-CMTzCm_G.d.ts.map +1 -0
- package/dist/object-artifact-store-wZ2j9cto.js +28 -0
- package/dist/object-artifact-store-wZ2j9cto.js.map +1 -0
- package/dist/pinecone-umY4t6OF.js +190 -0
- package/dist/pinecone-umY4t6OF.js.map +1 -0
- package/dist/provider-CgDAlg6K.js +34 -0
- package/dist/provider-CgDAlg6K.js.map +1 -0
- package/dist/qdrant-DMp4NhKR.js +253 -0
- package/dist/qdrant-DMp4NhKR.js.map +1 -0
- package/dist/resend-BAC38_dA.js +155 -0
- package/dist/resend-BAC38_dA.js.map +1 -0
- package/dist/s3-CsOaPWMP.js +955 -0
- package/dist/s3-CsOaPWMP.js.map +1 -0
- package/dist/schemas-ChOAhdo9.js +192 -0
- package/dist/schemas-ChOAhdo9.js.map +1 -0
- package/dist/slack-Di5BBNpt.js +1455 -0
- package/dist/slack-Di5BBNpt.js.map +1 -0
- package/dist/sqs-DCwS1i2N.js +225 -0
- package/dist/sqs-DCwS1i2N.js.map +1 -0
- package/dist/supabase-vector-Dpp9mmJR.js +218 -0
- package/dist/supabase-vector-Dpp9mmJR.js.map +1 -0
- package/dist/tanstack/index.d.ts +15 -0
- package/dist/tanstack/index.d.ts.map +1 -0
- package/dist/tanstack/index.js +28 -0
- package/dist/tanstack/index.js.map +1 -0
- package/dist/teams-DYAHNb39.js +835 -0
- package/dist/teams-DYAHNb39.js.map +1 -0
- package/dist/telegram-DDXWzkfL.js +734 -0
- package/dist/telegram-DDXWzkfL.js.map +1 -0
- package/dist/textract-CPLiB22H.js +554 -0
- package/dist/textract-CPLiB22H.js.map +1 -0
- package/dist/transport-B4vn-XiQ.js +157 -0
- package/dist/transport-B4vn-XiQ.js.map +1 -0
- package/dist/transport-i96ACAI_.d.ts +46 -0
- package/dist/transport-i96ACAI_.d.ts.map +1 -0
- package/dist/types-Ccb0DXY9.d.ts +150 -0
- package/dist/types-Ccb0DXY9.d.ts.map +1 -0
- package/dist/unique-EwBH1JPB.js +19 -0
- package/dist/unique-EwBH1JPB.js.map +1 -0
- package/dist/vector-store-C3nEO80e.js +193 -0
- package/dist/vector-store-C3nEO80e.js.map +1 -0
- package/dist/vendors/amazon-sp-api/index.d.ts +526 -0
- package/dist/vendors/amazon-sp-api/index.d.ts.map +1 -0
- package/dist/vendors/amazon-sp-api/index.js +975 -0
- package/dist/vendors/amazon-sp-api/index.js.map +1 -0
- package/dist/vendors/bedrock-agentcore-browser/index.d.ts +2 -0
- package/dist/vendors/bedrock-agentcore-browser/index.js +2 -0
- package/dist/vendors/bedrock-agentcore-code-interpreter/index.d.ts +228 -0
- package/dist/vendors/bedrock-agentcore-code-interpreter/index.d.ts.map +1 -0
- package/dist/vendors/bedrock-agentcore-code-interpreter/index.js +2 -0
- package/dist/vendors/cloudflare-browser/index.d.ts +2 -0
- package/dist/vendors/cloudflare-browser/index.js +2 -0
- package/dist/vendors/cloudflare-email/index.d.ts +260 -0
- package/dist/vendors/cloudflare-email/index.d.ts.map +1 -0
- package/dist/vendors/cloudflare-email/index.js +3 -0
- package/dist/vendors/cloudflare-sandbox/index.d.ts +565 -0
- package/dist/vendors/cloudflare-sandbox/index.d.ts.map +1 -0
- package/dist/vendors/cloudflare-sandbox/index.js +2 -0
- package/dist/vendors/eventbridge-scheduler/index.d.ts +2 -0
- package/dist/vendors/eventbridge-scheduler/index.js +2 -0
- package/dist/vendors/gotenberg/index.d.ts +306 -0
- package/dist/vendors/gotenberg/index.d.ts.map +1 -0
- package/dist/vendors/gotenberg/index.js +2 -0
- package/dist/vendors/imessage/index.d.ts +420 -0
- package/dist/vendors/imessage/index.d.ts.map +1 -0
- package/dist/vendors/imessage/index.js +4 -0
- package/dist/vendors/katana/index.d.ts +1570 -0
- package/dist/vendors/katana/index.d.ts.map +1 -0
- package/dist/vendors/katana/index.js +1639 -0
- package/dist/vendors/katana/index.js.map +1 -0
- package/dist/vendors/mastra-vector/index.d.ts +120 -0
- package/dist/vendors/mastra-vector/index.d.ts.map +1 -0
- package/dist/vendors/mastra-vector/index.js +3 -0
- package/dist/vendors/pinecone/index.d.ts +75 -0
- package/dist/vendors/pinecone/index.d.ts.map +1 -0
- package/dist/vendors/pinecone/index.js +3 -0
- package/dist/vendors/qdrant/index.d.ts +75 -0
- package/dist/vendors/qdrant/index.d.ts.map +1 -0
- package/dist/vendors/qdrant/index.js +3 -0
- package/dist/vendors/resend/index.d.ts +3 -0
- package/dist/vendors/resend/index.js +3 -0
- package/dist/vendors/s3/index.d.ts +2 -0
- package/dist/vendors/s3/index.js +2 -0
- package/dist/vendors/slack/index.d.ts +576 -0
- package/dist/vendors/slack/index.d.ts.map +1 -0
- package/dist/vendors/slack/index.js +3 -0
- package/dist/vendors/sqs/index.d.ts +2 -0
- package/dist/vendors/sqs/index.js +2 -0
- package/dist/vendors/supabase-vector/index.d.ts +89 -0
- package/dist/vendors/supabase-vector/index.d.ts.map +1 -0
- package/dist/vendors/supabase-vector/index.js +3 -0
- package/dist/vendors/teams/index.d.ts +303 -0
- package/dist/vendors/teams/index.d.ts.map +1 -0
- package/dist/vendors/teams/index.js +3 -0
- package/dist/vendors/telegram/index.d.ts +319 -0
- package/dist/vendors/telegram/index.d.ts.map +1 -0
- package/dist/vendors/telegram/index.js +3 -0
- package/dist/vendors/textract/index.d.ts +2 -0
- package/dist/vendors/textract/index.js +2 -0
- package/dist/vendors/woocommerce/index.d.ts +1700 -0
- package/dist/vendors/woocommerce/index.d.ts.map +1 -0
- package/dist/vendors/woocommerce/index.js +1427 -0
- package/dist/vendors/woocommerce/index.js.map +1 -0
- package/dist/with-auth-CpKqTrGK.js +240 -0
- package/dist/with-auth-CpKqTrGK.js.map +1 -0
- package/logos/LUCIDE-ATTRIBUTION.txt +4 -0
- package/logos/README.md +89 -0
- package/logos/amazon.svg +6 -0
- package/logos/artifacts.svg +9 -0
- package/logos/browser.svg +9 -0
- package/logos/calendar.svg +15 -0
- package/logos/cloudflare-browser.svg +5 -0
- package/logos/cloudflare-email.svg +5 -0
- package/logos/cloudflare.svg +4 -0
- package/logos/code-sandbox.svg +8 -0
- package/logos/content-type.svg +10 -0
- package/logos/crypto.svg +7 -0
- package/logos/document-extract.svg +12 -0
- package/logos/document-render.svg +8 -0
- package/logos/document.svg +10 -0
- package/logos/email-message.svg +8 -0
- package/logos/email.svg +7 -0
- package/logos/file-convert.svg +9 -0
- package/logos/files.svg +6 -0
- package/logos/gotenberg.svg +340 -0
- package/logos/image.svg +8 -0
- package/logos/imessage.svg +7 -0
- package/logos/katana.svg +13 -0
- package/logos/mastra.svg +7 -0
- package/logos/messaging.svg +7 -0
- package/logos/pack-logos.json +48 -0
- package/logos/pdf.svg +10 -0
- package/logos/pinecone.svg +25 -0
- package/logos/presentation.svg +8 -0
- package/logos/qdrant.svg +4 -0
- package/logos/queue.svg +11 -0
- package/logos/rag.svg +18 -0
- package/logos/resend.svg +5 -0
- package/logos/scheduler.svg +7 -0
- package/logos/skills.svg +10 -0
- package/logos/slack.svg +14 -0
- package/logos/supabase.svg +4 -0
- package/logos/tasks.svg +10 -0
- package/logos/teams.svg +6 -0
- package/logos/telegram.svg +10 -0
- package/logos/textract.svg +5 -0
- package/logos/vector-store.svg +8 -0
- package/logos/web-fetch.svg +8 -0
- package/logos/woocommerce.svg +4 -0
- package/package.json +373 -0
|
@@ -0,0 +1,975 @@
|
|
|
1
|
+
import { t as ToolError } from "../../errors-DoSpNHvs.js";
|
|
2
|
+
import { n as defineModule, r as defineTool } from "../../define-CvpJ_pNP.js";
|
|
3
|
+
import { n as requireAuth } from "../../provider-CgDAlg6K.js";
|
|
4
|
+
import { t as HttpService } from "../../http-service-DDNCO1s4.js";
|
|
5
|
+
import { t as AwsService } from "../../aws-service-msttbPrz.js";
|
|
6
|
+
import { isPlainObject, isString } from "es-toolkit";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import Decimal from "decimal.js";
|
|
9
|
+
import Papa from "papaparse";
|
|
10
|
+
//#region src/vendors/amazon-sp-api/contracts.ts
|
|
11
|
+
/** SP-API regional endpoints. */
|
|
12
|
+
const amazonSpApiEndpointSchema = z.enum([
|
|
13
|
+
"https://sellingpartnerapi-na.amazon.com",
|
|
14
|
+
"https://sellingpartnerapi-eu.amazon.com",
|
|
15
|
+
"https://sellingpartnerapi-fe.amazon.com"
|
|
16
|
+
]);
|
|
17
|
+
const amazonSpApiAuthSchema = z.object({
|
|
18
|
+
client_id: z.string().min(1).describe("LWA client id"),
|
|
19
|
+
client_secret: z.string().min(1).describe("LWA client secret"),
|
|
20
|
+
refresh_token: z.string().min(1).describe("LWA refresh token for the selling partner"),
|
|
21
|
+
access_key_id: z.string().min(1).describe("AWS access key id for SP-API SigV4"),
|
|
22
|
+
secret_access_key: z.string().min(1).describe("AWS secret access key for SP-API SigV4"),
|
|
23
|
+
region: z.string().min(1).describe("AWS region used for SigV4 (typically us-east-1 for NA, eu-west-1 for EU, us-west-2 for FE)"),
|
|
24
|
+
endpoint: amazonSpApiEndpointSchema.describe("SP-API regional endpoint"),
|
|
25
|
+
session_token: z.string().min(1).optional().describe("Optional AWS session token"),
|
|
26
|
+
marketplace_ids: z.array(z.string().min(1)).min(1).optional().describe("Default marketplace ids when a tool call omits marketplace_ids")
|
|
27
|
+
});
|
|
28
|
+
const amazonSpApiListOrdersInputSchema = z.object({
|
|
29
|
+
marketplace_ids: z.array(z.string().min(1)).min(1).optional().describe("Marketplace ids; omit to use the configured defaults"),
|
|
30
|
+
created_after: z.string().min(1).optional().describe("ISO 8601; orders created after"),
|
|
31
|
+
created_before: z.string().min(1).optional().describe("ISO 8601; orders created before"),
|
|
32
|
+
last_updated_after: z.string().min(1).optional().describe("ISO 8601; orders updated after"),
|
|
33
|
+
order_statuses: z.array(z.string().min(1)).optional().describe("Order status filter list"),
|
|
34
|
+
cursor: z.string().min(1).optional().describe("NextToken from a prior page"),
|
|
35
|
+
max_results: z.int().min(1).max(100).optional().describe("Page size (1-100)")
|
|
36
|
+
});
|
|
37
|
+
const amazonSpApiOrderSchema = z.object({
|
|
38
|
+
amazon_order_id: z.string(),
|
|
39
|
+
order_status: z.string().optional(),
|
|
40
|
+
purchase_date: z.string().optional(),
|
|
41
|
+
last_update_date: z.string().optional(),
|
|
42
|
+
marketplace_id: z.string().optional(),
|
|
43
|
+
order_total_amount: z.string().optional(),
|
|
44
|
+
order_total_currency: z.string().optional(),
|
|
45
|
+
fulfillment_channel: z.string().optional()
|
|
46
|
+
});
|
|
47
|
+
const amazonSpApiListOrdersOutputSchema = z.object({
|
|
48
|
+
items: z.array(amazonSpApiOrderSchema),
|
|
49
|
+
next_cursor: z.string().optional(),
|
|
50
|
+
truncated: z.boolean()
|
|
51
|
+
});
|
|
52
|
+
const amazonSpApiGetOrderInputSchema = z.object({ amazon_order_id: z.string().min(1).describe("Amazon order id") });
|
|
53
|
+
const amazonSpApiGetOrderOutputSchema = z.object({ order: amazonSpApiOrderSchema });
|
|
54
|
+
const amazonSpApiGetOrderItemsInputSchema = z.object({
|
|
55
|
+
amazon_order_id: z.string().min(1).describe("Amazon order id"),
|
|
56
|
+
cursor: z.string().min(1).optional().describe("NextToken from a prior page")
|
|
57
|
+
});
|
|
58
|
+
const amazonSpApiOrderItemSchema = z.object({
|
|
59
|
+
order_item_id: z.string(),
|
|
60
|
+
asin: z.string().optional(),
|
|
61
|
+
seller_sku: z.string().optional(),
|
|
62
|
+
title: z.string().optional(),
|
|
63
|
+
quantity_ordered: z.number().optional(),
|
|
64
|
+
quantity_shipped: z.number().optional(),
|
|
65
|
+
item_price_amount: z.string().optional(),
|
|
66
|
+
item_price_currency: z.string().optional()
|
|
67
|
+
});
|
|
68
|
+
const amazonSpApiGetOrderItemsOutputSchema = z.object({
|
|
69
|
+
amazon_order_id: z.string(),
|
|
70
|
+
items: z.array(amazonSpApiOrderItemSchema),
|
|
71
|
+
next_cursor: z.string().optional(),
|
|
72
|
+
truncated: z.boolean()
|
|
73
|
+
});
|
|
74
|
+
const amazonSpApiSearchOrdersInputSchema = z.object({
|
|
75
|
+
created_after: z.string().min(1).describe("ISO 8601; orders created at or after this time (required for reconciliation)"),
|
|
76
|
+
created_before: z.string().min(1).optional().describe("ISO 8601; orders created at or before this time"),
|
|
77
|
+
marketplace_ids: z.array(z.string().min(1)).min(1).optional().describe("Marketplace ids; omit to use the configured defaults"),
|
|
78
|
+
max_results: z.int().min(1).max(100).optional().describe("Page size (1-100, default 100)"),
|
|
79
|
+
cursor: z.string().min(1).optional().describe("paginationToken from a prior page"),
|
|
80
|
+
max_pages: z.int().min(1).max(50).optional().describe("When set, drains up to this many pages and returns a combined list (default 1)")
|
|
81
|
+
});
|
|
82
|
+
const amazonSpApiSearchOrderSchema = z.object({
|
|
83
|
+
order_id: z.string().describe("Amazon order id"),
|
|
84
|
+
created_time: z.string().optional().describe("Order created time (ISO 8601)"),
|
|
85
|
+
fulfillment_status: z.string().optional().describe("Fulfillment status when FULFILLMENT data is included")
|
|
86
|
+
});
|
|
87
|
+
const amazonSpApiSearchOrdersOutputSchema = z.object({
|
|
88
|
+
items: z.array(amazonSpApiSearchOrderSchema),
|
|
89
|
+
next_cursor: z.string().optional().describe("paginationToken for the next page when not fully drained"),
|
|
90
|
+
truncated: z.boolean()
|
|
91
|
+
});
|
|
92
|
+
const amazonSpApiListInventorySummariesInputSchema = z.object({
|
|
93
|
+
marketplace_id: z.string().min(1).optional().describe("Marketplace id; omit to use the first configured default"),
|
|
94
|
+
seller_skus: z.array(z.string().min(1)).max(50).optional().describe("Optional seller SKU filter (max 50)"),
|
|
95
|
+
start_date_time: z.string().min(1).optional().describe("ISO 8601; summaries changed after"),
|
|
96
|
+
cursor: z.string().min(1).optional().describe("nextToken from a prior page")
|
|
97
|
+
});
|
|
98
|
+
const amazonSpApiInventorySummarySchema = z.object({
|
|
99
|
+
seller_sku: z.string().optional(),
|
|
100
|
+
asin: z.string().optional(),
|
|
101
|
+
fn_sku: z.string().optional(),
|
|
102
|
+
condition: z.string().optional(),
|
|
103
|
+
total_quantity: z.number().optional(),
|
|
104
|
+
product_name: z.string().optional()
|
|
105
|
+
});
|
|
106
|
+
const amazonSpApiListInventorySummariesOutputSchema = z.object({
|
|
107
|
+
items: z.array(amazonSpApiInventorySummarySchema),
|
|
108
|
+
next_cursor: z.string().optional(),
|
|
109
|
+
truncated: z.boolean()
|
|
110
|
+
});
|
|
111
|
+
const amazonSpApiCreateReportInputSchema = z.object({
|
|
112
|
+
report_type: z.string().min(1).describe("Report type (e.g. GET_FLAT_FILE_OPEN_LISTINGS_DATA)"),
|
|
113
|
+
marketplace_ids: z.array(z.string().min(1)).min(1).optional().describe("Marketplace ids; omit to use the configured defaults"),
|
|
114
|
+
data_start_time: z.string().min(1).optional().describe("ISO 8601 report data start"),
|
|
115
|
+
data_end_time: z.string().min(1).optional().describe("ISO 8601 report data end"),
|
|
116
|
+
report_options: z.record(z.string(), z.string()).optional().describe("Optional report-type-specific options map")
|
|
117
|
+
});
|
|
118
|
+
const amazonSpApiCreateReportOutputSchema = z.object({ report_id: z.string() });
|
|
119
|
+
const amazonSpApiGetReportInputSchema = z.object({ report_id: z.string().min(1).describe("Report id from createReport or listReports") });
|
|
120
|
+
const amazonSpApiReportSchema = z.object({
|
|
121
|
+
report_id: z.string(),
|
|
122
|
+
report_type: z.string().optional(),
|
|
123
|
+
processing_status: z.string().optional(),
|
|
124
|
+
marketplace_ids: z.array(z.string()).optional(),
|
|
125
|
+
data_start_time: z.string().optional(),
|
|
126
|
+
data_end_time: z.string().optional(),
|
|
127
|
+
report_document_id: z.string().optional(),
|
|
128
|
+
created_time: z.string().optional()
|
|
129
|
+
});
|
|
130
|
+
const amazonSpApiGetReportOutputSchema = z.object({ report: amazonSpApiReportSchema });
|
|
131
|
+
const amazonSpApiListReportsInputSchema = z.object({
|
|
132
|
+
report_types: z.array(z.string().min(1)).optional().describe("Filter by report type(s)"),
|
|
133
|
+
processing_statuses: z.array(z.string().min(1)).optional().describe("Filter by processing status (e.g. DONE, IN_QUEUE, IN_PROGRESS, CANCELLED, FATAL)"),
|
|
134
|
+
marketplace_ids: z.array(z.string().min(1)).min(1).optional().describe("Marketplace ids filter; omit to use configured defaults when available"),
|
|
135
|
+
page_size: z.int().min(1).max(100).optional().describe("Page size (1-100)"),
|
|
136
|
+
created_since: z.string().min(1).optional().describe("ISO 8601; reports created after"),
|
|
137
|
+
created_until: z.string().min(1).optional().describe("ISO 8601; reports created before"),
|
|
138
|
+
cursor: z.string().min(1).optional().describe("nextToken from a prior page")
|
|
139
|
+
});
|
|
140
|
+
const amazonSpApiListReportsOutputSchema = z.object({
|
|
141
|
+
items: z.array(amazonSpApiReportSchema),
|
|
142
|
+
next_cursor: z.string().optional(),
|
|
143
|
+
truncated: z.boolean()
|
|
144
|
+
});
|
|
145
|
+
const amazonSpApiGetReportDocumentInputSchema = z.object({ report_document_id: z.string().min(1).describe("Report document id from a completed report") });
|
|
146
|
+
const amazonSpApiGetReportDocumentOutputSchema = z.object({
|
|
147
|
+
document_id: z.string(),
|
|
148
|
+
url: z.string(),
|
|
149
|
+
compression_algorithm: z.string().optional()
|
|
150
|
+
});
|
|
151
|
+
/**
|
|
152
|
+
* Composite input: pick newest completed V2 settlement report in the retention
|
|
153
|
+
* window (default 90d), download one document, return eight summary fields only.
|
|
154
|
+
*/
|
|
155
|
+
const amazonSpApiGetSettlementSummaryInputSchema = z.object({
|
|
156
|
+
report_id: z.string().min(1).optional().describe("Optional report id; when set, uses this report instead of listing the newest DONE settlement report"),
|
|
157
|
+
created_since: z.string().min(1).optional().describe("ISO 8601 lower bound when listing reports (default: now minus 90 days)")
|
|
158
|
+
});
|
|
159
|
+
/** Eight summary fields only — never raw TSV rows. */
|
|
160
|
+
const amazonSpApiSettlementSummarySchema = z.object({
|
|
161
|
+
settlement_id: z.string().describe("Amazon settlement id"),
|
|
162
|
+
settlement_start_date: z.string().describe("Settlement period start"),
|
|
163
|
+
settlement_end_date: z.string().describe("Settlement period end"),
|
|
164
|
+
deposit_date: z.string().describe("Deposit date when present; otherwise settlement end"),
|
|
165
|
+
currency: z.string().describe("ISO currency code from the report"),
|
|
166
|
+
total_amount_cents: z.number().int().describe("Report total-amount as safe integer cents (must equal amount_sum_cents)"),
|
|
167
|
+
amount_sum_cents: z.number().int().describe("Sum of amount column as safe integer cents"),
|
|
168
|
+
row_count: z.number().int().describe("Number of data rows in the TSV (excluding header)")
|
|
169
|
+
});
|
|
170
|
+
const amazonSpApiGetSettlementSummaryOutputSchema = amazonSpApiSettlementSummarySchema;
|
|
171
|
+
const amazonSpApiSearchCatalogItemsInputSchema = z.object({
|
|
172
|
+
keywords: z.array(z.string().min(1)).min(1).describe("Search keywords"),
|
|
173
|
+
marketplace_ids: z.array(z.string().min(1)).min(1).optional().describe("Marketplace ids; omit to use the configured defaults"),
|
|
174
|
+
included_data: z.array(z.string().min(1)).optional().describe("Data sets to include (e.g. summaries, images, attributes)"),
|
|
175
|
+
page_size: z.int().min(1).max(20).optional().describe("Page size (1-20)"),
|
|
176
|
+
cursor: z.string().min(1).optional().describe("pageToken from a prior page")
|
|
177
|
+
});
|
|
178
|
+
const amazonSpApiCatalogItemSchema = z.object({
|
|
179
|
+
asin: z.string(),
|
|
180
|
+
title: z.string().optional(),
|
|
181
|
+
brand: z.string().optional(),
|
|
182
|
+
product_type: z.string().optional(),
|
|
183
|
+
marketplace_id: z.string().optional()
|
|
184
|
+
});
|
|
185
|
+
const amazonSpApiSearchCatalogItemsOutputSchema = z.object({
|
|
186
|
+
items: z.array(amazonSpApiCatalogItemSchema),
|
|
187
|
+
number_of_results: z.number().optional(),
|
|
188
|
+
next_cursor: z.string().optional(),
|
|
189
|
+
truncated: z.boolean()
|
|
190
|
+
});
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/vendors/amazon-sp-api/domain.ts
|
|
193
|
+
/**
|
|
194
|
+
* Amazon SP-API: LWA body, order/inventory/report/catalog parse (no HTTP).
|
|
195
|
+
*/
|
|
196
|
+
const LWA_TOKEN_URL = "https://api.amazon.com/auth/o2/token";
|
|
197
|
+
function lwaTokenBody(auth) {
|
|
198
|
+
return new URLSearchParams({
|
|
199
|
+
grant_type: "refresh_token",
|
|
200
|
+
refresh_token: auth.refresh_token,
|
|
201
|
+
client_id: auth.client_id,
|
|
202
|
+
client_secret: auth.client_secret
|
|
203
|
+
}).toString();
|
|
204
|
+
}
|
|
205
|
+
function parseLwaAccessToken(data) {
|
|
206
|
+
if (!isPlainObject(data) || !isString(data["access_token"]) || data["access_token"].length === 0) throw new ToolError("Amazon LWA did not return an access_token", { code: "bad_auth" });
|
|
207
|
+
return data["access_token"];
|
|
208
|
+
}
|
|
209
|
+
function parseOrder(value) {
|
|
210
|
+
if (!isPlainObject(value) || !isString(value["AmazonOrderId"]) || value["AmazonOrderId"].length === 0) throw new ToolError("Amazon SP-API returned an invalid order", { code: "upstream" });
|
|
211
|
+
const total = value["OrderTotal"];
|
|
212
|
+
const amount = isPlainObject(total) && isString(total["Amount"]) ? total["Amount"] : void 0;
|
|
213
|
+
const currency = isPlainObject(total) && isString(total["CurrencyCode"]) ? total["CurrencyCode"] : void 0;
|
|
214
|
+
return {
|
|
215
|
+
amazon_order_id: value["AmazonOrderId"],
|
|
216
|
+
...isString(value["OrderStatus"]) && { order_status: value["OrderStatus"] },
|
|
217
|
+
...isString(value["PurchaseDate"]) && { purchase_date: value["PurchaseDate"] },
|
|
218
|
+
...isString(value["LastUpdateDate"]) && { last_update_date: value["LastUpdateDate"] },
|
|
219
|
+
...isString(value["MarketplaceId"]) && { marketplace_id: value["MarketplaceId"] },
|
|
220
|
+
...amount && { order_total_amount: amount },
|
|
221
|
+
...currency && { order_total_currency: currency },
|
|
222
|
+
...isString(value["FulfillmentChannel"]) && { fulfillment_channel: value["FulfillmentChannel"] }
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function parseOrdersPayload(data) {
|
|
226
|
+
if (!isPlainObject(data)) throw new ToolError("Amazon SP-API orders payload invalid", { code: "upstream" });
|
|
227
|
+
const payload = data["payload"];
|
|
228
|
+
if (!isPlainObject(payload)) throw new ToolError("Amazon SP-API orders missing payload", { code: "upstream" });
|
|
229
|
+
const orders = payload["Orders"];
|
|
230
|
+
if (!Array.isArray(orders)) throw new ToolError("Amazon SP-API orders missing Orders array", { code: "upstream" });
|
|
231
|
+
const nextToken = isString(payload["NextToken"]) && payload["NextToken"].length > 0 ? payload["NextToken"] : void 0;
|
|
232
|
+
return {
|
|
233
|
+
items: orders.map(parseOrder),
|
|
234
|
+
...nextToken && { nextToken }
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function parseOrderPayload(data) {
|
|
238
|
+
if (!isPlainObject(data) || !isPlainObject(data["payload"])) throw new ToolError("Amazon SP-API get order payload invalid", { code: "upstream" });
|
|
239
|
+
return parseOrder(data["payload"]);
|
|
240
|
+
}
|
|
241
|
+
/** Orders API v2026-01-01 SearchOrders — camelCase body, not v0 payload wrapper. */
|
|
242
|
+
function parseSearchOrder(value) {
|
|
243
|
+
if (!isPlainObject(value) || !isString(value["orderId"]) || value["orderId"].length === 0) throw new ToolError("Amazon SP-API searchOrders returned an invalid order", { code: "upstream" });
|
|
244
|
+
const fulfillment = value["fulfillment"];
|
|
245
|
+
const fulfillmentStatus = isPlainObject(fulfillment) && isString(fulfillment["fulfillmentStatus"]) ? fulfillment["fulfillmentStatus"] : void 0;
|
|
246
|
+
return {
|
|
247
|
+
order_id: value["orderId"],
|
|
248
|
+
...isString(value["createdTime"]) && { created_time: value["createdTime"] },
|
|
249
|
+
...fulfillmentStatus && { fulfillment_status: fulfillmentStatus }
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function parseSearchOrdersPayload(data) {
|
|
253
|
+
if (!isPlainObject(data)) throw new ToolError("Amazon SP-API searchOrders payload invalid", { code: "upstream" });
|
|
254
|
+
const root = isPlainObject(data["payload"]) ? data["payload"] : data;
|
|
255
|
+
if (!isPlainObject(root)) throw new ToolError("Amazon SP-API searchOrders missing body", { code: "upstream" });
|
|
256
|
+
const orders = root["orders"];
|
|
257
|
+
if (!Array.isArray(orders)) throw new ToolError("Amazon SP-API searchOrders missing orders array", { code: "upstream" });
|
|
258
|
+
const pagination = root["pagination"];
|
|
259
|
+
const nextToken = isPlainObject(pagination) && isString(pagination["nextToken"]) && pagination["nextToken"].length > 0 ? pagination["nextToken"] : void 0;
|
|
260
|
+
return {
|
|
261
|
+
items: orders.map(parseSearchOrder),
|
|
262
|
+
...nextToken && { nextToken }
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function parseOrderItem(value) {
|
|
266
|
+
if (!isPlainObject(value) || !isString(value["OrderItemId"]) || value["OrderItemId"].length === 0) throw new ToolError("Amazon SP-API returned an invalid order item", { code: "upstream" });
|
|
267
|
+
const price = value["ItemPrice"];
|
|
268
|
+
const amount = isPlainObject(price) && isString(price["Amount"]) ? price["Amount"] : void 0;
|
|
269
|
+
const currency = isPlainObject(price) && isString(price["CurrencyCode"]) ? price["CurrencyCode"] : void 0;
|
|
270
|
+
return {
|
|
271
|
+
order_item_id: value["OrderItemId"],
|
|
272
|
+
...isString(value["ASIN"]) && { asin: value["ASIN"] },
|
|
273
|
+
...isString(value["SellerSKU"]) && { seller_sku: value["SellerSKU"] },
|
|
274
|
+
...isString(value["Title"]) && { title: value["Title"] },
|
|
275
|
+
...typeof value["QuantityOrdered"] === "number" && { quantity_ordered: value["QuantityOrdered"] },
|
|
276
|
+
...typeof value["QuantityShipped"] === "number" && { quantity_shipped: value["QuantityShipped"] },
|
|
277
|
+
...amount && { item_price_amount: amount },
|
|
278
|
+
...currency && { item_price_currency: currency }
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function parseOrderItemsPayload(data) {
|
|
282
|
+
if (!isPlainObject(data)) throw new ToolError("Amazon SP-API order items payload invalid", { code: "upstream" });
|
|
283
|
+
const payload = data["payload"];
|
|
284
|
+
if (!isPlainObject(payload)) throw new ToolError("Amazon SP-API order items missing payload", { code: "upstream" });
|
|
285
|
+
if (!isString(payload["AmazonOrderId"]) || payload["AmazonOrderId"].length === 0) throw new ToolError("Amazon SP-API order items missing AmazonOrderId", { code: "upstream" });
|
|
286
|
+
const orderItems = payload["OrderItems"];
|
|
287
|
+
if (!Array.isArray(orderItems)) throw new ToolError("Amazon SP-API order items missing OrderItems array", { code: "upstream" });
|
|
288
|
+
const nextToken = isString(payload["NextToken"]) && payload["NextToken"].length > 0 ? payload["NextToken"] : void 0;
|
|
289
|
+
return {
|
|
290
|
+
amazon_order_id: payload["AmazonOrderId"],
|
|
291
|
+
items: orderItems.map(parseOrderItem),
|
|
292
|
+
...nextToken && { nextToken }
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function parseInventorySummary(value) {
|
|
296
|
+
if (!isPlainObject(value)) throw new ToolError("Amazon SP-API returned an invalid inventory summary", { code: "upstream" });
|
|
297
|
+
const totals = value["inventoryDetails"];
|
|
298
|
+
let totalQuantity;
|
|
299
|
+
if (isPlainObject(totals) && typeof totals["fulfillableQuantity"] === "number") totalQuantity = totals["fulfillableQuantity"];
|
|
300
|
+
else if (typeof value["totalQuantity"] === "number") totalQuantity = value["totalQuantity"];
|
|
301
|
+
return {
|
|
302
|
+
...isString(value["sellerSku"]) && { seller_sku: value["sellerSku"] },
|
|
303
|
+
...isString(value["asin"]) && { asin: value["asin"] },
|
|
304
|
+
...isString(value["fnSku"]) && { fn_sku: value["fnSku"] },
|
|
305
|
+
...isString(value["condition"]) && { condition: value["condition"] },
|
|
306
|
+
...totalQuantity !== void 0 && { total_quantity: totalQuantity },
|
|
307
|
+
...isString(value["productName"]) && { product_name: value["productName"] }
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function parseInventoryPayload(data) {
|
|
311
|
+
if (!isPlainObject(data)) throw new ToolError("Amazon SP-API inventory payload invalid", { code: "upstream" });
|
|
312
|
+
const payload = data["payload"];
|
|
313
|
+
if (!isPlainObject(payload)) throw new ToolError("Amazon SP-API inventory missing payload", { code: "upstream" });
|
|
314
|
+
const summaries = payload["inventorySummaries"];
|
|
315
|
+
if (!Array.isArray(summaries)) throw new ToolError("Amazon SP-API inventory missing inventorySummaries", { code: "upstream" });
|
|
316
|
+
const pagination = payload["pagination"];
|
|
317
|
+
const nextToken = isPlainObject(pagination) && isString(pagination["nextToken"]) && pagination["nextToken"].length > 0 ? pagination["nextToken"] : void 0;
|
|
318
|
+
return {
|
|
319
|
+
items: summaries.map(parseInventorySummary),
|
|
320
|
+
...nextToken && { nextToken }
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function parseCreateReportPayload(data) {
|
|
324
|
+
if (!isPlainObject(data) || !isString(data["reportId"]) || data["reportId"].length === 0) throw new ToolError("Amazon SP-API create report response invalid", { code: "upstream" });
|
|
325
|
+
return { report_id: data["reportId"] };
|
|
326
|
+
}
|
|
327
|
+
function parseReport(value) {
|
|
328
|
+
if (!isPlainObject(value) || !isString(value["reportId"]) || value["reportId"].length === 0) throw new ToolError("Amazon SP-API returned an invalid report", { code: "upstream" });
|
|
329
|
+
const marketplaceIds = value["marketplaceIds"];
|
|
330
|
+
const marketplace_ids = Array.isArray(marketplaceIds) && marketplaceIds.every((id) => isString(id)) ? marketplaceIds.filter((id) => isString(id) && id.length > 0) : void 0;
|
|
331
|
+
return {
|
|
332
|
+
report_id: value["reportId"],
|
|
333
|
+
...isString(value["reportType"]) && { report_type: value["reportType"] },
|
|
334
|
+
...isString(value["processingStatus"]) && { processing_status: value["processingStatus"] },
|
|
335
|
+
...marketplace_ids && marketplace_ids.length > 0 && { marketplace_ids },
|
|
336
|
+
...isString(value["dataStartTime"]) && { data_start_time: value["dataStartTime"] },
|
|
337
|
+
...isString(value["dataEndTime"]) && { data_end_time: value["dataEndTime"] },
|
|
338
|
+
...isString(value["reportDocumentId"]) && { report_document_id: value["reportDocumentId"] },
|
|
339
|
+
...isString(value["createdTime"]) && { created_time: value["createdTime"] }
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function parseGetReportPayload(data) {
|
|
343
|
+
return parseReport(data);
|
|
344
|
+
}
|
|
345
|
+
function parseListReportsPayload(data) {
|
|
346
|
+
if (!isPlainObject(data)) throw new ToolError("Amazon SP-API list reports payload invalid", { code: "upstream" });
|
|
347
|
+
const reports = data["reports"];
|
|
348
|
+
if (!Array.isArray(reports)) throw new ToolError("Amazon SP-API list reports missing reports array", { code: "upstream" });
|
|
349
|
+
const nextToken = isString(data["nextToken"]) && data["nextToken"].length > 0 ? data["nextToken"] : void 0;
|
|
350
|
+
return {
|
|
351
|
+
items: reports.map(parseReport),
|
|
352
|
+
...nextToken && { nextToken }
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function parseReportDocumentPayload(data) {
|
|
356
|
+
if (!isPlainObject(data) || !isString(data["reportDocumentId"]) || data["reportDocumentId"].length === 0 || !isString(data["url"]) || data["url"].length === 0) throw new ToolError("Amazon SP-API report document response invalid", { code: "upstream" });
|
|
357
|
+
return {
|
|
358
|
+
document_id: data["reportDocumentId"],
|
|
359
|
+
url: data["url"],
|
|
360
|
+
...isString(data["compressionAlgorithm"]) && data["compressionAlgorithm"].length > 0 && { compression_algorithm: data["compressionAlgorithm"] }
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function parseCatalogItem(value) {
|
|
364
|
+
if (!isPlainObject(value) || !isString(value["asin"]) || value["asin"].length === 0) throw new ToolError("Amazon SP-API returned an invalid catalog item", { code: "upstream" });
|
|
365
|
+
const summaries = value["summaries"];
|
|
366
|
+
let title;
|
|
367
|
+
let brand;
|
|
368
|
+
let marketplace_id;
|
|
369
|
+
if (Array.isArray(summaries) && summaries.length > 0 && isPlainObject(summaries[0])) {
|
|
370
|
+
const summary = summaries[0];
|
|
371
|
+
if (isString(summary["itemName"])) title = summary["itemName"];
|
|
372
|
+
if (isString(summary["brandName"])) brand = summary["brandName"];
|
|
373
|
+
if (isString(summary["marketplaceId"])) marketplace_id = summary["marketplaceId"];
|
|
374
|
+
}
|
|
375
|
+
const productTypes = value["productTypes"];
|
|
376
|
+
let product_type;
|
|
377
|
+
if (Array.isArray(productTypes) && productTypes.length > 0 && isPlainObject(productTypes[0])) {
|
|
378
|
+
const pt = productTypes[0];
|
|
379
|
+
if (isString(pt["productType"])) product_type = pt["productType"];
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
asin: value["asin"],
|
|
383
|
+
...title && { title },
|
|
384
|
+
...brand && { brand },
|
|
385
|
+
...product_type && { product_type },
|
|
386
|
+
...marketplace_id && { marketplace_id }
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
function parseSearchCatalogItemsPayload(data) {
|
|
390
|
+
if (!isPlainObject(data)) throw new ToolError("Amazon SP-API catalog search payload invalid", { code: "upstream" });
|
|
391
|
+
const items = data["items"];
|
|
392
|
+
if (!Array.isArray(items)) throw new ToolError("Amazon SP-API catalog search missing items array", { code: "upstream" });
|
|
393
|
+
const pagination = data["pagination"];
|
|
394
|
+
const nextToken = isPlainObject(pagination) && isString(pagination["nextToken"]) && pagination["nextToken"].length > 0 ? pagination["nextToken"] : void 0;
|
|
395
|
+
const numberOfResults = typeof data["numberOfResults"] === "number" ? data["numberOfResults"] : void 0;
|
|
396
|
+
return {
|
|
397
|
+
items: items.map(parseCatalogItem),
|
|
398
|
+
...numberOfResults !== void 0 && { numberOfResults },
|
|
399
|
+
...nextToken && { nextToken }
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
function requireMarketplaceIds(inputIds, authIds, label) {
|
|
403
|
+
const ids = inputIds ?? authIds;
|
|
404
|
+
if (!ids || ids.length === 0) throw new ToolError(`${label} requires marketplace_ids on the call or auth`, { code: "bad_input" });
|
|
405
|
+
return ids;
|
|
406
|
+
}
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/vendors/amazon-sp-api/domain/settlement.ts
|
|
409
|
+
/**
|
|
410
|
+
* Amazon settlement report V2 (GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2).
|
|
411
|
+
* TSV via papaparse; money via decimal.js. Never put raw row PII in errors/output.
|
|
412
|
+
*/
|
|
413
|
+
/** Report type for Flat File V2 Settlement (auto-scheduled by Amazon). */
|
|
414
|
+
const SETTLEMENT_REPORT_TYPE_V2 = "GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2";
|
|
415
|
+
/** Max compressed document body (bytes). */
|
|
416
|
+
const SETTLEMENT_MAX_COMPRESSED_BYTES = 16 * 1024 * 1024;
|
|
417
|
+
/** Required V2 header names (order free after parse; extra trailing columns OK). */
|
|
418
|
+
const SETTLEMENT_V2_REQUIRED_COLUMNS = [
|
|
419
|
+
"settlement-id",
|
|
420
|
+
"settlement-start-date",
|
|
421
|
+
"settlement-end-date",
|
|
422
|
+
"deposit-date",
|
|
423
|
+
"total-amount",
|
|
424
|
+
"currency",
|
|
425
|
+
"amount"
|
|
426
|
+
];
|
|
427
|
+
function settlementError(message, code = "upstream") {
|
|
428
|
+
throw new ToolError(message, { code });
|
|
429
|
+
}
|
|
430
|
+
function cell(row, key) {
|
|
431
|
+
return (row[key] ?? "").trim();
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Parse Amazon settlement amount strings to safe integer cents via decimal.js.
|
|
435
|
+
* Empty → 0. Strips US thousands commas only (`1,234.56` → `1234.56`).
|
|
436
|
+
*/
|
|
437
|
+
function parseUsMoneyToSafeCents(raw) {
|
|
438
|
+
const trimmed = raw.trim();
|
|
439
|
+
if (trimmed.length === 0) return 0;
|
|
440
|
+
const normalized = trimmed.replace(/,/g, "");
|
|
441
|
+
let value;
|
|
442
|
+
try {
|
|
443
|
+
value = new Decimal(normalized);
|
|
444
|
+
} catch {
|
|
445
|
+
settlementError("Settlement report has an invalid amount cell", "upstream");
|
|
446
|
+
}
|
|
447
|
+
if (!value.isFinite()) settlementError("Settlement report has a non-numeric amount", "upstream");
|
|
448
|
+
const cents = value.times(100).toDecimalPlaces(0, Decimal.ROUND_HALF_UP);
|
|
449
|
+
if (!cents.isInteger()) settlementError("Settlement report has a non-numeric amount", "upstream");
|
|
450
|
+
const n = cents.toNumber();
|
|
451
|
+
if (!Number.isSafeInteger(n)) settlementError("Settlement amount exceeds safe integer cents range", "upstream");
|
|
452
|
+
return n;
|
|
453
|
+
}
|
|
454
|
+
/** Copy into a fresh ArrayBuffer so Blob accepts it under exact DOM typings. */
|
|
455
|
+
function toArrayBuffer(bytes) {
|
|
456
|
+
const copy = new Uint8Array(bytes.byteLength);
|
|
457
|
+
copy.set(bytes);
|
|
458
|
+
return copy.buffer;
|
|
459
|
+
}
|
|
460
|
+
/** Decompress GZIP when report document uses compressionAlgorithm GZIP (Web DecompressionStream). */
|
|
461
|
+
async function maybeGunzipReportBytes(bytes, compressionAlgorithm) {
|
|
462
|
+
if (!compressionAlgorithm) return bytes;
|
|
463
|
+
const algo = compressionAlgorithm.toUpperCase();
|
|
464
|
+
if (algo !== "GZIP") settlementError(`Unsupported settlement report compression: ${algo}`, "upstream");
|
|
465
|
+
if (bytes.byteLength > 16777216) settlementError("Settlement report compressed body exceeds limit", "too_large");
|
|
466
|
+
if (typeof DecompressionStream === "undefined") settlementError("GZIP decompression is not available in this runtime", "unsupported");
|
|
467
|
+
try {
|
|
468
|
+
const stream = new Blob([toArrayBuffer(bytes)]).stream().pipeThrough(new DecompressionStream("gzip"));
|
|
469
|
+
const buffer = await new Response(stream).arrayBuffer();
|
|
470
|
+
if (buffer.byteLength > 67108864) settlementError("Settlement report decompressed body exceeds limit", "too_large");
|
|
471
|
+
return new Uint8Array(buffer);
|
|
472
|
+
} catch (error) {
|
|
473
|
+
if (error instanceof ToolError) throw error;
|
|
474
|
+
settlementError("Failed to decompress settlement report", "upstream");
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Parse Flat File V2 settlement TSV into the eight summary fields only.
|
|
479
|
+
* Validates single settlement-id, currency, period, and amount sum vs total-amount.
|
|
480
|
+
*/
|
|
481
|
+
function parseSettlementV2Tsv(text) {
|
|
482
|
+
const result = Papa.parse(text, {
|
|
483
|
+
delimiter: " ",
|
|
484
|
+
header: true,
|
|
485
|
+
skipEmptyLines: "greedy",
|
|
486
|
+
transformHeader: (header) => header.trim().replace(/^\uFEFF/, "")
|
|
487
|
+
});
|
|
488
|
+
if (result.errors.length > 0) settlementError("Settlement report TSV could not be parsed", "upstream");
|
|
489
|
+
const fields = result.meta.fields ?? [];
|
|
490
|
+
for (const required of SETTLEMENT_V2_REQUIRED_COLUMNS) if (!fields.includes(required)) settlementError("Settlement report header columns do not match Flat File V2 schema", "upstream");
|
|
491
|
+
const rows = result.data;
|
|
492
|
+
if (rows.length === 0) settlementError("Settlement report is empty or missing data rows", "upstream");
|
|
493
|
+
if (rows.length > 25e4) settlementError("Settlement report exceeds max row limit", "too_large");
|
|
494
|
+
let settlementId;
|
|
495
|
+
let settlementStart;
|
|
496
|
+
let settlementEnd;
|
|
497
|
+
let depositDate;
|
|
498
|
+
let currency;
|
|
499
|
+
let totalAmountCents;
|
|
500
|
+
let amountSum = new Decimal(0);
|
|
501
|
+
for (const row of rows) {
|
|
502
|
+
const rowSettlementId = cell(row, "settlement-id");
|
|
503
|
+
const rowStart = cell(row, "settlement-start-date");
|
|
504
|
+
const rowEnd = cell(row, "settlement-end-date");
|
|
505
|
+
const rowDeposit = cell(row, "deposit-date");
|
|
506
|
+
const rowTotal = cell(row, "total-amount");
|
|
507
|
+
const rowCurrency = cell(row, "currency");
|
|
508
|
+
const rowAmount = cell(row, "amount");
|
|
509
|
+
if (rowSettlementId.length === 0) settlementError("Settlement report row missing settlement-id", "upstream");
|
|
510
|
+
const rowTotalCents = parseUsMoneyToSafeCents(rowTotal);
|
|
511
|
+
const rowAmountCents = parseUsMoneyToSafeCents(rowAmount);
|
|
512
|
+
if (settlementId === void 0) {
|
|
513
|
+
settlementId = rowSettlementId;
|
|
514
|
+
settlementStart = rowStart;
|
|
515
|
+
settlementEnd = rowEnd;
|
|
516
|
+
depositDate = rowDeposit;
|
|
517
|
+
currency = rowCurrency;
|
|
518
|
+
totalAmountCents = rowTotalCents;
|
|
519
|
+
} else {
|
|
520
|
+
if (rowSettlementId !== settlementId) settlementError("Settlement report contains multiple settlement ids", "upstream");
|
|
521
|
+
if (rowStart !== settlementStart || rowEnd !== settlementEnd) settlementError("Settlement report has inconsistent settlement period", "upstream");
|
|
522
|
+
if (rowCurrency !== currency) settlementError("Settlement report has inconsistent currency", "upstream");
|
|
523
|
+
if (rowTotalCents !== totalAmountCents) settlementError("Settlement report has inconsistent total-amount", "upstream");
|
|
524
|
+
if (rowDeposit.length > 0) {
|
|
525
|
+
if (depositDate && depositDate.length > 0 && rowDeposit !== depositDate) settlementError("Settlement report has inconsistent deposit-date", "upstream");
|
|
526
|
+
if (!depositDate || depositDate.length === 0) depositDate = rowDeposit;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
amountSum = amountSum.plus(rowAmountCents);
|
|
530
|
+
}
|
|
531
|
+
if (settlementId === void 0 || settlementStart === void 0 || settlementEnd === void 0 || currency === void 0 || totalAmountCents === void 0) settlementError("Settlement report has no usable data rows", "upstream");
|
|
532
|
+
if (!amountSum.isInteger() || !Number.isSafeInteger(amountSum.toNumber())) settlementError("Settlement amount sum exceeds safe integer cents range", "upstream");
|
|
533
|
+
const amountSumCents = amountSum.toNumber();
|
|
534
|
+
if (amountSumCents !== totalAmountCents) settlementError("Settlement amount sum does not match total-amount", "upstream");
|
|
535
|
+
return {
|
|
536
|
+
settlement_id: settlementId,
|
|
537
|
+
settlement_start_date: settlementStart,
|
|
538
|
+
settlement_end_date: settlementEnd,
|
|
539
|
+
deposit_date: depositDate && depositDate.length > 0 ? depositDate : settlementEnd,
|
|
540
|
+
currency,
|
|
541
|
+
total_amount_cents: totalAmountCents,
|
|
542
|
+
amount_sum_cents: amountSumCents,
|
|
543
|
+
row_count: rows.length
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
/** Decode UTF-8 document bytes (after optional gunzip) and parse summary. */
|
|
547
|
+
async function summarizeSettlementDocument(bytes, compressionAlgorithm) {
|
|
548
|
+
if (!compressionAlgorithm && bytes.byteLength > 67108864) settlementError("Settlement report body exceeds limit", "too_large");
|
|
549
|
+
const plain = await maybeGunzipReportBytes(bytes, compressionAlgorithm);
|
|
550
|
+
if (plain.byteLength > 67108864) settlementError("Settlement report body exceeds limit", "too_large");
|
|
551
|
+
return parseSettlementV2Tsv(new TextDecoder("utf-8", { fatal: false }).decode(plain));
|
|
552
|
+
}
|
|
553
|
+
/** ISO createdSince for listReports retention window. */
|
|
554
|
+
function settlementCreatedSinceIso(now = /* @__PURE__ */ new Date(), retentionDays = 90) {
|
|
555
|
+
const ms = retentionDays * 24 * 60 * 60 * 1e3;
|
|
556
|
+
return new Date(now.getTime() - ms).toISOString();
|
|
557
|
+
}
|
|
558
|
+
//#endregion
|
|
559
|
+
//#region src/vendors/amazon-sp-api/client.ts
|
|
560
|
+
/**
|
|
561
|
+
* Amazon Selling Partner API vendor client.
|
|
562
|
+
* Host: `new AmazonSpApiClient(auth)`. Agent tools: `fromContext(ctx)`.
|
|
563
|
+
*
|
|
564
|
+
* LWA refresh → access token; SP-API calls use AwsService (SigV4 execute-api)
|
|
565
|
+
* plus x-amz-access-token.
|
|
566
|
+
*/
|
|
567
|
+
var AmazonSpApiClient = class AmazonSpApiClient {
|
|
568
|
+
#auth;
|
|
569
|
+
#lwa;
|
|
570
|
+
#api;
|
|
571
|
+
/** Absolute URL document download (report document URLs). */
|
|
572
|
+
#download;
|
|
573
|
+
#accessToken;
|
|
574
|
+
#accessTokenExpiresAt = 0;
|
|
575
|
+
constructor(auth, options = {}) {
|
|
576
|
+
const parsed = amazonSpApiAuthSchema.safeParse(auth);
|
|
577
|
+
if (!parsed.success) throw new ToolError("Invalid Amazon SP-API auth credentials", {
|
|
578
|
+
code: "bad_auth",
|
|
579
|
+
details: { issues: parsed.error.issues.map((issue) => issue.message) }
|
|
580
|
+
});
|
|
581
|
+
this.#auth = parsed.data;
|
|
582
|
+
this.#lwa = new HttpService({
|
|
583
|
+
...options,
|
|
584
|
+
label: "Amazon LWA"
|
|
585
|
+
});
|
|
586
|
+
this.#api = new AwsService({
|
|
587
|
+
...options,
|
|
588
|
+
accessKeyId: this.#auth.access_key_id,
|
|
589
|
+
secretAccessKey: this.#auth.secret_access_key,
|
|
590
|
+
region: this.#auth.region,
|
|
591
|
+
service: "execute-api",
|
|
592
|
+
baseURL: this.#auth.endpoint,
|
|
593
|
+
label: "Amazon SP-API",
|
|
594
|
+
...this.#auth.session_token && { sessionToken: this.#auth.session_token }
|
|
595
|
+
});
|
|
596
|
+
this.#download = new HttpService({
|
|
597
|
+
...options,
|
|
598
|
+
label: "Amazon SP-API report download"
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
static fromContext(ctx) {
|
|
602
|
+
const auth = requireAuth(ctx, amazonSpApiAuthSchema);
|
|
603
|
+
return new AmazonSpApiClient(auth, {
|
|
604
|
+
...ctx.fetch && { fetch: ctx.fetch },
|
|
605
|
+
...ctx.signal && { signal: ctx.signal }
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
async #ensureAccessToken() {
|
|
609
|
+
const now = Date.now();
|
|
610
|
+
if (this.#accessToken && now < this.#accessTokenExpiresAt - 6e4) return this.#accessToken;
|
|
611
|
+
const { data } = await this.#lwa.post(LWA_TOKEN_URL, lwaTokenBody(this.#auth), {
|
|
612
|
+
label: "Amazon LWA token",
|
|
613
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
614
|
+
});
|
|
615
|
+
const token = parseLwaAccessToken(data);
|
|
616
|
+
this.#accessToken = token;
|
|
617
|
+
this.#accessTokenExpiresAt = now + 3e6;
|
|
618
|
+
return token;
|
|
619
|
+
}
|
|
620
|
+
async #spGet(path, label, query) {
|
|
621
|
+
const token = await this.#ensureAccessToken();
|
|
622
|
+
return this.#api.get(path, {
|
|
623
|
+
label,
|
|
624
|
+
headers: { "x-amz-access-token": token },
|
|
625
|
+
...query && { query }
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
async #spPost(path, label, body) {
|
|
629
|
+
const token = await this.#ensureAccessToken();
|
|
630
|
+
return this.#api.post(path, body, {
|
|
631
|
+
label,
|
|
632
|
+
headers: {
|
|
633
|
+
"x-amz-access-token": token,
|
|
634
|
+
"Content-Type": "application/json"
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
/** GET /orders/v0/orders */
|
|
639
|
+
async listOrders(input = {}) {
|
|
640
|
+
const marketplaceIds = requireMarketplaceIds(input.marketplace_ids, this.#auth.marketplace_ids, "Amazon SP-API listOrders");
|
|
641
|
+
const { data } = await this.#spGet("/orders/v0/orders", "Amazon SP-API listOrders", {
|
|
642
|
+
MarketplaceIds: marketplaceIds.join(","),
|
|
643
|
+
...input.created_after && { CreatedAfter: input.created_after },
|
|
644
|
+
...input.created_before && { CreatedBefore: input.created_before },
|
|
645
|
+
...input.last_updated_after && { LastUpdatedAfter: input.last_updated_after },
|
|
646
|
+
...input.order_statuses && input.order_statuses.length > 0 && { OrderStatuses: input.order_statuses.join(",") },
|
|
647
|
+
...input.cursor && { NextToken: input.cursor },
|
|
648
|
+
...input.max_results !== void 0 && { MaxResultsPerPage: input.max_results }
|
|
649
|
+
});
|
|
650
|
+
const parsed = parseOrdersPayload(data);
|
|
651
|
+
return {
|
|
652
|
+
items: parsed.items,
|
|
653
|
+
truncated: Boolean(parsed.nextToken),
|
|
654
|
+
...parsed.nextToken && { next_cursor: parsed.nextToken }
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
/** GET /orders/v0/orders/{orderId} */
|
|
658
|
+
async getOrder(input) {
|
|
659
|
+
const { data } = await this.#spGet(`/orders/v0/orders/${encodeURIComponent(input.amazon_order_id)}`, "Amazon SP-API getOrder");
|
|
660
|
+
return { order: parseOrderPayload(data) };
|
|
661
|
+
}
|
|
662
|
+
/** GET /orders/v0/orders/{orderId}/orderItems */
|
|
663
|
+
async getOrderItems(input) {
|
|
664
|
+
const query = input.cursor ? { NextToken: input.cursor } : void 0;
|
|
665
|
+
const { data } = await this.#spGet(`/orders/v0/orders/${encodeURIComponent(input.amazon_order_id)}/orderItems`, "Amazon SP-API getOrderItems", query);
|
|
666
|
+
const parsed = parseOrderItemsPayload(data);
|
|
667
|
+
return {
|
|
668
|
+
amazon_order_id: parsed.amazon_order_id,
|
|
669
|
+
items: parsed.items,
|
|
670
|
+
truncated: Boolean(parsed.nextToken),
|
|
671
|
+
...parsed.nextToken && { next_cursor: parsed.nextToken }
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* GET /orders/2026-01-01/orders (searchOrders).
|
|
676
|
+
* Always requests includedData=FULFILLMENT for fulfillmentStatus.
|
|
677
|
+
* Optional max_pages drains pages sequentially (bounded).
|
|
678
|
+
*/
|
|
679
|
+
async searchOrders(input) {
|
|
680
|
+
const marketplaceIds = requireMarketplaceIds(input.marketplace_ids, this.#auth.marketplace_ids, "Amazon SP-API searchOrders");
|
|
681
|
+
const maxPages = input.max_pages ?? 1;
|
|
682
|
+
const pageSize = input.max_results ?? 100;
|
|
683
|
+
const items = [];
|
|
684
|
+
let cursor = input.cursor;
|
|
685
|
+
let pages = 0;
|
|
686
|
+
let nextToken;
|
|
687
|
+
while (pages < maxPages) {
|
|
688
|
+
pages += 1;
|
|
689
|
+
const { data } = await this.#spGet("/orders/2026-01-01/orders", "Amazon SP-API searchOrders", {
|
|
690
|
+
createdAfter: input.created_after,
|
|
691
|
+
...input.created_before && { createdBefore: input.created_before },
|
|
692
|
+
marketplaceIds: marketplaceIds.join(","),
|
|
693
|
+
includedData: "FULFILLMENT",
|
|
694
|
+
maxResultsPerPage: pageSize,
|
|
695
|
+
...cursor && { paginationToken: cursor }
|
|
696
|
+
});
|
|
697
|
+
const parsed = parseSearchOrdersPayload(data);
|
|
698
|
+
items.push(...parsed.items);
|
|
699
|
+
nextToken = parsed.nextToken;
|
|
700
|
+
if (!nextToken) break;
|
|
701
|
+
cursor = nextToken;
|
|
702
|
+
}
|
|
703
|
+
return {
|
|
704
|
+
items,
|
|
705
|
+
truncated: Boolean(nextToken),
|
|
706
|
+
...nextToken && { next_cursor: nextToken }
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
/** GET /fba/inventory/v1/summaries */
|
|
710
|
+
async listInventorySummaries(input = {}) {
|
|
711
|
+
const marketplaceId = requireMarketplaceIds(input.marketplace_id ? [input.marketplace_id] : void 0, this.#auth.marketplace_ids, "Amazon SP-API listInventorySummaries")[0];
|
|
712
|
+
if (!marketplaceId) throw new ToolError("Amazon SP-API listInventorySummaries requires a marketplace_id", { code: "bad_input" });
|
|
713
|
+
const { data } = await this.#spGet("/fba/inventory/v1/summaries", "Amazon SP-API listInventorySummaries", {
|
|
714
|
+
details: true,
|
|
715
|
+
granularityType: "Marketplace",
|
|
716
|
+
granularityId: marketplaceId,
|
|
717
|
+
marketplaceIds: marketplaceId,
|
|
718
|
+
...input.seller_skus && input.seller_skus.length > 0 && { sellerSkus: input.seller_skus.join(",") },
|
|
719
|
+
...input.start_date_time && { startDateTime: input.start_date_time },
|
|
720
|
+
...input.cursor && { nextToken: input.cursor }
|
|
721
|
+
});
|
|
722
|
+
const parsed = parseInventoryPayload(data);
|
|
723
|
+
return {
|
|
724
|
+
items: parsed.items,
|
|
725
|
+
truncated: Boolean(parsed.nextToken),
|
|
726
|
+
...parsed.nextToken && { next_cursor: parsed.nextToken }
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
/** POST /reports/2021-06-30/reports */
|
|
730
|
+
async createReport(input) {
|
|
731
|
+
const marketplaceIds = requireMarketplaceIds(input.marketplace_ids, this.#auth.marketplace_ids, "Amazon SP-API createReport");
|
|
732
|
+
const body = {
|
|
733
|
+
reportType: input.report_type,
|
|
734
|
+
marketplaceIds,
|
|
735
|
+
...input.data_start_time && { dataStartTime: input.data_start_time },
|
|
736
|
+
...input.data_end_time && { dataEndTime: input.data_end_time },
|
|
737
|
+
...input.report_options && { reportOptions: input.report_options }
|
|
738
|
+
};
|
|
739
|
+
const { data } = await this.#spPost("/reports/2021-06-30/reports", "Amazon SP-API createReport", body);
|
|
740
|
+
return parseCreateReportPayload(data);
|
|
741
|
+
}
|
|
742
|
+
/** GET /reports/2021-06-30/reports/{reportId} */
|
|
743
|
+
async getReport(input) {
|
|
744
|
+
const { data } = await this.#spGet(`/reports/2021-06-30/reports/${encodeURIComponent(input.report_id)}`, "Amazon SP-API getReport");
|
|
745
|
+
return { report: parseGetReportPayload(data) };
|
|
746
|
+
}
|
|
747
|
+
/** GET /reports/2021-06-30/reports */
|
|
748
|
+
async listReports(input = {}) {
|
|
749
|
+
const marketplaceIds = input.marketplace_ids ?? this.#auth.marketplace_ids;
|
|
750
|
+
const { data } = await this.#spGet("/reports/2021-06-30/reports", "Amazon SP-API listReports", {
|
|
751
|
+
...input.report_types && input.report_types.length > 0 && { reportTypes: input.report_types.join(",") },
|
|
752
|
+
...input.processing_statuses && input.processing_statuses.length > 0 && { processingStatuses: input.processing_statuses.join(",") },
|
|
753
|
+
...marketplaceIds && marketplaceIds.length > 0 && { marketplaceIds: marketplaceIds.join(",") },
|
|
754
|
+
...input.page_size !== void 0 && { pageSize: input.page_size },
|
|
755
|
+
...input.created_since && { createdSince: input.created_since },
|
|
756
|
+
...input.created_until && { createdUntil: input.created_until },
|
|
757
|
+
...input.cursor && { nextToken: input.cursor }
|
|
758
|
+
});
|
|
759
|
+
const parsed = parseListReportsPayload(data);
|
|
760
|
+
return {
|
|
761
|
+
items: parsed.items,
|
|
762
|
+
truncated: Boolean(parsed.nextToken),
|
|
763
|
+
...parsed.nextToken && { next_cursor: parsed.nextToken }
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
/** GET /reports/2021-06-30/documents/{reportDocumentId} */
|
|
767
|
+
async getReportDocument(input) {
|
|
768
|
+
const { data } = await this.#spGet(`/reports/2021-06-30/documents/${encodeURIComponent(input.report_document_id)}`, "Amazon SP-API getReportDocument");
|
|
769
|
+
return parseReportDocumentPayload(data);
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Composite: newest DONE Flat File V2 settlement report (or `report_id`) →
|
|
773
|
+
* one document download → eight summary fields in safe integer cents.
|
|
774
|
+
* Never returns raw TSV rows, order ids, skus, or document URLs.
|
|
775
|
+
*/
|
|
776
|
+
async getSettlementSummary(input = {}) {
|
|
777
|
+
const reportDocumentId = await this.#resolveSettlementReportDocumentId(input);
|
|
778
|
+
const doc = await this.getReportDocument({ report_document_id: reportDocumentId });
|
|
779
|
+
const { bytes } = await this.#download.bytes("GET", doc.url, {
|
|
780
|
+
label: "Amazon SP-API settlement document",
|
|
781
|
+
maxBytes: SETTLEMENT_MAX_COMPRESSED_BYTES
|
|
782
|
+
});
|
|
783
|
+
return await summarizeSettlementDocument(bytes, doc.compression_algorithm);
|
|
784
|
+
}
|
|
785
|
+
async #resolveSettlementReportDocumentId(input) {
|
|
786
|
+
if (input.report_id) {
|
|
787
|
+
const { report } = await this.getReport({ report_id: input.report_id });
|
|
788
|
+
if (report.processing_status && report.processing_status !== "DONE") throw new ToolError("Settlement report is not DONE", {
|
|
789
|
+
code: "bad_input",
|
|
790
|
+
details: { processing_status: report.processing_status }
|
|
791
|
+
});
|
|
792
|
+
if (!report.report_document_id) throw new ToolError("Settlement report has no document id", { code: "upstream" });
|
|
793
|
+
return report.report_document_id;
|
|
794
|
+
}
|
|
795
|
+
const createdSince = input.created_since ?? settlementCreatedSinceIso();
|
|
796
|
+
let cursor;
|
|
797
|
+
for (let page = 0; page < 5; page += 1) {
|
|
798
|
+
const listed = await this.listReports({
|
|
799
|
+
report_types: [SETTLEMENT_REPORT_TYPE_V2],
|
|
800
|
+
processing_statuses: ["DONE"],
|
|
801
|
+
created_since: createdSince,
|
|
802
|
+
page_size: 100,
|
|
803
|
+
...cursor && { cursor }
|
|
804
|
+
});
|
|
805
|
+
for (const report of listed.items) if (report.report_document_id) return report.report_document_id;
|
|
806
|
+
if (!listed.next_cursor) break;
|
|
807
|
+
cursor = listed.next_cursor;
|
|
808
|
+
}
|
|
809
|
+
throw new ToolError("No completed settlement report found in the retention window", { code: "not_found" });
|
|
810
|
+
}
|
|
811
|
+
/** GET /catalog/2022-04-01/items */
|
|
812
|
+
async searchCatalogItems(input) {
|
|
813
|
+
const marketplaceIds = requireMarketplaceIds(input.marketplace_ids, this.#auth.marketplace_ids, "Amazon SP-API searchCatalogItems");
|
|
814
|
+
const { data } = await this.#spGet("/catalog/2022-04-01/items", "Amazon SP-API searchCatalogItems", {
|
|
815
|
+
keywords: input.keywords.join(","),
|
|
816
|
+
marketplaceIds: marketplaceIds.join(","),
|
|
817
|
+
...input.included_data && input.included_data.length > 0 && { includedData: input.included_data.join(",") },
|
|
818
|
+
...input.page_size !== void 0 && { pageSize: input.page_size },
|
|
819
|
+
...input.cursor && { pageToken: input.cursor }
|
|
820
|
+
});
|
|
821
|
+
const parsed = parseSearchCatalogItemsPayload(data);
|
|
822
|
+
return {
|
|
823
|
+
items: parsed.items,
|
|
824
|
+
truncated: Boolean(parsed.nextToken),
|
|
825
|
+
...parsed.numberOfResults !== void 0 && { number_of_results: parsed.numberOfResults },
|
|
826
|
+
...parsed.nextToken && { next_cursor: parsed.nextToken }
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
//#endregion
|
|
831
|
+
//#region src/vendors/amazon-sp-api/module.ts
|
|
832
|
+
const amazonSpApiListOrdersTool = defineTool({
|
|
833
|
+
id: "amazon-sp-api-list-orders",
|
|
834
|
+
name: "amazonSpApiListOrders",
|
|
835
|
+
description: "List Amazon SP-API orders for one or more marketplaces. Optional date and status filters. Paginate with next_cursor (NextToken).",
|
|
836
|
+
inputSchema: amazonSpApiListOrdersInputSchema,
|
|
837
|
+
outputSchema: amazonSpApiListOrdersOutputSchema,
|
|
838
|
+
sideEffect: "read",
|
|
839
|
+
runtime: "both",
|
|
840
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).listOrders(input)
|
|
841
|
+
});
|
|
842
|
+
const amazonSpApiGetOrderTool = defineTool({
|
|
843
|
+
id: "amazon-sp-api-get-order",
|
|
844
|
+
name: "amazonSpApiGetOrder",
|
|
845
|
+
description: "Get one Amazon SP-API order by AmazonOrderId.",
|
|
846
|
+
inputSchema: amazonSpApiGetOrderInputSchema,
|
|
847
|
+
outputSchema: amazonSpApiGetOrderOutputSchema,
|
|
848
|
+
sideEffect: "read",
|
|
849
|
+
runtime: "both",
|
|
850
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).getOrder(input)
|
|
851
|
+
});
|
|
852
|
+
const amazonSpApiGetOrderItemsTool = defineTool({
|
|
853
|
+
id: "amazon-sp-api-get-order-items",
|
|
854
|
+
name: "amazonSpApiGetOrderItems",
|
|
855
|
+
description: "List line items for one Amazon SP-API order. Paginate with next_cursor (NextToken).",
|
|
856
|
+
inputSchema: amazonSpApiGetOrderItemsInputSchema,
|
|
857
|
+
outputSchema: amazonSpApiGetOrderItemsOutputSchema,
|
|
858
|
+
sideEffect: "read",
|
|
859
|
+
runtime: "both",
|
|
860
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).getOrderItems(input)
|
|
861
|
+
});
|
|
862
|
+
const amazonSpApiSearchOrdersTool = defineTool({
|
|
863
|
+
id: "amazon-sp-api-search-orders",
|
|
864
|
+
name: "amazonSpApiSearchOrders",
|
|
865
|
+
description: "Search Amazon orders via Orders API v2026-01-01 (searchOrders). Filter by created_after (required) and optional created_before. Always includes FULFILLMENT data for fulfillment_status. Optional max_pages drains pages sequentially (max 50). Paginate with next_cursor when truncated.",
|
|
866
|
+
inputSchema: amazonSpApiSearchOrdersInputSchema,
|
|
867
|
+
outputSchema: amazonSpApiSearchOrdersOutputSchema,
|
|
868
|
+
sideEffect: "read",
|
|
869
|
+
runtime: "both",
|
|
870
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).searchOrders(input)
|
|
871
|
+
});
|
|
872
|
+
const amazonSpApiListInventorySummariesTool = defineTool({
|
|
873
|
+
id: "amazon-sp-api-list-inventory-summaries",
|
|
874
|
+
name: "amazonSpApiListInventorySummaries",
|
|
875
|
+
description: "List FBA inventory summaries for a marketplace. Optional seller SKUs and start_date_time. Paginate with next_cursor.",
|
|
876
|
+
inputSchema: amazonSpApiListInventorySummariesInputSchema,
|
|
877
|
+
outputSchema: amazonSpApiListInventorySummariesOutputSchema,
|
|
878
|
+
sideEffect: "read",
|
|
879
|
+
runtime: "both",
|
|
880
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).listInventorySummaries(input)
|
|
881
|
+
});
|
|
882
|
+
const amazonSpApiCreateReportTool = defineTool({
|
|
883
|
+
id: "amazon-sp-api-create-report",
|
|
884
|
+
name: "amazonSpApiCreateReport",
|
|
885
|
+
description: "Request an Amazon SP-API report for given marketplace(s) and optional date range. Returns report_id for later getReport polling.",
|
|
886
|
+
inputSchema: amazonSpApiCreateReportInputSchema,
|
|
887
|
+
outputSchema: amazonSpApiCreateReportOutputSchema,
|
|
888
|
+
sideEffect: "write",
|
|
889
|
+
runtime: "both",
|
|
890
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).createReport(input)
|
|
891
|
+
});
|
|
892
|
+
const amazonSpApiGetReportTool = defineTool({
|
|
893
|
+
id: "amazon-sp-api-get-report",
|
|
894
|
+
name: "amazonSpApiGetReport",
|
|
895
|
+
description: "Get one Amazon SP-API report by report_id, including processing_status and report_document_id when DONE.",
|
|
896
|
+
inputSchema: amazonSpApiGetReportInputSchema,
|
|
897
|
+
outputSchema: amazonSpApiGetReportOutputSchema,
|
|
898
|
+
sideEffect: "read",
|
|
899
|
+
runtime: "both",
|
|
900
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).getReport(input)
|
|
901
|
+
});
|
|
902
|
+
const amazonSpApiListReportsTool = defineTool({
|
|
903
|
+
id: "amazon-sp-api-list-reports",
|
|
904
|
+
name: "amazonSpApiListReports",
|
|
905
|
+
description: "List Amazon SP-API reports with optional type, status, marketplace, and created-time filters. Paginate with next_cursor.",
|
|
906
|
+
inputSchema: amazonSpApiListReportsInputSchema,
|
|
907
|
+
outputSchema: amazonSpApiListReportsOutputSchema,
|
|
908
|
+
sideEffect: "read",
|
|
909
|
+
runtime: "both",
|
|
910
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).listReports(input)
|
|
911
|
+
});
|
|
912
|
+
const amazonSpApiGetReportDocumentTool = defineTool({
|
|
913
|
+
id: "amazon-sp-api-get-report-document",
|
|
914
|
+
name: "amazonSpApiGetReportDocument",
|
|
915
|
+
description: "Get a downloadable Amazon SP-API report document (document_id, url, optional compression_algorithm). Does not download the file body.",
|
|
916
|
+
inputSchema: amazonSpApiGetReportDocumentInputSchema,
|
|
917
|
+
outputSchema: amazonSpApiGetReportDocumentOutputSchema,
|
|
918
|
+
sideEffect: "read",
|
|
919
|
+
runtime: "both",
|
|
920
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).getReportDocument(input)
|
|
921
|
+
});
|
|
922
|
+
const amazonSpApiSearchCatalogItemsTool = defineTool({
|
|
923
|
+
id: "amazon-sp-api-search-catalog-items",
|
|
924
|
+
name: "amazonSpApiSearchCatalogItems",
|
|
925
|
+
description: "Search Amazon catalog items by keywords for marketplace(s). Optional included_data and page_size. Paginate with next_cursor (pageToken).",
|
|
926
|
+
inputSchema: amazonSpApiSearchCatalogItemsInputSchema,
|
|
927
|
+
outputSchema: amazonSpApiSearchCatalogItemsOutputSchema,
|
|
928
|
+
sideEffect: "read",
|
|
929
|
+
runtime: "both",
|
|
930
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).searchCatalogItems(input)
|
|
931
|
+
});
|
|
932
|
+
const amazonSpApiGetSettlementSummaryTool = defineTool({
|
|
933
|
+
id: "amazon-sp-api-get-settlement-summary",
|
|
934
|
+
name: "amazonSpApiGetSettlementSummary",
|
|
935
|
+
description: "Summarize the newest completed Amazon Flat File V2 settlement report (or a specific report_id): downloads one document, validates the TSV, and returns eight summary fields in integer cents (settlement id, period, deposit date, currency, total and amount sum, row count). Does not return line-level order or SKU data. Optional created_since (default last 90 days when listing).",
|
|
936
|
+
inputSchema: amazonSpApiGetSettlementSummaryInputSchema,
|
|
937
|
+
outputSchema: amazonSpApiGetSettlementSummaryOutputSchema,
|
|
938
|
+
sideEffect: "read",
|
|
939
|
+
runtime: "both",
|
|
940
|
+
execute: async (input, ctx) => AmazonSpApiClient.fromContext(ctx).getSettlementSummary(input)
|
|
941
|
+
});
|
|
942
|
+
const amazonSpApiModule = defineModule({
|
|
943
|
+
id: "amazon-sp-api",
|
|
944
|
+
title: "Amazon SP-API",
|
|
945
|
+
description: "Amazon Selling Partner API vendor pack: orders v0 and SearchOrders v2026, order items, FBA inventory summaries, reports (create/get/list/document), settlement V2 summary, and catalog item search.",
|
|
946
|
+
runtime: "both",
|
|
947
|
+
auth: {
|
|
948
|
+
type: "custom",
|
|
949
|
+
schema: amazonSpApiAuthSchema
|
|
950
|
+
},
|
|
951
|
+
categories: ["commerce", "amazon"],
|
|
952
|
+
classification: "pii",
|
|
953
|
+
tags: [
|
|
954
|
+
"orders",
|
|
955
|
+
"fba",
|
|
956
|
+
"reports"
|
|
957
|
+
],
|
|
958
|
+
tools: [
|
|
959
|
+
amazonSpApiListOrdersTool,
|
|
960
|
+
amazonSpApiGetOrderTool,
|
|
961
|
+
amazonSpApiGetOrderItemsTool,
|
|
962
|
+
amazonSpApiSearchOrdersTool,
|
|
963
|
+
amazonSpApiListInventorySummariesTool,
|
|
964
|
+
amazonSpApiCreateReportTool,
|
|
965
|
+
amazonSpApiGetReportTool,
|
|
966
|
+
amazonSpApiListReportsTool,
|
|
967
|
+
amazonSpApiGetReportDocumentTool,
|
|
968
|
+
amazonSpApiGetSettlementSummaryTool,
|
|
969
|
+
amazonSpApiSearchCatalogItemsTool
|
|
970
|
+
]
|
|
971
|
+
});
|
|
972
|
+
//#endregion
|
|
973
|
+
export { AmazonSpApiClient, amazonSpApiAuthSchema, amazonSpApiCatalogItemSchema, amazonSpApiCreateReportInputSchema, amazonSpApiCreateReportOutputSchema, amazonSpApiCreateReportTool, amazonSpApiEndpointSchema, amazonSpApiGetOrderInputSchema, amazonSpApiGetOrderItemsInputSchema, amazonSpApiGetOrderItemsOutputSchema, amazonSpApiGetOrderItemsTool, amazonSpApiGetOrderOutputSchema, amazonSpApiGetOrderTool, amazonSpApiGetReportDocumentInputSchema, amazonSpApiGetReportDocumentOutputSchema, amazonSpApiGetReportDocumentTool, amazonSpApiGetReportInputSchema, amazonSpApiGetReportOutputSchema, amazonSpApiGetReportTool, amazonSpApiGetSettlementSummaryInputSchema, amazonSpApiGetSettlementSummaryOutputSchema, amazonSpApiGetSettlementSummaryTool, amazonSpApiInventorySummarySchema, amazonSpApiListInventorySummariesInputSchema, amazonSpApiListInventorySummariesOutputSchema, amazonSpApiListInventorySummariesTool, amazonSpApiListOrdersInputSchema, amazonSpApiListOrdersOutputSchema, amazonSpApiListOrdersTool, amazonSpApiListReportsInputSchema, amazonSpApiListReportsOutputSchema, amazonSpApiListReportsTool, amazonSpApiModule, amazonSpApiOrderItemSchema, amazonSpApiOrderSchema, amazonSpApiReportSchema, amazonSpApiSearchCatalogItemsInputSchema, amazonSpApiSearchCatalogItemsOutputSchema, amazonSpApiSearchCatalogItemsTool, amazonSpApiSearchOrderSchema, amazonSpApiSearchOrdersInputSchema, amazonSpApiSearchOrdersOutputSchema, amazonSpApiSearchOrdersTool, amazonSpApiSettlementSummarySchema };
|
|
974
|
+
|
|
975
|
+
//# sourceMappingURL=index.js.map
|