Skip to content

Commit 5ccb213

Browse files
authored
Merge pull request #511 from EasyPost/ups_endpoint
fix: endpoint used for UPS create/update
2 parents 65f58c6 + 72e5fbb commit 5ccb213

File tree

8 files changed

+161
-462
lines changed

8 files changed

+161
-462
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## v8.0.2 (2025-05-27)
4+
5+
- Corrects the endpoint used for creating/updating UPS accounts
6+
37
## v8.0.1 (2025-05-08)
48

59
- Fixes built distribution by removing reference to removed `repl`

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@easypost/api",
33
"description": "EasyPost Node Client Library",
4-
"version": "8.0.1",
4+
"version": "8.0.2",
55
"author": "Easypost Engineering <[email protected]>",
66
"homepage": "https://easypost.com",
77
"exports": {

src/constants.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ export default class Constants {
77
static get CARRIER_ACCOUNTS_WITH_CUSTOM_CREATE_WORKFLOWS() {
88
return ['FedexAccount', 'FedexSmartpostAccount'];
99
}
10-
static get UPS_OAUTH_CARRIER_TYPES() {
11-
return ['UpsAccount', 'UpsMailInnovationsAccount', 'UpsSurepostAccount'];
12-
}
1310
static get CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH() {
14-
return ['AmazonShippingAccount'];
11+
return [
12+
'AmazonShippingAccount',
13+
'UpsAccount',
14+
'UpsMailInnovationsAccount',
15+
'UpsSurepostAccount',
16+
];
1517
}
1618
static EXTERNAL_API_CALL_FAILED = 'Communication with %s failed, please try again later';
1719
static INVALID_API_KEY_TYPE = 'Invalid API key type.';

src/services/carrier_account_service.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,10 @@ export default (easypostClient) =>
3939
* @returns {CarrierAccount} - The updated carrier account.
4040
*/
4141
static async update(id, params) {
42-
const carrierAccount = await this.retrieve(id);
43-
44-
const carrierAccountType = carrierAccount.type;
45-
46-
const endpoint = this._selectCarrierAccountUpdateEndpoint(carrierAccountType, id);
47-
const wrappedParams = this._wrapCarrierAccountParams(carrierAccountType, params);
42+
const wrappedParams = { carrier_account: params };
4843

4944
try {
50-
const response = await easypostClient._patch(endpoint, wrappedParams);
45+
const response = await easypostClient._patch(`carrier_accounts/${id}`, wrappedParams);
5146

5247
return this._convertToEasyPostObject(response.body, wrappedParams);
5348
} catch (e) {
@@ -82,29 +77,13 @@ export default (easypostClient) =>
8277
static _selectCarrierAccountCreationEndpoint(carrierAccountType) {
8378
if (Constants.CARRIER_ACCOUNTS_WITH_CUSTOM_CREATE_WORKFLOWS.includes(carrierAccountType)) {
8479
return 'carrier_accounts/register';
85-
} else if (Constants.UPS_OAUTH_CARRIER_TYPES.includes(carrierAccountType)) {
86-
return 'ups_oauth_registrations';
8780
} else if (Constants.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.includes(carrierAccountType)) {
8881
return 'carrier_accounts/register_oauth';
8982
}
9083

9184
return 'carrier_accounts';
9285
}
9386

94-
/**
95-
* Returns the correct carrier_account endpoint when updating a record based on the type.
96-
* @private
97-
* @param {string} carrierAccountType - The type of carrier account to be updated.
98-
* @param {string} carrierAccountId - The ID of the carrier account to be updated.
99-
* @returns {string} - The endpoint to be used for the carrier account update request.
100-
*/
101-
static _selectCarrierAccountUpdateEndpoint(carrierAccountType, carrierAccountId) {
102-
if (Constants.UPS_OAUTH_CARRIER_TYPES.includes(carrierAccountType)) {
103-
return `ups_oauth_registrations/${carrierAccountId}`;
104-
}
105-
return `carrier_accounts/${carrierAccountId}`;
106-
}
107-
10887
/**
10988
* Wraps the carrier account parameters in the correct format based on the type.
11089
* @private
@@ -113,9 +92,7 @@ export default (easypostClient) =>
11392
* @returns {Object} - The wrapped carrier account parameters.
11493
*/
11594
static _wrapCarrierAccountParams(carrierAccountType, params) {
116-
if (Constants.UPS_OAUTH_CARRIER_TYPES.includes(carrierAccountType)) {
117-
return { ups_oauth_registrations: params };
118-
} else if (Constants.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.includes(carrierAccountType)) {
95+
if (Constants.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.includes(carrierAccountType)) {
11996
return { carrier_account_oauth_registrations: params };
12097
}
12198

test/cassettes/CarrierAccount-Service_2076435725/creates-a-UPS-carrier-account_3537134608/recording.har

Lines changed: 27 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)