@longvansoftware/storefront-js-client 1.7.7 → 1.7.9

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.
@@ -15,7 +15,7 @@ exports.environmentEndpoints = {
15
15
  campaign: "https://crm.dev.longvan.vn/campaign-gateway/graphql",
16
16
  image: "https://product-service.dev.longvan.vn/product-service/v1/products",
17
17
  paymentV2: "https://payment.dev.longvan.vn/graphql",
18
- warehouseV2: "https://portal.dev.longvan.vn/facility-api/public-facility/1.0.0/product-inventory-v3"
18
+ warehouseV2: "https://portal.dev.longvan.vn/facility-api"
19
19
  },
20
20
  live: {
21
21
  product: "https://product-service.longvan.vn/product-service/graphql",
@@ -10,6 +10,7 @@ export declare class Service {
10
10
  setToken(token: string): void;
11
11
  setStoreId(storeId: string): void;
12
12
  setOrgId(orgId: string): void;
13
+ private handleApolloError;
13
14
  protected graphqlQuery(query: DocumentNode, variables: any): Promise<any>;
14
15
  protected graphqlMutation(mutation: DocumentNode, variables: any): Promise<any>;
15
16
  protected restApiCallWithToken(path: string, method: "GET" | "POST" | "PUT" | "DELETE", data?: any, headers?: any): Promise<any>;
@@ -43,6 +43,16 @@ class Service {
43
43
  setOrgId(orgId) {
44
44
  this.orgId = orgId;
45
45
  }
46
+ // Hàm xử lý lỗi từ Apollo Client
47
+ handleApolloError(error) {
48
+ if (error.graphQLErrors && error.graphQLErrors.length > 0) {
49
+ return error.graphQLErrors.map((err) => err.message).join(", ");
50
+ }
51
+ if (error.networkError) {
52
+ return `Network Error: ${error.networkError.message}`;
53
+ }
54
+ return error.message || "An unknown error occurred";
55
+ }
46
56
  graphqlQuery(query, variables) {
47
57
  return __awaiter(this, void 0, void 0, function* () {
48
58
  try {
@@ -59,14 +69,14 @@ class Service {
59
69
  },
60
70
  },
61
71
  });
62
- if (errors) {
63
- throw new Error(`GraphQL error! errors: ${errors}`);
72
+ if (errors && errors.length > 0) {
73
+ throw this.handleApolloError({ graphQLErrors: errors });
64
74
  }
65
75
  return data;
66
76
  }
67
77
  catch (error) {
68
- console.log(`Error in graphqlQuery: ${error}`);
69
- throw error;
78
+ const errorMessage = this.handleApolloError(error);
79
+ throw errorMessage; // Throw message trực tiếp
70
80
  }
71
81
  });
72
82
  }
@@ -86,13 +96,14 @@ class Service {
86
96
  },
87
97
  },
88
98
  });
89
- if (errors) {
90
- throw new Error(`GraphQL error! errors: ${errors}`);
99
+ if (errors && errors.length > 0) {
100
+ throw this.handleApolloError({ graphQLErrors: errors });
91
101
  }
92
102
  return data;
93
103
  }
94
104
  catch (error) {
95
- throw error;
105
+ const errorMessage = this.handleApolloError(error);
106
+ throw errorMessage; // Throw message trực tiếp
96
107
  }
97
108
  });
98
109
  }
@@ -9,4 +9,5 @@ export declare class WarehouseServiceV2 extends Service {
9
9
  constructor(endpoint: string, orgId: string, storeId: string);
10
10
  setToken(token: string): void;
11
11
  getInventory(warehouseId: string, data: any[]): Promise<any>;
12
+ getInfoWarehouse(warehouseId: string): Promise<any>;
12
13
  }
@@ -26,7 +26,7 @@ class WarehouseServiceV2 extends serviceSDK_1.Service {
26
26
  }
27
27
  getInventory(warehouseId, data) {
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
- const endpoint = `/${warehouseId}`;
29
+ const endpoint = `/public-facility/1.0.0/product-inventory-v3/${warehouseId}`;
30
30
  const method = "POST";
31
31
  try {
32
32
  const response = yield this.restApiCallWithNoToken(endpoint, method, data);
@@ -37,5 +37,18 @@ class WarehouseServiceV2 extends serviceSDK_1.Service {
37
37
  }
38
38
  });
39
39
  }
40
+ getInfoWarehouse(warehouseId) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ try {
43
+ const endpoint = `/facility/1.0.0/facility/${warehouseId}`;
44
+ const method = "GET";
45
+ const response = yield this.restApiCallWithNoToken(endpoint, method);
46
+ return response;
47
+ }
48
+ catch (error) {
49
+ throw error;
50
+ }
51
+ });
52
+ }
40
53
  }
41
54
  exports.WarehouseServiceV2 = WarehouseServiceV2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longvansoftware/storefront-js-client",
3
- "version": "1.7.7",
3
+ "version": "1.7.9",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "files": [