ng-miam 8.8.15 → 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.
- package/bundles/ng-miam.umd.js +61 -21
- package/bundles/ng-miam.umd.js.map +1 -1
- package/bundles/ng-miam.umd.min.js +1 -1
- package/bundles/ng-miam.umd.min.js.map +1 -1
- package/esm2015/lib/_services/baskets.service.js +23 -8
- package/esm2015/lib/_services/context.service.js +7 -8
- package/esm2015/lib/_services/recipes.service.js +9 -6
- package/esm2015/lib/_services/user.service.js +31 -5
- package/fesm2015/ng-miam.js +61 -20
- package/fesm2015/ng-miam.js.map +1 -1
- package/lib/_services/baskets.service.d.ts.map +1 -1
- package/lib/_services/context.service.d.ts.map +1 -1
- package/lib/_services/recipes.service.d.ts +3 -1
- package/lib/_services/recipes.service.d.ts.map +1 -1
- package/lib/_services/user.service.d.ts +7 -0
- package/lib/_services/user.service.d.ts.map +1 -1
- package/package.json +1 -1
package/bundles/ng-miam.umd.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
5016
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
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
|
}());
|