Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v8.0.2 (2025-05-27)

- Corrects the endpoint used for creating/updating UPS accounts

## v8.0.1 (2025-05-08)

- Fixes built distribution by removing reference to removed `repl`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@easypost/api",
"description": "EasyPost Node Client Library",
"version": "8.0.1",
"version": "8.0.2",
"author": "Easypost Engineering <oss@easypost.com>",
"homepage": "https://easypost.com",
"exports": {
Expand Down
10 changes: 6 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export default class Constants {
static get CARRIER_ACCOUNTS_WITH_CUSTOM_CREATE_WORKFLOWS() {
return ['FedexAccount', 'FedexSmartpostAccount'];
}
static get UPS_OAUTH_CARRIER_TYPES() {
return ['UpsAccount', 'UpsMailInnovationsAccount', 'UpsSurepostAccount'];
}
static get CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH() {
return ['AmazonShippingAccount'];
return [
'AmazonShippingAccount',
'UpsAccount',
'UpsMailInnovationsAccount',
'UpsSurepostAccount',
];
}
static EXTERNAL_API_CALL_FAILED = 'Communication with %s failed, please try again later';
static INVALID_API_KEY_TYPE = 'Invalid API key type.';
Expand Down
29 changes: 3 additions & 26 deletions src/services/carrier_account_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@ export default (easypostClient) =>
* @returns {CarrierAccount} - The updated carrier account.
*/
static async update(id, params) {
const carrierAccount = await this.retrieve(id);

const carrierAccountType = carrierAccount.type;

const endpoint = this._selectCarrierAccountUpdateEndpoint(carrierAccountType, id);
const wrappedParams = this._wrapCarrierAccountParams(carrierAccountType, params);
const wrappedParams = { carrier_account: params };

try {
const response = await easypostClient._patch(endpoint, wrappedParams);
const response = await easypostClient._patch(`carrier_accounts/${id}`, wrappedParams);

return this._convertToEasyPostObject(response.body, wrappedParams);
} catch (e) {
Expand Down Expand Up @@ -82,29 +77,13 @@ export default (easypostClient) =>
static _selectCarrierAccountCreationEndpoint(carrierAccountType) {
if (Constants.CARRIER_ACCOUNTS_WITH_CUSTOM_CREATE_WORKFLOWS.includes(carrierAccountType)) {
return 'carrier_accounts/register';
} else if (Constants.UPS_OAUTH_CARRIER_TYPES.includes(carrierAccountType)) {
return 'ups_oauth_registrations';
} else if (Constants.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.includes(carrierAccountType)) {
return 'carrier_accounts/register_oauth';
}

return 'carrier_accounts';
}

/**
* Returns the correct carrier_account endpoint when updating a record based on the type.
* @private
* @param {string} carrierAccountType - The type of carrier account to be updated.
* @param {string} carrierAccountId - The ID of the carrier account to be updated.
* @returns {string} - The endpoint to be used for the carrier account update request.
*/
static _selectCarrierAccountUpdateEndpoint(carrierAccountType, carrierAccountId) {
if (Constants.UPS_OAUTH_CARRIER_TYPES.includes(carrierAccountType)) {
return `ups_oauth_registrations/${carrierAccountId}`;
}
return `carrier_accounts/${carrierAccountId}`;
}

/**
* Wraps the carrier account parameters in the correct format based on the type.
* @private
Expand All @@ -113,9 +92,7 @@ export default (easypostClient) =>
* @returns {Object} - The wrapped carrier account parameters.
*/
static _wrapCarrierAccountParams(carrierAccountType, params) {
if (Constants.UPS_OAUTH_CARRIER_TYPES.includes(carrierAccountType)) {
return { ups_oauth_registrations: params };
} else if (Constants.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.includes(carrierAccountType)) {
if (Constants.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.includes(carrierAccountType)) {
return { carrier_account_oauth_registrations: params };
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading