Skip to content

feat: add luma functions #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2025
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## Next Release

- Adds the following functions
- `shipment.createAndBuyLuma`
- `shipment.buyLuma`
- `luma.getPromise`

## v8.1.0 (2025-05-29)

- Adds `reference` and `recipient_name` to Claims
Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 1556 files
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"homepage": "https://easypost.com",
"exports": {
".": {
"types": "./types/index.d.ts",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Note

I guess order here is important, tools were complaining so re-ordered

"import": "./dist/easypost.mjs",
"require": "./dist/easypost.js",
"types": "./types/index.d.ts"
"require": "./dist/easypost.js"
}
},
"main": "./dist/easypost.js",
Expand Down
2 changes: 2 additions & 0 deletions src/easypost.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import CustomsItemService from './services/customs_item_service';
import EndShipperService from './services/end_shipper_service';
import EventService from './services/event_service';
import InsuranceService from './services/insurance_service';
import LumaService from './services/luma_service';
import OrderService from './services/order_service';
import ParcelService from './services/parcel_service';
import PickupService from './services/pickup_service';
Expand Down Expand Up @@ -371,6 +372,7 @@ EasyPostClient.SERVICES = {
EndShipper: EndShipperService,
Event: EventService,
Insurance: InsuranceService,
Luma: LumaService,
Order: OrderService,
Parcel: ParcelService,
Pickup: PickupService,
Expand Down
29 changes: 29 additions & 0 deletions src/services/luma_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import baseService from './base_service';

export default (easypostClient) =>
/**
* The LumaService class provides methods for interacting with EasyPost Luma objects.
* @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service.
*/
class LumaService extends baseService(easypostClient) {
/**
* Get service recommendations from Luma that meet the criteria of your ruleset.
* @param {Object} params - The parameters to get a Luma promise with.
* @returns {Object} - An object containing the Luma promise.
*/
static async getPromise(params) {
const url = `luma/promise`;

const wrappedParams = {
shipment: params,
};

try {
const response = await easypostClient._post(url, wrappedParams);

return this._convertToEasyPostObject(response.body.luma_info, wrappedParams);
} catch (e) {
return Promise.reject(e);
}
}
};
51 changes: 45 additions & 6 deletions src/services/shipment_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ export default (easypostClient) =>
static async retrieveEstimatedDeliveryDate(id, plannedShipDate) {
const url = `shipments/${id}/smartrate/delivery_date`;

const params = {
const wrappedParams = {
planned_ship_date: plannedShipDate,
};

try {
const response = await easypostClient._get(url, params);
const response = await easypostClient._get(url, wrappedParams);

return this._convertToEasyPostObject(response.body.rates ?? [], params);
return this._convertToEasyPostObject(response.body.rates ?? [], wrappedParams);
} catch (e) {
return Promise.reject(e);
}
Expand All @@ -268,14 +268,53 @@ export default (easypostClient) =>
static async recommendShipDate(id, desiredDeliveryDate) {
const url = `shipments/${id}/smartrate/precision_shipping`;

const params = {
const wrappedParams = {
desired_delivery_date: desiredDeliveryDate,
};

try {
const response = await easypostClient._get(url, params);
const response = await easypostClient._get(url, wrappedParams);

return this._convertToEasyPostObject(response.body.rates ?? [], wrappedParams);
} catch (e) {
return Promise.reject(e);
}
}

/**
* Create and buy a Luma Shipment in one call.
* @param {Object} params - The parameters to create and buy a Shipment with Luma.
* @returns {Shipment} - The shipment with the given ID.
*/
static async createAndBuyLuma(params) {
const url = `shipments/luma`;

const wrappedParams = {
shipment: params,
};

try {
const response = await easypostClient._post(url, wrappedParams);

return this._convertToEasyPostObject(response.body, wrappedParams);
} catch (e) {
return Promise.reject(e);
}
}

/**
* Buy a Shipment with Luma.
* @param {string} id - The ID of the Shipment to buy with Luma.
* @param {Object} params - The parameters to buy a Shipment with Luma.
* @returns {Shipment} - The shipment with the given ID.
*/
static async buyLuma(id, params) {
const url = `shipments/${id}/luma`;

try {
const response = await easypostClient._post(url, params);

return this._convertToEasyPostObject(response.body.rates ?? [], params);
return this._convertToEasyPostObject(response.body, params);
} catch (e) {
return Promise.reject(e);
}
Expand Down

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

Loading