@longvansoftware/service-js-client 1.20.5 → 1.20.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.
@@ -5,3 +5,4 @@ export declare const GET_QUANTITY_ORDER_LINEITEMS: DocumentNode;
5
5
  export declare const GET_ORDER_LINE_ITEM_BY_SERVICE_ID: DocumentNode;
6
6
  export declare const GET_ORDER_BY_SERVICE_ID: DocumentNode;
7
7
  export declare const FIND_ORDER_BY_OWNER_PARTYID: DocumentNode;
8
+ export declare const CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC: (fields?: string[]) => DocumentNode;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FIND_ORDER_BY_OWNER_PARTYID = exports.GET_ORDER_BY_SERVICE_ID = exports.GET_ORDER_LINE_ITEM_BY_SERVICE_ID = exports.GET_QUANTITY_ORDER_LINEITEMS = exports.GET_ORDER_DETAIL_DYNAMIC = exports.GET_ORDER_DETAIL = void 0;
3
+ exports.CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC = exports.FIND_ORDER_BY_OWNER_PARTYID = exports.GET_ORDER_BY_SERVICE_ID = exports.GET_ORDER_LINE_ITEM_BY_SERVICE_ID = exports.GET_QUANTITY_ORDER_LINEITEMS = exports.GET_ORDER_DETAIL_DYNAMIC = exports.GET_ORDER_DETAIL = void 0;
4
4
  const graphql_tag_1 = require("graphql-tag");
5
5
  exports.GET_ORDER_DETAIL = (0, graphql_tag_1.gql) `
6
6
  query getOrderDetail($orderId: String!) {
@@ -138,46 +138,46 @@ exports.GET_ORDER_DETAIL = (0, graphql_tag_1.gql) `
138
138
  title
139
139
  }
140
140
  resourceConfigs {
141
- name
142
- quantity
143
- unit
144
- productId
145
- giftProductId
146
- gift
147
- giftQuantity
148
- campaignId
149
- campaignActionId
150
- qualify
151
- idParent
152
- addQuantity
153
- defaultQuantity
154
- title
155
- price
156
- unitPrice
157
- totalResource
158
- }
159
- resourceItems {
160
- name
161
- quantity
162
- unit
163
- productId
164
- giftProductId
165
- gift
166
- giftQuantity
167
- campaignId
168
- campaignActionId
169
- qualify
170
- idParent
171
- addQuantity
172
- defaultQuantity
173
- title
174
- price
175
- unitPrice
176
- totalResource
177
- unitGift
178
- giftDuration
179
- giftDurationUnit
180
- }
141
+ name
142
+ quantity
143
+ unit
144
+ productId
145
+ giftProductId
146
+ gift
147
+ giftQuantity
148
+ campaignId
149
+ campaignActionId
150
+ qualify
151
+ idParent
152
+ addQuantity
153
+ defaultQuantity
154
+ title
155
+ price
156
+ unitPrice
157
+ totalResource
158
+ }
159
+ resourceItems {
160
+ name
161
+ quantity
162
+ unit
163
+ productId
164
+ giftProductId
165
+ gift
166
+ giftQuantity
167
+ campaignId
168
+ campaignActionId
169
+ qualify
170
+ idParent
171
+ addQuantity
172
+ defaultQuantity
173
+ title
174
+ price
175
+ unitPrice
176
+ totalResource
177
+ unitGift
178
+ giftDuration
179
+ giftDurationUnit
180
+ }
181
181
  itemType
182
182
  }
183
183
  serviceId
@@ -434,3 +434,27 @@ exports.FIND_ORDER_BY_OWNER_PARTYID = (0, graphql_tag_1.gql) `
434
434
  findOrderByOwnerPartyId(partnerId: $partnerId, ownerPartyId: $ownerPartyId)
435
435
  }
436
436
  `;
437
+ const CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC = (fields = []) => {
438
+ const fieldStr = fields.join("\n ");
439
+ const hasFields = fields.length > 0;
440
+ return (0, graphql_tag_1.gql) `
441
+ query CalcExchangePriceExtendResourceDetail(
442
+ $partnerId: String!
443
+ $storeId: String!
444
+ $serviceId: String!
445
+ $productBaseIdNew: String!
446
+ $durationQuantity: BigDecimal!
447
+ $durationUnit: String!
448
+ ) {
449
+ calcExchangePriceExtendResourceDetail(
450
+ partnerId: $partnerId
451
+ storeId: $storeId
452
+ serviceId: $serviceId
453
+ productBaseIdNew: $productBaseIdNew
454
+ durationQuantity: $durationQuantity
455
+ durationUnit: $durationUnit
456
+ ) ${hasFields ? `{ ${fieldStr} }` : ""}
457
+ }
458
+ `;
459
+ };
460
+ exports.CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC = CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC;
@@ -24,3 +24,4 @@ export declare const GET_TAGS: DocumentNode;
24
24
  export declare const GET_TAGS_BY_CATEGORY: DocumentNode;
25
25
  export declare const GET_LIST_PRODUCTS_CONFIG_DYNAMIC: (fields?: string[]) => DocumentNode;
26
26
  export declare const GET_CATEGORIES: DocumentNode;
27
+ export declare const GET_PRICE_MENUS: DocumentNode;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GET_CATEGORIES = 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_QUERY_DYNAMIC = 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_PRICE_MENUS = exports.GET_CATEGORIES = 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_QUERY_DYNAMIC = 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(
@@ -1058,3 +1058,48 @@ exports.GET_CATEGORIES = (0, graphql_tag_1.gql) `
1058
1058
  }
1059
1059
  }
1060
1060
  `;
1061
+ exports.GET_PRICE_MENUS = (0, graphql_tag_1.gql) `
1062
+ query GetPriceMenus(
1063
+ $partnerId: String!
1064
+ $storeId: String!
1065
+ $categoryId: String!
1066
+ ) {
1067
+ getPriceMenus(
1068
+ partnerId: $partnerId
1069
+ storeId: $storeId
1070
+ categoryId: $categoryId
1071
+ ) {
1072
+ name
1073
+ products {
1074
+ id
1075
+ title
1076
+ subType
1077
+ sku
1078
+ shortDescription
1079
+ vat
1080
+ unitDTO {
1081
+ id
1082
+ name
1083
+ }
1084
+ qualify
1085
+ handle
1086
+ price
1087
+ displayPrice
1088
+ hint
1089
+ compareAtPrices
1090
+ priceUnit
1091
+ priceQuantity
1092
+ priceType
1093
+ salePolicy
1094
+ priceTypeName
1095
+ priceVaries
1096
+ available
1097
+ tags
1098
+ compareAtPrice
1099
+ featuredImage
1100
+ version
1101
+ images
1102
+ }
1103
+ }
1104
+ }
1105
+ `;
@@ -13,4 +13,5 @@ export declare class OrderGraphQLService extends Service {
13
13
  addToCart(serviceId: string, actorId: string, cartId: string): Promise<any>;
14
14
  removeProductOptionOrderLineItem(orderLineItemId: string, optionId: string, updateBy: string): Promise<any>;
15
15
  findOrderByOwnerPartyId(ownerPartyId: string): Promise<any>;
16
+ calcExchangePriceExtendResourceDetail(serviceId: string, productBaseIdNew: string, durationQuantity: string, durationUnit: string, fields: string[]): Promise<any>;
16
17
  }
@@ -188,5 +188,26 @@ class OrderGraphQLService extends serviceSDK_1.Service {
188
188
  }
189
189
  });
190
190
  }
191
+ calcExchangePriceExtendResourceDetail(serviceId, productBaseIdNew, durationQuantity, durationUnit, fields) {
192
+ return __awaiter(this, void 0, void 0, function* () {
193
+ const query = (0, queries_1.CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC)(fields);
194
+ const variables = {
195
+ partnerId: this.orgId,
196
+ storeId: this.storeId,
197
+ serviceId,
198
+ productBaseIdNew,
199
+ durationQuantity,
200
+ durationUnit,
201
+ };
202
+ try {
203
+ const response = yield this.graphqlQueryV2(query, variables);
204
+ return response.calcExchangePriceExtendResourceDetail;
205
+ }
206
+ catch (error) {
207
+ console.log(`Error in calcExchangePriceExtendResourceDetail: ${error}`);
208
+ throw error;
209
+ }
210
+ });
211
+ }
191
212
  }
192
213
  exports.OrderGraphQLService = OrderGraphQLService;
@@ -51,4 +51,5 @@ export declare class ProductService extends Service {
51
51
  getTagsByCategory(categoryId: string, storeId: string): Promise<any>;
52
52
  getListProductConfigDynamic(productId: string, store: string, fields: string[]): Promise<any>;
53
53
  getCategories(): Promise<any>;
54
+ getPriceMenus(categoryId: string, store: string): Promise<any>;
54
55
  }
@@ -369,5 +369,23 @@ class ProductService extends serviceSDK_1.Service {
369
369
  }
370
370
  });
371
371
  }
372
+ getPriceMenus(categoryId, store) {
373
+ return __awaiter(this, void 0, void 0, function* () {
374
+ const query = queries_1.GET_PRICE_MENUS;
375
+ const variables = {
376
+ partnerId: this.orgId,
377
+ storeId: store ? store : this.storeId,
378
+ categoryId,
379
+ };
380
+ try {
381
+ const response = yield this.graphqlQuery(query, variables);
382
+ return response.getPriceMenus;
383
+ }
384
+ catch (error) {
385
+ console.log(`Error fetching getPriceMenus by ID: ${error}`);
386
+ throw error;
387
+ }
388
+ });
389
+ }
372
390
  }
373
391
  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.20.5",
3
+ "version": "1.20.7",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "files": [