UNPKG

@spartacus/user

Version:

User feature library for Spartacus

185 lines (175 loc) 11 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common/http'), require('@angular/core'), require('@spartacus/core'), require('@spartacus/user/profile/core'), require('rxjs'), require('rxjs/operators')) : typeof define === 'function' && define.amd ? define('@spartacus/user/profile/occ', ['exports', '@angular/common/http', '@angular/core', '@spartacus/core', '@spartacus/user/profile/core', 'rxjs', 'rxjs/operators'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.spartacus = global.spartacus || {}, global.spartacus.user = global.spartacus.user || {}, global.spartacus.user.profile = global.spartacus.user.profile || {}, global.spartacus.user.profile.occ = {}), global.ng.common.http, global.ng.core, global.core, global.spartacus.user.profile.core, global.rxjs, global.rxjs.operators)); }(this, (function (exports, i1, i0, i2, core, rxjs, operators) { 'use strict'; function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n['default'] = e; return Object.freeze(n); } var i1__namespace = /*#__PURE__*/_interopNamespace(i1); var i0__namespace = /*#__PURE__*/_interopNamespace(i0); var i2__namespace = /*#__PURE__*/_interopNamespace(i2); var defaultOccUserProfileConfig = { backend: { occ: { endpoints: { userRegister: 'users', userForgotPassword: 'forgottenpasswordtokens', userResetPassword: 'resetpassword', userUpdateLoginId: 'users/${userId}/login', userUpdatePassword: 'users/${userId}/password', titles: 'titles', }, }, }, }; var OccUserProfileAdapter = /** @class */ (function () { function OccUserProfileAdapter(http, occEndpoints, converter) { this.http = http; this.occEndpoints = occEndpoints; this.converter = converter; } OccUserProfileAdapter.prototype.update = function (userId, user) { var endpoint = this.occEndpoints.isConfigured('userUpdateProfile') ? 'userUpdateProfile' : 'user'; var url = this.occEndpoints.buildUrl(endpoint, { urlParams: { userId: userId } }); user = this.converter.convert(user, core.USER_PROFILE_SERIALIZER); return this.http .patch(url, user) .pipe(operators.catchError(function (error) { return rxjs.throwError(i2.normalizeHttpError(error)); })); }; OccUserProfileAdapter.prototype.register = function (user) { var url = this.occEndpoints.buildUrl('userRegister'); var headers = new i1.HttpHeaders({ 'Content-Type': 'application/json', }); headers = i2.InterceptorUtil.createHeader(i2.USE_CLIENT_TOKEN, true, headers); user = this.converter.convert(user, core.USER_SIGN_UP_SERIALIZER); return this.http.post(url, user, { headers: headers }).pipe(operators.catchError(function (error) { return rxjs.throwError(i2.normalizeHttpError(error)); }), this.converter.pipeable(core.USER_PROFILE_NORMALIZER)); }; OccUserProfileAdapter.prototype.registerGuest = function (guid, password) { var url = this.occEndpoints.buildUrl('userRegister'); var headers = new i1.HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded', }); headers = i2.InterceptorUtil.createHeader(i2.USE_CLIENT_TOKEN, true, headers); var httpParams = new i1.HttpParams() .set('guid', guid) .set('password', password); return this.http.post(url, httpParams, { headers: headers }).pipe(operators.catchError(function (error) { return rxjs.throwError(i2.normalizeHttpError(error)); }), this.converter.pipeable(core.USER_PROFILE_NORMALIZER)); }; OccUserProfileAdapter.prototype.requestForgotPasswordEmail = function (userEmailAddress) { var url = this.occEndpoints.buildUrl('userForgotPassword'); var httpParams = new i1.HttpParams().set('userId', userEmailAddress); var headers = new i1.HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded', }); headers = i2.InterceptorUtil.createHeader(i2.USE_CLIENT_TOKEN, true, headers); return this.http .post(url, httpParams, { headers: headers }) .pipe(operators.catchError(function (error) { return rxjs.throwError(i2.normalizeHttpError(error)); })); }; OccUserProfileAdapter.prototype.resetPassword = function (token, newPassword) { var url = this.occEndpoints.buildUrl('userResetPassword'); var headers = new i1.HttpHeaders({ 'Content-Type': 'application/json', }); headers = i2.InterceptorUtil.createHeader(i2.USE_CLIENT_TOKEN, true, headers); return this.http .post(url, { token: token, newPassword: newPassword }, { headers: headers }) .pipe(operators.catchError(function (error) { return rxjs.throwError(i2.normalizeHttpError(error)); })); }; OccUserProfileAdapter.prototype.updateEmail = function (userId, currentPassword, newUserId) { var url = this.occEndpoints.buildUrl('userUpdateLoginId', { urlParams: { userId: userId }, }); var httpParams = new i1.HttpParams() .set('password', currentPassword) .set('newLogin', newUserId); var headers = new i1.HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded', }); return this.http .put(url, httpParams, { headers: headers }) .pipe(operators.catchError(function (error) { return rxjs.throwError(i2.normalizeHttpError(error)); })); }; OccUserProfileAdapter.prototype.updatePassword = function (userId, oldPassword, newPassword) { var url = this.occEndpoints.buildUrl('userUpdatePassword', { urlParams: { userId: userId }, }); var httpParams = new i1.HttpParams() .set('old', oldPassword) .set('new', newPassword); var headers = new i1.HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded', }); return this.http .put(url, httpParams, { headers: headers }) .pipe(operators.catchError(function (error) { return rxjs.throwError(i2.normalizeHttpError(error)); })); }; OccUserProfileAdapter.prototype.close = function (userId) { var endpoint = this.occEndpoints.isConfigured('userCloseAccount') ? 'userCloseAccount' : 'user'; var url = this.occEndpoints.buildUrl(endpoint, { urlParams: { userId: userId } }); return this.http .delete(url) .pipe(operators.catchError(function (error) { return rxjs.throwError(i2.normalizeHttpError(error)); })); }; OccUserProfileAdapter.prototype.loadTitles = function () { var url = this.occEndpoints.buildUrl('titles'); return this.http.get(url).pipe(operators.catchError(function (error) { return rxjs.throwError(i2.normalizeHttpError(error)); }), operators.map(function (titleList) { var _a; return (_a = titleList.titles) !== null && _a !== void 0 ? _a : []; }), this.converter.pipeableMany(core.TITLE_NORMALIZER)); }; return OccUserProfileAdapter; }()); OccUserProfileAdapter.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccUserProfileAdapter, deps: [{ token: i1__namespace.HttpClient }, { token: i2__namespace.OccEndpointsService }, { token: i2__namespace.ConverterService }], target: i0__namespace.ɵɵFactoryTarget.Injectable }); OccUserProfileAdapter.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccUserProfileAdapter }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccUserProfileAdapter, decorators: [{ type: i0.Injectable }], ctorParameters: function () { return [{ type: i1__namespace.HttpClient }, { type: i2__namespace.OccEndpointsService }, { type: i2__namespace.ConverterService }]; } }); var UserProfileOccModule = /** @class */ (function () { function UserProfileOccModule() { } return UserProfileOccModule; }()); UserProfileOccModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: UserProfileOccModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule }); UserProfileOccModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: UserProfileOccModule }); UserProfileOccModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: UserProfileOccModule, providers: [ i2.provideDefaultConfig(defaultOccUserProfileConfig), { provide: core.UserProfileAdapter, useClass: OccUserProfileAdapter }, ] }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: UserProfileOccModule, decorators: [{ type: i0.NgModule, args: [{ providers: [ i2.provideDefaultConfig(defaultOccUserProfileConfig), { provide: core.UserProfileAdapter, useClass: OccUserProfileAdapter }, ], }] }] }); /** * Generated bundle index. Do not edit. */ exports.OccUserProfileAdapter = OccUserProfileAdapter; exports.UserProfileOccModule = UserProfileOccModule; exports.defaultOccUserProfileConfig = defaultOccUserProfileConfig; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=spartacus-user-profile-occ.umd.js.map