@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,85 @@
1
+ import { CodeAnalysis } from "./code-analyzer.js";
2
+ import { MigrationData } from "./migration-data.js";
3
+
4
+ export function formatAnalysisReport(
5
+ analysis: CodeAnalysis,
6
+ migrationData: MigrationData,
7
+ ): string {
8
+ let report = `# πŸ” Migration Analysis Report\n\n`;
9
+ report += `## πŸ“Š Summary\n\n`;
10
+ report += `- **API Calls Found:** ${analysis.apiCalls.length}\n`;
11
+ report += `- **Attributes to Update:** ${analysis.usedAttributes.length}\n`;
12
+ report += `- **Breaking Changes:** ${analysis.breakingChanges.length}\n`;
13
+ report += `- **Deprecated Endpoints:** ${analysis.deprecatedEndpoints.length}\n\n`;
14
+
15
+ if (analysis.deprecatedEndpoints.length > 0) {
16
+ report += `## ❌ Deprecated Endpoints\n\n`;
17
+ analysis.deprecatedEndpoints.forEach((endpoint) => {
18
+ report += `- **${endpoint.endpoint}** β†’ ${endpoint.replacement}\n`;
19
+ });
20
+ report += `\n`;
21
+ }
22
+
23
+ if (analysis.breakingChanges.length > 0) {
24
+ report += `## ⚠️ Breaking Changes\n\n`;
25
+ analysis.breakingChanges.forEach((change, index) => {
26
+ report += `${index + 1}. **${change.change}**\n`;
27
+ report += ` ${change.explanation}\n\n`;
28
+ });
29
+ }
30
+
31
+ if (analysis.usedAttributes.length > 0) {
32
+ report += `## πŸ—ΊοΈ Attribute Mappings\n\n`;
33
+ analysis.usedAttributes.forEach((attr) => {
34
+ report += `- \`${attr.v0}\` β†’ \`${attr.v1}\`\n`;
35
+ });
36
+ report += `\n`;
37
+ }
38
+
39
+ if (analysis.apiCalls.length > 0) {
40
+ report += `## πŸ”Œ API Methods Detected\n\n`;
41
+ analysis.apiCalls.forEach((method) => {
42
+ const mapping = migrationData.apiMapping[method];
43
+ const status = mapping?.status || "Unknown";
44
+ report += `- **${method}** - ${status}\n`;
45
+ });
46
+ report += `\n`;
47
+ }
48
+
49
+ report += `## βœ… Migration Checklist\n\n`;
50
+ report += `- [ ] Review all deprecated endpoints and plan V0 fallback strategy\n`;
51
+ report += `- [ ] Update attribute references to new V1 structure\n`;
52
+ report += `- [ ] Add \`includedData\` parameter where needed (BUYER, RECIPIENT, etc.)\n`;
53
+ report += `- [ ] Update error handling for new response formats\n`;
54
+ report += `- [ ] Test with sandbox environment before production\n`;
55
+ report += `- [ ] Update TypeScript types/interfaces\n`;
56
+ report += `- [ ] Monitor for V0 API deprecation announcements\n\n`;
57
+
58
+ return report;
59
+ }
60
+
61
+ export function formatMigrationReport(
62
+ analysis: CodeAnalysis,
63
+ refactoredCode: string,
64
+ migrationData: MigrationData,
65
+ ): string {
66
+ let report = formatAnalysisReport(analysis, migrationData);
67
+
68
+ report += `\n---\n\n`;
69
+ report += `## πŸ’» Refactored Code\n\n`;
70
+ report += `\`\`\`javascript\n${refactoredCode}\n\`\`\`\n\n`;
71
+
72
+ report += `## πŸ§ͺ Testing Recommendations\n\n`;
73
+ report += `1. **Unit Tests:** Update test cases to match new V1 response structure\n`;
74
+ report += `2. **Integration Tests:** Test with SP-API sandbox environment\n`;
75
+ report += `3. **Error Handling:** Verify error responses match V1 format\n`;
76
+ report += `4. **Performance:** Monitor API response times and adjust \`includedData\` usage\n`;
77
+ report += `5. **Backward Compatibility:** Ensure V0 fallback works for unsupported operations\n\n`;
78
+
79
+ report += `## πŸ“š Additional Resources\n\n`;
80
+ report += `- [SP-API Orders V1 Documentation](https://developer-docs.amazon.com/sp-api/docs/orders-api-v1-reference)\n`;
81
+ report += `- [Migration Guide](https://developer-docs.amazon.com/sp-api/docs/orders-api-v0-to-v1-migration-guide)\n`;
82
+ report += `- Use \`getMigrationGuide\` tool for detailed attribute mappings\n\n`;
83
+
84
+ return report;
85
+ }
@@ -0,0 +1,75 @@
1
+ import { createWriteStream, existsSync, mkdirSync, WriteStream } from "fs";
2
+ import { join } from "path";
3
+
4
+ export interface LogEntry {
5
+ timestamp: string;
6
+ level: "INFO" | "ERROR" | "WARN" | "DEBUG";
7
+ message: string;
8
+ data: any;
9
+ pid: number;
10
+ }
11
+
12
+ export class Logger {
13
+ private logStream: WriteStream;
14
+ private logPath: string;
15
+
16
+ constructor(logFile: string = "dev-mcp.log") {
17
+ // Create logs directory under current working directory
18
+ const logsDir = join(process.cwd(), "logs");
19
+
20
+ // Ensure logs directory exists
21
+ if (!existsSync(logsDir)) {
22
+ mkdirSync(logsDir, { recursive: true });
23
+ }
24
+
25
+ // Create log file path
26
+ this.logPath = join(logsDir, logFile);
27
+
28
+ // Create write stream
29
+ this.logStream = createWriteStream(this.logPath, { flags: "a" });
30
+
31
+ // Log initialization
32
+ this.log("INFO", "Logger initialized", {
33
+ logPath: this.logPath,
34
+ cwd: process.cwd(),
35
+ });
36
+ }
37
+
38
+ private log(
39
+ level: LogEntry["level"],
40
+ message: string,
41
+ data: any = null,
42
+ ): void {
43
+ const timestamp = new Date().toISOString();
44
+ const logEntry: LogEntry = {
45
+ timestamp,
46
+ level,
47
+ message,
48
+ data,
49
+ pid: process.pid,
50
+ };
51
+
52
+ const logLine = JSON.stringify(logEntry);
53
+
54
+ // Write to log file
55
+ this.logStream.write(logLine + "\n");
56
+ }
57
+
58
+ info(message: string, data?: any): void {
59
+ this.log("INFO", message, data);
60
+ }
61
+
62
+ error(message: string, data?: any): void {
63
+ this.log("ERROR", message, data);
64
+ }
65
+
66
+ warn(message: string, data?: any): void {
67
+ this.log("WARN", message, data);
68
+ }
69
+
70
+ debug(message: string, data?: any): void {
71
+ this.log("DEBUG", message, data);
72
+ }
73
+ }
74
+
75
+ export const logger = new Logger();
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Zod schemas for Migration Assistant tool
3
+ */
4
+
5
+ import { z } from "zod";
6
+
7
+ export const migrationAssistantSchema = z.object({
8
+ source_code: z
9
+ .string()
10
+ .optional()
11
+ .describe(
12
+ "Your existing API integration code (optional - if not provided, returns general migration guidance)",
13
+ ),
14
+ source_version: z
15
+ .string()
16
+ .describe("Current API version (e.g., 'orders-v0')"),
17
+ target_version: z
18
+ .string()
19
+ .describe("Target API version (e.g., 'orders-2026-01-01')"),
20
+ language: z
21
+ .string()
22
+ .optional()
23
+ .describe("Programming language of the source code"),
24
+ analysis_only: z
25
+ .boolean()
26
+ .default(false)
27
+ .describe("Only analyze without generating code (default: false)"),
28
+ });
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Zod schemas for Orders API tools
3
+ */
4
+
5
+ import { z } from "zod";
6
+
7
+ // Orders API V1 Schemas
8
+ export const searchOrdersSchema = z.object({
9
+ createdAfter: z
10
+ .string()
11
+ .optional()
12
+ .describe(
13
+ "ISO 8601 date for orders created after this time (e.g., '2025-10-01T00:00:00Z')",
14
+ ),
15
+ createdBefore: z
16
+ .string()
17
+ .optional()
18
+ .describe("ISO 8601 date for orders created before this time"),
19
+ lastUpdatedAfter: z
20
+ .string()
21
+ .optional()
22
+ .describe("ISO 8601 date for orders last updated after this time"),
23
+ lastUpdatedBefore: z
24
+ .string()
25
+ .optional()
26
+ .describe("ISO 8601 date for orders last updated before this time"),
27
+ fulfillmentStatuses: z
28
+ .array(
29
+ z.enum([
30
+ "PENDING",
31
+ "UNSHIPPED",
32
+ "PARTIALLY_SHIPPED",
33
+ "SHIPPED",
34
+ "CANCELLED",
35
+ "UNFULFILLABLE",
36
+ ]),
37
+ )
38
+ .optional()
39
+ .describe("Filter by fulfillment status"),
40
+ marketplaceIds: z
41
+ .array(z.string())
42
+ .default(["ATVPDKIKX0DER"])
43
+ .describe("Marketplace IDs to search in (e.g., ['ATVPDKIKX0DER' for US])"),
44
+ fulfilledBy: z
45
+ .array(z.enum(["AMAZON", "MERCHANT"]))
46
+ .optional()
47
+ .describe("Filter by fulfillment channel"),
48
+ maxResultsPerPage: z
49
+ .number()
50
+ .min(1)
51
+ .max(100)
52
+ .default(50)
53
+ .describe("Number of results per page (1-100)"),
54
+ includedData: z
55
+ .array(
56
+ z.enum([
57
+ "BUYER",
58
+ "RECIPIENT",
59
+ "PROCEEDS",
60
+ "EXPENSE",
61
+ "PROMOTION",
62
+ "CANCELLATION",
63
+ "FULFILLMENT",
64
+ "PACKAGES",
65
+ ]),
66
+ )
67
+ .optional()
68
+ .describe("Data sets to include in response"),
69
+ paginationToken: z
70
+ .string()
71
+ .optional()
72
+ .describe("Token for pagination from previous response"),
73
+ });
74
+
75
+ export const getOrderSchema = z.object({
76
+ orderId: z.string().describe("Amazon order ID (e.g., '123-4567890-1234567')"),
77
+ includedData: z
78
+ .array(
79
+ z.enum([
80
+ "BUYER",
81
+ "RECIPIENT",
82
+ "PROCEEDS",
83
+ "EXPENSE",
84
+ "PROMOTION",
85
+ "CANCELLATION",
86
+ "FULFILLMENT",
87
+ "PACKAGES",
88
+ ]),
89
+ )
90
+ .optional()
91
+ .describe("Data sets to include in response"),
92
+ });
93
+
94
+ export const cancelOrderSchema = z.object({
95
+ orderId: z.string().describe("Amazon order ID to cancel"),
96
+ cancelReasonCode: z
97
+ .enum([
98
+ "NO_INVENTORY",
99
+ "BUYER_CANCELLED",
100
+ "SHIPPING_ADDRESS_UNDELIVERABLE",
101
+ "CUSTOMER_EXCHANGE",
102
+ "PRICING_ERROR",
103
+ ])
104
+ .describe("Reason for cancellation"),
105
+ });
106
+
107
+ // Orders API V0 Schemas
108
+ export const updateShipmentStatusSchema = z.object({
109
+ orderId: z.string().describe("Amazon order ID"),
110
+ marketplaceId: z
111
+ .string()
112
+ .default("ATVPDKIKX0DER")
113
+ .describe("Marketplace ID (e.g., 'ATVPDKIKX0DER' for US)"),
114
+ shipmentStatus: z
115
+ .enum(["ReadyForPickup", "PickedUp", "RefusedPickup"])
116
+ .describe("New shipment status"),
117
+ orderItems: z
118
+ .array(
119
+ z.object({
120
+ orderItemId: z.string().optional().describe("Order item ID"),
121
+ quantity: z.number().optional().describe("Quantity"),
122
+ }),
123
+ )
124
+ .optional()
125
+ .describe("Optional order items to update"),
126
+ });
127
+
128
+ export const updateVerificationStatusSchema = z.object({
129
+ orderId: z.string().describe("Amazon order ID"),
130
+ marketplaceId: z
131
+ .string()
132
+ .default("ATVPDKIKX0DER")
133
+ .describe("Marketplace ID (e.g., 'ATVPDKIKX0DER' for US)"),
134
+ regulatedOrderVerificationStatus: z.object({
135
+ status: z
136
+ .enum(["Approved", "Rejected", "Expired", "Cancelled"])
137
+ .describe("Verification status"),
138
+ validUntil: z
139
+ .string()
140
+ .optional()
141
+ .describe("ISO 8601 date when status is valid until"),
142
+ rejectionReason: z
143
+ .object({
144
+ rejectionReasonId: z.string().describe("Rejection reason ID"),
145
+ rejectionReasonDescription: z
146
+ .string()
147
+ .describe("Rejection reason description"),
148
+ })
149
+ .optional()
150
+ .describe("Rejection reason (required if status is 'Rejected')"),
151
+ }),
152
+ });
153
+
154
+ export const confirmShipmentSchema = z.object({
155
+ orderId: z.string().describe("Amazon order ID"),
156
+ marketplaceId: z
157
+ .string()
158
+ .default("ATVPDKIKX0DER")
159
+ .describe("Marketplace ID (e.g., 'ATVPDKIKX0DER' for US)"),
160
+ packageDetail: z.object({
161
+ packageReferenceId: z.string().describe("Package reference ID"),
162
+ carrierCode: z
163
+ .string()
164
+ .describe("Carrier code (e.g., 'UPS', 'FEDEX', 'USPS')"),
165
+ shippingMethod: z.string().optional().describe("Shipping method"),
166
+ trackingNumber: z.string().optional().describe("Tracking number"),
167
+ shipDate: z
168
+ .string()
169
+ .describe("ISO 8601 ship date (e.g., '2025-10-01T00:00:00Z')"),
170
+ carrierName: z.string().optional().describe("Carrier name"),
171
+ shipFrom: z
172
+ .object({
173
+ name: z.string().describe("Sender name"),
174
+ addressLine1: z.string().describe("Address line 1"),
175
+ addressLine2: z.string().optional().describe("Address line 2"),
176
+ addressLine3: z.string().optional().describe("Address line 3"),
177
+ city: z.string().describe("City"),
178
+ county: z.string().optional().describe("County"),
179
+ district: z.string().optional().describe("District"),
180
+ stateOrRegion: z.string().describe("State or region"),
181
+ postalCode: z.string().describe("Postal code"),
182
+ countryCode: z.string().describe("Country code (e.g., 'US')"),
183
+ phone: z.string().describe("Phone number"),
184
+ })
185
+ .optional()
186
+ .describe("Ship from address"),
187
+ }),
188
+ codCollectionMethod: z
189
+ .enum(["DirectPayment"])
190
+ .optional()
191
+ .describe("Cash on delivery collection method"),
192
+ });
193
+
194
+ export const getOrderRegulatedInfoSchema = z.object({
195
+ orderId: z.string().describe("Amazon order ID"),
196
+ });