lazada-api-client 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -0
- package/README.md +66 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/module/lazada/api/authorization.api.d.ts +21 -0
- package/dist/module/lazada/api/authorization.api.js +95 -0
- package/dist/module/lazada/api/order.api.d.ts +8 -0
- package/dist/module/lazada/api/order.api.js +83 -0
- package/dist/module/lazada/api/product.api.d.ts +50 -0
- package/dist/module/lazada/api/product.api.js +232 -0
- package/dist/module/lazada/common/constant.d.ts +87 -0
- package/dist/module/lazada/common/constant.js +103 -0
- package/dist/module/lazada/common/helper.d.ts +17 -0
- package/dist/module/lazada/common/helper.js +174 -0
- package/dist/module/lazada/dto/request/config.request.d.ts +14 -0
- package/dist/module/lazada/dto/request/config.request.js +2 -0
- package/dist/module/lazada/dto/request/product.request.d.ts +13 -0
- package/dist/module/lazada/dto/request/product.request.js +2 -0
- package/dist/module/lazada/dto/response/config.response.d.ts +18 -0
- package/dist/module/lazada/dto/response/config.response.js +2 -0
- package/dist/module/lazada/dto/response/order.response.d.ts +72 -0
- package/dist/module/lazada/dto/response/order.response.js +2 -0
- package/dist/module/lazada/dto/response/product.response.d.ts +65 -0
- package/dist/module/lazada/dto/response/product.response.js +6 -0
- package/dist/module/lazada/index.d.ts +25 -0
- package/dist/module/lazada/index.js +93 -0
- package/package.json +53 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LZD_MAX_RANGE_CAN_BE_REVIEW = exports.LZD_TIME_RANGE_EXCEED = exports.LZD_BUYER_USERNAME = exports.LZD_DROP_SHIP = exports.LZD_DIGEST = exports.LZD_ALGORITHM = exports.LZD_END_POINT_AUTH = exports.LZD_END_POINT = exports.LAZADA_WEBHOOK_TYPE = exports.LAZADA_CODE = exports.LAZADA_PATH = exports.LAZADA_ORDER_STATUS = exports.LAZADA_REVERSE_STATUS = exports.LAZADA_PRODUCT_STATUS = void 0;
|
|
4
|
+
var PRODUCT_STATUS;
|
|
5
|
+
(function (PRODUCT_STATUS) {
|
|
6
|
+
PRODUCT_STATUS["ACTIVE"] = "active";
|
|
7
|
+
PRODUCT_STATUS["INACTIVE"] = "inactive";
|
|
8
|
+
PRODUCT_STATUS["DELETED"] = "deleted";
|
|
9
|
+
})(PRODUCT_STATUS || (exports.LAZADA_PRODUCT_STATUS = PRODUCT_STATUS = {}));
|
|
10
|
+
var REVERSE_STATUS;
|
|
11
|
+
(function (REVERSE_STATUS) {
|
|
12
|
+
REVERSE_STATUS["REQUEST_INITIATE"] = "REQUEST_INITIATE";
|
|
13
|
+
REVERSE_STATUS["REQUEST_REJECT"] = "REQUEST_REJECT";
|
|
14
|
+
REVERSE_STATUS["REQUEST_CANCEL"] = "REQUEST_CANCEL";
|
|
15
|
+
REVERSE_STATUS["CANCEL_SUCCESS"] = "CANCEL_SUCCESS";
|
|
16
|
+
REVERSE_STATUS["REFUND_PENDING"] = "REFUND_PENDING";
|
|
17
|
+
REVERSE_STATUS["REFUND_AUTHORIZED"] = "REFUND_AUTHORIZED";
|
|
18
|
+
REVERSE_STATUS["REFUND_SUCCESS"] = "REFUND_SUCCESS";
|
|
19
|
+
REVERSE_STATUS["REFUND_REJECT"] = "REFUND_REJECT";
|
|
20
|
+
REVERSE_STATUS["REQUEST_COMPLETE"] = "REQUEST_COMPLETE";
|
|
21
|
+
REVERSE_STATUS["SELLER_AGREE_RETURN"] = "SELLER_AGREE_RETURN";
|
|
22
|
+
REVERSE_STATUS["SELLER_REJECT_RETURN"] = "SELLER_REJECT_RETURN";
|
|
23
|
+
REVERSE_STATUS["BUYER_RETURN_ITEM"] = "BUYER_RETURN_ITEM";
|
|
24
|
+
REVERSE_STATUS["SELLER_AGREE_REFUND"] = "SELLER_AGREE_REFUND";
|
|
25
|
+
REVERSE_STATUS["SELLER_REJECT_REFUND"] = "SELLER_REJECT_REFUND";
|
|
26
|
+
REVERSE_STATUS["CS_APPROVING"] = "CS_APPROVING";
|
|
27
|
+
REVERSE_STATUS["AGREE_CANCEL_ORDER"] = "AGREE_CANCEL_ORDER";
|
|
28
|
+
REVERSE_STATUS["REJECT_CANCEL_ORDER"] = "REJECT_CANCEL_ORDER";
|
|
29
|
+
})(REVERSE_STATUS || (exports.LAZADA_REVERSE_STATUS = REVERSE_STATUS = {}));
|
|
30
|
+
var ORDER_STATUS;
|
|
31
|
+
(function (ORDER_STATUS) {
|
|
32
|
+
ORDER_STATUS["UNPAID"] = "UNPAID";
|
|
33
|
+
ORDER_STATUS["PENDING"] = "PENDING";
|
|
34
|
+
ORDER_STATUS["PACKED"] = "PACKED";
|
|
35
|
+
ORDER_STATUS["READY_TO_SHIP"] = "READY_TO_SHIP";
|
|
36
|
+
ORDER_STATUS["READY_TO_SHIP_PENDING"] = "READY_TO_SHIP_PENDING";
|
|
37
|
+
ORDER_STATUS["SHIPPED"] = "SHIPPED";
|
|
38
|
+
ORDER_STATUS["FAILED_DELIVERY"] = "FAILED_DELIVERY";
|
|
39
|
+
ORDER_STATUS["DELIVERED"] = "DELIVERED";
|
|
40
|
+
ORDER_STATUS["CONFIRMED"] = "CONFIRMED";
|
|
41
|
+
ORDER_STATUS["LOST_BY_3PL"] = "LOST_BY_3PL";
|
|
42
|
+
ORDER_STATUS["DAMAGED_BY_3PL"] = "DAMAGED_BY_3PL";
|
|
43
|
+
ORDER_STATUS["RETURNED"] = "RETURNED";
|
|
44
|
+
ORDER_STATUS["CANCELED"] = "CANCELED";
|
|
45
|
+
ORDER_STATUS["SHIPPED_BACK"] = "SHIPPED_BACK";
|
|
46
|
+
ORDER_STATUS["SHIPPED_BACK_SUCCESS"] = "SHIPPED_BACK_SUCCESS";
|
|
47
|
+
ORDER_STATUS["SHIPPED_BACK_FAILED"] = "SHIPPED_BACK_FAILED";
|
|
48
|
+
ORDER_STATUS["PACKED_SCRAPPED"] = "PACKED_SCRAPPED";
|
|
49
|
+
})(ORDER_STATUS || (exports.LAZADA_ORDER_STATUS = ORDER_STATUS = {}));
|
|
50
|
+
var WEBHOOK_TYPE;
|
|
51
|
+
(function (WEBHOOK_TYPE) {
|
|
52
|
+
WEBHOOK_TYPE[WEBHOOK_TYPE["ORDER"] = 0] = "ORDER";
|
|
53
|
+
WEBHOOK_TYPE[WEBHOOK_TYPE["AUTH_EXPIRE"] = 8] = "AUTH_EXPIRE";
|
|
54
|
+
WEBHOOK_TYPE[WEBHOOK_TYPE["REVERSE"] = 10] = "REVERSE";
|
|
55
|
+
WEBHOOK_TYPE[WEBHOOK_TYPE["FULFILLMENT"] = 14] = "FULFILLMENT";
|
|
56
|
+
WEBHOOK_TYPE[WEBHOOK_TYPE["PRODUCT"] = 21] = "PRODUCT";
|
|
57
|
+
})(WEBHOOK_TYPE || (exports.LAZADA_WEBHOOK_TYPE = WEBHOOK_TYPE = {}));
|
|
58
|
+
const BUYER_USERNAME = 'Khách hàng đánh giá';
|
|
59
|
+
exports.LZD_BUYER_USERNAME = BUYER_USERNAME;
|
|
60
|
+
const MAX_RANGE_CAN_BE_REVIEW = 12; //WEEK
|
|
61
|
+
exports.LZD_MAX_RANGE_CAN_BE_REVIEW = MAX_RANGE_CAN_BE_REVIEW;
|
|
62
|
+
const TIME_RANGE_EXCEED = 7; //DAYS
|
|
63
|
+
exports.LZD_TIME_RANGE_EXCEED = TIME_RANGE_EXCEED;
|
|
64
|
+
const END_POINT = 'https://api.lazada.vn/rest';
|
|
65
|
+
exports.LZD_END_POINT = END_POINT;
|
|
66
|
+
const END_POINT_AUTH = 'https://auth.lazada.com/oauth/authorize';
|
|
67
|
+
exports.LZD_END_POINT_AUTH = END_POINT_AUTH;
|
|
68
|
+
const ALGORITHM = 'sha256';
|
|
69
|
+
exports.LZD_ALGORITHM = ALGORITHM;
|
|
70
|
+
const DIGEST = 'hex';
|
|
71
|
+
exports.LZD_DIGEST = DIGEST;
|
|
72
|
+
const DROP_SHIP = 'dropship';
|
|
73
|
+
exports.LZD_DROP_SHIP = DROP_SHIP;
|
|
74
|
+
var PATH;
|
|
75
|
+
(function (PATH) {
|
|
76
|
+
PATH["PRODUCT_GET"] = "/products/get";
|
|
77
|
+
PATH["UPDATE_SELLABLE_QUANTITY"] = "/product/stock/sellable/update";
|
|
78
|
+
PATH["UPDATE_PRICE"] = "/product/price_quantity/update";
|
|
79
|
+
PATH["ORDERS_GET"] = "/orders/get";
|
|
80
|
+
PATH["SINGLE_ORDER_GET"] = "/order/get";
|
|
81
|
+
PATH["SINGLE_ORDER_ITEM_GET"] = "/order/items/get";
|
|
82
|
+
PATH["PRODUCT_ITEM_GET"] = "/product/item/get";
|
|
83
|
+
PATH["SET_STATUS_TO_PACKED_BY_MARKETPLACE"] = "/order/pack";
|
|
84
|
+
PATH["REVERSE_LIST"] = "/reverse/getreverseordersforseller";
|
|
85
|
+
PATH["REVERSE_DETAIL"] = "/order/reverse/return/detail/list";
|
|
86
|
+
PATH["SHIPPING_LABEL_GET"] = "/order/document/awb/pdf/get";
|
|
87
|
+
PATH["SHIPPING_LABEL_V2"] = "/order/package/document/get";
|
|
88
|
+
PATH["STREAM_S3"] = "/stream-s3";
|
|
89
|
+
PATH["FULFILL_PACK"] = "/order/fulfill/pack";
|
|
90
|
+
PATH["SHIPMENT_PROVIDERS"] = "/order/shipment/providers/get";
|
|
91
|
+
PATH["READY_TO_SHIP"] = "/order/package/rts";
|
|
92
|
+
PATH["HISTORY_REVIEW"] = "/review/seller/history/list";
|
|
93
|
+
PATH["REVIEW_LIST"] = "/review/seller/list/v2";
|
|
94
|
+
PATH["UPDATE_PRODUCT"] = "/product/update";
|
|
95
|
+
PATH["TRACE_ORDER"] = "/logistic/order/trace";
|
|
96
|
+
PATH["FETCH_TOKEN"] = "/auth/token/create";
|
|
97
|
+
PATH["REFRESH_TOKEN"] = "/auth/token/refresh";
|
|
98
|
+
PATH["CREATE_PRODUCT"] = "/product/create";
|
|
99
|
+
})(PATH || (exports.LAZADA_PATH = PATH = {}));
|
|
100
|
+
var CODE;
|
|
101
|
+
(function (CODE) {
|
|
102
|
+
CODE["SUCCESS"] = "0";
|
|
103
|
+
})(CODE || (exports.LAZADA_CODE = CODE = {}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LAZADA_PRODUCT_STATUS } from './constant';
|
|
2
|
+
export declare function concatDictionaryKeyValue(object: any): string;
|
|
3
|
+
export declare function createSignature(path: any, payload: any, appSecret: any): string;
|
|
4
|
+
export declare function parseToRequestParam(obj: any): string;
|
|
5
|
+
export declare function keySort(unordered: any): {};
|
|
6
|
+
export declare function toRequestProductsXML(skus: any): string;
|
|
7
|
+
export declare function toProductXML(itemId: any, skuId: any, sellerSku: any, quantity: any): string;
|
|
8
|
+
export declare function productParametersXML(itemId: any, skuId: any, sellerSku: any, status: LAZADA_PRODUCT_STATUS): string;
|
|
9
|
+
export declare function priceParametersXML(itemId: any, skuId: any, sellerSku: any, price: any): string;
|
|
10
|
+
declare function httpGet(path: string, payload: any, appSecret: string): Promise<any>;
|
|
11
|
+
export declare function executePOST(path: string, payload: any, appSecret: string): Promise<any>;
|
|
12
|
+
export declare function executeAuth(path: string, payload: any, appSecret: string): Promise<any>;
|
|
13
|
+
declare function createProductParametersXML2(payload: any): string;
|
|
14
|
+
declare function getTimestampMilisec(): number;
|
|
15
|
+
declare function getTimestampSec(): number;
|
|
16
|
+
declare function isTokenExpired(time: any): boolean;
|
|
17
|
+
export { httpGet, getTimestampMilisec, getTimestampSec, isTokenExpired, createProductParametersXML2 };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.concatDictionaryKeyValue = concatDictionaryKeyValue;
|
|
16
|
+
exports.createSignature = createSignature;
|
|
17
|
+
exports.parseToRequestParam = parseToRequestParam;
|
|
18
|
+
exports.keySort = keySort;
|
|
19
|
+
exports.toRequestProductsXML = toRequestProductsXML;
|
|
20
|
+
exports.toProductXML = toProductXML;
|
|
21
|
+
exports.productParametersXML = productParametersXML;
|
|
22
|
+
exports.priceParametersXML = priceParametersXML;
|
|
23
|
+
exports.executePOST = executePOST;
|
|
24
|
+
exports.executeAuth = executeAuth;
|
|
25
|
+
exports.httpGet = httpGet;
|
|
26
|
+
exports.getTimestampMilisec = getTimestampMilisec;
|
|
27
|
+
exports.getTimestampSec = getTimestampSec;
|
|
28
|
+
exports.isTokenExpired = isTokenExpired;
|
|
29
|
+
exports.createProductParametersXML2 = createProductParametersXML2;
|
|
30
|
+
const constant_1 = require("./constant");
|
|
31
|
+
const axios_1 = __importDefault(require("axios"));
|
|
32
|
+
const crypto_1 = require("crypto");
|
|
33
|
+
function concatDictionaryKeyValue(object) {
|
|
34
|
+
return Object.keys(object).reduce(function (concatString, key) {
|
|
35
|
+
return concatString.concat(key + object[key]);
|
|
36
|
+
}, '');
|
|
37
|
+
}
|
|
38
|
+
function createSignature(path, payload, appSecret) {
|
|
39
|
+
const uri = concatDictionaryKeyValue(keySort(payload));
|
|
40
|
+
const input = `${path}${uri}`;
|
|
41
|
+
const hash = (0, crypto_1.createHmac)(constant_1.LZD_ALGORITHM, appSecret).update(input).digest(constant_1.LZD_DIGEST);
|
|
42
|
+
return hash.toUpperCase();
|
|
43
|
+
}
|
|
44
|
+
function parseToRequestParam(obj) {
|
|
45
|
+
let str = '';
|
|
46
|
+
for (const key in obj) {
|
|
47
|
+
if (str != '') {
|
|
48
|
+
str += '&';
|
|
49
|
+
}
|
|
50
|
+
str += key + '=' + encodeURIComponent(obj[key]);
|
|
51
|
+
}
|
|
52
|
+
return str;
|
|
53
|
+
}
|
|
54
|
+
function keySort(unordered) {
|
|
55
|
+
return Object.keys(unordered)
|
|
56
|
+
.sort()
|
|
57
|
+
.reduce(function (ordered, key) {
|
|
58
|
+
ordered[key] = unordered[key];
|
|
59
|
+
return ordered;
|
|
60
|
+
}, {});
|
|
61
|
+
}
|
|
62
|
+
function toRequestProductsXML(skus) {
|
|
63
|
+
return `<Request> <Product> <Skus> ${skus.join(' ')} </Skus> </Product> </Request>`;
|
|
64
|
+
}
|
|
65
|
+
function toProductXML(itemId, skuId, sellerSku, quantity) {
|
|
66
|
+
return `<Sku> <ItemId>${itemId}</ItemId> <SkuId>${skuId}</SkuId> <SellerSku>${sellerSku}</SellerSku> <SellableQuantity>${quantity}</SellableQuantity> </Sku>`;
|
|
67
|
+
}
|
|
68
|
+
function productParametersXML(itemId, skuId, sellerSku, status) {
|
|
69
|
+
return `<Sku> <ItemId>${itemId}</ItemId> <SkuId>${skuId}</SkuId> <SellerSku>${sellerSku}</SellerSku><Status>${status}</Status></Sku>`;
|
|
70
|
+
}
|
|
71
|
+
function priceParametersXML(itemId, skuId, sellerSku, price) {
|
|
72
|
+
return `<Sku> <ItemId>${itemId}</ItemId> <SkuId>${skuId}</SkuId> <SellerSku>${sellerSku}</SellerSku><Price>${price}</Price></Sku>`;
|
|
73
|
+
}
|
|
74
|
+
function httpGet(path, payload, appSecret) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const sortObject = keySort(payload);
|
|
77
|
+
const params = parseToRequestParam(sortObject);
|
|
78
|
+
const signature = createSignature(path, sortObject, appSecret);
|
|
79
|
+
try {
|
|
80
|
+
const res = yield axios_1.default.get(`${constant_1.LZD_END_POINT}${path}?${params}&sign=${signature}`);
|
|
81
|
+
return res.data;
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
console.log(e);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function executePOST(path, payload, appSecret) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const sortObject = keySort(payload);
|
|
91
|
+
const params = parseToRequestParam(sortObject);
|
|
92
|
+
const signature = createSignature(path, sortObject, appSecret);
|
|
93
|
+
try {
|
|
94
|
+
const res = yield axios_1.default.post(`${constant_1.LZD_END_POINT}${path}?${params}&sign=${signature}`);
|
|
95
|
+
return res.data;
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
console.log(e);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function executeAuth(path, payload, appSecret) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const sortObject = keySort(payload);
|
|
105
|
+
const params = parseToRequestParam(sortObject);
|
|
106
|
+
const signature = createSignature(path, sortObject, appSecret);
|
|
107
|
+
try {
|
|
108
|
+
const res = yield axios_1.default.get(`https://auth.lazada.com/rest${path}?${params}&sign=${signature}`);
|
|
109
|
+
return res.data;
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
console.log(e);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function createProductParametersXML2(payload) {
|
|
117
|
+
const { primaryCategory, images, name, description, disableAttributeAutoFill, brand_id, video, phoneType, warrantyType, skus } = payload;
|
|
118
|
+
// Build the Skus XML
|
|
119
|
+
const skusXML = skus
|
|
120
|
+
.map((sku) => {
|
|
121
|
+
return `
|
|
122
|
+
<Sku>
|
|
123
|
+
<SellerSku>${sku.sellerSku}</SellerSku>
|
|
124
|
+
<quantity>${sku.quantity}</quantity>
|
|
125
|
+
<price>${sku.price}</price>
|
|
126
|
+
<special_price>${sku.specialPrice}</special_price>
|
|
127
|
+
<package_height>${sku.packageHeight}</package_height>
|
|
128
|
+
<package_length>${sku.packageLength}</package_length>
|
|
129
|
+
<package_width>${sku.packageWidth}</package_width>
|
|
130
|
+
<package_weight>${sku.packageWeight}</package_weight>
|
|
131
|
+
<Images>
|
|
132
|
+
${sku.images.map((image) => `<Image>${image}</Image>`).join('\n')}
|
|
133
|
+
</Images>
|
|
134
|
+
</Sku>
|
|
135
|
+
`;
|
|
136
|
+
})
|
|
137
|
+
.join('\n');
|
|
138
|
+
// Build the final XML
|
|
139
|
+
const xml = `<Request>
|
|
140
|
+
<Product>
|
|
141
|
+
<PrimaryCategory>${primaryCategory}</PrimaryCategory>
|
|
142
|
+
<Images>
|
|
143
|
+
${images.map((image) => `<Image>${image}</Image>`).join('\n')}
|
|
144
|
+
</Images>
|
|
145
|
+
<Attributes>
|
|
146
|
+
<name>${name}</name>
|
|
147
|
+
<description>${description}</description>
|
|
148
|
+
<disableAttributeAutoFill>${disableAttributeAutoFill}</disableAttributeAutoFill>
|
|
149
|
+
<brand_id>${brand_id}</brand_id>
|
|
150
|
+
<video>${video}</video>
|
|
151
|
+
<phone_type>${phoneType}</phone_type>
|
|
152
|
+
<warranty_type>${warrantyType}</warranty_type>
|
|
153
|
+
</Attributes>
|
|
154
|
+
<Skus>
|
|
155
|
+
${skusXML}
|
|
156
|
+
</Skus>
|
|
157
|
+
</Product>
|
|
158
|
+
</Request>`;
|
|
159
|
+
return xml;
|
|
160
|
+
}
|
|
161
|
+
function getTimestampMilisec() {
|
|
162
|
+
return new Date().getTime();
|
|
163
|
+
}
|
|
164
|
+
function getTimestampSec() {
|
|
165
|
+
return Math.floor(Date.now() / 1000);
|
|
166
|
+
}
|
|
167
|
+
function isTokenExpired(time) {
|
|
168
|
+
if (time.toString().length === 13) {
|
|
169
|
+
time = time / 1000;
|
|
170
|
+
}
|
|
171
|
+
const now = Math.floor(Date.now() / 1000);
|
|
172
|
+
// If expiration time is less than or equal to current time, it's expired
|
|
173
|
+
return time <= now;
|
|
174
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface Config {
|
|
2
|
+
appKey: string;
|
|
3
|
+
appSecret: string;
|
|
4
|
+
countryCode?: string;
|
|
5
|
+
shopId?: string;
|
|
6
|
+
appAccessToken?: string;
|
|
7
|
+
refreshToken?: string;
|
|
8
|
+
expiresIn?: number;
|
|
9
|
+
refreshExpiresIn?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface ConfigList {
|
|
12
|
+
[shopId: string]: Config;
|
|
13
|
+
}
|
|
14
|
+
export { Config as LazadaConfig, ConfigList as LazadaConfigList };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface UpdateSellableQuantity {
|
|
2
|
+
itemId: string;
|
|
3
|
+
skuId: string;
|
|
4
|
+
sellerSku?: string;
|
|
5
|
+
quantity: number;
|
|
6
|
+
}
|
|
7
|
+
interface UpdateStatusProduct {
|
|
8
|
+
itemId: string;
|
|
9
|
+
skuId: string;
|
|
10
|
+
sellerSku?: string;
|
|
11
|
+
status: any;
|
|
12
|
+
}
|
|
13
|
+
export { UpdateSellableQuantity as LZD_UPDATE_SELLABLE_QUANTITY, UpdateStatusProduct as LZD_UPDATE_STATUS_PRODUCT };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface CountryUserInfo {
|
|
2
|
+
country: string;
|
|
3
|
+
user_id: string;
|
|
4
|
+
seller_id: string;
|
|
5
|
+
short_code: string;
|
|
6
|
+
}
|
|
7
|
+
interface ResponseGetAccessToken {
|
|
8
|
+
expires_in: number;
|
|
9
|
+
country: string;
|
|
10
|
+
country_user_info: CountryUserInfo[];
|
|
11
|
+
account_platform: string;
|
|
12
|
+
access_token: string;
|
|
13
|
+
account: string;
|
|
14
|
+
refresh_expires_in: number;
|
|
15
|
+
refresh_token: string;
|
|
16
|
+
code: string;
|
|
17
|
+
}
|
|
18
|
+
export { ResponseGetAccessToken as LazadaResponseAccessToken };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
interface PackageDetail {
|
|
2
|
+
package_detail_info_list: [
|
|
3
|
+
{
|
|
4
|
+
ofc_package_id: string;
|
|
5
|
+
tracking_number: string;
|
|
6
|
+
logistic_detail_info_list: [
|
|
7
|
+
{
|
|
8
|
+
status_code: string;
|
|
9
|
+
proof_images: [];
|
|
10
|
+
detail_type: string;
|
|
11
|
+
receive_time: number;
|
|
12
|
+
description: string;
|
|
13
|
+
title: string;
|
|
14
|
+
event_time: number;
|
|
15
|
+
package_location_name: string;
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
interface ResponseTraceOrder {
|
|
22
|
+
result: {
|
|
23
|
+
not_success: boolean;
|
|
24
|
+
success: boolean;
|
|
25
|
+
module: Array<PackageDetail>;
|
|
26
|
+
error_code: any;
|
|
27
|
+
repeated: boolean;
|
|
28
|
+
retry: boolean;
|
|
29
|
+
};
|
|
30
|
+
code: string;
|
|
31
|
+
request_id: string;
|
|
32
|
+
}
|
|
33
|
+
interface ItemList {
|
|
34
|
+
order_item_id: number;
|
|
35
|
+
msg: string;
|
|
36
|
+
item_err_code: string;
|
|
37
|
+
tracking_number: string;
|
|
38
|
+
shipment_provider: string;
|
|
39
|
+
package_id: string;
|
|
40
|
+
retry: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface PackOrder {
|
|
43
|
+
order_item_list: Array<ItemList>;
|
|
44
|
+
order_id: number;
|
|
45
|
+
}
|
|
46
|
+
interface ResponsePackOrder {
|
|
47
|
+
result: {
|
|
48
|
+
data: {
|
|
49
|
+
pack_order_list: Array<PackOrder>;
|
|
50
|
+
};
|
|
51
|
+
success: boolean;
|
|
52
|
+
};
|
|
53
|
+
code: string;
|
|
54
|
+
request_id: string;
|
|
55
|
+
}
|
|
56
|
+
interface PackageRTS {
|
|
57
|
+
msg: string;
|
|
58
|
+
item_err_code: string;
|
|
59
|
+
package_id: string;
|
|
60
|
+
retry: boolean;
|
|
61
|
+
}
|
|
62
|
+
interface ResponseRTSOrder {
|
|
63
|
+
result: {
|
|
64
|
+
data: {
|
|
65
|
+
packages: Array<PackageRTS>;
|
|
66
|
+
};
|
|
67
|
+
success: boolean;
|
|
68
|
+
};
|
|
69
|
+
code: string;
|
|
70
|
+
request_id: string;
|
|
71
|
+
}
|
|
72
|
+
export { ResponseTraceOrder as LazadaResponseTraceOrder, ResponsePackOrder as LazadaResponsePackOrder, ResponseRTSOrder as LazadaResponseRTSOrder, };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
interface Rating {
|
|
2
|
+
seller_rating?: number;
|
|
3
|
+
overall_rating?: number;
|
|
4
|
+
logistics_rating?: number;
|
|
5
|
+
product_rating?: number;
|
|
6
|
+
}
|
|
7
|
+
interface Skus {
|
|
8
|
+
Status: string;
|
|
9
|
+
quantity: number;
|
|
10
|
+
Images: Array<any>;
|
|
11
|
+
SellerSku: string;
|
|
12
|
+
ShopSku: string;
|
|
13
|
+
special_time_format: string;
|
|
14
|
+
saleProp: any;
|
|
15
|
+
Url: string;
|
|
16
|
+
multiWarehouseInventories: any;
|
|
17
|
+
package_width: string;
|
|
18
|
+
special_to_time: string;
|
|
19
|
+
special_from_time: string;
|
|
20
|
+
package_height: string;
|
|
21
|
+
fblWarehouseInventories: Array<any>;
|
|
22
|
+
special_price: number;
|
|
23
|
+
price: number;
|
|
24
|
+
channelInventories: Array<any>;
|
|
25
|
+
package_length: string;
|
|
26
|
+
special_from_date: string;
|
|
27
|
+
package_weight: string;
|
|
28
|
+
SkuId: number;
|
|
29
|
+
special_to_date: string;
|
|
30
|
+
}
|
|
31
|
+
interface ResponseProductItem {
|
|
32
|
+
created_time: string;
|
|
33
|
+
updated_time: string;
|
|
34
|
+
images: Array<string>;
|
|
35
|
+
skus: Array<Skus>;
|
|
36
|
+
item_id: number;
|
|
37
|
+
trialProduct: boolean;
|
|
38
|
+
primary_category: number;
|
|
39
|
+
marketImages: Array<any>;
|
|
40
|
+
attributes: {
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
brand: string;
|
|
44
|
+
mask_type: string;
|
|
45
|
+
ingredient_preference: string;
|
|
46
|
+
Hazmat: string;
|
|
47
|
+
source: string;
|
|
48
|
+
delivery_option_sof: string;
|
|
49
|
+
};
|
|
50
|
+
status: string;
|
|
51
|
+
}
|
|
52
|
+
declare class ResponseReview {
|
|
53
|
+
review_images?: any;
|
|
54
|
+
can_reply?: boolean;
|
|
55
|
+
create_time?: any;
|
|
56
|
+
submit_time?: any;
|
|
57
|
+
review_content?: string;
|
|
58
|
+
ratings?: Rating;
|
|
59
|
+
product_id: any;
|
|
60
|
+
id: any;
|
|
61
|
+
seller_reply?: string;
|
|
62
|
+
order_id?: number;
|
|
63
|
+
review_type?: string;
|
|
64
|
+
}
|
|
65
|
+
export { ResponseReview as LazadaResponseReview, ResponseProductItem as LazadaResponseProductItem };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LazadaConfig } from './dto/request/config.request';
|
|
2
|
+
import { LZD_UPDATE_SELLABLE_QUANTITY, LZD_UPDATE_STATUS_PRODUCT } from './dto/request/product.request';
|
|
3
|
+
import { LazadaResponseAccessToken } from './dto/response/config.response';
|
|
4
|
+
export declare class LazadaModule {
|
|
5
|
+
private config;
|
|
6
|
+
constructor(config: any);
|
|
7
|
+
setConfig(config: LazadaConfig): void;
|
|
8
|
+
getConfig(): LazadaConfig;
|
|
9
|
+
getOrdersBeforeSomeDay(): Promise<any>;
|
|
10
|
+
getOrderDetail(orderNumber: string): Promise<any>;
|
|
11
|
+
getProducts(): Promise<any[]>;
|
|
12
|
+
getProductItem(itemId: number): Promise<any>;
|
|
13
|
+
updateSellableQuantity(itemId: number, payload: LZD_UPDATE_SELLABLE_QUANTITY): Promise<any>;
|
|
14
|
+
updateStatusProduct(itemId: number, payload: LZD_UPDATE_STATUS_PRODUCT): Promise<any>;
|
|
15
|
+
updatePrice(itemId: number, payload: any): Promise<any>;
|
|
16
|
+
getCategoryTree(): Promise<any>;
|
|
17
|
+
generateAuthLink(redirectURL: string, appKey: string, uuid: string): {
|
|
18
|
+
url: string;
|
|
19
|
+
redirect: string;
|
|
20
|
+
};
|
|
21
|
+
fetchTokenWithAuthCode(authCode: string, uuid: string): Promise<LazadaResponseAccessToken>;
|
|
22
|
+
createProduct(payload: any): Promise<any>;
|
|
23
|
+
refreshToken(): Promise<any>;
|
|
24
|
+
getBrands(): Promise<any>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LazadaModule = void 0;
|
|
13
|
+
const authorization_api_1 = require("./api/authorization.api");
|
|
14
|
+
const order_api_1 = require("./api/order.api");
|
|
15
|
+
const product_api_1 = require("./api/product.api");
|
|
16
|
+
class LazadaModule {
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
}
|
|
20
|
+
setConfig(config) {
|
|
21
|
+
this.config.appAccessToken = config.appAccessToken;
|
|
22
|
+
this.config.refreshToken = config.refreshToken;
|
|
23
|
+
this.config.expiresIn = config.expiresIn;
|
|
24
|
+
this.config.refreshExpiresIn = config.refreshExpiresIn;
|
|
25
|
+
}
|
|
26
|
+
getConfig() {
|
|
27
|
+
return this.config;
|
|
28
|
+
}
|
|
29
|
+
getOrdersBeforeSomeDay() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return yield (0, order_api_1.getOrdersBeforeSomeDay)(this.config);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
getOrderDetail(orderNumber) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return yield (0, order_api_1.getOrderById)(this.config, orderNumber);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
getProducts() {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
return yield (0, product_api_1.getProducts)(this.config);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
getProductItem(itemId) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
return yield (0, product_api_1.getProductItem)(this.config, itemId);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
updateSellableQuantity(itemId, payload) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
return yield (0, product_api_1.updateSellableQuantity)(this.config, itemId, [payload]);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
updateStatusProduct(itemId, payload) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
return yield (0, product_api_1.updateStatusProduct)(this.config, itemId, [payload]);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
updatePrice(itemId, payload) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
return yield (0, product_api_1.updatePrice)(this.config, itemId, [payload]);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
getCategoryTree() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
return yield (0, product_api_1.getCategoryTree)(this.config);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
generateAuthLink(redirectURL, appKey, uuid) {
|
|
70
|
+
return (0, authorization_api_1.generateAuthLink)(redirectURL, appKey, uuid);
|
|
71
|
+
}
|
|
72
|
+
fetchTokenWithAuthCode(authCode, uuid) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
return (0, authorization_api_1.fetchTokenWithAuthCode)(authCode, uuid, this.config);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
createProduct(payload) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
return (0, product_api_1.createProduct)(payload, this.config);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
refreshToken() {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
return (0, authorization_api_1.refreshToken)(this.config);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
getBrands() {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
return (0, product_api_1.getBrandByPages)(this.config);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.LazadaModule = LazadaModule;
|