@longvansoftware/storefront-js-client 1.4.7 → 1.4.8
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/dist/config/config.d.ts +4 -2
- package/dist/src/lib/SDK.d.ts +2 -13
- package/dist/src/lib/SDK.js +3 -6
- package/dist/src/lib/order/index.d.ts +3 -2
- package/dist/src/lib/order/index.js +18 -4
- package/dist/src/types/order.d.ts +64 -0
- package/dist/src/utils/helpers.d.ts +1 -4
- package/dist/src/utils/helpers.js +32 -39
- package/package.json +1 -1
package/dist/config/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare const environmentEndpoints:
|
|
1
|
+
export declare const environmentEndpoints: Endpoints;
|
|
2
|
+
interface Endpoints {
|
|
2
3
|
dev: {
|
|
3
4
|
product: string;
|
|
4
5
|
crm: string;
|
|
@@ -21,4 +22,5 @@ export declare const environmentEndpoints: {
|
|
|
21
22
|
warehouse: string;
|
|
22
23
|
computing: string;
|
|
23
24
|
};
|
|
24
|
-
}
|
|
25
|
+
}
|
|
26
|
+
export {};
|
package/dist/src/lib/SDK.d.ts
CHANGED
|
@@ -7,21 +7,10 @@ import { PaymentService } from "../lib/payment/index";
|
|
|
7
7
|
import { CrmService } from "../lib/crm/index";
|
|
8
8
|
import { WarehouseService } from "../lib/warehouse/index";
|
|
9
9
|
import { ComputingService } from "../lib/computing/index";
|
|
10
|
-
export interface Endpoints {
|
|
11
|
-
product: string;
|
|
12
|
-
crm: string;
|
|
13
|
-
auth: string;
|
|
14
|
-
order: string;
|
|
15
|
-
user: string;
|
|
16
|
-
payment: string;
|
|
17
|
-
service: string;
|
|
18
|
-
warehouse: string;
|
|
19
|
-
computing: string;
|
|
20
|
-
}
|
|
21
10
|
export declare class SDK {
|
|
22
11
|
orgId: string;
|
|
23
12
|
storeId: string;
|
|
24
|
-
|
|
13
|
+
env: string;
|
|
25
14
|
product: ProductService;
|
|
26
15
|
auth: AuthService;
|
|
27
16
|
order: OrderService;
|
|
@@ -32,7 +21,7 @@ export declare class SDK {
|
|
|
32
21
|
warehouse: WarehouseService;
|
|
33
22
|
computing: ComputingService;
|
|
34
23
|
token: string | null;
|
|
35
|
-
constructor(orgId: string, storeId: string,
|
|
24
|
+
constructor(orgId: string, storeId: string, env: string);
|
|
36
25
|
setToken(token: string): void;
|
|
37
26
|
setStoreId(storeId: string): void;
|
|
38
27
|
}
|
package/dist/src/lib/SDK.js
CHANGED
|
@@ -8,20 +8,17 @@ const index_3 = require("../lib/order/index");
|
|
|
8
8
|
const index_4 = require("./service/index");
|
|
9
9
|
const index_5 = require("../lib/user/index");
|
|
10
10
|
const config_1 = require("../../config/config");
|
|
11
|
-
const helpers_1 = require("../utils/helpers");
|
|
12
11
|
const index_6 = require("../lib/payment/index");
|
|
13
12
|
const index_7 = require("../lib/crm/index");
|
|
14
13
|
const index_8 = require("../lib/warehouse/index");
|
|
15
14
|
const index_9 = require("../lib/computing/index");
|
|
16
15
|
class SDK {
|
|
17
|
-
constructor(orgId, storeId,
|
|
16
|
+
constructor(orgId, storeId, env) {
|
|
18
17
|
this.orgId = orgId;
|
|
19
18
|
this.storeId = storeId;
|
|
20
|
-
this.
|
|
19
|
+
this.env = env;
|
|
21
20
|
this.token = null;
|
|
22
|
-
|
|
23
|
-
const endpoints = config_1.environmentEndpoints.dev;
|
|
24
|
-
console.log("🚀 ~ SDK ~ endpoints:", endpoints.computing);
|
|
21
|
+
const endpoints = env === "dev" ? config_1.environmentEndpoints.dev : config_1.environmentEndpoints.live;
|
|
25
22
|
this.product = new index_1.ProductService(endpoints.product, orgId, storeId);
|
|
26
23
|
this.auth = new index_2.AuthService(endpoints.auth, orgId, storeId);
|
|
27
24
|
this.order = new index_3.OrderService(endpoints.order, orgId, storeId);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LineItem, DiscountCampaign, CancelOrder, MemberDiscount, CampaignPromotion, OrderQuery } from "../../types/order";
|
|
1
|
+
import { LineItem, DiscountCampaign, CancelOrder, MemberDiscount, CampaignPromotion, OrderQuery, OrderModel } from "../../types/order";
|
|
2
2
|
import { Service } from "../serviceSDK";
|
|
3
3
|
/**
|
|
4
4
|
* Represents a service for managing orders.
|
|
@@ -20,7 +20,8 @@ export declare class OrderService extends Service {
|
|
|
20
20
|
* @returns A promise that resolves with the created order.
|
|
21
21
|
* @throws If an error occurs while creating the order.
|
|
22
22
|
*/
|
|
23
|
-
createOrder(orderData:
|
|
23
|
+
createOrder(orderData: OrderModel): Promise<any>;
|
|
24
|
+
createOrderDraft(orderData: OrderModel): Promise<any>;
|
|
24
25
|
/**
|
|
25
26
|
* Creates a temporary order.
|
|
26
27
|
*
|
|
@@ -35,9 +35,23 @@ class OrderService extends serviceSDK_1.Service {
|
|
|
35
35
|
* @returns A promise that resolves with the created order.
|
|
36
36
|
* @throws If an error occurs while creating the order.
|
|
37
37
|
*/
|
|
38
|
-
createOrder(orderData
|
|
38
|
+
createOrder(orderData) {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const endpoint = `/orders/${this.orgId}/${this.storeId}
|
|
40
|
+
const endpoint = `/orders/${this.orgId}/${this.storeId}/WEB?create_draft=false`; // Replace with your actual endpoint
|
|
41
|
+
const method = "POST";
|
|
42
|
+
try {
|
|
43
|
+
const response = yield this.restApiCallWithToken(endpoint, method, orderData);
|
|
44
|
+
return response;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.log(`Error in createOrder: ${error}`);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
createOrderDraft(orderData) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const endpoint = `/orders/${this.orgId}/${this.storeId}/WEB?create_draft=true`; // Replace with your actual endpoint
|
|
41
55
|
const method = "POST";
|
|
42
56
|
try {
|
|
43
57
|
const response = yield this.restApiCallWithToken(endpoint, method, orderData);
|
|
@@ -1185,7 +1199,7 @@ class OrderService extends serviceSDK_1.Service {
|
|
|
1185
1199
|
const method = "PUT";
|
|
1186
1200
|
try {
|
|
1187
1201
|
const response = yield this.restApiCallWithToken(endpoint, method, description, {
|
|
1188
|
-
|
|
1202
|
+
"Content-Type": "text/plain",
|
|
1189
1203
|
});
|
|
1190
1204
|
return response;
|
|
1191
1205
|
}
|
|
@@ -1197,7 +1211,7 @@ class OrderService extends serviceSDK_1.Service {
|
|
|
1197
1211
|
}
|
|
1198
1212
|
getOrderDetail(orderId) {
|
|
1199
1213
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1200
|
-
return this.restApiCallWithToken(`/orders/${this.orgId}/${this.storeId}/${orderId}/sale_order`,
|
|
1214
|
+
return this.restApiCallWithToken(`/orders/${this.orgId}/${this.storeId}/${orderId}/sale_order`, "GET");
|
|
1201
1215
|
});
|
|
1202
1216
|
}
|
|
1203
1217
|
}
|
|
@@ -52,3 +52,67 @@ export interface OrderQuery {
|
|
|
52
52
|
maxResult?: number;
|
|
53
53
|
source?: string;
|
|
54
54
|
}
|
|
55
|
+
export interface OrderModel {
|
|
56
|
+
time?: number;
|
|
57
|
+
orderId?: string;
|
|
58
|
+
orderType?: string;
|
|
59
|
+
customer?: any;
|
|
60
|
+
customerId?: string;
|
|
61
|
+
lineItems?: OrderItemModel[];
|
|
62
|
+
shippingAddressId?: string;
|
|
63
|
+
shippingAddress?: any;
|
|
64
|
+
paymentMethod?: string;
|
|
65
|
+
voucherIds?: string[];
|
|
66
|
+
note?: string;
|
|
67
|
+
totalAlreadyPaid?: number;
|
|
68
|
+
totalAlreadyPaidPaymentMethod?: string;
|
|
69
|
+
isExchangeOrder?: boolean;
|
|
70
|
+
exchangeForOrderId?: string;
|
|
71
|
+
exchangeOrderReturnId?: string;
|
|
72
|
+
saleId?: string;
|
|
73
|
+
discount?: any;
|
|
74
|
+
discountMember?: any;
|
|
75
|
+
shipping?: any;
|
|
76
|
+
vat?: any;
|
|
77
|
+
customerPaying?: number;
|
|
78
|
+
referralCode?: string;
|
|
79
|
+
warehouseId?: string;
|
|
80
|
+
source?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface CustomerDTO {
|
|
83
|
+
id: string;
|
|
84
|
+
fullName: string;
|
|
85
|
+
phoneNumber: string;
|
|
86
|
+
email: string;
|
|
87
|
+
}
|
|
88
|
+
export interface OrderItemModel {
|
|
89
|
+
productId: string;
|
|
90
|
+
quantity: number;
|
|
91
|
+
price: number;
|
|
92
|
+
inputPrice: number;
|
|
93
|
+
discountAmount: number;
|
|
94
|
+
typeDiscount: string;
|
|
95
|
+
}
|
|
96
|
+
export interface AddressDTO {
|
|
97
|
+
id: string;
|
|
98
|
+
fullName: string;
|
|
99
|
+
phoneNumber: string;
|
|
100
|
+
email: string;
|
|
101
|
+
address: string;
|
|
102
|
+
province: string;
|
|
103
|
+
district: string;
|
|
104
|
+
ward: string;
|
|
105
|
+
}
|
|
106
|
+
export interface DiscountDTO {
|
|
107
|
+
code: string;
|
|
108
|
+
value: number;
|
|
109
|
+
type: string;
|
|
110
|
+
applied: boolean;
|
|
111
|
+
}
|
|
112
|
+
export interface ShippingDTO {
|
|
113
|
+
code: string;
|
|
114
|
+
value: number;
|
|
115
|
+
}
|
|
116
|
+
export interface VatDTO {
|
|
117
|
+
value: number;
|
|
118
|
+
}
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function createToken(environment: string): string;
|
|
3
|
-
export declare function decodeToken(token: string): string | null;
|
|
4
|
-
export declare function validateStorefrontAccessToken(storefrontAccessToken: string): Endpoints;
|
|
1
|
+
export {};
|
|
@@ -1,41 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
? config_1.environmentEndpoints.dev
|
|
39
|
-
: config_1.environmentEndpoints.live;
|
|
40
|
-
}
|
|
41
|
-
exports.validateStorefrontAccessToken = validateStorefrontAccessToken;
|
|
3
|
+
// import { Endpoints } from "../lib/SDK";
|
|
4
|
+
// export function createToken(environment: string): string {
|
|
5
|
+
// const cipherText = CryptoJS.AES.encrypt(environment, "lvs").toString();
|
|
6
|
+
// console.log("🚀 ~ createToken ~ cipherText:", cipherText)
|
|
7
|
+
// return cipherText;
|
|
8
|
+
// }
|
|
9
|
+
// export function decodeToken(token: string): string | null {
|
|
10
|
+
// try {
|
|
11
|
+
// const bytes = CryptoJS.AES.decrypt(token, "lvs");
|
|
12
|
+
// const decryptedData = bytes.toString(CryptoJS.enc.Utf8);
|
|
13
|
+
// return decryptedData;
|
|
14
|
+
// } catch (error) {
|
|
15
|
+
// console.log("Invalid token");
|
|
16
|
+
// return null;
|
|
17
|
+
// }
|
|
18
|
+
// }
|
|
19
|
+
// export function validateStorefrontAccessToken(
|
|
20
|
+
// storefrontAccessToken: string
|
|
21
|
+
// ): Endpoints {
|
|
22
|
+
// const environment = decodeToken(storefrontAccessToken) || ""; // Handle null case by providing a default value
|
|
23
|
+
// console.log("🚀 ~ environment:", environment)
|
|
24
|
+
// const validEnvironments = {
|
|
25
|
+
// dev: "dev",
|
|
26
|
+
// live: "live",
|
|
27
|
+
// };
|
|
28
|
+
// if (!Object.keys(validEnvironments).includes(environment)) {
|
|
29
|
+
// throw new Error("Invalid storefrontAccessToken");
|
|
30
|
+
// }
|
|
31
|
+
// return environment == "dev"
|
|
32
|
+
// ? environmentEndpoints.dev
|
|
33
|
+
// : environmentEndpoints.live;
|
|
34
|
+
// }
|