@infrab4a/connect 3.9.0-beta.3 → 3.9.0-beta.5

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.
@@ -1761,7 +1761,10 @@
1761
1761
  url: this.config.url + "/" + index + "/_doc/" + id,
1762
1762
  method: 'GET',
1763
1763
  responseType: 'json',
1764
- headers: { Authorization: "ApiKey " + this.config.credential, 'Content-Type': 'application/x-ndjson' },
1764
+ headers: {
1765
+ 'Content-Type': 'application/json',
1766
+ Authorization: "ApiKey " + this.config.credential,
1767
+ },
1765
1768
  })];
1766
1769
  case 1:
1767
1770
  data = (_a.sent()).data;
@@ -1783,7 +1786,11 @@
1783
1786
  url: this.config.url + "/" + index + "/_search",
1784
1787
  method: 'POST',
1785
1788
  responseType: 'json',
1786
- headers: { Authorization: "ApiKey " + this.config.credential, 'Content-Type': 'application/x-ndjson' },
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
+ },
1787
1794
  data: query,
1788
1795
  })];
1789
1796
  case 1:
@@ -1801,7 +1808,24 @@
1801
1808
  return __generator(this, function (_a) {
1802
1809
  switch (_a.label) {
1803
1810
  case 0: return [4 /*yield*/, axios__default["default"]({
1804
- 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,
1805
1829
  method: 'PUT',
1806
1830
  headers: { Authorization: "ApiKey " + this.config.credential },
1807
1831
  data: data,
@@ -1813,12 +1837,12 @@
1813
1837
  });
1814
1838
  });
1815
1839
  };
1816
- AxiosAdapter.prototype.delete = function (index) {
1840
+ AxiosAdapter.prototype.delete = function (index, id) {
1817
1841
  return __awaiter(this, void 0, void 0, function () {
1818
1842
  return __generator(this, function (_a) {
1819
1843
  switch (_a.label) {
1820
1844
  case 0: return [4 /*yield*/, axios__default["default"]({
1821
- url: this.config.url + "/" + index,
1845
+ url: this.config.url + "/" + index + "/_doc/" + id,
1822
1846
  method: 'DELETE',
1823
1847
  headers: { Authorization: "ApiKey " + this.config.credential },
1824
1848
  })];
@@ -1837,13 +1861,14 @@
1837
1861
  var ProductsIndex = /** @class */ (function () {
1838
1862
  function ProductsIndex(adapter) {
1839
1863
  this.adapter = adapter;
1864
+ this.index = "products";
1840
1865
  }
1841
- ProductsIndex.prototype.get = function (id) {
1866
+ ProductsIndex.prototype.getById = function (id) {
1842
1867
  return __awaiter(this, void 0, void 0, function () {
1843
1868
  var data;
1844
1869
  return __generator(this, function (_a) {
1845
1870
  switch (_a.label) {
1846
- case 0: return [4 /*yield*/, this.adapter.get('products', id)];
1871
+ case 0: return [4 /*yield*/, this.adapter.get(this.index, id)];
1847
1872
  case 1:
1848
1873
  data = _a.sent();
1849
1874
  return [2 /*return*/, Product.toInstance(data)];
@@ -1851,12 +1876,35 @@
1851
1876
  });
1852
1877
  });
1853
1878
  };
1879
+ ProductsIndex.prototype.getByAlloyId = function (id) {
1880
+ return __awaiter(this, void 0, void 0, function () {
1881
+ var data;
1882
+ return __generator(this, function (_a) {
1883
+ switch (_a.label) {
1884
+ case 0: return [4 /*yield*/, this.adapter.query(this.index, {
1885
+ query: {
1886
+ bool: {
1887
+ must: {
1888
+ match: {
1889
+ id: id,
1890
+ },
1891
+ },
1892
+ },
1893
+ },
1894
+ })];
1895
+ case 1:
1896
+ data = _a.sent();
1897
+ return [2 /*return*/, Product.toInstance(data.hits[0]._source)];
1898
+ }
1899
+ });
1900
+ });
1901
+ };
1854
1902
  ProductsIndex.prototype.search = function (searchTerm) {
1855
1903
  return __awaiter(this, void 0, void 0, function () {
1856
1904
  var search;
1857
1905
  return __generator(this, function (_a) {
1858
1906
  switch (_a.label) {
1859
- case 0: return [4 /*yield*/, this.adapter.query('products', {
1907
+ case 0: return [4 /*yield*/, this.adapter.query(this.index, {
1860
1908
  query: {
1861
1909
  bool: {
1862
1910
  must: {
@@ -1880,26 +1928,6 @@
1880
1928
  })];
1881
1929
  case 1:
1882
1930
  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
1931
  search.hits.forEach(function (row) {
1904
1932
  row._source.price = Object.assign(Object.assign({}, row._source.price), (!!row._source.price.Glamshop && row._source.price.Glamshop));
1905
1933
  });
@@ -1909,110 +1937,58 @@
1909
1937
  });
1910
1938
  });
1911
1939
  };
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
- // }
1966
1940
  ProductsIndex.prototype.save = function (product) {
1941
+ return __awaiter(this, void 0, void 0, function () {
1942
+ var createdAt, updatedAt, kitProducts, data;
1943
+ return __generator(this, function (_a) {
1944
+ try {
1945
+ createdAt = product.createdAt, updatedAt = product.updatedAt, kitProducts = product.kitProducts, data = __rest(product, ["createdAt", "updatedAt", "kitProducts"]);
1946
+ this.adapter.save(this.index, data);
1947
+ }
1948
+ catch (error) {
1949
+ console.error(error);
1950
+ }
1951
+ return [2 /*return*/];
1952
+ });
1953
+ });
1954
+ };
1955
+ ProductsIndex.prototype.update = function (product) {
1967
1956
  return __awaiter(this, void 0, void 0, function () {
1968
1957
  var error_1;
1969
1958
  return __generator(this, function (_a) {
1970
1959
  switch (_a.label) {
1971
1960
  case 0:
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;
1961
+ _a.trys.push([0, 2, , 3]);
1962
+ return [4 /*yield*/, this.adapter.update(this.index, product.id, product)];
1982
1963
  case 1:
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)];
1987
- case 2:
1988
1964
  _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:
1965
+ return [3 /*break*/, 3];
1966
+ case 2:
1994
1967
  error_1 = _a.sent();
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*/];
1968
+ console.error(error_1);
1969
+ return [3 /*break*/, 3];
1970
+ case 3: return [2 /*return*/];
2001
1971
  }
2002
1972
  });
2003
1973
  });
2004
1974
  };
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
- };
2012
1975
  ProductsIndex.prototype.delete = function (id) {
2013
1976
  return __awaiter(this, void 0, void 0, function () {
1977
+ var error_2;
2014
1978
  return __generator(this, function (_a) {
2015
- return [2 /*return*/];
1979
+ switch (_a.label) {
1980
+ case 0:
1981
+ _a.trys.push([0, 2, , 3]);
1982
+ return [4 /*yield*/, this.adapter.delete(this.index, id)];
1983
+ case 1:
1984
+ _a.sent();
1985
+ return [3 /*break*/, 3];
1986
+ case 2:
1987
+ error_2 = _a.sent();
1988
+ console.error(error_2);
1989
+ return [3 /*break*/, 3];
1990
+ case 3: return [2 /*return*/];
1991
+ }
2016
1992
  });
2017
1993
  });
2018
1994
  };