vinmonopolet-ts 2.0.1 → 2.0.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  #Changelog
2
2
 
3
+ ## [2.0.4]
4
+
5
+ #### Added
6
+
7
+ - GetProductsByStore now accepts page option.
8
+ - Paginatiation now has correct return type for next and previous functions.
9
+
10
+ ### Changed
11
+
12
+ - GetProductsByStore store parameter is now statically typed as a string.
13
+
3
14
  ## [2.0.0]
4
15
 
5
16
  Changed package export method to individual exports so that you no longer need to import the whole package.
@@ -7,13 +7,12 @@ const request_1 = __importDefault(require("../util/request"));
7
7
  const Facet_1 = __importDefault(require("../models/Facet"));
8
8
  function getFacets() {
9
9
  return request_1.default
10
- .get("/vmp/search/facets", {
10
+ .get("/api/search", {
11
11
  baseUrl: "https://www.vinmonopolet.no",
12
12
  query: {
13
- // 500 thrown if no "q" parameter supplied.
14
- q: "",
13
+ fields: "FULL",
15
14
  },
16
15
  })
17
- .then((res) => res.facets.map((i) => new Facet_1.default(i)));
16
+ .then((res) => res.productSearchResult.facets.map((i) => new Facet_1.default(i)));
18
17
  }
19
18
  exports.default = getFacets;
@@ -6,9 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const FacetValue_1 = __importDefault(require("../models/FacetValue"));
7
7
  const getProducts_1 = __importDefault(require("./getProducts"));
8
8
  async function getProductsByStore(store, opts) {
9
- const id = typeof store.name === "undefined" ? store : store.name;
10
9
  const storeFacet = new FacetValue_1.default({
11
- query: { query: { value: `availableInStores:${id}` } },
10
+ query: { query: { value: `availableInStores:${store}` } },
12
11
  });
13
12
  let facets = [storeFacet];
14
13
  if (opts?.facet)
@@ -17,8 +16,7 @@ async function getProductsByStore(store, opts) {
17
16
  const safeFacets = opts?.facets.filter((facet) => facet !== undefined);
18
17
  facets = facets.concat(safeFacets);
19
18
  }
20
- delete opts?.facet;
21
- const options = { limit: opts?.limit, facets: facets };
19
+ const options = { limit: opts?.limit, facets: facets, page: opts?.page ?? 1 };
22
20
  const allProducts = await (0, getProducts_1.default)(options);
23
21
  return { ...allProducts, store };
24
22
  }
@@ -2,13 +2,12 @@ import request from "../util/request";
2
2
  import Facet from "../models/Facet";
3
3
  function getFacets() {
4
4
  return request
5
- .get("/vmp/search/facets", {
5
+ .get("/api/search", {
6
6
  baseUrl: "https://www.vinmonopolet.no",
7
7
  query: {
8
- // 500 thrown if no "q" parameter supplied.
9
- q: "",
8
+ fields: "FULL",
10
9
  },
11
10
  })
12
- .then((res) => res.facets.map((i) => new Facet(i)));
11
+ .then((res) => res.productSearchResult.facets.map((i) => new Facet(i)));
13
12
  }
14
13
  export default getFacets;
@@ -1,9 +1,8 @@
1
1
  import FacetValue from "../models/FacetValue";
2
2
  import getProducts from "./getProducts";
3
3
  async function getProductsByStore(store, opts) {
4
- const id = typeof store.name === "undefined" ? store : store.name;
5
4
  const storeFacet = new FacetValue({
6
- query: { query: { value: `availableInStores:${id}` } },
5
+ query: { query: { value: `availableInStores:${store}` } },
7
6
  });
8
7
  let facets = [storeFacet];
9
8
  if (opts?.facet)
@@ -12,8 +11,7 @@ async function getProductsByStore(store, opts) {
12
11
  const safeFacets = opts?.facets.filter((facet) => facet !== undefined);
13
12
  facets = facets.concat(safeFacets);
14
13
  }
15
- delete opts?.facet;
16
- const options = { limit: opts?.limit, facets: facets };
14
+ const options = { limit: opts?.limit, facets: facets, page: opts?.page ?? 1 };
17
15
  const allProducts = await getProducts(options);
18
16
  return { ...allProducts, store };
19
17
  }
@@ -1,4 +1,4 @@
1
- declare class Pagination {
1
+ declare class Pagination<T> {
2
2
  /**
3
3
  * The current page of the results.
4
4
  */
@@ -29,8 +29,8 @@ declare class Pagination {
29
29
  sort: string;
30
30
  private fetcher;
31
31
  private options;
32
- constructor(paging: any, options: any, fetcher: () => any);
33
- next(): Promise<any>;
34
- previous(): Promise<any>;
32
+ constructor(paging: any, options: any, fetcher: () => Promise<T>);
33
+ next(): Promise<T>;
34
+ previous(): Promise<T>;
35
35
  }
36
36
  export default Pagination;
@@ -33,7 +33,7 @@ export interface IGetProductsResponse {
33
33
  /**
34
34
  * Pagination object used to traverse the results.
35
35
  */
36
- pagination: Pagination;
36
+ pagination: Pagination<IGetProductsResponse>;
37
37
  /**
38
38
  * a list of products. Represents one page of the results, use pagination.next to fetch next page of results.
39
39
  */
@@ -13,9 +13,13 @@ interface IGetProductsByStoreOptions {
13
13
  * Limits the number of products returned in a single, paginated response (Default: 50)
14
14
  */
15
15
  limit?: number;
16
+ /**
17
+ * Which page of the pagination you want to get. (Default: 1)
18
+ */
19
+ page?: number;
16
20
  }
17
21
  interface getProductsByStoreResponse extends IGetProductsResponse {
18
22
  store: string;
19
23
  }
20
- declare function getProductsByStore(store: any, opts?: IGetProductsByStoreOptions): Promise<getProductsByStoreResponse>;
24
+ declare function getProductsByStore(store: string, opts?: IGetProductsByStoreOptions): Promise<getProductsByStoreResponse>;
21
25
  export default getProductsByStore;
@@ -29,7 +29,7 @@ export interface ISearchStoreResult {
29
29
  /**
30
30
  * Pagination object used to traverse the results.
31
31
  */
32
- pagination?: Pagination;
32
+ pagination?: Pagination<ISearchStoreResult>;
33
33
  }
34
34
  export declare function searchStores(opts?: ISearchStoresOptions): Promise<ISearchStoreResult>;
35
35
  declare function getAllStores(): Promise<PopulatedStore[]>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vinmonopolet-ts",
3
3
  "description": "Extracts information on products, categories and stores from Vinmonopolet",
4
- "version": "2.0.1",
4
+ "version": "2.0.4",
5
5
  "keywords": [
6
6
  "vinmonopolet",
7
7
  "beer",