vinmonopolet-ts 2.0.6 → 2.1.0
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 +11 -0
- package/dist/cjs/constants.js +4 -0
- package/dist/cjs/datamaps/productMap.js +2 -5
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/models/Category.js +19 -0
- package/dist/cjs/models/Facet.js +1 -0
- package/dist/cjs/models/Product.js +149 -1
- package/dist/cjs/models/ProductImage.js +26 -0
- package/dist/cjs/models/ProductRelease.js +12 -0
- package/dist/cjs/models/Volume.js +30 -0
- package/dist/cjs/retrievers/getProductReleases.js +32 -0
- package/dist/cjs/util/GET.js +17 -0
- package/dist/esm/constants.js +1 -0
- package/dist/esm/datamaps/productMap.js +2 -5
- package/dist/esm/index.js +2 -0
- package/dist/esm/models/Category.js +19 -0
- package/dist/esm/models/Facet.js +1 -0
- package/dist/esm/models/Product.js +149 -1
- package/dist/esm/models/ProductImage.js +26 -0
- package/dist/esm/models/ProductRelease.js +15 -0
- package/dist/esm/models/Volume.js +29 -0
- package/dist/esm/retrievers/getProductReleases.js +27 -0
- package/dist/esm/util/GET.js +13 -0
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/datamaps/productMap.d.ts +2 -5
- package/dist/types/index.d.ts +2 -0
- package/dist/types/models/Facet.d.ts +1 -0
- package/dist/types/models/Product.d.ts +4 -7
- package/dist/types/models/ProductImage.d.ts +1 -1
- package/dist/types/models/ProductRelease.d.ts +9 -0
- package/dist/types/models/Volume.d.ts +6 -0
- package/dist/types/retrievers/getProductReleases.d.ts +3 -0
- package/dist/types/util/GET.d.ts +7 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,7 @@ const number_1 = __importDefault(require("../filters/number"));
|
|
|
13
13
|
const status_1 = __importDefault(require("../filters/status"));
|
|
14
14
|
const price_1 = __importDefault(require("../filters/price"));
|
|
15
15
|
const year_1 = __importDefault(require("../filters/year"));
|
|
16
|
+
const Volume_1 = require("../models/Volume");
|
|
16
17
|
const matchPairings = (pairings) => pairings.map((pairing) => FoodPairing_1.default[pairing.code]);
|
|
17
18
|
const toCategory = (category) => new Category_1.default(category);
|
|
18
19
|
const toCategories = (cats) => cats.map(toCategory);
|
|
@@ -20,11 +21,7 @@ const toImages = (imgs) => imgs.map((img) => new ProductImage_1.default(img));
|
|
|
20
21
|
const toRawMaterial = (mats) => mats ? mats.map((mat) => new RawMaterial_1.default(mat)) : null;
|
|
21
22
|
const productType = (mainCat) => mainCat.value;
|
|
22
23
|
const toVolume = (volume) => {
|
|
23
|
-
return
|
|
24
|
-
value: (0, number_1.default)(volume?.value),
|
|
25
|
-
formattedValue: volume?.formattedValue,
|
|
26
|
-
unit: volume?.formattedValue?.split(" ")[1],
|
|
27
|
-
};
|
|
24
|
+
return new Volume_1.Volume((0, number_1.default)(volume?.value), volume?.formattedValue, volume?.formattedValue?.split(" ")[1]);
|
|
28
25
|
};
|
|
29
26
|
/* eslint-disable camelcase */
|
|
30
27
|
exports.default = {
|
package/dist/cjs/index.js
CHANGED
|
@@ -26,7 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.stream = exports.getStore = exports.searchProducts = exports.searchStores = exports.getAllStores = exports.getProductsByIds = exports.getProductsByStore = exports.getProductByBarcode = exports.getFacets = exports.getProduct = exports.getProductCount = exports.getProducts = exports.BaseStore = exports.PopulatedStore = exports.RawMaterial = exports.ProductStatus = exports.ProductImage = exports.StreamProduct = exports.PopulatedProduct = exports.BaseProduct = exports.Pagination = exports.FoodPairing = exports.FacetCategory = exports.FacetValue = exports.Facet = void 0;
|
|
29
|
+
exports.stream = exports.getProductReleases = exports.getStore = exports.searchProducts = exports.searchStores = exports.getAllStores = exports.getProductsByIds = exports.getProductsByStore = exports.getProductByBarcode = exports.getFacets = exports.getProduct = exports.getProductCount = exports.getProducts = exports.BaseStore = exports.PopulatedStore = exports.RawMaterial = exports.ProductStatus = exports.ProductImage = exports.StreamProduct = exports.PopulatedProduct = exports.BaseProduct = exports.Pagination = exports.FoodPairing = exports.FacetCategory = exports.FacetValue = exports.Facet = void 0;
|
|
30
|
+
require("reflect-metadata");
|
|
30
31
|
var Facet_1 = require("./models/Facet");
|
|
31
32
|
Object.defineProperty(exports, "Facet", { enumerable: true, get: function () { return __importDefault(Facet_1).default; } });
|
|
32
33
|
var FacetValue_1 = require("./models/FacetValue");
|
|
@@ -69,5 +70,7 @@ var searchProducts_1 = require("./retrievers/searchProducts");
|
|
|
69
70
|
Object.defineProperty(exports, "searchProducts", { enumerable: true, get: function () { return __importDefault(searchProducts_1).default; } });
|
|
70
71
|
var getStore_1 = require("./retrievers/getStore");
|
|
71
72
|
Object.defineProperty(exports, "getStore", { enumerable: true, get: function () { return __importDefault(getStore_1).default; } });
|
|
73
|
+
var getProductReleases_1 = require("./retrievers/getProductReleases");
|
|
74
|
+
Object.defineProperty(exports, "getProductReleases", { enumerable: true, get: function () { return __importDefault(getProductReleases_1).default; } });
|
|
72
75
|
var stream_1 = require("./stream");
|
|
73
76
|
Object.defineProperty(exports, "stream", { enumerable: true, get: function () { return __importDefault(stream_1).default; } });
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const class_validator_1 = require("class-validator");
|
|
3
10
|
class Category {
|
|
4
11
|
constructor({ code, name, url }) {
|
|
5
12
|
this.code = code ?? null;
|
|
@@ -7,4 +14,16 @@ class Category {
|
|
|
7
14
|
this.url = url ?? null;
|
|
8
15
|
}
|
|
9
16
|
}
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsOptional)(),
|
|
19
|
+
(0, class_validator_1.IsString)()
|
|
20
|
+
], Category.prototype, "code", void 0);
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, class_validator_1.IsOptional)(),
|
|
23
|
+
(0, class_validator_1.IsString)()
|
|
24
|
+
], Category.prototype, "name", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, class_validator_1.IsOptional)(),
|
|
27
|
+
(0, class_validator_1.IsString)()
|
|
28
|
+
], Category.prototype, "url", void 0);
|
|
10
29
|
exports.default = Category;
|
package/dist/cjs/models/Facet.js
CHANGED
|
@@ -15,6 +15,12 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
18
24
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
25
|
if (mod && mod.__esModule) return mod;
|
|
20
26
|
var result = {};
|
|
@@ -27,9 +33,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
33
|
};
|
|
28
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
35
|
exports.PopulatedProduct = exports.StreamProduct = void 0;
|
|
36
|
+
const Category_1 = __importDefault(require("./Category"));
|
|
37
|
+
const ProductImage_1 = __importDefault(require("./ProductImage"));
|
|
30
38
|
const productMap_1 = __importDefault(require("../datamaps/productMap"));
|
|
31
39
|
const productStreamMap_1 = __importDefault(require("../datamaps/productStreamMap"));
|
|
32
40
|
const camelcase_1 = __importDefault(require("../util/camelcase"));
|
|
41
|
+
const class_validator_1 = require("class-validator");
|
|
42
|
+
const class_transformer_1 = require("class-transformer");
|
|
43
|
+
const Volume_1 = require("./Volume");
|
|
33
44
|
const defaultCategory = { code: null, name: null, url: null };
|
|
34
45
|
const defaultAvailability = {
|
|
35
46
|
deliveryAvailability: { available: true, mainText: "" },
|
|
@@ -107,7 +118,7 @@ class BaseProduct {
|
|
|
107
118
|
/**
|
|
108
119
|
* The volume of the product.
|
|
109
120
|
*/
|
|
110
|
-
this.volume =
|
|
121
|
+
this.volume = new Volume_1.Volume(0, "", "");
|
|
111
122
|
// Classification
|
|
112
123
|
/**
|
|
113
124
|
* The main category of the product (Øl, mjød, hvitvin etc..)
|
|
@@ -175,6 +186,71 @@ BaseProduct.fromStream = (streamProduct) => {
|
|
|
175
186
|
const prod = new BaseProduct({});
|
|
176
187
|
return mapFromStreamObject(prod, streamProduct);
|
|
177
188
|
};
|
|
189
|
+
__decorate([
|
|
190
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
191
|
+
(0, class_validator_1.IsString)()
|
|
192
|
+
], BaseProduct.prototype, "code", void 0);
|
|
193
|
+
__decorate([
|
|
194
|
+
(0, class_validator_1.IsString)(),
|
|
195
|
+
(0, class_validator_1.IsNotEmpty)()
|
|
196
|
+
], BaseProduct.prototype, "name", void 0);
|
|
197
|
+
__decorate([
|
|
198
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
199
|
+
(0, class_validator_1.IsString)()
|
|
200
|
+
], BaseProduct.prototype, "productType", void 0);
|
|
201
|
+
__decorate([
|
|
202
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
203
|
+
(0, class_validator_1.IsString)()
|
|
204
|
+
], BaseProduct.prototype, "url", void 0);
|
|
205
|
+
__decorate([
|
|
206
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
207
|
+
(0, class_validator_1.IsNumber)()
|
|
208
|
+
], BaseProduct.prototype, "price", void 0);
|
|
209
|
+
__decorate([
|
|
210
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
211
|
+
(0, class_validator_1.IsNumber)()
|
|
212
|
+
], BaseProduct.prototype, "pricePerLiter", void 0);
|
|
213
|
+
__decorate([
|
|
214
|
+
(0, class_validator_1.IsDefined)(),
|
|
215
|
+
(0, class_validator_1.ValidateNested)(),
|
|
216
|
+
(0, class_transformer_1.Type)(() => ProductImage_1.default)
|
|
217
|
+
], BaseProduct.prototype, "images", void 0);
|
|
218
|
+
__decorate([
|
|
219
|
+
(0, class_validator_1.ValidateNested)(),
|
|
220
|
+
(0, class_transformer_1.Type)(() => Volume_1.Volume)
|
|
221
|
+
], BaseProduct.prototype, "volume", void 0);
|
|
222
|
+
__decorate([
|
|
223
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
224
|
+
(0, class_validator_1.ValidateNested)(),
|
|
225
|
+
(0, class_transformer_1.Type)(() => Category_1.default)
|
|
226
|
+
], BaseProduct.prototype, "mainCategory", void 0);
|
|
227
|
+
__decorate([
|
|
228
|
+
(0, class_validator_1.IsOptional)(),
|
|
229
|
+
(0, class_validator_1.ValidateNested)(),
|
|
230
|
+
(0, class_transformer_1.Type)(() => Category_1.default)
|
|
231
|
+
], BaseProduct.prototype, "mainSubCategory", void 0);
|
|
232
|
+
__decorate([
|
|
233
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
234
|
+
(0, class_validator_1.ValidateNested)(),
|
|
235
|
+
(0, class_transformer_1.Type)(() => Category_1.default)
|
|
236
|
+
], BaseProduct.prototype, "mainCountry", void 0);
|
|
237
|
+
__decorate([
|
|
238
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
239
|
+
(0, class_validator_1.ValidateNested)(),
|
|
240
|
+
(0, class_transformer_1.Type)(() => Category_1.default)
|
|
241
|
+
], BaseProduct.prototype, "district", void 0);
|
|
242
|
+
__decorate([
|
|
243
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
244
|
+
(0, class_validator_1.ValidateNested)(),
|
|
245
|
+
(0, class_transformer_1.Type)(() => Category_1.default)
|
|
246
|
+
], BaseProduct.prototype, "subDistrict", void 0);
|
|
247
|
+
__decorate([
|
|
248
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
249
|
+
(0, class_validator_1.IsString)()
|
|
250
|
+
], BaseProduct.prototype, "productSelection", void 0);
|
|
251
|
+
__decorate([
|
|
252
|
+
(0, class_validator_1.IsBoolean)()
|
|
253
|
+
], BaseProduct.prototype, "buyable", void 0);
|
|
178
254
|
class PopulatedProduct extends BaseProduct {
|
|
179
255
|
constructor(product) {
|
|
180
256
|
super(product);
|
|
@@ -302,5 +378,77 @@ class PopulatedProduct extends BaseProduct {
|
|
|
302
378
|
return Promise.resolve(this);
|
|
303
379
|
}
|
|
304
380
|
}
|
|
381
|
+
__decorate([
|
|
382
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
383
|
+
(0, class_validator_1.IsNumber)()
|
|
384
|
+
], PopulatedProduct.prototype, "abv", void 0);
|
|
385
|
+
__decorate([
|
|
386
|
+
(0, class_validator_1.IsString)(),
|
|
387
|
+
(0, class_validator_1.IsOptional)()
|
|
388
|
+
], PopulatedProduct.prototype, "allergens", void 0);
|
|
389
|
+
__decorate([
|
|
390
|
+
(0, class_validator_1.IsBoolean)()
|
|
391
|
+
], PopulatedProduct.prototype, "bioDynamic", void 0);
|
|
392
|
+
__decorate([
|
|
393
|
+
(0, class_validator_1.IsString)()
|
|
394
|
+
], PopulatedProduct.prototype, "color", void 0);
|
|
395
|
+
__decorate([
|
|
396
|
+
(0, class_validator_1.IsBoolean)()
|
|
397
|
+
], PopulatedProduct.prototype, "eco", void 0);
|
|
398
|
+
__decorate([
|
|
399
|
+
(0, class_validator_1.IsBoolean)()
|
|
400
|
+
], PopulatedProduct.prototype, "environmentalPackaging", void 0);
|
|
401
|
+
__decorate([
|
|
402
|
+
(0, class_validator_1.IsBoolean)()
|
|
403
|
+
], PopulatedProduct.prototype, "expired", void 0);
|
|
404
|
+
__decorate([
|
|
405
|
+
(0, class_validator_1.IsBoolean)()
|
|
406
|
+
], PopulatedProduct.prototype, "fairTrade", void 0);
|
|
407
|
+
__decorate([
|
|
408
|
+
(0, class_validator_1.IsBoolean)()
|
|
409
|
+
], PopulatedProduct.prototype, "gluten", void 0);
|
|
410
|
+
__decorate([
|
|
411
|
+
(0, class_validator_1.IsBoolean)()
|
|
412
|
+
], PopulatedProduct.prototype, "kosher", void 0);
|
|
413
|
+
__decorate([
|
|
414
|
+
(0, class_validator_1.IsOptional)(),
|
|
415
|
+
(0, class_validator_1.IsString)()
|
|
416
|
+
], PopulatedProduct.prototype, "storable", void 0);
|
|
417
|
+
__decorate([
|
|
418
|
+
(0, class_validator_1.IsOptional)(),
|
|
419
|
+
(0, class_validator_1.IsString)()
|
|
420
|
+
], PopulatedProduct.prototype, "containerType", void 0);
|
|
421
|
+
__decorate([
|
|
422
|
+
(0, class_validator_1.IsOptional)(),
|
|
423
|
+
(0, class_validator_1.IsString)()
|
|
424
|
+
], PopulatedProduct.prototype, "taste", void 0);
|
|
425
|
+
__decorate([
|
|
426
|
+
(0, class_validator_1.IsOptional)(),
|
|
427
|
+
(0, class_validator_1.IsString)()
|
|
428
|
+
], PopulatedProduct.prototype, "aroma", void 0);
|
|
429
|
+
__decorate([
|
|
430
|
+
(0, class_validator_1.IsOptional)(),
|
|
431
|
+
(0, class_validator_1.IsNumber)()
|
|
432
|
+
], PopulatedProduct.prototype, "sugar", void 0);
|
|
433
|
+
__decorate([
|
|
434
|
+
(0, class_validator_1.IsOptional)(),
|
|
435
|
+
(0, class_validator_1.IsNumber)()
|
|
436
|
+
], PopulatedProduct.prototype, "acid", void 0);
|
|
437
|
+
__decorate([
|
|
438
|
+
(0, class_validator_1.IsOptional)(),
|
|
439
|
+
(0, class_validator_1.IsNumber)()
|
|
440
|
+
], PopulatedProduct.prototype, "tannins", void 0);
|
|
441
|
+
__decorate([
|
|
442
|
+
(0, class_validator_1.IsOptional)(),
|
|
443
|
+
(0, class_validator_1.IsNumber)()
|
|
444
|
+
], PopulatedProduct.prototype, "bitterness", void 0);
|
|
445
|
+
__decorate([
|
|
446
|
+
(0, class_validator_1.IsOptional)(),
|
|
447
|
+
(0, class_validator_1.IsNumber)()
|
|
448
|
+
], PopulatedProduct.prototype, "freshness", void 0);
|
|
449
|
+
__decorate([
|
|
450
|
+
(0, class_validator_1.IsOptional)(),
|
|
451
|
+
(0, class_validator_1.IsNumber)()
|
|
452
|
+
], PopulatedProduct.prototype, "fullness", void 0);
|
|
305
453
|
exports.PopulatedProduct = PopulatedProduct;
|
|
306
454
|
exports.default = BaseProduct;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const class_validator_1 = require("class-validator");
|
|
3
10
|
const sizeMatcher = /cache\/(\d+)x(\d+)[/-]/;
|
|
4
11
|
class ProductImage {
|
|
5
12
|
constructor(img) {
|
|
@@ -10,6 +17,25 @@ class ProductImage {
|
|
|
10
17
|
this.size = guessSizeFromUrl(img.url);
|
|
11
18
|
}
|
|
12
19
|
}
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, class_validator_1.IsString)(),
|
|
22
|
+
(0, class_validator_1.IsNotEmpty)()
|
|
23
|
+
], ProductImage.prototype, "format", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, class_validator_1.IsString)(),
|
|
26
|
+
(0, class_validator_1.IsOptional)()
|
|
27
|
+
], ProductImage.prototype, "description", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, class_validator_1.IsString)(),
|
|
30
|
+
(0, class_validator_1.IsNotEmpty)()
|
|
31
|
+
], ProductImage.prototype, "type", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, class_validator_1.IsString)(),
|
|
34
|
+
(0, class_validator_1.IsNotEmpty)()
|
|
35
|
+
], ProductImage.prototype, "url", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, class_validator_1.IsOptional)()
|
|
38
|
+
], ProductImage.prototype, "size", void 0);
|
|
13
39
|
ProductImage.prototype.toString = function () {
|
|
14
40
|
return this.url;
|
|
15
41
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ProductRelease {
|
|
4
|
+
constructor(title, primaryCategoryName, url, image, releaseDate) {
|
|
5
|
+
this.title = title;
|
|
6
|
+
this.primaryCategoryName = primaryCategoryName;
|
|
7
|
+
this.url = url;
|
|
8
|
+
this.image = image;
|
|
9
|
+
this.releaseDate = releaseDate;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.default = ProductRelease;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Volume = void 0;
|
|
10
|
+
const class_validator_1 = require("class-validator");
|
|
11
|
+
class Volume {
|
|
12
|
+
constructor(value, formattedValue, unit) {
|
|
13
|
+
this.value = value;
|
|
14
|
+
this.formattedValue = formattedValue;
|
|
15
|
+
this.unit = unit;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
__decorate([
|
|
19
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
20
|
+
(0, class_validator_1.IsNumber)()
|
|
21
|
+
], Volume.prototype, "value", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
24
|
+
(0, class_validator_1.IsString)()
|
|
25
|
+
], Volume.prototype, "formattedValue", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
28
|
+
(0, class_validator_1.IsString)()
|
|
29
|
+
], Volume.prototype, "unit", void 0);
|
|
30
|
+
exports.Volume = Volume;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const ProductRelease_1 = __importDefault(require("../models/ProductRelease"));
|
|
8
|
+
const GET_1 = require("../util/GET");
|
|
9
|
+
function getAbsoluteURL(path) {
|
|
10
|
+
return path.startsWith("/")
|
|
11
|
+
? "www.vinmonopolet.no" + path
|
|
12
|
+
: "www.vinmonopolet.no/" + path;
|
|
13
|
+
}
|
|
14
|
+
function tryToGetReleaseDate(title) {
|
|
15
|
+
const splitTitle = title.split(":");
|
|
16
|
+
if (splitTitle.length < 2) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return splitTitle[0];
|
|
20
|
+
}
|
|
21
|
+
function toProductRelease(dto) {
|
|
22
|
+
return new ProductRelease_1.default(dto.title, dto.primaryCategoryName, getAbsoluteURL(dto.label), getAbsoluteURL(dto.listImageUrl), tryToGetReleaseDate(dto.title));
|
|
23
|
+
}
|
|
24
|
+
async function getProductReleases() {
|
|
25
|
+
const { contentSearchResult } = await (0, GET_1.GET)(constants_1.VINMONOPOLET_SEARCH_URL, {
|
|
26
|
+
queryParams: {
|
|
27
|
+
categoryCode: "lanseringer",
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
return contentSearchResult.results.map(toProductRelease);
|
|
31
|
+
}
|
|
32
|
+
exports.default = getProductReleases;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GET = void 0;
|
|
4
|
+
async function GET(url, { queryParams }) {
|
|
5
|
+
const urlSearchParams = queryParams
|
|
6
|
+
? `?${new URLSearchParams(queryParams)}`
|
|
7
|
+
: "";
|
|
8
|
+
const response = await fetch(url + urlSearchParams);
|
|
9
|
+
if (!response.ok) {
|
|
10
|
+
console.log(response.status);
|
|
11
|
+
const errorMessage = await response.text();
|
|
12
|
+
throw new Error(errorMessage);
|
|
13
|
+
}
|
|
14
|
+
const responseJson = (await response.json());
|
|
15
|
+
return responseJson;
|
|
16
|
+
}
|
|
17
|
+
exports.GET = GET;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VINMONOPOLET_SEARCH_URL = "https://www.vinmonopolet.no/vmpws/v2/vmp/search/content";
|
|
@@ -8,6 +8,7 @@ import number from "../filters/number";
|
|
|
8
8
|
import status from "../filters/status";
|
|
9
9
|
import price from "../filters/price";
|
|
10
10
|
import year from "../filters/year";
|
|
11
|
+
import { Volume } from "../models/Volume";
|
|
11
12
|
const matchPairings = (pairings) => pairings.map((pairing) => FoodPairing[pairing.code]);
|
|
12
13
|
const toCategory = (category) => new Category(category);
|
|
13
14
|
const toCategories = (cats) => cats.map(toCategory);
|
|
@@ -15,11 +16,7 @@ const toImages = (imgs) => imgs.map((img) => new ProductImage(img));
|
|
|
15
16
|
const toRawMaterial = (mats) => mats ? mats.map((mat) => new RawMaterial(mat)) : null;
|
|
16
17
|
const productType = (mainCat) => mainCat.value;
|
|
17
18
|
const toVolume = (volume) => {
|
|
18
|
-
return
|
|
19
|
-
value: number(volume?.value),
|
|
20
|
-
formattedValue: volume?.formattedValue,
|
|
21
|
-
unit: volume?.formattedValue?.split(" ")[1],
|
|
22
|
-
};
|
|
19
|
+
return new Volume(number(volume?.value), volume?.formattedValue, volume?.formattedValue?.split(" ")[1]);
|
|
23
20
|
};
|
|
24
21
|
/* eslint-disable camelcase */
|
|
25
22
|
export default {
|
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
1
2
|
export { default as Facet } from "./models/Facet";
|
|
2
3
|
export { default as FacetValue } from "./models/FacetValue";
|
|
3
4
|
export * as FacetCategory from "./models/FacetCategories";
|
|
@@ -17,4 +18,5 @@ export { default as getProductsByIds } from "./retrievers/getProductsById";
|
|
|
17
18
|
export { default as getAllStores, searchStores } from "./retrievers/getStores";
|
|
18
19
|
export { default as searchProducts } from "./retrievers/searchProducts";
|
|
19
20
|
export { default as getStore } from "./retrievers/getStore";
|
|
21
|
+
export { default as getProductReleases } from "./retrievers/getProductReleases";
|
|
20
22
|
export { default as stream } from "./stream";
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { IsOptional, IsString } from "class-validator";
|
|
1
8
|
class Category {
|
|
2
9
|
code;
|
|
3
10
|
name;
|
|
@@ -8,4 +15,16 @@ class Category {
|
|
|
8
15
|
this.url = url ?? null;
|
|
9
16
|
}
|
|
10
17
|
}
|
|
18
|
+
__decorate([
|
|
19
|
+
IsOptional(),
|
|
20
|
+
IsString()
|
|
21
|
+
], Category.prototype, "code", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
IsOptional(),
|
|
24
|
+
IsString()
|
|
25
|
+
], Category.prototype, "name", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
IsOptional(),
|
|
28
|
+
IsString()
|
|
29
|
+
], Category.prototype, "url", void 0);
|
|
11
30
|
export default Category;
|
package/dist/esm/models/Facet.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import Category from "./Category";
|
|
8
|
+
import ProductImage from "./ProductImage";
|
|
1
9
|
import productMap from "../datamaps/productMap";
|
|
2
10
|
import streamMap from "../datamaps/productStreamMap";
|
|
3
11
|
import camelcase from "../util/camelcase";
|
|
12
|
+
import { IsBoolean, IsDefined, IsNotEmpty, IsNumber, IsOptional, IsString, ValidateNested, } from "class-validator";
|
|
13
|
+
import { Type } from "class-transformer";
|
|
14
|
+
import { Volume } from "./Volume";
|
|
4
15
|
const defaultCategory = { code: null, name: null, url: null };
|
|
5
16
|
const defaultAvailability = {
|
|
6
17
|
deliveryAvailability: { available: true, mainText: "" },
|
|
@@ -79,7 +90,7 @@ class BaseProduct {
|
|
|
79
90
|
/**
|
|
80
91
|
* The volume of the product.
|
|
81
92
|
*/
|
|
82
|
-
volume =
|
|
93
|
+
volume = new Volume(0, "", "");
|
|
83
94
|
// Classification
|
|
84
95
|
/**
|
|
85
96
|
* The main category of the product (Øl, mjød, hvitvin etc..)
|
|
@@ -149,6 +160,71 @@ class BaseProduct {
|
|
|
149
160
|
return mapFromStreamObject(prod, streamProduct);
|
|
150
161
|
};
|
|
151
162
|
}
|
|
163
|
+
__decorate([
|
|
164
|
+
IsNotEmpty(),
|
|
165
|
+
IsString()
|
|
166
|
+
], BaseProduct.prototype, "code", void 0);
|
|
167
|
+
__decorate([
|
|
168
|
+
IsString(),
|
|
169
|
+
IsNotEmpty()
|
|
170
|
+
], BaseProduct.prototype, "name", void 0);
|
|
171
|
+
__decorate([
|
|
172
|
+
IsNotEmpty(),
|
|
173
|
+
IsString()
|
|
174
|
+
], BaseProduct.prototype, "productType", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
IsNotEmpty(),
|
|
177
|
+
IsString()
|
|
178
|
+
], BaseProduct.prototype, "url", void 0);
|
|
179
|
+
__decorate([
|
|
180
|
+
IsNotEmpty(),
|
|
181
|
+
IsNumber()
|
|
182
|
+
], BaseProduct.prototype, "price", void 0);
|
|
183
|
+
__decorate([
|
|
184
|
+
IsNotEmpty(),
|
|
185
|
+
IsNumber()
|
|
186
|
+
], BaseProduct.prototype, "pricePerLiter", void 0);
|
|
187
|
+
__decorate([
|
|
188
|
+
IsDefined(),
|
|
189
|
+
ValidateNested(),
|
|
190
|
+
Type(() => ProductImage)
|
|
191
|
+
], BaseProduct.prototype, "images", void 0);
|
|
192
|
+
__decorate([
|
|
193
|
+
ValidateNested(),
|
|
194
|
+
Type(() => Volume)
|
|
195
|
+
], BaseProduct.prototype, "volume", void 0);
|
|
196
|
+
__decorate([
|
|
197
|
+
IsNotEmpty(),
|
|
198
|
+
ValidateNested(),
|
|
199
|
+
Type(() => Category)
|
|
200
|
+
], BaseProduct.prototype, "mainCategory", void 0);
|
|
201
|
+
__decorate([
|
|
202
|
+
IsOptional(),
|
|
203
|
+
ValidateNested(),
|
|
204
|
+
Type(() => Category)
|
|
205
|
+
], BaseProduct.prototype, "mainSubCategory", void 0);
|
|
206
|
+
__decorate([
|
|
207
|
+
IsNotEmpty(),
|
|
208
|
+
ValidateNested(),
|
|
209
|
+
Type(() => Category)
|
|
210
|
+
], BaseProduct.prototype, "mainCountry", void 0);
|
|
211
|
+
__decorate([
|
|
212
|
+
IsNotEmpty(),
|
|
213
|
+
ValidateNested(),
|
|
214
|
+
Type(() => Category)
|
|
215
|
+
], BaseProduct.prototype, "district", void 0);
|
|
216
|
+
__decorate([
|
|
217
|
+
IsNotEmpty(),
|
|
218
|
+
ValidateNested(),
|
|
219
|
+
Type(() => Category)
|
|
220
|
+
], BaseProduct.prototype, "subDistrict", void 0);
|
|
221
|
+
__decorate([
|
|
222
|
+
IsNotEmpty(),
|
|
223
|
+
IsString()
|
|
224
|
+
], BaseProduct.prototype, "productSelection", void 0);
|
|
225
|
+
__decorate([
|
|
226
|
+
IsBoolean()
|
|
227
|
+
], BaseProduct.prototype, "buyable", void 0);
|
|
152
228
|
export class PopulatedProduct extends BaseProduct {
|
|
153
229
|
// Detailed product info
|
|
154
230
|
/**
|
|
@@ -276,4 +352,76 @@ export class PopulatedProduct extends BaseProduct {
|
|
|
276
352
|
return mapFromStreamObject(prod, streamProduct);
|
|
277
353
|
};
|
|
278
354
|
}
|
|
355
|
+
__decorate([
|
|
356
|
+
IsNotEmpty(),
|
|
357
|
+
IsNumber()
|
|
358
|
+
], PopulatedProduct.prototype, "abv", void 0);
|
|
359
|
+
__decorate([
|
|
360
|
+
IsString(),
|
|
361
|
+
IsOptional()
|
|
362
|
+
], PopulatedProduct.prototype, "allergens", void 0);
|
|
363
|
+
__decorate([
|
|
364
|
+
IsBoolean()
|
|
365
|
+
], PopulatedProduct.prototype, "bioDynamic", void 0);
|
|
366
|
+
__decorate([
|
|
367
|
+
IsString()
|
|
368
|
+
], PopulatedProduct.prototype, "color", void 0);
|
|
369
|
+
__decorate([
|
|
370
|
+
IsBoolean()
|
|
371
|
+
], PopulatedProduct.prototype, "eco", void 0);
|
|
372
|
+
__decorate([
|
|
373
|
+
IsBoolean()
|
|
374
|
+
], PopulatedProduct.prototype, "environmentalPackaging", void 0);
|
|
375
|
+
__decorate([
|
|
376
|
+
IsBoolean()
|
|
377
|
+
], PopulatedProduct.prototype, "expired", void 0);
|
|
378
|
+
__decorate([
|
|
379
|
+
IsBoolean()
|
|
380
|
+
], PopulatedProduct.prototype, "fairTrade", void 0);
|
|
381
|
+
__decorate([
|
|
382
|
+
IsBoolean()
|
|
383
|
+
], PopulatedProduct.prototype, "gluten", void 0);
|
|
384
|
+
__decorate([
|
|
385
|
+
IsBoolean()
|
|
386
|
+
], PopulatedProduct.prototype, "kosher", void 0);
|
|
387
|
+
__decorate([
|
|
388
|
+
IsOptional(),
|
|
389
|
+
IsString()
|
|
390
|
+
], PopulatedProduct.prototype, "storable", void 0);
|
|
391
|
+
__decorate([
|
|
392
|
+
IsOptional(),
|
|
393
|
+
IsString()
|
|
394
|
+
], PopulatedProduct.prototype, "containerType", void 0);
|
|
395
|
+
__decorate([
|
|
396
|
+
IsOptional(),
|
|
397
|
+
IsString()
|
|
398
|
+
], PopulatedProduct.prototype, "taste", void 0);
|
|
399
|
+
__decorate([
|
|
400
|
+
IsOptional(),
|
|
401
|
+
IsString()
|
|
402
|
+
], PopulatedProduct.prototype, "aroma", void 0);
|
|
403
|
+
__decorate([
|
|
404
|
+
IsOptional(),
|
|
405
|
+
IsNumber()
|
|
406
|
+
], PopulatedProduct.prototype, "sugar", void 0);
|
|
407
|
+
__decorate([
|
|
408
|
+
IsOptional(),
|
|
409
|
+
IsNumber()
|
|
410
|
+
], PopulatedProduct.prototype, "acid", void 0);
|
|
411
|
+
__decorate([
|
|
412
|
+
IsOptional(),
|
|
413
|
+
IsNumber()
|
|
414
|
+
], PopulatedProduct.prototype, "tannins", void 0);
|
|
415
|
+
__decorate([
|
|
416
|
+
IsOptional(),
|
|
417
|
+
IsNumber()
|
|
418
|
+
], PopulatedProduct.prototype, "bitterness", void 0);
|
|
419
|
+
__decorate([
|
|
420
|
+
IsOptional(),
|
|
421
|
+
IsNumber()
|
|
422
|
+
], PopulatedProduct.prototype, "freshness", void 0);
|
|
423
|
+
__decorate([
|
|
424
|
+
IsOptional(),
|
|
425
|
+
IsNumber()
|
|
426
|
+
], PopulatedProduct.prototype, "fullness", void 0);
|
|
279
427
|
export default BaseProduct;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { IsNotEmpty, IsOptional, IsString } from "class-validator";
|
|
1
8
|
const sizeMatcher = /cache\/(\d+)x(\d+)[/-]/;
|
|
2
9
|
class ProductImage {
|
|
3
10
|
format;
|
|
@@ -13,6 +20,25 @@ class ProductImage {
|
|
|
13
20
|
this.size = guessSizeFromUrl(img.url);
|
|
14
21
|
}
|
|
15
22
|
}
|
|
23
|
+
__decorate([
|
|
24
|
+
IsString(),
|
|
25
|
+
IsNotEmpty()
|
|
26
|
+
], ProductImage.prototype, "format", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
IsString(),
|
|
29
|
+
IsOptional()
|
|
30
|
+
], ProductImage.prototype, "description", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
IsString(),
|
|
33
|
+
IsNotEmpty()
|
|
34
|
+
], ProductImage.prototype, "type", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
IsString(),
|
|
37
|
+
IsNotEmpty()
|
|
38
|
+
], ProductImage.prototype, "url", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
IsOptional()
|
|
41
|
+
], ProductImage.prototype, "size", void 0);
|
|
16
42
|
ProductImage.prototype.toString = function () {
|
|
17
43
|
return this.url;
|
|
18
44
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class ProductRelease {
|
|
2
|
+
title;
|
|
3
|
+
primaryCategoryName;
|
|
4
|
+
url;
|
|
5
|
+
image;
|
|
6
|
+
releaseDate;
|
|
7
|
+
constructor(title, primaryCategoryName, url, image, releaseDate) {
|
|
8
|
+
this.title = title;
|
|
9
|
+
this.primaryCategoryName = primaryCategoryName;
|
|
10
|
+
this.url = url;
|
|
11
|
+
this.image = image;
|
|
12
|
+
this.releaseDate = releaseDate;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export default ProductRelease;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { IsNotEmpty, IsNumber, IsString } from "class-validator";
|
|
8
|
+
export class Volume {
|
|
9
|
+
value;
|
|
10
|
+
formattedValue;
|
|
11
|
+
unit;
|
|
12
|
+
constructor(value, formattedValue, unit) {
|
|
13
|
+
this.value = value;
|
|
14
|
+
this.formattedValue = formattedValue;
|
|
15
|
+
this.unit = unit;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
__decorate([
|
|
19
|
+
IsNotEmpty(),
|
|
20
|
+
IsNumber()
|
|
21
|
+
], Volume.prototype, "value", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
IsNotEmpty(),
|
|
24
|
+
IsString()
|
|
25
|
+
], Volume.prototype, "formattedValue", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
IsNotEmpty(),
|
|
28
|
+
IsString()
|
|
29
|
+
], Volume.prototype, "unit", void 0);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { VINMONOPOLET_SEARCH_URL } from "../constants";
|
|
2
|
+
import ProductRelease from "../models/ProductRelease";
|
|
3
|
+
import { GET } from "../util/GET";
|
|
4
|
+
function getAbsoluteURL(path) {
|
|
5
|
+
return path.startsWith("/")
|
|
6
|
+
? "www.vinmonopolet.no" + path
|
|
7
|
+
: "www.vinmonopolet.no/" + path;
|
|
8
|
+
}
|
|
9
|
+
function tryToGetReleaseDate(title) {
|
|
10
|
+
const splitTitle = title.split(":");
|
|
11
|
+
if (splitTitle.length < 2) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return splitTitle[0];
|
|
15
|
+
}
|
|
16
|
+
function toProductRelease(dto) {
|
|
17
|
+
return new ProductRelease(dto.title, dto.primaryCategoryName, getAbsoluteURL(dto.label), getAbsoluteURL(dto.listImageUrl), tryToGetReleaseDate(dto.title));
|
|
18
|
+
}
|
|
19
|
+
async function getProductReleases() {
|
|
20
|
+
const { contentSearchResult } = await GET(VINMONOPOLET_SEARCH_URL, {
|
|
21
|
+
queryParams: {
|
|
22
|
+
categoryCode: "lanseringer",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return contentSearchResult.results.map(toProductRelease);
|
|
26
|
+
}
|
|
27
|
+
export default getProductReleases;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export async function GET(url, { queryParams }) {
|
|
2
|
+
const urlSearchParams = queryParams
|
|
3
|
+
? `?${new URLSearchParams(queryParams)}`
|
|
4
|
+
: "";
|
|
5
|
+
const response = await fetch(url + urlSearchParams);
|
|
6
|
+
if (!response.ok) {
|
|
7
|
+
console.log(response.status);
|
|
8
|
+
const errorMessage = await response.text();
|
|
9
|
+
throw new Error(errorMessage);
|
|
10
|
+
}
|
|
11
|
+
const responseJson = (await response.json());
|
|
12
|
+
return responseJson;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VINMONOPOLET_SEARCH_URL = "https://www.vinmonopolet.no/vmpws/v2/vmp/search/content";
|
|
@@ -4,6 +4,7 @@ import clockToPercentage from "../filters/clockToPercentage";
|
|
|
4
4
|
import number from "../filters/number";
|
|
5
5
|
import status from "../filters/status";
|
|
6
6
|
import price from "../filters/price";
|
|
7
|
+
import { Volume } from "../models/Volume";
|
|
7
8
|
declare const _default: {
|
|
8
9
|
productType: (string | ((mainCat: any) => any))[];
|
|
9
10
|
isGoodFor: (string | ((pairings: any) => any))[];
|
|
@@ -16,11 +17,7 @@ declare const _default: {
|
|
|
16
17
|
matured: string[];
|
|
17
18
|
images: (string | ((imgs: any) => any))[];
|
|
18
19
|
alcohol: (string | typeof number)[];
|
|
19
|
-
volume: (string | ((volume: any) =>
|
|
20
|
-
value: any;
|
|
21
|
-
formattedValue: any;
|
|
22
|
-
unit: any;
|
|
23
|
-
}))[];
|
|
20
|
+
volume: (string | ((volume: any) => Volume))[];
|
|
24
21
|
packageType: string[];
|
|
25
22
|
price: (string | typeof price)[];
|
|
26
23
|
nyhet: string[];
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
1
2
|
export { default as Facet } from "./models/Facet";
|
|
2
3
|
export { default as FacetValue } from "./models/FacetValue";
|
|
3
4
|
export * as FacetCategory from "./models/FacetCategories";
|
|
@@ -17,4 +18,5 @@ export { default as getProductsByIds } from "./retrievers/getProductsById";
|
|
|
17
18
|
export { default as getAllStores, searchStores } from "./retrievers/getStores";
|
|
18
19
|
export { default as searchProducts } from "./retrievers/searchProducts";
|
|
19
20
|
export { default as getStore } from "./retrievers/getStore";
|
|
21
|
+
export { default as getProductReleases } from "./retrievers/getProductReleases";
|
|
20
22
|
export { default as stream } from "./stream";
|
|
@@ -2,6 +2,7 @@ import Category from "./Category";
|
|
|
2
2
|
import FoodPairing from "./FoodPairing";
|
|
3
3
|
import ProductImage from "./ProductImage";
|
|
4
4
|
import RawMaterial from "./RawMaterial";
|
|
5
|
+
import { Volume } from "./Volume";
|
|
5
6
|
interface IAvailability {
|
|
6
7
|
deliveryAvailability: {
|
|
7
8
|
available: boolean;
|
|
@@ -54,11 +55,7 @@ declare class BaseProduct {
|
|
|
54
55
|
/**
|
|
55
56
|
* The volume of the product.
|
|
56
57
|
*/
|
|
57
|
-
volume:
|
|
58
|
-
value: number;
|
|
59
|
-
unit: string;
|
|
60
|
-
formattedValue: string;
|
|
61
|
-
};
|
|
58
|
+
volume: Volume;
|
|
62
59
|
/**
|
|
63
60
|
* The main category of the product (Øl, mjød, hvitvin etc..)
|
|
64
61
|
*/
|
|
@@ -74,11 +71,11 @@ declare class BaseProduct {
|
|
|
74
71
|
/**
|
|
75
72
|
* The district the product is from. Might not always have values if no district is given.
|
|
76
73
|
*/
|
|
77
|
-
district
|
|
74
|
+
district?: Category;
|
|
78
75
|
/**
|
|
79
76
|
* The sub-district the product is from. Might not always have values if no sub-district is given.
|
|
80
77
|
*/
|
|
81
|
-
subDistrict
|
|
78
|
+
subDistrict?: Category;
|
|
82
79
|
/**
|
|
83
80
|
* The given product selection the product is available in (Bestillingsutvalget, Basisutvalget etc).
|
|
84
81
|
*/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare class ProductRelease {
|
|
2
|
+
title: string;
|
|
3
|
+
primaryCategoryName: string;
|
|
4
|
+
url: string;
|
|
5
|
+
image: string;
|
|
6
|
+
releaseDate: string | undefined;
|
|
7
|
+
constructor(title: string, primaryCategoryName: string, url: string, image: string, releaseDate: string | undefined);
|
|
8
|
+
}
|
|
9
|
+
export default ProductRelease;
|
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
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vinmonopolet",
|
|
7
7
|
"beer",
|
|
@@ -58,11 +58,14 @@
|
|
|
58
58
|
"ts-node": "^10.8.1"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
+
"class-transformer": "^0.5.1",
|
|
62
|
+
"class-validator": "^0.14.0",
|
|
61
63
|
"csv-parser": "^1.12.0",
|
|
62
64
|
"fetch-cookie": "^2.0.5",
|
|
63
65
|
"node-fetch": "^2.0.0",
|
|
64
66
|
"promise-map-limit": "^1.0.0",
|
|
65
67
|
"query-string": "^4.3.4",
|
|
68
|
+
"reflect-metadata": "^0.1.13",
|
|
66
69
|
"typescript": "^4.7.3"
|
|
67
70
|
}
|
|
68
71
|
}
|