@longvansoftware/storefront-js-client 3.8.7 → 3.8.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.
@@ -1,3 +1,7 @@
1
+ export declare const defaultTokens: {
2
+ dev: string;
3
+ live: string;
4
+ };
1
5
  export declare const environmentEndpoints: {
2
6
  dev: {
3
7
  product: string;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.environmentEndpoints = void 0;
3
+ exports.environmentEndpoints = exports.defaultTokens = void 0;
4
+ exports.defaultTokens = {
5
+ dev: "0194deb7-288b-7935-88ef-2671719a4324",
6
+ live: "0195f9f6-467c-7ff5-8d83-d0229ef63f8f",
7
+ };
4
8
  exports.environmentEndpoints = {
5
9
  dev: {
6
10
  product: "https://product-service.dev.longvan.vn/product-service/graphql",
@@ -37,7 +37,7 @@ class SDK {
37
37
  const endpoints = config_1.environmentEndpoints[environment];
38
38
  this.product = new index_1.ProductService(endpoints.product, orgId, storeId);
39
39
  this.auth = new index_2.AuthService(endpoints.auth, orgId, storeId);
40
- this.order = new index_3.OrderService(endpoints.order, orgId, storeId);
40
+ this.order = new index_3.OrderService(endpoints.order, orgId, storeId, environment);
41
41
  this.user = new index_5.UserService(endpoints.user, orgId, storeId);
42
42
  this.payment = new index_6.PaymentService(endpoints.payment, orgId, storeId);
43
43
  this.crm = new index_7.CrmService(endpoints.crm, orgId, storeId);
@@ -10,8 +10,12 @@ 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);
13
+ constructor(endpoint: string, orgId: string, storeId: string, environment?: "dev" | "live");
14
14
  setToken(token: string): void;
15
+ /**
16
+ * Override restApiCallWithToken to use default token if no token is set
17
+ */
18
+ protected restApiCallWithToken(path: string, method: "GET" | "POST" | "PUT" | "DELETE", data?: any, headers?: any): Promise<any>;
15
19
  /**
16
20
  * Creates a new order.
17
21
  * @param orderData - The data for the order.
@@ -8,10 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.OrderService = void 0;
13
16
  const serviceSDK_1 = require("../serviceSDK");
14
17
  const validatePhoneNumber_1 = require("../../utils/validatePhoneNumber");
18
+ const axios_1 = __importDefault(require("axios"));
19
+ const config_1 = require("../../../config/config");
15
20
  /**
16
21
  * Represents a service for managing orders.
17
22
  */
@@ -22,12 +27,33 @@ class OrderService extends serviceSDK_1.Service {
22
27
  * @param orgId - The organization ID.
23
28
  * @param storeId - The store ID.
24
29
  */
25
- constructor(endpoint, orgId, storeId) {
26
- super(endpoint, orgId, storeId);
30
+ constructor(endpoint, orgId, storeId, environment = "dev") {
31
+ super(endpoint, orgId, storeId, environment);
27
32
  }
28
33
  setToken(token) {
29
34
  this.token = token;
30
35
  }
36
+ /**
37
+ * Override restApiCallWithToken to use default token if no token is set
38
+ */
39
+ restApiCallWithToken(path, method, data, headers) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const tokenToUse = this.token || config_1.defaultTokens[this.environment];
42
+ try {
43
+ const modifiedHeaders = Object.assign(Object.assign({}, headers), { PartnerId: this.orgId, Authorization: "Bearer " + tokenToUse, "X-Ecomos-Access-Token": tokenToUse, "Partner-Id": this.orgId });
44
+ const response = yield (0, axios_1.default)({
45
+ url: this.endpoint + path,
46
+ method,
47
+ data,
48
+ headers: modifiedHeaders,
49
+ });
50
+ return response.data;
51
+ }
52
+ catch (error) {
53
+ throw error;
54
+ }
55
+ });
56
+ }
31
57
  /**
32
58
  * Creates a new order.
33
59
  * @param orderData - The data for the order.
@@ -6,7 +6,8 @@ export declare class Service {
6
6
  protected orgId: string;
7
7
  protected storeId: string;
8
8
  protected endpoint: string;
9
- constructor(endpoint: string, orgId: string, storeId: string);
9
+ protected environment: "dev" | "live";
10
+ constructor(endpoint: string, orgId: string, storeId: string, environment?: "dev" | "live");
10
11
  setToken(token: string): void;
11
12
  setStoreId(storeId: string): void;
12
13
  setOrgId(orgId: string): void;
@@ -18,7 +18,7 @@ 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) {
21
+ constructor(endpoint, orgId, storeId, environment = "dev") {
22
22
  this.token = null;
23
23
  this.client = new client_1.ApolloClient({
24
24
  link: new client_1.HttpLink({ uri: endpoint, fetch: cross_fetch_1.default }),
@@ -33,6 +33,7 @@ class Service {
33
33
  this.orgId = orgId;
34
34
  this.storeId = storeId;
35
35
  this.endpoint = endpoint;
36
+ this.environment = environment;
36
37
  }
37
38
  setToken(token) {
38
39
  this.token = token;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longvansoftware/storefront-js-client",
3
- "version": "3.8.7",
3
+ "version": "3.8.8",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "files": [