@amazon-sp-api-release/dev-mcp 0.0.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.
Files changed (47) hide show
  1. package/README.md +82 -0
  2. package/dist/auth/sp-api-auth.d.ts +17 -0
  3. package/dist/auth/sp-api-auth.d.ts.map +1 -0
  4. package/dist/auth/sp-api-auth.js +55 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +96 -0
  8. package/dist/tools/api-tools/orders-api-tools.d.ts +103 -0
  9. package/dist/tools/api-tools/orders-api-tools.d.ts.map +1 -0
  10. package/dist/tools/api-tools/orders-api-tools.js +459 -0
  11. package/dist/tools/migration-assistant-tools/migration-tools.d.ts +21 -0
  12. package/dist/tools/migration-assistant-tools/migration-tools.d.ts.map +1 -0
  13. package/dist/tools/migration-assistant-tools/migration-tools.js +82 -0
  14. package/dist/tools/migration-assistant-tools/orders-api-migration/code-analyzer.d.ts +19 -0
  15. package/dist/tools/migration-assistant-tools/orders-api-migration/code-analyzer.d.ts.map +1 -0
  16. package/dist/tools/migration-assistant-tools/orders-api-migration/code-analyzer.js +52 -0
  17. package/dist/tools/migration-assistant-tools/orders-api-migration/code-generator.d.ts +3 -0
  18. package/dist/tools/migration-assistant-tools/orders-api-migration/code-generator.d.ts.map +1 -0
  19. package/dist/tools/migration-assistant-tools/orders-api-migration/code-generator.js +45 -0
  20. package/dist/tools/migration-assistant-tools/orders-api-migration/guidance-formatter.d.ts +3 -0
  21. package/dist/tools/migration-assistant-tools/orders-api-migration/guidance-formatter.d.ts.map +1 -0
  22. package/dist/tools/migration-assistant-tools/orders-api-migration/guidance-formatter.js +134 -0
  23. package/dist/tools/migration-assistant-tools/orders-api-migration/migration-data.d.ts +13 -0
  24. package/dist/tools/migration-assistant-tools/orders-api-migration/migration-data.d.ts.map +1 -0
  25. package/dist/tools/migration-assistant-tools/orders-api-migration/migration-data.js +181 -0
  26. package/dist/tools/migration-assistant-tools/orders-api-migration/report-formatter.d.ts +5 -0
  27. package/dist/tools/migration-assistant-tools/orders-api-migration/report-formatter.d.ts.map +1 -0
  28. package/dist/tools/migration-assistant-tools/orders-api-migration/report-formatter.js +64 -0
  29. package/dist/zod-schemas/migration-schemas.d.ts +24 -0
  30. package/dist/zod-schemas/migration-schemas.d.ts.map +1 -0
  31. package/dist/zod-schemas/migration-schemas.js +24 -0
  32. package/dist/zod-schemas/orders-schemas.d.ts +291 -0
  33. package/dist/zod-schemas/orders-schemas.d.ts.map +1 -0
  34. package/dist/zod-schemas/orders-schemas.js +178 -0
  35. package/package.json +66 -0
  36. package/src/auth/sp-api-auth.ts +88 -0
  37. package/src/index.ts +168 -0
  38. package/src/tools/api-tools/orders-api-tools.ts +684 -0
  39. package/src/tools/migration-assistant-tools/migration-tools.ts +143 -0
  40. package/src/tools/migration-assistant-tools/orders-api-migration/code-analyzer.ts +72 -0
  41. package/src/tools/migration-assistant-tools/orders-api-migration/code-generator.ts +64 -0
  42. package/src/tools/migration-assistant-tools/orders-api-migration/guidance-formatter.ts +154 -0
  43. package/src/tools/migration-assistant-tools/orders-api-migration/migration-data.ts +221 -0
  44. package/src/tools/migration-assistant-tools/orders-api-migration/report-formatter.ts +85 -0
  45. package/src/utils/logger.ts +75 -0
  46. package/src/zod-schemas/migration-schemas.ts +28 -0
  47. package/src/zod-schemas/orders-schemas.ts +196 -0
@@ -0,0 +1,684 @@
1
+ import { SPAPIAuth } from "../../auth/sp-api-auth.js";
2
+
3
+ // Type Definitions
4
+ export interface SPAPIConfig {
5
+ clientId?: string;
6
+ clientSecret?: string;
7
+ refreshToken?: string;
8
+ baseUrl?: string;
9
+ }
10
+
11
+ export interface SearchOrdersArgs {
12
+ createdAfter?: string;
13
+ createdBefore?: string;
14
+ lastUpdatedAfter?: string;
15
+ lastUpdatedBefore?: string;
16
+ fulfillmentStatuses?: Array<
17
+ | "PENDING"
18
+ | "UNSHIPPED"
19
+ | "PARTIALLY_SHIPPED"
20
+ | "SHIPPED"
21
+ | "CANCELLED"
22
+ | "UNFULFILLABLE"
23
+ >;
24
+ marketplaceIds?: string[];
25
+ fulfilledBy?: Array<"AMAZON" | "MERCHANT">;
26
+ maxResultsPerPage?: number;
27
+ includedData?: Array<
28
+ | "BUYER"
29
+ | "RECIPIENT"
30
+ | "PROCEEDS"
31
+ | "EXPENSE"
32
+ | "PROMOTION"
33
+ | "CANCELLATION"
34
+ | "FULFILLMENT"
35
+ | "PACKAGES"
36
+ >;
37
+ paginationToken?: string;
38
+ }
39
+
40
+ export interface GetOrderArgs {
41
+ orderId: string;
42
+ includedData?: Array<
43
+ | "BUYER"
44
+ | "RECIPIENT"
45
+ | "PROCEEDS"
46
+ | "EXPENSE"
47
+ | "PROMOTION"
48
+ | "CANCELLATION"
49
+ | "FULFILLMENT"
50
+ | "PACKAGES"
51
+ >;
52
+ }
53
+
54
+ export interface CancelOrderArgs {
55
+ orderId: string;
56
+ cancelReasonCode:
57
+ | "NO_INVENTORY"
58
+ | "BUYER_CANCELLED"
59
+ | "SHIPPING_ADDRESS_UNDELIVERABLE"
60
+ | "CUSTOMER_EXCHANGE"
61
+ | "PRICING_ERROR";
62
+ }
63
+
64
+ // V0 API Args
65
+ export interface UpdateShipmentStatusArgs {
66
+ orderId: string;
67
+ marketplaceId: string;
68
+ shipmentStatus: "ReadyForPickup" | "PickedUp" | "RefusedPickup";
69
+ orderItems?: Array<{
70
+ orderItemId?: string;
71
+ quantity?: number;
72
+ }>;
73
+ }
74
+
75
+ export interface UpdateVerificationStatusArgs {
76
+ orderId: string;
77
+ marketplaceId: string;
78
+ regulatedOrderVerificationStatus: {
79
+ status: "Approved" | "Rejected" | "Expired" | "Cancelled";
80
+ validUntil?: string;
81
+ rejectionReason?: {
82
+ rejectionReasonId: string;
83
+ rejectionReasonDescription: string;
84
+ };
85
+ };
86
+ }
87
+
88
+ export interface ConfirmShipmentArgs {
89
+ orderId: string;
90
+ marketplaceId: string;
91
+ packageDetail: {
92
+ packageReferenceId: string;
93
+ carrierCode: string;
94
+ shippingMethod?: string;
95
+ trackingNumber?: string;
96
+ shipDate: string;
97
+ carrierName?: string;
98
+ shipFrom?: {
99
+ name: string;
100
+ addressLine1: string;
101
+ addressLine2?: string;
102
+ addressLine3?: string;
103
+ city: string;
104
+ county?: string;
105
+ district?: string;
106
+ stateOrRegion: string;
107
+ postalCode: string;
108
+ countryCode: string;
109
+ phone: string;
110
+ };
111
+ };
112
+ codCollectionMethod?: "DirectPayment";
113
+ }
114
+
115
+ export interface GetOrderRegulatedInfoArgs {
116
+ orderId: string;
117
+ }
118
+
119
+ export interface ToolResponse {
120
+ content: Array<{
121
+ type: "text";
122
+ text: string;
123
+ meta?: Record<string, unknown>;
124
+ }>;
125
+ isError?: boolean;
126
+ [key: string]: unknown;
127
+ }
128
+
129
+ export class OrdersApiTool {
130
+ private config: SPAPIConfig;
131
+ private auth?: SPAPIAuth;
132
+ private hasCredentials: boolean;
133
+
134
+ constructor(config?: SPAPIConfig) {
135
+ this.config = {
136
+ ...config,
137
+ baseUrl: config?.baseUrl || "https://sellingpartnerapi-na.amazon.com",
138
+ };
139
+
140
+ this.hasCredentials = !!(
141
+ this.config.clientId &&
142
+ this.config.clientSecret &&
143
+ this.config.refreshToken
144
+ );
145
+
146
+ if (this.hasCredentials) {
147
+ this.auth = new SPAPIAuth(this.config);
148
+ }
149
+ }
150
+
151
+ private checkCredentials(): ToolResponse | null {
152
+ if (!this.hasCredentials) {
153
+ return {
154
+ content: [
155
+ {
156
+ type: "text",
157
+ text: `āŒ **SP-API Credentials Required**
158
+
159
+ To use this tool, you need to provide SP-API credentials
160
+
161
+ **Environment variables**:
162
+ \`\`\`bash
163
+ export SP_API_CLIENT_ID="your_client_id"
164
+ export SP_API_CLIENT_SECRET="your_client_secret"
165
+ export SP_API_REFRESH_TOKEN="your_refresh_token"
166
+ export SP_API_BASE_URL="https://sellingpartnerapi-na.amazon.com"
167
+ \`\`\`
168
+
169
+ **Note:** The migration assistant tool does not require credentials and can be used without API access.`,
170
+ },
171
+ ],
172
+ isError: true,
173
+ };
174
+ }
175
+ return null;
176
+ }
177
+
178
+ async searchOrders(args: SearchOrdersArgs): Promise<ToolResponse> {
179
+ const credentialError = this.checkCredentials();
180
+ if (credentialError) return credentialError;
181
+
182
+ const {
183
+ createdAfter,
184
+ createdBefore,
185
+ lastUpdatedAfter,
186
+ lastUpdatedBefore,
187
+ fulfillmentStatuses,
188
+ marketplaceIds = ["ATVPDKIKX0DER"],
189
+ fulfilledBy,
190
+ maxResultsPerPage = 50,
191
+ includedData = [],
192
+ paginationToken,
193
+ } = args;
194
+
195
+ // Validate date parameters
196
+ if (!createdAfter && !lastUpdatedAfter) {
197
+ return {
198
+ content: [
199
+ {
200
+ type: "text",
201
+ text: "Error: Either createdAfter or lastUpdatedAfter must be provided",
202
+ },
203
+ ],
204
+ isError: true,
205
+ };
206
+ }
207
+
208
+ const queryParams: Record<string, string> = {
209
+ marketplaceIds: marketplaceIds.join(","),
210
+ maxResultsPerPage: maxResultsPerPage.toString(),
211
+ };
212
+
213
+ if (createdAfter) queryParams.createdAfter = createdAfter;
214
+ if (createdBefore) queryParams.createdBefore = createdBefore;
215
+ if (lastUpdatedAfter) queryParams.lastUpdatedAfter = lastUpdatedAfter;
216
+ if (lastUpdatedBefore) queryParams.lastUpdatedBefore = lastUpdatedBefore;
217
+ if (fulfillmentStatuses && fulfillmentStatuses.length > 0) {
218
+ queryParams.fulfillmentStatuses = fulfillmentStatuses.join(",");
219
+ }
220
+ if (fulfilledBy && fulfilledBy.length > 0) {
221
+ queryParams.fulfilledBy = fulfilledBy.join(",");
222
+ }
223
+ if (includedData.length > 0) {
224
+ queryParams.includedData = includedData.join(",");
225
+ }
226
+ if (paginationToken) {
227
+ queryParams.paginationToken = paginationToken;
228
+ }
229
+
230
+ try {
231
+ const response = await this.auth!.makeAuthenticatedRequest(
232
+ "GET",
233
+ `${this.config.baseUrl}/orders/2026-01-01/orders`,
234
+ queryParams,
235
+ );
236
+
237
+ return {
238
+ content: [
239
+ {
240
+ type: "text",
241
+ text: this.formatOrdersResponse(response.data),
242
+ },
243
+ ],
244
+ };
245
+ } catch (error: any) {
246
+ return {
247
+ content: [
248
+ {
249
+ type: "text",
250
+ text: `Error: ${error.message}`,
251
+ },
252
+ ],
253
+ isError: true,
254
+ };
255
+ }
256
+ }
257
+
258
+ async getOrder(args: GetOrderArgs): Promise<ToolResponse> {
259
+ const credentialError = this.checkCredentials();
260
+ if (credentialError) return credentialError;
261
+
262
+ const { orderId, includedData = [] } = args;
263
+
264
+ const queryParams: Record<string, string> = {};
265
+ if (includedData.length > 0) {
266
+ queryParams.includedData = includedData.join(",");
267
+ }
268
+
269
+ try {
270
+ const response = await this.auth!.makeAuthenticatedRequest(
271
+ "GET",
272
+ `${this.config.baseUrl}/orders/2026-01-01/orders/${orderId}`,
273
+ queryParams,
274
+ );
275
+
276
+ return {
277
+ content: [
278
+ {
279
+ type: "text",
280
+ text: this.formatOrderResponse(response.data.order),
281
+ },
282
+ ],
283
+ };
284
+ } catch (error: any) {
285
+ return {
286
+ content: [
287
+ {
288
+ type: "text",
289
+ text: `Error: ${error.message}`,
290
+ },
291
+ ],
292
+ isError: true,
293
+ };
294
+ }
295
+ }
296
+
297
+ async cancelOrder(args: CancelOrderArgs): Promise<ToolResponse> {
298
+ const credentialError = this.checkCredentials();
299
+ if (credentialError) return credentialError;
300
+
301
+ const { orderId, cancelReasonCode } = args;
302
+
303
+ const requestBody = {
304
+ cancelReasonCode: cancelReasonCode,
305
+ };
306
+
307
+ try {
308
+ await this.auth!.makeAuthenticatedRequest(
309
+ "PUT",
310
+ `${this.config.baseUrl}/orders/2026-01-01/orders/${orderId}/cancellation`,
311
+ {},
312
+ requestBody,
313
+ );
314
+
315
+ return {
316
+ content: [
317
+ {
318
+ type: "text",
319
+ text: `āœ… Order cancellation request accepted for order ${orderId}. The cancellation process is underway.`,
320
+ },
321
+ ],
322
+ };
323
+ } catch (error: any) {
324
+ return {
325
+ content: [
326
+ {
327
+ type: "text",
328
+ text: `Error: ${error.message}`,
329
+ },
330
+ ],
331
+ isError: true,
332
+ };
333
+ }
334
+ }
335
+
336
+ // V0 APIs
337
+ async updateShipmentStatus(
338
+ args: UpdateShipmentStatusArgs,
339
+ ): Promise<ToolResponse> {
340
+ const credentialError = this.checkCredentials();
341
+ if (credentialError) return credentialError;
342
+
343
+ const { orderId, marketplaceId, shipmentStatus, orderItems } = args;
344
+
345
+ const requestBody: any = {
346
+ marketplaceId,
347
+ shipmentStatus,
348
+ };
349
+
350
+ if (orderItems && orderItems.length > 0) {
351
+ requestBody.orderItems = orderItems;
352
+ }
353
+
354
+ try {
355
+ const response = await this.auth!.makeAuthenticatedRequest(
356
+ "POST",
357
+ `${this.config.baseUrl}/orders/v0/orders/${orderId}/shipment`,
358
+ {},
359
+ requestBody,
360
+ );
361
+
362
+ return {
363
+ content: [
364
+ {
365
+ type: "text",
366
+ text: `āœ… Shipment status updated successfully for order ${orderId}.\n\nResponse: ${JSON.stringify(response.data, null, 2)}`,
367
+ },
368
+ ],
369
+ };
370
+ } catch (error: any) {
371
+ return {
372
+ content: [
373
+ {
374
+ type: "text",
375
+ text: `Error updating shipment status: ${error.message}`,
376
+ },
377
+ ],
378
+ isError: true,
379
+ };
380
+ }
381
+ }
382
+
383
+ async updateVerificationStatus(
384
+ args: UpdateVerificationStatusArgs,
385
+ ): Promise<ToolResponse> {
386
+ const credentialError = this.checkCredentials();
387
+ if (credentialError) return credentialError;
388
+
389
+ const { orderId, marketplaceId, regulatedOrderVerificationStatus } = args;
390
+
391
+ const requestBody = {
392
+ marketplaceId,
393
+ regulatedOrderVerificationStatus,
394
+ };
395
+
396
+ try {
397
+ const response = await this.auth!.makeAuthenticatedRequest(
398
+ "PATCH",
399
+ `${this.config.baseUrl}/orders/v0/orders/${orderId}/regulatedInfo`,
400
+ {},
401
+ requestBody,
402
+ );
403
+
404
+ return {
405
+ content: [
406
+ {
407
+ type: "text",
408
+ text: `āœ… Verification status updated successfully for order ${orderId}.\n\nResponse: ${JSON.stringify(response.data, null, 2)}`,
409
+ },
410
+ ],
411
+ };
412
+ } catch (error: any) {
413
+ return {
414
+ content: [
415
+ {
416
+ type: "text",
417
+ text: `Error updating verification status: ${error.message}`,
418
+ },
419
+ ],
420
+ isError: true,
421
+ };
422
+ }
423
+ }
424
+
425
+ async confirmShipment(args: ConfirmShipmentArgs): Promise<ToolResponse> {
426
+ const credentialError = this.checkCredentials();
427
+ if (credentialError) return credentialError;
428
+
429
+ const { orderId, marketplaceId, packageDetail, codCollectionMethod } = args;
430
+
431
+ const requestBody: any = {
432
+ marketplaceId,
433
+ packageDetail,
434
+ };
435
+
436
+ if (codCollectionMethod) {
437
+ requestBody.codCollectionMethod = codCollectionMethod;
438
+ }
439
+
440
+ try {
441
+ const response = await this.auth!.makeAuthenticatedRequest(
442
+ "POST",
443
+ `${this.config.baseUrl}/orders/v0/orders/${orderId}/shipmentConfirmation`,
444
+ {},
445
+ requestBody,
446
+ );
447
+
448
+ return {
449
+ content: [
450
+ {
451
+ type: "text",
452
+ text: `āœ… Shipment confirmed successfully for order ${orderId}.\n\nResponse: ${JSON.stringify(response.data, null, 2)}`,
453
+ },
454
+ ],
455
+ };
456
+ } catch (error: any) {
457
+ return {
458
+ content: [
459
+ {
460
+ type: "text",
461
+ text: `Error confirming shipment: ${error.message}`,
462
+ },
463
+ ],
464
+ isError: true,
465
+ };
466
+ }
467
+ }
468
+
469
+ async getOrderRegulatedInfo(
470
+ args: GetOrderRegulatedInfoArgs,
471
+ ): Promise<ToolResponse> {
472
+ const credentialError = this.checkCredentials();
473
+ if (credentialError) return credentialError;
474
+
475
+ const { orderId } = args;
476
+
477
+ try {
478
+ const response = await this.auth!.makeAuthenticatedRequest(
479
+ "GET",
480
+ `${this.config.baseUrl}/orders/v0/orders/${orderId}/regulatedInfo`,
481
+ {},
482
+ );
483
+
484
+ return {
485
+ content: [
486
+ {
487
+ type: "text",
488
+ text: this.formatRegulatedInfoResponse(response.data),
489
+ },
490
+ ],
491
+ };
492
+ } catch (error: any) {
493
+ return {
494
+ content: [
495
+ {
496
+ type: "text",
497
+ text: `Error getting regulated info: ${error.message}`,
498
+ },
499
+ ],
500
+ isError: true,
501
+ };
502
+ }
503
+ }
504
+
505
+ private formatOrdersResponse(data: any): string {
506
+ if (!data.orders || data.orders.length === 0) {
507
+ return "No orders found matching the criteria.";
508
+ }
509
+
510
+ let result = `šŸ“¦ Found ${data.orders.length} orders:\n\n`;
511
+ result += "=".repeat(50) + "\n\n";
512
+
513
+ data.orders.forEach((order: any, index: number) => {
514
+ result += `**Order ${index + 1}**\n`;
515
+ result += `Order ID: ${order.orderId}\n`;
516
+ result += `Created: ${new Date(order.createdTime).toLocaleDateString()}\n`;
517
+ result += `Status: ${order.fulfillment?.fulfillmentStatus || "Unknown"}\n`;
518
+ result += `Marketplace: ${order.salesChannel?.marketplaceName || "N/A"}\n`;
519
+
520
+ if (order.buyer) {
521
+ result += `Buyer: ${order.buyer.buyerName || "N/A"}\n`;
522
+ }
523
+
524
+ if (order.recipient?.deliveryAddress) {
525
+ const addr = order.recipient.deliveryAddress;
526
+ result += `Shipping: ${addr.addressLine1 || ""}, ${addr.city || ""}, ${addr.stateOrRegion || ""} ${addr.postalCode || ""}\n`;
527
+ }
528
+
529
+ if (order.orderItems && order.orderItems.length > 0) {
530
+ result += `Items: ${order.orderItems.length} item(s)\n`;
531
+ order.orderItems.forEach((item: any, itemIndex: number) => {
532
+ const price = item.product?.price?.unitPrice;
533
+ const priceStr = price
534
+ ? `${price.amount} ${price.currencyCode}`
535
+ : "N/A";
536
+ result += ` ${itemIndex + 1}. ${item.product?.title || "Unknown"} (Qty: ${item.quantityOrdered}, Price: ${priceStr})\n`;
537
+ });
538
+ }
539
+
540
+ result += "\n" + "-".repeat(40) + "\n\n";
541
+ });
542
+
543
+ if (data.pagination?.nextToken) {
544
+ result += `\nšŸ”— **Next page available** - Use paginationToken: ${data.pagination.nextToken}`;
545
+ }
546
+
547
+ return result;
548
+ }
549
+
550
+ private formatOrderResponse(order: any): string {
551
+ let result = `šŸ“‹ **Order Details**\n\n`;
552
+ result += "=".repeat(50) + "\n\n";
553
+
554
+ result += `**Basic Information**\n`;
555
+ result += `Order ID: ${order.orderId}\n`;
556
+ result += `Created: ${new Date(order.createdTime).toLocaleString()}\n`;
557
+ result += `Last Updated: ${new Date(order.lastUpdatedTime).toLocaleString()}\n`;
558
+ result += `Marketplace: ${order.salesChannel?.marketplaceName || "N/A"}\n`;
559
+ result += `Channel: ${order.salesChannel?.channelName || "N/A"}\n`;
560
+
561
+ if (order.programs && order.programs.length > 0) {
562
+ result += `Programs: ${order.programs.join(", ")}\n`;
563
+ }
564
+
565
+ if (order.buyer) {
566
+ result += `\n**Buyer Information**\n`;
567
+ result += `Name: ${order.buyer.buyerName || "N/A"}\n`;
568
+ result += `Email: ${order.buyer.buyerEmail || "N/A"}\n`;
569
+ if (order.buyer.buyerCompanyName) {
570
+ result += `Company: ${order.buyer.buyerCompanyName}\n`;
571
+ }
572
+ if (order.buyer.buyerPurchaseOrderNumber) {
573
+ result += `PO Number: ${order.buyer.buyerPurchaseOrderNumber}\n`;
574
+ }
575
+ }
576
+
577
+ if (order.recipient?.deliveryAddress) {
578
+ result += `\n**Shipping Address**\n`;
579
+ const addr = order.recipient.deliveryAddress;
580
+ result += `Name: ${addr.name || "N/A"}\n`;
581
+ if (addr.companyName) result += `Company: ${addr.companyName}\n`;
582
+ result += `Address: ${addr.addressLine1 || ""}\n`;
583
+ if (addr.addressLine2) result += ` ${addr.addressLine2}\n`;
584
+ if (addr.addressLine3) result += ` ${addr.addressLine3}\n`;
585
+ result += `City: ${addr.city || "N/A"}\n`;
586
+ result += `State/Region: ${addr.stateOrRegion || "N/A"}\n`;
587
+ result += `Postal Code: ${addr.postalCode || "N/A"}\n`;
588
+ result += `Country: ${addr.countryCode || "N/A"}\n`;
589
+ if (addr.phone) result += `Phone: ${addr.phone}\n`;
590
+ result += `Address Type: ${addr.addressType || "N/A"}\n`;
591
+ }
592
+
593
+ if (order.fulfillment) {
594
+ result += `\n**Fulfillment Information**\n`;
595
+ result += `Status: ${order.fulfillment.fulfillmentStatus}\n`;
596
+ result += `Fulfilled By: ${order.fulfillment.fulfilledBy}\n`;
597
+ if (order.fulfillment.fulfillmentServiceLevel) {
598
+ result += `Service Level: ${order.fulfillment.fulfillmentServiceLevel}\n`;
599
+ }
600
+ }
601
+
602
+ if (order.orderItems && order.orderItems.length > 0) {
603
+ result += `\n**Order Items (${order.orderItems.length})**\n\n`;
604
+ order.orderItems.forEach((item: any, index: number) => {
605
+ result += `**${index + 1}. ${item.product?.title || "Unknown Product"}**\n`;
606
+ result += ` Order Item ID: ${item.orderItemId}\n`;
607
+ result += ` ASIN: ${item.product?.asin || "N/A"}\n`;
608
+ result += ` SKU: ${item.product?.sellerSku || "N/A"}\n`;
609
+ result += ` Quantity Ordered: ${item.quantityOrdered}\n`;
610
+
611
+ if (item.product?.price?.unitPrice) {
612
+ const price = item.product.price.unitPrice;
613
+ result += ` Unit Price: ${price.amount} ${price.currencyCode}\n`;
614
+ }
615
+
616
+ if (item.fulfillment) {
617
+ result += ` Fulfilled: ${item.fulfillment.quantityFulfilled || 0}\n`;
618
+ result += ` Unfulfilled: ${item.fulfillment.quantityUnfulfilled || 0}\n`;
619
+ }
620
+
621
+ result += "\n";
622
+ });
623
+ }
624
+
625
+ return result;
626
+ }
627
+
628
+ private formatRegulatedInfoResponse(data: any): string {
629
+ if (!data) {
630
+ return "No regulated information found for this order.";
631
+ }
632
+
633
+ let result = `šŸ“‹ **Regulated Order Information**\n\n`;
634
+ result += "=".repeat(50) + "\n\n";
635
+
636
+ if (data.regulatedInformation) {
637
+ const info = data.regulatedInformation;
638
+
639
+ if (info.verificationStatus) {
640
+ result += `**Verification Status**\n`;
641
+ result += `Status: ${info.verificationStatus.status}\n`;
642
+ if (info.verificationStatus.validUntil) {
643
+ result += `Valid Until: ${new Date(info.verificationStatus.validUntil).toLocaleString()}\n`;
644
+ }
645
+ if (info.verificationStatus.rejectionReason) {
646
+ result += `Rejection Reason: ${info.verificationStatus.rejectionReason.rejectionReasonDescription}\n`;
647
+ }
648
+ result += "\n";
649
+ }
650
+
651
+ if (info.regulatedOrderItems && info.regulatedOrderItems.length > 0) {
652
+ result += `**Regulated Items (${info.regulatedOrderItems.length})**\n\n`;
653
+ info.regulatedOrderItems.forEach((item: any, index: number) => {
654
+ result += `**${index + 1}. ${item.title || "Unknown Item"}**\n`;
655
+ result += ` Order Item ID: ${item.orderItemId}\n`;
656
+ result += ` ASIN: ${item.asin}\n`;
657
+ result += ` Quantity Ordered: ${item.quantityOrdered}\n`;
658
+ if (item.verificationStatus) {
659
+ result += ` Verification Status: ${item.verificationStatus.status}\n`;
660
+ }
661
+ if (item.fulfillmentInstructions) {
662
+ result += ` Fulfillment Instructions:\n`;
663
+ if (item.fulfillmentInstructions.fulfillmentInstructionsType) {
664
+ result += ` Type: ${item.fulfillmentInstructions.fulfillmentInstructionsType}\n`;
665
+ }
666
+ if (item.fulfillmentInstructions.fulfillmentInstructionsText) {
667
+ result += ` Text: ${item.fulfillmentInstructions.fulfillmentInstructionsText}\n`;
668
+ }
669
+ }
670
+ result += "\n";
671
+ });
672
+ }
673
+ }
674
+
675
+ if (data.errors && data.errors.length > 0) {
676
+ result += `**Errors**\n`;
677
+ data.errors.forEach((error: any) => {
678
+ result += `- Code: ${error.code}, Message: ${error.message}\n`;
679
+ });
680
+ }
681
+
682
+ return result;
683
+ }
684
+ }