n8n-nodes-amazon-selling-partner-marketplace 0.0.14

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 (69) hide show
  1. package/LICENSE.md +19 -0
  2. package/README.md +125 -0
  3. package/dist/credentials/AmazonSpApi.credentials.d.ts +10 -0
  4. package/dist/credentials/AmazonSpApi.credentials.js +267 -0
  5. package/dist/credentials/AmazonSpApi.credentials.js.map +1 -0
  6. package/dist/icons/amazon-sp.dark.svg +13 -0
  7. package/dist/icons/amazon-sp.svg +13 -0
  8. package/dist/nodes/AmazonSellingPartner/AmazonSellingPartner.node.d.ts +5 -0
  9. package/dist/nodes/AmazonSellingPartner/AmazonSellingPartner.node.js +93 -0
  10. package/dist/nodes/AmazonSellingPartner/AmazonSellingPartner.node.js.map +1 -0
  11. package/dist/nodes/AmazonSellingPartner/AmazonSellingPartner.node.json +18 -0
  12. package/dist/nodes/AmazonSellingPartner/amazonSpApi.svg +25 -0
  13. package/dist/nodes/AmazonSellingPartner/core/AuditLogger.d.ts +67 -0
  14. package/dist/nodes/AmazonSellingPartner/core/AuditLogger.js +296 -0
  15. package/dist/nodes/AmazonSellingPartner/core/AuditLogger.js.map +1 -0
  16. package/dist/nodes/AmazonSellingPartner/core/ErrorHandler.d.ts +6 -0
  17. package/dist/nodes/AmazonSellingPartner/core/ErrorHandler.js +82 -0
  18. package/dist/nodes/AmazonSellingPartner/core/ErrorHandler.js.map +1 -0
  19. package/dist/nodes/AmazonSellingPartner/core/MetricsCollector.d.ts +48 -0
  20. package/dist/nodes/AmazonSellingPartner/core/MetricsCollector.js +181 -0
  21. package/dist/nodes/AmazonSellingPartner/core/MetricsCollector.js.map +1 -0
  22. package/dist/nodes/AmazonSellingPartner/core/RateLimiter.d.ts +43 -0
  23. package/dist/nodes/AmazonSellingPartner/core/RateLimiter.js +260 -0
  24. package/dist/nodes/AmazonSellingPartner/core/RateLimiter.js.map +1 -0
  25. package/dist/nodes/AmazonSellingPartner/core/SecurityValidator.d.ts +35 -0
  26. package/dist/nodes/AmazonSellingPartner/core/SecurityValidator.js +383 -0
  27. package/dist/nodes/AmazonSellingPartner/core/SecurityValidator.js.map +1 -0
  28. package/dist/nodes/AmazonSellingPartner/core/rateLimitConfig.d.ts +14 -0
  29. package/dist/nodes/AmazonSellingPartner/core/rateLimitConfig.js +93 -0
  30. package/dist/nodes/AmazonSellingPartner/core/rateLimitConfig.js.map +1 -0
  31. package/dist/nodes/AmazonSellingPartner/descriptions/Custom.description.d.ts +3 -0
  32. package/dist/nodes/AmazonSellingPartner/descriptions/Custom.description.js +147 -0
  33. package/dist/nodes/AmazonSellingPartner/descriptions/Custom.description.js.map +1 -0
  34. package/dist/nodes/AmazonSellingPartner/generated/Generated.description.d.ts +4977 -0
  35. package/dist/nodes/AmazonSellingPartner/generated/Generated.description.js +40893 -0
  36. package/dist/nodes/AmazonSellingPartner/generated/Generated.description.js.map +1 -0
  37. package/dist/nodes/AmazonSellingPartner/helpers/LwaClient.d.ts +10 -0
  38. package/dist/nodes/AmazonSellingPartner/helpers/LwaClient.js +79 -0
  39. package/dist/nodes/AmazonSellingPartner/helpers/LwaClient.js.map +1 -0
  40. package/dist/nodes/AmazonSellingPartner/helpers/RdtClient.d.ts +11 -0
  41. package/dist/nodes/AmazonSellingPartner/helpers/RdtClient.js +66 -0
  42. package/dist/nodes/AmazonSellingPartner/helpers/RdtClient.js.map +1 -0
  43. package/dist/nodes/AmazonSellingPartner/helpers/ReportDownloader.d.ts +16 -0
  44. package/dist/nodes/AmazonSellingPartner/helpers/ReportDownloader.js +65 -0
  45. package/dist/nodes/AmazonSellingPartner/helpers/ReportDownloader.js.map +1 -0
  46. package/dist/nodes/AmazonSellingPartner/helpers/SigV4Signer.d.ts +4 -0
  47. package/dist/nodes/AmazonSellingPartner/helpers/SigV4Signer.js +76 -0
  48. package/dist/nodes/AmazonSellingPartner/helpers/SigV4Signer.js.map +1 -0
  49. package/dist/nodes/AmazonSellingPartner/helpers/SpApiRequest.d.ts +23 -0
  50. package/dist/nodes/AmazonSellingPartner/helpers/SpApiRequest.js +220 -0
  51. package/dist/nodes/AmazonSellingPartner/helpers/SpApiRequest.js.map +1 -0
  52. package/dist/nodes/AmazonSellingPartner/helpers/downloadPresigned.d.ts +4 -0
  53. package/dist/nodes/AmazonSellingPartner/helpers/downloadPresigned.js +16 -0
  54. package/dist/nodes/AmazonSellingPartner/helpers/downloadPresigned.js.map +1 -0
  55. package/dist/nodes/AmazonSellingPartner/helpers/graphql.d.ts +1 -0
  56. package/dist/nodes/AmazonSellingPartner/helpers/graphql.js +13 -0
  57. package/dist/nodes/AmazonSellingPartner/helpers/graphql.js.map +1 -0
  58. package/dist/nodes/AmazonSellingPartner/operations/Custom.operations.d.ts +2 -0
  59. package/dist/nodes/AmazonSellingPartner/operations/Custom.operations.js +232 -0
  60. package/dist/nodes/AmazonSellingPartner/operations/Custom.operations.js.map +1 -0
  61. package/dist/nodes/AmazonSellingPartner/operations/Generated.operations.d.ts +2 -0
  62. package/dist/nodes/AmazonSellingPartner/operations/Generated.operations.js +186 -0
  63. package/dist/nodes/AmazonSellingPartner/operations/Generated.operations.js.map +1 -0
  64. package/dist/nodes/AmazonSellingPartner/operations/analytics/constants.d.ts +126 -0
  65. package/dist/nodes/AmazonSellingPartner/operations/analytics/constants.js +213 -0
  66. package/dist/nodes/AmazonSellingPartner/operations/analytics/constants.js.map +1 -0
  67. package/dist/package.json +63 -0
  68. package/dist/tsconfig.tsbuildinfo +1 -0
  69. package/package.json +63 -0
@@ -0,0 +1,10 @@
1
+ import { ICredentialDataDecryptedObject } from 'n8n-workflow';
2
+ export declare class LwaClient {
3
+ private static tokenCache;
4
+ private static readonly TOKEN_ENDPOINT;
5
+ private static readonly BUFFER_TIME_SECONDS;
6
+ static getAccessToken(credentials: ICredentialDataDecryptedObject): Promise<string>;
7
+ private static fetchAccessToken;
8
+ private static getCacheKey;
9
+ static clearCache(credentials?: ICredentialDataDecryptedObject): void;
10
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LwaClient = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const n8n_workflow_1 = require("n8n-workflow");
9
+ class LwaClient {
10
+ static async getAccessToken(credentials) {
11
+ const cacheKey = this.getCacheKey(credentials);
12
+ const cached = this.tokenCache.get(cacheKey);
13
+ if (cached && cached.expiresAt > Date.now()) {
14
+ return cached.accessToken;
15
+ }
16
+ const newToken = await this.fetchAccessToken(credentials);
17
+ this.tokenCache.set(cacheKey, {
18
+ accessToken: newToken.access_token,
19
+ expiresAt: Date.now() + (newToken.expires_in - this.BUFFER_TIME_SECONDS) * 1000,
20
+ });
21
+ return newToken.access_token;
22
+ }
23
+ static async fetchAccessToken(credentials) {
24
+ try {
25
+ const formData = new URLSearchParams({
26
+ grant_type: 'refresh_token',
27
+ refresh_token: credentials.lwaRefreshToken,
28
+ client_id: credentials.lwaClientId,
29
+ client_secret: credentials.lwaClientSecret,
30
+ });
31
+ const response = await axios_1.default.post(this.TOKEN_ENDPOINT, formData.toString(), {
32
+ headers: {
33
+ 'Content-Type': 'application/x-www-form-urlencoded',
34
+ 'User-Agent': 'n8n-amazon-sp-api/1.0.0',
35
+ },
36
+ timeout: 30000,
37
+ });
38
+ return response.data;
39
+ }
40
+ catch (error) {
41
+ if (axios_1.default.isAxiosError(error) && error.response) {
42
+ const { status, data } = error.response;
43
+ if (!process.env.JEST_SILENT_LOGS) {
44
+ console.error('LWA Token Request Failed:', {
45
+ status,
46
+ data,
47
+ requestUrl: this.TOKEN_ENDPOINT,
48
+ clientId: credentials.lwaClientId,
49
+ });
50
+ }
51
+ throw new n8n_workflow_1.NodeOperationError({}, `LWA authentication failed (${status}): ${data.error_description || data.error || JSON.stringify(data)}`, {
52
+ description: 'Check your LWA credentials and ensure they are valid and not expired. See server logs for details.',
53
+ });
54
+ }
55
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
56
+ if (!process.env.JEST_SILENT_LOGS) {
57
+ console.error('LWA Token Request Error (non-HTTP):', errorMessage);
58
+ }
59
+ throw new n8n_workflow_1.NodeOperationError({}, `LWA request failed: ${errorMessage}`);
60
+ }
61
+ }
62
+ static getCacheKey(credentials) {
63
+ return `lwa_${credentials.lwaClientId}`;
64
+ }
65
+ static clearCache(credentials) {
66
+ if (credentials) {
67
+ const cacheKey = this.getCacheKey(credentials);
68
+ this.tokenCache.delete(cacheKey);
69
+ }
70
+ else {
71
+ this.tokenCache.clear();
72
+ }
73
+ }
74
+ }
75
+ exports.LwaClient = LwaClient;
76
+ LwaClient.tokenCache = new Map();
77
+ LwaClient.TOKEN_ENDPOINT = 'https://api.amazon.com/auth/o2/token';
78
+ LwaClient.BUFFER_TIME_SECONDS = 300;
79
+ //# sourceMappingURL=LwaClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LwaClient.js","sourceRoot":"","sources":["../../../../nodes/AmazonSellingPartner/helpers/LwaClient.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAC7C,+CAAkF;AAclF,MAAa,SAAS;IAKrB,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,WAA2C;QACtE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAG7C,IAAI,MAAM,IAAI,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YAC7C,OAAO,MAAM,CAAC,WAAW,CAAC;QAC3B,CAAC;QAGD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAG1D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE;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AI,iCAAkB,CAC3B,EAAS,EACT,8BAA8B,MAAM,MAAM,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EACxG;oBACC,WAAW,EAAE,oGAAoG;iBACjH,CACD,CAAC;YACH,CAAC;YACD,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC;YAC9E,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;gBAChC,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,YAAY,CAAC,CAAC;YACvE,CAAC;YACV,MAAM,IAAI,iCAAkB,CAAC,EAAS,EAAE,uBAAuB,YAAY,EAAE,CAAC,CAAC;QAChF,CAAC;IACF,CAAC;IAEO,MAAM,CAAC,WAAW,CAAC,WAA2C;QAErE,OAAO,OAAO,WAAW,CAAC,WAAW,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,WAA4C;QAC7D,IAAI,WAAW,EAAE,CAAC;YACjB,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;YAC/C,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;IACF,CAAC;;AAzFF,8BA0FC;AAzFe,oBAAU,GAAG,IAAI,GAAG,EAAuB,CAAC;AACnC,wBAAc,GAAG,sCAAsC,CAAC;AACxD,6BAAmB,GAAG,GAAG,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { ICredentialDataDecryptedObject } from 'n8n-workflow';
2
+ export interface RestrictedResource {
3
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
4
+ path: string;
5
+ dataElements?: string[];
6
+ }
7
+ export declare class RdtClient {
8
+ private static readonly RDT_ENDPOINT;
9
+ static getRestrictedAccessToken(credentials: ICredentialDataDecryptedObject, restrictedResources: RestrictedResource[]): Promise<string>;
10
+ private static getBaseUrl;
11
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RdtClient = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const n8n_workflow_1 = require("n8n-workflow");
9
+ const LwaClient_1 = require("./LwaClient");
10
+ class RdtClient {
11
+ static async getRestrictedAccessToken(credentials, restrictedResources) {
12
+ var _a, _b;
13
+ try {
14
+ const lwaToken = await LwaClient_1.LwaClient.getAccessToken(credentials);
15
+ const baseUrl = this.getBaseUrl(credentials);
16
+ const rdtUrl = new URL(this.RDT_ENDPOINT, baseUrl);
17
+ const requestBody = {
18
+ restrictedResources,
19
+ };
20
+ const response = await axios_1.default.post(rdtUrl.toString(), requestBody, {
21
+ headers: {
22
+ 'Content-Type': 'application/json',
23
+ 'User-Agent': 'n8n-amazon-sp-api/1.0.0',
24
+ 'x-amz-access-token': lwaToken,
25
+ },
26
+ timeout: 30000,
27
+ });
28
+ return response.data.restrictedDataToken;
29
+ }
30
+ catch (error) {
31
+ const isAxiosErr = ((_b = (_a = axios_1.default).isAxiosError) === null || _b === void 0 ? void 0 : _b.call(_a, error)) || (error === null || error === void 0 ? void 0 : error.isAxiosError);
32
+ if (isAxiosErr && error.response) {
33
+ const { status, data } = error.response;
34
+ throw new n8n_workflow_1.NodeOperationError({}, `RDT authentication failed (${status}): ${data.error_description || data.error || 'Unknown error'}`, {
35
+ description: 'Check your LWA credentials and restricted resource configuration',
36
+ });
37
+ }
38
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
39
+ throw new n8n_workflow_1.NodeOperationError({}, `RDT request failed: ${errorMessage}`);
40
+ }
41
+ }
42
+ static getBaseUrl(credentials) {
43
+ const advancedOptions = credentials.advancedOptions;
44
+ const customEndpoint = credentials.spApiEndpoint || (advancedOptions === null || advancedOptions === void 0 ? void 0 : advancedOptions.spApiEndpoint);
45
+ if (customEndpoint) {
46
+ return customEndpoint;
47
+ }
48
+ const region = credentials.awsRegion;
49
+ const environment = credentials.environment;
50
+ const endpoints = {
51
+ 'us-east-1': environment === 'sandbox'
52
+ ? 'https://sandbox.sellingpartnerapi-na.amazon.com'
53
+ : 'https://sellingpartnerapi-na.amazon.com',
54
+ 'eu-west-1': environment === 'sandbox'
55
+ ? 'https://sandbox.sellingpartnerapi-eu.amazon.com'
56
+ : 'https://sellingpartnerapi-eu.amazon.com',
57
+ 'us-west-2': environment === 'sandbox'
58
+ ? 'https://sandbox.sellingpartnerapi-fe.amazon.com'
59
+ : 'https://sellingpartnerapi-fe.amazon.com',
60
+ };
61
+ return endpoints[region] || endpoints['us-east-1'];
62
+ }
63
+ }
64
+ exports.RdtClient = RdtClient;
65
+ RdtClient.RDT_ENDPOINT = '/tokens/2021-03-01/restrictedDataToken';
66
+ //# sourceMappingURL=RdtClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RdtClient.js","sourceRoot":"","sources":["../../../../nodes/AmazonSellingPartner/helpers/RdtClient.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAC7C,+CAAkF;AAClF,2CAAwC;AAaxC,MAAa,SAAS;IAGrB,MAAM,CAAC,KAAK,CAAC,wBAAwB,CACpC,WAA2C,EAC3C,mBAAyC;;QAEzC,IAAI,CAAC;YAEJ,MAAM,QAAQ,GAAG,MAAM,qBAAS,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YAG7D,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YAC7C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YAGnD,MAAM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Aa,CAAA,CAAC;QAEnF,IAAI,cAAc,EAAE,CAAC;YACpB,OAAO,cAAwB,CAAC;QACjC,CAAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,SAAmB,CAAC;QAC/C,MAAM,WAAW,GAAG,WAAW,CAAC,WAAqB,CAAC;QAEtD,MAAM,SAAS,GAA2B;YACzC,WAAW,EAAE,WAAW,KAAK,SAAS;gBACrC,CAAC,CAAC,iDAAiD;gBACnD,CAAC,CAAC,yCAAyC;YAC5C,WAAW,EAAE,WAAW,KAAK,SAAS;gBACrC,CAAC,CAAC,iDAAiD;gBACnD,CAAC,CAAC,yCAAyC;YAC5C,WAAW,EAAE,WAAW,KAAK,SAAS;gBACrC,CAAC,CAAC,iDAAiD;gBACnD,CAAC,CAAC,yCAAyC;SAC5C,CAAC;QAEF,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,WAAW,CAAC,CAAC;IACpD,CAAC;;AA5EF,8BA6EC;AA5EwB,sBAAY,GAAG,wCAAwC,CAAC"}
@@ -0,0 +1,16 @@
1
+ interface EncryptionDetails {
2
+ standard: string;
3
+ initializationVector: string;
4
+ key: string;
5
+ }
6
+ interface ReportDocument {
7
+ reportDocumentId: string;
8
+ url: string;
9
+ encryptionDetails?: EncryptionDetails;
10
+ compressionAlgorithm?: string;
11
+ }
12
+ export declare class ReportDownloader {
13
+ static downloadReportDocument(document: ReportDocument, nodeId?: string): Promise<Buffer>;
14
+ private static decryptDocument;
15
+ }
16
+ export {};
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ReportDownloader = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const crypto_1 = require("crypto");
9
+ const zlib_1 = require("zlib");
10
+ const n8n_workflow_1 = require("n8n-workflow");
11
+ class ReportDownloader {
12
+ static async downloadReportDocument(document, nodeId) {
13
+ try {
14
+ const response = await (0, axios_1.default)({
15
+ method: 'GET',
16
+ url: document.url,
17
+ responseType: 'arraybuffer',
18
+ timeout: 300000,
19
+ });
20
+ let data = Buffer.from(response.data);
21
+ if (document.encryptionDetails) {
22
+ data = this.decryptDocument(data, document.encryptionDetails);
23
+ }
24
+ if (document.compressionAlgorithm === 'GZIP') {
25
+ try {
26
+ data = (0, zlib_1.gunzipSync)(data);
27
+ }
28
+ catch (err) {
29
+ throw new n8n_workflow_1.NodeOperationError({ id: nodeId || 'unknown', name: 'ReportDownloader', type: 'helper' }, `Failed to decompress GZIP report: ${(err === null || err === void 0 ? void 0 : err.message) || 'Unknown error'}`);
30
+ }
31
+ }
32
+ return data;
33
+ }
34
+ catch (error) {
35
+ if (axios_1.default.isAxiosError(error)) {
36
+ throw new n8n_workflow_1.NodeOperationError({ id: nodeId || 'unknown', name: 'ReportDownloader', type: 'helper' }, `Failed to download report document: ${error.message}`, {
37
+ description: 'Check if the document URL is still valid and accessible'
38
+ });
39
+ }
40
+ throw new n8n_workflow_1.NodeOperationError({ id: nodeId || 'unknown', name: 'ReportDownloader', type: 'helper' }, `Unexpected error downloading report: ${error instanceof Error ? error.message : 'Unknown error'}`);
41
+ }
42
+ }
43
+ static decryptDocument(encryptedData, encryptionDetails) {
44
+ try {
45
+ if (encryptionDetails.standard !== 'AES') {
46
+ throw new Error(`Unsupported encryption standard: ${encryptionDetails.standard}`);
47
+ }
48
+ const key = Buffer.from(encryptionDetails.key, 'base64');
49
+ const iv = Buffer.from(encryptionDetails.initializationVector, 'base64');
50
+ const decipher = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, iv);
51
+ const decrypted = Buffer.concat([
52
+ decipher.update(encryptedData),
53
+ decipher.final()
54
+ ]);
55
+ return decrypted;
56
+ }
57
+ catch (error) {
58
+ throw new n8n_workflow_1.NodeOperationError({ id: 'unknown', name: 'ReportDownloader', type: 'helper' }, `Failed to decrypt report document: ${error instanceof Error ? error.message : 'Unknown error'}`, {
59
+ description: 'The encryption key or initialization vector may be invalid'
60
+ });
61
+ }
62
+ }
63
+ }
64
+ exports.ReportDownloader = ReportDownloader;
65
+ //# sourceMappingURL=ReportDownloader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReportDownloader.js","sourceRoot":"","sources":["../../../../nodes/AmazonSellingPartner/helpers/ReportDownloader.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mCAA0C;AAC1C,+BAAkC;AAClC,+CAAkD;AAelD,MAAa,gBAAgB;IAI5B,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAClC,QAAwB,EACxB,MAAe;QAEf,IAAI,CAAC;YAEJ,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC;gBAC5B,MAAM,EAAE,KAAK;gBACb,GAAG,EAAE,QAAQ,CAAC,GAAG;gBACjB,YAAY,EAAE,aAAa;gBAC3B,OAAO,EAAE,MAAM;aACf,CAAC,CAAC;YAEH,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAGtC,IAAI,QAAQ,CAAC,iBAAiB,EAAE,CAAC;gBAChC,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC;YAC/D,CAAC;YAGD,IAAI,QAAQ,CAAC,oBAAoB,KAAK,MAAM,EAAE,CAAC;gBAC9C,IAAI,CAAC;oBACJ,IAAI,GAAG,IAAA,iBAAU,EAAC,IAAI,CAAC,CAAC;gBACzB,CAAC;gBAAC,OAAO,GAAQ,EAAE,CAAC;oBACnB,MAAM,IAAI,iCAAkB,CAC3B,EAAE,EAAE,EAAE,MAAM,IAAI,SAAS,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,EAAS,EAC5E,qCAAqC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,KAAI,eAAe,EAAE,C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aAAa,CAAC;gBAC9B,QAAQ,CAAC,KAAK,EAAE;aAChB,CAAC,CAAC;YAEH,OAAO,SAAS,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,iCAAkB,CAC3B,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,EAAS,EAClE,sCAAsC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,EAChG;gBACC,WAAW,EAAE,4DAA4D;aACzE,CACD,CAAC;QACH,CAAC;IACF,CAAC;CACD;AAxFD,4CAwFC"}
@@ -0,0 +1,4 @@
1
+ import { ICredentialDataDecryptedObject } from 'n8n-workflow';
2
+ export declare class SigV4Signer {
3
+ static signRequest(method: string, url: string, headers: Record<string, string>, body: string | undefined, credentials: ICredentialDataDecryptedObject): Promise<Record<string, string>>;
4
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SigV4Signer = void 0;
37
+ const aws4 = __importStar(require("aws4"));
38
+ const url_1 = require("url");
39
+ const n8n_workflow_1 = require("n8n-workflow");
40
+ class SigV4Signer {
41
+ static async signRequest(method, url, headers, body, credentials) {
42
+ try {
43
+ const urlParts = new url_1.URL(url);
44
+ const advancedOptions = credentials.advancedOptions;
45
+ const awsAccessKeyId = credentials.awsAccessKeyId || (advancedOptions === null || advancedOptions === void 0 ? void 0 : advancedOptions.awsAccessKeyId);
46
+ const awsSecretAccessKey = credentials.awsSecretAccessKey || (advancedOptions === null || advancedOptions === void 0 ? void 0 : advancedOptions.awsSecretAccessKey);
47
+ const awsRegion = credentials.awsRegion;
48
+ if (!awsAccessKeyId || !awsSecretAccessKey) {
49
+ throw new Error('AWS credentials are required for SigV4 signing');
50
+ }
51
+ const requestOptions = {
52
+ method,
53
+ host: urlParts.hostname,
54
+ path: urlParts.pathname + urlParts.search,
55
+ headers: { ...headers },
56
+ body,
57
+ service: 'execute-api',
58
+ region: awsRegion,
59
+ };
60
+ const awsCredentials = {
61
+ accessKeyId: awsAccessKeyId,
62
+ secretAccessKey: awsSecretAccessKey,
63
+ };
64
+ const signedRequest = aws4.sign(requestOptions, awsCredentials);
65
+ return signedRequest.headers;
66
+ }
67
+ catch (error) {
68
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
69
+ throw new n8n_workflow_1.NodeOperationError({}, `Failed to sign request: ${errorMessage}`, {
70
+ description: 'Check your AWS credentials and region configuration',
71
+ });
72
+ }
73
+ }
74
+ }
75
+ exports.SigV4Signer = SigV4Signer;
76
+ //# sourceMappingURL=SigV4Signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SigV4Signer.js","sourceRoot":"","sources":["../../../../nodes/AmazonSellingPartner/helpers/SigV4Signer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,6BAA0B;AAC1B,+CAAkF;AAElF,MAAa,WAAW;IACvB,MAAM,CAAC,KAAK,CAAC,WAAW,CACvB,MAAc,EACd,GAAW,EACX,OAA+B,EAC/B,IAAwB,EACxB,WAA2C;QAE3C,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;YAG9B,MAAM,eAAe,GAAG,WAAW,CAAC,eAAsB,CAAC;YAC3D,MAAM,cAAc,GAAG,WAAW,CAAC,cAAc,KAAI,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,cAAc,CAAA,CAAC;YACrF,MAAM,kBAAkB,GAAG,WAAW,CAAC,kBAAkB,KAAI,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,kBAAkB,CAAA,CAAC;YACjG,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC;YAExC,IAAI,CAAC,cAAc,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBAC5C,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;YACnE,CAAC;YAED,MAAM,cAAc,GAAG;gBACtB,MAAM;gBACN,IAAI,EAAE,QAAQ,CAAC,QAAQ;gBACvB,IAAI,EAAE,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM;gBACzC,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE;gBACvB,IAAI;gBACJ,OAAO,EAAE,aAAa;gBACtB,MAAM,EAAE,SAAmB;aAC3B,CAAC;YAEF,MAAM,cAAc,GAAG;gBACtB,WAAW,EAAE,cAAwB;gBACrC,eAAe,EAAE,kBAA4B;aAC7C,CAAC;YAGF,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;YAEhE,OAAO,aAAa,CAAC,OAAiC,CAAC;QACxD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC;YACvF,MAAM,IAAI,iCAAkB,CAC3B,EAAS,EACT,2BAA2B,YAAY,EAAE,EACzC;gBACC,WAAW,EAAE,qDAAqD;aAClE,CACD,CAAC;QACH,CAAC;IACF,CAAC;CACD;AAnDD,kCAmDC"}
@@ -0,0 +1,23 @@
1
+ import { IExecuteFunctions } from 'n8n-workflow';
2
+ import { RestrictedResource } from './RdtClient';
3
+ interface SpApiRequestOptions {
4
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
+ endpoint: string;
6
+ query?: Record<string, any>;
7
+ body?: any;
8
+ headers?: Record<string, string>;
9
+ responseType?: 'json' | 'stream' | 'text';
10
+ restrictedResources?: RestrictedResource[];
11
+ }
12
+ interface SpApiResponse<T = any> {
13
+ data: T;
14
+ headers: Record<string, string>;
15
+ status: number;
16
+ }
17
+ export declare class SpApiRequest {
18
+ private static rateLimiter;
19
+ static makeRequest<T = any>(executeFunctions: IExecuteFunctions, options: SpApiRequestOptions): Promise<SpApiResponse<T>>;
20
+ private static validateCredentials;
21
+ private static getBaseUrl;
22
+ }
23
+ export {};
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SpApiRequest = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const url_1 = require("url");
9
+ const n8n_workflow_1 = require("n8n-workflow");
10
+ const LwaClient_1 = require("./LwaClient");
11
+ const RdtClient_1 = require("./RdtClient");
12
+ const RateLimiter_1 = require("../core/RateLimiter");
13
+ const ErrorHandler_1 = require("../core/ErrorHandler");
14
+ const MetricsCollector_1 = require("../core/MetricsCollector");
15
+ const AuditLogger_1 = require("../core/AuditLogger");
16
+ const SecurityValidator_1 = require("../core/SecurityValidator");
17
+ const rateLimitConfig_1 = require("../core/rateLimitConfig");
18
+ const SigV4Signer_1 = require("./SigV4Signer");
19
+ class SpApiRequest {
20
+ static async makeRequest(executeFunctions, options) {
21
+ const startTime = Date.now();
22
+ const nodeId = executeFunctions.getNode().id;
23
+ try {
24
+ const credentials = await executeFunctions.getCredentials('amazonSpApi');
25
+ const credentialValidation = this.validateCredentials(credentials);
26
+ if (!credentialValidation.isValid) {
27
+ AuditLogger_1.auditLogger.logCredentialUsage(nodeId, 'amazonSpApi', false, {
28
+ errors: credentialValidation.errors,
29
+ });
30
+ throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Invalid credentials: ${credentialValidation.errors.join(', ')}`);
31
+ }
32
+ try {
33
+ const environmentValidation = SecurityValidator_1.securityValidator.validateEnvironmentIsolation(credentials, nodeId);
34
+ if (!environmentValidation.isValid) {
35
+ throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Environment isolation violation: ${environmentValidation.errors.join(', ')}`);
36
+ }
37
+ }
38
+ catch (error) {
39
+ console.warn('Security validator not available, skipping environment validation');
40
+ }
41
+ if (options.query) {
42
+ try {
43
+ const paramValidation = SecurityValidator_1.securityValidator.validateApiParameters(options.query, nodeId);
44
+ if (!paramValidation.isValid) {
45
+ throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Invalid parameters: ${paramValidation.errors.join(', ')}`);
46
+ }
47
+ options.query = paramValidation.sanitizedData;
48
+ }
49
+ catch (error) {
50
+ console.warn('Security validator not available, skipping parameter validation');
51
+ }
52
+ }
53
+ const baseUrl = this.getBaseUrl(credentials);
54
+ const url = new url_1.URL(options.endpoint, baseUrl);
55
+ if (options.query) {
56
+ Object.entries(options.query).forEach(([key, value]) => {
57
+ if (value !== undefined && value !== null && value !== '') {
58
+ if (Array.isArray(value)) {
59
+ value.forEach(v => url.searchParams.append(key, v));
60
+ }
61
+ else {
62
+ url.searchParams.set(key, String(value));
63
+ }
64
+ }
65
+ });
66
+ }
67
+ const rateLimitGroup = (0, rateLimitConfig_1.getEndpointGroup)(options.method, options.endpoint);
68
+ await this.rateLimiter.waitForToken(rateLimitGroup);
69
+ let accessToken;
70
+ let authType;
71
+ if (options.restrictedResources && options.restrictedResources.length > 0) {
72
+ accessToken = await RdtClient_1.RdtClient.getRestrictedAccessToken(credentials, options.restrictedResources);
73
+ authType = 'RDT';
74
+ }
75
+ else {
76
+ accessToken = await LwaClient_1.LwaClient.getAccessToken(credentials);
77
+ authType = 'LWA';
78
+ }
79
+ AuditLogger_1.auditLogger.logAuthentication(nodeId, authType, true, { endpoint: options.endpoint });
80
+ const acceptHeader = (options.responseType === 'stream' || options.responseType === 'text')
81
+ ? '*/*'
82
+ : 'application/json';
83
+ const headers = {
84
+ 'Accept': acceptHeader,
85
+ 'Content-Type': 'application/json',
86
+ 'User-Agent': 'n8n-amazon-sp-api/1.0.0',
87
+ 'x-amz-access-token': accessToken,
88
+ ...options.headers,
89
+ };
90
+ const bodyString = options.body === undefined
91
+ ? undefined
92
+ : typeof options.body === 'string'
93
+ ? options.body
94
+ : JSON.stringify(options.body);
95
+ const finalHeaders = await SigV4Signer_1.SigV4Signer.signRequest(options.method, url.toString(), headers, bodyString, credentials);
96
+ console.log('SP-API Request:', {
97
+ method: options.method,
98
+ url: url.toString(),
99
+ endpoint: options.endpoint,
100
+ baseUrl,
101
+ hasAccessToken: !!accessToken,
102
+ region: credentials.awsRegion,
103
+ marketplace: credentials.primaryMarketplace,
104
+ });
105
+ const axiosConfig = {
106
+ method: options.method,
107
+ url: url.toString(),
108
+ headers: finalHeaders,
109
+ data: bodyString !== null && bodyString !== void 0 ? bodyString : options.body,
110
+ timeout: 60000,
111
+ validateStatus: (status) => status < 500,
112
+ };
113
+ if (options.responseType === 'stream') {
114
+ axiosConfig.responseType = 'stream';
115
+ }
116
+ else if (options.responseType === 'text') {
117
+ axiosConfig.responseType = 'text';
118
+ }
119
+ const response = await (0, axios_1.default)(axiosConfig);
120
+ const duration = Date.now() - startTime;
121
+ this.rateLimiter.updateFromHeaders(rateLimitGroup, response.headers);
122
+ if (response.status >= 400) {
123
+ console.error('SP-API Request Failed:', {
124
+ status: response.status,
125
+ statusText: response.statusText,
126
+ url: url.toString(),
127
+ endpoint: options.endpoint,
128
+ method: options.method,
129
+ baseUrl,
130
+ responseData: response.data,
131
+ requestHeaders: headers,
132
+ responseHeaders: response.headers,
133
+ });
134
+ AuditLogger_1.auditLogger.logApiAccess(nodeId, options.endpoint, false, {
135
+ status: response.status,
136
+ duration,
137
+ method: options.method,
138
+ });
139
+ MetricsCollector_1.metricsCollector.recordApiRequest(options.endpoint, duration, false, `HTTP_${response.status}`);
140
+ throw await ErrorHandler_1.ErrorHandler.handleApiError(response);
141
+ }
142
+ AuditLogger_1.auditLogger.logApiAccess(nodeId, options.endpoint, true, {
143
+ status: response.status,
144
+ duration,
145
+ method: options.method,
146
+ });
147
+ MetricsCollector_1.metricsCollector.recordApiRequest(options.endpoint, duration, true);
148
+ return {
149
+ data: response.data,
150
+ headers: response.headers,
151
+ status: response.status,
152
+ };
153
+ }
154
+ catch (error) {
155
+ const duration = Date.now() - startTime;
156
+ AuditLogger_1.auditLogger.logError(nodeId, error instanceof Error ? error : new Error('Unknown error'), {
157
+ endpoint: options.endpoint,
158
+ method: options.method,
159
+ duration,
160
+ });
161
+ if (error instanceof n8n_workflow_1.NodeOperationError) {
162
+ MetricsCollector_1.metricsCollector.recordApiRequest(options.endpoint, duration, false, 'NODE_OPERATION_ERROR');
163
+ throw error;
164
+ }
165
+ if (axios_1.default.isAxiosError(error)) {
166
+ MetricsCollector_1.metricsCollector.recordApiRequest(options.endpoint, duration, false, 'NETWORK_ERROR');
167
+ throw await ErrorHandler_1.ErrorHandler.handleNetworkError(error);
168
+ }
169
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
170
+ MetricsCollector_1.metricsCollector.recordApiRequest(options.endpoint, duration, false, 'UNEXPECTED_ERROR');
171
+ throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Unexpected error: ${errorMessage}`);
172
+ }
173
+ }
174
+ static validateCredentials(credentials) {
175
+ const errors = [];
176
+ if (!credentials.lwaClientId) {
177
+ errors.push('LWA Client ID is required');
178
+ }
179
+ if (!credentials.lwaClientSecret) {
180
+ errors.push('LWA Client Secret is required');
181
+ }
182
+ if (!credentials.lwaRefreshToken) {
183
+ errors.push('LWA Refresh Token is required');
184
+ }
185
+ if (!credentials.awsAccessKeyId) {
186
+ errors.push('AWS Access Key ID is required');
187
+ }
188
+ if (!credentials.awsSecretAccessKey) {
189
+ errors.push('AWS Secret Access Key is required');
190
+ }
191
+ return {
192
+ isValid: errors.length === 0,
193
+ errors,
194
+ };
195
+ }
196
+ static getBaseUrl(credentials) {
197
+ const advancedOptions = credentials.advancedOptions;
198
+ const customEndpoint = credentials.spApiEndpoint || (advancedOptions === null || advancedOptions === void 0 ? void 0 : advancedOptions.spApiEndpoint);
199
+ if (customEndpoint) {
200
+ return customEndpoint;
201
+ }
202
+ const region = credentials.awsRegion;
203
+ const environment = credentials.environment;
204
+ const endpoints = {
205
+ 'us-east-1': environment === 'sandbox'
206
+ ? 'https://sandbox.sellingpartnerapi-na.amazon.com'
207
+ : 'https://sellingpartnerapi-na.amazon.com',
208
+ 'eu-west-1': environment === 'sandbox'
209
+ ? 'https://sandbox.sellingpartnerapi-eu.amazon.com'
210
+ : 'https://sellingpartnerapi-eu.amazon.com',
211
+ 'us-west-2': environment === 'sandbox'
212
+ ? 'https://sandbox.sellingpartnerapi-fe.amazon.com'
213
+ : 'https://sellingpartnerapi-fe.amazon.com',
214
+ };
215
+ return endpoints[region] || endpoints['us-east-1'];
216
+ }
217
+ }
218
+ exports.SpApiRequest = SpApiRequest;
219
+ SpApiRequest.rateLimiter = new RateLimiter_1.RateLimiter();
220
+ //# sourceMappingURL=SpApiRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpApiRequest.js","sourceRoot":"","sources":["../../../../nodes/AmazonSellingPartner/helpers/SpApiRequest.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAC7C,6BAA0B;AAC1B,+CAIsB;AACtB,2CAAwC;AACxC,2CAA4D;AAC5D,qDAAkD;AAClD,uDAAoD;AACpD,+DAA4D;AAC5D,qDAAkD;AAClD,iEAA8D;AAC9D,6DAA2D;AAC3D,+CAA4C;AAkB5C,MAAa,YAAY;IAGxB,MAAM,CAAC,KAAK,CAAC,WAAW,CACvB,gBAAmC,EACnC,OAA4B;QAE5B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QAE7C,IAAI,CAAC;YACJ,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;YAGzE,MAAM,oBAAoB,GAAG,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;YACnE,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC;gBACnC,yBAAW,CAAC,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE;oBAC5D,MAAM,EAAE,oBAAoB,CAAC,MAAM;iBACnC,CAAC,CAAC;gBACH,MAAM,IAAI,iCAAkB,CAC3B,gBAAgB,CAAC,OAAO,EAAE,EAC1B,wBAAwB,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAChE,CAAC;YACH,CAAC;YAGD,IAAI,CAAC;gBACJ,MAAM,qBAAqB,GAAG,qCAAiB,CAAC,4BAA4B,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;gBACl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I,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,aAAa,CAAA,CAAC;QAEnF,IAAI,cAAc,EAAE,CAAC;YACpB,OAAO,cAAwB,CAAC;QACjC,CAAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,SAAmB,CAAC;QAC/C,MAAM,WAAW,GAAG,WAAW,CAAC,WAAqB,CAAC;QAEtD,MAAM,SAAS,GAA2B;YACzC,WAAW,EAAE,WAAW,KAAK,SAAS;gBACrC,CAAC,CAAC,iDAAiD;gBACnD,CAAC,CAAC,yCAAyC;YAC5C,WAAW,EAAE,WAAW,KAAK,SAAS;gBACrC,CAAC,CAAC,iDAAiD;gBACnD,CAAC,CAAC,yCAAyC;YAC5C,WAAW,EAAE,WAAW,KAAK,SAAS;gBACrC,CAAC,CAAC,iDAAiD;gBACnD,CAAC,CAAC,yCAAyC;SAC5C,CAAC;QAEF,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,WAAW,CAAC,CAAC;IACpD,CAAC;;AAjRF,oCAkRC;AAjRe,wBAAW,GAAG,IAAI,yBAAW,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function downloadPresigned(url: string): Promise<{
2
+ buffer: Buffer;
3
+ contentType?: string;
4
+ }>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.downloadPresigned = downloadPresigned;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ async function downloadPresigned(url) {
9
+ const res = await axios_1.default.get(url, { responseType: 'arraybuffer', validateStatus: s => s < 500 });
10
+ if (res.status >= 400) {
11
+ throw new Error(`Failed to download document: HTTP ${res.status}`);
12
+ }
13
+ const contentType = res.headers['content-type'];
14
+ return { buffer: Buffer.from(res.data), contentType };
15
+ }
16
+ //# sourceMappingURL=downloadPresigned.js.map