ng-miam 10.3.0 → 10.3.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.
Files changed (34) hide show
  1. package/bundles/ng-miam.umd.js +107 -24
  2. package/bundles/ng-miam.umd.js.map +1 -1
  3. package/bundles/ng-miam.umd.min.js +1 -1
  4. package/bundles/ng-miam.umd.min.js.map +1 -1
  5. package/esm2015/lib/_services/baskets.service.js +28 -9
  6. package/esm2015/lib/_services/context.service.js +35 -13
  7. package/esm2015/lib/_services/index.js +2 -1
  8. package/esm2015/lib/_services/menus.service.js +34 -0
  9. package/esm2015/lib/_services/new-recipe-details.service.js +8 -2
  10. package/esm2015/lib/_services/replace-item.service.js +4 -1
  11. package/esm2015/lib/_types/builded/mealz-internal-interface.js +1 -1
  12. package/esm2015/lib/_utils/journey.util.js +7 -2
  13. package/esm2015/lib/environments/environment.js +2 -2
  14. package/esm2015/lib/environments/environment.prod.js +2 -2
  15. package/esm2015/lib/environments/version.js +2 -2
  16. package/fesm2015/ng-miam.js +118 -40
  17. package/fesm2015/ng-miam.js.map +1 -1
  18. package/lib/_services/baskets.service.d.ts +4 -1
  19. package/lib/_services/baskets.service.d.ts.map +1 -1
  20. package/lib/_services/context.service.d.ts +1 -0
  21. package/lib/_services/context.service.d.ts.map +1 -1
  22. package/lib/_services/index.d.ts +1 -0
  23. package/lib/_services/index.d.ts.map +1 -1
  24. package/lib/_services/menus.service.d.ts +18 -0
  25. package/lib/_services/menus.service.d.ts.map +1 -0
  26. package/lib/_services/new-recipe-details.service.d.ts +1 -1
  27. package/lib/_services/new-recipe-details.service.d.ts.map +1 -1
  28. package/lib/_services/replace-item.service.d.ts +1 -0
  29. package/lib/_services/replace-item.service.d.ts.map +1 -1
  30. package/lib/_types/builded/mealz-internal-interface.d.ts +18 -3
  31. package/lib/_types/builded/mealz-internal-interface.d.ts.map +1 -1
  32. package/lib/_utils/journey.util.d.ts.map +1 -1
  33. package/lib/environments/version.d.ts +1 -1
  34. package/package.json +1 -1
@@ -735,9 +735,14 @@
735
735
  var detectJourney = function (mappings, document, location) {
736
736
  var e_1, _b;
737
737
  var doc = document !== null && document !== void 0 ? document : (typeof window !== 'undefined' ? window.document : null);
738
- if (!doc) {
738
+ var loc = location !== null && location !== void 0 ? location : (typeof window !== 'undefined' ? window.location : null);
739
+ if (!doc || !loc) {
739
740
  return null;
740
741
  }
742
+ var urlParams = new URLSearchParams(loc.search);
743
+ if (urlParams.has('from') && urlParams.get('from') === 'header') {
744
+ return 'meals-space-header';
745
+ }
741
746
  var journeyMappings = mappings !== null && mappings !== void 0 ? mappings : defaultJourneyMappings;
742
747
  try {
743
748
  // Check each journey mapping
@@ -1635,7 +1640,7 @@
1635
1640
  env: 'prod',
1636
1641
  miamAPI: 'https://api.miam.tech',
1637
1642
  miamWeb: 'https://miam.tech',
1638
- mealzComponents: 'https://cdn.jsdelivr.net/npm/mealz-components@2.5/dist',
1643
+ mealzComponents: 'https://cdn.jsdelivr.net/npm/mealz-components@2.6/dist',
1639
1644
  mealzSsrApi: 'https://ssr-api.mealz.ai',
1640
1645
  lang: 'fr',
1641
1646
  analyticsEnabled: true // Only used in DEV mode
@@ -3435,7 +3440,7 @@
3435
3440
  EventJourney["EMPTY"] = "";
3436
3441
  })(EventJourney || (EventJourney = {}));
3437
3442
 
3438
- var VERSION = "10.3.0"; // TODO: replace by ##VERSION## and update it in the CI/CD
3443
+ var VERSION = "10.3.2"; // TODO: replace by ##VERSION## and update it in the CI/CD
3439
3444
 
3440
3445
  var ContextRegistryService = /** @class */ (function () {
3441
3446
  function ContextRegistryService() {
@@ -5902,12 +5907,40 @@
5902
5907
  }], function () { return [{ type: CurrencyService }]; }, null);
5903
5908
  })();
5904
5909
 
5910
+ var MenusService = /** @class */ (function () {
5911
+ function MenusService(http, statesService) {
5912
+ this.http = http;
5913
+ this.statesService = statesService;
5914
+ }
5915
+ /**
5916
+ * Transfers the authless user's current menu to the authenticated user.
5917
+ * Replaces the user's menu with the authless one (no merge).
5918
+ * Call at end of authless journey when user logs in. Authless user must have a current menu.
5919
+ */
5920
+ MenusService.prototype.transferAuthlessMenu = function (authlessId) {
5921
+ this.statesService.callAuthlessTransfer.next();
5922
+ var url = environment$1.miamAPI + "/api/v1/menus/transfer-authless?authless_user_id=" + authlessId;
5923
+ return this.http.patch(url, {}).pipe(operators.map(function () { return undefined; }), operators.catchError(function () { return rxjs.of(undefined); }));
5924
+ };
5925
+ return MenusService;
5926
+ }());
5927
+ MenusService.ɵfac = function MenusService_Factory(t) { return new (t || MenusService)(i0__namespace.ɵɵinject(i1__namespace.HttpClient), i0__namespace.ɵɵinject(StatesService)); };
5928
+ MenusService.ɵprov = i0__namespace.ɵɵdefineInjectable({ token: MenusService, factory: MenusService.ɵfac, providedIn: 'root' });
5929
+ (function () {
5930
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(MenusService, [{
5931
+ type: i0.Injectable,
5932
+ args: [{
5933
+ providedIn: 'root'
5934
+ }]
5935
+ }], function () { return [{ type: i1__namespace.HttpClient }, { type: StatesService }]; }, null);
5936
+ })();
5937
+
5905
5938
  var BASKET_SPARSE_FIELDS = {
5906
5939
  baskets: ['total-price', 'recipes-infos', 'completion', 'status']
5907
5940
  };
5908
5941
  var BasketsService = /** @class */ (function (_super) {
5909
5942
  __extends(BasketsService, _super);
5910
- function BasketsService(http, basketEntriesService, posService, recipesService, analyticsService, usersService, toasterService, ignoredBasketsService, statesService, priceService) {
5943
+ function BasketsService(http, basketEntriesService, posService, recipesService, analyticsService, usersService, toasterService, ignoredBasketsService, statesService, priceService, menusService) {
5911
5944
  var _this = _super.call(this) || this;
5912
5945
  _this.http = http;
5913
5946
  _this.basketEntriesService = basketEntriesService;
@@ -5919,6 +5952,7 @@
5919
5952
  _this.ignoredBasketsService = ignoredBasketsService;
5920
5953
  _this.statesService = statesService;
5921
5954
  _this.priceService = priceService;
5955
+ _this.menusService = menusService;
5922
5956
  _this.resource = Basket;
5923
5957
  _this.type = 'baskets';
5924
5958
  _this._basket$ = new rxjs.BehaviorSubject(null);
@@ -5932,6 +5966,7 @@
5932
5966
  _this.confirming = new rxjs.BehaviorSubject(false);
5933
5967
  _this.currentlyAddingRecipes = [];
5934
5968
  _this.basketActionsQueue = new rxjs.BehaviorSubject([]);
5969
+ _this.authlessTransferInProgress$ = new rxjs.BehaviorSubject(false);
5935
5970
  _this._entries$ = new rxjs.BehaviorSubject([]);
5936
5971
  _this.actionsBeingProcessed = new rxjs.BehaviorSubject([]);
5937
5972
  _this.actionsBeingOverridden = [];
@@ -6146,12 +6181,27 @@
6146
6181
  mealzDebug('[Mealz] refreshing basket');
6147
6182
  var authlessId = localStorage.getItem('_miam/authlessId');
6148
6183
  var userId = localStorage.getItem('_miam/userId');
6149
- if (_this.currentSubscription) {
6184
+ var hasAuthlessAndUser = !!authlessId && !!userId;
6185
+ if (_this.authlessTransferInProgress$.value) {
6186
+ return _this._basket$;
6187
+ }
6188
+ // We can safely cancel any previous in-flight request as long as it's not an authless transfer.
6189
+ if (_this.currentSubscription && !_this.authlessTransferInProgress$.value) {
6150
6190
  _this.currentSubscription.unsubscribe();
6151
6191
  }
6152
- var basketObservable = (authlessId && userId)
6153
- ? _this.transferAuthlessBasket(pos.id, authlessId)
6154
- : _this.fetchCurrentBasket(pos.id);
6192
+ var basketObservable;
6193
+ if (hasAuthlessAndUser) {
6194
+ _this.authlessTransferInProgress$.next(true);
6195
+ basketObservable = rxjs.forkJoin([
6196
+ _this.transferAuthlessBasket(pos.id, authlessId),
6197
+ _this.menusService.transferAuthlessMenu(authlessId)
6198
+ ]).pipe(operators.map(function () { return undefined; }), operators.finalize(function () {
6199
+ _this.authlessTransferInProgress$.next(false);
6200
+ }));
6201
+ }
6202
+ else {
6203
+ basketObservable = _this.fetchCurrentBasket(pos.id);
6204
+ }
6155
6205
  if (authlessId && userId) {
6156
6206
  localStorage.removeItem('_miam/authlessId');
6157
6207
  localStorage.removeItem('_miam/authless-forbid-profiling');
@@ -6920,7 +6970,7 @@
6920
6970
  return BasketsService;
6921
6971
  }(i2$2.Service));
6922
6972
  BasketsService.entriesPerPages = 30;
6923
- BasketsService.ɵfac = function BasketsService_Factory(t) { return new (t || BasketsService)(i0__namespace.ɵɵinject(i1__namespace.HttpClient), i0__namespace.ɵɵinject(BasketEntriesService), i0__namespace.ɵɵinject(PointOfSalesService), i0__namespace.ɵɵinject(RecipesService), i0__namespace.ɵɵinject(AnalyticsService), i0__namespace.ɵɵinject(UserService), i0__namespace.ɵɵinject(ToasterService), i0__namespace.ɵɵinject(IgnoredIngredientsService), i0__namespace.ɵɵinject(StatesService), i0__namespace.ɵɵinject(PriceService)); };
6973
+ BasketsService.ɵfac = function BasketsService_Factory(t) { return new (t || BasketsService)(i0__namespace.ɵɵinject(i1__namespace.HttpClient), i0__namespace.ɵɵinject(BasketEntriesService), i0__namespace.ɵɵinject(PointOfSalesService), i0__namespace.ɵɵinject(RecipesService), i0__namespace.ɵɵinject(AnalyticsService), i0__namespace.ɵɵinject(UserService), i0__namespace.ɵɵinject(ToasterService), i0__namespace.ɵɵinject(IgnoredIngredientsService), i0__namespace.ɵɵinject(StatesService), i0__namespace.ɵɵinject(PriceService), i0__namespace.ɵɵinject(MenusService)); };
6924
6974
  BasketsService.ɵprov = i0__namespace.ɵɵdefineInjectable({ token: BasketsService, factory: BasketsService.ɵfac, providedIn: 'root' });
6925
6975
  (function () {
6926
6976
  (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(BasketsService, [{
@@ -6928,7 +6978,7 @@
6928
6978
  args: [{
6929
6979
  providedIn: 'root'
6930
6980
  }]
6931
- }], function () { return [{ type: i1__namespace.HttpClient }, { type: BasketEntriesService }, { type: PointOfSalesService }, { type: RecipesService }, { type: AnalyticsService }, { type: UserService }, { type: ToasterService }, { type: IgnoredIngredientsService }, { type: StatesService }, { type: PriceService }]; }, null);
6981
+ }], function () { return [{ type: i1__namespace.HttpClient }, { type: BasketEntriesService }, { type: PointOfSalesService }, { type: RecipesService }, { type: AnalyticsService }, { type: UserService }, { type: ToasterService }, { type: IgnoredIngredientsService }, { type: StatesService }, { type: PriceService }, { type: MenusService }]; }, null);
6932
6982
  })();
6933
6983
 
6934
6984
  var BasketRecipeCleanupService = /** @class */ (function () {
@@ -9707,6 +9757,9 @@
9707
9757
  this.addProductMode = state;
9708
9758
  this.additionModalOpen$.next(state);
9709
9759
  };
9760
+ ReplaceItemService.prototype.setRecipe = function (recipe) {
9761
+ this.recipe = recipe;
9762
+ };
9710
9763
  /**
9711
9764
  * Replaces the selected item in the given basket entry with the given item.
9712
9765
  * If the basket entry currently has a selected item, it will be removed.
@@ -10671,8 +10724,14 @@
10671
10724
  _this.invalidPosDisplay$.next(!_this.noPosDisplay$.value && !isValid);
10672
10725
  });
10673
10726
  };
10674
- NewRecipeDetailsService.prototype.updateGuests = function (eventTrace) {
10727
+ NewRecipeDetailsService.prototype.updateGuests = function (eventTrace, guests) {
10675
10728
  var _this = this;
10729
+ if (!this.recipe) {
10730
+ return;
10731
+ }
10732
+ if (typeof guests === 'number' && this.recipe) {
10733
+ this.recipe.modifiedGuests = guests;
10734
+ }
10676
10735
  this.basketsService.recipeIsInBasket(this.recipe.id).pipe(operators.take(1)).subscribe(function (inBasket) {
10677
10736
  _this.basketsService.updateRecipesInBasket([_this.recipe.id], _this.recipe.modifiedGuests, eventTrace, true);
10678
10737
  _this.recipeDetailsProductsService.getIngredientsBasketEntries(_this.recipe.ingredients, _this.recipe.modifiedGuests, false).pipe(operators.take(1)).subscribe(function (products) {
@@ -11272,8 +11331,9 @@
11272
11331
  if (categoryId === void 0) { categoryId = null; }
11273
11332
  return _this.recipesService.openRecipeDetails(recipeId, guests, initialTabIndex, path, categoryId);
11274
11333
  },
11334
+ loadAndSetupRecipe: function (recipeId, guests) { return _this.loadAndSetupRecipe(recipeId, guests); },
11275
11335
  replaceBasketEntry: function (basketEntry, ignoreSelected) { return _this.recipeDetailsProductsService.replaceBasketEntry(basketEntry, ignoreSelected); },
11276
- updateGuests: function (eventTrace) { return _this.newRecipeDetailsService.updateGuests(eventTrace); },
11336
+ updateGuests: function (eventTrace, guests) { return _this.newRecipeDetailsService.updateGuests(eventTrace, guests); },
11277
11337
  addAllIngredientsToBasket: function (eventTrace) { return _this.newRecipeDetailsService.addAllIngredientsToBasket(eventTrace); },
11278
11338
  addToBasket: function (product, eventTrace) { return _this.newRecipeDetailsService.addToBasket(product, eventTrace); },
11279
11339
  ingredientRemoved: function (ingredient, eventTrace) { return _this.newRecipeDetailsService.ingredientRemoved(ingredient, eventTrace); },
@@ -11342,6 +11402,7 @@
11342
11402
  },
11343
11403
  pos: {
11344
11404
  currentPos: function () { return _this.posService.pos$; },
11405
+ posWasInitialized: function () { return _this.posService.posWasInitialized(); },
11345
11406
  loadPos: function (posId) { return _this.posService.loadPos(posId); },
11346
11407
  basketLoadedForNewPos: function () { return _this.posService.basketLoadedForNewPos(); }
11347
11408
  },
@@ -11408,9 +11469,23 @@
11408
11469
  autocomplete: function (query) { return _this.tagsService.autocomplete(query); }
11409
11470
  },
11410
11471
  hook: {
11411
- hookCallback: function () { return rxjs.combineLatest([
11412
- _this.userService.isLogged$,
11413
- _this.posService.posWasInitialized()
11472
+ hookCallback: function (needLogin, needPos) { return rxjs.combineLatest([
11473
+ // needLogin === true => ask for login (false)
11474
+ // needLogin === false => don't ask (true)
11475
+ // needLogin === undefined => check userService.isLogged$
11476
+ needLogin === true
11477
+ ? rxjs.of(false)
11478
+ : needLogin === false
11479
+ ? rxjs.of(true)
11480
+ : _this.userService.isLogged$,
11481
+ // needPos === true => ask for pos (false)
11482
+ // needPos === false => don't ask (true)
11483
+ // needPos === undefined => check posService.posWasInitialized()
11484
+ needPos === true
11485
+ ? rxjs.of(false)
11486
+ : needPos === false
11487
+ ? rxjs.of(true)
11488
+ : _this.posService.posWasInitialized()
11414
11489
  ]).pipe(operators.take(1), operators.switchMap(function (_a) {
11415
11490
  var _b = __read(_a, 2), isLogged = _b[0], posId = _b[1];
11416
11491
  return rxjs.of(_this.contextRegistryService.hookCallback(isLogged, posId));
@@ -11546,13 +11621,7 @@
11546
11621
  ContextService.prototype.addAllIngredientsFromRecipeId = function (recipeId, guests) {
11547
11622
  var _this = this;
11548
11623
  var eventTrace = { originPath: '/locator', props: { recipe_id: recipeId } };
11549
- return this.recipesService.get(recipeId, { include: ['ingredients', 'recipe-steps', 'recipe-type', 'sponsors', 'tags', 'recipe-provider'] })
11550
- .pipe(operators.map(function (recipe) {
11551
- if (guests && guests > 0) {
11552
- recipe.modifiedGuests = guests;
11553
- }
11554
- return recipe;
11555
- }), operators.switchMap(function (recipe) { return _this.newRecipeDetailsService.setupRecipe(recipe); }), operators.tap(function () {
11624
+ return this.loadAndSetupRecipe(recipeId, guests).pipe(operators.tap(function () {
11556
11625
  // Wait for the loading to complete and open basket
11557
11626
  _this.waitForIngredientsToFinish().pipe(operators.tap(function () {
11558
11627
  _this.basketUtilsService.openBasket('/locator', 1);
@@ -11561,7 +11630,6 @@
11561
11630
  _this.newRecipeDetailsService.addAllIngredientsToBasket(eventTrace);
11562
11631
  }), operators.take(1), operators.map(function () { return void 0; }));
11563
11632
  };
11564
- ;
11565
11633
  ContextService.prototype.waitForIngredientsToFinish = function () {
11566
11634
  var _this = this;
11567
11635
  var waitFor = function (loadingState) { return _this.newRecipeDetailsService.allIngredientsToBasketLoading$.pipe(operators.skipWhile(function (loading) { return loading === loadingState; }), operators.take(1)); };
@@ -11572,6 +11640,20 @@
11572
11640
  // Finally wait for false again (loading completed)
11573
11641
  operators.switchMap(function () { return waitFor(true); }));
11574
11642
  };
11643
+ ContextService.prototype.loadAndSetupRecipe = function (recipeId, guests) {
11644
+ var _this = this;
11645
+ if (!recipeId) {
11646
+ return rxjs.of(void 0);
11647
+ }
11648
+ return this.recipesService.get(recipeId, { include: ['ingredients', 'recipe-steps', 'recipe-type', 'sponsors', 'tags', 'recipe-provider'] })
11649
+ .pipe(operators.take(1), operators.switchMap(function (recipe) {
11650
+ if (guests != null) {
11651
+ recipe.modifiedGuests = guests;
11652
+ }
11653
+ _this.replaceItemService.setRecipe(recipe);
11654
+ return _this.newRecipeDetailsService.setupRecipe(recipe);
11655
+ }));
11656
+ };
11575
11657
  return ContextService;
11576
11658
  }());
11577
11659
  ContextService.ɵfac = function ContextService_Factory(t) { return new (t || ContextService)(i0__namespace.ɵɵinject(PointOfSalesService), i0__namespace.ɵɵinject(BasketsService), i0__namespace.ɵɵinject(UserService), i0__namespace.ɵɵinject(PreferencesService), i0__namespace.ɵɵinject(AnalyticsService), i0__namespace.ɵɵinject(RecipesService), i0__namespace.ɵɵinject(BasketRecipeCleanupService), i0__namespace.ɵɵinject(i8__namespace.MediaMatcher), i0__namespace.ɵɵinject(SuppliersService), i0__namespace.ɵɵinject(i8__namespace.BreakpointObserver), i0__namespace.ɵɵinject(BasketsSynchronizerService), i0__namespace.ɵɵinject(StoreLocatorService), i0__namespace.ɵɵinject(RecipeLikesService), i0__namespace.ɵɵinject(FakeRetailerCartService), i0__namespace.ɵɵinject(ContextRegistryService), i0__namespace.ɵɵinject(BasketUtilsService), i0__namespace.ɵɵinject(BasketTransferService), i0__namespace.ɵɵinject(RecipeDetailsService), i0__namespace.ɵɵinject(RecipeDetailsProductsService), i0__namespace.ɵɵinject(RecipeDetailsProductsPlannerService), i0__namespace.ɵɵinject(NewRecipeDetailsService), i0__namespace.ɵɵinject(ReplaceItemService), i0__namespace.ɵɵinject(MealsPlannerService), i0__namespace.ɵɵinject(TagsService)); };
@@ -12923,7 +13005,7 @@
12923
13005
  env: 'prod',
12924
13006
  miamAPI: 'https://api.miam.tech',
12925
13007
  miamWeb: 'https://miam.tech',
12926
- mealzComponents: 'https://cdn.jsdelivr.net/npm/mealz-components@2.5/dist',
13008
+ mealzComponents: 'https://cdn.jsdelivr.net/npm/mealz-components@2.6/dist',
12927
13009
  mealzSsrApi: 'https://ssr-api.mealz.ai',
12928
13010
  lang: 'fr',
12929
13011
  analyticsEnabled: true // Only used in DEV mode
@@ -22234,6 +22316,7 @@
22234
22316
  exports.Menu = Menu;
22235
22317
  exports.MenuItem = MenuItem;
22236
22318
  exports.MenuRecipe = MenuRecipe;
22319
+ exports.MenusService = MenusService;
22237
22320
  exports.MiamInterceptor = MiamInterceptor;
22238
22321
  exports.ModalComponent = ModalComponent;
22239
22322
  exports.NgMiamModule = NgMiamModule;