@longvansoftware/service-js-client 2.8.3 → 2.8.5

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.
Files changed (64) hide show
  1. package/dist/config/config.d.ts +4 -0
  2. package/dist/config/config.js +6 -2
  3. package/dist/src/graphql/campaign/queries.d.ts +13 -11
  4. package/dist/src/graphql/campaign/queries.js +39 -111
  5. package/dist/src/graphql/cloudCloud/mutations.d.ts +2 -0
  6. package/dist/src/graphql/cloudCloud/mutations.js +101 -27
  7. package/dist/src/graphql/cloudCloud/queries.js +4 -0
  8. package/dist/src/graphql/crm/queries.d.ts +1 -0
  9. package/dist/src/graphql/crm/queries.js +18 -1
  10. package/dist/src/graphql/marketplace/mutations.d.ts +0 -0
  11. package/dist/src/graphql/marketplace/mutations.js +1 -0
  12. package/dist/src/graphql/marketplace/queries.d.ts +2 -0
  13. package/dist/src/graphql/marketplace/queries.js +24 -0
  14. package/dist/src/graphql/orderCloud/mutations.d.ts +3 -1
  15. package/dist/src/graphql/orderCloud/mutations.js +21 -5
  16. package/dist/src/graphql/orderGraphQL/mutations.d.ts +1 -0
  17. package/dist/src/graphql/orderGraphQL/mutations.js +18 -1
  18. package/dist/src/graphql/paymentV2/mutations.d.ts +1 -0
  19. package/dist/src/graphql/paymentV2/mutations.js +23 -37
  20. package/dist/src/graphql/paymentV2/queries.d.ts +2 -0
  21. package/dist/src/graphql/paymentV2/queries.js +58 -1
  22. package/dist/src/graphql/storefont/mutation.d.ts +2 -0
  23. package/dist/src/graphql/storefont/mutation.js +28 -0
  24. package/dist/src/graphql/storefont/queries.d.ts +5 -0
  25. package/dist/src/graphql/storefont/queries.js +99 -0
  26. package/dist/src/graphql/storefront/mutation.d.ts +2 -0
  27. package/dist/src/graphql/storefront/mutation.js +28 -0
  28. package/dist/src/graphql/tag/mutations.d.ts +2 -0
  29. package/dist/src/graphql/tag/mutations.js +44 -0
  30. package/dist/src/graphql/tag/queries.d.ts +1 -0
  31. package/dist/src/graphql/tag/queries.js +20 -0
  32. package/dist/src/lib/SDK.d.ts +6 -0
  33. package/dist/src/lib/SDK.js +9 -4
  34. package/dist/src/lib/campaign/index.d.ts +1 -0
  35. package/dist/src/lib/campaign/index.js +69 -12
  36. package/dist/src/lib/cloudCloud/index.d.ts +1 -0
  37. package/dist/src/lib/cloudCloud/index.js +16 -0
  38. package/dist/src/lib/crm/index.d.ts +1 -0
  39. package/dist/src/lib/crm/index.js +16 -0
  40. package/dist/src/lib/imageGateway/index.d.ts +6 -0
  41. package/dist/src/lib/imageGateway/index.js +18 -0
  42. package/dist/src/lib/marketplace/index.d.ts +13 -0
  43. package/dist/src/lib/marketplace/index.js +50 -0
  44. package/dist/src/lib/orderCloud/index.d.ts +2 -0
  45. package/dist/src/lib/orderCloud/index.js +47 -1
  46. package/dist/src/lib/orderGraphQL/index.d.ts +1 -0
  47. package/dist/src/lib/orderGraphQL/index.js +16 -0
  48. package/dist/src/lib/paymentV2/index.d.ts +11 -1
  49. package/dist/src/lib/paymentV2/index.js +55 -14
  50. package/dist/src/lib/portal/index.d.ts +10 -2
  51. package/dist/src/lib/portal/index.js +171 -11
  52. package/dist/src/lib/storefont/index.d.ts +6 -0
  53. package/dist/src/lib/storefont/index.js +41 -0
  54. package/dist/src/lib/storefront/index.d.ts +7 -0
  55. package/dist/src/lib/storefront/index.js +44 -0
  56. package/dist/src/lib/tag/index.d.ts +7 -0
  57. package/dist/src/lib/tag/index.js +61 -0
  58. package/dist/src/utils/helpers.d.ts +2 -0
  59. package/dist/src/utils/helpers.js +11 -5
  60. package/package.json +1 -1
  61. package/dist/src/lib/service.d.ts +0 -14
  62. package/dist/src/lib/service.js +0 -101
  63. package/dist/src/utils/build-field-string.d.ts +0 -1
  64. package/dist/src/utils/build-field-string.js +0 -16
@@ -77,14 +77,6 @@ class PortalService extends serviceSDK_1.Service {
77
77
  const url = `${this.endpoint}/facility/manager/session/inventory-item-by-product.xhtml?${sku ? `sku=${sku}` : `id=${id}`}&orgId=${this.orgId}`;
78
78
  return url;
79
79
  }
80
- imageProduct(parentId, parentType, width, height) {
81
- const url = `${this.endpoint}/image-gateway/public/image/${parentType}/${parentId}${width ? `?w=${width}` : ``}${`${height ? `&h=${height}` : ``}`} `;
82
- return url;
83
- }
84
- imagesProduct(parentId, parentType, width, height) {
85
- const url = `${this.endpoint}/image-gateway/public/images/${parentType}/${parentId}?w=${width}&h=${height}`;
86
- return url;
87
- }
88
80
  completeOrder(orderId, byUser) {
89
81
  return __awaiter(this, void 0, void 0, function* () {
90
82
  const endpoint = `/fulfillment-api/public/fulfillment/${this.orgId}/${orderId}/complete-fulfillment/${byUser}`;
@@ -157,7 +149,7 @@ class PortalService extends serviceSDK_1.Service {
157
149
  const endpoint = `/fulfillment-api/public/fulfillment/${this.orgId}/packageBoxes`;
158
150
  const method = "GET";
159
151
  try {
160
- const response = yield this.restApiCallWithNoHeader(endpoint, method);
152
+ const response = yield this.restApiCallWithToken(endpoint, method);
161
153
  return response;
162
154
  }
163
155
  catch (error) {
@@ -170,7 +162,7 @@ class PortalService extends serviceSDK_1.Service {
170
162
  const endpoint = `/fulfillment-api/public/fulfillment/${this.orgId}/${orderId}/shipment-parameters`;
171
163
  const method = "GET";
172
164
  try {
173
- const response = yield this.restApiCallWithNoHeader(endpoint, method);
165
+ const response = yield this.restApiCallWithToken(endpoint, method);
174
166
  return response;
175
167
  }
176
168
  catch (error) {
@@ -199,7 +191,7 @@ class PortalService extends serviceSDK_1.Service {
199
191
  const endpoint = `/fulfillment-api/public/fulfillment/${this.orgId}/${orderId}/fulfillment-stage`;
200
192
  const method = "GET";
201
193
  try {
202
- const response = yield this.restApiCallWithNoHeader(endpoint, method);
194
+ const response = yield this.restApiCallWithToken(endpoint, method);
203
195
  return response;
204
196
  }
205
197
  catch (error) {
@@ -452,5 +444,173 @@ class PortalService extends serviceSDK_1.Service {
452
444
  }
453
445
  });
454
446
  }
447
+ getSlugPathFromDynamicFrom(query) {
448
+ return __awaiter(this, void 0, void 0, function* () {
449
+ const method = "GET";
450
+ const baseUrl = `/dynamic-collection/public/v2/records/slug_path/slug_path_view`;
451
+ const params = new URLSearchParams();
452
+ if (query) {
453
+ Object.entries(query).forEach(([key, value]) => {
454
+ if (value !== undefined && value !== null) {
455
+ params.append(key, String(value));
456
+ }
457
+ });
458
+ }
459
+ const endpoint = params.toString()
460
+ ? `${baseUrl}?${params.toString()}`
461
+ : baseUrl;
462
+ try {
463
+ const response = yield this.restApiCallWithNoToken(endpoint, method);
464
+ return response;
465
+ }
466
+ catch (error) {
467
+ throw error;
468
+ }
469
+ });
470
+ }
471
+ putSlugPathFromDynamicFrom(data) {
472
+ return __awaiter(this, void 0, void 0, function* () {
473
+ const method = "PUT";
474
+ const endpoint = `/dynamic-collection/public/v2/records/slug_path/slug_path_form`;
475
+ try {
476
+ const response = yield this.restApiCallWithNoToken(endpoint, method, data);
477
+ return response;
478
+ }
479
+ catch (error) {
480
+ throw error;
481
+ }
482
+ });
483
+ }
484
+ postSlugPathFromDynamicFrom(data) {
485
+ return __awaiter(this, void 0, void 0, function* () {
486
+ const method = "POST";
487
+ const endpoint = `/dynamic-collection/public/v2/records/slug_path/slug_path_form`;
488
+ try {
489
+ const response = yield this.restApiCallWithNoHeader(endpoint, method, data);
490
+ return response;
491
+ }
492
+ catch (error) {
493
+ throw error;
494
+ }
495
+ });
496
+ }
497
+ getExamGroupTimeSlots(query) {
498
+ return __awaiter(this, void 0, void 0, function* () {
499
+ const method = "GET";
500
+ const baseUrl = `/dynamic-collection/public/v2/exam-group/time-slots`;
501
+ const params = new URLSearchParams();
502
+ if (query) {
503
+ Object.entries(query).forEach(([key, value]) => {
504
+ if (value !== undefined && value !== null) {
505
+ params.append(key, String(value));
506
+ }
507
+ });
508
+ }
509
+ const endpoint = params.toString()
510
+ ? `${baseUrl}?${params.toString()}`
511
+ : baseUrl;
512
+ try {
513
+ const response = yield this.restApiCallWithNoToken(endpoint, method);
514
+ return response;
515
+ }
516
+ catch (error) {
517
+ throw error;
518
+ }
519
+ });
520
+ }
521
+ getExamGroupExecutionDates(query) {
522
+ return __awaiter(this, void 0, void 0, function* () {
523
+ const method = "GET";
524
+ const baseUrl = `/dynamic-collection/public/v2/exam-group/execution-dates`;
525
+ const params = new URLSearchParams();
526
+ if (query) {
527
+ Object.entries(query).forEach(([key, value]) => {
528
+ if (value !== undefined && value !== null) {
529
+ params.append(key, String(value));
530
+ }
531
+ });
532
+ }
533
+ const endpoint = params.toString()
534
+ ? `${baseUrl}?${params.toString()}`
535
+ : baseUrl;
536
+ try {
537
+ const response = yield this.restApiCallWithNoToken(endpoint, method);
538
+ return response;
539
+ }
540
+ catch (error) {
541
+ throw error;
542
+ }
543
+ });
544
+ }
545
+ getExamGroupExecutionLocations(query) {
546
+ return __awaiter(this, void 0, void 0, function* () {
547
+ const method = "GET";
548
+ const baseUrl = `/dynamic-collection/public/v2/exam-group/execution-locations`;
549
+ const params = new URLSearchParams();
550
+ if (query) {
551
+ Object.entries(query).forEach(([key, value]) => {
552
+ if (value !== undefined && value !== null) {
553
+ params.append(key, String(value));
554
+ }
555
+ });
556
+ }
557
+ const endpoint = params.toString()
558
+ ? `${baseUrl}?${params.toString()}`
559
+ : baseUrl;
560
+ try {
561
+ const response = yield this.restApiCallWithNoToken(endpoint, method);
562
+ return response;
563
+ }
564
+ catch (error) {
565
+ throw error;
566
+ }
567
+ });
568
+ }
569
+ getEventsActivity(query) {
570
+ return __awaiter(this, void 0, void 0, function* () {
571
+ const method = "GET";
572
+ const baseUrl = `/dynamic-collection/public/v2/event/event-activity`;
573
+ const params = new URLSearchParams();
574
+ if (query) {
575
+ Object.entries(query).forEach(([key, value]) => {
576
+ if (value !== undefined && value !== null) {
577
+ params.append(key, String(value));
578
+ }
579
+ });
580
+ }
581
+ const endpoint = params.toString()
582
+ ? `${baseUrl}?${params.toString()}`
583
+ : baseUrl;
584
+ try {
585
+ const response = yield this.restApiCallWithNoToken(endpoint, method);
586
+ return response;
587
+ }
588
+ catch (error) {
589
+ throw error;
590
+ }
591
+ });
592
+ }
593
+ imageProduct(parentId, parentType, width, height) {
594
+ const url = `${this.endpoint}/image-gateway/public/image/${parentType}/${parentId}${width ? `?w=${width}` : ``}${`${height ? `&h=${height}` : ``}`} `;
595
+ return url;
596
+ }
597
+ imagesProduct(parentId, parentType, width, height) {
598
+ const url = `${this.endpoint}/image-gateway/public/images/${parentType}/${parentId}?w=${width}&h=${height}`;
599
+ return url;
600
+ }
601
+ // API confirmOrder xử lý FFM cho order có mặt hàng có offerType = SUBCRIPTION
602
+ confirmOrderWithoutPaid(partnerId, orderId, createBy) {
603
+ return __awaiter(this, void 0, void 0, function* () {
604
+ const endpoint = `/order-cloud-service/service-webhook/confirm-order-without-paid?partnerId=${partnerId}&orderId=${orderId}&createBy=${createBy}`;
605
+ const method = "GET";
606
+ try {
607
+ const response = yield this.restApiCallWithNoHeader(endpoint, method);
608
+ return response;
609
+ }
610
+ catch (error) {
611
+ throw error;
612
+ }
613
+ });
614
+ }
455
615
  }
456
616
  exports.PortalService = PortalService;
@@ -0,0 +1,6 @@
1
+ import { Service } from "../serviceSDK";
2
+ export declare class StorageS3Service extends Service {
3
+ constructor(endpoint: string, orgId: string, storeId: string);
4
+ setToken(token: string): void;
5
+ mergeOrderCart(oldCartId: string, newCartId: string, actorId: string, isAllowedToMergeItem: boolean, fields?: string[]): Promise<any>;
6
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.StorageS3Service = void 0;
13
+ const mutation_1 = require("../../graphql/storefont/mutation");
14
+ const serviceSDK_1 = require("../serviceSDK");
15
+ class StorageS3Service extends serviceSDK_1.Service {
16
+ constructor(endpoint, orgId, storeId) {
17
+ super(endpoint, orgId, storeId);
18
+ }
19
+ setToken(token) {
20
+ this.token = token;
21
+ }
22
+ mergeOrderCart(oldCartId_1, newCartId_1, actorId_1, isAllowedToMergeItem_1) {
23
+ return __awaiter(this, arguments, void 0, function* (oldCartId, newCartId, actorId, isAllowedToMergeItem, fields = ["success", "movedItemCount", "skippedItemCount", "oldCartCanceled", "message"]) {
24
+ const mutation = (0, mutation_1.MERGE_ORDER_CART)(fields);
25
+ const variables = {
26
+ oldCartId,
27
+ newCartId,
28
+ actorId,
29
+ isAllowedToMergeItem
30
+ };
31
+ try {
32
+ const response = yield this.graphqlMutationV2(mutation, variables);
33
+ return response.mergeOrderCart;
34
+ }
35
+ catch (error) {
36
+ throw error;
37
+ }
38
+ });
39
+ }
40
+ }
41
+ exports.StorageS3Service = StorageS3Service;
@@ -0,0 +1,7 @@
1
+ import { Service } from "../serviceSDK";
2
+ export declare class StorefrontService extends Service {
3
+ constructor(endpoint: string, orgId: string, storeId: string);
4
+ setToken(token: string): void;
5
+ setStoreId(storeId: string): void;
6
+ mergeOrderCart(oldCartId: string, newCartId: string, actorId: string, isAllowedToMergeItem: boolean, fields?: string[]): Promise<any>;
7
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.StorefrontService = void 0;
13
+ const mutation_1 = require("../../graphql/storefront/mutation");
14
+ const serviceSDK_1 = require("../serviceSDK");
15
+ class StorefrontService extends serviceSDK_1.Service {
16
+ constructor(endpoint, orgId, storeId) {
17
+ super(endpoint, orgId, storeId);
18
+ }
19
+ setToken(token) {
20
+ this.token = token;
21
+ }
22
+ setStoreId(storeId) {
23
+ this.storeId = storeId;
24
+ }
25
+ mergeOrderCart(oldCartId_1, newCartId_1, actorId_1, isAllowedToMergeItem_1) {
26
+ return __awaiter(this, arguments, void 0, function* (oldCartId, newCartId, actorId, isAllowedToMergeItem, fields = ["success", "movedItemCount", "skippedItemCount", "oldCartCanceled", "message"]) {
27
+ const mutation = (0, mutation_1.MERGE_ORDER_CART)(fields);
28
+ const variables = {
29
+ oldCartId,
30
+ newCartId,
31
+ actorId,
32
+ isAllowedToMergeItem
33
+ };
34
+ try {
35
+ const response = yield this.graphqlMutationV2(mutation, variables);
36
+ return response.mergeOrderCart;
37
+ }
38
+ catch (error) {
39
+ throw error;
40
+ }
41
+ });
42
+ }
43
+ }
44
+ exports.StorefrontService = StorefrontService;
@@ -0,0 +1,7 @@
1
+ import { Service } from "../serviceSDK";
2
+ export declare class TagService extends Service {
3
+ constructor(endpoint: string, orgId: string, storeId: string);
4
+ addTagToTagGroup(data: any): Promise<any>;
5
+ removeTagToTagGroup(data: any): Promise<any>;
6
+ getResultTag(resourceId: string, resourceType: string): Promise<any>;
7
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TagService = void 0;
13
+ const serviceSDK_1 = require("../serviceSDK");
14
+ const mutations_1 = require("../../graphql/tag/mutations");
15
+ const queries_1 = require("../../graphql/tag/queries");
16
+ class TagService extends serviceSDK_1.Service {
17
+ constructor(endpoint, orgId, storeId) {
18
+ super(endpoint, orgId, storeId);
19
+ }
20
+ addTagToTagGroup(data) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const mutation = mutations_1.ADD_TAG_TO_TAG_GROUP;
23
+ try {
24
+ const response = yield this.graphqlMutation(mutation, data);
25
+ return response.addTagToTagGroup;
26
+ }
27
+ catch (error) {
28
+ throw error;
29
+ }
30
+ });
31
+ }
32
+ removeTagToTagGroup(data) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const mutation = mutations_1.REMOVE_TAG_TO_TAG_GROUP;
35
+ try {
36
+ const response = yield this.graphqlMutation(mutation, data);
37
+ return response.removeTagToTagGroup;
38
+ }
39
+ catch (error) {
40
+ throw error;
41
+ }
42
+ });
43
+ }
44
+ getResultTag(resourceId, resourceType) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const queries = queries_1.GET_RESULT_TAG;
47
+ const variables = {
48
+ resourceId,
49
+ resourceType,
50
+ };
51
+ try {
52
+ const response = yield this.graphqlMutationV3(queries, variables);
53
+ return response.getResultTag;
54
+ }
55
+ catch (error) {
56
+ throw error;
57
+ }
58
+ });
59
+ }
60
+ }
61
+ exports.TagService = TagService;
@@ -2,3 +2,5 @@ import { Endpoints } from "../lib/SDK";
2
2
  export declare function createToken(environment: string): string;
3
3
  export declare function decodeToken(token: string): string | null;
4
4
  export declare function validateStorefrontAccessToken(storefrontAccessToken: string): Endpoints;
5
+ export declare function joinField(fields?: string[]): string;
6
+ export declare function hasFields(fields?: string[]): boolean;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.validateStorefrontAccessToken = exports.decodeToken = exports.createToken = void 0;
6
+ exports.hasFields = exports.joinField = exports.validateStorefrontAccessToken = exports.decodeToken = exports.createToken = void 0;
7
7
  const crypto_js_1 = __importDefault(require("crypto-js"));
8
8
  const config_1 = require("../../config/config");
9
9
  function createToken(environment) {
@@ -29,13 +29,19 @@ function validateStorefrontAccessToken(storefrontAccessToken) {
29
29
  console.log("🚀 ~ environment:", environment);
30
30
  const validEnvironments = {
31
31
  dev: "dev",
32
- live: "live",
32
+ live: "live"
33
33
  };
34
34
  if (!Object.keys(validEnvironments).includes(environment)) {
35
35
  throw new Error("Invalid storefrontAccessToken");
36
36
  }
37
- return environment == "dev"
38
- ? config_1.environmentEndpoints.dev
39
- : config_1.environmentEndpoints.live;
37
+ return environment == "dev" ? config_1.environmentEndpoints.dev : config_1.environmentEndpoints.live;
40
38
  }
41
39
  exports.validateStorefrontAccessToken = validateStorefrontAccessToken;
40
+ function joinField(fields = []) {
41
+ return fields.join("\n ");
42
+ }
43
+ exports.joinField = joinField;
44
+ function hasFields(fields = []) {
45
+ return fields.length > 0;
46
+ }
47
+ exports.hasFields = hasFields;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longvansoftware/service-js-client",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
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;