@infrab4a/connect 4.14.0-beta.1 → 4.14.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.
package/index.cjs.js CHANGED
@@ -2596,7 +2596,9 @@ class ProductsIndex {
2596
2596
  RoundProductPricesHelper.roundProductPrices(hit._source);
2597
2597
  return hit;
2598
2598
  });
2599
- return search;
2599
+ return search.hits.map((hit) => {
2600
+ return Object.assign(Object.assign({}, hit._source), { stock: hit._source.stock.quantity });
2601
+ });
2600
2602
  }
2601
2603
  async save(product) {
2602
2604
  try {
@@ -6413,19 +6415,12 @@ class VertexAxiosAdapter {
6413
6415
  responseType: 'json',
6414
6416
  headers: {
6415
6417
  Accept: 'application/json',
6416
- // 'Content-Type': 'application/vnd.elasticsearch+json;compatible-with=7',
6417
- // Authorization: `ApiKey ${this.config.credential}`,
6418
6418
  },
6419
6419
  data: { searchTerm, total, gender },
6420
6420
  };
6421
6421
  try {
6422
6422
  const { data } = await axios__default["default"](req);
6423
6423
  console.log('response vertex axios', data);
6424
- // const res = {
6425
- // total: data.hits.total.value,
6426
- // hits: data.hits.hits,
6427
- // }
6428
- // logger.log({ req, res })
6429
6424
  return data;
6430
6425
  }
6431
6426
  catch (error) {
@@ -6433,17 +6428,83 @@ class VertexAxiosAdapter {
6433
6428
  throw error;
6434
6429
  }
6435
6430
  }
6436
- get(id) {
6437
- throw new Error('Method not implemented.');
6431
+ async get(id) {
6432
+ const logger = this.logger.with('update');
6433
+ const req = {
6434
+ url: `${this.config.url}/${id}`,
6435
+ method: 'GET',
6436
+ responseType: 'json',
6437
+ headers: {
6438
+ Accept: 'application/json',
6439
+ },
6440
+ };
6441
+ try {
6442
+ const { data } = await axios__default["default"](req);
6443
+ return data;
6444
+ }
6445
+ catch (error) {
6446
+ logger.error({ req, res: error });
6447
+ throw error;
6448
+ }
6438
6449
  }
6439
- save(data) {
6440
- throw new Error('Method not implemented.');
6450
+ async save(data) {
6451
+ const logger = this.logger.with('save');
6452
+ const req = {
6453
+ url: `${this.config.url}/sync`,
6454
+ method: 'POST',
6455
+ responseType: 'json',
6456
+ headers: {
6457
+ Accept: 'application/json',
6458
+ },
6459
+ data,
6460
+ };
6461
+ try {
6462
+ const { data } = await axios__default["default"](req);
6463
+ return data;
6464
+ }
6465
+ catch (error) {
6466
+ logger.error({ req, res: error });
6467
+ throw error;
6468
+ }
6441
6469
  }
6442
- update(id, data) {
6443
- throw new Error('Method not implemented.');
6470
+ async update(id, data) {
6471
+ const logger = this.logger.with('update');
6472
+ const req = {
6473
+ url: `${this.config.url}/${id}`,
6474
+ method: 'PUT',
6475
+ responseType: 'json',
6476
+ headers: {
6477
+ Accept: 'application/json',
6478
+ },
6479
+ data,
6480
+ };
6481
+ try {
6482
+ const { data } = await axios__default["default"](req);
6483
+ return data;
6484
+ }
6485
+ catch (error) {
6486
+ logger.error({ req, res: error });
6487
+ throw error;
6488
+ }
6444
6489
  }
6445
- delete(id) {
6446
- throw new Error('Method not implemented.');
6490
+ async delete(id) {
6491
+ const logger = this.logger.with('delete');
6492
+ const req = {
6493
+ url: `${this.config.url}/${id}`,
6494
+ method: 'DELETE',
6495
+ responseType: 'json',
6496
+ headers: {
6497
+ Accept: 'application/json',
6498
+ },
6499
+ };
6500
+ try {
6501
+ const { data } = await axios__default["default"](req);
6502
+ return data;
6503
+ }
6504
+ catch (error) {
6505
+ logger.error({ req, res: error });
6506
+ throw error;
6507
+ }
6447
6508
  }
6448
6509
  }
6449
6510
 
package/index.esm.js CHANGED
@@ -2590,7 +2590,9 @@ class ProductsIndex {
2590
2590
  RoundProductPricesHelper.roundProductPrices(hit._source);
2591
2591
  return hit;
2592
2592
  });
2593
- return search;
2593
+ return search.hits.map((hit) => {
2594
+ return Object.assign(Object.assign({}, hit._source), { stock: hit._source.stock.quantity });
2595
+ });
2594
2596
  }
2595
2597
  async save(product) {
2596
2598
  try {
@@ -6407,19 +6409,12 @@ class VertexAxiosAdapter {
6407
6409
  responseType: 'json',
6408
6410
  headers: {
6409
6411
  Accept: 'application/json',
6410
- // 'Content-Type': 'application/vnd.elasticsearch+json;compatible-with=7',
6411
- // Authorization: `ApiKey ${this.config.credential}`,
6412
6412
  },
6413
6413
  data: { searchTerm, total, gender },
6414
6414
  };
6415
6415
  try {
6416
6416
  const { data } = await axios(req);
6417
6417
  console.log('response vertex axios', data);
6418
- // const res = {
6419
- // total: data.hits.total.value,
6420
- // hits: data.hits.hits,
6421
- // }
6422
- // logger.log({ req, res })
6423
6418
  return data;
6424
6419
  }
6425
6420
  catch (error) {
@@ -6427,17 +6422,83 @@ class VertexAxiosAdapter {
6427
6422
  throw error;
6428
6423
  }
6429
6424
  }
6430
- get(id) {
6431
- throw new Error('Method not implemented.');
6425
+ async get(id) {
6426
+ const logger = this.logger.with('update');
6427
+ const req = {
6428
+ url: `${this.config.url}/${id}`,
6429
+ method: 'GET',
6430
+ responseType: 'json',
6431
+ headers: {
6432
+ Accept: 'application/json',
6433
+ },
6434
+ };
6435
+ try {
6436
+ const { data } = await axios(req);
6437
+ return data;
6438
+ }
6439
+ catch (error) {
6440
+ logger.error({ req, res: error });
6441
+ throw error;
6442
+ }
6432
6443
  }
6433
- save(data) {
6434
- throw new Error('Method not implemented.');
6444
+ async save(data) {
6445
+ const logger = this.logger.with('save');
6446
+ const req = {
6447
+ url: `${this.config.url}/sync`,
6448
+ method: 'POST',
6449
+ responseType: 'json',
6450
+ headers: {
6451
+ Accept: 'application/json',
6452
+ },
6453
+ data,
6454
+ };
6455
+ try {
6456
+ const { data } = await axios(req);
6457
+ return data;
6458
+ }
6459
+ catch (error) {
6460
+ logger.error({ req, res: error });
6461
+ throw error;
6462
+ }
6435
6463
  }
6436
- update(id, data) {
6437
- throw new Error('Method not implemented.');
6464
+ async update(id, data) {
6465
+ const logger = this.logger.with('update');
6466
+ const req = {
6467
+ url: `${this.config.url}/${id}`,
6468
+ method: 'PUT',
6469
+ responseType: 'json',
6470
+ headers: {
6471
+ Accept: 'application/json',
6472
+ },
6473
+ data,
6474
+ };
6475
+ try {
6476
+ const { data } = await axios(req);
6477
+ return data;
6478
+ }
6479
+ catch (error) {
6480
+ logger.error({ req, res: error });
6481
+ throw error;
6482
+ }
6438
6483
  }
6439
- delete(id) {
6440
- throw new Error('Method not implemented.');
6484
+ async delete(id) {
6485
+ const logger = this.logger.with('delete');
6486
+ const req = {
6487
+ url: `${this.config.url}/${id}`,
6488
+ method: 'DELETE',
6489
+ responseType: 'json',
6490
+ headers: {
6491
+ Accept: 'application/json',
6492
+ },
6493
+ };
6494
+ try {
6495
+ const { data } = await axios(req);
6496
+ return data;
6497
+ }
6498
+ catch (error) {
6499
+ logger.error({ req, res: error });
6500
+ throw error;
6501
+ }
6441
6502
  }
6442
6503
  }
6443
6504
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.14.0-beta.1",
3
+ "version": "4.14.0-beta.2",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -1 +1,2 @@
1
+ export * from './search';
1
2
  export * from './storage';
@@ -0,0 +1 @@
1
+ export * from './product-search-index';
@@ -0,0 +1,3 @@
1
+ export interface ProductSearchIndex {
2
+ search<T>(searchTerm: string, total: number, gender?: String): Promise<T[]>;
3
+ }
@@ -6,7 +6,42 @@ export declare class ProductsIndex {
6
6
  private index;
7
7
  constructor(adapter: ElasticSearchAdapter<Product>);
8
8
  getById(id: string): Promise<Product>;
9
- search(searchTerm: string, total: number, shop?: string): Promise<import("..").ElasticSearchResult<Product>>;
9
+ search(searchTerm: string, total: number, shop?: string): Promise<{
10
+ stock: number;
11
+ category: import("../../../domain/catalog/models/category-for-product").CategoryForProduct;
12
+ kitProducts?: import("../../../domain").KitProduct[];
13
+ id: string;
14
+ name: string;
15
+ slug: string;
16
+ description: import("../../../domain").ShopDescription;
17
+ sku: string;
18
+ price: import("../../../domain").ShopPrice;
19
+ hasVariants: boolean;
20
+ NCM: string;
21
+ EAN: string;
22
+ CEST: string;
23
+ weight: number;
24
+ costPrice: number;
25
+ images?: string[];
26
+ miniatures?: string[];
27
+ published: boolean;
28
+ createdAt?: Date;
29
+ updatedAt?: Date;
30
+ brand: string;
31
+ tags?: string[];
32
+ filters?: string[];
33
+ type?: string;
34
+ categories?: string[];
35
+ reviews?: import("../../../domain").ProductReview[];
36
+ variants?: import("../../../domain").Variant[];
37
+ video?: string;
38
+ isKit?: boolean;
39
+ rate?: number;
40
+ gender?: import("../../../domain").ProductGender;
41
+ shoppingCount?: number;
42
+ metadata: import("../../../domain").ProductMetadata;
43
+ outlet?: boolean;
44
+ }[]>;
10
45
  save(product: ProductHasuraGraphQL): Promise<void>;
11
46
  update(product: ProductHasuraGraphQL): Promise<void>;
12
47
  delete(id: string): Promise<void>;
@@ -3,7 +3,7 @@ import { ProductSearch } from '../types';
3
3
  export interface VertexSearchAdapter<T> {
4
4
  query(searchTerm: string, total: number, gender?: String): Promise<ProductSearch[]>;
5
5
  get(id: string): Promise<T>;
6
- save(data: Product): any;
7
- update(id: string, data: Product): any;
6
+ save(data: Product): Promise<any>;
7
+ update(id: string, data: Product): Promise<any>;
8
8
  delete(id: string): Promise<void>;
9
9
  }
@@ -8,7 +8,7 @@ export declare class VertexAxiosAdapter implements VertexSearchAdapter<ProductSe
8
8
  constructor(config: VertexSearchConfig);
9
9
  query(searchTerm: string, total: number, gender?: String): Promise<ProductSearch[]>;
10
10
  get(id: string): Promise<ProductSearch>;
11
- save(data: Product): void;
12
- update(id: string, data: Product): void;
11
+ save(data: Product): Promise<any>;
12
+ update(id: string, data: Product): Promise<any>;
13
13
  delete(id: string): Promise<void>;
14
14
  }
@@ -1,11 +1,12 @@
1
+ import { ProductSearchIndex } from '../../../domain';
1
2
  import { ProductHasuraGraphQL } from '../../hasura-graphql';
2
3
  import { VertexSearchAdapter } from '../adapters';
3
4
  import { ProductSearch } from '../types';
4
- export declare class ProductsVertexSearch {
5
+ export declare class ProductsVertexSearch implements ProductSearchIndex {
5
6
  private readonly adapter;
6
7
  constructor(adapter: VertexSearchAdapter<ProductSearch>);
7
8
  getById(id: string): Promise<ProductSearch>;
8
- search(searchTerm: string, total: number, gender?: String): Promise<ProductSearch[]>;
9
+ search<ProductSearch>(searchTerm: string, total: number, gender?: String): Promise<ProductSearch[]>;
9
10
  save(product: ProductHasuraGraphQL): Promise<void>;
10
11
  update(product: ProductHasuraGraphQL): Promise<void>;
11
12
  delete(id: string): Promise<void>;