@phystack/products 4.4.29
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/CHANGELOG.md +2736 -0
- package/dist/api.d.ts +11 -0
- package/dist/api.js +49 -0
- package/dist/helpers.d.ts +2 -0
- package/dist/helpers.js +11 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +29 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +1423 -0
- package/dist/services/grid-product-service-admin.d.ts +23 -0
- package/dist/services/grid-product-service-admin.js +120 -0
- package/dist/services/grid-product-service-client.d.ts +80 -0
- package/dist/services/grid-product-service-client.js +633 -0
- package/dist/services/grid-product-service-interface.d.ts +47 -0
- package/dist/services/grid-product-service-interface.js +2 -0
- package/dist/services/http-service.d.ts +14 -0
- package/dist/services/http-service.js +44 -0
- package/dist/types/grid-product.d.ts +458 -0
- package/dist/types/grid-product.js +38 -0
- package/dist/types/iso-currency-codes.d.ts +182 -0
- package/dist/types/iso-currency-codes.js +186 -0
- package/dist/types/iso-language-ids.d.ts +170 -0
- package/dist/types/iso-language-ids.js +174 -0
- package/dist/types/parameters.d.ts +242 -0
- package/dist/types/parameters.js +99 -0
- package/dist/utils.d.ts +27 -0
- package/dist/utils.js +187 -0
- package/jest.config.js +10 -0
- package/jest.setup.js +1 -0
- package/package.json +31 -0
- package/src/api.ts +47 -0
- package/src/helpers.ts +7 -0
- package/src/index.test.ts +1526 -0
- package/src/index.ts +8 -0
- package/src/services/grid-product-service-admin.ts +123 -0
- package/src/services/grid-product-service-client.ts +995 -0
- package/src/services/grid-product-service-interface.ts +105 -0
- package/src/services/http-service.ts +50 -0
- package/src/types/grid-product.ts +548 -0
- package/src/types/iso-currency-codes.ts +182 -0
- package/src/types/iso-language-ids.ts +170 -0
- package/src/types/parameters.ts +231 -0
- package/src/utils.ts +325 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,633 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.GridProductServiceClient = void 0;
|
|
16
|
+
const http_service_1 = __importDefault(require("./http-service"));
|
|
17
|
+
const parameters_1 = require("../types/parameters");
|
|
18
|
+
const grid_product_1 = require("../types/grid-product");
|
|
19
|
+
const api_1 = require("../api");
|
|
20
|
+
class GridProductServiceClient {
|
|
21
|
+
constructor({ tenantId, environment, dataResidency, locale, fallbackLocale }) {
|
|
22
|
+
this.getLocalizedValue = (list, locale) => {
|
|
23
|
+
const fallbackLocale = this.fallbackLocale;
|
|
24
|
+
const filteredList = list.filter((item) => item.isoLanguageId === locale);
|
|
25
|
+
if (filteredList.length === 0 && fallbackLocale) {
|
|
26
|
+
const newFilteredList = list.filter((item) => item.isoLanguageId === fallbackLocale);
|
|
27
|
+
return newFilteredList[0];
|
|
28
|
+
}
|
|
29
|
+
return filteredList[0];
|
|
30
|
+
};
|
|
31
|
+
this.getLocalizedList = (list, locale) => {
|
|
32
|
+
if (locale === '*') {
|
|
33
|
+
return list;
|
|
34
|
+
}
|
|
35
|
+
const filteredList = list.filter((item) => {
|
|
36
|
+
if (!item.isoLanguageId) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return item.isoLanguageId === locale;
|
|
40
|
+
});
|
|
41
|
+
const fallbackLocale = this.fallbackLocale;
|
|
42
|
+
if (filteredList.length === 0 && fallbackLocale) {
|
|
43
|
+
const newFilteredList = list.filter((item) => item.isoLanguageId === fallbackLocale);
|
|
44
|
+
return newFilteredList;
|
|
45
|
+
}
|
|
46
|
+
return filteredList;
|
|
47
|
+
};
|
|
48
|
+
this.getFilteredList = (list, filterFn) => {
|
|
49
|
+
if (!filterFn) {
|
|
50
|
+
return list;
|
|
51
|
+
}
|
|
52
|
+
return list.filter(filterFn);
|
|
53
|
+
};
|
|
54
|
+
this.buildSelectableProduct = (product) => {
|
|
55
|
+
const defaultLocale = this.locale;
|
|
56
|
+
const getShortDescription = (input) => {
|
|
57
|
+
var _a, _b, _c;
|
|
58
|
+
const locale = (_a = input === null || input === void 0 ? void 0 : input.locale) !== null && _a !== void 0 ? _a : defaultLocale;
|
|
59
|
+
const list = (_b = product.productShortDescription) !== null && _b !== void 0 ? _b : [];
|
|
60
|
+
const localizedValue = this.getLocalizedValue(list, locale);
|
|
61
|
+
const value = (_c = localizedValue === null || localizedValue === void 0 ? void 0 : localizedValue.productShortDescription) !== null && _c !== void 0 ? _c : '';
|
|
62
|
+
return (input === null || input === void 0 ? void 0 : input.locale) === '*'
|
|
63
|
+
? list
|
|
64
|
+
: value;
|
|
65
|
+
};
|
|
66
|
+
const getLabel = (input) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const locale = (_a = input === null || input === void 0 ? void 0 : input.locale) !== null && _a !== void 0 ? _a : defaultLocale;
|
|
69
|
+
const filterFn = input === null || input === void 0 ? void 0 : input.filter;
|
|
70
|
+
const list = (_b = product.productLabel) !== null && _b !== void 0 ? _b : [];
|
|
71
|
+
const newList = this.getFilteredList(this.getLocalizedList(list, locale), filterFn);
|
|
72
|
+
return newList.map((item) => item.productLabel);
|
|
73
|
+
};
|
|
74
|
+
const getLabelBySpace = (input) => getLabel(Object.assign(Object.assign({}, input), { filter: (item) => item.spaceId === input.spaceId }));
|
|
75
|
+
const getPriceList = (input) => {
|
|
76
|
+
var _a;
|
|
77
|
+
const filterFn = input === null || input === void 0 ? void 0 : input.filter;
|
|
78
|
+
const list = (_a = product.productPriceList) !== null && _a !== void 0 ? _a : [];
|
|
79
|
+
const filteredList = this.getFilteredList(list, filterFn);
|
|
80
|
+
return filteredList;
|
|
81
|
+
};
|
|
82
|
+
const getStandardPrice = ({ spaceId }) => {
|
|
83
|
+
const priceList = getPriceList({
|
|
84
|
+
filter: (item) => item.spaceId === spaceId && item.priceListType === grid_product_1.PriceListTypeEnum.Standard,
|
|
85
|
+
});
|
|
86
|
+
const firstItem = priceList[0];
|
|
87
|
+
if (!firstItem) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
return { amount: firstItem.listPrice, currencyCode: firstItem.isoCurrencyCode };
|
|
91
|
+
};
|
|
92
|
+
const getPromotionalPrice = ({ spaceId, }) => {
|
|
93
|
+
const priceList = getPriceList({
|
|
94
|
+
filter: (item) => item.spaceId === spaceId &&
|
|
95
|
+
item.priceListType === grid_product_1.PriceListTypeEnum.Promotional,
|
|
96
|
+
});
|
|
97
|
+
const firstItem = priceList[0];
|
|
98
|
+
if (!firstItem) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return { amount: firstItem.listPrice, currencyCode: firstItem.isoCurrencyCode };
|
|
102
|
+
};
|
|
103
|
+
const getName = (input) => {
|
|
104
|
+
var _a, _b, _c;
|
|
105
|
+
const locale = (_a = input === null || input === void 0 ? void 0 : input.locale) !== null && _a !== void 0 ? _a : defaultLocale;
|
|
106
|
+
const list = (_b = product.productName) !== null && _b !== void 0 ? _b : [];
|
|
107
|
+
const localizedValue = this.getLocalizedValue(list, locale);
|
|
108
|
+
const value = (_c = localizedValue === null || localizedValue === void 0 ? void 0 : localizedValue.productName) !== null && _c !== void 0 ? _c : '';
|
|
109
|
+
return (input === null || input === void 0 ? void 0 : input.locale) === '*'
|
|
110
|
+
? list
|
|
111
|
+
: value;
|
|
112
|
+
};
|
|
113
|
+
const getDescription = (input) => {
|
|
114
|
+
var _a, _b, _c;
|
|
115
|
+
const locale = (_a = input === null || input === void 0 ? void 0 : input.locale) !== null && _a !== void 0 ? _a : defaultLocale;
|
|
116
|
+
const list = (_b = product.productDescription) !== null && _b !== void 0 ? _b : [];
|
|
117
|
+
const localizedValue = this.getLocalizedValue(list, locale);
|
|
118
|
+
const value = (_c = localizedValue === null || localizedValue === void 0 ? void 0 : localizedValue.productDescription) !== null && _c !== void 0 ? _c : '';
|
|
119
|
+
return (input === null || input === void 0 ? void 0 : input.locale) === '*'
|
|
120
|
+
? list
|
|
121
|
+
: value;
|
|
122
|
+
};
|
|
123
|
+
const getBrandName = (input) => {
|
|
124
|
+
var _a, _b, _c;
|
|
125
|
+
const locale = (_a = input === null || input === void 0 ? void 0 : input.locale) !== null && _a !== void 0 ? _a : defaultLocale;
|
|
126
|
+
const list = (_b = product.brand) !== null && _b !== void 0 ? _b : [];
|
|
127
|
+
const localizedValue = this.getLocalizedValue(list, locale);
|
|
128
|
+
const value = (_c = localizedValue === null || localizedValue === void 0 ? void 0 : localizedValue.brandName) !== null && _c !== void 0 ? _c : '';
|
|
129
|
+
return (input === null || input === void 0 ? void 0 : input.locale) === '*'
|
|
130
|
+
? list
|
|
131
|
+
: value;
|
|
132
|
+
};
|
|
133
|
+
const getItemQuantity = (input) => {
|
|
134
|
+
var _a;
|
|
135
|
+
const filterFn = input === null || input === void 0 ? void 0 : input.filter;
|
|
136
|
+
const list = (_a = product.productItemQuantity) !== null && _a !== void 0 ? _a : [];
|
|
137
|
+
const filteredList = this.getFilteredList(list, filterFn);
|
|
138
|
+
return filteredList;
|
|
139
|
+
};
|
|
140
|
+
const getVariantQuantity = ({ variantId, spaceId, }) => {
|
|
141
|
+
const filteredList = getItemQuantity({
|
|
142
|
+
filter: (item) => {
|
|
143
|
+
if (!spaceId) {
|
|
144
|
+
return item.productId === variantId;
|
|
145
|
+
}
|
|
146
|
+
return item.productId === variantId && item.spaceId === spaceId;
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
const sum = filteredList.reduce((accumulator, item) => accumulator + item.productItemQuantity, 0);
|
|
150
|
+
return sum;
|
|
151
|
+
};
|
|
152
|
+
const getCatalogPageLocationProduct = (input) => {
|
|
153
|
+
var _a;
|
|
154
|
+
const filterFn = input === null || input === void 0 ? void 0 : input.filter;
|
|
155
|
+
const list = (_a = product.catalogPageLocationProduct) !== null && _a !== void 0 ? _a : [];
|
|
156
|
+
const filteredList = this.getFilteredList(list, filterFn);
|
|
157
|
+
return filteredList;
|
|
158
|
+
};
|
|
159
|
+
const getImages = () => {
|
|
160
|
+
const list = getCatalogPageLocationProduct();
|
|
161
|
+
const result = list.map((item) => item.catalogPageLocationProduct);
|
|
162
|
+
return result;
|
|
163
|
+
};
|
|
164
|
+
const getImage = () => {
|
|
165
|
+
var _a;
|
|
166
|
+
const list = getCatalogPageLocationProduct();
|
|
167
|
+
const images = list.map((item) => item.catalogPageLocationProduct);
|
|
168
|
+
const result = (_a = images[0]) !== null && _a !== void 0 ? _a : '';
|
|
169
|
+
return result;
|
|
170
|
+
};
|
|
171
|
+
const getFeature = (input) => {
|
|
172
|
+
var _a, _b;
|
|
173
|
+
const locale = (_a = input === null || input === void 0 ? void 0 : input.locale) !== null && _a !== void 0 ? _a : defaultLocale;
|
|
174
|
+
const filterFn = input === null || input === void 0 ? void 0 : input.filter;
|
|
175
|
+
const list = (_b = product.productFeature) !== null && _b !== void 0 ? _b : [];
|
|
176
|
+
const filteredList = this.getFilteredList(this.getLocalizedList(list, locale), filterFn);
|
|
177
|
+
return filteredList;
|
|
178
|
+
};
|
|
179
|
+
const getVariantFeature = (input) => getFeature(Object.assign(Object.assign({}, input), { filter: (item) => item.productId === input.productId }));
|
|
180
|
+
const getVariants = (input) => {
|
|
181
|
+
var _a;
|
|
182
|
+
const filterFn = input === null || input === void 0 ? void 0 : input.filter;
|
|
183
|
+
const list = (_a = product.variants) !== null && _a !== void 0 ? _a : [];
|
|
184
|
+
const filteredList = this.getFilteredList(list, filterFn);
|
|
185
|
+
return filteredList;
|
|
186
|
+
};
|
|
187
|
+
const getFirstVariant = () => {
|
|
188
|
+
const variants = getVariants();
|
|
189
|
+
const result = variants[0];
|
|
190
|
+
return result;
|
|
191
|
+
};
|
|
192
|
+
const getVariantsByProductId = ({ productId, }) => getVariants({ filter: (item) => item.productId === productId });
|
|
193
|
+
const getVariantImages = ({ variantId, }) => {
|
|
194
|
+
const filteredList = getCatalogPageLocationProduct({
|
|
195
|
+
filter: (item) => item.productId === variantId,
|
|
196
|
+
});
|
|
197
|
+
const result = filteredList.map((item) => item.catalogPageLocationProduct);
|
|
198
|
+
return result;
|
|
199
|
+
};
|
|
200
|
+
const getVariantStandardPrice = ({ variantId, spaceId, }) => {
|
|
201
|
+
const priceList = getPriceList({
|
|
202
|
+
filter: (item) => item.productId === variantId &&
|
|
203
|
+
item.spaceId === spaceId &&
|
|
204
|
+
item.priceListType === grid_product_1.PriceListTypeEnum.Standard,
|
|
205
|
+
});
|
|
206
|
+
const firstItem = priceList[0];
|
|
207
|
+
if (!firstItem) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
return { amount: firstItem.listPrice, currencyCode: firstItem.isoCurrencyCode };
|
|
211
|
+
};
|
|
212
|
+
const getVariantPromotionalPrice = ({ variantId, spaceId }) => {
|
|
213
|
+
const priceList = getPriceList({
|
|
214
|
+
filter: (item) => item.productId === variantId &&
|
|
215
|
+
item.spaceId === spaceId &&
|
|
216
|
+
item.priceListType === grid_product_1.PriceListTypeEnum.Promotional,
|
|
217
|
+
});
|
|
218
|
+
const firstItem = priceList[0];
|
|
219
|
+
if (!firstItem) {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
return { amount: firstItem.listPrice, currencyCode: firstItem.isoCurrencyCode };
|
|
223
|
+
};
|
|
224
|
+
const selectableProduct = Object.assign(Object.assign({}, product), { getShortDescription,
|
|
225
|
+
getLabel,
|
|
226
|
+
getLabelBySpace,
|
|
227
|
+
getPriceList,
|
|
228
|
+
getStandardPrice,
|
|
229
|
+
getPromotionalPrice,
|
|
230
|
+
getName,
|
|
231
|
+
getDescription,
|
|
232
|
+
getBrandName,
|
|
233
|
+
getItemQuantity,
|
|
234
|
+
getCatalogPageLocationProduct,
|
|
235
|
+
getImages,
|
|
236
|
+
getImage,
|
|
237
|
+
getFeature,
|
|
238
|
+
getVariantFeature,
|
|
239
|
+
getVariants,
|
|
240
|
+
getFirstVariant,
|
|
241
|
+
getVariantsByProductId,
|
|
242
|
+
getVariantImages,
|
|
243
|
+
getVariantStandardPrice,
|
|
244
|
+
getVariantPromotionalPrice,
|
|
245
|
+
getVariantQuantity });
|
|
246
|
+
return selectableProduct;
|
|
247
|
+
};
|
|
248
|
+
this.getProductById = (id, params) => __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
var _a;
|
|
250
|
+
try {
|
|
251
|
+
const result = yield this.httpService.get(`/products/${id}`, {
|
|
252
|
+
params,
|
|
253
|
+
});
|
|
254
|
+
return this.buildSelectableProduct(result.data);
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
// @ts-ignore
|
|
258
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
this.getProductByBarcode = (code, params) => __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
var _a;
|
|
263
|
+
try {
|
|
264
|
+
const result = yield this.httpService.get(`/products-barcode/${code}`, {
|
|
265
|
+
params,
|
|
266
|
+
});
|
|
267
|
+
return {
|
|
268
|
+
productDetails: this.buildSelectableProduct(result.data.productDetails),
|
|
269
|
+
productId: result.data.productId,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
// @ts-ignore
|
|
274
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
this.getProductList = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
var _a;
|
|
279
|
+
try {
|
|
280
|
+
const buildParams = (params) => {
|
|
281
|
+
const stringParams = {};
|
|
282
|
+
if (params) {
|
|
283
|
+
Object.keys(params).forEach((key) => {
|
|
284
|
+
var _a;
|
|
285
|
+
stringParams[key] = (_a = params[key]) === null || _a === void 0 ? void 0 : _a.toString();
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return stringParams;
|
|
289
|
+
};
|
|
290
|
+
const getRequestLength = (path, params) => {
|
|
291
|
+
return (path.length +
|
|
292
|
+
Object.entries(params).reduce((acc, [key, value]) => {
|
|
293
|
+
return (acc + encodeURIComponent(key).length + encodeURIComponent(value).length + 2);
|
|
294
|
+
}, 0));
|
|
295
|
+
};
|
|
296
|
+
const allowedGetRequestLength = 2048; // Replace with the allowed GET API request length
|
|
297
|
+
const requestPath = '/products';
|
|
298
|
+
const requestParams = buildParams(params);
|
|
299
|
+
const requestType = getRequestLength(requestPath, requestParams) < allowedGetRequestLength
|
|
300
|
+
? parameters_1.RequestTypeEnum.GET
|
|
301
|
+
: parameters_1.RequestTypeEnum.POST;
|
|
302
|
+
const result = requestType === parameters_1.RequestTypeEnum.POST
|
|
303
|
+
? yield this.httpService.post(requestPath, Object.assign({}, params))
|
|
304
|
+
: yield this.httpService.get(requestPath, {
|
|
305
|
+
params: requestParams,
|
|
306
|
+
});
|
|
307
|
+
const response = Object.assign(Object.assign({}, result.data), { list: result.data.list.map(this.buildSelectableProduct) });
|
|
308
|
+
return response;
|
|
309
|
+
}
|
|
310
|
+
catch (err) {
|
|
311
|
+
// @ts-ignore
|
|
312
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
// TODO: Remove
|
|
316
|
+
// Temporary - for testing purposes only on v2 product list connected to cosmos
|
|
317
|
+
this.getProductListV2 = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
318
|
+
var _a;
|
|
319
|
+
try {
|
|
320
|
+
const buildParams = (params) => {
|
|
321
|
+
const stringParams = {};
|
|
322
|
+
if (params) {
|
|
323
|
+
Object.keys(params).forEach((key) => {
|
|
324
|
+
var _a;
|
|
325
|
+
stringParams[key] = (_a = params[key]) === null || _a === void 0 ? void 0 : _a.toString();
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return stringParams;
|
|
329
|
+
};
|
|
330
|
+
const getRequestLength = (path, params) => {
|
|
331
|
+
return (path.length +
|
|
332
|
+
Object.entries(params).reduce((acc, [key, value]) => {
|
|
333
|
+
return (acc + encodeURIComponent(key).length + encodeURIComponent(value).length + 2);
|
|
334
|
+
}, 0));
|
|
335
|
+
};
|
|
336
|
+
const allowedGetRequestLength = 2048; // Replace with the allowed GET API request length
|
|
337
|
+
const requestPath = '/products-v2';
|
|
338
|
+
const requestParams = buildParams(params);
|
|
339
|
+
const requestType = getRequestLength(requestPath, requestParams) < allowedGetRequestLength
|
|
340
|
+
? parameters_1.RequestTypeEnum.GET
|
|
341
|
+
: parameters_1.RequestTypeEnum.POST;
|
|
342
|
+
const result = requestType === parameters_1.RequestTypeEnum.POST
|
|
343
|
+
? yield this.httpService.post(requestPath, Object.assign({}, params))
|
|
344
|
+
: yield this.httpService.get(requestPath, {
|
|
345
|
+
params: requestParams,
|
|
346
|
+
});
|
|
347
|
+
const response = Object.assign(Object.assign({}, result.data), { list: result.data.list.map(this.buildSelectableProduct) });
|
|
348
|
+
return response;
|
|
349
|
+
}
|
|
350
|
+
catch (err) {
|
|
351
|
+
// @ts-ignore
|
|
352
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
this.search = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
var _a;
|
|
357
|
+
try {
|
|
358
|
+
const result = yield this.httpService.get('/search', {
|
|
359
|
+
params,
|
|
360
|
+
});
|
|
361
|
+
const response = Object.assign(Object.assign({}, result.data), { products: result.data.products.map(this.buildSelectableProduct) });
|
|
362
|
+
return response;
|
|
363
|
+
}
|
|
364
|
+
catch (err) {
|
|
365
|
+
// @ts-ignore
|
|
366
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
this.getProductTypesList = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
370
|
+
var _a, _b, _c;
|
|
371
|
+
try {
|
|
372
|
+
const result = yield this.httpService.get('/product-types', {
|
|
373
|
+
params: Object.assign(Object.assign({}, params), { ids: (_b = (_a = params === null || params === void 0 ? void 0 : params.ids) === null || _a === void 0 ? void 0 : _a.join(',')) !== null && _b !== void 0 ? _b : '' }),
|
|
374
|
+
});
|
|
375
|
+
return result.data;
|
|
376
|
+
}
|
|
377
|
+
catch (err) {
|
|
378
|
+
// @ts-ignore
|
|
379
|
+
throw new Error((_c = err.response.data.message) !== null && _c !== void 0 ? _c : err.message);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
this.getProductTypesListWithSpaceProducts = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
383
|
+
var _a;
|
|
384
|
+
try {
|
|
385
|
+
const result = yield this.httpService.get('/product-types-with-space-products', {
|
|
386
|
+
params: {
|
|
387
|
+
spaceIds: params.spaceIds.join(','),
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
return result.data;
|
|
391
|
+
}
|
|
392
|
+
catch (err) {
|
|
393
|
+
// @ts-ignore
|
|
394
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
this.getProductType = (id) => __awaiter(this, void 0, void 0, function* () {
|
|
398
|
+
var _a;
|
|
399
|
+
try {
|
|
400
|
+
const result = yield this.httpService.get(`/product-types/${id}`, {});
|
|
401
|
+
return result.data;
|
|
402
|
+
}
|
|
403
|
+
catch (err) {
|
|
404
|
+
// @ts-ignore
|
|
405
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
this.getProductFilters = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
409
|
+
var _a, _b, _c, _d, _e;
|
|
410
|
+
try {
|
|
411
|
+
const result = yield this.httpService.get(`/products-filters`, {
|
|
412
|
+
// Join by ";" to handle productTypes with ","
|
|
413
|
+
params: Object.assign(Object.assign({}, params), { productTypes: (_b = (_a = params.productTypes) === null || _a === void 0 ? void 0 : _a.join(';')) !== null && _b !== void 0 ? _b : [], filterKeys: (_d = (_c = params.filterKeys) === null || _c === void 0 ? void 0 : _c.join(';')) !== null && _d !== void 0 ? _d : [] }),
|
|
414
|
+
});
|
|
415
|
+
return result.data;
|
|
416
|
+
}
|
|
417
|
+
catch (err) {
|
|
418
|
+
// @ts-ignore
|
|
419
|
+
throw new Error((_e = err.response.data.message) !== null && _e !== void 0 ? _e : err.message);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
this.getProductSortOptions = (isoLanguageId) => __awaiter(this, void 0, void 0, function* () {
|
|
423
|
+
var _a;
|
|
424
|
+
try {
|
|
425
|
+
const result = yield this.httpService.get(`/product-sort-options`, {
|
|
426
|
+
params: { isoLanguageId },
|
|
427
|
+
});
|
|
428
|
+
return result.data;
|
|
429
|
+
}
|
|
430
|
+
catch (err) {
|
|
431
|
+
// @ts-ignore
|
|
432
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
this.getProductRecommendations = (id) => __awaiter(this, void 0, void 0, function* () {
|
|
436
|
+
var _a;
|
|
437
|
+
try {
|
|
438
|
+
const result = yield this.httpService.get(`/product-recommendations/${id}`, {});
|
|
439
|
+
const response = result.data.map(this.buildSelectableProduct);
|
|
440
|
+
return response;
|
|
441
|
+
}
|
|
442
|
+
catch (err) {
|
|
443
|
+
// @ts-ignore
|
|
444
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
this.getProductRecommendationsByProductId = (id, params) => __awaiter(this, void 0, void 0, function* () {
|
|
448
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
449
|
+
try {
|
|
450
|
+
const result = yield this.httpService.get(`/product-recommendations-by-productId/${id}`, {
|
|
451
|
+
params,
|
|
452
|
+
});
|
|
453
|
+
const response = {
|
|
454
|
+
default: (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.default) === null || _b === void 0 ? void 0 : _b.map(this.buildSelectableProduct),
|
|
455
|
+
similar: (_d = (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.similar) === null || _d === void 0 ? void 0 : _d.map(this.buildSelectableProduct),
|
|
456
|
+
styleWith: (_f = (_e = result === null || result === void 0 ? void 0 : result.data) === null || _e === void 0 ? void 0 : _e.styleWith) === null || _f === void 0 ? void 0 : _f.map(this.buildSelectableProduct),
|
|
457
|
+
similarItems: (_h = (_g = result === null || result === void 0 ? void 0 : result.data) === null || _g === void 0 ? void 0 : _g.similarItems) === null || _h === void 0 ? void 0 : _h.map(this.buildSelectableProduct),
|
|
458
|
+
completeTheLook: (_k = (_j = result === null || result === void 0 ? void 0 : result.data) === null || _j === void 0 ? void 0 : _j.completeTheLook) === null || _k === void 0 ? void 0 : _k.map(this.buildSelectableProduct),
|
|
459
|
+
};
|
|
460
|
+
return response;
|
|
461
|
+
}
|
|
462
|
+
catch (err) {
|
|
463
|
+
// @ts-ignore
|
|
464
|
+
throw new Error((_l = err.response.data.message) !== null && _l !== void 0 ? _l : err.message);
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
this.getProductRecommendationsByProductIdV2 = (id, payload) => __awaiter(this, void 0, void 0, function* () {
|
|
468
|
+
var _a;
|
|
469
|
+
try {
|
|
470
|
+
const result = yield this.httpService.get(`/products/${id}/recommendations`, {
|
|
471
|
+
params: {
|
|
472
|
+
payload: JSON.stringify(payload),
|
|
473
|
+
},
|
|
474
|
+
});
|
|
475
|
+
const response = result.data.map(this.buildSelectableProduct);
|
|
476
|
+
return response;
|
|
477
|
+
}
|
|
478
|
+
catch (err) {
|
|
479
|
+
// @ts-ignore
|
|
480
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
this.getVariantsList = (productIds) => __awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
var _a;
|
|
485
|
+
try {
|
|
486
|
+
const result = yield this.httpService.get(`/variants`, {
|
|
487
|
+
params: {
|
|
488
|
+
productIds: productIds.join(','),
|
|
489
|
+
},
|
|
490
|
+
});
|
|
491
|
+
return result.data;
|
|
492
|
+
}
|
|
493
|
+
catch (err) {
|
|
494
|
+
// @ts-ignore
|
|
495
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
this.getVariantsListByIds = (productIds) => __awaiter(this, void 0, void 0, function* () {
|
|
499
|
+
var _a;
|
|
500
|
+
try {
|
|
501
|
+
const result = yield this.httpService.get(`/variants`, {
|
|
502
|
+
baseURL: `${this.apiEndpoint}/tenants/${this.tenantId}`,
|
|
503
|
+
params: {
|
|
504
|
+
productIds: productIds.join(','),
|
|
505
|
+
},
|
|
506
|
+
});
|
|
507
|
+
return result.data;
|
|
508
|
+
}
|
|
509
|
+
catch (err) {
|
|
510
|
+
// @ts-ignore
|
|
511
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
this.getVariantDetails = (productId) => __awaiter(this, void 0, void 0, function* () {
|
|
515
|
+
var _a;
|
|
516
|
+
try {
|
|
517
|
+
const result = yield this.httpService.get(`/variants/${productId}`, {});
|
|
518
|
+
return result.data;
|
|
519
|
+
}
|
|
520
|
+
catch (err) {
|
|
521
|
+
// @ts-ignore
|
|
522
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
this.getProductEanByEpc = (epc) => __awaiter(this, void 0, void 0, function* () {
|
|
526
|
+
var _a;
|
|
527
|
+
try {
|
|
528
|
+
const result = yield this.httpService.get(`/product-ean-by-epc/${epc}`, {});
|
|
529
|
+
return result.data;
|
|
530
|
+
}
|
|
531
|
+
catch (err) {
|
|
532
|
+
// @ts-ignore
|
|
533
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
this.getProductByEpc = (code, params) => __awaiter(this, void 0, void 0, function* () {
|
|
537
|
+
var _a;
|
|
538
|
+
try {
|
|
539
|
+
const result = yield this.httpService.get(`/products-by-epc/${code}`, {
|
|
540
|
+
params,
|
|
541
|
+
});
|
|
542
|
+
const response = Object.assign(Object.assign({}, result.data), { productDetails: this.buildSelectableProduct(result.data.productDetails) });
|
|
543
|
+
return response;
|
|
544
|
+
}
|
|
545
|
+
catch (err) {
|
|
546
|
+
// @ts-ignore
|
|
547
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
this.getProductInventory = (_a) => __awaiter(this, [_a], void 0, function* ({ deviceId, requestedQty, skuId, }) {
|
|
551
|
+
var _b;
|
|
552
|
+
try {
|
|
553
|
+
const result = yield this.httpService.get(`/products-inventory`, {
|
|
554
|
+
params: { deviceId, requestedQty, skuId },
|
|
555
|
+
});
|
|
556
|
+
return result.data;
|
|
557
|
+
}
|
|
558
|
+
catch (err) {
|
|
559
|
+
// @ts-ignore
|
|
560
|
+
throw new Error((_b = err.response.data.message) !== null && _b !== void 0 ? _b : err.message);
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
this.getVariantInventory = (_a) => __awaiter(this, [_a], void 0, function* ({ productId, spaceId, }) {
|
|
564
|
+
var _b;
|
|
565
|
+
try {
|
|
566
|
+
const result = yield this.httpService.get(`/variants/${productId}/inventory`, {
|
|
567
|
+
params: { spaceId },
|
|
568
|
+
});
|
|
569
|
+
return result.data;
|
|
570
|
+
}
|
|
571
|
+
catch (err) {
|
|
572
|
+
// @ts-ignore
|
|
573
|
+
throw new Error((_b = err.response.data.message) !== null && _b !== void 0 ? _b : err.message);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
this.getProductGroupStoresInventory = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
577
|
+
var _a;
|
|
578
|
+
try {
|
|
579
|
+
const result = yield this.httpService.get(`/product-group-stores-inventory`, {
|
|
580
|
+
params,
|
|
581
|
+
});
|
|
582
|
+
return result.data;
|
|
583
|
+
}
|
|
584
|
+
catch (err) {
|
|
585
|
+
// @ts-ignore
|
|
586
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
this.getCartPromotions = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
590
|
+
var _a;
|
|
591
|
+
try {
|
|
592
|
+
const { transactionTotal, items } = params;
|
|
593
|
+
const result = yield this.httpService.get(`/cart/promotions`, {
|
|
594
|
+
params: Object.assign(Object.assign({}, params), { transactionTotal: transactionTotal.toFixed(2), items: JSON.stringify(items.map((item) => (Object.assign(Object.assign({}, item), { sequenceId: item.sequenceId.toString(), price: item.price.toFixed(2), quantity: item.quantity.toString() })))) }),
|
|
595
|
+
});
|
|
596
|
+
return result.data;
|
|
597
|
+
}
|
|
598
|
+
catch (err) {
|
|
599
|
+
// @ts-ignore
|
|
600
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
this.getVariantActivePrice = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
604
|
+
var _a;
|
|
605
|
+
try {
|
|
606
|
+
const result = yield this.httpService.get(`/variant-active-price/${params.productId}`, {
|
|
607
|
+
params,
|
|
608
|
+
});
|
|
609
|
+
return result.data;
|
|
610
|
+
}
|
|
611
|
+
catch (err) {
|
|
612
|
+
// @ts-ignore
|
|
613
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
if (!tenantId) {
|
|
617
|
+
throw new Error('Error: tenantId is required');
|
|
618
|
+
}
|
|
619
|
+
if (!environment) {
|
|
620
|
+
throw new Error('Error: environment is required');
|
|
621
|
+
}
|
|
622
|
+
const apiEndpoint = (0, api_1.setApiEndpoint)(dataResidency);
|
|
623
|
+
this.httpService = new http_service_1.default({
|
|
624
|
+
baseUrl: `${apiEndpoint}/tenants/${tenantId}/${environment}`,
|
|
625
|
+
});
|
|
626
|
+
this.apiEndpoint = apiEndpoint;
|
|
627
|
+
this.tenantId = tenantId;
|
|
628
|
+
this.locale = locale;
|
|
629
|
+
this.fallbackLocale = fallbackLocale;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
exports.GridProductServiceClient = GridProductServiceClient;
|
|
633
|
+
exports.default = GridProductServiceClient;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import HttpService from './http-service';
|
|
2
|
+
import { ProductDetailsByCodeQueryParameters, ProductDetailsQueryParameters, ProductFiltersQueryParameters, ProductGroupStoresInventoryParam, ProductGroupStoresInventoryResponse, ProductQueryParameters, ProductRecommendationsQueryParameters, ProductTypesListQueryParameters, RequestTypeEnum, SearchQueryParameters } from '../types/parameters';
|
|
3
|
+
import { FilterByGroup, FilterByLanguage, GetCartPromotionsParams, GetCartPromotionsResponse, GetVariantActivePriceParams, GetVariantActivePriceResponse, GridProduct, InventoryItem, ProductRecommendationResponse, ProductType, SortOptionsResponse, VariantInfo, VariantInventory } from '../types/grid-product';
|
|
4
|
+
import { IsoLanguageIds } from '../types/iso-language-ids';
|
|
5
|
+
interface GridProductServiceInterface {
|
|
6
|
+
readonly httpService: HttpService;
|
|
7
|
+
locale: IsoLanguageIds | '*';
|
|
8
|
+
getProductById: (id: string, params: ProductDetailsQueryParameters) => Promise<Partial<GridProduct>>;
|
|
9
|
+
getProductByBarcode: (code: string, params: ProductDetailsByCodeQueryParameters) => Promise<{
|
|
10
|
+
productDetails: Partial<GridProduct>;
|
|
11
|
+
productId: string;
|
|
12
|
+
}>;
|
|
13
|
+
getProductList: (params?: ProductQueryParameters, requestType?: RequestTypeEnum) => Promise<{
|
|
14
|
+
list: Partial<GridProduct>[];
|
|
15
|
+
attributeFilters: FilterByLanguage;
|
|
16
|
+
}>;
|
|
17
|
+
search: (params: SearchQueryParameters) => Promise<{
|
|
18
|
+
products: Array<Partial<GridProduct>>;
|
|
19
|
+
productTypes: Array<ProductType>;
|
|
20
|
+
}>;
|
|
21
|
+
getProductTypesList: (params?: ProductTypesListQueryParameters) => Promise<ProductType[]>;
|
|
22
|
+
getProductType: (id: string) => Promise<ProductType>;
|
|
23
|
+
getProductFilters: (params: ProductFiltersQueryParameters) => Promise<FilterByGroup>;
|
|
24
|
+
getProductSortOptions: (isoLanguageId?: IsoLanguageIds) => Promise<SortOptionsResponse>;
|
|
25
|
+
getProductRecommendations: (id: string) => Promise<Partial<GridProduct>[]>;
|
|
26
|
+
getProductRecommendationsByProductId: (id: string, params: Partial<ProductRecommendationsQueryParameters>) => Promise<ProductRecommendationResponse>;
|
|
27
|
+
getVariantsList: (productIds: string[]) => Promise<VariantInfo[]>;
|
|
28
|
+
getVariantDetails: (productId: string) => Promise<VariantInfo>;
|
|
29
|
+
getProductEanByEpc: (epc: string) => Promise<string>;
|
|
30
|
+
getProductByEpc: (code: string, params: ProductDetailsByCodeQueryParameters) => Promise<{
|
|
31
|
+
productDetails: Partial<GridProduct>;
|
|
32
|
+
productId: string;
|
|
33
|
+
}>;
|
|
34
|
+
getProductInventory: ({ deviceId, requestedQty, skuId, }: {
|
|
35
|
+
deviceId?: string;
|
|
36
|
+
requestedQty: number;
|
|
37
|
+
skuId: string;
|
|
38
|
+
}) => Promise<InventoryItem | null>;
|
|
39
|
+
getVariantInventory: ({ productId, spaceId, }: {
|
|
40
|
+
productId: string;
|
|
41
|
+
spaceId?: string;
|
|
42
|
+
}) => Promise<VariantInventory>;
|
|
43
|
+
getProductGroupStoresInventory: (params: ProductGroupStoresInventoryParam) => Promise<ProductGroupStoresInventoryResponse | null>;
|
|
44
|
+
getCartPromotions: (params: GetCartPromotionsParams) => Promise<GetCartPromotionsResponse | null>;
|
|
45
|
+
getVariantActivePrice: (params: GetVariantActivePriceParams) => Promise<GetVariantActivePriceResponse | null>;
|
|
46
|
+
}
|
|
47
|
+
export default GridProductServiceInterface;
|