@longvansoftware/service-js-client 1.13.5 → 1.13.7

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.
@@ -21,3 +21,4 @@ export declare const GET_DETAIL_STORES: DocumentNode;
21
21
  export declare const GET_LIST_PRICE: DocumentNode;
22
22
  export declare const GET_TAGS: DocumentNode;
23
23
  export declare const GET_TAGS_BY_CATEGORY: DocumentNode;
24
+ export declare const GET_LIST_PRODUCTS_CONFIG_DYNAMIC: (fields?: string[]) => DocumentNode;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GET_TAGS_BY_CATEGORY = exports.GET_TAGS = exports.GET_LIST_PRICE = exports.GET_DETAIL_STORES = exports.GET_RELATED_INFOR = exports.GET_PRODUCT_VARIANT_BY_ID = exports.GET_RESOURCE_BY_PRODUCT = exports.GET_HANDLE_BY_SERVICETYPE = exports.GET_PRODUCTS_DYNAMIC = exports.GET_PRODUCTS = exports.GET_POLICY = exports.GET_PRODUCT_OPTION = exports.GET_BRAND_DETAIL_QUERY = exports.GET_BRANDS_BY_CATEGORY_QUERY = exports.GET_BRANDS_QUERY = exports.GET_CATEGORY_BY_ID_QUERY = exports.GET_CATEGORY_BY_HANDLE_QUERY = exports.GET_CATEGORIES_QUERY = exports.GET_SIMPLE_PRODUCTS_QUERY = exports.GET_PRODUCT_BY_SLUG_QUERY = exports.GET_PRODUCT_BY_ID_QUERY_DYNAMIC = exports.GET_PRODUCT_BY_ID_QUERY = void 0;
3
+ exports.GET_LIST_PRODUCTS_CONFIG_DYNAMIC = exports.GET_TAGS_BY_CATEGORY = exports.GET_TAGS = exports.GET_LIST_PRICE = exports.GET_DETAIL_STORES = exports.GET_RELATED_INFOR = exports.GET_PRODUCT_VARIANT_BY_ID = exports.GET_RESOURCE_BY_PRODUCT = exports.GET_HANDLE_BY_SERVICETYPE = exports.GET_PRODUCTS_DYNAMIC = exports.GET_PRODUCTS = exports.GET_POLICY = exports.GET_PRODUCT_OPTION = exports.GET_BRAND_DETAIL_QUERY = exports.GET_BRANDS_BY_CATEGORY_QUERY = exports.GET_BRANDS_QUERY = exports.GET_CATEGORY_BY_ID_QUERY = exports.GET_CATEGORY_BY_HANDLE_QUERY = exports.GET_CATEGORIES_QUERY = exports.GET_SIMPLE_PRODUCTS_QUERY = exports.GET_PRODUCT_BY_SLUG_QUERY = exports.GET_PRODUCT_BY_ID_QUERY_DYNAMIC = exports.GET_PRODUCT_BY_ID_QUERY = void 0;
4
4
  const graphql_tag_1 = require("graphql-tag");
5
5
  // export const GET_PRODUCT_BY_ID_QUERY = gql`
6
6
  // query GetProductById(
@@ -499,6 +499,7 @@ exports.GET_PRODUCT_OPTION = (0, graphql_tag_1.gql) `
499
499
  type
500
500
  subType
501
501
  fill
502
+ otherItem
502
503
  requireData
503
504
  values
504
505
  valuesFull {
@@ -997,3 +998,23 @@ exports.GET_TAGS_BY_CATEGORY = (0, graphql_tag_1.gql) `
997
998
  }
998
999
  }
999
1000
  `;
1001
+ const GET_LIST_PRODUCTS_CONFIG_DYNAMIC = (fields = []) => {
1002
+ const fieldStr = fields.join("\n ");
1003
+ const hasFields = fields.length > 0;
1004
+ return (0, graphql_tag_1.gql) `
1005
+ query getListProductConfig(
1006
+ $partnerId: String!
1007
+ $storeChannel: String!
1008
+ $productId: String!
1009
+ ) {
1010
+ getListProductConfig(
1011
+ partnerId: $partnerId
1012
+ storeChannel: $storeChannel
1013
+ productId: $productId
1014
+ ) {
1015
+ ${hasFields ? `${fieldStr}` : ""}
1016
+ }
1017
+ }
1018
+ `;
1019
+ };
1020
+ exports.GET_LIST_PRODUCTS_CONFIG_DYNAMIC = GET_LIST_PRODUCTS_CONFIG_DYNAMIC;
@@ -48,4 +48,5 @@ export declare class ProductService extends Service {
48
48
  getListPrice(productIds: string[], storeId: string): Promise<any>;
49
49
  getTags(storeId: string): Promise<any>;
50
50
  getTagsByCategory(categoryId: string, storeId: string): Promise<any>;
51
+ getListProductConfigDynamic(productId: string, store: string, fields: string[]): Promise<any>;
51
52
  }
@@ -317,5 +317,23 @@ class ProductService extends serviceSDK_1.Service {
317
317
  }
318
318
  });
319
319
  }
320
+ getListProductConfigDynamic(productId, store, fields) {
321
+ return __awaiter(this, void 0, void 0, function* () {
322
+ const query = (0, queries_1.GET_LIST_PRODUCTS_CONFIG_DYNAMIC)(fields);
323
+ const variablesHandle = {
324
+ partnerId: this.orgId,
325
+ storeChannel: store ? store : this.storeId,
326
+ productId,
327
+ };
328
+ try {
329
+ const response = yield this.graphqlQueryV2(query, variablesHandle);
330
+ return response.getListProductConfig;
331
+ }
332
+ catch (error) {
333
+ console.log(`Error fetching getListProductConfig : ${error}`);
334
+ throw error;
335
+ }
336
+ });
337
+ }
320
338
  }
321
339
  exports.ProductService = ProductService;
@@ -0,0 +1,14 @@
1
+ import { ApolloClient, NormalizedCacheObject } from "@apollo/client";
2
+ import { DocumentNode } from "graphql";
3
+ export declare class Service {
4
+ protected token: string | null;
5
+ protected client: ApolloClient<NormalizedCacheObject>;
6
+ protected orgId: string;
7
+ protected storeId: string;
8
+ protected endpoint: string;
9
+ constructor(endpoint: string, orgId: string, storeId: string);
10
+ setToken(token: string): void;
11
+ protected graphqlQuery(query: DocumentNode, variables: any): Promise<any>;
12
+ protected graphqlMutation(mutation: DocumentNode, variables: any): Promise<any>;
13
+ protected restApiCallWithToken(path: string, method: "GET" | "POST" | "PUT" | "DELETE", data?: any, headers?: any): Promise<any>;
14
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ // src/service.ts
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.Service = void 0;
17
+ const client_1 = require("@apollo/client");
18
+ const axios_1 = __importDefault(require("axios"));
19
+ class Service {
20
+ constructor(endpoint, orgId, storeId) {
21
+ this.token = null;
22
+ this.client = new client_1.ApolloClient({
23
+ uri: endpoint,
24
+ cache: new client_1.InMemoryCache(),
25
+ defaultOptions: {
26
+ query: {
27
+ fetchPolicy: "network-only",
28
+ },
29
+ },
30
+ });
31
+ this.orgId = orgId;
32
+ this.storeId = storeId;
33
+ this.endpoint = endpoint;
34
+ }
35
+ setToken(token) {
36
+ this.token = token;
37
+ }
38
+ // setOrgId(orgId: string) {
39
+ // this.orgId = orgId;
40
+ // }
41
+ graphqlQuery(query, variables) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ try {
44
+ const { data, errors } = yield this.client.query({
45
+ query: (0, client_1.gql) `
46
+ ${query}
47
+ `,
48
+ variables,
49
+ });
50
+ if (errors) {
51
+ throw new Error(`GraphQL error! errors: ${errors}`);
52
+ }
53
+ return data;
54
+ }
55
+ catch (error) {
56
+ console.log(`Error in graphqlQuery: ${error}`);
57
+ throw error;
58
+ }
59
+ });
60
+ }
61
+ graphqlMutation(mutation, variables) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ try {
64
+ const { data, errors } = yield this.client.mutate({
65
+ mutation: (0, client_1.gql) `
66
+ ${mutation}
67
+ `,
68
+ variables,
69
+ });
70
+ if (errors) {
71
+ throw new Error(`GraphQL error! errors: ${errors}`);
72
+ }
73
+ return data;
74
+ }
75
+ catch (error) {
76
+ console.log(`Error in graphqlMutation: ${error}`);
77
+ throw error;
78
+ }
79
+ });
80
+ }
81
+ restApiCallWithToken(path, method, data, headers) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ try {
84
+ const modifiedHeaders = Object.assign(Object.assign({}, headers), { "Partner-Id": this.orgId, "X-Ecomos-Access-Token": this.token });
85
+ console.log("🚀 ~ Service ~ modifiedHeaders:", modifiedHeaders);
86
+ const response = yield (0, axios_1.default)({
87
+ url: this.endpoint + path,
88
+ method,
89
+ data,
90
+ headers: modifiedHeaders,
91
+ });
92
+ return response.data;
93
+ }
94
+ catch (error) {
95
+ console.log(`Error in restApiCallWithToken: ${error}`);
96
+ throw error;
97
+ }
98
+ });
99
+ }
100
+ }
101
+ exports.Service = Service;
@@ -0,0 +1 @@
1
+ export declare function buildFieldString(fields: (string | Record<string, any>)[], indent?: number): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildFieldString = void 0;
4
+ function buildFieldString(fields, indent = 6) {
5
+ const space = " ".repeat(indent);
6
+ return fields
7
+ .map((field) => {
8
+ if (typeof field === "string")
9
+ return `${space}${field}`;
10
+ const [key, value] = Object.entries(field)[0];
11
+ const nested = buildFieldString(value, indent + 2);
12
+ return `${space}${key} {\n${nested}\n${space}}`;
13
+ })
14
+ .join("\n");
15
+ }
16
+ exports.buildFieldString = buildFieldString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longvansoftware/service-js-client",
3
- "version": "1.13.5",
3
+ "version": "1.13.7",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "files": [