@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
package/dist/utils.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getProductEanByEpc = exports.isLeafProductType = exports.getProductTypeChildrenAndSubchildrenIds = exports.getProductTypeChildren = exports.getProductTypeById = exports.getProductTypeTitle = exports.getProductLabel = exports.getProductPrice = exports.getProductPriceList = exports.getProductFeature = exports.getProductStatus = exports.getProductBrand = exports.getVariantProductName = exports.getProductDescription = exports.getProductName = exports.getProductShippingInstruction = exports.getProductConsumerStorageInstruction = exports.getProductStorageInstructions = exports.getProductInternalName = exports.getProductShortDescription = void 0;
|
|
7
|
+
const iso_language_ids_1 = require("./types/iso-language-ids");
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const epc_ean_1 = __importDefault(require("@ombori/epc-ean"));
|
|
10
|
+
// Returns default "en" related language as fallback if isoLanguageId not found in products data
|
|
11
|
+
const getLocalizedValue = ({ data = [], isoLanguageId = iso_language_ids_1.IsoLanguageIds.en_US, }) => {
|
|
12
|
+
const dataMap = data.reduce((accumulator, dataItem) => {
|
|
13
|
+
const newAccumulator = Object.assign(Object.assign({}, accumulator), { [dataItem.isoLanguageId]: dataItem });
|
|
14
|
+
return newAccumulator;
|
|
15
|
+
}, {});
|
|
16
|
+
let result = dataMap[isoLanguageId];
|
|
17
|
+
if (!result) {
|
|
18
|
+
const defaultLanguage = Object.keys(dataMap).find((key) => key.startsWith('en'));
|
|
19
|
+
if (defaultLanguage) {
|
|
20
|
+
result = dataMap[defaultLanguage];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
// Returns default "en" related language as fallback if isoLanguageId not found in products data
|
|
26
|
+
const getLocalizedValues = ({ data = [], isoLanguageId = iso_language_ids_1.IsoLanguageIds.en_US, }) => {
|
|
27
|
+
let result = data.filter((dataItem) => dataItem.isoLanguageId === isoLanguageId);
|
|
28
|
+
if (result.length === 0) {
|
|
29
|
+
result = data.filter((dataItem) => dataItem.isoLanguageId && dataItem.isoLanguageId.startsWith('en'));
|
|
30
|
+
}
|
|
31
|
+
if (result.length === 0) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
const getProductShortDescription = (product, isoLanguageId) => {
|
|
37
|
+
const result = getLocalizedValue({
|
|
38
|
+
data: product.productShortDescription,
|
|
39
|
+
isoLanguageId,
|
|
40
|
+
});
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
exports.getProductShortDescription = getProductShortDescription;
|
|
44
|
+
const getProductInternalName = (product, isoLanguageId) => {
|
|
45
|
+
const result = getLocalizedValue({
|
|
46
|
+
data: product.productInternalName,
|
|
47
|
+
isoLanguageId,
|
|
48
|
+
});
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
exports.getProductInternalName = getProductInternalName;
|
|
52
|
+
const getProductStorageInstructions = (product, isoLanguageId) => {
|
|
53
|
+
const result = getLocalizedValue({
|
|
54
|
+
data: product.storageInstructions,
|
|
55
|
+
isoLanguageId,
|
|
56
|
+
});
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
exports.getProductStorageInstructions = getProductStorageInstructions;
|
|
60
|
+
const getProductConsumerStorageInstruction = (product, isoLanguageId) => {
|
|
61
|
+
const result = getLocalizedValue({
|
|
62
|
+
data: product.consumerStorageInstruction,
|
|
63
|
+
isoLanguageId,
|
|
64
|
+
});
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
exports.getProductConsumerStorageInstruction = getProductConsumerStorageInstruction;
|
|
68
|
+
const getProductShippingInstruction = (product, isoLanguageId) => {
|
|
69
|
+
const result = getLocalizedValue({
|
|
70
|
+
data: product.productShippingInstruction,
|
|
71
|
+
isoLanguageId,
|
|
72
|
+
});
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
exports.getProductShippingInstruction = getProductShippingInstruction;
|
|
76
|
+
const getProductName = (product, isoLanguageId) => {
|
|
77
|
+
const result = getLocalizedValue({
|
|
78
|
+
data: product.productName,
|
|
79
|
+
isoLanguageId,
|
|
80
|
+
});
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
exports.getProductName = getProductName;
|
|
84
|
+
const getProductDescription = (product, isoLanguageId) => {
|
|
85
|
+
const result = getLocalizedValue({
|
|
86
|
+
data: product.productDescription,
|
|
87
|
+
isoLanguageId,
|
|
88
|
+
});
|
|
89
|
+
return result;
|
|
90
|
+
};
|
|
91
|
+
exports.getProductDescription = getProductDescription;
|
|
92
|
+
const getVariantProductName = (variant, isoLanguageId) => {
|
|
93
|
+
const result = getLocalizedValue({
|
|
94
|
+
data: variant.productName,
|
|
95
|
+
isoLanguageId,
|
|
96
|
+
});
|
|
97
|
+
return result;
|
|
98
|
+
};
|
|
99
|
+
exports.getVariantProductName = getVariantProductName;
|
|
100
|
+
const getProductBrand = (product, isoLanguageId) => {
|
|
101
|
+
const result = getLocalizedValue({
|
|
102
|
+
data: product.brand,
|
|
103
|
+
isoLanguageId,
|
|
104
|
+
});
|
|
105
|
+
return result;
|
|
106
|
+
};
|
|
107
|
+
exports.getProductBrand = getProductBrand;
|
|
108
|
+
const getProductStatus = (product) => {
|
|
109
|
+
return product.productStatus;
|
|
110
|
+
};
|
|
111
|
+
exports.getProductStatus = getProductStatus;
|
|
112
|
+
const getProductFeature = (product, isoLanguageId) => {
|
|
113
|
+
const result = getLocalizedValues({
|
|
114
|
+
data: product.productFeature,
|
|
115
|
+
isoLanguageId,
|
|
116
|
+
});
|
|
117
|
+
return result;
|
|
118
|
+
};
|
|
119
|
+
exports.getProductFeature = getProductFeature;
|
|
120
|
+
const getProductPriceList = (product) => {
|
|
121
|
+
return product.productPriceList;
|
|
122
|
+
};
|
|
123
|
+
exports.getProductPriceList = getProductPriceList;
|
|
124
|
+
const getProductPrice = (productPriceList, isoLanguageId) => {
|
|
125
|
+
const label = new Intl.NumberFormat(isoLanguageId, {
|
|
126
|
+
style: 'currency',
|
|
127
|
+
currency: productPriceList.isoCurrencyCode,
|
|
128
|
+
}).format(productPriceList.listPrice);
|
|
129
|
+
const priceData = {
|
|
130
|
+
label,
|
|
131
|
+
currency: productPriceList.isoCurrencyCode,
|
|
132
|
+
price: productPriceList.listPrice,
|
|
133
|
+
};
|
|
134
|
+
return priceData;
|
|
135
|
+
};
|
|
136
|
+
exports.getProductPrice = getProductPrice;
|
|
137
|
+
const getProductLabel = (product, isoLanguageId) => {
|
|
138
|
+
const result = getLocalizedValues({
|
|
139
|
+
data: product.productLabel,
|
|
140
|
+
isoLanguageId,
|
|
141
|
+
});
|
|
142
|
+
return result;
|
|
143
|
+
};
|
|
144
|
+
exports.getProductLabel = getProductLabel;
|
|
145
|
+
const getProductTypeTitle = (productType, isoLanguageId) => {
|
|
146
|
+
const result = getLocalizedValue({
|
|
147
|
+
data: productType.title,
|
|
148
|
+
isoLanguageId,
|
|
149
|
+
});
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
exports.getProductTypeTitle = getProductTypeTitle;
|
|
153
|
+
const getProductTypeById = (productTypes, productTypeId) => {
|
|
154
|
+
const productTypeList = productTypes.filter((productType) => productType.productTypeId === productTypeId);
|
|
155
|
+
return productTypeList;
|
|
156
|
+
};
|
|
157
|
+
exports.getProductTypeById = getProductTypeById;
|
|
158
|
+
const getProductTypeChildren = (productTypes, productTypeId) => {
|
|
159
|
+
const children = productTypes.filter((productType) => productType.parentId === productTypeId &&
|
|
160
|
+
productType.productTypeId !== productTypeId);
|
|
161
|
+
return children;
|
|
162
|
+
};
|
|
163
|
+
exports.getProductTypeChildren = getProductTypeChildren;
|
|
164
|
+
const getProductTypeChildrenAndSubchildrenIds = (productTypes, productTypeId) => {
|
|
165
|
+
let result = [];
|
|
166
|
+
const traverseAllChildren = (id) => {
|
|
167
|
+
const currProductTypeChildren = (0, exports.getProductTypeChildren)(productTypes, id).map((productType) => productType.productTypeId);
|
|
168
|
+
if (currProductTypeChildren.length > 0) {
|
|
169
|
+
result = result.concat([...currProductTypeChildren]);
|
|
170
|
+
currProductTypeChildren.forEach((child) => child !== id && traverseAllChildren(child));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
traverseAllChildren(productTypeId);
|
|
174
|
+
return result;
|
|
175
|
+
};
|
|
176
|
+
exports.getProductTypeChildrenAndSubchildrenIds = getProductTypeChildrenAndSubchildrenIds;
|
|
177
|
+
const isLeafProductType = (productTypes, productTypeId) => {
|
|
178
|
+
const children = productTypes.filter((productType) => productType.parentId === productTypeId);
|
|
179
|
+
return children.length === 0;
|
|
180
|
+
};
|
|
181
|
+
exports.isLeafProductType = isLeafProductType;
|
|
182
|
+
const getProductEanByEpc = (epc) => {
|
|
183
|
+
const data = epc_ean_1.default.valueOf(epc);
|
|
184
|
+
const barcode = data.toBarcode();
|
|
185
|
+
return barcode;
|
|
186
|
+
};
|
|
187
|
+
exports.getProductEanByEpc = getProductEanByEpc;
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
roots: ['<rootDir>'],
|
|
4
|
+
setupFilesAfterEnv: ['./jest.setup.js'],
|
|
5
|
+
testEnvironment: 'node',
|
|
6
|
+
testRegex: '\\.(test)\\.ts$',
|
|
7
|
+
// we need this since we have typescript which emits js files and by default jest uses js files in tests.
|
|
8
|
+
// moduleFileExtensions option overrides such behaviour and jest imports ts file first.
|
|
9
|
+
moduleFileExtensions: ['ts', 'js'],
|
|
10
|
+
};
|
package/jest.setup.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@phystack/products",
|
|
3
|
+
"version": "4.4.29",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"build:watch": "tsc -w",
|
|
9
|
+
"format": "yarn lint --fix",
|
|
10
|
+
"test": "jest --watch",
|
|
11
|
+
"test:ci": "jest --ci"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@babel/cli": "^7.2.3",
|
|
18
|
+
"@faker-js/faker": "^7.6.0",
|
|
19
|
+
"@ombori/babel-config-typescript": "2.154.10",
|
|
20
|
+
"@ombori/tslint-config-gdm": "2.1.1",
|
|
21
|
+
"ts-jest": "24",
|
|
22
|
+
"typescript": "^5.4.5"
|
|
23
|
+
},
|
|
24
|
+
"author": "",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@ombori/epc-ean": "4.1.31",
|
|
28
|
+
"axios": "^0.27.2"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "7dba834ca1f446f669992ff14352862d2fbcfe22"
|
|
31
|
+
}
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
enum DataResidencyEnum {
|
|
2
|
+
'EU' = "EU",
|
|
3
|
+
'US' = "US",
|
|
4
|
+
'UAE' = "UAE",
|
|
5
|
+
'AU' = "AU",
|
|
6
|
+
'IN' = "IN",
|
|
7
|
+
'QA' = "QA",
|
|
8
|
+
'DEV' = "DEV"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const setApiEndpoint = (dataResidency: DataResidencyEnum) => {
|
|
12
|
+
let endpoint: string;
|
|
13
|
+
|
|
14
|
+
switch (dataResidency) {
|
|
15
|
+
case DataResidencyEnum.EU: {
|
|
16
|
+
endpoint = 'https://api.omborigrid.com/regions/eu/products/v1';
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
case DataResidencyEnum.US: {
|
|
20
|
+
endpoint = 'https://api.omborigrid.com/regions/us/products/v1';
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case DataResidencyEnum.UAE: {
|
|
24
|
+
endpoint = 'https://api.omborigrid.com/regions/uae/products/v1';
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case DataResidencyEnum.AU: {
|
|
28
|
+
endpoint = 'https://api.omborigrid.com/regions/au/products/v1';
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
case DataResidencyEnum.IN: {
|
|
32
|
+
endpoint = 'https://api.omborigrid.com/regions/in/products/v1';
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
//@ts-ignore
|
|
36
|
+
case 'DEV': {
|
|
37
|
+
endpoint = 'https://api.griddeveloper.com/regions/dev/products/v1';
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
default: {
|
|
41
|
+
endpoint = 'https://api-qa.omborigrid.com/regions/qa/products/v1';
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return endpoint;
|
|
47
|
+
};
|
package/src/helpers.ts
ADDED