UNPKG

@spartacus/order

Version:

Order feature library for Spartacus

310 lines (297 loc) 17.6 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@spartacus/core'), require('@angular/common/http'), require('@spartacus/order/core'), require('rxjs'), require('rxjs/operators'), require('@angular/common')) : typeof define === 'function' && define.amd ? define('@spartacus/order/occ', ['exports', '@angular/core', '@spartacus/core', '@angular/common/http', '@spartacus/order/core', 'rxjs', 'rxjs/operators', '@angular/common'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.spartacus = global.spartacus || {}, global.spartacus.order = global.spartacus.order || {}, global.spartacus.order.occ = {}), global.ng.core, global.core, global.ng.common.http, global.spartacus.order.core, global.rxjs, global.rxjs.operators, global.ng.common)); }(this, (function (exports, i0, i2, i1, core, rxjs, operators, common) { '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 i0__namespace = /*#__PURE__*/_interopNamespace(i0); var i2__namespace = /*#__PURE__*/_interopNamespace(i2); var i1__namespace = /*#__PURE__*/_interopNamespace(i1); var OccReturnRequestNormalizer = /** @class */ (function () { function OccReturnRequestNormalizer(converter) { this.converter = converter; } OccReturnRequestNormalizer.prototype.convert = function (source, target) { var _this = this; if (target === undefined) { target = Object.assign({}, source); } if (source.returnEntries) { target.returnEntries = source.returnEntries.map(function (entry) { return (Object.assign(Object.assign({}, entry), { orderEntry: _this.convertOrderEntry(entry.orderEntry) })); }); } return target; }; OccReturnRequestNormalizer.prototype.convertOrderEntry = function (source) { return Object.assign(Object.assign({}, source), { product: this.converter.convert(source === null || source === void 0 ? void 0 : source.product, i2.PRODUCT_NORMALIZER) }); }; return OccReturnRequestNormalizer; }()); OccReturnRequestNormalizer.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccReturnRequestNormalizer, deps: [{ token: i2__namespace.ConverterService }], target: i0__namespace.ɵɵFactoryTarget.Injectable }); OccReturnRequestNormalizer.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccReturnRequestNormalizer, providedIn: 'root' }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccReturnRequestNormalizer, decorators: [{ type: i0.Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: function () { return [{ type: i2__namespace.ConverterService }]; } }); var OccOrderAdapter = /** @class */ (function () { function OccOrderAdapter(http, occEndpoints, converter) { this.http = http; this.occEndpoints = occEndpoints; this.converter = converter; } OccOrderAdapter.prototype.load = function (userId, orderCode) { var url = this.occEndpoints.buildUrl('orderDetail', { urlParams: { userId: userId, orderId: orderCode }, }); var headers = new i1.HttpHeaders(); if (userId === i2.OCC_USER_ID_ANONYMOUS) { headers = i2.InterceptorUtil.createHeader(i2.USE_CLIENT_TOKEN, true, headers); } return this.http .get(url, { headers: headers }) .pipe(this.converter.pipeable(i2.ORDER_NORMALIZER)); }; OccOrderAdapter.prototype.loadHistory = function (userId, pageSize, currentPage, sort) { var params = {}; if (pageSize) { params['pageSize'] = pageSize.toString(); } if (currentPage) { params['currentPage'] = currentPage.toString(); } if (sort) { params['sort'] = sort.toString(); } var url = this.occEndpoints.buildUrl('orderHistory', { urlParams: { userId: userId }, queryParams: params, }); return this.http .get(url) .pipe(this.converter.pipeable(core.ORDER_HISTORY_NORMALIZER)); }; OccOrderAdapter.prototype.getConsignmentTracking = function (orderCode, consignmentCode, userId) { if (userId === void 0) { userId = i2.OCC_USER_ID_CURRENT; } var url = this.occEndpoints.buildUrl('consignmentTracking', { urlParams: { userId: userId, orderCode: orderCode, consignmentCode: consignmentCode }, }); return this.http .get(url) .pipe(this.converter.pipeable(core.CONSIGNMENT_TRACKING_NORMALIZER)); }; OccOrderAdapter.prototype.cancel = function (userId, orderCode, cancelRequestInput) { var url = this.occEndpoints.buildUrl('cancelOrder', { urlParams: { userId: userId, orderId: orderCode }, }); var headers = new i1.HttpHeaders({ 'Content-Type': 'application/json', }); return this.http .post(url, cancelRequestInput, { headers: headers }) .pipe(operators.catchError(function (error) { return rxjs.throwError(error); })); }; OccOrderAdapter.prototype.createReturnRequest = function (userId, returnRequestInput) { var url = this.occEndpoints.buildUrl('returnOrder', { urlParams: { userId: userId }, }); var headers = new i1.HttpHeaders({ 'Content-Type': 'application/json', }); returnRequestInput = this.converter.convert(returnRequestInput, core.ORDER_RETURN_REQUEST_INPUT_SERIALIZER); return this.http.post(url, returnRequestInput, { headers: headers }).pipe(operators.catchError(function (error) { return rxjs.throwError(error); }), this.converter.pipeable(core.ORDER_RETURN_REQUEST_NORMALIZER)); }; OccOrderAdapter.prototype.loadReturnRequestList = function (userId, pageSize, currentPage, sort) { var params = {}; if (pageSize) { params['pageSize'] = pageSize.toString(); } if (currentPage) { params['currentPage'] = currentPage.toString(); } if (sort) { params['sort'] = sort.toString(); } var url = this.occEndpoints.buildUrl('orderReturns', { urlParams: { userId: userId }, queryParams: params, }); return this.http .get(url) .pipe(this.converter.pipeable(core.ORDER_RETURNS_NORMALIZER)); }; OccOrderAdapter.prototype.loadReturnRequestDetail = function (userId, returnRequestCode) { var url = this.occEndpoints.buildUrl('orderReturnDetail', { urlParams: { userId: userId, returnRequestCode: returnRequestCode }, }); return this.http .get(url) .pipe(this.converter.pipeable(core.ORDER_RETURN_REQUEST_NORMALIZER)); }; OccOrderAdapter.prototype.cancelReturnRequest = function (userId, returnRequestCode, returnRequestModification) { var url = this.occEndpoints.buildUrl('cancelReturn', { urlParams: { userId: userId, returnRequestCode: returnRequestCode }, }); var headers = new i1.HttpHeaders({ 'Content-Type': 'application/json', }); return this.http .patch(url, returnRequestModification, { headers: headers }) .pipe(operators.catchError(function (error) { return rxjs.throwError(error); })); }; return OccOrderAdapter; }()); OccOrderAdapter.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccOrderAdapter, deps: [{ token: i1__namespace.HttpClient }, { token: i2__namespace.OccEndpointsService }, { token: i2__namespace.ConverterService }], target: i0__namespace.ɵɵFactoryTarget.Injectable }); OccOrderAdapter.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccOrderAdapter }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccOrderAdapter, decorators: [{ type: i0.Injectable }], ctorParameters: function () { return [{ type: i1__namespace.HttpClient }, { type: i2__namespace.OccEndpointsService }, { type: i2__namespace.ConverterService }]; } }); var OccReplenishmentOrderAdapter = /** @class */ (function () { function OccReplenishmentOrderAdapter(http, occEndpoints, converter) { this.http = http; this.occEndpoints = occEndpoints; this.converter = converter; } OccReplenishmentOrderAdapter.prototype.load = function (userId, replenishmentOrderCode) { return this.http .get(this.occEndpoints.buildUrl('replenishmentOrderDetails', { urlParams: { userId: userId, replenishmentOrderCode: replenishmentOrderCode }, })) .pipe(this.converter.pipeable(i2.REPLENISHMENT_ORDER_NORMALIZER)); }; OccReplenishmentOrderAdapter.prototype.loadReplenishmentDetailsHistory = function (userId, replenishmentOrderCode, pageSize, currentPage, sort) { var params = {}; if (pageSize) { params['pageSize'] = pageSize.toString(); } if (currentPage) { params['currentPage'] = currentPage.toString(); } if (sort) { params['sort'] = sort.toString(); } return this.http .get(this.occEndpoints.buildUrl('replenishmentOrderDetailsHistory', { urlParams: { userId: userId, replenishmentOrderCode: replenishmentOrderCode }, queryParams: params, })) .pipe(this.converter.pipeable(core.ORDER_HISTORY_NORMALIZER)); }; OccReplenishmentOrderAdapter.prototype.cancelReplenishmentOrder = function (userId, replenishmentOrderCode) { var headers = new i1.HttpHeaders().set('Content-Type', 'application/json'); return this.http .patch(this.occEndpoints.buildUrl('cancelReplenishmentOrder', { urlParams: { userId: userId, replenishmentOrderCode: replenishmentOrderCode }, }), {}, { headers: headers }) .pipe(this.converter.pipeable(i2.REPLENISHMENT_ORDER_NORMALIZER)); }; OccReplenishmentOrderAdapter.prototype.loadHistory = function (userId, pageSize, currentPage, sort) { var params = {}; if (pageSize) { params['pageSize'] = pageSize.toString(); } if (currentPage) { params['currentPage'] = currentPage.toString(); } if (sort) { params['sort'] = sort.toString(); } var url = this.occEndpoints.buildUrl('replenishmentOrderHistory', { urlParams: { userId: userId }, queryParams: params, }); return this.http .get(url) .pipe(this.converter.pipeable(core.REPLENISHMENT_ORDER_HISTORY_NORMALIZER)); }; return OccReplenishmentOrderAdapter; }()); OccReplenishmentOrderAdapter.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccReplenishmentOrderAdapter, deps: [{ token: i1__namespace.HttpClient }, { token: i2__namespace.OccEndpointsService }, { token: i2__namespace.ConverterService }], target: i0__namespace.ɵɵFactoryTarget.Injectable }); OccReplenishmentOrderAdapter.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccReplenishmentOrderAdapter }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OccReplenishmentOrderAdapter, decorators: [{ type: i0.Injectable }], ctorParameters: function () { return [{ type: i1__namespace.HttpClient }, { type: i2__namespace.OccEndpointsService }, { type: i2__namespace.ConverterService }]; } }); // Imported for side effects (module augmentation) var defaultOccOrderConfig = { backend: { occ: { endpoints: { /* eslint-disable max-len */ orderHistory: 'users/${userId}/orders', orderDetail: 'users/${userId}/orders/${orderId}?fields=FULL', consignmentTracking: 'users/${userId}/orders/${orderCode}/consignments/${consignmentCode}/tracking', cancelOrder: 'users/${userId}/orders/${orderId}/cancellation', returnOrder: 'users/${userId}/orderReturns?fields=BASIC,returnEntries(BASIC,refundAmount(formattedValue),orderEntry(basePrice(formattedValue),product(name,code,baseOptions,images(DEFAULT,galleryIndex)))),deliveryCost(formattedValue),totalPrice(formattedValue),subTotal(formattedValue)', orderReturns: 'users/${userId}/orderReturns?fields=BASIC', orderReturnDetail: 'users/${userId}/orderReturns/${returnRequestCode}?fields=BASIC,returnEntries(BASIC,refundAmount(formattedValue),orderEntry(basePrice(formattedValue),product(name,code,baseOptions,images(DEFAULT,galleryIndex)))),deliveryCost(formattedValue),totalPrice(formattedValue),subTotal(formattedValue)', cancelReturn: 'users/${userId}/orderReturns/${returnRequestCode}', /* eslint-enable */ }, }, }, }; var OrderOccModule = /** @class */ (function () { function OrderOccModule() { } return OrderOccModule; }()); OrderOccModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderOccModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule }); OrderOccModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderOccModule, imports: [common.CommonModule] }); OrderOccModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderOccModule, providers: [ i2.provideDefaultConfig(defaultOccOrderConfig), { provide: core.OrderAdapter, useClass: OccOrderAdapter }, { provide: core.ReplenishmentOrderAdapter, useClass: OccReplenishmentOrderAdapter, }, { provide: core.ORDER_RETURN_REQUEST_NORMALIZER, useExisting: OccReturnRequestNormalizer, multi: true, }, ], imports: [[common.CommonModule]] }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderOccModule, decorators: [{ type: i0.NgModule, args: [{ imports: [common.CommonModule], providers: [ i2.provideDefaultConfig(defaultOccOrderConfig), { provide: core.OrderAdapter, useClass: OccOrderAdapter }, { provide: core.ReplenishmentOrderAdapter, useClass: OccReplenishmentOrderAdapter, }, { provide: core.ORDER_RETURN_REQUEST_NORMALIZER, useExisting: OccReturnRequestNormalizer, multi: true, }, ], }] }] }); /** * Generated bundle index. Do not edit. */ exports.OccOrderAdapter = OccOrderAdapter; exports.OccReplenishmentOrderAdapter = OccReplenishmentOrderAdapter; exports.OccReturnRequestNormalizer = OccReturnRequestNormalizer; exports.OrderOccModule = OrderOccModule; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=spartacus-order-occ.umd.js.map