@longvansoftware/service-js-client 2.2.7 → 2.2.9
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.
- package/dist/src/graphql/cloud/mutations.d.ts +1 -0
- package/dist/src/graphql/cloud/mutations.js +17 -1
- package/dist/src/graphql/orderGraphQL/queries.d.ts +1 -0
- package/dist/src/graphql/orderGraphQL/queries.js +11 -1
- package/dist/src/graphql/product/queries.d.ts +1 -0
- package/dist/src/graphql/product/queries.js +25 -3
- package/dist/src/lib/cloud/index.d.ts +1 -0
- package/dist/src/lib/cloud/index.js +19 -0
- package/dist/src/lib/orderGraphQL/index.d.ts +1 -0
- package/dist/src/lib/orderGraphQL/index.js +20 -0
- package/dist/src/lib/product/index.d.ts +1 -0
- package/dist/src/lib/product/index.js +18 -2
- package/dist/src/lib/service.d.ts +14 -0
- package/dist/src/lib/service.js +101 -0
- package/dist/src/utils/build-field-string.d.ts +1 -0
- package/dist/src/utils/build-field-string.js +16 -0
- package/package.json +1 -1
|
@@ -21,3 +21,4 @@ export declare const UPDATE_SERVICE_READY_DEPLOY: DocumentNode;
|
|
|
21
21
|
export declare const UPDATE_URL_PUBLIC: DocumentNode;
|
|
22
22
|
export declare const CHECK_ENTERPRISE_BY_TAX_CODE_DYNAMIC: (fields?: string[]) => DocumentNode;
|
|
23
23
|
export declare const CHECK_BUSINESS_BY_TAX_CODE_DYNAMIC: (fields?: string[]) => DocumentNode;
|
|
24
|
+
export declare const CONVERT_PRODUCT_RESOURCE_OUTPUTS_TO_PRODUCT_JSON_LIST: (fields?: string[]) => DocumentNode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CHECK_BUSINESS_BY_TAX_CODE_DYNAMIC = exports.CHECK_ENTERPRISE_BY_TAX_CODE_DYNAMIC = exports.UPDATE_URL_PUBLIC = exports.UPDATE_SERVICE_READY_DEPLOY = exports.UPDATE_SERVICE_NEW = exports.UPDATE_SERVICE_COMPLETED = exports.UPDATE_ACTION_CUSTOM_ATTRIBUTE = exports.UPDATE_ACTION_STATUS = exports.CREATE_ACTION_CHANGE_IP_OF_SERVICE = exports.GET_ORDER_CHANGE_RESOURCE_TERM = exports.CREATE_DOMAIN_CONTACT = exports.UPDATE_DNS = exports.UPDATE_USER_PASSWORD = exports.UPDATE_PASSWORD = exports.UPDATE_USER_NAME = exports.UPDATE_DOMAIN_NAME = exports.DELETE_USER_MAIL_HOSTING = exports.CREATE_USER_MAIL_HOSTING = exports.CHANGE_SERVICE_NAME = exports.CHECK_DOMAIN_NAME = exports.CHECK_LIST_DOMAIN_NAME = exports.GET_DOMAIN_INFO = void 0;
|
|
3
|
+
exports.CONVERT_PRODUCT_RESOURCE_OUTPUTS_TO_PRODUCT_JSON_LIST = exports.CHECK_BUSINESS_BY_TAX_CODE_DYNAMIC = exports.CHECK_ENTERPRISE_BY_TAX_CODE_DYNAMIC = exports.UPDATE_URL_PUBLIC = exports.UPDATE_SERVICE_READY_DEPLOY = exports.UPDATE_SERVICE_NEW = exports.UPDATE_SERVICE_COMPLETED = exports.UPDATE_ACTION_CUSTOM_ATTRIBUTE = exports.UPDATE_ACTION_STATUS = exports.CREATE_ACTION_CHANGE_IP_OF_SERVICE = exports.GET_ORDER_CHANGE_RESOURCE_TERM = exports.CREATE_DOMAIN_CONTACT = exports.UPDATE_DNS = exports.UPDATE_USER_PASSWORD = exports.UPDATE_PASSWORD = exports.UPDATE_USER_NAME = exports.UPDATE_DOMAIN_NAME = exports.DELETE_USER_MAIL_HOSTING = exports.CREATE_USER_MAIL_HOSTING = exports.CHANGE_SERVICE_NAME = exports.CHECK_DOMAIN_NAME = exports.CHECK_LIST_DOMAIN_NAME = exports.GET_DOMAIN_INFO = void 0;
|
|
4
4
|
const graphql_tag_1 = require("graphql-tag");
|
|
5
5
|
exports.GET_DOMAIN_INFO = (0, graphql_tag_1.gql) `
|
|
6
6
|
mutation GetDomainInfo($domainName: String!) {
|
|
@@ -358,3 +358,19 @@ const CHECK_BUSINESS_BY_TAX_CODE_DYNAMIC = (fields = []) => {
|
|
|
358
358
|
`;
|
|
359
359
|
};
|
|
360
360
|
exports.CHECK_BUSINESS_BY_TAX_CODE_DYNAMIC = CHECK_BUSINESS_BY_TAX_CODE_DYNAMIC;
|
|
361
|
+
const CONVERT_PRODUCT_RESOURCE_OUTPUTS_TO_PRODUCT_JSON_LIST = (fields = []) => {
|
|
362
|
+
const fieldStr = fields.join("\n ");
|
|
363
|
+
const hasFields = fields.length > 0;
|
|
364
|
+
return (0, graphql_tag_1.gql) `
|
|
365
|
+
mutation convertProductResourceOutputsToProductJsonList(
|
|
366
|
+
$productResourceInput: ProductResourceInput!
|
|
367
|
+
) {
|
|
368
|
+
convertProductResourceOutputsToProductJsonList(
|
|
369
|
+
productResourceInput: $productResourceInput
|
|
370
|
+
) {
|
|
371
|
+
${hasFields ? `${fieldStr}` : ""}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
`;
|
|
375
|
+
};
|
|
376
|
+
exports.CONVERT_PRODUCT_RESOURCE_OUTPUTS_TO_PRODUCT_JSON_LIST = CONVERT_PRODUCT_RESOURCE_OUTPUTS_TO_PRODUCT_JSON_LIST;
|
|
@@ -7,3 +7,4 @@ export declare const GET_ORDER_BY_SERVICE_ID: DocumentNode;
|
|
|
7
7
|
export declare const FIND_ORDER_BY_OWNER_PARTYID: DocumentNode;
|
|
8
8
|
export declare const CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC: (fields?: string[]) => DocumentNode;
|
|
9
9
|
export declare const SEARCH_ORDER_DYNAMIC: (fields?: string[]) => DocumentNode;
|
|
10
|
+
export declare const CALCULATE_RESOURCE_CHANGE_PRICE: (fields?: string[]) => DocumentNode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SEARCH_ORDER_DYNAMIC = 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;
|
|
3
|
+
exports.CALCULATE_RESOURCE_CHANGE_PRICE = exports.SEARCH_ORDER_DYNAMIC = 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!) {
|
|
@@ -468,3 +468,13 @@ const SEARCH_ORDER_DYNAMIC = (fields = []) => {
|
|
|
468
468
|
`;
|
|
469
469
|
};
|
|
470
470
|
exports.SEARCH_ORDER_DYNAMIC = SEARCH_ORDER_DYNAMIC;
|
|
471
|
+
const CALCULATE_RESOURCE_CHANGE_PRICE = (fields = []) => {
|
|
472
|
+
const fieldStr = fields.join("\n ");
|
|
473
|
+
const hasFields = fields.length > 0;
|
|
474
|
+
return (0, graphql_tag_1.gql) `
|
|
475
|
+
query calculateResourceChangePrice($partnerId: String! $storeId: String! $productIds: [String] $quantity: BigDecimal! $unit: String!) {
|
|
476
|
+
calculateResourceChangePrice(partnerId: $partnerId storeId: $storeId productIds: $productIds quantity: $quantity unit: $unit) ${hasFields ? `{ ${fieldStr} }` : ""}
|
|
477
|
+
}
|
|
478
|
+
`;
|
|
479
|
+
};
|
|
480
|
+
exports.CALCULATE_RESOURCE_CHANGE_PRICE = CALCULATE_RESOURCE_CHANGE_PRICE;
|
|
@@ -28,3 +28,4 @@ export declare const GET_CATEGORIES: DocumentNode;
|
|
|
28
28
|
export declare const GET_PRICE_MENUS: DocumentNode;
|
|
29
29
|
export declare const GET_SIMPLE_PRODUCTS_DYNAMIC: (fields?: string[]) => DocumentNode;
|
|
30
30
|
export declare const GET_PRODUCT_RELATED_TO_ARTICLE: (fields?: string[]) => DocumentNode;
|
|
31
|
+
export declare const GET_PRODUCTS_FEATURE_TYPE_DYNAMIC: (fields?: string[]) => 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_SIMPLE_PRODUCT_BY_ID_QUERY_DYNAMIC = exports.GET_PRODUCT_BY_ID_QUERY_DYNAMIC = exports.GET_PRODUCT_BY_ID_QUERY = void 0;
|
|
3
|
+
exports.GET_PRODUCTS_FEATURE_TYPE_DYNAMIC = 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(
|
|
@@ -308,7 +308,7 @@ exports.GET_SIMPLE_PRODUCTS_QUERY = (0, graphql_tag_1.gql) `
|
|
|
308
308
|
query getSimpleProducts(
|
|
309
309
|
$partnerId: String!
|
|
310
310
|
$storeChannel: String!
|
|
311
|
-
$
|
|
311
|
+
$group: String
|
|
312
312
|
$category: String
|
|
313
313
|
$product: String
|
|
314
314
|
$sku: String
|
|
@@ -333,7 +333,7 @@ exports.GET_SIMPLE_PRODUCTS_QUERY = (0, graphql_tag_1.gql) `
|
|
|
333
333
|
getSimpleProducts(
|
|
334
334
|
partnerId: $partnerId
|
|
335
335
|
storeChannel: $storeChannel
|
|
336
|
-
|
|
336
|
+
group: $group
|
|
337
337
|
category: $category
|
|
338
338
|
product: $product
|
|
339
339
|
sku: $sku
|
|
@@ -1136,6 +1136,7 @@ const GET_SIMPLE_PRODUCTS_DYNAMIC = (fields = []) => {
|
|
|
1136
1136
|
query GetSimpleProducts(
|
|
1137
1137
|
$partnerId: String!
|
|
1138
1138
|
$storeChannel: String!
|
|
1139
|
+
$group: String
|
|
1139
1140
|
$category: String
|
|
1140
1141
|
$product: String
|
|
1141
1142
|
$sku: String
|
|
@@ -1160,6 +1161,7 @@ const GET_SIMPLE_PRODUCTS_DYNAMIC = (fields = []) => {
|
|
|
1160
1161
|
getSimpleProducts(
|
|
1161
1162
|
partnerId: $partnerId
|
|
1162
1163
|
storeChannel: $storeChannel
|
|
1164
|
+
group: $group
|
|
1163
1165
|
category: $category
|
|
1164
1166
|
product: $product
|
|
1165
1167
|
sku: $sku
|
|
@@ -1213,3 +1215,23 @@ const GET_PRODUCT_RELATED_TO_ARTICLE = (fields = []) => {
|
|
|
1213
1215
|
`;
|
|
1214
1216
|
};
|
|
1215
1217
|
exports.GET_PRODUCT_RELATED_TO_ARTICLE = GET_PRODUCT_RELATED_TO_ARTICLE;
|
|
1218
|
+
const GET_PRODUCTS_FEATURE_TYPE_DYNAMIC = (fields = []) => {
|
|
1219
|
+
const fieldStr = fields.join("\n ");
|
|
1220
|
+
const hasFields = fields.length > 0;
|
|
1221
|
+
return (0, graphql_tag_1.gql) `
|
|
1222
|
+
query getProductFeatureTypes(
|
|
1223
|
+
$partnerId: String!
|
|
1224
|
+
$storeChannel: String!
|
|
1225
|
+
$productId: String!
|
|
1226
|
+
) {
|
|
1227
|
+
getProductFeatureTypes(
|
|
1228
|
+
partnerId: $partnerId
|
|
1229
|
+
storeChannel: $storeChannel
|
|
1230
|
+
productId: $productId
|
|
1231
|
+
) {
|
|
1232
|
+
${hasFields ? `${fieldStr}` : ""}
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
`;
|
|
1236
|
+
};
|
|
1237
|
+
exports.GET_PRODUCTS_FEATURE_TYPE_DYNAMIC = GET_PRODUCTS_FEATURE_TYPE_DYNAMIC;
|
|
@@ -53,4 +53,5 @@ export declare class CloudService extends Service {
|
|
|
53
53
|
updateActionCustomAttribute(actionId: string, attrName: string, attrValue: string, byUser: string): Promise<any>;
|
|
54
54
|
getElasticCloudResource(serviceId: string): Promise<any>;
|
|
55
55
|
searchServiceDynamic(filter: Filter, fields: string[]): Promise<any>;
|
|
56
|
+
convertProductResourceOutputsToProductJsonList(productResourceInput: any, fields: string[]): Promise<any>;
|
|
56
57
|
}
|
|
@@ -766,5 +766,24 @@ class CloudService extends serviceSDK_1.Service {
|
|
|
766
766
|
}
|
|
767
767
|
});
|
|
768
768
|
}
|
|
769
|
+
convertProductResourceOutputsToProductJsonList(productResourceInput, fields) {
|
|
770
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
771
|
+
const query = (0, mutations_1.CONVERT_PRODUCT_RESOURCE_OUTPUTS_TO_PRODUCT_JSON_LIST)(fields);
|
|
772
|
+
const variables = {
|
|
773
|
+
productResourceInput: {
|
|
774
|
+
productId: productResourceInput === null || productResourceInput === void 0 ? void 0 : productResourceInput.productId,
|
|
775
|
+
resources: productResourceInput === null || productResourceInput === void 0 ? void 0 : productResourceInput.resources,
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
try {
|
|
779
|
+
const response = yield this.graphqlQueryV2(query, variables);
|
|
780
|
+
return response.convertProductResourceOutputsToProductJsonList;
|
|
781
|
+
}
|
|
782
|
+
catch (error) {
|
|
783
|
+
console.log(`Error in convertProductResourceOutputsToProductJsonList: ${error}`);
|
|
784
|
+
throw error;
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
}
|
|
769
788
|
}
|
|
770
789
|
exports.CloudService = CloudService;
|
|
@@ -18,4 +18,5 @@ export declare class OrderGraphQLService extends Service {
|
|
|
18
18
|
addItemIntoOrderByProductJsonResource(serviceId: string, orderId: string, itemInput: any, durationQuantity: number, durationUnit: string, actorId: string, fields: string[]): Promise<any>;
|
|
19
19
|
updateOrderLineItemParentId(orderLineItemChildIds: string[], orderLineItemParentId: string, updateBy: string): Promise<any>;
|
|
20
20
|
updateProductOptionOrderLineItem(orderLineItemId: string, productOptionUpdate: any, updateBy: string): Promise<any>;
|
|
21
|
+
calculateResourceChangePrice(productIds: string[], quantity: string, unit: string, storeId: string, fields: string[]): Promise<any>;
|
|
21
22
|
}
|
|
@@ -285,5 +285,25 @@ class OrderGraphQLService extends serviceSDK_1.Service {
|
|
|
285
285
|
}
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
|
+
calculateResourceChangePrice(productIds, quantity, unit, storeId, fields) {
|
|
289
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
+
const query = (0, queries_1.CALCULATE_RESOURCE_CHANGE_PRICE)(fields);
|
|
291
|
+
const variables = {
|
|
292
|
+
partnerId: this.orgId,
|
|
293
|
+
storeId: storeId ? storeId : this.storeId,
|
|
294
|
+
productIds,
|
|
295
|
+
quantity,
|
|
296
|
+
unit
|
|
297
|
+
};
|
|
298
|
+
try {
|
|
299
|
+
const response = yield this.graphqlQueryV2(query, variables);
|
|
300
|
+
return response.calculateResourceChangePrice;
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
console.log(`Error in calculateResourceChangePrice: ${error}`);
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
288
308
|
}
|
|
289
309
|
exports.OrderGraphQLService = OrderGraphQLService;
|
|
@@ -55,4 +55,5 @@ export declare class ProductService extends Service {
|
|
|
55
55
|
getPriceMenus(categoryId: string, store: string): Promise<any>;
|
|
56
56
|
getSimpleProductsDynamic(variables: any, storeId: string, fields: string[]): Promise<any>;
|
|
57
57
|
getProductRelatedToArticle(articleId: string, storeId: string, fields: string[]): Promise<any>;
|
|
58
|
+
getProductFeatureTypesDynamic(productId: string, storeId: string, fields: string[]): Promise<any>;
|
|
58
59
|
}
|
|
@@ -184,9 +184,7 @@ class ProductService extends serviceSDK_1.Service {
|
|
|
184
184
|
getProductsDynamic(param, store, fields) {
|
|
185
185
|
return __awaiter(this, void 0, void 0, function* () {
|
|
186
186
|
const query = (0, queries_1.GET_PRODUCTS_DYNAMIC)(fields);
|
|
187
|
-
console.log("Variables getProductsDynamic", param);
|
|
188
187
|
const variablesHandle = Object.assign({ partnerId: this.orgId, storeChannel: store ? store : this.storeId }, param);
|
|
189
|
-
console.log("variablesHandle getProductsDynamic", variablesHandle);
|
|
190
188
|
try {
|
|
191
189
|
const response = yield this.graphqlQueryV2(query, variablesHandle);
|
|
192
190
|
return response.getProducts;
|
|
@@ -439,5 +437,23 @@ class ProductService extends serviceSDK_1.Service {
|
|
|
439
437
|
}
|
|
440
438
|
});
|
|
441
439
|
}
|
|
440
|
+
getProductFeatureTypesDynamic(productId, storeId, fields) {
|
|
441
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
442
|
+
const query = (0, queries_1.GET_PRODUCTS_FEATURE_TYPE_DYNAMIC)(fields);
|
|
443
|
+
const variablesHandle = {
|
|
444
|
+
partnerId: this.orgId,
|
|
445
|
+
storeChannel: storeId ? storeId : this.storeId,
|
|
446
|
+
productId: productId,
|
|
447
|
+
};
|
|
448
|
+
try {
|
|
449
|
+
const response = yield this.graphqlQuery(query, variablesHandle);
|
|
450
|
+
return response.getProductFeatureTypes;
|
|
451
|
+
}
|
|
452
|
+
catch (error) {
|
|
453
|
+
console.log(`Error fetching getProductFeatureTypes: ${error}`);
|
|
454
|
+
throw error;
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
}
|
|
442
458
|
}
|
|
443
459
|
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;
|