@longvansoftware/storefront-js-client 3.9.1 → 3.9.3
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/src/lib/SDK.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export declare class SDK {
|
|
|
85
85
|
orderCloud: OrderCloudService;
|
|
86
86
|
constructor(orgId: string, storeId: string, environment: "dev" | "live");
|
|
87
87
|
setToken(token: string): void;
|
|
88
|
+
setDefaultToken(defaultToken: string | null): void;
|
|
88
89
|
setStoreId(storeId: string): void;
|
|
89
90
|
setOrgId(orgId: string): void;
|
|
90
91
|
}
|
package/dist/src/lib/SDK.js
CHANGED
|
@@ -29,6 +29,7 @@ const cashbook_1 = require("./cashbook");
|
|
|
29
29
|
const store_1 = require("./store");
|
|
30
30
|
const fileService_1 = require("./fileService");
|
|
31
31
|
const orderCloud_1 = require("./orderCloud");
|
|
32
|
+
const config_2 = require("../../config/config");
|
|
32
33
|
class SDK {
|
|
33
34
|
constructor(orgId, storeId, environment) {
|
|
34
35
|
this.orgId = orgId;
|
|
@@ -36,6 +37,7 @@ class SDK {
|
|
|
36
37
|
this.environment = environment;
|
|
37
38
|
this.token = null;
|
|
38
39
|
const endpoints = config_1.environmentEndpoints[environment];
|
|
40
|
+
const defaultToken = config_2.defaultTokens[environment];
|
|
39
41
|
this.product = new index_1.ProductService(endpoints.product, orgId, storeId);
|
|
40
42
|
this.auth = new index_2.AuthService(endpoints.auth, orgId, storeId);
|
|
41
43
|
this.order = new index_3.OrderService(endpoints.order, orgId, storeId, environment);
|
|
@@ -62,6 +64,32 @@ class SDK {
|
|
|
62
64
|
this.store = new store_1.StoreService(endpoints.store, orgId, storeId); // Using product endpoint for now
|
|
63
65
|
this.fileService = new fileService_1.FileServiceSerVice(endpoints.fileService, orgId, storeId);
|
|
64
66
|
this.orderCloud = new orderCloud_1.OrderCloudService(endpoints.orderCloud, orgId, storeId);
|
|
67
|
+
this.product.setDefaultToken(defaultToken);
|
|
68
|
+
this.auth.setDefaultToken(defaultToken);
|
|
69
|
+
this.order.setDefaultToken(defaultToken);
|
|
70
|
+
this.user.setDefaultToken(defaultToken);
|
|
71
|
+
this.payment.setDefaultToken(defaultToken);
|
|
72
|
+
this.crm.setDefaultToken(defaultToken);
|
|
73
|
+
this.service.setDefaultToken(defaultToken);
|
|
74
|
+
this.warehouse.setDefaultToken(defaultToken);
|
|
75
|
+
this.computing.setDefaultToken(defaultToken);
|
|
76
|
+
this.campaign.setDefaultToken(defaultToken);
|
|
77
|
+
this.image.setDefaultToken(defaultToken);
|
|
78
|
+
this.paymentV2.setDefaultToken(defaultToken);
|
|
79
|
+
this.warehouseV2.setDefaultToken(defaultToken);
|
|
80
|
+
this.deepLinkVietQr.setDefaultToken(defaultToken);
|
|
81
|
+
this.comhub.setDefaultToken(defaultToken);
|
|
82
|
+
this.portal.setDefaultToken(defaultToken);
|
|
83
|
+
this.upload.setDefaultToken(defaultToken);
|
|
84
|
+
this.getImage.setDefaultToken(defaultToken);
|
|
85
|
+
this.accounting.setDefaultToken(defaultToken);
|
|
86
|
+
this.omnigateway.setDefaultToken(defaultToken);
|
|
87
|
+
this.authorization.setDefaultToken(defaultToken);
|
|
88
|
+
this.zca.setDefaultToken(defaultToken);
|
|
89
|
+
this.cashbook.setDefaultToken(defaultToken);
|
|
90
|
+
this.store.setDefaultToken(defaultToken);
|
|
91
|
+
this.fileService.setDefaultToken(defaultToken);
|
|
92
|
+
this.orderCloud.setDefaultToken(defaultToken);
|
|
65
93
|
// Initialize other services here
|
|
66
94
|
}
|
|
67
95
|
setToken(token) {
|
|
@@ -95,6 +123,34 @@ class SDK {
|
|
|
95
123
|
this.fileService.setToken(token);
|
|
96
124
|
this.orderCloud.setToken(token);
|
|
97
125
|
}
|
|
126
|
+
setDefaultToken(defaultToken) {
|
|
127
|
+
this.product.setDefaultToken(defaultToken);
|
|
128
|
+
this.auth.setDefaultToken(defaultToken);
|
|
129
|
+
this.order.setDefaultToken(defaultToken);
|
|
130
|
+
this.user.setDefaultToken(defaultToken);
|
|
131
|
+
this.payment.setDefaultToken(defaultToken);
|
|
132
|
+
this.crm.setDefaultToken(defaultToken);
|
|
133
|
+
this.service.setDefaultToken(defaultToken);
|
|
134
|
+
this.warehouse.setDefaultToken(defaultToken);
|
|
135
|
+
this.computing.setDefaultToken(defaultToken);
|
|
136
|
+
this.campaign.setDefaultToken(defaultToken);
|
|
137
|
+
this.image.setDefaultToken(defaultToken);
|
|
138
|
+
this.paymentV2.setDefaultToken(defaultToken);
|
|
139
|
+
this.warehouseV2.setDefaultToken(defaultToken);
|
|
140
|
+
this.deepLinkVietQr.setDefaultToken(defaultToken);
|
|
141
|
+
this.comhub.setDefaultToken(defaultToken);
|
|
142
|
+
this.portal.setDefaultToken(defaultToken);
|
|
143
|
+
this.upload.setDefaultToken(defaultToken);
|
|
144
|
+
this.getImage.setDefaultToken(defaultToken);
|
|
145
|
+
this.accounting.setDefaultToken(defaultToken);
|
|
146
|
+
this.omnigateway.setDefaultToken(defaultToken);
|
|
147
|
+
this.authorization.setDefaultToken(defaultToken);
|
|
148
|
+
this.zca.setDefaultToken(defaultToken);
|
|
149
|
+
this.cashbook.setDefaultToken(defaultToken);
|
|
150
|
+
this.store.setDefaultToken(defaultToken);
|
|
151
|
+
this.fileService.setDefaultToken(defaultToken);
|
|
152
|
+
this.orderCloud.setDefaultToken(defaultToken);
|
|
153
|
+
}
|
|
98
154
|
// các module export từ serviceSDK.ts set storeId vào serviceSDK.ts
|
|
99
155
|
// src/service.ts
|
|
100
156
|
setStoreId(storeId) {
|
|
@@ -10,7 +10,7 @@ export declare class OrderService extends Service {
|
|
|
10
10
|
* @param orgId - The organization ID.
|
|
11
11
|
* @param storeId - The store ID.
|
|
12
12
|
*/
|
|
13
|
-
constructor(endpoint: string, orgId: string, storeId: string, environment
|
|
13
|
+
constructor(endpoint: string, orgId: string, storeId: string, environment: "dev" | "live");
|
|
14
14
|
setToken(token: string): void;
|
|
15
15
|
/**
|
|
16
16
|
* Override restApiCallWithToken to use default token if no token is set
|
|
@@ -75,6 +75,17 @@ export declare class OrderService extends Service {
|
|
|
75
75
|
* @throws If an error occurs while updating the customer and shipping address.
|
|
76
76
|
*/
|
|
77
77
|
updateCustomerAndShippingAddress(orderId: string, customerId: string, shippingAddress: string): Promise<any>;
|
|
78
|
+
updateShippingAddressWithoutLogin(orderId: string, shippingData: {
|
|
79
|
+
name: string;
|
|
80
|
+
phone: string;
|
|
81
|
+
address: string;
|
|
82
|
+
province: string;
|
|
83
|
+
district: string;
|
|
84
|
+
ward: string;
|
|
85
|
+
province_code: string;
|
|
86
|
+
district_code: string;
|
|
87
|
+
ward_code: string;
|
|
88
|
+
}): Promise<any>;
|
|
78
89
|
/**
|
|
79
90
|
* Retrieves the order line items for a specific order.
|
|
80
91
|
* @param partnerId - The partner ID.
|
|
@@ -16,7 +16,6 @@ exports.OrderService = void 0;
|
|
|
16
16
|
const serviceSDK_1 = require("../serviceSDK");
|
|
17
17
|
const validatePhoneNumber_1 = require("../../utils/validatePhoneNumber");
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
|
-
const config_1 = require("../../../config/config");
|
|
20
19
|
/**
|
|
21
20
|
* Represents a service for managing orders.
|
|
22
21
|
*/
|
|
@@ -27,7 +26,7 @@ class OrderService extends serviceSDK_1.Service {
|
|
|
27
26
|
* @param orgId - The organization ID.
|
|
28
27
|
* @param storeId - The store ID.
|
|
29
28
|
*/
|
|
30
|
-
constructor(endpoint, orgId, storeId, environment
|
|
29
|
+
constructor(endpoint, orgId, storeId, environment) {
|
|
31
30
|
super(endpoint, orgId, storeId, environment);
|
|
32
31
|
}
|
|
33
32
|
setToken(token) {
|
|
@@ -38,7 +37,10 @@ class OrderService extends serviceSDK_1.Service {
|
|
|
38
37
|
*/
|
|
39
38
|
restApiCallWithToken(path, method, data, headers) {
|
|
40
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const tokenToUse = this.token ||
|
|
40
|
+
const tokenToUse = this.token || this.defaultToken;
|
|
41
|
+
if (!tokenToUse) {
|
|
42
|
+
throw new Error("Token is required");
|
|
43
|
+
}
|
|
42
44
|
try {
|
|
43
45
|
const modifiedHeaders = Object.assign(Object.assign({}, headers), { PartnerId: this.orgId, Authorization: "Bearer " + tokenToUse, "X-Ecomos-Access-Token": tokenToUse, "Partner-Id": this.orgId });
|
|
44
46
|
const response = yield (0, axios_1.default)({
|
|
@@ -208,6 +210,23 @@ class OrderService extends serviceSDK_1.Service {
|
|
|
208
210
|
}
|
|
209
211
|
});
|
|
210
212
|
}
|
|
213
|
+
updateShippingAddressWithoutLogin(orderId, shippingData) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
const endpoint = `/front/orders/express/${this.orgId}/${this.storeId}/${orderId}/shipping-address`;
|
|
216
|
+
const method = "PUT";
|
|
217
|
+
try {
|
|
218
|
+
const response = yield this.restApiCallWithNoToken(endpoint, method, shippingData);
|
|
219
|
+
console.log("RESPONSE:", response);
|
|
220
|
+
return response;
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
if (error.response && error.response.data) {
|
|
224
|
+
console.error("Backend Error Detail:", JSON.stringify(error.response.data, null, 2));
|
|
225
|
+
}
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
211
230
|
/**
|
|
212
231
|
* Retrieves the order line items for a specific order.
|
|
213
232
|
* @param partnerId - The partner ID.
|
|
@@ -2,13 +2,15 @@ import { ApolloClient, NormalizedCacheObject } from "@apollo/client";
|
|
|
2
2
|
import { DocumentNode } from "graphql";
|
|
3
3
|
export declare class Service {
|
|
4
4
|
protected token: string | null;
|
|
5
|
+
protected defaultToken: string | null;
|
|
5
6
|
protected client: ApolloClient<NormalizedCacheObject>;
|
|
6
7
|
protected orgId: string;
|
|
7
8
|
protected storeId: string;
|
|
8
9
|
protected endpoint: string;
|
|
9
10
|
protected environment: "dev" | "live";
|
|
10
|
-
constructor(endpoint: string, orgId: string, storeId: string, environment?: "dev" | "live");
|
|
11
|
+
constructor(endpoint: string, orgId: string, storeId: string, environment?: "dev" | "live", defaultToken?: string | null);
|
|
11
12
|
setToken(token: string): void;
|
|
13
|
+
setDefaultToken(defaultToken: string | null): void;
|
|
12
14
|
setStoreId(storeId: string): void;
|
|
13
15
|
setOrgId(orgId: string): void;
|
|
14
16
|
private handleApolloError;
|
|
@@ -18,8 +18,9 @@ const client_1 = require("@apollo/client");
|
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
19
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
20
20
|
class Service {
|
|
21
|
-
constructor(endpoint, orgId, storeId, environment = "dev") {
|
|
21
|
+
constructor(endpoint, orgId, storeId, environment = "dev", defaultToken = null) {
|
|
22
22
|
this.token = null;
|
|
23
|
+
this.defaultToken = null;
|
|
23
24
|
this.client = new client_1.ApolloClient({
|
|
24
25
|
link: new client_1.HttpLink({ uri: endpoint, fetch: cross_fetch_1.default }),
|
|
25
26
|
// uri: endpoint,
|
|
@@ -34,10 +35,14 @@ class Service {
|
|
|
34
35
|
this.storeId = storeId;
|
|
35
36
|
this.endpoint = endpoint;
|
|
36
37
|
this.environment = environment;
|
|
38
|
+
this.defaultToken = defaultToken;
|
|
37
39
|
}
|
|
38
40
|
setToken(token) {
|
|
39
41
|
this.token = token;
|
|
40
42
|
}
|
|
43
|
+
setDefaultToken(defaultToken) {
|
|
44
|
+
this.defaultToken = defaultToken;
|
|
45
|
+
}
|
|
41
46
|
setStoreId(storeId) {
|
|
42
47
|
this.storeId = storeId;
|
|
43
48
|
}
|
|
@@ -111,7 +116,11 @@ class Service {
|
|
|
111
116
|
restApiCallWithToken(path, method, data, headers) {
|
|
112
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
118
|
try {
|
|
114
|
-
const
|
|
119
|
+
const tokenToUse = this.token || this.defaultToken;
|
|
120
|
+
if (!tokenToUse) {
|
|
121
|
+
throw new Error("Token is required");
|
|
122
|
+
}
|
|
123
|
+
const modifiedHeaders = Object.assign(Object.assign({}, headers), { PartnerId: this.orgId, Authorization: "Bearer " + tokenToUse, "X-Ecomos-Access-Token": tokenToUse, "Partner-Id": this.orgId });
|
|
115
124
|
const response = yield (0, axios_1.default)({
|
|
116
125
|
url: this.endpoint + path,
|
|
117
126
|
method,
|