@longvansoftware/storefront-js-client 3.9.3 → 3.9.4

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.
@@ -85,7 +85,6 @@ 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;
89
88
  setStoreId(storeId: string): void;
90
89
  setOrgId(orgId: string): void;
91
90
  }
@@ -29,7 +29,6 @@ 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");
33
32
  class SDK {
34
33
  constructor(orgId, storeId, environment) {
35
34
  this.orgId = orgId;
@@ -37,7 +36,6 @@ class SDK {
37
36
  this.environment = environment;
38
37
  this.token = null;
39
38
  const endpoints = config_1.environmentEndpoints[environment];
40
- const defaultToken = config_2.defaultTokens[environment];
41
39
  this.product = new index_1.ProductService(endpoints.product, orgId, storeId);
42
40
  this.auth = new index_2.AuthService(endpoints.auth, orgId, storeId);
43
41
  this.order = new index_3.OrderService(endpoints.order, orgId, storeId, environment);
@@ -64,32 +62,6 @@ class SDK {
64
62
  this.store = new store_1.StoreService(endpoints.store, orgId, storeId); // Using product endpoint for now
65
63
  this.fileService = new fileService_1.FileServiceSerVice(endpoints.fileService, orgId, storeId);
66
64
  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);
93
65
  // Initialize other services here
94
66
  }
95
67
  setToken(token) {
@@ -123,34 +95,6 @@ class SDK {
123
95
  this.fileService.setToken(token);
124
96
  this.orderCloud.setToken(token);
125
97
  }
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
- }
154
98
  // các module export từ serviceSDK.ts set storeId vào serviceSDK.ts
155
99
  // src/service.ts
156
100
  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: "dev" | "live");
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,17 +75,6 @@ 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>;
89
78
  /**
90
79
  * Retrieves the order line items for a specific order.
91
80
  * @param partnerId - The partner ID.
@@ -16,6 +16,7 @@ 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");
19
20
  /**
20
21
  * Represents a service for managing orders.
21
22
  */
@@ -26,7 +27,7 @@ class OrderService extends serviceSDK_1.Service {
26
27
  * @param orgId - The organization ID.
27
28
  * @param storeId - The store ID.
28
29
  */
29
- constructor(endpoint, orgId, storeId, environment) {
30
+ constructor(endpoint, orgId, storeId, environment = "dev") {
30
31
  super(endpoint, orgId, storeId, environment);
31
32
  }
32
33
  setToken(token) {
@@ -37,10 +38,7 @@ class OrderService extends serviceSDK_1.Service {
37
38
  */
38
39
  restApiCallWithToken(path, method, data, headers) {
39
40
  return __awaiter(this, void 0, void 0, function* () {
40
- const tokenToUse = this.token || this.defaultToken;
41
- if (!tokenToUse) {
42
- throw new Error("Token is required");
43
- }
41
+ const tokenToUse = this.token || config_1.defaultTokens[this.environment];
44
42
  try {
45
43
  const modifiedHeaders = Object.assign(Object.assign({}, headers), { PartnerId: this.orgId, Authorization: "Bearer " + tokenToUse, "X-Ecomos-Access-Token": tokenToUse, "Partner-Id": this.orgId });
46
44
  const response = yield (0, axios_1.default)({
@@ -210,23 +208,6 @@ class OrderService extends serviceSDK_1.Service {
210
208
  }
211
209
  });
212
210
  }
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
- }
230
211
  /**
231
212
  * Retrieves the order line items for a specific order.
232
213
  * @param partnerId - The partner ID.
@@ -2,15 +2,13 @@ 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;
6
5
  protected client: ApolloClient<NormalizedCacheObject>;
7
6
  protected orgId: string;
8
7
  protected storeId: string;
9
8
  protected endpoint: string;
10
9
  protected environment: "dev" | "live";
11
- constructor(endpoint: string, orgId: string, storeId: string, environment?: "dev" | "live", defaultToken?: string | null);
10
+ constructor(endpoint: string, orgId: string, storeId: string, environment?: "dev" | "live");
12
11
  setToken(token: string): void;
13
- setDefaultToken(defaultToken: string | null): void;
14
12
  setStoreId(storeId: string): void;
15
13
  setOrgId(orgId: string): void;
16
14
  private handleApolloError;
@@ -18,9 +18,8 @@ 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", defaultToken = null) {
21
+ constructor(endpoint, orgId, storeId, environment = "dev") {
22
22
  this.token = null;
23
- this.defaultToken = null;
24
23
  this.client = new client_1.ApolloClient({
25
24
  link: new client_1.HttpLink({ uri: endpoint, fetch: cross_fetch_1.default }),
26
25
  // uri: endpoint,
@@ -35,14 +34,10 @@ class Service {
35
34
  this.storeId = storeId;
36
35
  this.endpoint = endpoint;
37
36
  this.environment = environment;
38
- this.defaultToken = defaultToken;
39
37
  }
40
38
  setToken(token) {
41
39
  this.token = token;
42
40
  }
43
- setDefaultToken(defaultToken) {
44
- this.defaultToken = defaultToken;
45
- }
46
41
  setStoreId(storeId) {
47
42
  this.storeId = storeId;
48
43
  }
@@ -116,11 +111,7 @@ class Service {
116
111
  restApiCallWithToken(path, method, data, headers) {
117
112
  return __awaiter(this, void 0, void 0, function* () {
118
113
  try {
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 });
114
+ const modifiedHeaders = Object.assign(Object.assign({}, headers), { PartnerId: this.orgId, Authorization: "Bearer " + this.token, "X-Ecomos-Access-Token": this.token, "Partner-Id": this.orgId });
124
115
  const response = yield (0, axios_1.default)({
125
116
  url: this.endpoint + path,
126
117
  method,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longvansoftware/storefront-js-client",
3
- "version": "3.9.3",
3
+ "version": "3.9.4",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "files": [