ng-miam 8.8.14 → 8.8.16

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.
@@ -3329,6 +3329,8 @@
3329
3329
  this.generatingAuthlessId$ = new rxjs.BehaviorSubject(false);
3330
3330
  this.userCoordinates$ = new rxjs.BehaviorSubject(undefined);
3331
3331
  this.userInfo$ = new rxjs.BehaviorSubject(undefined);
3332
+ /** In-flight authless POST shared by concurrent callers (replaces debounce-only coalescing). */
3333
+ this.authlessInFlight$ = null;
3332
3334
  this.userRoles$ = new rxjs.BehaviorSubject([]);
3333
3335
  this.userProvider$ = new rxjs.BehaviorSubject(undefined);
3334
3336
  this.userSupplier$ = new rxjs.BehaviorSubject(undefined);
@@ -3389,14 +3391,38 @@
3389
3391
  this.userProvider$.next(null);
3390
3392
  this.userSupplier$.next(null);
3391
3393
  };
3394
+ /**
3395
+ * Ensures API calls that need `Authorization: user_id …` have either a logged user id or an authless id
3396
+ * (same rule as MiamInterceptor: Bearer token, else user_id from `_miam/userId` or `_miam/authlessId`).
3397
+ */
3398
+ UserService.prototype.ensureAnonymousUserIdIfMissing = function () {
3399
+ if (localStorage.getItem('_miam/userToken') || localStorage.getItem('_miam/userId')) {
3400
+ return rxjs.of(void 0);
3401
+ }
3402
+ return this.generateAnonymousUserId().pipe(operators.map(function () { return void 0; }));
3403
+ };
3392
3404
  UserService.prototype.generateAnonymousUserId = function () {
3393
3405
  var _this = this;
3406
+ var existing = localStorage.getItem('_miam/authlessId');
3407
+ if (existing) {
3408
+ return rxjs.of(existing);
3409
+ }
3410
+ if (this.authlessInFlight$) {
3411
+ return this.authlessInFlight$;
3412
+ }
3394
3413
  var url = environment$1.miamAPI + "/api/v1/users/authless";
3395
3414
  this.generatingAuthlessId$.next(true);
3396
- return this.http.post(url, {}).pipe(operators.map(function (result) { return result['authless_id']; }), operators.tap(function (anonymousUserId) {
3415
+ this.authlessInFlight$ = this.http.post(url, {}).pipe(operators.map(function (result) { return result.authless_id; }), operators.tap(function (anonymousUserId) {
3397
3416
  localStorage.setItem('_miam/authlessId', anonymousUserId);
3398
3417
  _this.generatingAuthlessId$.next(false);
3399
- }));
3418
+ }), operators.catchError(function (err) {
3419
+ _this.generatingAuthlessId$.next(false);
3420
+ _this.authlessInFlight$ = null;
3421
+ return rxjs.throwError(err);
3422
+ }), operators.finalize(function () {
3423
+ _this.authlessInFlight$ = null;
3424
+ }), operators.shareReplay(1));
3425
+ return this.authlessInFlight$;
3400
3426
  };
3401
3427
  UserService.prototype.setPreference = function (pref, state) {
3402
3428
  var _this = this;
@@ -4628,7 +4654,7 @@
4628
4654
  var MIAM_API_HOST$2 = environment$1.miamAPI + "/api/v1/";
4629
4655
  var RecipesService = /** @class */ (function (_super) {
4630
4656
  __extends(RecipesService, _super);
4631
- function RecipesService(http, providerService, statusService, typeService, suppliersService, posService, ingredientsService, recipeStepsService, sponsorService, packageService, tagsService, recipeLikesService, seoService, preferencesService, storeLocatorService) {
4657
+ function RecipesService(http, providerService, statusService, typeService, suppliersService, posService, ingredientsService, recipeStepsService, sponsorService, packageService, tagsService, recipeLikesService, seoService, preferencesService, storeLocatorService, userService) {
4632
4658
  var _this = _super.call(this) || this;
4633
4659
  _this.http = http;
4634
4660
  _this.providerService = providerService;
@@ -4645,6 +4671,7 @@
4645
4671
  _this.seoService = seoService;
4646
4672
  _this.preferencesService = preferencesService;
4647
4673
  _this.storeLocatorService = storeLocatorService;
4674
+ _this.userService = userService;
4648
4675
  _this.resource = Recipe;
4649
4676
  _this.type = 'recipes';
4650
4677
  _this.displayedRecipe$ = new rxjs.BehaviorSubject(null);
@@ -5011,14 +5038,14 @@
5011
5038
  return;
5012
5039
  }
5013
5040
  var queuedContexts = Array.from(this.pendingContexts.values());
5014
- rxjs.combineLatest([
5015
- this.suppliersService.supplier$,
5016
- this.posService.posWasInitialized().pipe(operators.skipWhile(function (wasInitialized) { return !wasInitialized; }), operators.switchMap(function () { return _this.posService.pos$; }))
5041
+ this.userService.ensureAnonymousUserIdIfMissing().pipe(operators.switchMap(function () { return rxjs.combineLatest([
5042
+ _this.suppliersService.supplier$,
5043
+ _this.posService.posWasInitialized().pipe(operators.skipWhile(function (wasInitialized) { return !wasInitialized; }), operators.switchMap(function () { return _this.posService.pos$; }))
5017
5044
  ]).pipe(operators.skipWhile(function (results) { return !results[0]; }), operators.take(1), operators.switchMap(function (results) {
5018
5045
  var url = _this.buildSuggestionsBatchUrl(results[0], results[1]);
5019
5046
  var body = _this.buildSuggestionsBatchBody(queuedContexts);
5020
5047
  return _this.http.post(url, body);
5021
- }), operators.catchError(function (error) {
5048
+ })); }), operators.catchError(function (error) {
5022
5049
  _this.handleBatchSuggestionsError(error);
5023
5050
  return rxjs.of(null);
5024
5051
  })).subscribe(function (returnedRecipes) {
@@ -5091,7 +5118,7 @@
5091
5118
  };
5092
5119
  return RecipesService;
5093
5120
  }(i2$2.Service));
5094
- RecipesService.ɵfac = function RecipesService_Factory(t) { return new (t || RecipesService)(i0__namespace.ɵɵinject(i1__namespace.HttpClient), i0__namespace.ɵɵinject(RecipeProviderService), i0__namespace.ɵɵinject(RecipeStatusService), i0__namespace.ɵɵinject(RecipeTypeService), i0__namespace.ɵɵinject(SuppliersService), i0__namespace.ɵɵinject(PointOfSalesService), i0__namespace.ɵɵinject(IngredientsService), i0__namespace.ɵɵinject(RecipeStepsService), i0__namespace.ɵɵinject(SponsorService), i0__namespace.ɵɵinject(PackageService), i0__namespace.ɵɵinject(TagsService), i0__namespace.ɵɵinject(RecipeLikesService), i0__namespace.ɵɵinject(SeoService), i0__namespace.ɵɵinject(PreferencesService), i0__namespace.ɵɵinject(StoreLocatorService)); };
5121
+ RecipesService.ɵfac = function RecipesService_Factory(t) { return new (t || RecipesService)(i0__namespace.ɵɵinject(i1__namespace.HttpClient), i0__namespace.ɵɵinject(RecipeProviderService), i0__namespace.ɵɵinject(RecipeStatusService), i0__namespace.ɵɵinject(RecipeTypeService), i0__namespace.ɵɵinject(SuppliersService), i0__namespace.ɵɵinject(PointOfSalesService), i0__namespace.ɵɵinject(IngredientsService), i0__namespace.ɵɵinject(RecipeStepsService), i0__namespace.ɵɵinject(SponsorService), i0__namespace.ɵɵinject(PackageService), i0__namespace.ɵɵinject(TagsService), i0__namespace.ɵɵinject(RecipeLikesService), i0__namespace.ɵɵinject(SeoService), i0__namespace.ɵɵinject(PreferencesService), i0__namespace.ɵɵinject(StoreLocatorService), i0__namespace.ɵɵinject(UserService)); };
5095
5122
  RecipesService.ɵprov = i0__namespace.ɵɵdefineInjectable({ token: RecipesService, factory: RecipesService.ɵfac, providedIn: 'root' });
5096
5123
  (function () {
5097
5124
  (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(RecipesService, [{
@@ -5099,7 +5126,7 @@
5099
5126
  args: [{
5100
5127
  providedIn: 'root'
5101
5128
  }]
5102
- }], function () { return [{ type: i1__namespace.HttpClient }, { type: RecipeProviderService }, { type: RecipeStatusService }, { type: RecipeTypeService }, { type: SuppliersService }, { type: PointOfSalesService }, { type: IngredientsService }, { type: RecipeStepsService }, { type: SponsorService }, { type: PackageService }, { type: TagsService }, { type: RecipeLikesService }, { type: SeoService }, { type: PreferencesService }, { type: StoreLocatorService }]; }, null);
5129
+ }], function () { return [{ type: i1__namespace.HttpClient }, { type: RecipeProviderService }, { type: RecipeStatusService }, { type: RecipeTypeService }, { type: SuppliersService }, { type: PointOfSalesService }, { type: IngredientsService }, { type: RecipeStepsService }, { type: SponsorService }, { type: PackageService }, { type: TagsService }, { type: RecipeLikesService }, { type: SeoService }, { type: PreferencesService }, { type: StoreLocatorService }, { type: UserService }]; }, null);
5103
5130
  })();
5104
5131
 
5105
5132
  var BASKET_SPARSE_FIELDS = {
@@ -5308,27 +5335,40 @@
5308
5335
  BasketsService.prototype.refreshCurrentBasket = function () {
5309
5336
  var _this = this;
5310
5337
  this.currentAndPreviewFetching.next(true);
5311
- return this.posService.waitForPos.pipe(operators.take(1), operators.switchMap(function (pos) {
5338
+ return this.usersService.ensureAnonymousUserIdIfMissing().pipe(operators.switchMap(function () { return _this.posService.waitForPos.pipe(operators.take(1), operators.switchMap(function (pos) {
5312
5339
  console.debug('[Miam] refreshing basket');
5313
5340
  var authlessId = localStorage.getItem('_miam/authlessId');
5314
5341
  var userId = localStorage.getItem('_miam/userId');
5315
5342
  if (_this.currentSubscription) {
5316
5343
  _this.currentSubscription.unsubscribe();
5317
5344
  }
5318
- var basketObservable = (authlessId && userId)
5345
+ var basketLoad$ = (authlessId && userId)
5319
5346
  ? _this.transferAuthlessBasket(pos.id, authlessId)
5320
5347
  : _this.fetchCurrentBasket(pos.id);
5321
5348
  if (authlessId && userId) {
5322
5349
  localStorage.removeItem('_miam/authlessId');
5323
5350
  }
5351
+ var basketObservable = basketLoad$.pipe(
5352
+ // Affiliated requires a basket to exist server-side; run only after current basket fetch/update completes.
5353
+ operators.tap(function () { return _this.checkIfIsAffiliated(); }));
5324
5354
  _this.currentSubscription = basketObservable.subscribe();
5325
- _this.checkIfIsAffiliated();
5326
5355
  return _this._basket$;
5327
- }));
5356
+ })); }));
5328
5357
  };
5329
5358
  BasketsService.prototype.checkIfIsAffiliated = function () {
5330
5359
  var getAffiliatedUrl = environment$1.miamAPI + "/api/v1/baskets/affiliated";
5331
- this.http.get(getAffiliatedUrl).pipe(operators.take(1)).subscribe(function (response) {
5360
+ this.http
5361
+ .get(getAffiliatedUrl)
5362
+ .pipe(operators.retryWhen(function (errors) { return errors.pipe(operators.mergeMap(function (err, attempt) {
5363
+ var body = err === null || err === void 0 ? void 0 : err.error;
5364
+ var msg = typeof (body === null || body === void 0 ? void 0 : body.error) === 'string' ? body.error : '';
5365
+ var transientBasket = /no basket found/i.test(msg);
5366
+ if (transientBasket && attempt < 4) {
5367
+ return rxjs.timer(350 + attempt * 150);
5368
+ }
5369
+ return rxjs.throwError(err);
5370
+ })); }), operators.take(1))
5371
+ .subscribe(function (response) {
5332
5372
  var affiliated = response === null || response === void 0 ? void 0 : response.affiliated;
5333
5373
  if (affiliated) {
5334
5374
  localStorage.setItem('_miam/affiliated', affiliated);
@@ -5338,6 +5378,8 @@
5338
5378
  localStorage.removeItem('_miam/affiliated');
5339
5379
  mealzSharedAnalytics.setAffiliate(null);
5340
5380
  }
5381
+ }, function () {
5382
+ /* keep previous affiliate state on failure */
5341
5383
  });
5342
5384
  };
5343
5385
  BasketsService.prototype.transferAuthlessBasket = function (posId, authlessId) {
@@ -6946,13 +6988,11 @@
6946
6988
  document.head.appendChild(storeLocatorScript);
6947
6989
  };
6948
6990
  ContextService.prototype.generateAuthlessIdIfNecessary = function () {
6949
- var _this = this;
6950
- return this.userService.generatingAuthlessId$.pipe(operators.debounceTime(800), operators.take(1), operators.switchMap(function (isGenerating) {
6951
- if (isGenerating || _this.loggedOnSession || !!localStorage.getItem('_miam/authlessId')) {
6952
- return rxjs.of(null);
6953
- }
6954
- return _this.userService.generateAnonymousUserId();
6955
- }));
6991
+ if (this.loggedOnSession || !!localStorage.getItem('_miam/authlessId')) {
6992
+ return rxjs.of(void 0);
6993
+ }
6994
+ // Emit the authless id string so callers like user.reset can branch on a truthy value after creation.
6995
+ return this.userService.generateAnonymousUserId();
6956
6996
  };
6957
6997
  return ContextService;
6958
6998
  }());
@@ -25998,10 +26038,11 @@
25998
26038
  }
25999
26039
  var NoSupplierOnboardingComponent = /** @class */ (function (_super) {
26000
26040
  __extends(NoSupplierOnboardingComponent, _super);
26001
- function NoSupplierOnboardingComponent(storeLocatoreService, cdr, analyticsService) {
26041
+ function NoSupplierOnboardingComponent(storeLocatoreService, cdr, elRef, analyticsService) {
26002
26042
  var _this = _super.call(this, analyticsService) || this;
26003
26043
  _this.storeLocatoreService = storeLocatoreService;
26004
26044
  _this.cdr = cdr;
26045
+ _this.elRef = elRef;
26005
26046
  _this.analyticsService = analyticsService;
26006
26047
  _this.display = false;
26007
26048
  _this.step = 1;
@@ -26035,6 +26076,13 @@
26035
26076
  this.sendEvent(this.analyticsService.EVENT_ONBOARDING_ACTION);
26036
26077
  this.confirm();
26037
26078
  };
26079
+ NoSupplierOnboardingComponent.prototype.onConfirmButtonClick = function () {
26080
+ this.elRef.nativeElement.dispatchEvent(new CustomEvent('mealz-onboarding-confirm-select-store', {
26081
+ bubbles: true,
26082
+ composed: true
26083
+ }));
26084
+ this.onConfirm();
26085
+ };
26038
26086
  NoSupplierOnboardingComponent.prototype.onClose = function () {
26039
26087
  this.sendEvent(this.analyticsService.EVENT_ONBOARDING_CLOSE);
26040
26088
  this.onConfirm();
@@ -26055,7 +26103,7 @@
26055
26103
  };
26056
26104
  return NoSupplierOnboardingComponent;
26057
26105
  }(EventTracerComponent));
26058
- NoSupplierOnboardingComponent.ɵfac = function NoSupplierOnboardingComponent_Factory(t) { return new (t || NoSupplierOnboardingComponent)(i0__namespace.ɵɵdirectiveInject(StoreLocatorService), i0__namespace.ɵɵdirectiveInject(i0__namespace.ChangeDetectorRef), i0__namespace.ɵɵdirectiveInject(AnalyticsService)); };
26106
+ NoSupplierOnboardingComponent.ɵfac = function NoSupplierOnboardingComponent_Factory(t) { return new (t || NoSupplierOnboardingComponent)(i0__namespace.ɵɵdirectiveInject(StoreLocatorService), i0__namespace.ɵɵdirectiveInject(i0__namespace.ChangeDetectorRef), i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(AnalyticsService)); };
26059
26107
  NoSupplierOnboardingComponent.ɵcmp = i0__namespace.ɵɵdefineComponent({ type: NoSupplierOnboardingComponent, selectors: [["ng-miam-no-supplier-onboarding"]], features: [i0__namespace.ɵɵInheritDefinitionFeature], decls: 25, vars: 27, consts: function () {
26060
26108
  var i18n_0;
26061
26109
  if (typeof ngI18nClosureMode !== "undefined" && ngI18nClosureMode) {
@@ -26157,7 +26205,7 @@
26157
26205
  }, template: function NoSupplierOnboardingComponent_Template(rf, ctx) {
26158
26206
  if (rf & 1) {
26159
26207
  i0__namespace.ɵɵelementStart(0, "ng-miam-modal", 0);
26160
- i0__namespace.ɵɵlistener("confirm", function NoSupplierOnboardingComponent_Template_ng_miam_modal_confirm_0_listener() { return ctx.onConfirm(); })("close", function NoSupplierOnboardingComponent_Template_ng_miam_modal_close_0_listener() { return ctx.onClose(); });
26208
+ i0__namespace.ɵɵlistener("confirm", function NoSupplierOnboardingComponent_Template_ng_miam_modal_confirm_0_listener() { return ctx.onConfirmButtonClick(); })("close", function NoSupplierOnboardingComponent_Template_ng_miam_modal_close_0_listener() { return ctx.onClose(); });
26161
26209
  i0__namespace.ɵɵelementStart(1, "div", 1);
26162
26210
  i0__namespace.ɵɵelementStart(2, "div", 2);
26163
26211
  i0__namespace.ɵɵelementStart(3, "span", 3);
@@ -26242,7 +26290,7 @@
26242
26290
  encapsulation: i0.ViewEncapsulation.None,
26243
26291
  changeDetection: i0.ChangeDetectionStrategy.OnPush
26244
26292
  }]
26245
- }], function () { return [{ type: StoreLocatorService }, { type: i0__namespace.ChangeDetectorRef }, { type: AnalyticsService }]; }, null);
26293
+ }], function () { return [{ type: StoreLocatorService }, { type: i0__namespace.ChangeDetectorRef }, { type: i0__namespace.ElementRef }, { type: AnalyticsService }]; }, null);
26246
26294
  })();
26247
26295
  var templateObject_1$1, templateObject_2$1, templateObject_3$1, templateObject_4$1, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12;
26248
26296