@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,459 @@
1
+ import { SPAPIAuth } from "../../auth/sp-api-auth.js";
2
+ export class OrdersApiTool {
3
+ config;
4
+ auth;
5
+ hasCredentials;
6
+ constructor(config) {
7
+ this.config = {
8
+ ...config,
9
+ baseUrl: config?.baseUrl || "https://sellingpartnerapi-na.amazon.com",
10
+ };
11
+ this.hasCredentials = !!(this.config.clientId &&
12
+ this.config.clientSecret &&
13
+ this.config.refreshToken);
14
+ if (this.hasCredentials) {
15
+ this.auth = new SPAPIAuth(this.config);
16
+ }
17
+ }
18
+ checkCredentials() {
19
+ if (!this.hasCredentials) {
20
+ return {
21
+ content: [
22
+ {
23
+ type: "text",
24
+ text: `❌ **SP-API Credentials Required**
25
+
26
+ To use this tool, you need to provide SP-API credentials
27
+
28
+ **Environment variables**:
29
+ \`\`\`bash
30
+ export SP_API_CLIENT_ID="your_client_id"
31
+ export SP_API_CLIENT_SECRET="your_client_secret"
32
+ export SP_API_REFRESH_TOKEN="your_refresh_token"
33
+ export SP_API_BASE_URL="https://sellingpartnerapi-na.amazon.com"
34
+ \`\`\`
35
+
36
+ **Note:** The migration assistant tool does not require credentials and can be used without API access.`,
37
+ },
38
+ ],
39
+ isError: true,
40
+ };
41
+ }
42
+ return null;
43
+ }
44
+ async searchOrders(args) {
45
+ const credentialError = this.checkCredentials();
46
+ if (credentialError)
47
+ return credentialError;
48
+ const { createdAfter, createdBefore, lastUpdatedAfter, lastUpdatedBefore, fulfillmentStatuses, marketplaceIds = ["ATVPDKIKX0DER"], fulfilledBy, maxResultsPerPage = 50, includedData = [], paginationToken, } = args;
49
+ // Validate date parameters
50
+ if (!createdAfter && !lastUpdatedAfter) {
51
+ return {
52
+ content: [
53
+ {
54
+ type: "text",
55
+ text: "Error: Either createdAfter or lastUpdatedAfter must be provided",
56
+ },
57
+ ],
58
+ isError: true,
59
+ };
60
+ }
61
+ const queryParams = {
62
+ marketplaceIds: marketplaceIds.join(","),
63
+ maxResultsPerPage: maxResultsPerPage.toString(),
64
+ };
65
+ if (createdAfter)
66
+ queryParams.createdAfter = createdAfter;
67
+ if (createdBefore)
68
+ queryParams.createdBefore = createdBefore;
69
+ if (lastUpdatedAfter)
70
+ queryParams.lastUpdatedAfter = lastUpdatedAfter;
71
+ if (lastUpdatedBefore)
72
+ queryParams.lastUpdatedBefore = lastUpdatedBefore;
73
+ if (fulfillmentStatuses && fulfillmentStatuses.length > 0) {
74
+ queryParams.fulfillmentStatuses = fulfillmentStatuses.join(",");
75
+ }
76
+ if (fulfilledBy && fulfilledBy.length > 0) {
77
+ queryParams.fulfilledBy = fulfilledBy.join(",");
78
+ }
79
+ if (includedData.length > 0) {
80
+ queryParams.includedData = includedData.join(",");
81
+ }
82
+ if (paginationToken) {
83
+ queryParams.paginationToken = paginationToken;
84
+ }
85
+ try {
86
+ const response = await this.auth.makeAuthenticatedRequest("GET", `${this.config.baseUrl}/orders/2026-01-01/orders`, queryParams);
87
+ return {
88
+ content: [
89
+ {
90
+ type: "text",
91
+ text: this.formatOrdersResponse(response.data),
92
+ },
93
+ ],
94
+ };
95
+ }
96
+ catch (error) {
97
+ return {
98
+ content: [
99
+ {
100
+ type: "text",
101
+ text: `Error: ${error.message}`,
102
+ },
103
+ ],
104
+ isError: true,
105
+ };
106
+ }
107
+ }
108
+ async getOrder(args) {
109
+ const credentialError = this.checkCredentials();
110
+ if (credentialError)
111
+ return credentialError;
112
+ const { orderId, includedData = [] } = args;
113
+ const queryParams = {};
114
+ if (includedData.length > 0) {
115
+ queryParams.includedData = includedData.join(",");
116
+ }
117
+ try {
118
+ const response = await this.auth.makeAuthenticatedRequest("GET", `${this.config.baseUrl}/orders/2026-01-01/orders/${orderId}`, queryParams);
119
+ return {
120
+ content: [
121
+ {
122
+ type: "text",
123
+ text: this.formatOrderResponse(response.data.order),
124
+ },
125
+ ],
126
+ };
127
+ }
128
+ catch (error) {
129
+ return {
130
+ content: [
131
+ {
132
+ type: "text",
133
+ text: `Error: ${error.message}`,
134
+ },
135
+ ],
136
+ isError: true,
137
+ };
138
+ }
139
+ }
140
+ async cancelOrder(args) {
141
+ const credentialError = this.checkCredentials();
142
+ if (credentialError)
143
+ return credentialError;
144
+ const { orderId, cancelReasonCode } = args;
145
+ const requestBody = {
146
+ cancelReasonCode: cancelReasonCode,
147
+ };
148
+ try {
149
+ await this.auth.makeAuthenticatedRequest("PUT", `${this.config.baseUrl}/orders/2026-01-01/orders/${orderId}/cancellation`, {}, requestBody);
150
+ return {
151
+ content: [
152
+ {
153
+ type: "text",
154
+ text: `✅ Order cancellation request accepted for order ${orderId}. The cancellation process is underway.`,
155
+ },
156
+ ],
157
+ };
158
+ }
159
+ catch (error) {
160
+ return {
161
+ content: [
162
+ {
163
+ type: "text",
164
+ text: `Error: ${error.message}`,
165
+ },
166
+ ],
167
+ isError: true,
168
+ };
169
+ }
170
+ }
171
+ // V0 APIs
172
+ async updateShipmentStatus(args) {
173
+ const credentialError = this.checkCredentials();
174
+ if (credentialError)
175
+ return credentialError;
176
+ const { orderId, marketplaceId, shipmentStatus, orderItems } = args;
177
+ const requestBody = {
178
+ marketplaceId,
179
+ shipmentStatus,
180
+ };
181
+ if (orderItems && orderItems.length > 0) {
182
+ requestBody.orderItems = orderItems;
183
+ }
184
+ try {
185
+ const response = await this.auth.makeAuthenticatedRequest("POST", `${this.config.baseUrl}/orders/v0/orders/${orderId}/shipment`, {}, requestBody);
186
+ return {
187
+ content: [
188
+ {
189
+ type: "text",
190
+ text: `✅ Shipment status updated successfully for order ${orderId}.\n\nResponse: ${JSON.stringify(response.data, null, 2)}`,
191
+ },
192
+ ],
193
+ };
194
+ }
195
+ catch (error) {
196
+ return {
197
+ content: [
198
+ {
199
+ type: "text",
200
+ text: `Error updating shipment status: ${error.message}`,
201
+ },
202
+ ],
203
+ isError: true,
204
+ };
205
+ }
206
+ }
207
+ async updateVerificationStatus(args) {
208
+ const credentialError = this.checkCredentials();
209
+ if (credentialError)
210
+ return credentialError;
211
+ const { orderId, marketplaceId, regulatedOrderVerificationStatus } = args;
212
+ const requestBody = {
213
+ marketplaceId,
214
+ regulatedOrderVerificationStatus,
215
+ };
216
+ try {
217
+ const response = await this.auth.makeAuthenticatedRequest("PATCH", `${this.config.baseUrl}/orders/v0/orders/${orderId}/regulatedInfo`, {}, requestBody);
218
+ return {
219
+ content: [
220
+ {
221
+ type: "text",
222
+ text: `✅ Verification status updated successfully for order ${orderId}.\n\nResponse: ${JSON.stringify(response.data, null, 2)}`,
223
+ },
224
+ ],
225
+ };
226
+ }
227
+ catch (error) {
228
+ return {
229
+ content: [
230
+ {
231
+ type: "text",
232
+ text: `Error updating verification status: ${error.message}`,
233
+ },
234
+ ],
235
+ isError: true,
236
+ };
237
+ }
238
+ }
239
+ async confirmShipment(args) {
240
+ const credentialError = this.checkCredentials();
241
+ if (credentialError)
242
+ return credentialError;
243
+ const { orderId, marketplaceId, packageDetail, codCollectionMethod } = args;
244
+ const requestBody = {
245
+ marketplaceId,
246
+ packageDetail,
247
+ };
248
+ if (codCollectionMethod) {
249
+ requestBody.codCollectionMethod = codCollectionMethod;
250
+ }
251
+ try {
252
+ const response = await this.auth.makeAuthenticatedRequest("POST", `${this.config.baseUrl}/orders/v0/orders/${orderId}/shipmentConfirmation`, {}, requestBody);
253
+ return {
254
+ content: [
255
+ {
256
+ type: "text",
257
+ text: `✅ Shipment confirmed successfully for order ${orderId}.\n\nResponse: ${JSON.stringify(response.data, null, 2)}`,
258
+ },
259
+ ],
260
+ };
261
+ }
262
+ catch (error) {
263
+ return {
264
+ content: [
265
+ {
266
+ type: "text",
267
+ text: `Error confirming shipment: ${error.message}`,
268
+ },
269
+ ],
270
+ isError: true,
271
+ };
272
+ }
273
+ }
274
+ async getOrderRegulatedInfo(args) {
275
+ const credentialError = this.checkCredentials();
276
+ if (credentialError)
277
+ return credentialError;
278
+ const { orderId } = args;
279
+ try {
280
+ const response = await this.auth.makeAuthenticatedRequest("GET", `${this.config.baseUrl}/orders/v0/orders/${orderId}/regulatedInfo`, {});
281
+ return {
282
+ content: [
283
+ {
284
+ type: "text",
285
+ text: this.formatRegulatedInfoResponse(response.data),
286
+ },
287
+ ],
288
+ };
289
+ }
290
+ catch (error) {
291
+ return {
292
+ content: [
293
+ {
294
+ type: "text",
295
+ text: `Error getting regulated info: ${error.message}`,
296
+ },
297
+ ],
298
+ isError: true,
299
+ };
300
+ }
301
+ }
302
+ formatOrdersResponse(data) {
303
+ if (!data.orders || data.orders.length === 0) {
304
+ return "No orders found matching the criteria.";
305
+ }
306
+ let result = `📦 Found ${data.orders.length} orders:\n\n`;
307
+ result += "=".repeat(50) + "\n\n";
308
+ data.orders.forEach((order, index) => {
309
+ result += `**Order ${index + 1}**\n`;
310
+ result += `Order ID: ${order.orderId}\n`;
311
+ result += `Created: ${new Date(order.createdTime).toLocaleDateString()}\n`;
312
+ result += `Status: ${order.fulfillment?.fulfillmentStatus || "Unknown"}\n`;
313
+ result += `Marketplace: ${order.salesChannel?.marketplaceName || "N/A"}\n`;
314
+ if (order.buyer) {
315
+ result += `Buyer: ${order.buyer.buyerName || "N/A"}\n`;
316
+ }
317
+ if (order.recipient?.deliveryAddress) {
318
+ const addr = order.recipient.deliveryAddress;
319
+ result += `Shipping: ${addr.addressLine1 || ""}, ${addr.city || ""}, ${addr.stateOrRegion || ""} ${addr.postalCode || ""}\n`;
320
+ }
321
+ if (order.orderItems && order.orderItems.length > 0) {
322
+ result += `Items: ${order.orderItems.length} item(s)\n`;
323
+ order.orderItems.forEach((item, itemIndex) => {
324
+ const price = item.product?.price?.unitPrice;
325
+ const priceStr = price
326
+ ? `${price.amount} ${price.currencyCode}`
327
+ : "N/A";
328
+ result += ` ${itemIndex + 1}. ${item.product?.title || "Unknown"} (Qty: ${item.quantityOrdered}, Price: ${priceStr})\n`;
329
+ });
330
+ }
331
+ result += "\n" + "-".repeat(40) + "\n\n";
332
+ });
333
+ if (data.pagination?.nextToken) {
334
+ result += `\n🔗 **Next page available** - Use paginationToken: ${data.pagination.nextToken}`;
335
+ }
336
+ return result;
337
+ }
338
+ formatOrderResponse(order) {
339
+ let result = `📋 **Order Details**\n\n`;
340
+ result += "=".repeat(50) + "\n\n";
341
+ result += `**Basic Information**\n`;
342
+ result += `Order ID: ${order.orderId}\n`;
343
+ result += `Created: ${new Date(order.createdTime).toLocaleString()}\n`;
344
+ result += `Last Updated: ${new Date(order.lastUpdatedTime).toLocaleString()}\n`;
345
+ result += `Marketplace: ${order.salesChannel?.marketplaceName || "N/A"}\n`;
346
+ result += `Channel: ${order.salesChannel?.channelName || "N/A"}\n`;
347
+ if (order.programs && order.programs.length > 0) {
348
+ result += `Programs: ${order.programs.join(", ")}\n`;
349
+ }
350
+ if (order.buyer) {
351
+ result += `\n**Buyer Information**\n`;
352
+ result += `Name: ${order.buyer.buyerName || "N/A"}\n`;
353
+ result += `Email: ${order.buyer.buyerEmail || "N/A"}\n`;
354
+ if (order.buyer.buyerCompanyName) {
355
+ result += `Company: ${order.buyer.buyerCompanyName}\n`;
356
+ }
357
+ if (order.buyer.buyerPurchaseOrderNumber) {
358
+ result += `PO Number: ${order.buyer.buyerPurchaseOrderNumber}\n`;
359
+ }
360
+ }
361
+ if (order.recipient?.deliveryAddress) {
362
+ result += `\n**Shipping Address**\n`;
363
+ const addr = order.recipient.deliveryAddress;
364
+ result += `Name: ${addr.name || "N/A"}\n`;
365
+ if (addr.companyName)
366
+ result += `Company: ${addr.companyName}\n`;
367
+ result += `Address: ${addr.addressLine1 || ""}\n`;
368
+ if (addr.addressLine2)
369
+ result += ` ${addr.addressLine2}\n`;
370
+ if (addr.addressLine3)
371
+ result += ` ${addr.addressLine3}\n`;
372
+ result += `City: ${addr.city || "N/A"}\n`;
373
+ result += `State/Region: ${addr.stateOrRegion || "N/A"}\n`;
374
+ result += `Postal Code: ${addr.postalCode || "N/A"}\n`;
375
+ result += `Country: ${addr.countryCode || "N/A"}\n`;
376
+ if (addr.phone)
377
+ result += `Phone: ${addr.phone}\n`;
378
+ result += `Address Type: ${addr.addressType || "N/A"}\n`;
379
+ }
380
+ if (order.fulfillment) {
381
+ result += `\n**Fulfillment Information**\n`;
382
+ result += `Status: ${order.fulfillment.fulfillmentStatus}\n`;
383
+ result += `Fulfilled By: ${order.fulfillment.fulfilledBy}\n`;
384
+ if (order.fulfillment.fulfillmentServiceLevel) {
385
+ result += `Service Level: ${order.fulfillment.fulfillmentServiceLevel}\n`;
386
+ }
387
+ }
388
+ if (order.orderItems && order.orderItems.length > 0) {
389
+ result += `\n**Order Items (${order.orderItems.length})**\n\n`;
390
+ order.orderItems.forEach((item, index) => {
391
+ result += `**${index + 1}. ${item.product?.title || "Unknown Product"}**\n`;
392
+ result += ` Order Item ID: ${item.orderItemId}\n`;
393
+ result += ` ASIN: ${item.product?.asin || "N/A"}\n`;
394
+ result += ` SKU: ${item.product?.sellerSku || "N/A"}\n`;
395
+ result += ` Quantity Ordered: ${item.quantityOrdered}\n`;
396
+ if (item.product?.price?.unitPrice) {
397
+ const price = item.product.price.unitPrice;
398
+ result += ` Unit Price: ${price.amount} ${price.currencyCode}\n`;
399
+ }
400
+ if (item.fulfillment) {
401
+ result += ` Fulfilled: ${item.fulfillment.quantityFulfilled || 0}\n`;
402
+ result += ` Unfulfilled: ${item.fulfillment.quantityUnfulfilled || 0}\n`;
403
+ }
404
+ result += "\n";
405
+ });
406
+ }
407
+ return result;
408
+ }
409
+ formatRegulatedInfoResponse(data) {
410
+ if (!data) {
411
+ return "No regulated information found for this order.";
412
+ }
413
+ let result = `📋 **Regulated Order Information**\n\n`;
414
+ result += "=".repeat(50) + "\n\n";
415
+ if (data.regulatedInformation) {
416
+ const info = data.regulatedInformation;
417
+ if (info.verificationStatus) {
418
+ result += `**Verification Status**\n`;
419
+ result += `Status: ${info.verificationStatus.status}\n`;
420
+ if (info.verificationStatus.validUntil) {
421
+ result += `Valid Until: ${new Date(info.verificationStatus.validUntil).toLocaleString()}\n`;
422
+ }
423
+ if (info.verificationStatus.rejectionReason) {
424
+ result += `Rejection Reason: ${info.verificationStatus.rejectionReason.rejectionReasonDescription}\n`;
425
+ }
426
+ result += "\n";
427
+ }
428
+ if (info.regulatedOrderItems && info.regulatedOrderItems.length > 0) {
429
+ result += `**Regulated Items (${info.regulatedOrderItems.length})**\n\n`;
430
+ info.regulatedOrderItems.forEach((item, index) => {
431
+ result += `**${index + 1}. ${item.title || "Unknown Item"}**\n`;
432
+ result += ` Order Item ID: ${item.orderItemId}\n`;
433
+ result += ` ASIN: ${item.asin}\n`;
434
+ result += ` Quantity Ordered: ${item.quantityOrdered}\n`;
435
+ if (item.verificationStatus) {
436
+ result += ` Verification Status: ${item.verificationStatus.status}\n`;
437
+ }
438
+ if (item.fulfillmentInstructions) {
439
+ result += ` Fulfillment Instructions:\n`;
440
+ if (item.fulfillmentInstructions.fulfillmentInstructionsType) {
441
+ result += ` Type: ${item.fulfillmentInstructions.fulfillmentInstructionsType}\n`;
442
+ }
443
+ if (item.fulfillmentInstructions.fulfillmentInstructionsText) {
444
+ result += ` Text: ${item.fulfillmentInstructions.fulfillmentInstructionsText}\n`;
445
+ }
446
+ }
447
+ result += "\n";
448
+ });
449
+ }
450
+ }
451
+ if (data.errors && data.errors.length > 0) {
452
+ result += `**Errors**\n`;
453
+ data.errors.forEach((error) => {
454
+ result += `- Code: ${error.code}, Message: ${error.message}\n`;
455
+ });
456
+ }
457
+ return result;
458
+ }
459
+ }
@@ -0,0 +1,21 @@
1
+ export interface MigrationAssistantArgs {
2
+ source_code?: string;
3
+ source_version: string;
4
+ target_version: string;
5
+ language?: string;
6
+ analysis_only?: boolean;
7
+ }
8
+ export interface ToolResponse {
9
+ content: Array<{
10
+ type: "text";
11
+ text: string;
12
+ meta?: Record<string, unknown>;
13
+ }>;
14
+ isError?: boolean;
15
+ [key: string]: unknown;
16
+ }
17
+ export declare class SPAPIMigrationAssistantTool {
18
+ migrationAssistant(args: MigrationAssistantArgs): Promise<ToolResponse>;
19
+ private handleOrdersApiMigration;
20
+ }
21
+ //# sourceMappingURL=migration-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-tools.d.ts","sourceRoot":"","sources":["../../../src/tools/migration-assistant-tools/migration-tools.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAChC,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,qBAAa,2BAA2B;IAChC,kBAAkB,CACtB,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,YAAY,CAAC;YA8DV,wBAAwB;CAkDvC"}
@@ -0,0 +1,82 @@
1
+ import { getOrdersApiMigrationData } from "./orders-api-migration/migration-data.js";
2
+ import { analyzeOrdersApiCode } from "./orders-api-migration/code-analyzer.js";
3
+ import { generateRefactoredOrdersApiCode } from "./orders-api-migration/code-generator.js";
4
+ import { formatAnalysisReport, formatMigrationReport, } from "./orders-api-migration/report-formatter.js";
5
+ import { formatGeneralGuidance } from "./orders-api-migration/guidance-formatter.js";
6
+ export class SPAPIMigrationAssistantTool {
7
+ async migrationAssistant(args) {
8
+ const { source_code, source_version, target_version, analysis_only = false, } = args;
9
+ // Validate supported migrations
10
+ const supportedMigrations = {
11
+ "orders-v0->orders-2026-01-01": {
12
+ source: "orders-v0",
13
+ target: "orders-2026-01-01",
14
+ },
15
+ };
16
+ const isSupported = Object.values(supportedMigrations).some((m) => m.source === source_version && m.target === target_version);
17
+ if (!isSupported) {
18
+ return {
19
+ content: [
20
+ {
21
+ type: "text",
22
+ text: `❌ Unsupported migration path: ${source_version} → ${target_version}\n\nSupported migrations:\n${Object.values(supportedMigrations)
23
+ .map((m) => `- ${m.source} → ${m.target}`)
24
+ .join("\n")}`,
25
+ },
26
+ ],
27
+ isError: true,
28
+ };
29
+ }
30
+ // Route to appropriate migration handler
31
+ if (source_version === "orders-v0" &&
32
+ target_version === "orders-2026-01-01") {
33
+ return this.handleOrdersApiMigration(source_code, target_version, analysis_only);
34
+ }
35
+ return {
36
+ content: [
37
+ {
38
+ type: "text",
39
+ text: `Migration handler not implemented for ${source_version} → ${target_version}`,
40
+ },
41
+ ],
42
+ isError: true,
43
+ };
44
+ }
45
+ async handleOrdersApiMigration(sourceCode, targetVersion, analysisOnly) {
46
+ // Get migration data
47
+ const migrationData = getOrdersApiMigrationData();
48
+ // If no source code provided, return general guidance
49
+ if (!sourceCode) {
50
+ return {
51
+ content: [
52
+ {
53
+ type: "text",
54
+ text: formatGeneralGuidance(migrationData),
55
+ },
56
+ ],
57
+ };
58
+ }
59
+ // Analyze the source code
60
+ const analysis = analyzeOrdersApiCode(sourceCode, migrationData);
61
+ if (analysisOnly) {
62
+ return {
63
+ content: [
64
+ {
65
+ type: "text",
66
+ text: formatAnalysisReport(analysis, migrationData),
67
+ },
68
+ ],
69
+ };
70
+ }
71
+ // Generate refactored code
72
+ const refactoredCode = generateRefactoredOrdersApiCode(sourceCode, analysis, targetVersion);
73
+ return {
74
+ content: [
75
+ {
76
+ type: "text",
77
+ text: formatMigrationReport(analysis, refactoredCode, migrationData),
78
+ },
79
+ ],
80
+ };
81
+ }
82
+ }
@@ -0,0 +1,19 @@
1
+ import { MigrationData } from "./migration-data.js";
2
+ export interface CodeAnalysis {
3
+ deprecatedEndpoints: Array<{
4
+ endpoint: string;
5
+ replacement: string;
6
+ }>;
7
+ breakingChanges: Array<{
8
+ change: string;
9
+ explanation: string;
10
+ }>;
11
+ usedAttributes: Array<{
12
+ v0: string;
13
+ v1: string;
14
+ notes: string;
15
+ }>;
16
+ apiCalls: string[];
17
+ }
18
+ export declare function analyzeOrdersApiCode(sourceCode: string, migrationData: MigrationData): CodeAnalysis;
19
+ //# sourceMappingURL=code-analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-analyzer.d.ts","sourceRoot":"","sources":["../../../../src/tools/migration-assistant-tools/orders-api-migration/code-analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,YAAY;IAC3B,mBAAmB,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtE,eAAe,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChE,cAAc,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjE,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,aAAa,GAC3B,YAAY,CA2Dd"}
@@ -0,0 +1,52 @@
1
+ export function analyzeOrdersApiCode(sourceCode, migrationData) {
2
+ const deprecatedEndpoints = [];
3
+ const breakingChanges = [];
4
+ const usedAttributes = [];
5
+ const apiCalls = [];
6
+ // Detect API method calls
7
+ const apiMethodPatterns = Object.keys(migrationData.apiMapping);
8
+ apiMethodPatterns.forEach((method) => {
9
+ const regex = new RegExp(`\\b${method}\\b`, "g");
10
+ if (regex.test(sourceCode)) {
11
+ apiCalls.push(method);
12
+ const mapping = migrationData.apiMapping[method];
13
+ if (mapping.status.includes("❌")) {
14
+ deprecatedEndpoints.push({
15
+ endpoint: method,
16
+ replacement: mapping.v1,
17
+ });
18
+ breakingChanges.push({
19
+ change: `${method} has no V1 counterpart`,
20
+ explanation: mapping.notes,
21
+ });
22
+ }
23
+ }
24
+ });
25
+ // Detect deprecated attributes
26
+ migrationData.deprecated.forEach((attr) => {
27
+ const regex = new RegExp(`\\b${attr.replace(/\./g, "\\.")}\\b`, "g");
28
+ if (regex.test(sourceCode)) {
29
+ breakingChanges.push({
30
+ change: `Deprecated attribute: ${attr}`,
31
+ explanation: "This attribute is removed in V1 and has no replacement",
32
+ });
33
+ }
34
+ });
35
+ // Detect attribute mappings
36
+ Object.entries(migrationData.mappingExamples).forEach(([v0, v1]) => {
37
+ const regex = new RegExp(`\\b${v0.replace(/\./g, "\\.")}\\b`, "g");
38
+ if (regex.test(sourceCode)) {
39
+ usedAttributes.push({
40
+ v0,
41
+ v1,
42
+ notes: `Mapped from ${v0} to ${v1}`,
43
+ });
44
+ }
45
+ });
46
+ return {
47
+ deprecatedEndpoints,
48
+ breakingChanges,
49
+ usedAttributes,
50
+ apiCalls,
51
+ };
52
+ }
@@ -0,0 +1,3 @@
1
+ import { CodeAnalysis } from "./code-analyzer.js";
2
+ export declare function generateRefactoredOrdersApiCode(sourceCode: string, analysis: CodeAnalysis, targetVersion: string): string;
3
+ //# sourceMappingURL=code-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-generator.d.ts","sourceRoot":"","sources":["../../../../src/tools/migration-assistant-tools/orders-api-migration/code-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,MAAM,GACpB,MAAM,CAyDR"}