@infrab4a/connect 3.9.0-beta.1 → 3.9.0-beta.2

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata'), require('class-transformer'), require('date-fns'), require('lodash'), require('ts-custom-error'), require('axios'), require('@elastic/elasticsearch'), require('firebase'), require('gql-query-builder')) :
3
- typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'reflect-metadata', 'class-transformer', 'date-fns', 'lodash', 'ts-custom-error', 'axios', '@elastic/elasticsearch', 'firebase', 'gql-query-builder'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), null, global["class-transformer"], global["date-fns"], global.lodash, global["ts-custom-error"], global.axios, global["@elasticElasticsearch"], global.firebase, global["gql-query-builder"]));
5
- })(this, (function (exports, reflectMetadata, classTransformer, dateFns, lodash, tsCustomError, axios, elasticsearch, firebase, gqlQueryBuilder) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata'), require('class-transformer'), require('date-fns'), require('lodash'), require('ts-custom-error'), require('axios'), require('firebase'), require('gql-query-builder')) :
3
+ typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'reflect-metadata', 'class-transformer', 'date-fns', 'lodash', 'ts-custom-error', 'axios', 'firebase', 'gql-query-builder'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), null, global["class-transformer"], global["date-fns"], global.lodash, global["ts-custom-error"], global.axios, global.firebase, global["gql-query-builder"]));
5
+ })(this, (function (exports, reflectMetadata, classTransformer, dateFns, lodash, tsCustomError, axios, firebase, gqlQueryBuilder) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -1750,7 +1750,7 @@
1750
1750
  function AxiosAdapter(config) {
1751
1751
  this.config = config;
1752
1752
  }
1753
- AxiosAdapter.prototype.get = function (index) {
1753
+ AxiosAdapter.prototype.get = function (index, id) {
1754
1754
  return __awaiter(this, void 0, void 0, function () {
1755
1755
  var data, error_1;
1756
1756
  return __generator(this, function (_a) {
@@ -1758,9 +1758,9 @@
1758
1758
  case 0:
1759
1759
  _a.trys.push([0, 2, , 3]);
1760
1760
  return [4 /*yield*/, axios__default["default"]({
1761
- url: this.config.url + "/" + index,
1761
+ url: this.config.url + "/" + index + "/_doc/" + id,
1762
1762
  method: 'GET',
1763
- headers: { Authorization: "Basic " + this.config.credential },
1763
+ headers: { Authorization: "ApiKey " + this.config.credential },
1764
1764
  })];
1765
1765
  case 1:
1766
1766
  data = (_a.sent()).data;
@@ -1779,9 +1779,9 @@
1779
1779
  return __generator(this, function (_a) {
1780
1780
  switch (_a.label) {
1781
1781
  case 0: return [4 /*yield*/, axios__default["default"]({
1782
- url: this.config.url + "/" + index,
1783
- method: 'POST',
1784
- headers: { Authorization: "Basic " + this.config.credential },
1782
+ url: this.config.url + "/" + index + "/_search",
1783
+ method: 'GET',
1784
+ headers: { Authorization: "ApiKey " + this.config.credential },
1785
1785
  data: query,
1786
1786
  })];
1787
1787
  case 1:
@@ -1801,7 +1801,7 @@
1801
1801
  case 0: return [4 /*yield*/, axios__default["default"]({
1802
1802
  url: this.config.url + "/" + index,
1803
1803
  method: 'PUT',
1804
- headers: { Authorization: "Basic " + this.config.credential },
1804
+ headers: { Authorization: "ApiKey " + this.config.credential },
1805
1805
  data: data,
1806
1806
  })];
1807
1807
  case 1:
@@ -1818,7 +1818,7 @@
1818
1818
  case 0: return [4 /*yield*/, axios__default["default"]({
1819
1819
  url: this.config.url + "/" + index,
1820
1820
  method: 'DELETE',
1821
- headers: { Authorization: "Basic " + this.config.credential },
1821
+ headers: { Authorization: "ApiKey " + this.config.credential },
1822
1822
  })];
1823
1823
  case 1:
1824
1824
  _a.sent();
@@ -1830,96 +1830,20 @@
1830
1830
  return AxiosAdapter;
1831
1831
  }());
1832
1832
 
1833
- var ElasticSearchAdapter = /** @class */ (function () {
1834
- function ElasticSearchAdapter(config) {
1835
- this.client = new elasticsearch.Client(config);
1836
- }
1837
- ElasticSearchAdapter.prototype.getById = function (index, id) {
1838
- return __awaiter(this, void 0, void 0, function () {
1839
- var data, erro_1;
1840
- return __generator(this, function (_a) {
1841
- switch (_a.label) {
1842
- case 0:
1843
- _a.trys.push([0, 2, , 3]);
1844
- return [4 /*yield*/, this.client.get({ index: index, id: id })];
1845
- case 1:
1846
- data = _a.sent();
1847
- return [2 /*return*/, data._source];
1848
- case 2:
1849
- erro_1 = _a.sent();
1850
- throw new NotFoundError(erro_1.message);
1851
- case 3: return [2 /*return*/];
1852
- }
1853
- });
1854
- });
1855
- };
1856
- ElasticSearchAdapter.prototype.search = function (indice, query) {
1857
- return __awaiter(this, void 0, void 0, function () {
1858
- var result;
1859
- return __generator(this, function (_a) {
1860
- switch (_a.label) {
1861
- case 0: return [4 /*yield*/, this.client.search({
1862
- index: indice,
1863
- query: query,
1864
- })];
1865
- case 1:
1866
- result = _a.sent();
1867
- return [2 /*return*/, {
1868
- total: result.hits.total,
1869
- hits: result.hits.hits,
1870
- }];
1871
- }
1872
- });
1873
- });
1874
- };
1875
- ElasticSearchAdapter.prototype.save = function (index, data) {
1876
- return this.client.index({
1877
- index: index,
1878
- document: data,
1879
- });
1880
- };
1881
- ElasticSearchAdapter.prototype.update = function (index, id, data) {
1882
- try {
1883
- return this.client.update({
1884
- index: index,
1885
- id: id,
1886
- doc: data,
1887
- });
1888
- }
1889
- catch (error) {
1890
- console.log(error);
1891
- throw new Error(error.message);
1892
- }
1893
- };
1894
- ElasticSearchAdapter.prototype.delete = function (index, id) {
1895
- try {
1896
- this.client.delete({
1897
- index: index,
1898
- id: id,
1899
- });
1900
- }
1901
- catch (error) {
1902
- console.log(error);
1903
- }
1904
- };
1905
- return ElasticSearchAdapter;
1906
- }());
1833
+ // export * from './elastic-search.adapter'
1907
1834
 
1908
1835
  var ProductsIndex = /** @class */ (function () {
1909
- function ProductsIndex(
1910
- // private readonly adapter: AxiosAdapter<Product>,
1911
- esadapter) {
1912
- this.esadapter = esadapter;
1836
+ function ProductsIndex(adapter) {
1837
+ this.adapter = adapter;
1913
1838
  }
1914
1839
  ProductsIndex.prototype.get = function (id) {
1915
1840
  return __awaiter(this, void 0, void 0, function () {
1916
1841
  var data;
1917
1842
  return __generator(this, function (_a) {
1918
1843
  switch (_a.label) {
1919
- case 0: return [4 /*yield*/, this.esadapter.getById("products", id)];
1844
+ case 0: return [4 /*yield*/, this.adapter.get('products', id)];
1920
1845
  case 1:
1921
1846
  data = _a.sent();
1922
- // const data = await this.adapter.get(`products/_doc/${id}`)
1923
1847
  return [2 /*return*/, Product.toInstance(data)];
1924
1848
  }
1925
1849
  });
@@ -1930,28 +1854,50 @@
1930
1854
  var search;
1931
1855
  return __generator(this, function (_a) {
1932
1856
  switch (_a.label) {
1933
- case 0: return [4 /*yield*/, this.esadapter.search("products", {
1934
- bool: {
1935
- must: {
1936
- multi_match: {
1937
- query: "" + searchTerm,
1938
- fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
1939
- fuzziness: 2,
1940
- },
1941
- },
1942
- should: {
1943
- match_phrase_prefix: {
1944
- 'name.search': {
1857
+ case 0: return [4 /*yield*/, this.adapter.query('products', {
1858
+ query: {
1859
+ bool: {
1860
+ must: {
1861
+ multi_match: {
1945
1862
  query: "" + searchTerm,
1946
- slop: 10,
1863
+ fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
1864
+ fuzziness: 2,
1947
1865
  },
1948
1866
  },
1867
+ should: {
1868
+ match_phrase_prefix: {
1869
+ 'name.search': {
1870
+ query: "" + searchTerm,
1871
+ slop: 10,
1872
+ },
1873
+ },
1874
+ },
1875
+ filter: [{ term: { published: true } }],
1949
1876
  },
1950
- filter: [{ term: { published: true } }],
1951
1877
  },
1952
1878
  })];
1953
1879
  case 1:
1954
1880
  search = _a.sent();
1881
+ // const search = await this.esadapter.search(`products`, {
1882
+ // bool: {
1883
+ // must: {
1884
+ // multi_match: {
1885
+ // query: `${searchTerm}`,
1886
+ // fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
1887
+ // fuzziness: 2,
1888
+ // },
1889
+ // },
1890
+ // should: {
1891
+ // match_phrase_prefix: {
1892
+ // 'name.search': {
1893
+ // query: `${searchTerm}`,
1894
+ // slop: 10,
1895
+ // },
1896
+ // },
1897
+ // },
1898
+ // filter: [{ term: { published: true } }],
1899
+ // },
1900
+ // })
1955
1901
  search.hits.forEach(function (row) {
1956
1902
  row._source.price = Object.assign(Object.assign({}, row._source.price), (!!row._source.price.Glamshop && row._source.price.Glamshop));
1957
1903
  });
@@ -2017,36 +1963,53 @@
2017
1963
  // }
2018
1964
  ProductsIndex.prototype.save = function (product) {
2019
1965
  return __awaiter(this, void 0, void 0, function () {
2020
- var createdAt, updatedAt, kitProducts, data;
1966
+ var error_1;
2021
1967
  return __generator(this, function (_a) {
2022
- try {
2023
- createdAt = product.createdAt, updatedAt = product.updatedAt, kitProducts = product.kitProducts, data = __rest(product, ["createdAt", "updatedAt", "kitProducts"]);
2024
- this.esadapter.save("product", data);
2025
- }
2026
- catch (error) {
2027
- console.error(error);
1968
+ switch (_a.label) {
1969
+ case 0:
1970
+ // try {
1971
+ // const { createdAt, updatedAt, kitProducts, ...data } = product
1972
+ // this.esadapter.save(`product`, data)
1973
+ // } catch (error) {
1974
+ // console.error(error)
1975
+ // }
1976
+ delete product.createdAt;
1977
+ delete product.updatedAt;
1978
+ delete product.kitProducts;
1979
+ _a.label = 1;
1980
+ case 1:
1981
+ _a.trys.push([1, 4, , 6]);
1982
+ if (!product.firestoreId)
1983
+ throw new Error('Is not a product from firestore');
1984
+ return [4 /*yield*/, this.get(product.firestoreId)];
1985
+ case 2:
1986
+ _a.sent();
1987
+ return [4 /*yield*/, this.adapter.save("products/_doc/" + product.firestoreId, product.toPlain())];
1988
+ case 3:
1989
+ _a.sent();
1990
+ return [3 /*break*/, 6];
1991
+ case 4:
1992
+ error_1 = _a.sent();
1993
+ console.error(error_1.message);
1994
+ return [4 /*yield*/, this.adapter.save("products/_doc/" + product.id, product.toPlain())];
1995
+ case 5:
1996
+ _a.sent();
1997
+ return [3 /*break*/, 6];
1998
+ case 6: return [2 /*return*/];
2028
1999
  }
2029
- return [2 /*return*/];
2030
2000
  });
2031
2001
  });
2032
2002
  };
2033
2003
  ProductsIndex.prototype.update = function (product) {
2034
- try {
2035
- this.esadapter.update("products", product.id, product);
2036
- }
2037
- catch (error) {
2038
- console.error(error);
2039
- }
2004
+ // try {
2005
+ // this.esadapter.update(`products`, product.id, product)
2006
+ // } catch (error) {
2007
+ // console.error(error)
2008
+ // }
2040
2009
  };
2041
2010
  ProductsIndex.prototype.delete = function (id) {
2042
2011
  return __awaiter(this, void 0, void 0, function () {
2043
2012
  return __generator(this, function (_a) {
2044
- try {
2045
- this.esadapter.delete("products", id);
2046
- }
2047
- catch (error) {
2048
- console.error(error);
2049
- }
2050
2013
  return [2 /*return*/];
2051
2014
  });
2052
2015
  });
@@ -5636,7 +5599,6 @@
5636
5599
  exports.CouponFirestoreRepository = CouponFirestoreRepository;
5637
5600
  exports.DuplicatedResultsError = DuplicatedResultsError;
5638
5601
  exports.Edition = Edition;
5639
- exports.ElasticSearchAdapter = ElasticSearchAdapter;
5640
5602
  exports.Filter = Filter;
5641
5603
  exports.FilterHasuraGraphQLRepository = FilterHasuraGraphQLRepository;
5642
5604
  exports.FilterOption = FilterOption;