store-scrapper-js-common 2.0.2 → 2.0.4
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/classes/command.js +5 -8
- package/dist/classes/command.js.map +1 -1
- package/dist/classes/response.js +2 -3
- package/dist/classes/response.js.map +1 -1
- package/dist/dto/process-product-category.dto.d.ts +6 -5
- package/dist/dto/process-product-category.dto.js.map +1 -1
- package/dist/dto/telegram-queue-command.dto.d.ts +2 -0
- package/dist/dto/telegram-queue-command.dto.js.map +1 -1
- package/dist/entities/abstract-base.d.ts +2 -2
- package/dist/entities/abstract-base.js +4 -4
- package/dist/entities/abstract-base.js.map +1 -1
- package/dist/entities/alert-conditions.js +12 -12
- package/dist/entities/alert-conditions.js.map +1 -1
- package/dist/entities/category-entity.js +7 -7
- package/dist/entities/category-entity.js.map +1 -1
- package/dist/entities/category.js +1 -1
- package/dist/entities/category.js.map +1 -1
- package/dist/entities/keyword.js +16 -16
- package/dist/entities/keyword.js.map +1 -1
- package/dist/entities/price.js +23 -23
- package/dist/entities/price.js.map +1 -1
- package/dist/entities/prices-stats.js +32 -32
- package/dist/entities/prices-stats.js.map +1 -1
- package/dist/entities/product.js +63 -63
- package/dist/entities/product.js.map +1 -1
- package/dist/entities/store.js +22 -22
- package/dist/entities/store.js.map +1 -1
- package/dist/entities/user.js +15 -15
- package/dist/entities/user.js.map +1 -1
- package/dist/enums/telegram-queue.enum.d.ts +62 -0
- package/dist/enums/telegram-queue.enum.js +62 -0
- package/dist/enums/telegram-queue.enum.js.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/array-utils.js +6 -10
- package/dist/utils/array-utils.js.map +1 -1
- package/dist/utils/entity-queries-utils.js +1 -2
- package/dist/utils/entity-queries-utils.js.map +1 -1
- package/dist/utils/number-utils.js +8 -13
- package/dist/utils/number-utils.js.map +1 -1
- package/dist/utils/price-utils.js +19 -29
- package/dist/utils/price-utils.js.map +1 -1
- package/dist/utils/product.utils.js +2 -4
- package/dist/utils/product.utils.js.map +1 -1
- package/dist/utils/string-formatter.js +7 -15
- package/dist/utils/string-formatter.js.map +1 -1
- package/dist/utils/string-utils.js +14 -22
- package/dist/utils/string-utils.js.map +1 -1
- package/dist/utils/url-utils.js +4 -8
- package/dist/utils/url-utils.js.map +1 -1
- package/package.json +2 -2
- package/src/dto/process-product-category.dto.ts +7 -5
- package/src/dto/telegram-queue-command.dto.ts +4 -0
- package/src/entities/abstract-base.ts +2 -2
- package/src/enums/telegram-queue.enum.ts +65 -0
|
@@ -3,13 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isCheaper = exports.getPriceByMeasurementUnitMultiplier = exports.getAvgPrice = exports.getMaxPrice = exports.getMinPrice = exports.getPriceOperation = exports.removeZeroPrices = exports.isValidPrice = exports.checkIfSamePrices = exports.hasMeasurementUnitMultiplier = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const entities_1 = require("../entities");
|
|
6
|
-
|
|
7
|
-
exports.
|
|
8
|
-
|
|
9
|
-
exports.
|
|
10
|
-
const isValidPrice = (price) => !(!price || (!price.normalPrice && !price.cardPrice && !price.offerPrice));
|
|
11
|
-
exports.isValidPrice = isValidPrice;
|
|
12
|
-
const removeZeroPrices = (price) => {
|
|
6
|
+
exports.hasMeasurementUnitMultiplier = (price) => !!price && !!price.unitMultiplier && !!price.measurementUnit;
|
|
7
|
+
exports.checkIfSamePrices = (_price, _price2) => _price && _price2 && lodash_1.isEqual(lodash_1.pickBy({ normalPrice: _price.normalPrice, offerPrice: _price.offerPrice, cardPrice: _price.cardPrice }, lodash_1.identity), lodash_1.pickBy({ normalPrice: _price2.normalPrice, offerPrice: _price2.offerPrice, cardPrice: _price2.cardPrice }, lodash_1.identity));
|
|
8
|
+
exports.isValidPrice = (price) => !(!price || (!price.normalPrice && !price.cardPrice && !price.offerPrice));
|
|
9
|
+
exports.removeZeroPrices = (price) => {
|
|
13
10
|
const removedZeroesPrice = price;
|
|
14
11
|
if (!price.cardPrice) {
|
|
15
12
|
delete removedZeroesPrice.cardPrice;
|
|
@@ -22,8 +19,7 @@ const removeZeroPrices = (price) => {
|
|
|
22
19
|
}
|
|
23
20
|
return removedZeroesPrice;
|
|
24
21
|
};
|
|
25
|
-
exports.
|
|
26
|
-
const getPriceOperation = (price, fn) => {
|
|
22
|
+
exports.getPriceOperation = (price, fn) => {
|
|
27
23
|
if (!price) {
|
|
28
24
|
return null;
|
|
29
25
|
}
|
|
@@ -33,25 +29,21 @@ const getPriceOperation = (price, fn) => {
|
|
|
33
29
|
}
|
|
34
30
|
return fn(...arr);
|
|
35
31
|
};
|
|
36
|
-
exports.
|
|
37
|
-
|
|
38
|
-
exports.
|
|
39
|
-
const getMaxPrice = (price) => (0, exports.getPriceOperation)(price, Math.max);
|
|
40
|
-
exports.getMaxPrice = getMaxPrice;
|
|
41
|
-
const getAvgPrice = (price) => {
|
|
32
|
+
exports.getMinPrice = (price) => exports.getPriceOperation(price, Math.min);
|
|
33
|
+
exports.getMaxPrice = (price) => exports.getPriceOperation(price, Math.max);
|
|
34
|
+
exports.getAvgPrice = (price) => {
|
|
42
35
|
const fn = (...arr) => {
|
|
43
36
|
const sum = arr.reduce(((previousValue, currentValue) => previousValue + currentValue));
|
|
44
37
|
return (sum / arr.length);
|
|
45
38
|
};
|
|
46
|
-
return
|
|
39
|
+
return exports.getPriceOperation(price, fn);
|
|
47
40
|
};
|
|
48
|
-
exports.
|
|
49
|
-
|
|
50
|
-
if (!(0, exports.hasMeasurementUnitMultiplier)(price)) {
|
|
41
|
+
exports.getPriceByMeasurementUnitMultiplier = (price, minUnit = 100) => {
|
|
42
|
+
if (!exports.hasMeasurementUnitMultiplier(price)) {
|
|
51
43
|
return null;
|
|
52
44
|
}
|
|
53
45
|
const { measurementUnit, unitMultiplier } = price;
|
|
54
|
-
const minPrice =
|
|
46
|
+
const minPrice = exports.getMinPrice(price);
|
|
55
47
|
let value;
|
|
56
48
|
if ([entities_1.MeasurementUnitEnum.KG, entities_1.MeasurementUnitEnum.L].includes(measurementUnit)) {
|
|
57
49
|
const grams = unitMultiplier * 1000;
|
|
@@ -65,21 +57,19 @@ const getPriceByMeasurementUnitMultiplier = (price, minUnit = 100) => {
|
|
|
65
57
|
}
|
|
66
58
|
return value ? Math.round(value) : null;
|
|
67
59
|
};
|
|
68
|
-
exports.
|
|
69
|
-
|
|
70
|
-
if (!(0, exports.isValidPrice)(price) || !(0, exports.isValidPrice)(comparePrice)) {
|
|
60
|
+
exports.isCheaper = (price, comparePrice) => {
|
|
61
|
+
if (!exports.isValidPrice(price) || !exports.isValidPrice(comparePrice)) {
|
|
71
62
|
return null;
|
|
72
63
|
}
|
|
73
|
-
const minPrice =
|
|
74
|
-
const minComparePrice =
|
|
75
|
-
if (
|
|
76
|
-
const minPriceWithMeasurementUnit =
|
|
77
|
-
const comparePriceWithMeasurementUnit =
|
|
64
|
+
const minPrice = exports.getMinPrice(price);
|
|
65
|
+
const minComparePrice = exports.getMinPrice(comparePrice);
|
|
66
|
+
if (exports.hasMeasurementUnitMultiplier(price) && exports.hasMeasurementUnitMultiplier(comparePrice)) {
|
|
67
|
+
const minPriceWithMeasurementUnit = exports.getPriceByMeasurementUnitMultiplier(price);
|
|
68
|
+
const comparePriceWithMeasurementUnit = exports.getPriceByMeasurementUnitMultiplier(comparePrice);
|
|
78
69
|
if (minPriceWithMeasurementUnit && comparePriceWithMeasurementUnit) {
|
|
79
70
|
return minPriceWithMeasurementUnit < comparePriceWithMeasurementUnit;
|
|
80
71
|
}
|
|
81
72
|
}
|
|
82
73
|
return minPrice < minComparePrice;
|
|
83
74
|
};
|
|
84
|
-
exports.isCheaper = isCheaper;
|
|
85
75
|
//# sourceMappingURL=price-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price-utils.js","sourceRoot":"/","sources":["utils/price-utils.ts"],"names":[],"mappings":";;;AAAA,mCAAmD;AACnD,0C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I,2BAA2B,IAAI,+BAA+B,EAAE;YAClE,OAAO,2BAA2B,GAAG,+BAA+B,CAAC;SACtE;KACF;IAED,OAAO,QAAQ,GAAG,eAAe,CAAC;AACpC,CAAC,CAAC","sourcesContent":["import { identity, isEqual, pickBy } from 'lodash';\nimport { MeasurementUnitEnum, Price } from '../entities';\n\nexport const hasMeasurementUnitMultiplier = (price: Price): boolean => !!price && !!price.unitMultiplier && !!price.measurementUnit;\n\nexport const checkIfSamePrices = (_price: Price, _price2: Price): boolean => _price && _price2 && isEqual(\n pickBy({ normalPrice: _price.normalPrice, offerPrice: _price.offerPrice, cardPrice: _price.cardPrice }, identity),\n pickBy({ normalPrice: _price2.normalPrice, offerPrice: _price2.offerPrice, cardPrice: _price2.cardPrice }, identity),\n);\n\nexport const isValidPrice = (price: Price): boolean => !(!price || (!price.normalPrice && !price.cardPrice && !price.offerPrice));\n\nexport const removeZeroPrices = (price:Price): Price => {\n const removedZeroesPrice = price;\n\n if (!price.cardPrice) {\n delete removedZeroesPrice.cardPrice;\n }\n\n if (!price.normalPrice) {\n delete removedZeroesPrice.normalPrice;\n }\n\n if (!price.offerPrice) {\n delete removedZeroesPrice.offerPrice;\n }\n\n return removedZeroesPrice;\n};\n\nexport const getPriceOperation = (price: Price, fn: (...p) => number): number => {\n if (!price) {\n return null;\n }\n\n const arr = [price.normalPrice, price.offerPrice, price.cardPrice].filter((v) => v);\n if (arr.length === 0) {\n return null;\n }\n\n return fn(...arr);\n};\n\nexport const getMinPrice = (price: Price): number => getPriceOperation(price, Math.min);\n\nexport const getMaxPrice = (price: Price): number => getPriceOperation(price, Math.max);\n\nexport const getAvgPrice = (price: Price): number => {\n const fn = (...arr) => {\n const sum = arr.reduce(((previousValue, currentValue) => previousValue + currentValue));\n\n return (sum / arr.length);\n };\n\n return getPriceOperation(price, fn);\n};\n\nexport const getPriceByMeasurementUnitMultiplier = (price: Price, minUnit = 100): number => {\n if (!hasMeasurementUnitMultiplier(price)) {\n return null;\n }\n\n const { measurementUnit, unitMultiplier } = price;\n\n const minPrice = getMinPrice(price);\n\n let value;\n if ([MeasurementUnitEnum.KG, MeasurementUnitEnum.L].includes(measurementUnit)) {\n const grams = unitMultiplier * 1000;\n value = (minPrice / grams) * minUnit;\n } else if ([MeasurementUnitEnum.G, MeasurementUnitEnum.ML].includes(measurementUnit)) {\n value = (minPrice / unitMultiplier) * minUnit;\n } else {\n value = minPrice * unitMultiplier;\n }\n\n return value ? Math.round(value) : null;\n};\n\nexport const isCheaper = (price: Price, comparePrice: Price): boolean | null => {\n if (!isValidPrice(price) || !isValidPrice(comparePrice)) {\n return null;\n }\n\n const minPrice = getMinPrice(price);\n const minComparePrice = getMinPrice(comparePrice);\n\n if (hasMeasurementUnitMultiplier(price) && hasMeasurementUnitMultiplier(comparePrice)) {\n const minPriceWithMeasurementUnit = getPriceByMeasurementUnitMultiplier(price);\n const comparePriceWithMeasurementUnit = getPriceByMeasurementUnitMultiplier(comparePrice);\n\n if (minPriceWithMeasurementUnit && comparePriceWithMeasurementUnit) {\n return minPriceWithMeasurementUnit < comparePriceWithMeasurementUnit;\n }\n }\n\n return minPrice < minComparePrice;\n};\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hasUpdateReason = exports.getStoreName = void 0;
|
|
4
4
|
const array_utils_1 = require("./array-utils");
|
|
5
|
-
|
|
5
|
+
exports.getStoreName = (product, stores) => {
|
|
6
6
|
if ((!stores || stores.length === 0) && product) {
|
|
7
7
|
return product.storeName;
|
|
8
8
|
}
|
|
@@ -12,7 +12,5 @@ const getStoreName = (product, stores) => {
|
|
|
12
12
|
}
|
|
13
13
|
return null;
|
|
14
14
|
};
|
|
15
|
-
exports.
|
|
16
|
-
const hasUpdateReason = (enums, search) => (0, array_utils_1.hasElementInArray)(enums, search);
|
|
17
|
-
exports.hasUpdateReason = hasUpdateReason;
|
|
15
|
+
exports.hasUpdateReason = (enums, search) => array_utils_1.hasElementInArray(enums, search);
|
|
18
16
|
//# sourceMappingURL=product.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.utils.js","sourceRoot":"/","sources":["utils/product.utils.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;
|
|
1
|
+
{"version":3,"file":"product.utils.js","sourceRoot":"/","sources":["utils/product.utils.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAGrC,QAAA,YAAY,GAAG,CAAC,OAAgB,EAAE,MAAe,EAAU,EAAE;IACxE,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,IAAI,OAAO,EAAE;QAC/C,OAAO,OAAO,CAAC,SAAS,CAAC;KAC1B;IAGD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9F,IAAI,KAAK,EAAE;QACT,OAAO,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC;KACxC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEW,QAAA,eAAe,GAAG,CAAC,KAAyB,EAAE,MAA0B,EAAW,EAAE,CAAC,+BAAiB,CAAmB,KAAK,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { hasElementInArray } from './array-utils';\nimport { Product, Store, UpdateReasonEnum } from '../entities';\n\nexport const getStoreName = (product: Product, stores: Store[]): string => {\n if ((!stores || stores.length === 0) && product) {\n return product.storeName;\n }\n\n // eslint-disable-next-line no-underscore-dangle\n const store = stores.find((storeElement) => storeElement._id.toString() === product.storeRef);\n if (store) {\n return store.displayName || store.name;\n }\n\n return null;\n};\n\nexport const hasUpdateReason = (enums: UpdateReasonEnum[], search: UpdateReasonEnum[]): boolean => hasElementInArray<UpdateReasonEnum>(enums, search);\n"]}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -27,7 +23,7 @@ exports.formatPct = exports.formatDate = exports.formatMoney = exports.addThousa
|
|
|
27
23
|
const moment = __importStar(require("moment-timezone"));
|
|
28
24
|
const entities_1 = require("../entities");
|
|
29
25
|
const array_utils_1 = require("./array-utils");
|
|
30
|
-
|
|
26
|
+
exports.addThousandSeparator = (str, separator = '.') => {
|
|
31
27
|
let nStr = (`${str}`);
|
|
32
28
|
if (nStr && separator === ',') {
|
|
33
29
|
nStr = nStr.replace(',', '.');
|
|
@@ -41,13 +37,12 @@ const addThousandSeparator = (str, separator = '.') => {
|
|
|
41
37
|
}
|
|
42
38
|
return x1 + x2;
|
|
43
39
|
};
|
|
44
|
-
exports.
|
|
45
|
-
const formatMoney = (money, currency) => {
|
|
40
|
+
exports.formatMoney = (money, currency) => {
|
|
46
41
|
if (!money) {
|
|
47
42
|
return '';
|
|
48
43
|
}
|
|
49
44
|
let moneyStr = money.toString();
|
|
50
|
-
if (moneyStr &&
|
|
45
|
+
if (moneyStr && array_utils_1.hasElementInArray([currency], [entities_1.CurrencyEnum.ARS]) && moneyStr.includes('.')) {
|
|
51
46
|
const beforeDot = moneyStr.split('.')[0];
|
|
52
47
|
const afterDot = moneyStr.split('.')[1];
|
|
53
48
|
const useDecimals = afterDot.length >= 2 ? 2 : afterDot.length;
|
|
@@ -73,22 +68,19 @@ const formatMoney = (money, currency) => {
|
|
|
73
68
|
else if (!currency || !currency.toLowerCase().includes('pts')) {
|
|
74
69
|
prependSign = '$';
|
|
75
70
|
}
|
|
76
|
-
return prependSign +
|
|
71
|
+
return prependSign + exports.addThousandSeparator(moneyStr, thousandSeparator) + appendSign;
|
|
77
72
|
};
|
|
78
|
-
exports.
|
|
79
|
-
const formatDate = (str, timezone = 'America/Santiago', format = 'DD-MM-YYYY HH:mm:ss') => {
|
|
73
|
+
exports.formatDate = (str, timezone = 'America/Santiago', format = 'DD-MM-YYYY HH:mm:ss') => {
|
|
80
74
|
if (!str) {
|
|
81
75
|
return '';
|
|
82
76
|
}
|
|
83
77
|
const date = new Date(str);
|
|
84
78
|
return moment.tz(date, timezone).format(format);
|
|
85
79
|
};
|
|
86
|
-
exports.
|
|
87
|
-
const formatPct = (pct) => {
|
|
80
|
+
exports.formatPct = (pct) => {
|
|
88
81
|
if (!pct) {
|
|
89
82
|
return '';
|
|
90
83
|
}
|
|
91
84
|
return `${pct}%`.replace('.', ',');
|
|
92
85
|
};
|
|
93
|
-
exports.formatPct = formatPct;
|
|
94
86
|
//# sourceMappingURL=string-formatter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-formatter.js","sourceRoot":"/","sources":["utils/string-formatter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string-formatter.js","sourceRoot":"/","sources":["utils/string-formatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,0CAA2C;AAC3C,+CAAkD;AAErC,QAAA,oBAAoB,GAAG,CAAC,GAAW,EAAE,SAAS,GAAG,GAAG,EAAE,EAAE;IACnE,IAAI,IAAI,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACtB,IAAI,IAAI,IAAI,SAAS,KAAK,GAAG,EAAE;QAC7B,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,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,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAClD,CAAC,CAAC;AAEW,QAAA,SAAS,GAAG,CAAC,GAAoB,EAAU,EAAE;IACxD,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,EAAE,CAAC;KACX;IAED,OAAO,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import * as moment from 'moment-timezone';\nimport { CurrencyEnum } from '../entities';\nimport { hasElementInArray } from './array-utils';\n\nexport const addThousandSeparator = (str: string, separator = '.') => {\n let nStr = (`${str}`);\n if (nStr && separator === ',') {\n nStr = nStr.replace(',', '.');\n }\n\n const x = nStr.split(separator);\n let x1 = x[0];\n const x2 = x.length > 1 ? `${separator}${x[1]}` : '';\n const rgx = /(\\d+)(\\d{3})/;\n while (rgx.test(x1)) {\n x1 = x1.replace(rgx, `$1${separator}$2`);\n }\n return x1 + x2;\n};\n\nexport const formatMoney = (money: number | string, currency?: CurrencyEnum): string => {\n if (!money) {\n return '';\n }\n\n let moneyStr = money.toString();\n\n // TODO: ARS 2 decimals\n if (moneyStr && hasElementInArray([currency], [CurrencyEnum.ARS]) && moneyStr.includes('.')) {\n const beforeDot = moneyStr.split('.')[0];\n const afterDot = moneyStr.split('.')[1];\n\n const useDecimals = afterDot.length >= 2 ? 2 : afterDot.length;\n\n moneyStr = `${beforeDot}.${afterDot.substring(0, useDecimals)}`;\n }\n\n if (typeof money === 'number') {\n moneyStr = moneyStr.replace(/\\./g, ',');\n }\n\n let appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';\n let prependSign = '';\n let thousandSeparator = '.';\n\n if (currency === CurrencyEnum.USD) {\n prependSign = 'U$';\n thousandSeparator = ',';\n } else if (currency === CurrencyEnum.EUR) {\n appendSign = `€ ${appendSign}`.trim();\n } else if (currency === CurrencyEnum.MXN) {\n prependSign = '$';\n thousandSeparator = ',';\n } else if (!currency || !currency.toLowerCase().includes('pts')) {\n prependSign = '$';\n }\n\n return prependSign + addThousandSeparator(moneyStr, thousandSeparator) + appendSign;\n};\n\nexport const formatDate = (str: string, timezone = 'America/Santiago', format = 'DD-MM-YYYY HH:mm:ss'): string => {\n if (!str) {\n return '';\n }\n\n const date = new Date(str);\n\n return moment.tz(date, timezone).format(format);\n};\n\nexport const formatPct = (pct: number | string): string => {\n if (!pct) {\n return '';\n }\n\n return `${pct}%`.replace('.', ',');\n};\n"]}
|
|
@@ -1,57 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.compareNormalizedText = exports.normalizeText = exports.includesStringArray = exports.removeIfEndsWith = exports.replaceMultipleSpacesByOne = exports.removeNewLines = exports.getLastAfter = exports.reverseString = void 0;
|
|
4
|
-
|
|
4
|
+
exports.reverseString = (str) => {
|
|
5
5
|
if (!str) {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
8
|
return str.split('').reverse().join('');
|
|
9
9
|
};
|
|
10
|
-
exports.
|
|
11
|
-
const getLastAfter = (str, after) => {
|
|
10
|
+
exports.getLastAfter = (str, after) => {
|
|
12
11
|
if (!str) {
|
|
13
12
|
return null;
|
|
14
13
|
}
|
|
15
|
-
const reverseSplit =
|
|
14
|
+
const reverseSplit = exports.reverseString(str).split(after);
|
|
16
15
|
if (reverseSplit && reverseSplit.length > 0) {
|
|
17
|
-
return
|
|
16
|
+
return exports.reverseString(reverseSplit[0]);
|
|
18
17
|
}
|
|
19
18
|
return null;
|
|
20
19
|
};
|
|
21
|
-
exports.
|
|
22
|
-
const removeNewLines = (str) => {
|
|
20
|
+
exports.removeNewLines = (str) => {
|
|
23
21
|
if (!str) {
|
|
24
22
|
return null;
|
|
25
23
|
}
|
|
26
24
|
return str.replace(/\r?\n|\r/g, '');
|
|
27
25
|
};
|
|
28
|
-
exports.
|
|
29
|
-
const replaceMultipleSpacesByOne = (str) => {
|
|
26
|
+
exports.replaceMultipleSpacesByOne = (str) => {
|
|
30
27
|
if (!str) {
|
|
31
28
|
return null;
|
|
32
29
|
}
|
|
33
30
|
return str.replace(/\s\s+/g, ' ');
|
|
34
31
|
};
|
|
35
|
-
exports.
|
|
36
|
-
const
|
|
37
|
-
const removedNewLines = (0, exports.removeNewLines)(str);
|
|
32
|
+
exports.removeIfEndsWith = (str, search) => {
|
|
33
|
+
const removedNewLines = exports.removeNewLines(str);
|
|
38
34
|
const trimmed = removedNewLines ? removedNewLines.trim() : null;
|
|
39
35
|
if (trimmed && trimmed.endsWith(search) && trimmed !== search) {
|
|
40
|
-
const reversed =
|
|
36
|
+
const reversed = exports.reverseString(str);
|
|
41
37
|
const substr = reversed.substr(reversed.indexOf(search) + 1, reversed.length);
|
|
42
|
-
return
|
|
38
|
+
return exports.reverseString(substr);
|
|
43
39
|
}
|
|
44
40
|
return str;
|
|
45
41
|
};
|
|
46
|
-
exports.
|
|
47
|
-
const includesStringArray = (str, search) => {
|
|
42
|
+
exports.includesStringArray = (str, search) => {
|
|
48
43
|
if (!str || !search) {
|
|
49
44
|
return false;
|
|
50
45
|
}
|
|
51
46
|
return !!search.find((s) => str.toLowerCase().includes(s.toLowerCase()));
|
|
52
47
|
};
|
|
53
|
-
exports.
|
|
54
|
-
const normalizeText = (str, options = { trim: false, lowerCase: false }) => {
|
|
48
|
+
exports.normalizeText = (str, options = { trim: false, lowerCase: false }) => {
|
|
55
49
|
if (!str) {
|
|
56
50
|
return null;
|
|
57
51
|
}
|
|
@@ -66,10 +60,8 @@ const normalizeText = (str, options = { trim: false, lowerCase: false }) => {
|
|
|
66
60
|
}
|
|
67
61
|
return normalized;
|
|
68
62
|
};
|
|
69
|
-
exports.
|
|
70
|
-
const compareNormalizedText = (str, str2, options = {
|
|
63
|
+
exports.compareNormalizedText = (str, str2, options = {
|
|
71
64
|
trim: true,
|
|
72
65
|
lowerCase: true,
|
|
73
|
-
}) =>
|
|
74
|
-
exports.compareNormalizedText = compareNormalizedText;
|
|
66
|
+
}) => exports.normalizeText(str, options) === exports.normalizeText(str2, options);
|
|
75
67
|
//# sourceMappingURL=string-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-utils.js","sourceRoot":"/","sources":["utils/string-utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"string-utils.js","sourceRoot":"/","sources":["utils/string-utils.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,CAAC,GAAW,EAAU,EAAE;IACnD,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,IAAI,CAAC;KACb;IAED,OAAO,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEW,QAAA,YAAY,GAAG,CAAC,GAAW,EAAE,KAAa,EAAU,EAAE;IACjE,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,IAAI,CAAC;KACb;IAED,MAAM,YAAY,GAAG,qBAAa,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrD,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3C,OAAO,qBAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;KACvC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEW,QAAA,cAAc,GAAG,CAAC,GAAW,EAAU,EAAE;IACpD,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,IAAI,CAAC;KACb;IACD,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC,CAAC;AAEW,QAAA,0BAA0B,GAAG,CAAC,GAAW,EAAU,EAAE;IAChE,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,IAAI,CAAC;KACb;IAED,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAA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AS,EAAE,CAAC;IAEf,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,UAAU,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;KAChC;IAED,IAAI,OAAO,CAAC,SAAS,EAAE;QACrB,UAAU,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;KACvC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEW,QAAA,qBAAqB,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,OAAO,GAAG;IACzE,IAAI,EAAE,IAAI;IACV,SAAS,EAAE,IAAI;CAChB,EAAW,EAAE,CAAC,qBAAa,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,qBAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC","sourcesContent":["export const reverseString = (str: string): string => {\n if (!str) {\n return null;\n }\n\n return str.split('').reverse().join('');\n};\n\nexport const getLastAfter = (str: string, after: string): string => {\n if (!str) {\n return null;\n }\n\n const reverseSplit = reverseString(str).split(after);\n if (reverseSplit && reverseSplit.length > 0) {\n return reverseString(reverseSplit[0]);\n }\n\n return null;\n};\n\nexport const removeNewLines = (str: string): string => {\n if (!str) {\n return null;\n }\n return str.replace(/\\r?\\n|\\r/g, '');\n};\n\nexport const replaceMultipleSpacesByOne = (str: string): string => {\n if (!str) {\n return null;\n }\n\n return str.replace(/\\s\\s+/g, ' ');\n};\n\nexport const removeIfEndsWith = (str: string, search: string): string => {\n const removedNewLines = removeNewLines(str);\n const trimmed = removedNewLines ? removedNewLines.trim() : null;\n if (trimmed && trimmed.endsWith(search) && trimmed !== search) {\n const reversed = reverseString(str);\n const substr = reversed.substr(reversed.indexOf(search) + 1, reversed.length);\n return reverseString(substr);\n }\n\n return str;\n};\n\nexport const includesStringArray = (str: string, search: string[]): boolean => {\n if (!str || !search) {\n return false;\n }\n\n return !!search.find((s) => str.toLowerCase().includes(s.toLowerCase()));\n};\n\nexport const normalizeText = (str: string, options = { trim: false, lowerCase: false }): string => {\n if (!str) {\n return null;\n }\n\n let normalized = str.normalize('NFD')\n .replace(/([aeio])\\u0301|(u)[\\u0301\\u0308]/gi, '$1$2')\n .normalize();\n\n if (options.trim) {\n normalized = normalized.trim();\n }\n\n if (options.lowerCase) {\n normalized = normalized.toLowerCase();\n }\n\n return normalized;\n};\n\nexport const compareNormalizedText = (str: string, str2: string, options = {\n trim: true,\n lowerCase: true,\n}): boolean => normalizeText(str, options) === normalizeText(str2, options);\n"]}
|
package/dist/utils/url-utils.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPathname = exports.getHostname = exports.getParam = exports.isUrl = void 0;
|
|
4
4
|
const url_1 = require("url");
|
|
5
|
-
|
|
5
|
+
exports.isUrl = (s) => {
|
|
6
6
|
try {
|
|
7
7
|
return Boolean(new url_1.URL(s));
|
|
8
8
|
}
|
|
@@ -10,8 +10,7 @@ const isUrl = (s) => {
|
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
exports.
|
|
14
|
-
const getParam = (url, param) => {
|
|
13
|
+
exports.getParam = (url, param) => {
|
|
15
14
|
try {
|
|
16
15
|
return new url_1.URL(url).searchParams.get(param);
|
|
17
16
|
}
|
|
@@ -19,18 +18,15 @@ const getParam = (url, param) => {
|
|
|
19
18
|
return null;
|
|
20
19
|
}
|
|
21
20
|
};
|
|
22
|
-
exports.
|
|
23
|
-
const getHostname = (url) => {
|
|
21
|
+
exports.getHostname = (url) => {
|
|
24
22
|
const { host } = new url_1.URL(url);
|
|
25
23
|
return url.split(host)[0] + host;
|
|
26
24
|
};
|
|
27
|
-
exports.
|
|
28
|
-
const getPathname = (url, includeGetParams = false) => {
|
|
25
|
+
exports.getPathname = (url, includeGetParams = false) => {
|
|
29
26
|
const urlObj = new url_1.URL(url);
|
|
30
27
|
if (includeGetParams) {
|
|
31
28
|
return `${urlObj.pathname}?${urlObj.searchParams}`;
|
|
32
29
|
}
|
|
33
30
|
return urlObj.pathname;
|
|
34
31
|
};
|
|
35
|
-
exports.getPathname = getPathname;
|
|
36
32
|
//# sourceMappingURL=url-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-utils.js","sourceRoot":"/","sources":["utils/url-utils.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;
|
|
1
|
+
{"version":3,"file":"url-utils.js","sourceRoot":"/","sources":["utils/url-utils.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAEb,QAAA,KAAK,GAAG,CAAC,CAAS,EAAW,EAAE;IAC1C,IAAI;QAAE,OAAO,OAAO,CAAC,IAAI,SAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAAE;IAAC,OAAO,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;KAAE;AACjE,CAAC,CAAC;AAEW,QAAA,QAAQ,GAAG,CAAC,GAAW,EAAE,KAAa,EAAU,EAAE;IAC7D,IAAI;QACF,OAAO,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KAC7C;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;AACH,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,CAAC,GAAW,EAAU,EAAE;IACjD,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AACnC,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,CAAC,GAAW,EAAE,gBAAgB,GAAG,KAAK,EAAU,EAAE;IAC3E,MAAM,MAAM,GAAG,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;IAE5B,IAAI,gBAAgB,EAAE;QACpB,OAAO,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;KACpD;IAED,OAAO,MAAM,CAAC,QAAQ,CAAC;AACzB,CAAC,CAAC","sourcesContent":["import { URL } from 'url';\n\nexport const isUrl = (s: string): boolean => {\n try { return Boolean(new URL(s)); } catch (e) { return false; }\n};\n\nexport const getParam = (url: string, param: string): string => {\n try {\n return new URL(url).searchParams.get(param);\n } catch (err) {\n return null;\n }\n};\n\nexport const getHostname = (url: string): string => {\n const { host } = new URL(url);\n return url.split(host)[0] + host;\n};\n\nexport const getPathname = (url: string, includeGetParams = false): string => {\n const urlObj = new URL(url);\n\n if (includeGetParams) {\n return `${urlObj.pathname}?${urlObj.searchParams}`;\n }\n\n return urlObj.pathname;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "store-scrapper-js-common",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lodash": "^4.17.21",
|
|
21
21
|
"moment-timezone": "^0.5.43",
|
|
22
22
|
"rimraf": "^5.0.0",
|
|
23
|
-
"typeorm": "
|
|
23
|
+
"typeorm": "0.3.14"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/jest": "^29.5.1",
|
|
@@ -3,15 +3,17 @@ import { Keyword } from '../entities/keyword';
|
|
|
3
3
|
export class ProcessProductCategoryDto {
|
|
4
4
|
_id: string;
|
|
5
5
|
|
|
6
|
-
name
|
|
6
|
+
name?: string;
|
|
7
7
|
|
|
8
|
-
category
|
|
8
|
+
category?: string;
|
|
9
9
|
|
|
10
|
-
categoryPath
|
|
10
|
+
categoryPath?: string;
|
|
11
11
|
|
|
12
|
-
sku
|
|
12
|
+
sku?: string;
|
|
13
13
|
|
|
14
|
-
storeRef
|
|
14
|
+
storeRef?: string;
|
|
15
|
+
|
|
16
|
+
url?: string;
|
|
15
17
|
|
|
16
18
|
categoryKeywords?: Keyword[];
|
|
17
19
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseEntity,
|
|
3
|
-
CreateDateColumn,
|
|
3
|
+
CreateDateColumn, ObjectID, ObjectIdColumn, UpdateDateColumn,
|
|
4
4
|
} from 'typeorm';
|
|
5
5
|
|
|
6
6
|
export abstract class AbstractBase extends BaseEntity {
|
|
7
7
|
@ObjectIdColumn()
|
|
8
|
-
_id?:
|
|
8
|
+
_id?: ObjectID;
|
|
9
9
|
|
|
10
10
|
@CreateDateColumn()
|
|
11
11
|
createdAt?: Date;
|
|
@@ -15,12 +15,22 @@ export enum TelegramQueueEnum {
|
|
|
15
15
|
TELEGRAM_ALERT_PUBLIC_13 = 'telegram_alert_public_13',
|
|
16
16
|
TELEGRAM_ALERT_PUBLIC_14 = 'telegram_alert_public_14',
|
|
17
17
|
TELEGRAM_ALERT_PUBLIC_15 = 'telegram_alert_public_15',
|
|
18
|
+
TELEGRAM_ALERT_PUBLIC_16 = 'telegram_alert_public_16',
|
|
19
|
+
TELEGRAM_ALERT_PUBLIC_17 = 'telegram_alert_public_17',
|
|
20
|
+
TELEGRAM_ALERT_PUBLIC_18 = 'telegram_alert_public_18',
|
|
21
|
+
TELEGRAM_ALERT_PUBLIC_19 = 'telegram_alert_public_19',
|
|
22
|
+
TELEGRAM_ALERT_PUBLIC_20 = 'telegram_alert_public_20',
|
|
18
23
|
|
|
19
24
|
TELEGRAM_PRIVATE_1 = 'telegram_private_1',
|
|
20
25
|
TELEGRAM_PRIVATE_2 = 'telegram_private_2',
|
|
21
26
|
TELEGRAM_PRIVATE_3 = 'telegram_private_3',
|
|
22
27
|
TELEGRAM_PRIVATE_4 = 'telegram_private_4',
|
|
23
28
|
TELEGRAM_PRIVATE_5 = 'telegram_private_5',
|
|
29
|
+
TELEGRAM_PRIVATE_6 = 'telegram_private_6',
|
|
30
|
+
TELEGRAM_PRIVATE_7 = 'telegram_private_7',
|
|
31
|
+
TELEGRAM_PRIVATE_8 = 'telegram_private_8',
|
|
32
|
+
TELEGRAM_PRIVATE_9 = 'telegram_private_9',
|
|
33
|
+
TELEGRAM_PRIVATE_10 = 'telegram_private_10',
|
|
24
34
|
|
|
25
35
|
TELEGRAM_ARG_PUBLIC_1 = 'telegram_arg_public_1',
|
|
26
36
|
TELEGRAM_ARG_PUBLIC_2 = 'telegram_arg_public_2',
|
|
@@ -105,6 +115,18 @@ export enum TelegramQueueEnum {
|
|
|
105
115
|
TELEGRAM_RESELLER_PUBLIC_8 = 'telegram_reseller_public_8',
|
|
106
116
|
TELEGRAM_RESELLER_PUBLIC_9 = 'telegram_reseller_public_9',
|
|
107
117
|
TELEGRAM_RESELLER_PUBLIC_10 = 'telegram_reseller_public_10',
|
|
118
|
+
TELEGRAM_RESELLER_PUBLIC_11 = 'telegram_reseller_public_11',
|
|
119
|
+
TELEGRAM_RESELLER_PUBLIC_12 = 'telegram_reseller_public_12',
|
|
120
|
+
TELEGRAM_RESELLER_PUBLIC_13 = 'telegram_reseller_public_13',
|
|
121
|
+
TELEGRAM_RESELLER_PUBLIC_14 = 'telegram_reseller_public_14',
|
|
122
|
+
TELEGRAM_RESELLER_PUBLIC_15 = 'telegram_reseller_public_15',
|
|
123
|
+
TELEGRAM_RESELLER_PUBLIC_16 = 'telegram_reseller_public_16',
|
|
124
|
+
TELEGRAM_RESELLER_PUBLIC_17 = 'telegram_reseller_public_17',
|
|
125
|
+
TELEGRAM_RESELLER_PUBLIC_18 = 'telegram_reseller_public_18',
|
|
126
|
+
TELEGRAM_RESELLER_PUBLIC_19 = 'telegram_reseller_public_19',
|
|
127
|
+
TELEGRAM_RESELLER_PUBLIC_20 = 'telegram_reseller_public_20',
|
|
128
|
+
TELEGRAM_RESELLER_PUBLIC_21 = 'telegram_reseller_public_21',
|
|
129
|
+
TELEGRAM_RESELLER_PUBLIC_22 = 'telegram_reseller_public_22',
|
|
108
130
|
|
|
109
131
|
TELEGRAM_RESENT_PRIVATE_1 = 'TELEGRAM_RESENT_PRIVATE_1',
|
|
110
132
|
TELEGRAM_RESENT_PRIVATE_2 = 'TELEGRAM_RESENT_PRIVATE_2',
|
|
@@ -288,6 +310,49 @@ export enum TelegramQueueEnum {
|
|
|
288
310
|
TELEGRAM_RESELLER_159 = 'telegram_reseller_159',
|
|
289
311
|
TELEGRAM_RESELLER_160 = 'telegram_reseller_160',
|
|
290
312
|
|
|
313
|
+
TELEGRAM_RESELLER_161 = 'telegram_reseller_161',
|
|
314
|
+
TELEGRAM_RESELLER_162 = 'telegram_reseller_162',
|
|
315
|
+
TELEGRAM_RESELLER_163 = 'telegram_reseller_163',
|
|
316
|
+
TELEGRAM_RESELLER_164 = 'telegram_reseller_164',
|
|
317
|
+
TELEGRAM_RESELLER_165 = 'telegram_reseller_165',
|
|
318
|
+
TELEGRAM_RESELLER_166 = 'telegram_reseller_166',
|
|
319
|
+
TELEGRAM_RESELLER_167 = 'telegram_reseller_167',
|
|
320
|
+
TELEGRAM_RESELLER_168 = 'telegram_reseller_168',
|
|
321
|
+
TELEGRAM_RESELLER_169 = 'telegram_reseller_169',
|
|
322
|
+
TELEGRAM_RESELLER_170 = 'telegram_reseller_170',
|
|
323
|
+
|
|
324
|
+
TELEGRAM_RESELLER_171 = 'telegram_reseller_171',
|
|
325
|
+
TELEGRAM_RESELLER_172 = 'telegram_reseller_172',
|
|
326
|
+
TELEGRAM_RESELLER_173 = 'telegram_reseller_173',
|
|
327
|
+
TELEGRAM_RESELLER_174 = 'telegram_reseller_174',
|
|
328
|
+
TELEGRAM_RESELLER_175 = 'telegram_reseller_175',
|
|
329
|
+
TELEGRAM_RESELLER_176 = 'telegram_reseller_176',
|
|
330
|
+
TELEGRAM_RESELLER_177 = 'telegram_reseller_177',
|
|
331
|
+
TELEGRAM_RESELLER_178 = 'telegram_reseller_178',
|
|
332
|
+
TELEGRAM_RESELLER_179 = 'telegram_reseller_179',
|
|
333
|
+
TELEGRAM_RESELLER_180 = 'telegram_reseller_180',
|
|
334
|
+
|
|
335
|
+
TELEGRAM_RESELLER_181 = 'telegram_reseller_181',
|
|
336
|
+
TELEGRAM_RESELLER_182 = 'telegram_reseller_182',
|
|
337
|
+
TELEGRAM_RESELLER_183 = 'telegram_reseller_183',
|
|
338
|
+
TELEGRAM_RESELLER_184 = 'telegram_reseller_184',
|
|
339
|
+
TELEGRAM_RESELLER_185 = 'telegram_reseller_185',
|
|
340
|
+
TELEGRAM_RESELLER_186 = 'telegram_reseller_186',
|
|
341
|
+
TELEGRAM_RESELLER_187 = 'telegram_reseller_187',
|
|
342
|
+
TELEGRAM_RESELLER_188 = 'telegram_reseller_188',
|
|
343
|
+
TELEGRAM_RESELLER_189 = 'telegram_reseller_189',
|
|
344
|
+
TELEGRAM_RESELLER_190 = 'telegram_reseller_190',
|
|
345
|
+
TELEGRAM_RESELLER_191 = 'telegram_reseller_191',
|
|
346
|
+
TELEGRAM_RESELLER_192 = 'telegram_reseller_192',
|
|
347
|
+
TELEGRAM_RESELLER_193 = 'telegram_reseller_193',
|
|
348
|
+
TELEGRAM_RESELLER_194 = 'telegram_reseller_194',
|
|
349
|
+
TELEGRAM_RESELLER_195 = 'telegram_reseller_195',
|
|
350
|
+
TELEGRAM_RESELLER_196 = 'telegram_reseller_196',
|
|
351
|
+
TELEGRAM_RESELLER_197 = 'telegram_reseller_197',
|
|
352
|
+
TELEGRAM_RESELLER_198 = 'telegram_reseller_198',
|
|
353
|
+
TELEGRAM_RESELLER_199 = 'telegram_reseller_199',
|
|
354
|
+
TELEGRAM_RESELLER_200 = 'telegram_reseller_200',
|
|
355
|
+
|
|
291
356
|
TELEGRAM_RESELLER_CURRENT_PRICE_1 = 'telegram_reseller_current_price_1',
|
|
292
357
|
TELEGRAM_RESELLER_CURRENT_PRICE_2 = 'telegram_reseller_current_price_2',
|
|
293
358
|
TELEGRAM_RESELLER_CURRENT_PRICE_3 = 'telegram_reseller_current_price_3',
|