ng-miam 8.8.15 → 8.8.17

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;
@@ -3856,9 +3882,71 @@
3856
3882
  return RecipeLike;
3857
3883
  }(i2$2.Resource));
3858
3884
 
3885
+ var VERSION = '8.8.17';
3886
+
3887
+ var _eventEmitter = new i0.EventEmitter();
3888
+ /** Maps SDK 8.8 legacy names to canonical mealz-shared-analytics@4.13 event names. */
3889
+ var LEGACY_EVENT_NAME_MAP = {
3890
+ 'entry.add': 'entry.added',
3891
+ 'entry.delete': 'entry.deleted',
3892
+ 'entry.replace': 'entry.replaced',
3893
+ 'pos.selected': 'locator.select',
3894
+ 'search.store': 'locator.search',
3895
+ 'planner.confirmed': 'planner.confirm',
3896
+ 'recipe.print': 'recipe.show'
3897
+ };
3898
+ /** Maps SDK 8.8 legacy prop keys to canonical shared-analytics keys. */
3899
+ var LEGACY_PROP_KEY_MAP = {
3900
+ recipes_count: 'recipe_count',
3901
+ new_ext_item_id: 'new_item_ext_id',
3902
+ old_ext_item_id: 'old_item_ext_id'
3903
+ };
3904
+ /** Legacy marker event; reset is already tracked via subsequent recipe.remove events. */
3905
+ var LEGACY_EVENTS_SKIPPED = new Set(['recipe.reset']);
3906
+ function mapLegacyEventName(name) {
3907
+ var _a;
3908
+ return (_a = LEGACY_EVENT_NAME_MAP[name]) !== null && _a !== void 0 ? _a : name;
3909
+ }
3910
+ function shouldSkipLegacyEvent(name) {
3911
+ return LEGACY_EVENTS_SKIPPED.has(name);
3912
+ }
3913
+ function normalizeLegacyProps(props) {
3914
+ if (!props) {
3915
+ return {};
3916
+ }
3917
+ var normalized = {};
3918
+ Object.keys(props).forEach(function (key) {
3919
+ var _a;
3920
+ var value = props[key];
3921
+ if (value === undefined || value === null) {
3922
+ return;
3923
+ }
3924
+ var normalizedKey = (_a = LEGACY_PROP_KEY_MAP[key]) !== null && _a !== void 0 ? _a : key;
3925
+ normalized[normalizedKey] = String(value);
3926
+ });
3927
+ return normalized;
3928
+ }
3929
+ var getAnalyticsEnvironment = function () { return environment$1.env === 'prod' ? 'prod' : 'uat'; };
3930
+ // Exported for unit tests
3931
+ // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
3932
+ function url(path) {
3933
+ if (path) {
3934
+ return "" + location.origin + path;
3935
+ }
3936
+ return location.href;
3937
+ }
3938
+ // Exported for unit tests
3939
+ // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
3940
+ function _onEmit(event) {
3941
+ _eventEmitter.emit(JSON.stringify({
3942
+ name: event.name,
3943
+ path: event.url,
3944
+ props: event.props
3945
+ }));
3946
+ }
3859
3947
  var AnalyticsService = /** @class */ (function () {
3860
3948
  function AnalyticsService() {
3861
- this.EVENT_PAGEVIEW = 'pageview'; // GA4 is page_view -> use this one on ga to autotrack some fields
3949
+ this.EVENT_PAGEVIEW = 'pageview';
3862
3950
  this.EVENT_SEARCH = 'search';
3863
3951
  this.EVENT_RECIPE_SHOW = 'recipe.show';
3864
3952
  this.EVENT_RECIPE_DISPLAY = 'recipe.display';
@@ -3887,69 +3975,54 @@
3887
3975
  this.EVENT_ONBOARDING_CLOSE = 'onboarding.close';
3888
3976
  this.EVENT_ONBOARDING_ACTION = 'onboarding.action';
3889
3977
  this.ready$ = new rxjs.BehaviorSubject(false);
3890
- this.eventEmitter = new i0.EventEmitter();
3978
+ this.eventEmitter = _eventEmitter;
3979
+ this.alreadyInitialized = false;
3891
3980
  }
3892
3981
  // DEPRECATED: optimizeKey parameter to be removed with next major version
3893
3982
  AnalyticsService.prototype.init = function (domain, _optimizeKey) {
3894
- this._injectPlausible(domain);
3895
- };
3896
- /**
3897
- * Set the identifier of the ABTest experience if one is running
3898
- * It will then be added as props to all events sent
3899
- * @param key A unique identifier for the ABTest experience
3900
- */
3901
- AnalyticsService.prototype.setAbTestKey = function (key) {
3902
- this.abTestkey = key;
3903
- };
3904
- AnalyticsService.prototype.event = function (name, path, props) {
3905
3983
  var _a;
3906
- if (this.abTestkey) {
3907
- props.abTestKey = this.abTestkey;
3984
+ if (this.alreadyInitialized || !domain) {
3985
+ return;
3986
+ }
3987
+ mealzSharedAnalytics.initSharedAnalytics(domain, VERSION, _onEmit, getAnalyticsEnvironment());
3988
+ var storedAbTestKey = localStorage.getItem('_miam/ab');
3989
+ if ((storedAbTestKey === null || storedAbTestKey === void 0 ? void 0 : storedAbTestKey.length) > 0) {
3990
+ mealzSharedAnalytics.setABTestKey(storedAbTestKey);
3991
+ }
3992
+ else if (this.pendingAbTestKey !== undefined) {
3993
+ mealzSharedAnalytics.setABTestKey(this.pendingAbTestKey);
3908
3994
  }
3909
3995
  if (((_a = localStorage.getItem('_miam/affiliate')) === null || _a === void 0 ? void 0 : _a.length) > 0) {
3910
- props.affiliate = localStorage.getItem('_miam/affiliate');
3911
- }
3912
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
3913
- plausible(name, { u: this.url(path), props: props });
3914
- this.eventEmitter.emit(JSON.stringify({
3915
- name: name,
3916
- path: this.url(path),
3917
- props: props
3918
- }));
3996
+ mealzSharedAnalytics.setAffiliate(localStorage.getItem('_miam/affiliate'));
3997
+ }
3998
+ this.alreadyInitialized = true;
3999
+ this.ready$.next(true);
4000
+ };
4001
+ AnalyticsService.prototype.setAbTestKey = function (key) {
4002
+ this.pendingAbTestKey = key;
4003
+ if (this.alreadyInitialized) {
4004
+ mealzSharedAnalytics.setABTestKey(key);
4005
+ }
3919
4006
  };
3920
4007
  AnalyticsService.prototype.sendEventWhenReady = function (name, path, props) {
3921
4008
  var _this = this;
3922
4009
  if (this.ready$.getValue()) {
3923
- return this.event(name, path, props);
4010
+ this.sendAnalyticsEvent(name, path, props);
4011
+ return;
3924
4012
  }
3925
- this.ready$.pipe(operators.filter(function (ready) { return ready; }), operators.take(1)).subscribe(function () { return _this.event(name, path, props); });
4013
+ this.ready$.pipe(operators.filter(function (ready) { return ready; }), operators.take(1)).subscribe(function () { return _this.sendAnalyticsEvent(name, path, props); });
3926
4014
  };
3927
- AnalyticsService.prototype.url = function (path) {
3928
- if (path) {
3929
- return "" + location.origin + path;
4015
+ AnalyticsService.prototype.sendAnalyticsEvent = function (name, path, props) {
4016
+ if (shouldSkipLegacyEvent(name)) {
4017
+ return;
3930
4018
  }
3931
- return location.href;
3932
- };
3933
- AnalyticsService.prototype._injectPlausible = function (domain) {
3934
- var _this = this;
3935
- var script = document.createElement('script');
3936
- if (domain === 'miam.test') {
3937
- // In development, charge the "local" extension to make sure events can be routed from localhost to miam.test domain
3938
- script.src = 'https://plausible.io/js/plausible.local.manual.js';
4019
+ var eventName = mapLegacyEventName(name);
4020
+ try {
4021
+ mealzSharedAnalytics.sendEvent(eventName, url(path), '', normalizeLegacyProps(props));
3939
4022
  }
3940
- else {
3941
- // Use manual script to limit the number of pageviews
3942
- // Don't trigger pageviews automatically. Also allows you to specify custom locations to redact URLs with identifiers.
3943
- // You can also use it to track custom query parameters
3944
- script.src = 'https://plausible.io/js/plausible.manual.js';
4023
+ catch (error) {
4024
+ console.error('[Miam] Error sending analytics event', error);
3945
4025
  }
3946
- script.defer = true;
3947
- script.setAttribute('data-domain', domain);
3948
- script.onload = function () {
3949
- console.debug("[Miam] Analytics ready for domain: " + JSON.stringify(domain));
3950
- _this.ready$.next(true);
3951
- };
3952
- document.head.appendChild(script);
3953
4026
  };
3954
4027
  /** ************************************************* SEND EVENT FOR BASKET ACTIONS ************************************************* **/
3955
4028
  AnalyticsService.prototype.sendRemoveRecipesEvents = function (actions) {
@@ -4024,7 +4097,7 @@
4024
4097
  item_id: action.params.basketEntry.selectedItem.id,
4025
4098
  ext_item_id: action.params.basketEntry.selectedItem.attributes['ext-id'],
4026
4099
  item_ean: action.params.basketEntry.selectedItem.ean,
4027
- diff: action.params.newQuantity - action.params.basketEntry.quantity
4100
+ product_quantity: action.params.newQuantity
4028
4101
  });
4029
4102
  });
4030
4103
  };
@@ -4032,6 +4105,7 @@
4032
4105
  this.sendEventWhenReady(this.EVENT_ENTRY_REPLACE, action.params.eventTrace.originPath, {
4033
4106
  recipe_id: action.params.recipeId,
4034
4107
  entry_name: action.params.basketEntry.name,
4108
+ product_quantity: action.params.basketEntry.quantity,
4035
4109
  new_item_id: action.params.basketEntry.selectedItem.id,
4036
4110
  new_ext_item_id: action.params.basketEntry.selectedItem.attributes['ext-id'],
4037
4111
  new_item_ean: action.params.basketEntry.selectedItem.ean,
@@ -4628,7 +4702,7 @@
4628
4702
  var MIAM_API_HOST$2 = environment$1.miamAPI + "/api/v1/";
4629
4703
  var RecipesService = /** @class */ (function (_super) {
4630
4704
  __extends(RecipesService, _super);
4631
- function RecipesService(http, providerService, statusService, typeService, suppliersService, posService, ingredientsService, recipeStepsService, sponsorService, packageService, tagsService, recipeLikesService, seoService, preferencesService, storeLocatorService) {
4705
+ function RecipesService(http, providerService, statusService, typeService, suppliersService, posService, ingredientsService, recipeStepsService, sponsorService, packageService, tagsService, recipeLikesService, seoService, preferencesService, storeLocatorService, userService) {
4632
4706
  var _this = _super.call(this) || this;
4633
4707
  _this.http = http;
4634
4708
  _this.providerService = providerService;
@@ -4645,6 +4719,7 @@
4645
4719
  _this.seoService = seoService;
4646
4720
  _this.preferencesService = preferencesService;
4647
4721
  _this.storeLocatorService = storeLocatorService;
4722
+ _this.userService = userService;
4648
4723
  _this.resource = Recipe;
4649
4724
  _this.type = 'recipes';
4650
4725
  _this.displayedRecipe$ = new rxjs.BehaviorSubject(null);
@@ -5011,14 +5086,14 @@
5011
5086
  return;
5012
5087
  }
5013
5088
  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$; }))
5089
+ this.userService.ensureAnonymousUserIdIfMissing().pipe(operators.switchMap(function () { return rxjs.combineLatest([
5090
+ _this.suppliersService.supplier$,
5091
+ _this.posService.posWasInitialized().pipe(operators.skipWhile(function (wasInitialized) { return !wasInitialized; }), operators.switchMap(function () { return _this.posService.pos$; }))
5017
5092
  ]).pipe(operators.skipWhile(function (results) { return !results[0]; }), operators.take(1), operators.switchMap(function (results) {
5018
5093
  var url = _this.buildSuggestionsBatchUrl(results[0], results[1]);
5019
5094
  var body = _this.buildSuggestionsBatchBody(queuedContexts);
5020
5095
  return _this.http.post(url, body);
5021
- }), operators.catchError(function (error) {
5096
+ })); }), operators.catchError(function (error) {
5022
5097
  _this.handleBatchSuggestionsError(error);
5023
5098
  return rxjs.of(null);
5024
5099
  })).subscribe(function (returnedRecipes) {
@@ -5091,7 +5166,7 @@
5091
5166
  };
5092
5167
  return RecipesService;
5093
5168
  }(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)); };
5169
+ 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
5170
  RecipesService.ɵprov = i0__namespace.ɵɵdefineInjectable({ token: RecipesService, factory: RecipesService.ɵfac, providedIn: 'root' });
5096
5171
  (function () {
5097
5172
  (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(RecipesService, [{
@@ -5099,7 +5174,7 @@
5099
5174
  args: [{
5100
5175
  providedIn: 'root'
5101
5176
  }]
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);
5177
+ }], 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
5178
  })();
5104
5179
 
5105
5180
  var BASKET_SPARSE_FIELDS = {
@@ -5127,6 +5202,7 @@
5127
5202
  _this.basketPreviewIsCalculating = false;
5128
5203
  _this.basketInitCalled = false;
5129
5204
  _this.confirming = new rxjs.BehaviorSubject(false);
5205
+ _this.authlessTransferInProgress = false;
5130
5206
  _this.basketActionsQueue = new rxjs.BehaviorSubject([]);
5131
5207
  _this._entries$ = new rxjs.BehaviorSubject([]);
5132
5208
  _this.actionsBeingProcessed = new rxjs.BehaviorSubject([]);
@@ -5305,30 +5381,51 @@
5305
5381
  this.loadPreview().subscribe();
5306
5382
  }
5307
5383
  };
5384
+ /** Marks basket as initialized and loads preview only (no loadBasket) — used before authless→logged-in transfer. */
5385
+ BasketsService.prototype.initBasketPreviewOnly = function () {
5386
+ if (!this.basketInitCalled) {
5387
+ this.basketInitCalled = true;
5388
+ this.loadPreview().subscribe();
5389
+ }
5390
+ };
5308
5391
  BasketsService.prototype.refreshCurrentBasket = function () {
5309
5392
  var _this = this;
5310
- this.currentAndPreviewFetching.next(true);
5311
- return this.posService.waitForPos.pipe(operators.take(1), operators.switchMap(function (pos) {
5393
+ return this.usersService.ensureAnonymousUserIdIfMissing().pipe(operators.switchMap(function () { return _this.posService.waitForPos.pipe(operators.take(1), operators.switchMap(function (pos) {
5312
5394
  console.debug('[Miam] refreshing basket');
5313
5395
  var authlessId = localStorage.getItem('_miam/authlessId');
5314
5396
  var userId = localStorage.getItem('_miam/userId');
5397
+ var willTransfer = !!(authlessId && userId);
5398
+ if (_this.authlessTransferInProgress) {
5399
+ return _this._basket$;
5400
+ }
5401
+ _this.currentAndPreviewFetching.next(true);
5315
5402
  if (_this.currentSubscription) {
5316
5403
  _this.currentSubscription.unsubscribe();
5317
5404
  }
5318
- var basketObservable = (authlessId && userId)
5405
+ var basketLoad$ = willTransfer
5319
5406
  ? _this.transferAuthlessBasket(pos.id, authlessId)
5320
5407
  : _this.fetchCurrentBasket(pos.id);
5321
- if (authlessId && userId) {
5322
- localStorage.removeItem('_miam/authlessId');
5323
- }
5408
+ var basketObservable = basketLoad$.pipe(
5409
+ // Affiliated requires a basket to exist server-side; run only after current basket fetch/update completes.
5410
+ operators.tap(function () { return _this.checkIfIsAffiliated(); }));
5324
5411
  _this.currentSubscription = basketObservable.subscribe();
5325
- _this.checkIfIsAffiliated();
5326
5412
  return _this._basket$;
5327
- }));
5413
+ })); }));
5328
5414
  };
5329
5415
  BasketsService.prototype.checkIfIsAffiliated = function () {
5330
5416
  var getAffiliatedUrl = environment$1.miamAPI + "/api/v1/baskets/affiliated";
5331
- this.http.get(getAffiliatedUrl).pipe(operators.take(1)).subscribe(function (response) {
5417
+ this.http
5418
+ .get(getAffiliatedUrl)
5419
+ .pipe(operators.retryWhen(function (errors) { return errors.pipe(operators.mergeMap(function (err, attempt) {
5420
+ var body = err === null || err === void 0 ? void 0 : err.error;
5421
+ var msg = typeof (body === null || body === void 0 ? void 0 : body.error) === 'string' ? body.error : '';
5422
+ var transientBasket = /no basket found/i.test(msg);
5423
+ if (transientBasket && attempt < 4) {
5424
+ return rxjs.timer(350 + attempt * 150);
5425
+ }
5426
+ return rxjs.throwError(err);
5427
+ })); }), operators.take(1))
5428
+ .subscribe(function (response) {
5332
5429
  var affiliated = response === null || response === void 0 ? void 0 : response.affiliated;
5333
5430
  if (affiliated) {
5334
5431
  localStorage.setItem('_miam/affiliated', affiliated);
@@ -5338,18 +5435,25 @@
5338
5435
  localStorage.removeItem('_miam/affiliated');
5339
5436
  mealzSharedAnalytics.setAffiliate(null);
5340
5437
  }
5438
+ }, function () {
5439
+ /* keep previous affiliate state on failure */
5341
5440
  });
5342
5441
  };
5343
5442
  BasketsService.prototype.transferAuthlessBasket = function (posId, authlessId) {
5344
5443
  var _this = this;
5345
5444
  var transferAuthlessBasketUrl = environment$1.miamAPI + "/api/v1/baskets/transfer_authless?point_of_sale_id=" + posId + "&authless_user_id=" + authlessId;
5346
- return this.http.patch(transferAuthlessBasketUrl, {}).pipe(operators.switchMap(function (response) {
5445
+ this.authlessTransferInProgress = true;
5446
+ return this.http.patch(transferAuthlessBasketUrl, {}).pipe(operators.tap(function () {
5447
+ localStorage.removeItem('_miam/authlessId');
5448
+ }), operators.switchMap(function (response) {
5347
5449
  var confirmedBasket = _this.new();
5348
5450
  confirmedBasket.fill(response);
5349
5451
  return _this.updateLocalBasket(confirmedBasket);
5350
5452
  }), operators.catchError(function () {
5351
5453
  // If authless transfer returned an error, there might be something wrong with the basketId in localStorage, thus we fetchCurrent
5352
5454
  return _this.fetchCurrentBasket(posId);
5455
+ }), operators.finalize(function () {
5456
+ _this.authlessTransferInProgress = false;
5353
5457
  }));
5354
5458
  };
5355
5459
  BasketsService.prototype.fetchCurrentBasket = function (posId) {
@@ -6928,12 +7032,17 @@
6928
7032
  if (tokenOrId) {
6929
7033
  this.userService.toggleIsLogged(true);
6930
7034
  }
7035
+ var pendingAuthlessTransfer = !!localStorage.getItem('_miam/authlessId');
6931
7036
  // if initBasket is set to false, the basket & list will not be initialised until the first time they are needed
6932
- if (initBasket) {
7037
+ if (initBasket && !pendingAuthlessTransfer) {
6933
7038
  this.basketsService.initBasket();
6934
7039
  }
7040
+ else if (initBasket && pendingAuthlessTransfer) {
7041
+ // reloadBasket below runs transfer_authless — skip loadBasket to avoid a concurrent refreshCurrentBasket
7042
+ this.basketsService.initBasketPreviewOnly();
7043
+ }
6935
7044
  return this.userService.generatingAuthlessId$.pipe(operators.skipWhile(function (generating) { return generating; }), operators.take(1), operators.switchMap(function () {
6936
- if (!!localStorage.getItem('_miam/authlessId')) {
7045
+ if (pendingAuthlessTransfer) {
6937
7046
  return _this.basketsService.reloadBasket();
6938
7047
  }
6939
7048
  return rxjs.of(null);
@@ -6946,13 +7055,11 @@
6946
7055
  document.head.appendChild(storeLocatorScript);
6947
7056
  };
6948
7057
  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
- }));
7058
+ if (this.loggedOnSession || !!localStorage.getItem('_miam/authlessId')) {
7059
+ return rxjs.of(void 0);
7060
+ }
7061
+ // Emit the authless id string so callers like user.reset can branch on a truthy value after creation.
7062
+ return this.userService.generateAnonymousUserId();
6956
7063
  };
6957
7064
  return ContextService;
6958
7065
  }());
@@ -8717,7 +8824,7 @@
8717
8824
  MiamInterceptor.prototype.setMiamHeaders = function (request) {
8718
8825
  var headersToAdd = {
8719
8826
  'miam-origin': this.context.origin.value,
8720
- 'miam-front-version': '8.8.10',
8827
+ 'miam-front-version': '8.8.17',
8721
8828
  'miam-front-type': 'web',
8722
8829
  'miam-api-version': '4.7.0'
8723
8830
  };
@@ -26712,6 +26819,11 @@
26712
26819
  exports.WEB_COMPONENTS_NAMES = WEB_COMPONENTS_NAMES;
26713
26820
  exports.WarningStoreLocatorComponent = WarningStoreLocatorComponent;
26714
26821
  exports.WebComponentsModule = WebComponentsModule;
26822
+ exports._onEmit = _onEmit;
26823
+ exports.mapLegacyEventName = mapLegacyEventName;
26824
+ exports.normalizeLegacyProps = normalizeLegacyProps;
26825
+ exports.shouldSkipLegacyEvent = shouldSkipLegacyEvent;
26826
+ exports.url = url;
26715
26827
 
26716
26828
  Object.defineProperty(exports, '__esModule', { value: true });
26717
26829