@infrab4a/connect-angular 1.0.0-beta.9 → 1.0.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/bundles/infrab4a-connect-angular.umd.js +107 -52
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/angular-firestore.module.js +18 -4
- package/esm2015/angular-hasura-graphql.module.js +24 -2
- package/esm2015/services/cart.service.js +38 -31
- package/esm2015/services/errors/group-invalid-coupon.error.js +3 -2
- package/esm2015/services/errors/invalid-coupon.error.js +3 -2
- package/esm2015/services/home-shop.service.js +2 -2
- package/fesm2015/infrab4a-connect-angular.js +77 -34
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +3 -3
- package/services/cart.service.d.ts +3 -2
- package/services/errors/group-invalid-coupon.error.d.ts +2 -1
- package/services/errors/invalid-coupon.error.d.ts +2 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/fire/auth'), require('@infrab4a/connect'), require('js-cookie'), require('@angular/fire/firestore'), require('@angular/fire')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@infrab4a/connect-angular', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/fire/auth', '@infrab4a/connect', 'js-cookie', '@angular/fire/firestore', '@angular/fire'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a["connect-angular"] = {}), global.ng.core, global.rxjs, global.rxjs.operators, global.ng.fire.auth, global["@infrab4a/connect"], global["js-cookie"], global.ng.fire.firestore, global.ng.fire));
|
|
5
|
-
})(this, (function (exports, i0, rxjs, operators, i1, i2, cookie, i1$1, fire) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/fire/auth'), require('@infrab4a/connect'), require('js-cookie'), require('ts-custom-error'), require('@angular/fire/firestore'), require('@angular/fire')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('@infrab4a/connect-angular', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/fire/auth', '@infrab4a/connect', 'js-cookie', 'ts-custom-error', '@angular/fire/firestore', '@angular/fire'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a["connect-angular"] = {}), global.ng.core, global.rxjs, global.rxjs.operators, global.ng.fire.auth, global["@infrab4a/connect"], global["js-cookie"], global["ts-custom-error"], global.ng.fire.firestore, global.ng.fire));
|
|
5
|
+
})(this, (function (exports, i0, rxjs, operators, i1, i2, cookie, tsCustomError, i1$1, fire) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -403,7 +403,7 @@
|
|
|
403
403
|
return _this;
|
|
404
404
|
}
|
|
405
405
|
return InvalidCouponError;
|
|
406
|
-
}(
|
|
406
|
+
}(tsCustomError.CustomError));
|
|
407
407
|
|
|
408
408
|
var GroupInvalidCouponError = /** @class */ (function (_super) {
|
|
409
409
|
__extends(GroupInvalidCouponError, _super);
|
|
@@ -413,7 +413,7 @@
|
|
|
413
413
|
return _this;
|
|
414
414
|
}
|
|
415
415
|
return GroupInvalidCouponError;
|
|
416
|
-
}(
|
|
416
|
+
}(tsCustomError.CustomError));
|
|
417
417
|
|
|
418
418
|
var CouponService = /** @class */ (function () {
|
|
419
419
|
function CouponService(couponRepository, defaultShop) {
|
|
@@ -566,11 +566,12 @@
|
|
|
566
566
|
} });
|
|
567
567
|
|
|
568
568
|
var CartService = /** @class */ (function () {
|
|
569
|
-
function CartService(authService, checkoutService, defaultShop) {
|
|
569
|
+
function CartService(authService, checkoutService, defaultShop, productRepository) {
|
|
570
570
|
var _this = this;
|
|
571
571
|
this.authService = authService;
|
|
572
572
|
this.checkoutService = checkoutService;
|
|
573
573
|
this.defaultShop = defaultShop;
|
|
574
|
+
this.productRepository = productRepository;
|
|
574
575
|
this.cartSubject = new rxjs.Subject();
|
|
575
576
|
this.updateLineItemInCart = function (lineItem, quantity, checkout) { return (i2.isNil(checkout) ? _this.checkoutService.getCheckout() : rxjs.of(checkout)).pipe(operators.concatMap(function (checkoutLoaded) {
|
|
576
577
|
var _a;
|
|
@@ -594,39 +595,52 @@
|
|
|
594
595
|
});
|
|
595
596
|
return cart;
|
|
596
597
|
};
|
|
597
|
-
this.buildLineItem = function (
|
|
598
|
-
var checkout =
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
598
|
+
this.buildLineItem = function (_g) {
|
|
599
|
+
var checkout = _g.checkout, item = _g.item, quantity = _g.quantity;
|
|
600
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
601
|
+
var _a, _b, _c, _d, _e, _f, product, image, id, name, EAN, brand, slug, stock, price, weight, categories, sku, isGift, pricePaid;
|
|
602
|
+
return __generator(this, function (_g) {
|
|
603
|
+
switch (_g.label) {
|
|
604
|
+
case 0: return [4 /*yield*/, this.productRepository.get({ id: item.id })];
|
|
605
|
+
case 1:
|
|
606
|
+
product = _g.sent();
|
|
607
|
+
item.quantity = (item === null || item === void 0 ? void 0 : item.quantity) || ((_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find(function (lineItem) { return lineItem.sku === item.sku; })) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
|
|
608
|
+
if (this.checkMaxStock(item, quantity || 0))
|
|
609
|
+
throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
|
|
610
|
+
image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
|
|
611
|
+
id = item.id, name = item.name, EAN = item.EAN, brand = item.brand, slug = item.slug, stock = item.stock, price = item.price, weight = item.weight, categories = item.categories, sku = item.sku;
|
|
612
|
+
isGift = item.isGift || null;
|
|
613
|
+
pricePaid = this.getProductPrice({
|
|
614
|
+
product: item,
|
|
615
|
+
shop: checkout.shop || this.defaultShop,
|
|
616
|
+
isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
|
|
617
|
+
});
|
|
618
|
+
return [2 /*return*/, {
|
|
619
|
+
checkout: checkout,
|
|
620
|
+
lineItem: i2.LineItem.toInstance({
|
|
621
|
+
id: id,
|
|
622
|
+
name: name,
|
|
623
|
+
EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
|
|
624
|
+
brand: product.brand,
|
|
625
|
+
slug: slug,
|
|
626
|
+
sku: sku,
|
|
627
|
+
stock: stock,
|
|
628
|
+
price: price,
|
|
629
|
+
image: image,
|
|
630
|
+
weight: weight !== null && weight !== void 0 ? weight : product.weight,
|
|
631
|
+
quantity: (item.quantity || 0) + (quantity || 0),
|
|
632
|
+
pricePaid: pricePaid,
|
|
633
|
+
categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
|
|
634
|
+
isGift: isGift !== null && isGift !== void 0 ? isGift : null,
|
|
635
|
+
costPrice: item === null || item === void 0 ? void 0 : item.costPrice,
|
|
636
|
+
}),
|
|
637
|
+
}];
|
|
638
|
+
}
|
|
639
|
+
});
|
|
626
640
|
});
|
|
627
641
|
};
|
|
628
|
-
this.getProductPrice = function (
|
|
629
|
-
var product =
|
|
642
|
+
this.getProductPrice = function (_g) {
|
|
643
|
+
var product = _g.product, shop = _g.shop, isSubscriber = _g.isSubscriber;
|
|
630
644
|
var info = product.getInfoByShop(shop);
|
|
631
645
|
if (product.isGift)
|
|
632
646
|
return 0;
|
|
@@ -642,11 +656,8 @@
|
|
|
642
656
|
CartService.prototype.addItem = function (item, quantity) {
|
|
643
657
|
var _this = this;
|
|
644
658
|
if (quantity === void 0) { quantity = 1; }
|
|
645
|
-
return this.checkoutService.getCheckout().pipe(operators.
|
|
646
|
-
checkout
|
|
647
|
-
lineItem: _this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 }),
|
|
648
|
-
}); }), operators.concatMap(function (_f) {
|
|
649
|
-
var checkout = _f.checkout, lineItem = _f.lineItem;
|
|
659
|
+
return rxjs.from(this.checkoutService.getCheckout()).pipe(operators.concatMap(function (checkout) { return _this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 }); }), operators.mergeMap(function (_g) {
|
|
660
|
+
var checkout = _g.checkout, lineItem = _g.lineItem;
|
|
650
661
|
return _this.updateLineItemInCart(lineItem, quantity || 1, checkout);
|
|
651
662
|
}), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
652
663
|
};
|
|
@@ -699,7 +710,12 @@
|
|
|
699
710
|
var _this = this;
|
|
700
711
|
return this.checkoutService.getCheckout().pipe(operators.concatMap(function (checkout) { return _this.checkoutService.updateCheckoutUser(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user: user }))); }), operators.concatMap(function (checkout) {
|
|
701
712
|
var _a;
|
|
702
|
-
return _this.checkoutService.updateCheckoutLineItems(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (item) { return _this
|
|
713
|
+
return _this.checkoutService.updateCheckoutLineItems(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_g) {
|
|
714
|
+
switch (_g.label) {
|
|
715
|
+
case 0: return [4 /*yield*/, this.buildLineItem({ checkout: checkout, item: item })];
|
|
716
|
+
case 1: return [2 /*return*/, _g.sent()];
|
|
717
|
+
}
|
|
718
|
+
}); }); })) || [] })));
|
|
703
719
|
}), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
704
720
|
};
|
|
705
721
|
CartService.prototype.clearCart = function () {
|
|
@@ -726,7 +742,7 @@
|
|
|
726
742
|
};
|
|
727
743
|
return CartService;
|
|
728
744
|
}());
|
|
729
|
-
CartService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
745
|
+
CartService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
730
746
|
CartService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService });
|
|
731
747
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, decorators: [{
|
|
732
748
|
type: i0.Injectable
|
|
@@ -734,6 +750,9 @@
|
|
|
734
750
|
return [{ type: AuthService }, { type: CheckoutService }, { type: i2__namespace.Shops, decorators: [{
|
|
735
751
|
type: i0.Inject,
|
|
736
752
|
args: [DEFAULT_SHOP]
|
|
753
|
+
}] }, { type: undefined, decorators: [{
|
|
754
|
+
type: i0.Inject,
|
|
755
|
+
args: ['ProductRepository']
|
|
737
756
|
}] }];
|
|
738
757
|
} });
|
|
739
758
|
|
|
@@ -878,10 +897,10 @@
|
|
|
878
897
|
});
|
|
879
898
|
HomeShopService.prototype.getHomeData = function () {
|
|
880
899
|
var _this = this;
|
|
881
|
-
return this.getHomeConfiguration().pipe(operators.map(function () { return null; }), operators.concatMap(function (home) { return home
|
|
900
|
+
return this.getHomeConfiguration().pipe(operators.map(function (home) { var _a; return (((_a = home === null || home === void 0 ? void 0 : home.data) === null || _a === void 0 ? void 0 : _a.expiresAt) > new Date() ? home : null); }), operators.concatMap(function (home) { return home
|
|
882
901
|
? rxjs.of(home)
|
|
883
|
-
: rxjs.forkJoin([_this.getDiscoverProducts(), _this.getFeaturedProducts(), _this.getVerticalProducts()]).pipe(operators.map(function (
|
|
884
|
-
var
|
|
902
|
+
: rxjs.forkJoin([_this.getDiscoverProducts(), _this.getFeaturedProducts(), _this.getVerticalProducts()]).pipe(operators.map(function (_b) {
|
|
903
|
+
var _c = __read(_b, 3), discoverProducts = _c[0], featuredProducts = _c[1], verticalProducts = _c[2];
|
|
885
904
|
return ({
|
|
886
905
|
discoverProducts: discoverProducts,
|
|
887
906
|
featuredProducts: featuredProducts,
|
|
@@ -914,8 +933,8 @@
|
|
|
914
933
|
return this.getHomeConfiguration().pipe(operators.concatMap(function (home) { return rxjs.forkJoin(home.verticalCarousels.filter(Boolean).map(function (id) { return rxjs.from(_this.categoryRepository.get({ id: id })).pipe(operators.concatMap(function (category) { return rxjs.from(_this.productRepository.find({
|
|
915
934
|
filters: { categories: { operator: i2.Where.IN, value: [category.id] } },
|
|
916
935
|
limits: { limit: 12 },
|
|
917
|
-
})).pipe(operators.map(function (products) { return ({ category: category, products: products }); })); }), operators.map(function (
|
|
918
|
-
var category =
|
|
936
|
+
})).pipe(operators.map(function (products) { return ({ category: category, products: products }); })); }), operators.map(function (_b) {
|
|
937
|
+
var category = _b.category, products = _b.products;
|
|
919
938
|
return ({ category: category, products: products.data });
|
|
920
939
|
}), operators.map(_this.buildCategoryGroupWithRequiredData)); })); }));
|
|
921
940
|
};
|
|
@@ -1141,6 +1160,13 @@
|
|
|
1141
1160
|
},
|
|
1142
1161
|
deps: [i1$1.AngularFirestore],
|
|
1143
1162
|
},
|
|
1163
|
+
{
|
|
1164
|
+
provide: i2.CategoryFirestoreRepository,
|
|
1165
|
+
useFactory: function (firestore) {
|
|
1166
|
+
return new i2.CategoryFirestoreRepository(firestore.firestore);
|
|
1167
|
+
},
|
|
1168
|
+
deps: [i1$1.AngularFirestore],
|
|
1169
|
+
},
|
|
1144
1170
|
{
|
|
1145
1171
|
provide: 'CheckoutRepository',
|
|
1146
1172
|
useFactory: function (firestore) {
|
|
@@ -1268,7 +1294,7 @@
|
|
|
1268
1294
|
deps: [i1$1.AngularFirestore, 'UserRepository'],
|
|
1269
1295
|
},
|
|
1270
1296
|
{
|
|
1271
|
-
provide:
|
|
1297
|
+
provide: i2.ProductVariantFirestoreRepository,
|
|
1272
1298
|
useFactory: function (firestore, productRepository) {
|
|
1273
1299
|
return new i2.ProductVariantFirestoreRepository(firestore.firestore, productRepository);
|
|
1274
1300
|
},
|
|
@@ -1294,6 +1320,13 @@
|
|
|
1294
1320
|
},
|
|
1295
1321
|
deps: [i1$1.AngularFirestore],
|
|
1296
1322
|
},
|
|
1323
|
+
{
|
|
1324
|
+
provide: i2.CategoryFirestoreRepository,
|
|
1325
|
+
useFactory: function (firestore) {
|
|
1326
|
+
return new i2.CategoryFirestoreRepository(firestore.firestore);
|
|
1327
|
+
},
|
|
1328
|
+
deps: [i1$1.AngularFirestore],
|
|
1329
|
+
},
|
|
1297
1330
|
{
|
|
1298
1331
|
provide: 'CheckoutRepository',
|
|
1299
1332
|
useFactory: function (firestore) {
|
|
@@ -1421,7 +1454,7 @@
|
|
|
1421
1454
|
deps: [i1$1.AngularFirestore, 'UserRepository'],
|
|
1422
1455
|
},
|
|
1423
1456
|
{
|
|
1424
|
-
provide:
|
|
1457
|
+
provide: i2.ProductVariantFirestoreRepository,
|
|
1425
1458
|
useFactory: function (firestore, productRepository) {
|
|
1426
1459
|
return new i2.ProductVariantFirestoreRepository(firestore.firestore, productRepository);
|
|
1427
1460
|
},
|
|
@@ -1467,6 +1500,17 @@
|
|
|
1467
1500
|
},
|
|
1468
1501
|
deps: [HASURA_OPTIONS],
|
|
1469
1502
|
},
|
|
1503
|
+
{
|
|
1504
|
+
provide: 'VariantRepository',
|
|
1505
|
+
useExisting: i2.VariantHasuraGraphQLRepository,
|
|
1506
|
+
},
|
|
1507
|
+
{
|
|
1508
|
+
provide: i2.VariantHasuraGraphQLRepository,
|
|
1509
|
+
useFactory: function (options) {
|
|
1510
|
+
return new i2.VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
|
|
1511
|
+
},
|
|
1512
|
+
deps: [HASURA_OPTIONS],
|
|
1513
|
+
},
|
|
1470
1514
|
] });
|
|
1471
1515
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: AngularHasuraGraphQLModule, decorators: [{
|
|
1472
1516
|
type: i0.NgModule,
|
|
@@ -1494,6 +1538,17 @@
|
|
|
1494
1538
|
},
|
|
1495
1539
|
deps: [HASURA_OPTIONS],
|
|
1496
1540
|
},
|
|
1541
|
+
{
|
|
1542
|
+
provide: 'VariantRepository',
|
|
1543
|
+
useExisting: i2.VariantHasuraGraphQLRepository,
|
|
1544
|
+
},
|
|
1545
|
+
{
|
|
1546
|
+
provide: i2.VariantHasuraGraphQLRepository,
|
|
1547
|
+
useFactory: function (options) {
|
|
1548
|
+
return new i2.VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
|
|
1549
|
+
},
|
|
1550
|
+
deps: [HASURA_OPTIONS],
|
|
1551
|
+
},
|
|
1497
1552
|
],
|
|
1498
1553
|
}]
|
|
1499
1554
|
}] });
|