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