n8n-nodes-amazon-selling-partner-dnangelx 0.0.2 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/credentials/AmazonSpApi.credentials.d.ts +9 -0
- package/dist/credentials/AmazonSpApi.credentials.js +212 -0
- package/dist/credentials/AmazonSpApi.credentials.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/AmazonSellingPartner.node.d.ts +1 -1
- package/dist/nodes/AmazonSellingPartner/AmazonSellingPartner.node.js +142 -33
- package/dist/nodes/AmazonSellingPartner/AmazonSellingPartner.node.js.map +1 -1
- package/dist/nodes/AmazonSellingPartner/AmazonSellingPartner.node.json +1 -1
- package/dist/nodes/AmazonSellingPartner/amazonSpApi.svg +25 -0
- package/dist/nodes/AmazonSellingPartner/core/AuditLogger.d.ts +67 -0
- package/dist/nodes/AmazonSellingPartner/core/AuditLogger.js +296 -0
- package/dist/nodes/AmazonSellingPartner/core/AuditLogger.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/core/ErrorHandler.d.ts +6 -0
- package/dist/nodes/AmazonSellingPartner/core/ErrorHandler.js +82 -0
- package/dist/nodes/AmazonSellingPartner/core/ErrorHandler.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/core/MetricsCollector.d.ts +48 -0
- package/dist/nodes/AmazonSellingPartner/core/MetricsCollector.js +181 -0
- package/dist/nodes/AmazonSellingPartner/core/MetricsCollector.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/core/RateLimiter.d.ts +43 -0
- package/dist/nodes/AmazonSellingPartner/core/RateLimiter.js +260 -0
- package/dist/nodes/AmazonSellingPartner/core/RateLimiter.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/core/SecurityValidator.d.ts +35 -0
- package/dist/nodes/AmazonSellingPartner/core/SecurityValidator.js +383 -0
- package/dist/nodes/AmazonSellingPartner/core/SecurityValidator.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/core/rateLimitConfig.d.ts +14 -0
- package/dist/nodes/AmazonSellingPartner/core/rateLimitConfig.js +93 -0
- package/dist/nodes/AmazonSellingPartner/core/rateLimitConfig.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Analytics.description.d.ts +3 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Analytics.description.js +27 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Analytics.description.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/DataKiosk.description.d.ts +3 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/DataKiosk.description.js +196 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/DataKiosk.description.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Finance.description.d.ts +3 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Finance.description.js +341 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Finance.description.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Invoices.description.d.ts +3 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Invoices.description.js +312 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Invoices.description.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Listings.description.d.ts +3 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Listings.description.js +292 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Listings.description.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Orders.description.d.ts +3 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Orders.description.js +202 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Orders.description.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Reports.description.d.ts +3 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Reports.description.js +289 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Reports.description.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Shipments.description.d.ts +3 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Shipments.description.js +181 -0
- package/dist/nodes/AmazonSellingPartner/descriptions/Shipments.description.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/helpers/LwaClient.d.ts +10 -0
- package/dist/nodes/AmazonSellingPartner/helpers/LwaClient.js +79 -0
- package/dist/nodes/AmazonSellingPartner/helpers/LwaClient.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/helpers/RdtClient.d.ts +11 -0
- package/dist/nodes/AmazonSellingPartner/helpers/RdtClient.js +66 -0
- package/dist/nodes/AmazonSellingPartner/helpers/RdtClient.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/helpers/ReportDownloader.d.ts +16 -0
- package/dist/nodes/AmazonSellingPartner/helpers/ReportDownloader.js +65 -0
- package/dist/nodes/AmazonSellingPartner/helpers/ReportDownloader.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/helpers/SigV4Signer.d.ts +4 -0
- package/dist/nodes/AmazonSellingPartner/helpers/SigV4Signer.js +76 -0
- package/dist/nodes/AmazonSellingPartner/helpers/SigV4Signer.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/helpers/SpApiRequest.d.ts +23 -0
- package/dist/nodes/AmazonSellingPartner/helpers/SpApiRequest.js +208 -0
- package/dist/nodes/AmazonSellingPartner/helpers/SpApiRequest.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/helpers/downloadPresigned.d.ts +4 -0
- package/dist/nodes/AmazonSellingPartner/helpers/downloadPresigned.js +16 -0
- package/dist/nodes/AmazonSellingPartner/helpers/downloadPresigned.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/helpers/graphql.d.ts +1 -0
- package/dist/nodes/AmazonSellingPartner/helpers/graphql.js +13 -0
- package/dist/nodes/AmazonSellingPartner/helpers/graphql.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/operations/Analytics.operations.d.ts +2 -0
- package/dist/nodes/AmazonSellingPartner/operations/Analytics.operations.js +66 -0
- package/dist/nodes/AmazonSellingPartner/operations/Analytics.operations.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/operations/DataKiosk.operations.d.ts +2 -0
- package/dist/nodes/AmazonSellingPartner/operations/DataKiosk.operations.js +249 -0
- package/dist/nodes/AmazonSellingPartner/operations/DataKiosk.operations.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/operations/Finance.operations.d.ts +2 -0
- package/dist/nodes/AmazonSellingPartner/operations/Finance.operations.js +444 -0
- package/dist/nodes/AmazonSellingPartner/operations/Finance.operations.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/operations/Invoices.operations.d.ts +4 -0
- package/dist/nodes/AmazonSellingPartner/operations/Invoices.operations.js +224 -0
- package/dist/nodes/AmazonSellingPartner/operations/Invoices.operations.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/operations/Listings.operations.d.ts +2 -0
- package/dist/nodes/AmazonSellingPartner/operations/Listings.operations.js +426 -0
- package/dist/nodes/AmazonSellingPartner/operations/Listings.operations.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/operations/Orders.operations.d.ts +2 -0
- package/dist/nodes/AmazonSellingPartner/operations/Orders.operations.js +169 -0
- package/dist/nodes/AmazonSellingPartner/operations/Orders.operations.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/operations/Reports.operations.d.ts +2 -0
- package/dist/nodes/AmazonSellingPartner/operations/Reports.operations.js +434 -0
- package/dist/nodes/AmazonSellingPartner/operations/Reports.operations.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/operations/Shipments.operations.d.ts +2 -0
- package/dist/nodes/AmazonSellingPartner/operations/Shipments.operations.js +78 -0
- package/dist/nodes/AmazonSellingPartner/operations/Shipments.operations.js.map +1 -0
- package/dist/nodes/AmazonSellingPartner/operations/analytics/constants.d.ts +126 -0
- package/dist/nodes/AmazonSellingPartner/operations/analytics/constants.js +213 -0
- package/dist/nodes/AmazonSellingPartner/operations/analytics/constants.js.map +1 -0
- package/dist/package.json +12 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -3
- package/dist/credentials/AmazonSellingPartnerOAuth2Api.credentials.d.ts +0 -17
- package/dist/credentials/AmazonSellingPartnerOAuth2Api.credentials.js +0 -177
- package/dist/credentials/AmazonSellingPartnerOAuth2Api.credentials.js.map +0 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGstReport = getGstReport;
|
|
4
|
+
exports.getVatInvoiceReport = getVatInvoiceReport;
|
|
5
|
+
exports.getVatInvoicePdfLinks = getVatInvoicePdfLinks;
|
|
6
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
7
|
+
const SpApiRequest_1 = require("../helpers/SpApiRequest");
|
|
8
|
+
const ReportDownloader_1 = require("../helpers/ReportDownloader");
|
|
9
|
+
async function getGstReport(index) {
|
|
10
|
+
const reportType = this.getNodeParameter('reportType', index);
|
|
11
|
+
const marketplaceId = this.getNodeParameter('marketplaceId', index);
|
|
12
|
+
const outputOptions = this.getNodeParameter('outputOptions', index, {});
|
|
13
|
+
const advancedOptions = this.getNodeParameter('advancedOptions', index, {});
|
|
14
|
+
if (marketplaceId !== 'A21TJRUUN4KGV') {
|
|
15
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'GST reports are only available for Amazon.in marketplace (A21TJRUUN4KGV)');
|
|
16
|
+
}
|
|
17
|
+
const reportRequest = {
|
|
18
|
+
reportType,
|
|
19
|
+
marketplaceIds: [marketplaceId],
|
|
20
|
+
};
|
|
21
|
+
const customReportTypes = ['GET_GST_MTR_B2B_CUSTOM', 'GET_GST_MTR_B2C_CUSTOM', 'GET_GST_STR_ADHOC'];
|
|
22
|
+
if (customReportTypes.includes(reportType)) {
|
|
23
|
+
const startDate = this.getNodeParameter('startDate', index);
|
|
24
|
+
const endDate = this.getNodeParameter('endDate', index);
|
|
25
|
+
if (!startDate || !endDate) {
|
|
26
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Start date and end date are required for custom GST reports');
|
|
27
|
+
}
|
|
28
|
+
reportRequest.dataStartTime = new Date(startDate).toISOString();
|
|
29
|
+
reportRequest.dataEndTime = new Date(endDate).toISOString();
|
|
30
|
+
const daysDiff = (new Date(endDate).getTime() - new Date(startDate).getTime()) / (1000 * 60 * 60 * 24);
|
|
31
|
+
if (daysDiff > 31) {
|
|
32
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Date range for GST reports cannot exceed 31 days');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return await processReportRequest.call(this, reportRequest, outputOptions, advancedOptions);
|
|
36
|
+
}
|
|
37
|
+
async function getVatInvoiceReport(index) {
|
|
38
|
+
const reportType = this.getNodeParameter('reportType', index);
|
|
39
|
+
const marketplaceId = this.getNodeParameter('marketplaceId', index);
|
|
40
|
+
const reportOptions = this.getNodeParameter('reportOptions', index, {});
|
|
41
|
+
const outputOptions = this.getNodeParameter('outputOptions', index, {});
|
|
42
|
+
const advancedOptions = this.getNodeParameter('advancedOptions', index, {});
|
|
43
|
+
const euUkMarketplaces = ['A1F83G8C2ARO7P', 'A1PA6795UKMFR9', 'A13V1IB3VIYZZH', 'APJ6JRA9NG5V4', 'A1RKKUPIHCS9HS', 'A1805IZSGTT6HS', 'A2NODRKZP88ZB9', 'A1C3SOZRARQ6R3'];
|
|
44
|
+
if (!euUkMarketplaces.includes(marketplaceId)) {
|
|
45
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'VAT invoice reports are only available for EU/UK marketplaces');
|
|
46
|
+
}
|
|
47
|
+
const reportRequest = {
|
|
48
|
+
reportType,
|
|
49
|
+
marketplaceIds: [marketplaceId],
|
|
50
|
+
};
|
|
51
|
+
if (!reportOptions.pendingInvoices || reportOptions.all) {
|
|
52
|
+
const startDate = this.getNodeParameter('startDate', index);
|
|
53
|
+
const endDate = this.getNodeParameter('endDate', index);
|
|
54
|
+
if (!startDate || !endDate) {
|
|
55
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Start date and end date are required when not using pending invoices only');
|
|
56
|
+
}
|
|
57
|
+
reportRequest.dataStartTime = new Date(startDate).toISOString();
|
|
58
|
+
reportRequest.dataEndTime = new Date(endDate).toISOString();
|
|
59
|
+
const daysDiff = (new Date(endDate).getTime() - new Date(startDate).getTime()) / (1000 * 60 * 60 * 24);
|
|
60
|
+
if (daysDiff > 30) {
|
|
61
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Date range for VAT invoice reports cannot exceed 30 days');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (reportOptions.pendingInvoices && !reportOptions.all) {
|
|
65
|
+
reportRequest.reportOptions = { PendingInvoices: 'true' };
|
|
66
|
+
}
|
|
67
|
+
else if (reportOptions.all) {
|
|
68
|
+
reportRequest.reportOptions = { All: 'true' };
|
|
69
|
+
}
|
|
70
|
+
return await processReportRequest.call(this, reportRequest, outputOptions, advancedOptions);
|
|
71
|
+
}
|
|
72
|
+
async function getVatInvoicePdfLinks(index) {
|
|
73
|
+
const marketplaceId = this.getNodeParameter('marketplaceId', index);
|
|
74
|
+
const outputOptions = this.getNodeParameter('outputOptions', index, {});
|
|
75
|
+
const advancedOptions = this.getNodeParameter('advancedOptions', index, {});
|
|
76
|
+
const reportRequest = {
|
|
77
|
+
reportType: 'SC_VAT_TAX_REPORT',
|
|
78
|
+
marketplaceIds: [marketplaceId],
|
|
79
|
+
};
|
|
80
|
+
return await processReportRequest.call(this, reportRequest, outputOptions, advancedOptions);
|
|
81
|
+
}
|
|
82
|
+
async function processReportRequest(reportRequest, outputOptions, advancedOptions) {
|
|
83
|
+
const maxPollTimeMinutes = advancedOptions.maxPollTimeMinutes || 10;
|
|
84
|
+
const pollIntervalSeconds = advancedOptions.pollIntervalSeconds || 30;
|
|
85
|
+
const maxPollTime = maxPollTimeMinutes * 60 * 1000;
|
|
86
|
+
const pollInterval = pollIntervalSeconds * 1000;
|
|
87
|
+
try {
|
|
88
|
+
const reportResponse = await SpApiRequest_1.SpApiRequest.makeRequest(this, {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
endpoint: '/reports/2021-06-30/reports',
|
|
91
|
+
body: reportRequest,
|
|
92
|
+
});
|
|
93
|
+
const reportId = reportResponse.data.reportId;
|
|
94
|
+
const startTime = Date.now();
|
|
95
|
+
let reportStatus;
|
|
96
|
+
do {
|
|
97
|
+
if (Date.now() - startTime > maxPollTime) {
|
|
98
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Report generation timed out after ${maxPollTimeMinutes} minutes. The report may still be processing in Amazon's system.`, {
|
|
99
|
+
description: 'Try increasing the max poll time or check the report status later manually'
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (Date.now() - startTime > 0) {
|
|
103
|
+
await new Promise(resolve => setTimeout(resolve, pollInterval));
|
|
104
|
+
}
|
|
105
|
+
const statusResponse = await SpApiRequest_1.SpApiRequest.makeRequest(this, {
|
|
106
|
+
method: 'GET',
|
|
107
|
+
endpoint: `/reports/2021-06-30/reports/${reportId}`,
|
|
108
|
+
});
|
|
109
|
+
reportStatus = statusResponse.data;
|
|
110
|
+
} while (reportStatus.processingStatus === 'IN_QUEUE' || reportStatus.processingStatus === 'IN_PROGRESS');
|
|
111
|
+
if (reportStatus.processingStatus === 'CANCELLED') {
|
|
112
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Report generation was cancelled by Amazon');
|
|
113
|
+
}
|
|
114
|
+
if (reportStatus.processingStatus === 'FATAL') {
|
|
115
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Report generation failed with a fatal error');
|
|
116
|
+
}
|
|
117
|
+
if (!reportStatus.reportDocumentId) {
|
|
118
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Report completed but no document ID was provided');
|
|
119
|
+
}
|
|
120
|
+
const documentResponse = await SpApiRequest_1.SpApiRequest.makeRequest(this, {
|
|
121
|
+
method: 'GET',
|
|
122
|
+
endpoint: `/reports/2021-06-30/documents/${reportStatus.reportDocumentId}`,
|
|
123
|
+
});
|
|
124
|
+
const document = documentResponse.data;
|
|
125
|
+
const reportData = await ReportDownloader_1.ReportDownloader.downloadReportDocument(document, this.getNode().id);
|
|
126
|
+
return await processReportData.call(this, reportStatus, reportRequest, reportData, outputOptions);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error instanceof n8n_workflow_1.NodeOperationError) {
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to process invoice report: ${error instanceof Error ? error.message : 'Unknown error'}`, {
|
|
133
|
+
description: 'Check your credentials and try again. Some reports may take longer to generate.'
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async function processReportData(reportStatus, reportRequest, reportData, outputOptions) {
|
|
138
|
+
const returnBinary = outputOptions.returnBinary !== false;
|
|
139
|
+
const parseToJson = outputOptions.parseToJson === true;
|
|
140
|
+
const binaryPropertyName = outputOptions.binaryPropertyName || 'data';
|
|
141
|
+
if (returnBinary && !parseToJson) {
|
|
142
|
+
const binaryData = await this.helpers.prepareBinaryData(reportData, `${reportRequest.reportType}_${new Date().toISOString().split('T')[0]}.${getFileExtension(reportRequest.reportType)}`, getContentType(reportRequest.reportType));
|
|
143
|
+
return [
|
|
144
|
+
{
|
|
145
|
+
json: {
|
|
146
|
+
reportId: reportStatus.reportId,
|
|
147
|
+
reportType: reportStatus.reportType,
|
|
148
|
+
processingTime: reportStatus.processingEndTime ?
|
|
149
|
+
new Date(reportStatus.processingEndTime).getTime() - new Date(reportStatus.createdTime).getTime() : null,
|
|
150
|
+
fileSize: reportData.length,
|
|
151
|
+
success: true,
|
|
152
|
+
},
|
|
153
|
+
binary: {
|
|
154
|
+
[binaryPropertyName]: binaryData,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
else if (parseToJson && (reportRequest.reportType.includes('FLAT_FILE') || reportRequest.reportType.includes('GST'))) {
|
|
160
|
+
const textData = reportData.toString('utf-8');
|
|
161
|
+
const lines = textData.trim().split('\n');
|
|
162
|
+
if (lines.length === 0) {
|
|
163
|
+
return [{
|
|
164
|
+
json: {
|
|
165
|
+
reportId: reportStatus.reportId,
|
|
166
|
+
reportType: reportStatus.reportType,
|
|
167
|
+
message: 'Report is empty',
|
|
168
|
+
data: [],
|
|
169
|
+
},
|
|
170
|
+
}];
|
|
171
|
+
}
|
|
172
|
+
const delimiter = textData.includes('\t') ? '\t' : ',';
|
|
173
|
+
const headers = lines[0].split(delimiter);
|
|
174
|
+
const rows = lines.slice(1).map(line => {
|
|
175
|
+
const values = line.split(delimiter);
|
|
176
|
+
const row = {};
|
|
177
|
+
headers.forEach((header, index) => {
|
|
178
|
+
var _a;
|
|
179
|
+
row[header.trim()] = ((_a = values[index]) === null || _a === void 0 ? void 0 : _a.trim()) || '';
|
|
180
|
+
});
|
|
181
|
+
return row;
|
|
182
|
+
});
|
|
183
|
+
return [{
|
|
184
|
+
json: {
|
|
185
|
+
reportId: reportStatus.reportId,
|
|
186
|
+
reportType: reportStatus.reportType,
|
|
187
|
+
processingTime: reportStatus.processingEndTime ?
|
|
188
|
+
new Date(reportStatus.processingEndTime).getTime() - new Date(reportStatus.createdTime).getTime() : null,
|
|
189
|
+
recordCount: rows.length,
|
|
190
|
+
data: rows,
|
|
191
|
+
success: true,
|
|
192
|
+
},
|
|
193
|
+
}];
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
return [{
|
|
197
|
+
json: {
|
|
198
|
+
reportId: reportStatus.reportId,
|
|
199
|
+
reportType: reportStatus.reportType,
|
|
200
|
+
processingTime: reportStatus.processingEndTime ?
|
|
201
|
+
new Date(reportStatus.processingEndTime).getTime() - new Date(reportStatus.createdTime).getTime() : null,
|
|
202
|
+
content: reportData.toString('utf-8'),
|
|
203
|
+
fileSize: reportData.length,
|
|
204
|
+
success: true,
|
|
205
|
+
},
|
|
206
|
+
}];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function getFileExtension(reportType) {
|
|
210
|
+
if (reportType.includes('XML')) {
|
|
211
|
+
return 'xml';
|
|
212
|
+
}
|
|
213
|
+
if (reportType.includes('FLAT_FILE') || reportType.includes('GST')) {
|
|
214
|
+
return 'txt';
|
|
215
|
+
}
|
|
216
|
+
return 'txt';
|
|
217
|
+
}
|
|
218
|
+
function getContentType(reportType) {
|
|
219
|
+
if (reportType.includes('XML')) {
|
|
220
|
+
return 'application/xml';
|
|
221
|
+
}
|
|
222
|
+
return 'text/plain';
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=Invoices.operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Invoices.operations.js","sourceRoot":"","sources":["../../../../nodes/AmazonSellingPartner/operations/Invoices.operations.ts"],"names":[],"mappings":";;AAqCA,oCAkDC;AAED,kDA0DC;AAED,sDAeC;AApKD,+CAAyF;AACzF,0DAAuD;AACvD,kEAA+D;AAmCxD,KAAK,UAAU,YAAY,CAEjC,KAAa;IAEb,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,KAAK,CAAW,CAAC;IACxE,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,KAAK,CAAW,CAAC;IAC9E,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,KAAK,EAAE,EAAE,CAAQ,CAAC;IAC/E,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,KAAK,EAAE,EAAE,CAAQ,CAAC;IAGnF,IAAI,aAAa,KAAK,eAAe,EAAE,CAAC;QACvC,MAAM,IAAI,iCAAkB,CAC3B,IAAI,CAAC,OAAO,EAAE,EACd,0EAA0E,CAC1E,CAAC;IACH,CAAC;IAGD,MAAM,aAAa,GAAkB;QACpC,UAAU;QACV,cAAc,EAAE,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,CAAC;IACD,IAAI,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACpE,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,cAAc,CAAC,UAAkB;IACzC,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,iBAAiB,CAAC;IAC1B,CAAC;IACD,OAAO,YAAY,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeListingsOperation = executeListingsOperation;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const SpApiRequest_1 = require("../helpers/SpApiRequest");
|
|
6
|
+
const SecurityValidator_1 = require("../core/SecurityValidator");
|
|
7
|
+
const MetricsCollector_1 = require("../core/MetricsCollector");
|
|
8
|
+
const AuditLogger_1 = require("../core/AuditLogger");
|
|
9
|
+
async function extractSellerId() {
|
|
10
|
+
const nodeId = this.getNode().id;
|
|
11
|
+
try {
|
|
12
|
+
const credentials = await this.getCredentials('amazonSpApi');
|
|
13
|
+
if (credentials.sellerId && typeof credentials.sellerId === 'string') {
|
|
14
|
+
return credentials.sellerId;
|
|
15
|
+
}
|
|
16
|
+
const response = await SpApiRequest_1.SpApiRequest.makeRequest(this, {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
endpoint: '/sellers/v1/marketplaceParticipations',
|
|
19
|
+
});
|
|
20
|
+
if (response.data && response.data.length > 0) {
|
|
21
|
+
const sellerId = response.data[0].sellerId;
|
|
22
|
+
if (sellerId) {
|
|
23
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
24
|
+
nodeId,
|
|
25
|
+
action: 'seller_id_extraction',
|
|
26
|
+
resource: 'credentials',
|
|
27
|
+
details: { sellerId, source: 'marketplace_participations' },
|
|
28
|
+
severity: 'low',
|
|
29
|
+
source: 'system',
|
|
30
|
+
outcome: 'success'
|
|
31
|
+
});
|
|
32
|
+
return sellerId;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw new Error('Could not auto-extract seller ID. Please ensure your SP-API credentials include sellerId or have marketplace participations configured.');
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
39
|
+
nodeId,
|
|
40
|
+
action: 'seller_id_extraction',
|
|
41
|
+
resource: 'credentials',
|
|
42
|
+
details: {
|
|
43
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
44
|
+
source: 'auto_extraction'
|
|
45
|
+
},
|
|
46
|
+
severity: 'high',
|
|
47
|
+
source: 'system',
|
|
48
|
+
outcome: 'failure'
|
|
49
|
+
});
|
|
50
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to extract seller ID: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function formatListingForOutput(listing, marketplaceId) {
|
|
54
|
+
const output = {
|
|
55
|
+
asin: listing.asin,
|
|
56
|
+
sku: listing.sku,
|
|
57
|
+
};
|
|
58
|
+
if (listing.summaries) {
|
|
59
|
+
const relevantSummary = marketplaceId
|
|
60
|
+
? listing.summaries.find(s => s.marketplaceId === marketplaceId)
|
|
61
|
+
: listing.summaries[0];
|
|
62
|
+
if (relevantSummary) {
|
|
63
|
+
output.itemName = relevantSummary.itemName;
|
|
64
|
+
output.conditionType = relevantSummary.conditionType;
|
|
65
|
+
output.status = relevantSummary.status;
|
|
66
|
+
output.fulfillmentChannels = relevantSummary.fulfillmentChannels;
|
|
67
|
+
output.createdDate = relevantSummary.createdDate;
|
|
68
|
+
output.lastUpdatedDate = relevantSummary.lastUpdatedDate;
|
|
69
|
+
output.mainImage = relevantSummary.mainImage;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (listing.attributes && marketplaceId) {
|
|
73
|
+
const relevantAttributes = listing.attributes.find(a => a.marketplaceId === marketplaceId);
|
|
74
|
+
if (relevantAttributes) {
|
|
75
|
+
output.attributes = relevantAttributes.attributes.reduce((acc, attr) => {
|
|
76
|
+
acc[attr.attributeName] = attr.attributeValue;
|
|
77
|
+
return acc;
|
|
78
|
+
}, {});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (listing.offers && marketplaceId) {
|
|
82
|
+
const relevantOffers = listing.offers.find(o => o.marketplaceId === marketplaceId);
|
|
83
|
+
if (relevantOffers) {
|
|
84
|
+
output.offers = relevantOffers.offers;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (listing.issues && marketplaceId) {
|
|
88
|
+
const relevantIssues = listing.issues.find(i => i.marketplaceId === marketplaceId);
|
|
89
|
+
if (relevantIssues) {
|
|
90
|
+
output.issues = relevantIssues.issues;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (listing.fulfillmentAvailability && marketplaceId) {
|
|
94
|
+
const relevantAvailability = listing.fulfillmentAvailability.find(f => f.marketplaceId === marketplaceId);
|
|
95
|
+
if (relevantAvailability) {
|
|
96
|
+
output.fulfillmentAvailability = relevantAvailability.fulfillmentAvailability;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (listing.procurement && marketplaceId) {
|
|
100
|
+
const relevantProcurement = listing.procurement.find(p => p.marketplaceId === marketplaceId);
|
|
101
|
+
if (relevantProcurement) {
|
|
102
|
+
output.procurement = relevantProcurement;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
output.marketplaceId = marketplaceId;
|
|
106
|
+
output.extractedAt = new Date().toISOString();
|
|
107
|
+
return output;
|
|
108
|
+
}
|
|
109
|
+
async function executeListingsOperation(operation, itemIndex) {
|
|
110
|
+
var _a;
|
|
111
|
+
const returnData = [];
|
|
112
|
+
const nodeId = this.getNode().id;
|
|
113
|
+
if (operation === 'listAsins') {
|
|
114
|
+
try {
|
|
115
|
+
const startTime = Date.now();
|
|
116
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
117
|
+
nodeId,
|
|
118
|
+
action: 'operation_start',
|
|
119
|
+
resource: 'listings',
|
|
120
|
+
details: { operation: 'listAsins', itemIndex },
|
|
121
|
+
severity: 'low',
|
|
122
|
+
source: 'user',
|
|
123
|
+
outcome: 'success'
|
|
124
|
+
});
|
|
125
|
+
const marketplaceIds = this.getNodeParameter('marketplaceIds', itemIndex);
|
|
126
|
+
const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
|
|
127
|
+
const includedData = additionalOptions.includedData || ['summaries', 'attributes', 'offers'];
|
|
128
|
+
const pageSize = additionalOptions.pageSize || 20;
|
|
129
|
+
const returnAll = additionalOptions.returnAll !== false;
|
|
130
|
+
const maxResultsLimit = additionalOptions.maxResultsLimit || 1000;
|
|
131
|
+
const skuFilter = additionalOptions.skuFilter || '';
|
|
132
|
+
const statusFilter = additionalOptions.statusFilter || [];
|
|
133
|
+
const issueLocale = additionalOptions.issueLocale || 'en_US';
|
|
134
|
+
const marketplaceValidation = SecurityValidator_1.securityValidator.validateMarketplaceIds(marketplaceIds, nodeId);
|
|
135
|
+
if (!marketplaceValidation.isValid) {
|
|
136
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid marketplace IDs: ${marketplaceValidation.errors.join(', ')}`);
|
|
137
|
+
}
|
|
138
|
+
if (pageSize < 1 || pageSize > 20) {
|
|
139
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Page size must be between 1 and 20');
|
|
140
|
+
}
|
|
141
|
+
const sellerId = await extractSellerId.call(this);
|
|
142
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
143
|
+
nodeId,
|
|
144
|
+
action: 'seller_id_extracted',
|
|
145
|
+
resource: 'credentials',
|
|
146
|
+
details: { sellerId },
|
|
147
|
+
severity: 'low',
|
|
148
|
+
source: 'system',
|
|
149
|
+
outcome: 'success'
|
|
150
|
+
});
|
|
151
|
+
const allListings = [];
|
|
152
|
+
let nextToken;
|
|
153
|
+
let requestCount = 0;
|
|
154
|
+
let totalProcessed = 0;
|
|
155
|
+
do {
|
|
156
|
+
requestCount++;
|
|
157
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
158
|
+
nodeId,
|
|
159
|
+
action: 'api_request_start',
|
|
160
|
+
resource: 'listings',
|
|
161
|
+
details: {
|
|
162
|
+
requestNumber: requestCount,
|
|
163
|
+
pageSize,
|
|
164
|
+
hasNextToken: !!nextToken,
|
|
165
|
+
totalProcessed
|
|
166
|
+
},
|
|
167
|
+
severity: 'low',
|
|
168
|
+
source: 'system',
|
|
169
|
+
outcome: 'success'
|
|
170
|
+
});
|
|
171
|
+
const queryParams = {
|
|
172
|
+
marketplaceIds: marketplaceIds.join(','),
|
|
173
|
+
includedData: includedData.join(','),
|
|
174
|
+
pageSize: pageSize.toString(),
|
|
175
|
+
};
|
|
176
|
+
if (nextToken) {
|
|
177
|
+
queryParams.pageToken = nextToken;
|
|
178
|
+
}
|
|
179
|
+
if (skuFilter) {
|
|
180
|
+
queryParams.sku = skuFilter;
|
|
181
|
+
}
|
|
182
|
+
if (statusFilter.length > 0) {
|
|
183
|
+
queryParams.status = statusFilter.join(',');
|
|
184
|
+
}
|
|
185
|
+
if (issueLocale) {
|
|
186
|
+
queryParams.issuesLocale = issueLocale;
|
|
187
|
+
}
|
|
188
|
+
const response = await SpApiRequest_1.SpApiRequest.makeRequest(this, {
|
|
189
|
+
method: 'GET',
|
|
190
|
+
endpoint: `/listings/2021-08-01/items/${encodeURIComponent(sellerId)}`,
|
|
191
|
+
query: queryParams,
|
|
192
|
+
});
|
|
193
|
+
const apiData = response.data;
|
|
194
|
+
if (apiData && apiData.listings && apiData.listings.length > 0) {
|
|
195
|
+
allListings.push(...apiData.listings);
|
|
196
|
+
totalProcessed += apiData.listings.length;
|
|
197
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
198
|
+
nodeId,
|
|
199
|
+
action: 'batch_processed',
|
|
200
|
+
resource: 'listings',
|
|
201
|
+
details: {
|
|
202
|
+
batchSize: apiData.listings.length,
|
|
203
|
+
totalProcessed,
|
|
204
|
+
hasNextToken: !!apiData.nextToken
|
|
205
|
+
},
|
|
206
|
+
severity: 'low',
|
|
207
|
+
source: 'system',
|
|
208
|
+
outcome: 'success'
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
nextToken = apiData === null || apiData === void 0 ? void 0 : apiData.nextToken;
|
|
212
|
+
if (totalProcessed >= maxResultsLimit) {
|
|
213
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
214
|
+
nodeId,
|
|
215
|
+
action: 'max_results_reached',
|
|
216
|
+
resource: 'listings',
|
|
217
|
+
details: { maxResultsLimit, totalProcessed },
|
|
218
|
+
severity: 'medium',
|
|
219
|
+
source: 'system',
|
|
220
|
+
outcome: 'warning'
|
|
221
|
+
});
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
if (requestCount >= 100) {
|
|
225
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
226
|
+
nodeId,
|
|
227
|
+
action: 'max_requests_reached',
|
|
228
|
+
resource: 'listings',
|
|
229
|
+
details: { requestCount, totalProcessed },
|
|
230
|
+
severity: 'medium',
|
|
231
|
+
source: 'system',
|
|
232
|
+
outcome: 'warning'
|
|
233
|
+
});
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
} while (nextToken && returnAll);
|
|
237
|
+
const outputData = [];
|
|
238
|
+
if (marketplaceIds.length === 1) {
|
|
239
|
+
allListings.forEach(listing => {
|
|
240
|
+
outputData.push(formatListingForOutput(listing, marketplaceIds[0]));
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
allListings.forEach(listing => {
|
|
245
|
+
marketplaceIds.forEach(marketplaceId => {
|
|
246
|
+
outputData.push(formatListingForOutput(listing, marketplaceId));
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
outputData.forEach(data => {
|
|
251
|
+
returnData.push({
|
|
252
|
+
json: data,
|
|
253
|
+
pairedItem: { item: itemIndex },
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
const duration = Date.now() - startTime;
|
|
257
|
+
MetricsCollector_1.metricsCollector.recordMetric('operation_duration', duration, { operation: 'listAsins' });
|
|
258
|
+
MetricsCollector_1.metricsCollector.recordMetric('api_requests_count', requestCount, { operation: 'listAsins' });
|
|
259
|
+
MetricsCollector_1.metricsCollector.recordMetric('results_count', outputData.length, { operation: 'listAsins' });
|
|
260
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
261
|
+
nodeId,
|
|
262
|
+
action: 'operation_completed',
|
|
263
|
+
resource: 'listings',
|
|
264
|
+
details: {
|
|
265
|
+
operation: 'listAsins',
|
|
266
|
+
itemIndex,
|
|
267
|
+
duration,
|
|
268
|
+
requestCount,
|
|
269
|
+
totalListings: allListings.length,
|
|
270
|
+
outputCount: outputData.length,
|
|
271
|
+
marketplaces: marketplaceIds.length,
|
|
272
|
+
},
|
|
273
|
+
severity: 'low',
|
|
274
|
+
source: 'system',
|
|
275
|
+
outcome: 'success'
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
280
|
+
nodeId,
|
|
281
|
+
action: 'operation_failed',
|
|
282
|
+
resource: 'listings',
|
|
283
|
+
details: {
|
|
284
|
+
operation: 'listAsins',
|
|
285
|
+
itemIndex,
|
|
286
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
287
|
+
},
|
|
288
|
+
severity: 'high',
|
|
289
|
+
source: 'system',
|
|
290
|
+
outcome: 'failure'
|
|
291
|
+
});
|
|
292
|
+
if (error instanceof n8n_workflow_1.NodeOperationError) {
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
296
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Amazon SP-API Listings error: ${errorMessage}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
else if (operation === 'getListingDetails') {
|
|
300
|
+
try {
|
|
301
|
+
const startTime = Date.now();
|
|
302
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
303
|
+
nodeId,
|
|
304
|
+
action: 'operation_start',
|
|
305
|
+
resource: 'listing_details',
|
|
306
|
+
details: { operation: 'getListingDetails', itemIndex },
|
|
307
|
+
severity: 'low',
|
|
308
|
+
source: 'user',
|
|
309
|
+
outcome: 'success'
|
|
310
|
+
});
|
|
311
|
+
const identifierType = this.getNodeParameter('identifierType', itemIndex);
|
|
312
|
+
const marketplaceIds = this.getNodeParameter('marketplaceIds', itemIndex);
|
|
313
|
+
const detailOptions = this.getNodeParameter('detailOptions', itemIndex, {});
|
|
314
|
+
let identifier;
|
|
315
|
+
if (identifierType === 'sku') {
|
|
316
|
+
identifier = this.getNodeParameter('sku', itemIndex);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
identifier = this.getNodeParameter('asin', itemIndex);
|
|
320
|
+
}
|
|
321
|
+
const includedData = detailOptions.includedData || ['summaries', 'attributes', 'offers', 'issues'];
|
|
322
|
+
const issueLocale = detailOptions.issueLocale || 'en_US';
|
|
323
|
+
const marketplaceValidation = SecurityValidator_1.securityValidator.validateMarketplaceIds(marketplaceIds, nodeId);
|
|
324
|
+
if (!marketplaceValidation.isValid) {
|
|
325
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid marketplace IDs: ${marketplaceValidation.errors.join(', ')}`);
|
|
326
|
+
}
|
|
327
|
+
if (!identifier || identifier.trim().length === 0) {
|
|
328
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Identifier cannot be empty');
|
|
329
|
+
}
|
|
330
|
+
const sellerId = await extractSellerId.call(this);
|
|
331
|
+
const queryParams = {
|
|
332
|
+
marketplaceIds: marketplaceIds.join(','),
|
|
333
|
+
includedData: includedData.join(','),
|
|
334
|
+
};
|
|
335
|
+
if (issueLocale) {
|
|
336
|
+
queryParams.issuesLocale = issueLocale;
|
|
337
|
+
}
|
|
338
|
+
let endpoint;
|
|
339
|
+
if (identifierType === 'sku') {
|
|
340
|
+
endpoint = `/listings/2021-08-01/items/${encodeURIComponent(sellerId)}/${encodeURIComponent(identifier)}`;
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
queryParams.asin = identifier;
|
|
344
|
+
endpoint = `/listings/2021-08-01/items/${encodeURIComponent(sellerId)}`;
|
|
345
|
+
}
|
|
346
|
+
const response = await SpApiRequest_1.SpApiRequest.makeRequest(this, {
|
|
347
|
+
method: 'GET',
|
|
348
|
+
endpoint,
|
|
349
|
+
query: queryParams,
|
|
350
|
+
});
|
|
351
|
+
let listingData;
|
|
352
|
+
if (identifierType === 'sku') {
|
|
353
|
+
listingData = response.data;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
if (((_a = response.data) === null || _a === void 0 ? void 0 : _a.listings) && response.data.listings.length > 0) {
|
|
357
|
+
const matchingListing = response.data.listings.find((listing) => listing.asin === identifier);
|
|
358
|
+
if (matchingListing) {
|
|
359
|
+
listingData = matchingListing;
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `No listing found for ASIN: ${identifier}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `No listing found for ASIN: ${identifier}`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const outputData = [];
|
|
370
|
+
marketplaceIds.forEach(marketplaceId => {
|
|
371
|
+
outputData.push(formatListingForOutput(listingData, marketplaceId));
|
|
372
|
+
});
|
|
373
|
+
outputData.forEach(data => {
|
|
374
|
+
returnData.push({
|
|
375
|
+
json: data,
|
|
376
|
+
pairedItem: { item: itemIndex },
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
const duration = Date.now() - startTime;
|
|
380
|
+
MetricsCollector_1.metricsCollector.recordMetric('operation_duration', duration, { operation: 'getListingDetails' });
|
|
381
|
+
MetricsCollector_1.metricsCollector.recordMetric('results_count', outputData.length, { operation: 'getListingDetails' });
|
|
382
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
383
|
+
nodeId,
|
|
384
|
+
action: 'operation_completed',
|
|
385
|
+
resource: 'listing_details',
|
|
386
|
+
details: {
|
|
387
|
+
operation: 'getListingDetails',
|
|
388
|
+
itemIndex,
|
|
389
|
+
duration,
|
|
390
|
+
identifier,
|
|
391
|
+
identifierType,
|
|
392
|
+
outputCount: outputData.length,
|
|
393
|
+
marketplaces: marketplaceIds.length,
|
|
394
|
+
},
|
|
395
|
+
severity: 'low',
|
|
396
|
+
source: 'system',
|
|
397
|
+
outcome: 'success'
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
AuditLogger_1.auditLogger.logEvent({
|
|
402
|
+
nodeId,
|
|
403
|
+
action: 'operation_failed',
|
|
404
|
+
resource: 'listing_details',
|
|
405
|
+
details: {
|
|
406
|
+
operation: 'getListingDetails',
|
|
407
|
+
itemIndex,
|
|
408
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
409
|
+
},
|
|
410
|
+
severity: 'high',
|
|
411
|
+
source: 'system',
|
|
412
|
+
outcome: 'failure'
|
|
413
|
+
});
|
|
414
|
+
if (error instanceof n8n_workflow_1.NodeOperationError) {
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
418
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Amazon SP-API Listings error: ${errorMessage}`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`);
|
|
423
|
+
}
|
|
424
|
+
return returnData;
|
|
425
|
+
}
|
|
426
|
+
//# sourceMappingURL=Listings.operations.js.map
|