@viyet/magento-client
Version:
Sotheby's Home Custom Magento API Client
119 lines • 4.1 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Offer statuses
*/
var OfferStatusEnum;
(function (OfferStatusEnum) {
OfferStatusEnum["NEGOTIATING"] = "Negotiating";
})(OfferStatusEnum = exports.OfferStatusEnum || (exports.OfferStatusEnum = {}));
/**
* Type of entity placing offer
*/
var OfferLogEntityTypeEnum;
(function (OfferLogEntityTypeEnum) {
OfferLogEntityTypeEnum["ADMIN"] = "Admin";
OfferLogEntityTypeEnum["CONSIGNOR"] = "Consignor";
OfferLogEntityTypeEnum["CUSTOMER"] = "Customer";
})(OfferLogEntityTypeEnum = exports.OfferLogEntityTypeEnum || (exports.OfferLogEntityTypeEnum = {}));
/**
* Offers handler class
*/
class Offers {
/**
* Offers handler class
*
* @param transport - API transport handler
*/
constructor(transport) {
this.transport = transport;
}
/**
* Accepts an offer.
*
* @param offer - Offer to accept
* @param headers - Request headers
*
* @returns A promise that resolves to a boolean indicating whether the request was successful
*/
accept(offer, headers) {
return __awaiter(this, void 0, void 0, function* () {
const route = {
key: "offers.accept",
transforms: {
offerId: offer.id,
}
};
return yield this.transport.putToApiRoute(route, offer, headers);
});
}
/**
* Counteroffers with a new offer
*
* @param offer - Offer to counteroffer
* @param counterOffer - Counteroffer object { offerAmount: number }
* @param headers - Request headers
*
* @returns A promise that resolves to a boolean indicating whether the request was successful
*/
counter(offer, counterOffer, headers) {
return __awaiter(this, void 0, void 0, function* () {
const data = {
counterPrice: counterOffer.offerAmount,
};
const route = {
key: "offers.counter",
transforms: {
offerId: offer.id,
}
};
return yield this.transport.putToApiRoute(route, data, headers);
});
}
/**
* Retrieves an offer by ID
*
* @param offerId - offerId
* @param headers - Request headers
*
* @returns A promise that resolves to an offer
*/
findById(offerId, headers) {
return __awaiter(this, void 0, void 0, function* () {
const route = {
key: "offers.findById",
transforms: {
offerId: offerId,
}
};
return yield this.transport.getFromApiRoute(route, headers);
});
}
/**
* Retrieves all offers
*
* @param searchParams - OfferSearchParams
* @param headers - Request headers
*
* @returns A promise that resolves to an array of offers
*/
findAll(searchParams, headers) {
return __awaiter(this, void 0, void 0, function* () {
const route = {
key: "offers.findAll",
params: searchParams,
};
return yield this.transport.getFromApiRoute(route, headers);
});
}
}
exports.Offers = Offers;
//# sourceMappingURL=Offers.js.map