Skip to content

Commit 4ea502a

Browse files
authored
Merge pull request #513 from EasyPost/luma
feat: add luma functions
2 parents 91842e4 + a5530b7 commit 4ea502a

File tree

12 files changed

+792
-9
lines changed

12 files changed

+792
-9
lines changed

CHANGELOG.md

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

3+
## Next Release
4+
5+
- Adds the following functions
6+
- `shipment.createAndBuyLuma`
7+
- `shipment.buyLuma`
8+
- `luma.getPromise`
9+
310
## v8.1.0 (2025-05-29)
411

512
- Adds `reference` and `recipient_name` to Claims

examples

Submodule examples updated 1556 files

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"homepage": "https://easypost.com",
77
"exports": {
88
".": {
9+
"types": "./types/index.d.ts",
910
"import": "./dist/easypost.mjs",
10-
"require": "./dist/easypost.js",
11-
"types": "./types/index.d.ts"
11+
"require": "./dist/easypost.js"
1212
}
1313
},
1414
"main": "./dist/easypost.js",

src/easypost.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import CustomsItemService from './services/customs_item_service';
2222
import EndShipperService from './services/end_shipper_service';
2323
import EventService from './services/event_service';
2424
import InsuranceService from './services/insurance_service';
25+
import LumaService from './services/luma_service';
2526
import OrderService from './services/order_service';
2627
import ParcelService from './services/parcel_service';
2728
import PickupService from './services/pickup_service';
@@ -371,6 +372,7 @@ EasyPostClient.SERVICES = {
371372
EndShipper: EndShipperService,
372373
Event: EventService,
373374
Insurance: InsuranceService,
375+
Luma: LumaService,
374376
Order: OrderService,
375377
Parcel: ParcelService,
376378
Pickup: PickupService,

src/services/luma_service.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import baseService from './base_service';
2+
3+
export default (easypostClient) =>
4+
/**
5+
* The LumaService class provides methods for interacting with EasyPost Luma objects.
6+
* @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service.
7+
*/
8+
class LumaService extends baseService(easypostClient) {
9+
/**
10+
* Get service recommendations from Luma that meet the criteria of your ruleset.
11+
* @param {Object} params - The parameters to get a Luma promise with.
12+
* @returns {Object} - An object containing the Luma promise.
13+
*/
14+
static async getPromise(params) {
15+
const url = `luma/promise`;
16+
17+
const wrappedParams = {
18+
shipment: params,
19+
};
20+
21+
try {
22+
const response = await easypostClient._post(url, wrappedParams);
23+
24+
return this._convertToEasyPostObject(response.body.luma_info, wrappedParams);
25+
} catch (e) {
26+
return Promise.reject(e);
27+
}
28+
}
29+
};

src/services/shipment_service.js

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,14 @@ export default (easypostClient) =>
246246
static async retrieveEstimatedDeliveryDate(id, plannedShipDate) {
247247
const url = `shipments/${id}/smartrate/delivery_date`;
248248

249-
const params = {
249+
const wrappedParams = {
250250
planned_ship_date: plannedShipDate,
251251
};
252252

253253
try {
254-
const response = await easypostClient._get(url, params);
254+
const response = await easypostClient._get(url, wrappedParams);
255255

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

271-
const params = {
271+
const wrappedParams = {
272272
desired_delivery_date: desiredDeliveryDate,
273273
};
274274

275275
try {
276-
const response = await easypostClient._get(url, params);
276+
const response = await easypostClient._get(url, wrappedParams);
277+
278+
return this._convertToEasyPostObject(response.body.rates ?? [], wrappedParams);
279+
} catch (e) {
280+
return Promise.reject(e);
281+
}
282+
}
283+
284+
/**
285+
* Create and buy a Luma Shipment in one call.
286+
* @param {Object} params - The parameters to create and buy a Shipment with Luma.
287+
* @returns {Shipment} - The shipment with the given ID.
288+
*/
289+
static async createAndBuyLuma(params) {
290+
const url = `shipments/luma`;
291+
292+
const wrappedParams = {
293+
shipment: params,
294+
};
295+
296+
try {
297+
const response = await easypostClient._post(url, wrappedParams);
298+
299+
return this._convertToEasyPostObject(response.body, wrappedParams);
300+
} catch (e) {
301+
return Promise.reject(e);
302+
}
303+
}
304+
305+
/**
306+
* Buy a Shipment with Luma.
307+
* @param {string} id - The ID of the Shipment to buy with Luma.
308+
* @param {Object} params - The parameters to buy a Shipment with Luma.
309+
* @returns {Shipment} - The shipment with the given ID.
310+
*/
311+
static async buyLuma(id, params) {
312+
const url = `shipments/${id}/luma`;
313+
314+
try {
315+
const response = await easypostClient._post(url, params);
277316

278-
return this._convertToEasyPostObject(response.body.rates ?? [], params);
317+
return this._convertToEasyPostObject(response.body, params);
279318
} catch (e) {
280319
return Promise.reject(e);
281320
}

test/cassettes/Luma-Service_3101642631/gets-service-recommendations-from-Luma-based-on-your-ruleset_3329319999/recording.har

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

0 commit comments

Comments
 (0)