shopee-client
Version:
Shoppe Open API Client
301 lines (300 loc) • 14.1 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var BaseModule_1 = __importDefault(require("../BaseModule"));
var hmac_1 = __importDefault(require("../../helper/hmac"));
var handleReject_1 = __importDefault(require("../../helper/handleReject"));
var LogisticModule = /** @class */ (function (_super) {
__extends(LogisticModule, _super);
function LogisticModule() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Use this call to get all supported logistic channels.
*/
LogisticModule.prototype.getLogistic = function () {
var full_url = this.client.defaults.baseURL + 'logistics/channel/get';
var params = {
partner_id: Number(this.config.partner_id),
shopid: Number(this.config.shop_id),
timestamp: Math.round(Date.now() / 1000),
};
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/channel/get', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* For integrated logistics channel, use this call to get pickup address for pickup mode order.
*/
LogisticModule.prototype.getAddress = function () {
var full_url = this.client.defaults.baseURL + 'logistics/address/get';
var params = {
partner_id: Number(this.config.partner_id),
shopid: Number(this.config.shop_id),
timestamp: Math.round(Date.now() / 1000),
};
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/address/get', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* For integrated logistics channel, use this call to get pickup timeslot for pickup mode order.
* @param ordersn The order serial numbers.
* @param address_id The identify of address.
*/
LogisticModule.prototype.getTimeSlot = function (ordersn, address_id) {
var full_url = this.client.defaults.baseURL + 'logistics/timeslot/get';
var params = {
ordersn: ordersn,
address_id: address_id,
partner_id: Number(this.config.partner_id),
shopid: Number(this.config.shop_id),
timestamp: Math.round(Date.now() / 1000),
};
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/timeslot/get', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* For integrated logistics channel, use this call to get dropoff location for dropoff mode order.
* @param ordersn The order serial numbers.
*/
LogisticModule.prototype.getBranch = function (ordersn) {
var full_url = this.client.defaults.baseURL + 'logistics/branch/get';
var params = {
ordersn: ordersn,
partner_id: Number(this.config.partner_id),
shopid: Number(this.config.shop_id),
timestamp: Math.round(Date.now() / 1000),
};
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/branch/get', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* Get all the logistics info of an order to Init.
* This API consolidates the output of GetParameterForInit, GetAddresss, GetTimeSlot and GetBranch based on each order so that developer can get all the required parameters ready in this API for Init.
* This API is an alternative of GetParameterForInit, GetAddresss, GetTimeSlot and GetBranch as a set.
* @param ordersn The order serial numbers.
*/
LogisticModule.prototype.getLogisticInfo = function (ordersn) {
var full_url = this.client.defaults.baseURL + 'logistics/init_info/get';
var params = {
ordersn: ordersn,
partner_id: Number(this.config.partner_id),
shopid: Number(this.config.shop_id),
timestamp: Math.round(Date.now() / 1000),
};
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/init_info/get', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* Use this call to initiate logistics including arrange Pickup, Dropoff or shipment for non-integrated logistic channels.
* Should call shopee.logistics.GetLogisticInfo to fetch all required param first.
* It's recommended to initiate logistics one hour AFTER the orders were placed since there is one-hour window buyer can cancel any order without request to seller.
* @param request
*/
LogisticModule.prototype.init = function (request) {
var full_url = this.client.defaults.baseURL + 'logistics/init';
var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) });
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/init', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* Use this API to get airway bill for orders.
* AirwayBill is only fetchable when the order status is under READY_TO_SHIP and RETRY_SHIP.
* @param request
*/
LogisticModule.prototype.getAirwayBill = function (request) {
var full_url = this.client.defaults.baseURL + 'logistics/airway_bill/get_mass';
var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) });
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/airway_bill/get_mass', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* Use this call to get the logistics tracking information of an order.
* @param request
*/
LogisticModule.prototype.getLogisticMessage = function (request) {
var full_url = this.client.defaults.baseURL + 'logistics/tracking';
var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) });
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/tracking', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* Use this API to get airwaybill for fulfillment orders.
* @param request
*/
LogisticModule.prototype.getForderWaybill = function (request) {
var full_url = this.client.defaults.baseURL + 'logistics/forder_waybill/get_mass';
var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) });
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/forder_waybill/get_mass', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* Use this API to set default_address/pick_up_address/return_address of shop.
* @param request
*/
LogisticModule.prototype.setAddress = function (request) {
var full_url = this.client.defaults.baseURL + 'logistics/address/set';
var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) });
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/address/set', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* Use this API to delete the address of shop by address_id.
* @param address_id The identity of address
*/
LogisticModule.prototype.deleteAddress = function (address_id) {
var full_url = this.client.defaults.baseURL + 'logistics/address/delete';
var params = {
address_id: address_id,
partner_id: Number(this.config.partner_id),
shopid: Number(this.config.shop_id),
timestamp: Math.round(Date.now() / 1000),
};
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/address/delete', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* Use this call to fetch the logistics information of an order, these info can be used for airwaybill printing.
* Dedicated for crossborder SLS order airwaybill. May not be applicable for local channel airwaybill.
* @param ordersn The order serial numbers.
*/
LogisticModule.prototype.getOrderLogistic = function (ordersn, forder_id) {
var full_url = this.client.defaults.baseURL + 'logistics/order/get';
var params = {
ordersn: ordersn,
partner_id: Number(this.config.partner_id),
shopid: Number(this.config.shop_id),
timestamp: Math.round(Date.now() / 1000),
};
if (forder_id && typeof forder_id == 'string') {
params.forder_id = forder_id;
}
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/order/get', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* Configure shop level logistics
* @param logistic_id The identity of logistic channel
* @param enabled Whether to enable this logistic channel
* @param prefered Whether to make this logistic channel preferred. Indonestia logistics channel are not applicable.
* @param cod Whether to enable COD for this logistic channel. Only COD supported channels are applicable.
*/
LogisticModule.prototype.updateShopLogistic = function (logistic_id, enabled, prefered, cod) {
var full_url = this.client.defaults.baseURL + 'logistics/channel/update';
var params = {
partner_id: Number(this.config.partner_id),
shopid: Number(this.config.shop_id),
timestamp: Math.round(Date.now() / 1000),
logistic_id: logistic_id,
};
if (typeof enabled == "boolean") {
params.enabled = enabled;
}
if (typeof prefered == "boolean") {
params.prefered = prefered;
}
if (typeof cod == "boolean") {
params.cod = cod;
}
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/channel/update', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
/**
* Use this call to get all required param for logistic initiation.
* @param ordersn The identity of order
*/
LogisticModule.prototype.getParameterInit = function (ordersn) {
var full_url = this.client.defaults.baseURL + 'logistics/init_parameter/get';
var params = {
partner_id: Number(this.config.partner_id),
shopid: Number(this.config.shop_id),
timestamp: Math.round(Date.now() / 1000),
ordersn: ordersn,
};
var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params));
return this.client.post('logistics/init_parameter/get', params, {
headers: {
Authorization: hmac
}
}).then(handleReject_1.default);
};
return LogisticModule;
}(BaseModule_1.default));
exports.default = LogisticModule;