@infrab4a/connect 3.9.0-beta.10 → 3.9.0-beta.3
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/bundles/infrab4a-connect.umd.js +134 -142
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/esm2015/infra/elasticsearch/adapters/axios.adapter.js +6 -23
- package/esm2015/infra/elasticsearch/adapters/index.js +2 -1
- package/esm2015/infra/elasticsearch/indexes/products-index.js +117 -79
- package/fesm2015/infrab4a-connect.js +121 -98
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/infra/elasticsearch/adapters/axios.adapter.d.ts +2 -4
- package/infra/elasticsearch/indexes/products-index.d.ts +3 -5
- package/package.json +1 -1
- package/esm2015/infra/elasticsearch/adapters/elastic-search.adapter.js +0 -2
- package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +0 -8
|
@@ -1761,10 +1761,7 @@
|
|
|
1761
1761
|
url: this.config.url + "/" + index + "/_doc/" + id,
|
|
1762
1762
|
method: 'GET',
|
|
1763
1763
|
responseType: 'json',
|
|
1764
|
-
headers: {
|
|
1765
|
-
'Content-Type': 'application/json',
|
|
1766
|
-
Authorization: "ApiKey " + this.config.credential,
|
|
1767
|
-
},
|
|
1764
|
+
headers: { Authorization: "ApiKey " + this.config.credential, 'Content-Type': 'application/x-ndjson' },
|
|
1768
1765
|
})];
|
|
1769
1766
|
case 1:
|
|
1770
1767
|
data = (_a.sent()).data;
|
|
@@ -1786,11 +1783,7 @@
|
|
|
1786
1783
|
url: this.config.url + "/" + index + "/_search",
|
|
1787
1784
|
method: 'POST',
|
|
1788
1785
|
responseType: 'json',
|
|
1789
|
-
headers: {
|
|
1790
|
-
Accept: 'application/vnd.elasticsearch+json;compatible-with=7',
|
|
1791
|
-
'Content-Type': 'application/vnd.elasticsearch+json;compatible-with=7',
|
|
1792
|
-
Authorization: "ApiKey " + this.config.credential,
|
|
1793
|
-
},
|
|
1786
|
+
headers: { Authorization: "ApiKey " + this.config.credential, 'Content-Type': 'application/x-ndjson' },
|
|
1794
1787
|
data: query,
|
|
1795
1788
|
})];
|
|
1796
1789
|
case 1:
|
|
@@ -1808,24 +1801,7 @@
|
|
|
1808
1801
|
return __generator(this, function (_a) {
|
|
1809
1802
|
switch (_a.label) {
|
|
1810
1803
|
case 0: return [4 /*yield*/, axios__default["default"]({
|
|
1811
|
-
url: this.config.url + "/" + index
|
|
1812
|
-
method: 'POST',
|
|
1813
|
-
headers: { Authorization: "ApiKey " + this.config.credential },
|
|
1814
|
-
data: data,
|
|
1815
|
-
})];
|
|
1816
|
-
case 1:
|
|
1817
|
-
_a.sent();
|
|
1818
|
-
return [2 /*return*/];
|
|
1819
|
-
}
|
|
1820
|
-
});
|
|
1821
|
-
});
|
|
1822
|
-
};
|
|
1823
|
-
AxiosAdapter.prototype.update = function (index, id, data) {
|
|
1824
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1825
|
-
return __generator(this, function (_a) {
|
|
1826
|
-
switch (_a.label) {
|
|
1827
|
-
case 0: return [4 /*yield*/, axios__default["default"]({
|
|
1828
|
-
url: this.config.url + "/" + index + "/_update/" + id,
|
|
1804
|
+
url: this.config.url + "/" + index,
|
|
1829
1805
|
method: 'PUT',
|
|
1830
1806
|
headers: { Authorization: "ApiKey " + this.config.credential },
|
|
1831
1807
|
data: data,
|
|
@@ -1837,12 +1813,12 @@
|
|
|
1837
1813
|
});
|
|
1838
1814
|
});
|
|
1839
1815
|
};
|
|
1840
|
-
AxiosAdapter.prototype.delete = function (index
|
|
1816
|
+
AxiosAdapter.prototype.delete = function (index) {
|
|
1841
1817
|
return __awaiter(this, void 0, void 0, function () {
|
|
1842
1818
|
return __generator(this, function (_a) {
|
|
1843
1819
|
switch (_a.label) {
|
|
1844
1820
|
case 0: return [4 /*yield*/, axios__default["default"]({
|
|
1845
|
-
url: this.config.url + "/" + index
|
|
1821
|
+
url: this.config.url + "/" + index,
|
|
1846
1822
|
method: 'DELETE',
|
|
1847
1823
|
headers: { Authorization: "ApiKey " + this.config.credential },
|
|
1848
1824
|
})];
|
|
@@ -1856,17 +1832,18 @@
|
|
|
1856
1832
|
return AxiosAdapter;
|
|
1857
1833
|
}());
|
|
1858
1834
|
|
|
1835
|
+
// export * from './elastic-search.adapter'
|
|
1836
|
+
|
|
1859
1837
|
var ProductsIndex = /** @class */ (function () {
|
|
1860
1838
|
function ProductsIndex(adapter) {
|
|
1861
1839
|
this.adapter = adapter;
|
|
1862
|
-
this.index = "products";
|
|
1863
1840
|
}
|
|
1864
|
-
ProductsIndex.prototype.
|
|
1841
|
+
ProductsIndex.prototype.get = function (id) {
|
|
1865
1842
|
return __awaiter(this, void 0, void 0, function () {
|
|
1866
1843
|
var data;
|
|
1867
1844
|
return __generator(this, function (_a) {
|
|
1868
1845
|
switch (_a.label) {
|
|
1869
|
-
case 0: return [4 /*yield*/, this.adapter.get(
|
|
1846
|
+
case 0: return [4 /*yield*/, this.adapter.get('products', id)];
|
|
1870
1847
|
case 1:
|
|
1871
1848
|
data = _a.sent();
|
|
1872
1849
|
return [2 /*return*/, Product.toInstance(data)];
|
|
@@ -1874,153 +1851,168 @@
|
|
|
1874
1851
|
});
|
|
1875
1852
|
});
|
|
1876
1853
|
};
|
|
1877
|
-
ProductsIndex.prototype.
|
|
1854
|
+
ProductsIndex.prototype.search = function (searchTerm) {
|
|
1878
1855
|
return __awaiter(this, void 0, void 0, function () {
|
|
1879
|
-
var
|
|
1856
|
+
var search;
|
|
1880
1857
|
return __generator(this, function (_a) {
|
|
1881
1858
|
switch (_a.label) {
|
|
1882
|
-
case 0: return [4 /*yield*/, this.adapter.query(
|
|
1859
|
+
case 0: return [4 /*yield*/, this.adapter.query('products', {
|
|
1883
1860
|
query: {
|
|
1884
1861
|
bool: {
|
|
1885
1862
|
must: {
|
|
1886
|
-
|
|
1887
|
-
|
|
1863
|
+
multi_match: {
|
|
1864
|
+
query: "" + searchTerm,
|
|
1865
|
+
fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
|
|
1866
|
+
fuzziness: 2,
|
|
1888
1867
|
},
|
|
1889
1868
|
},
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
case 1:
|
|
1894
|
-
data = _a.sent();
|
|
1895
|
-
return [2 /*return*/, Product.toInstance(data.hits[0]._source)];
|
|
1896
|
-
}
|
|
1897
|
-
});
|
|
1898
|
-
});
|
|
1899
|
-
};
|
|
1900
|
-
ProductsIndex.prototype.search = function (searchTerm, total, shop) {
|
|
1901
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1902
|
-
var size, fields, filter, search;
|
|
1903
|
-
return __generator(this, function (_a) {
|
|
1904
|
-
switch (_a.label) {
|
|
1905
|
-
case 0:
|
|
1906
|
-
size = total >= 10 ? 500 : 9;
|
|
1907
|
-
fields = [
|
|
1908
|
-
'EAN',
|
|
1909
|
-
'brand',
|
|
1910
|
-
'id',
|
|
1911
|
-
'images',
|
|
1912
|
-
'miniatures',
|
|
1913
|
-
'name',
|
|
1914
|
-
'price',
|
|
1915
|
-
'sku',
|
|
1916
|
-
'stock',
|
|
1917
|
-
'slug',
|
|
1918
|
-
'reviews',
|
|
1919
|
-
'hasVariants',
|
|
1920
|
-
'rate',
|
|
1921
|
-
];
|
|
1922
|
-
filter = [{ term: { published: true } }];
|
|
1923
|
-
if (size > 9) {
|
|
1924
|
-
fields.push.apply(fields, ['pricePaid', 'isGift', 'stock', 'weight', 'tags']);
|
|
1925
|
-
}
|
|
1926
|
-
else {
|
|
1927
|
-
filter.push({ term: { tags: shop == exports.Shops.GLAMSHOP ? 'feminino' : 'masculino' } });
|
|
1928
|
-
}
|
|
1929
|
-
return [4 /*yield*/, this.adapter.query(this.index, {
|
|
1930
|
-
size: size,
|
|
1931
|
-
_source: fields,
|
|
1932
|
-
query: {
|
|
1933
|
-
bool: {
|
|
1934
|
-
must: {
|
|
1935
|
-
multi_match: {
|
|
1869
|
+
should: {
|
|
1870
|
+
match_phrase_prefix: {
|
|
1871
|
+
'name.search': {
|
|
1936
1872
|
query: "" + searchTerm,
|
|
1937
|
-
|
|
1938
|
-
fields: [
|
|
1939
|
-
'name',
|
|
1940
|
-
'name.folded',
|
|
1941
|
-
'name.search',
|
|
1942
|
-
'description',
|
|
1943
|
-
'description.search',
|
|
1944
|
-
'description.folded',
|
|
1945
|
-
'brand',
|
|
1946
|
-
'brand.search',
|
|
1947
|
-
'brand.folded',
|
|
1948
|
-
],
|
|
1949
|
-
fuzziness: 2,
|
|
1873
|
+
slop: 10,
|
|
1950
1874
|
},
|
|
1951
1875
|
},
|
|
1952
|
-
should: {
|
|
1953
|
-
match_phrase_prefix: {
|
|
1954
|
-
'name.search': {
|
|
1955
|
-
query: "" + searchTerm,
|
|
1956
|
-
slop: 10,
|
|
1957
|
-
},
|
|
1958
|
-
},
|
|
1959
|
-
},
|
|
1960
|
-
filter: filter,
|
|
1961
1876
|
},
|
|
1877
|
+
filter: [{ term: { published: true } }],
|
|
1962
1878
|
},
|
|
1963
|
-
}
|
|
1879
|
+
},
|
|
1880
|
+
})];
|
|
1964
1881
|
case 1:
|
|
1965
1882
|
search = _a.sent();
|
|
1883
|
+
// const search = await this.esadapter.search(`products`, {
|
|
1884
|
+
// bool: {
|
|
1885
|
+
// must: {
|
|
1886
|
+
// multi_match: {
|
|
1887
|
+
// query: `${searchTerm}`,
|
|
1888
|
+
// fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
|
|
1889
|
+
// fuzziness: 2,
|
|
1890
|
+
// },
|
|
1891
|
+
// },
|
|
1892
|
+
// should: {
|
|
1893
|
+
// match_phrase_prefix: {
|
|
1894
|
+
// 'name.search': {
|
|
1895
|
+
// query: `${searchTerm}`,
|
|
1896
|
+
// slop: 10,
|
|
1897
|
+
// },
|
|
1898
|
+
// },
|
|
1899
|
+
// },
|
|
1900
|
+
// filter: [{ term: { published: true } }],
|
|
1901
|
+
// },
|
|
1902
|
+
// })
|
|
1903
|
+
search.hits.forEach(function (row) {
|
|
1904
|
+
row._source.price = Object.assign(Object.assign({}, row._source.price), (!!row._source.price.Glamshop && row._source.price.Glamshop));
|
|
1905
|
+
});
|
|
1966
1906
|
search.hits = search.hits.filter(function (e) { return e._source.name !== ''; });
|
|
1967
1907
|
return [2 /*return*/, search];
|
|
1968
1908
|
}
|
|
1969
1909
|
});
|
|
1970
1910
|
});
|
|
1971
1911
|
};
|
|
1912
|
+
// async findById(ids: string[], options?: { hasStock: boolean; size: number; shop: Shops }): Promise<Product[]> {
|
|
1913
|
+
// const fields = [
|
|
1914
|
+
// 'brand',
|
|
1915
|
+
// 'id',
|
|
1916
|
+
// 'images',
|
|
1917
|
+
// 'miniatures',
|
|
1918
|
+
// 'name',
|
|
1919
|
+
// 'price',
|
|
1920
|
+
// 'sku',
|
|
1921
|
+
// 'stock',
|
|
1922
|
+
// 'slug',
|
|
1923
|
+
// 'reviews',
|
|
1924
|
+
// 'pricePaid',
|
|
1925
|
+
// 'isGift',
|
|
1926
|
+
// 'stock',
|
|
1927
|
+
// 'weight',
|
|
1928
|
+
// 'tags',
|
|
1929
|
+
// 'filters',
|
|
1930
|
+
// 'hasVariants',
|
|
1931
|
+
// 'type',
|
|
1932
|
+
// ]
|
|
1933
|
+
// const { hits } = await this.adapter.query('products/_search', {
|
|
1934
|
+
// _source: fields,
|
|
1935
|
+
// query: {
|
|
1936
|
+
// bool: {
|
|
1937
|
+
// filter: [
|
|
1938
|
+
// {
|
|
1939
|
+
// terms: {
|
|
1940
|
+
// _id: ids,
|
|
1941
|
+
// },
|
|
1942
|
+
// },
|
|
1943
|
+
// {
|
|
1944
|
+
// term: {
|
|
1945
|
+
// published: true,
|
|
1946
|
+
// },
|
|
1947
|
+
// },
|
|
1948
|
+
// ...(options.hasStock
|
|
1949
|
+
// ? [
|
|
1950
|
+
// {
|
|
1951
|
+
// range: {
|
|
1952
|
+
// 'stock.quantity': {
|
|
1953
|
+
// gt: 0,
|
|
1954
|
+
// },
|
|
1955
|
+
// },
|
|
1956
|
+
// },
|
|
1957
|
+
// ]
|
|
1958
|
+
// : []),
|
|
1959
|
+
// ],
|
|
1960
|
+
// },
|
|
1961
|
+
// },
|
|
1962
|
+
// ...(options.size ? { size: options.size } : {}),
|
|
1963
|
+
// })
|
|
1964
|
+
// return hits.map((hit) => Product.toInstance(hit._source))
|
|
1965
|
+
// }
|
|
1972
1966
|
ProductsIndex.prototype.save = function (product) {
|
|
1973
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1974
|
-
var createdAt, updatedAt, kitProducts, data;
|
|
1975
|
-
return __generator(this, function (_a) {
|
|
1976
|
-
try {
|
|
1977
|
-
createdAt = product.createdAt, updatedAt = product.updatedAt, kitProducts = product.kitProducts, data = __rest(product, ["createdAt", "updatedAt", "kitProducts"]);
|
|
1978
|
-
this.adapter.save(this.index, data);
|
|
1979
|
-
}
|
|
1980
|
-
catch (error) {
|
|
1981
|
-
console.error(error);
|
|
1982
|
-
}
|
|
1983
|
-
return [2 /*return*/];
|
|
1984
|
-
});
|
|
1985
|
-
});
|
|
1986
|
-
};
|
|
1987
|
-
ProductsIndex.prototype.update = function (product) {
|
|
1988
1967
|
return __awaiter(this, void 0, void 0, function () {
|
|
1989
1968
|
var error_1;
|
|
1990
1969
|
return __generator(this, function (_a) {
|
|
1991
1970
|
switch (_a.label) {
|
|
1992
1971
|
case 0:
|
|
1993
|
-
|
|
1994
|
-
|
|
1972
|
+
// try {
|
|
1973
|
+
// const { createdAt, updatedAt, kitProducts, ...data } = product
|
|
1974
|
+
// this.esadapter.save(`product`, data)
|
|
1975
|
+
// } catch (error) {
|
|
1976
|
+
// console.error(error)
|
|
1977
|
+
// }
|
|
1978
|
+
delete product.createdAt;
|
|
1979
|
+
delete product.updatedAt;
|
|
1980
|
+
delete product.kitProducts;
|
|
1981
|
+
_a.label = 1;
|
|
1995
1982
|
case 1:
|
|
1996
|
-
_a.
|
|
1997
|
-
|
|
1983
|
+
_a.trys.push([1, 4, , 6]);
|
|
1984
|
+
if (!product.firestoreId)
|
|
1985
|
+
throw new Error('Is not a product from firestore');
|
|
1986
|
+
return [4 /*yield*/, this.get(product.firestoreId)];
|
|
1998
1987
|
case 2:
|
|
1988
|
+
_a.sent();
|
|
1989
|
+
return [4 /*yield*/, this.adapter.save("products/_doc/" + product.firestoreId, product.toPlain())];
|
|
1990
|
+
case 3:
|
|
1991
|
+
_a.sent();
|
|
1992
|
+
return [3 /*break*/, 6];
|
|
1993
|
+
case 4:
|
|
1999
1994
|
error_1 = _a.sent();
|
|
2000
|
-
console.error(error_1);
|
|
2001
|
-
return [
|
|
2002
|
-
case
|
|
1995
|
+
console.error(error_1.message);
|
|
1996
|
+
return [4 /*yield*/, this.adapter.save("products/_doc/" + product.id, product.toPlain())];
|
|
1997
|
+
case 5:
|
|
1998
|
+
_a.sent();
|
|
1999
|
+
return [3 /*break*/, 6];
|
|
2000
|
+
case 6: return [2 /*return*/];
|
|
2003
2001
|
}
|
|
2004
2002
|
});
|
|
2005
2003
|
});
|
|
2006
2004
|
};
|
|
2005
|
+
ProductsIndex.prototype.update = function (product) {
|
|
2006
|
+
// try {
|
|
2007
|
+
// this.esadapter.update(`products`, product.id, product)
|
|
2008
|
+
// } catch (error) {
|
|
2009
|
+
// console.error(error)
|
|
2010
|
+
// }
|
|
2011
|
+
};
|
|
2007
2012
|
ProductsIndex.prototype.delete = function (id) {
|
|
2008
2013
|
return __awaiter(this, void 0, void 0, function () {
|
|
2009
|
-
var error_2;
|
|
2010
2014
|
return __generator(this, function (_a) {
|
|
2011
|
-
|
|
2012
|
-
case 0:
|
|
2013
|
-
_a.trys.push([0, 2, , 3]);
|
|
2014
|
-
return [4 /*yield*/, this.adapter.delete(this.index, id)];
|
|
2015
|
-
case 1:
|
|
2016
|
-
_a.sent();
|
|
2017
|
-
return [3 /*break*/, 3];
|
|
2018
|
-
case 2:
|
|
2019
|
-
error_2 = _a.sent();
|
|
2020
|
-
console.error(error_2);
|
|
2021
|
-
return [3 /*break*/, 3];
|
|
2022
|
-
case 3: return [2 /*return*/];
|
|
2023
|
-
}
|
|
2015
|
+
return [2 /*return*/];
|
|
2024
2016
|
});
|
|
2025
2017
|
});
|
|
2026
2018
|
};
|