@longvansoftware/service-js-client 2.2.5 → 2.2.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.
@@ -1,6 +1,7 @@
1
1
  import { DocumentNode } from "graphql";
2
2
  export declare const GET_PRODUCT_BY_ID_QUERY: DocumentNode;
3
3
  export declare const GET_PRODUCT_BY_ID_QUERY_DYNAMIC: (fields?: string[]) => DocumentNode;
4
+ export declare const GET_SIMPLE_PRODUCT_BY_ID_QUERY_DYNAMIC: (fields?: string[]) => DocumentNode;
4
5
  export declare const GET_PRODUCT_BY_SLUG_QUERY: DocumentNode;
5
6
  export declare const GET_SIMPLE_PRODUCTS_QUERY: DocumentNode;
6
7
  export declare const GET_CATEGORIES_QUERY: DocumentNode;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GET_PRODUCT_RELATED_TO_ARTICLE = exports.GET_SIMPLE_PRODUCTS_DYNAMIC = 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;
3
+ exports.GET_PRODUCT_RELATED_TO_ARTICLE = exports.GET_SIMPLE_PRODUCTS_DYNAMIC = 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_SIMPLE_PRODUCT_BY_ID_QUERY_DYNAMIC = 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(
@@ -210,6 +210,24 @@ const GET_PRODUCT_BY_ID_QUERY_DYNAMIC = (fields = []) => {
210
210
  `;
211
211
  };
212
212
  exports.GET_PRODUCT_BY_ID_QUERY_DYNAMIC = GET_PRODUCT_BY_ID_QUERY_DYNAMIC;
213
+ const GET_SIMPLE_PRODUCT_BY_ID_QUERY_DYNAMIC = (fields = []) => {
214
+ const fieldStr = fields.join("\n ");
215
+ const hasFields = fields.length > 0;
216
+ return (0, graphql_tag_1.gql) `
217
+ query GetSimpleProductById(
218
+ $partnerId: String!
219
+ $storeChannel: String!
220
+ $productId: String!
221
+ ) {
222
+ getSimpleProductById(
223
+ partnerId: $partnerId
224
+ storeChannel: $storeChannel
225
+ productId: $productId
226
+ ) ${hasFields ? `{ ${fieldStr} }` : ""}
227
+ }
228
+ `;
229
+ };
230
+ exports.GET_SIMPLE_PRODUCT_BY_ID_QUERY_DYNAMIC = GET_SIMPLE_PRODUCT_BY_ID_QUERY_DYNAMIC;
213
231
  exports.GET_PRODUCT_BY_SLUG_QUERY = (0, graphql_tag_1.gql) `
214
232
  query GetProductByHandle(
215
233
  $partnerId: String!
@@ -1115,10 +1133,9 @@ const GET_SIMPLE_PRODUCTS_DYNAMIC = (fields = []) => {
1115
1133
  const fieldStr = fields.join("\n ");
1116
1134
  const hasFields = fields.length > 0;
1117
1135
  return (0, graphql_tag_1.gql) `
1118
- query getSimpleProducts(
1136
+ query GetSimpleProducts(
1119
1137
  $partnerId: String!
1120
1138
  $storeChannel: String!
1121
- $hash: String
1122
1139
  $category: String
1123
1140
  $product: String
1124
1141
  $sku: String
@@ -1143,7 +1160,6 @@ const GET_SIMPLE_PRODUCTS_DYNAMIC = (fields = []) => {
1143
1160
  getSimpleProducts(
1144
1161
  partnerId: $partnerId
1145
1162
  storeChannel: $storeChannel
1146
- hash: $hash
1147
1163
  category: $category
1148
1164
  product: $product
1149
1165
  sku: $sku
@@ -22,6 +22,7 @@ export declare class ProductService extends Service {
22
22
  */
23
23
  getProductById(productId: string, store: string): Promise<any>;
24
24
  getProductByIdDynamic(productId: string, store: string, fields: string[]): Promise<any>;
25
+ getSimpleProductByIdDynamic(productId: string, store: string, fields: string[]): Promise<any>;
25
26
  /**
26
27
  * Retrieves a product by its slug.
27
28
  * @param slug - The slug of the product.
@@ -70,6 +70,24 @@ class ProductService extends serviceSDK_1.Service {
70
70
  }
71
71
  });
72
72
  }
73
+ getSimpleProductByIdDynamic(productId, store, fields) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const query = (0, queries_1.GET_SIMPLE_PRODUCT_BY_ID_QUERY_DYNAMIC)(fields);
76
+ const variables = {
77
+ partnerId: this.orgId,
78
+ storeChannel: store ? store : this.storeId,
79
+ productId,
80
+ };
81
+ try {
82
+ const response = yield this.graphqlQuery(query, variables);
83
+ return response.getSimpleProductById;
84
+ }
85
+ catch (error) {
86
+ console.log(`Error fetching simple product by ID: ${error}`);
87
+ throw error;
88
+ }
89
+ });
90
+ }
73
91
  /**
74
92
  * Retrieves a product by its slug.
75
93
  * @param slug - The slug of the product.
@@ -166,7 +184,9 @@ class ProductService extends serviceSDK_1.Service {
166
184
  getProductsDynamic(param, store, fields) {
167
185
  return __awaiter(this, void 0, void 0, function* () {
168
186
  const query = (0, queries_1.GET_PRODUCTS_DYNAMIC)(fields);
187
+ console.log("Variables getProductsDynamic", param);
169
188
  const variablesHandle = Object.assign({ partnerId: this.orgId, storeChannel: store ? store : this.storeId }, param);
189
+ console.log("variablesHandle getProductsDynamic", variablesHandle);
170
190
  try {
171
191
  const response = yield this.graphqlQueryV2(query, variablesHandle);
172
192
  return response.getProducts;
@@ -491,7 +491,7 @@ class StorageS3Service extends serviceSDK_1.Service {
491
491
  }
492
492
  addCorsBucket(s3UserId, bucketId, allowedMethods, allowedOrigins, allowedHeaders, exposeHeaders, maxAgeSeconds, updateBy, fields) {
493
493
  return __awaiter(this, void 0, void 0, function* () {
494
- const query = (0, mutations_1.ADD_CORS_BUCKET)(fields);
494
+ const mutation = (0, mutations_1.ADD_CORS_BUCKET)(fields);
495
495
  const variables = {
496
496
  s3UserId,
497
497
  bucketId,
@@ -503,7 +503,7 @@ class StorageS3Service extends serviceSDK_1.Service {
503
503
  updateBy,
504
504
  };
505
505
  try {
506
- const response = yield this.graphqlQueryV2(query, variables);
506
+ const response = yield this.graphqlMutationV2(mutation, variables);
507
507
  return response.addCorsBucket;
508
508
  }
509
509
  catch (error) {
@@ -514,7 +514,7 @@ class StorageS3Service extends serviceSDK_1.Service {
514
514
  }
515
515
  updateCorsBucket(s3UserId, bucketId, corsId, allowedMethods, allowedOrigins, allowedHeaders, exposeHeaders, maxAgeSeconds, updateBy, fields) {
516
516
  return __awaiter(this, void 0, void 0, function* () {
517
- const query = (0, mutations_1.UPDATE_CORS_BUCKET)(fields);
517
+ const mutation = (0, mutations_1.UPDATE_CORS_BUCKET)(fields);
518
518
  const variables = {
519
519
  s3UserId,
520
520
  bucketId,
@@ -527,7 +527,7 @@ class StorageS3Service extends serviceSDK_1.Service {
527
527
  updateBy,
528
528
  };
529
529
  try {
530
- const response = yield this.graphqlQueryV2(query, variables);
530
+ const response = yield this.graphqlMutationV2(mutation, variables);
531
531
  return response.updateCorsBucket;
532
532
  }
533
533
  catch (error) {
@@ -538,14 +538,14 @@ class StorageS3Service extends serviceSDK_1.Service {
538
538
  }
539
539
  removeCorsBucket(bucketId, corsId, updateBy, fields) {
540
540
  return __awaiter(this, void 0, void 0, function* () {
541
- const query = (0, mutations_1.REMOVE_CORS_BUCKET)(fields);
541
+ const mutation = (0, mutations_1.REMOVE_CORS_BUCKET)(fields);
542
542
  const variables = {
543
543
  bucketId,
544
544
  corsId,
545
545
  updateBy,
546
546
  };
547
547
  try {
548
- const response = yield this.graphqlQueryV2(query, variables);
548
+ const response = yield this.graphqlMutationV2(mutation, variables);
549
549
  return response.removeCorsBucket;
550
550
  }
551
551
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longvansoftware/service-js-client",
3
- "version": "2.2.5",
3
+ "version": "2.2.7",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "files": [
@@ -1,14 +0,0 @@
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
- }
@@ -1,101 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export declare function buildFieldString(fields: (string | Record<string, any>)[], indent?: number): string;
@@ -1,16 +0,0 @@
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;