From 347fbc5a02e1bb7c1476b43137608660dbdf1d47 Mon Sep 17 00:00:00 2001 From: Pradeep S <85151832+pradeep-gox@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:29:07 +0530 Subject: [PATCH 1/2] fix: return exact sp-api response from callAPI wrapper --- lib/SellingPartner.js | 128 ++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 67 deletions(-) diff --git a/lib/SellingPartner.js b/lib/SellingPartner.js index 6e28a3b..ec0d15e 100644 --- a/lib/SellingPartner.js +++ b/lib/SellingPartner.js @@ -62,7 +62,7 @@ class SellingPartner { user_agent: `amazon-sp-api/${client_version} (Language=Node.js/${node_version}; Platform=${os.type()}/${os.release()})`, debug_log: false, timeouts: {}, - retry_remote_timeout: true + retry_remote_timeout: true, }, config.options ); @@ -79,14 +79,14 @@ class SellingPartner { if (!this._region || !/^(eu|na|fe)$/.test(this._region)) { throw new CustomError({ code: "NO_VALID_REGION_PROVIDED", - message: 'Please provide one of: "eu", "na" or "fe"' + message: 'Please provide one of: "eu", "na" or "fe"', }); } if (!this._refresh_token && !this._options.only_grantless_operations) { throw new CustomError({ code: "NO_REFRESH_TOKEN_PROVIDED", message: - 'Please provide a refresh token or set "only_grantless_operations" option to true' + 'Please provide a refresh token or set "only_grantless_operations" option to true', }); } @@ -113,7 +113,7 @@ class SellingPartner { code: "VERSION_DEFINED_FOR_INVALID_ENDPOINTS", message: `One or more endpoints are not valid. These endpoints don't exist: ${invalid_endpoints.join( "," - )}` + )}`, }); } let invalid_endpoints_versions = Object.keys(endpoints_versions).filter( @@ -128,7 +128,7 @@ class SellingPartner { code: "INVALID_VERSION_FOR_ENDPOINTS", message: `The provided version for the following endpoint(s) is not valid: ${invalid_endpoints_versions.join( "," - )}` + )}`, }); } return endpoints_versions; @@ -182,7 +182,7 @@ class SellingPartner { if (!details || !details.url) { throw new CustomError({ code: "DOCUMENT_INFORMATION_MISSING", - message: "Please provide url" + message: "Please provide url", }); } let compression = details.compressionAlgorithm; @@ -190,7 +190,7 @@ class SellingPartner { if (compression && compression !== "GZIP") { throw new CustomError({ code: "UNKNOWN_ZIP_STANDARD", - message: `Cannot unzip ${compression}, expecting GZIP` + message: `Cannot unzip ${compression}, expecting GZIP`, }); } } @@ -203,18 +203,18 @@ class SellingPartner { } catch (e) { throw new CustomError({ code: `${request_type}_ERROR`, - message: res.body + message: res.body, }); } if (json_res && json_res.Error) { throw new CustomError({ code: json_res.Error.Code, - message: json_res.Error.Message + message: json_res.Error.Message, }); } else { throw new CustomError({ code: `${request_type}_ERROR`, - message: json_res + message: json_res, }); } } @@ -238,7 +238,7 @@ class SellingPartner { } catch (e) { throw new CustomError({ code: "DECODE_ERROR", - message: e.message + message: e.message, }); } } @@ -246,11 +246,11 @@ class SellingPartner { _constructRefreshAccessTokenBody(scope) { let body = { client_id: this._credentials.app_client.id, - client_secret: this._credentials.app_client.secret + client_secret: this._credentials.app_client.secret, }; let valid_scopes = [ "sellingpartnerapi::notifications", - "sellingpartnerapi::client_credential:rotation" + "sellingpartnerapi::client_credential:rotation", ]; if (scope) { // Make sure that scope is valid @@ -259,7 +259,7 @@ class SellingPartner { code: "INVALID_SCOPE_ERROR", message: `"Scope for requesting token for grantless operations is invalid. Please provide one of: ${valid_scopes.join( "," - )}` + )}`, }); } body.grant_type = "client_credentials"; @@ -272,7 +272,7 @@ class SellingPartner { code: "NO_SCOPE_PROVIDED", message: `"Grantless tokens require a scope. Please provide one of: ${valid_scopes.join( "," - )}` + )}`, }); } return JSON.stringify(body); @@ -294,7 +294,7 @@ class SellingPartner { throw new CustomError({ code: "NO_ACCESS_TOKEN_PRESENT", message: - 'Did you turn off "auto_request_tokens" and forgot to refresh the access token or the scope for a grantless token?' + 'Did you turn off "auto_request_tokens" and forgot to refresh the access token or the scope for a grantless token?', }); } } @@ -307,7 +307,7 @@ class SellingPartner { throw new CustomError({ code: "NO_VALID_METHOD_PROVIDED", message: - 'Please provide a valid HTTP Method ("GET","POST","PUT","DELETE" or "PATCH") when using "api_path"' + 'Please provide a valid HTTP Method ("GET","POST","PUT","DELETE" or "PATCH") when using "api_path"', }); } return method.toUpperCase(); @@ -317,7 +317,7 @@ class SellingPartner { if (!operation) { throw new CustomError({ code: "NO_OPERATION_GIVEN", - message: "Please provide an operation to call" + message: "Please provide an operation to call", }); } // Split operation in endpoint and operation if shorthand dot notation @@ -328,19 +328,19 @@ class SellingPartner { } else if (!endpoint) { throw new CustomError({ code: "NO_ENDPOINT_GIVEN", - message: "Please provide an endpoint to call" + message: "Please provide an endpoint to call", }); } if (!endpoints[endpoint]) { throw new CustomError({ code: "ENDPOINT_NOT_FOUND", - message: `No endpoint found: ${endpoint}` + message: `No endpoint found: ${endpoint}`, }); } if (!endpoints[endpoint].__operations.includes(operation)) { throw new CustomError({ code: "INVALID_OPERATION_FOR_ENDPOINT", - message: `The operation ${operation} is not valid for endpoint ${endpoint}` + message: `The operation ${operation} is not valid for endpoint ${endpoint}`, }); } return { operation, endpoint }; @@ -360,7 +360,7 @@ class SellingPartner { if (!this._options.version_fallback || !fallback_version) { throw new CustomError({ code: "OPERATION_NOT_FOUND_FOR_VERSION", - message: `Operation ${operation} not found for version ${version}` + message: `Operation ${operation} not found for version ${version}`, }); } return fallback_version; @@ -374,7 +374,7 @@ class SellingPartner { code: "INVALID_VERSION", message: `Invalid version ${version} for endpoint ${endpoint} and operation ${operation}. Should be one of: ${endpoints[ endpoint - ].__versions.join('","')}` + ].__versions.join('","')}`, }); } // If operation is not supported for the version: @@ -416,7 +416,7 @@ class SellingPartner { throw new CustomError({ code: "INVALID_OPERATION_ERROR", message: - 'Operation is not grantless. Set "only_grantless_operations" to false and provide a "refresh_token" to be able to call the operation.' + 'Operation is not grantless. Set "only_grantless_operations" to false and provide a "refresh_token" to be able to call the operation.', }); } } @@ -426,14 +426,14 @@ class SellingPartner { throw new CustomError({ code: "NO_AUTH_CODE_PROVIDED", message: - 'Please provide an authorization code (spapi_auth_code) operation to exchange it for a "refresh_token".' + 'Please provide an authorization code (spapi_auth_code) operation to exchange it for a "refresh_token".', }); } let body = { grant_type: "authorization_code", code: auth_code, client_id: this._credentials.app_client.id, - client_secret: this._credentials.app_client.secret + client_secret: this._credentials.app_client.secret, }; return JSON.stringify(body); } @@ -443,8 +443,8 @@ class SellingPartner { operation: "reports.createReport", body: req_params.body, options: { - ...(req_params.version ? { version: req_params.version } : {}) - } + ...(req_params.version ? { version: req_params.version } : {}), + }, }); return res.reportId; } @@ -453,11 +453,11 @@ class SellingPartner { await this.callAPI({ operation: "reports.cancelReport", path: { - reportId: report_id + reportId: report_id, }, options: { - ...(req_params.version ? { version: req_params.version } : {}) - } + ...(req_params.version ? { version: req_params.version } : {}), + }, }); } @@ -465,18 +465,18 @@ class SellingPartner { let res = await this.callAPI({ operation: "reports.getReport", path: { - reportId: report_id + reportId: report_id, }, options: { - ...(req_params.version ? { version: req_params.version } : {}) - } + ...(req_params.version ? { version: req_params.version } : {}), + }, }); if (res.processingStatus === "DONE") { return res.reportDocumentId; } else if (["CANCELLED", "FATAL"].includes(res.processingStatus)) { throw new CustomError({ code: "REPORT_PROCESSING_" + res.processingStatus, - message: "Something went wrong while processing the report." + message: "Something went wrong while processing the report.", }); } else { req_params.tries++; @@ -496,7 +496,7 @@ class SellingPartner { await this._cancelReport(req_params, report_id); throw new CustomError({ code: "REPORT_PROCESSING_CANCELLED_MANUALLY", - message: `Report did not finish after ${req_params.tries} tries (interval ${interval} ms).` + message: `Report did not finish after ${req_params.tries} tries (interval ${interval} ms).`, }); } } @@ -506,11 +506,11 @@ class SellingPartner { let res = await this.callAPI({ operation: "reports.getReportDocument", path: { - reportDocumentId: report_document_id + reportDocumentId: report_document_id, }, options: { - ...(req_params.version ? { version: req_params.version } : {}) - } + ...(req_params.version ? { version: req_params.version } : {}), + }, }); return res; } @@ -541,8 +541,8 @@ class SellingPartner { url: "https://api.amazon.com/auth/o2/token", body: this._constructExchangeBody(auth_code), headers: { - "Content-Type": "application/json" - } + "Content-Type": "application/json", + }, }); let json_res; try { @@ -550,13 +550,13 @@ class SellingPartner { } catch (e) { throw new CustomError({ code: "EXCHANGE_AUTH_CODE_PARSE_ERROR", - message: res.body + message: res.body, }); } if (json_res.error) { throw new CustomError({ code: json_res.error, - message: json_res.error_description + message: json_res.error_description, }); } return json_res; @@ -570,8 +570,8 @@ class SellingPartner { url: "https://api.amazon.com/auth/o2/token", body: this._constructRefreshAccessTokenBody(scope), headers: { - "Content-Type": "application/json" - } + "Content-Type": "application/json", + }, }); let json_res; try { @@ -579,7 +579,7 @@ class SellingPartner { } catch (e) { throw new CustomError({ code: "REFRESH_ACCESS_TOKEN_PARSE_ERROR", - message: res.body + message: res.body, }); } if (json_res.access_token) { @@ -591,12 +591,12 @@ class SellingPartner { } else if (json_res.error) { throw new CustomError({ code: json_res.error, - message: json_res.error_description + message: json_res.error_description, }); } else { throw new CustomError({ code: "UNKNOWN_REFRESH_ACCESS_TOKEN_ERROR", - message: res.body + message: res.body, }); } } @@ -637,7 +637,7 @@ class SellingPartner { ); req_params = { ...endpoints[endpoint][version][operation](req_params), - ...(req_params.headers || {}) + ...(req_params.headers || {}), }; if (req_params.deprecation_date) { utils.warn("DEPRECATION", req_params.deprecation_date); @@ -680,7 +680,7 @@ class SellingPartner { } catch (e) { throw new CustomError({ code: "JSON_PARSE_ERROR", - message: res.body + message: res.body, }); } if (json_res.errors?.length) { @@ -713,19 +713,13 @@ class SellingPartner { throw new CustomError({ code: "INVALID_SANDBOX_PARAMETERS", message: - "You're in SANDBOX mode, make sure sandbox parameters are correct, as in Amazon SP API documentation: https://github.com/amzn/selling-partner-api-docs/blob/main/guides/developer-guide/SellingPartnerApiDeveloperGuide.md#how-to-make-a-sandbox-call-to-the-selling-partner-api" + "You're in SANDBOX mode, make sure sandbox parameters are correct, as in Amazon SP API documentation: https://github.com/amzn/selling-partner-api-docs/blob/main/guides/developer-guide/SellingPartnerApiDeveloperGuide.md#how-to-make-a-sandbox-call-to-the-selling-partner-api", }); } throw new CustomError(error); } - // If there is a pagination outside payload (like for getInventorySummaries), this will include it with the result - if (json_res.pagination && json_res.payload) { - return Object.assign(json_res.pagination, json_res.payload); - } - - // Some calls do not return response in payload but directly (i.e. operation "getSmallAndLightEligibilityBySellerSKU")! - return json_res.payload || json_res; + return json_res; } // Download a report or feed result @@ -737,7 +731,7 @@ class SellingPartner { async download(details, options = {}) { options = Object.assign( { - unzip: true + unzip: true, }, options ); @@ -745,7 +739,7 @@ class SellingPartner { // Result will be a tab-delimited flat file or an xml document let res = await this._request.execute({ url: details.url, - timeouts: options.timeouts + timeouts: options.timeouts, }); this._validateUpOrDownloadSuccess(res, "DOWNLOAD"); @@ -765,7 +759,7 @@ class SellingPartner { throw new CustomError({ code: "PARSE_ERROR", message: - "Report is a .xlsx file. Could not parse result to JSON. Remove the 'json:true' option." + "Report is a .xlsx file. Could not parse result to JSON. Remove the 'json:true' option.", }); } @@ -781,7 +775,7 @@ class SellingPartner { } catch { decoded = await csv({ delimiter: "\t", - quote: "off" + quote: "off", }).fromString(decoded); } } @@ -789,7 +783,7 @@ class SellingPartner { throw new CustomError({ code: "PARSE_ERROR", message: "Could not parse result to JSON.", - details: decoded + details: decoded, }); } } @@ -811,14 +805,14 @@ class SellingPartner { throw new CustomError({ code: "NO_FEED_CONTENT_PROVIDED", message: - 'Please provide "content" (string) or "file" (absolute path) of feed.' + 'Please provide "content" (string) or "file" (absolute path) of feed.', }); } if (!feed.contentType) { throw new CustomError({ code: "NO_FEED_CONTENT_TYPE_PROVIDED", message: - 'Please provide "contentType" of feed (should be identical to the contentType used in "createFeedDocument" operation).' + 'Please provide "contentType" of feed (should be identical to the contentType used in "createFeedDocument" operation).', }); } let feed_content = @@ -828,9 +822,9 @@ class SellingPartner { url: details.url, method: "PUT", headers: { - "Content-Type": feed.contentType + "Content-Type": feed.contentType, }, - body: Buffer.from(feed_content) + body: Buffer.from(feed_content), }); this._validateUpOrDownloadSuccess(res, "UPLOAD"); return { success: true }; From 9d7a8703adc4e8ad1032de7f462cbb0f8f2acb07 Mon Sep 17 00:00:00 2001 From: Pradeep S <85151832+pradeep-gox@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:33:31 +0530 Subject: [PATCH 2/2] chore: remove formatting --- lib/SellingPartner.js | 120 +++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/lib/SellingPartner.js b/lib/SellingPartner.js index ec0d15e..f892ffd 100644 --- a/lib/SellingPartner.js +++ b/lib/SellingPartner.js @@ -62,7 +62,7 @@ class SellingPartner { user_agent: `amazon-sp-api/${client_version} (Language=Node.js/${node_version}; Platform=${os.type()}/${os.release()})`, debug_log: false, timeouts: {}, - retry_remote_timeout: true, + retry_remote_timeout: true }, config.options ); @@ -79,14 +79,14 @@ class SellingPartner { if (!this._region || !/^(eu|na|fe)$/.test(this._region)) { throw new CustomError({ code: "NO_VALID_REGION_PROVIDED", - message: 'Please provide one of: "eu", "na" or "fe"', + message: 'Please provide one of: "eu", "na" or "fe"' }); } if (!this._refresh_token && !this._options.only_grantless_operations) { throw new CustomError({ code: "NO_REFRESH_TOKEN_PROVIDED", message: - 'Please provide a refresh token or set "only_grantless_operations" option to true', + 'Please provide a refresh token or set "only_grantless_operations" option to true' }); } @@ -113,7 +113,7 @@ class SellingPartner { code: "VERSION_DEFINED_FOR_INVALID_ENDPOINTS", message: `One or more endpoints are not valid. These endpoints don't exist: ${invalid_endpoints.join( "," - )}`, + )}` }); } let invalid_endpoints_versions = Object.keys(endpoints_versions).filter( @@ -128,7 +128,7 @@ class SellingPartner { code: "INVALID_VERSION_FOR_ENDPOINTS", message: `The provided version for the following endpoint(s) is not valid: ${invalid_endpoints_versions.join( "," - )}`, + )}` }); } return endpoints_versions; @@ -182,7 +182,7 @@ class SellingPartner { if (!details || !details.url) { throw new CustomError({ code: "DOCUMENT_INFORMATION_MISSING", - message: "Please provide url", + message: "Please provide url" }); } let compression = details.compressionAlgorithm; @@ -190,7 +190,7 @@ class SellingPartner { if (compression && compression !== "GZIP") { throw new CustomError({ code: "UNKNOWN_ZIP_STANDARD", - message: `Cannot unzip ${compression}, expecting GZIP`, + message: `Cannot unzip ${compression}, expecting GZIP` }); } } @@ -203,18 +203,18 @@ class SellingPartner { } catch (e) { throw new CustomError({ code: `${request_type}_ERROR`, - message: res.body, + message: res.body }); } if (json_res && json_res.Error) { throw new CustomError({ code: json_res.Error.Code, - message: json_res.Error.Message, + message: json_res.Error.Message }); } else { throw new CustomError({ code: `${request_type}_ERROR`, - message: json_res, + message: json_res }); } } @@ -238,7 +238,7 @@ class SellingPartner { } catch (e) { throw new CustomError({ code: "DECODE_ERROR", - message: e.message, + message: e.message }); } } @@ -246,11 +246,11 @@ class SellingPartner { _constructRefreshAccessTokenBody(scope) { let body = { client_id: this._credentials.app_client.id, - client_secret: this._credentials.app_client.secret, + client_secret: this._credentials.app_client.secret }; let valid_scopes = [ "sellingpartnerapi::notifications", - "sellingpartnerapi::client_credential:rotation", + "sellingpartnerapi::client_credential:rotation" ]; if (scope) { // Make sure that scope is valid @@ -259,7 +259,7 @@ class SellingPartner { code: "INVALID_SCOPE_ERROR", message: `"Scope for requesting token for grantless operations is invalid. Please provide one of: ${valid_scopes.join( "," - )}`, + )}` }); } body.grant_type = "client_credentials"; @@ -272,7 +272,7 @@ class SellingPartner { code: "NO_SCOPE_PROVIDED", message: `"Grantless tokens require a scope. Please provide one of: ${valid_scopes.join( "," - )}`, + )}` }); } return JSON.stringify(body); @@ -294,7 +294,7 @@ class SellingPartner { throw new CustomError({ code: "NO_ACCESS_TOKEN_PRESENT", message: - 'Did you turn off "auto_request_tokens" and forgot to refresh the access token or the scope for a grantless token?', + 'Did you turn off "auto_request_tokens" and forgot to refresh the access token or the scope for a grantless token?' }); } } @@ -307,7 +307,7 @@ class SellingPartner { throw new CustomError({ code: "NO_VALID_METHOD_PROVIDED", message: - 'Please provide a valid HTTP Method ("GET","POST","PUT","DELETE" or "PATCH") when using "api_path"', + 'Please provide a valid HTTP Method ("GET","POST","PUT","DELETE" or "PATCH") when using "api_path"' }); } return method.toUpperCase(); @@ -317,7 +317,7 @@ class SellingPartner { if (!operation) { throw new CustomError({ code: "NO_OPERATION_GIVEN", - message: "Please provide an operation to call", + message: "Please provide an operation to call" }); } // Split operation in endpoint and operation if shorthand dot notation @@ -328,19 +328,19 @@ class SellingPartner { } else if (!endpoint) { throw new CustomError({ code: "NO_ENDPOINT_GIVEN", - message: "Please provide an endpoint to call", + message: "Please provide an endpoint to call" }); } if (!endpoints[endpoint]) { throw new CustomError({ code: "ENDPOINT_NOT_FOUND", - message: `No endpoint found: ${endpoint}`, + message: `No endpoint found: ${endpoint}` }); } if (!endpoints[endpoint].__operations.includes(operation)) { throw new CustomError({ code: "INVALID_OPERATION_FOR_ENDPOINT", - message: `The operation ${operation} is not valid for endpoint ${endpoint}`, + message: `The operation ${operation} is not valid for endpoint ${endpoint}` }); } return { operation, endpoint }; @@ -360,7 +360,7 @@ class SellingPartner { if (!this._options.version_fallback || !fallback_version) { throw new CustomError({ code: "OPERATION_NOT_FOUND_FOR_VERSION", - message: `Operation ${operation} not found for version ${version}`, + message: `Operation ${operation} not found for version ${version}` }); } return fallback_version; @@ -374,7 +374,7 @@ class SellingPartner { code: "INVALID_VERSION", message: `Invalid version ${version} for endpoint ${endpoint} and operation ${operation}. Should be one of: ${endpoints[ endpoint - ].__versions.join('","')}`, + ].__versions.join('","')}` }); } // If operation is not supported for the version: @@ -416,7 +416,7 @@ class SellingPartner { throw new CustomError({ code: "INVALID_OPERATION_ERROR", message: - 'Operation is not grantless. Set "only_grantless_operations" to false and provide a "refresh_token" to be able to call the operation.', + 'Operation is not grantless. Set "only_grantless_operations" to false and provide a "refresh_token" to be able to call the operation.' }); } } @@ -426,14 +426,14 @@ class SellingPartner { throw new CustomError({ code: "NO_AUTH_CODE_PROVIDED", message: - 'Please provide an authorization code (spapi_auth_code) operation to exchange it for a "refresh_token".', + 'Please provide an authorization code (spapi_auth_code) operation to exchange it for a "refresh_token".' }); } let body = { grant_type: "authorization_code", code: auth_code, client_id: this._credentials.app_client.id, - client_secret: this._credentials.app_client.secret, + client_secret: this._credentials.app_client.secret }; return JSON.stringify(body); } @@ -443,8 +443,8 @@ class SellingPartner { operation: "reports.createReport", body: req_params.body, options: { - ...(req_params.version ? { version: req_params.version } : {}), - }, + ...(req_params.version ? { version: req_params.version } : {}) + } }); return res.reportId; } @@ -453,11 +453,11 @@ class SellingPartner { await this.callAPI({ operation: "reports.cancelReport", path: { - reportId: report_id, + reportId: report_id }, options: { - ...(req_params.version ? { version: req_params.version } : {}), - }, + ...(req_params.version ? { version: req_params.version } : {}) + } }); } @@ -465,18 +465,18 @@ class SellingPartner { let res = await this.callAPI({ operation: "reports.getReport", path: { - reportId: report_id, + reportId: report_id }, options: { - ...(req_params.version ? { version: req_params.version } : {}), - }, + ...(req_params.version ? { version: req_params.version } : {}) + } }); if (res.processingStatus === "DONE") { return res.reportDocumentId; } else if (["CANCELLED", "FATAL"].includes(res.processingStatus)) { throw new CustomError({ code: "REPORT_PROCESSING_" + res.processingStatus, - message: "Something went wrong while processing the report.", + message: "Something went wrong while processing the report." }); } else { req_params.tries++; @@ -496,7 +496,7 @@ class SellingPartner { await this._cancelReport(req_params, report_id); throw new CustomError({ code: "REPORT_PROCESSING_CANCELLED_MANUALLY", - message: `Report did not finish after ${req_params.tries} tries (interval ${interval} ms).`, + message: `Report did not finish after ${req_params.tries} tries (interval ${interval} ms).` }); } } @@ -506,11 +506,11 @@ class SellingPartner { let res = await this.callAPI({ operation: "reports.getReportDocument", path: { - reportDocumentId: report_document_id, + reportDocumentId: report_document_id }, options: { - ...(req_params.version ? { version: req_params.version } : {}), - }, + ...(req_params.version ? { version: req_params.version } : {}) + } }); return res; } @@ -541,8 +541,8 @@ class SellingPartner { url: "https://api.amazon.com/auth/o2/token", body: this._constructExchangeBody(auth_code), headers: { - "Content-Type": "application/json", - }, + "Content-Type": "application/json" + } }); let json_res; try { @@ -550,13 +550,13 @@ class SellingPartner { } catch (e) { throw new CustomError({ code: "EXCHANGE_AUTH_CODE_PARSE_ERROR", - message: res.body, + message: res.body }); } if (json_res.error) { throw new CustomError({ code: json_res.error, - message: json_res.error_description, + message: json_res.error_description }); } return json_res; @@ -570,8 +570,8 @@ class SellingPartner { url: "https://api.amazon.com/auth/o2/token", body: this._constructRefreshAccessTokenBody(scope), headers: { - "Content-Type": "application/json", - }, + "Content-Type": "application/json" + } }); let json_res; try { @@ -579,7 +579,7 @@ class SellingPartner { } catch (e) { throw new CustomError({ code: "REFRESH_ACCESS_TOKEN_PARSE_ERROR", - message: res.body, + message: res.body }); } if (json_res.access_token) { @@ -591,12 +591,12 @@ class SellingPartner { } else if (json_res.error) { throw new CustomError({ code: json_res.error, - message: json_res.error_description, + message: json_res.error_description }); } else { throw new CustomError({ code: "UNKNOWN_REFRESH_ACCESS_TOKEN_ERROR", - message: res.body, + message: res.body }); } } @@ -637,7 +637,7 @@ class SellingPartner { ); req_params = { ...endpoints[endpoint][version][operation](req_params), - ...(req_params.headers || {}), + ...(req_params.headers || {}) }; if (req_params.deprecation_date) { utils.warn("DEPRECATION", req_params.deprecation_date); @@ -680,7 +680,7 @@ class SellingPartner { } catch (e) { throw new CustomError({ code: "JSON_PARSE_ERROR", - message: res.body, + message: res.body }); } if (json_res.errors?.length) { @@ -713,7 +713,7 @@ class SellingPartner { throw new CustomError({ code: "INVALID_SANDBOX_PARAMETERS", message: - "You're in SANDBOX mode, make sure sandbox parameters are correct, as in Amazon SP API documentation: https://github.com/amzn/selling-partner-api-docs/blob/main/guides/developer-guide/SellingPartnerApiDeveloperGuide.md#how-to-make-a-sandbox-call-to-the-selling-partner-api", + "You're in SANDBOX mode, make sure sandbox parameters are correct, as in Amazon SP API documentation: https://github.com/amzn/selling-partner-api-docs/blob/main/guides/developer-guide/SellingPartnerApiDeveloperGuide.md#how-to-make-a-sandbox-call-to-the-selling-partner-api" }); } throw new CustomError(error); @@ -731,7 +731,7 @@ class SellingPartner { async download(details, options = {}) { options = Object.assign( { - unzip: true, + unzip: true }, options ); @@ -739,7 +739,7 @@ class SellingPartner { // Result will be a tab-delimited flat file or an xml document let res = await this._request.execute({ url: details.url, - timeouts: options.timeouts, + timeouts: options.timeouts }); this._validateUpOrDownloadSuccess(res, "DOWNLOAD"); @@ -759,7 +759,7 @@ class SellingPartner { throw new CustomError({ code: "PARSE_ERROR", message: - "Report is a .xlsx file. Could not parse result to JSON. Remove the 'json:true' option.", + "Report is a .xlsx file. Could not parse result to JSON. Remove the 'json:true' option." }); } @@ -775,7 +775,7 @@ class SellingPartner { } catch { decoded = await csv({ delimiter: "\t", - quote: "off", + quote: "off" }).fromString(decoded); } } @@ -783,7 +783,7 @@ class SellingPartner { throw new CustomError({ code: "PARSE_ERROR", message: "Could not parse result to JSON.", - details: decoded, + details: decoded }); } } @@ -805,14 +805,14 @@ class SellingPartner { throw new CustomError({ code: "NO_FEED_CONTENT_PROVIDED", message: - 'Please provide "content" (string) or "file" (absolute path) of feed.', + 'Please provide "content" (string) or "file" (absolute path) of feed.' }); } if (!feed.contentType) { throw new CustomError({ code: "NO_FEED_CONTENT_TYPE_PROVIDED", message: - 'Please provide "contentType" of feed (should be identical to the contentType used in "createFeedDocument" operation).', + 'Please provide "contentType" of feed (should be identical to the contentType used in "createFeedDocument" operation).' }); } let feed_content = @@ -822,9 +822,9 @@ class SellingPartner { url: details.url, method: "PUT", headers: { - "Content-Type": feed.contentType, + "Content-Type": feed.contentType }, - body: Buffer.from(feed_content), + body: Buffer.from(feed_content) }); this._validateUpOrDownloadSuccess(res, "UPLOAD"); return { success: true };