{"version":3,"sources":["webpack:///javascripts/16-257c10c0995a4d25fa59.min.js","webpack:///./app/assets/javascripts/settings/services/SubscriptionSvc.ts","webpack:///./app/assets/javascripts/settings/subscription/containers/SubscriptionPredictPriceContainer.ts","webpack:///./app/assets/html/settings/subscription/containers/subscription-predict-price-container.html"],"names":["webpackJsonp","VXOl","module","exports","__webpack_require__","Object","defineProperty","value","tslib_1","underscore_extensions_1","AuthenticationSvc_1","UPDATE_SUBSCRIPTION_CARD","APPLY_COUPON","CouponCompaniesNames","prod","AppSumo117","title","MightyDeals417","StackSocial0718","defaultCompany","dev","MightyDeals417Test","SubscriptionSvc","$q","$filter","$http","$rootScope","$state","TranslateSvc","analyticSvc","AuthenticationSvc","affiliateSvc","HttpSvc","_this","this","specialSubscriptionNames","handlerHttpResponse","res","deferred","defer","data","Utils","isApiError","reject","errorMessage","console","error","resolve","promise","$on","USER_LOGOUT","upgradesDiscount","undefined","cardDetailsCashed","cardDetailsErrorMessage","$inject","isStripeError","message","type","prototype","get","getProduct","enumerable","configurable","params","product","getError","_","isString","getStripeCouponError","getRequiredSubscriptionError","getStripeCardError","has","toLowerCase","findSubscriptionByName","displayName","upgrade","getUpgradesByName","currentSubscription","getDetails","getDowngradesByName","getPredictPrice","_a","coupon","__rest","then","name","secureGet","__assign","r","isStripe","options","user","getAnnualSave","monthlyPrice","annualPrice","getAnnualPrice","details","discountPercentOff","discount","percentOff","round","calcDiscount","getMonthlyPrice","isFree","includes","isHigh","isSpecial","isAppSumo","_b","billingPeriod","provider","subscription","subscriptionDetails","prepareSubscription","setUpgradesDiscount","getAffiliateUser","affiliateInfo","getCardDetails","productParams","card","checkExpired","expires","catch","errMsg","upgrades","filter","upgradeItem","getDowngrades","downgrades","downgrade","downgradeItem","getUpgrades","excludeFromUI","hidden","cancelSubscription","secureDelete","changeSubscription","updateUser","dateArr","split","length","monthDays","getMonthDaysCount","toString","splice","formattedDate","join","expiredDate","Date","getTime","currentDate","now","isExpired","request","securePut","headers","getGaHeader","changeSubscriptionErrorHandler","updateCard","token","url","apiDomain","extend","Content-Type","post","$emit","err","status","errorCode","num","Math","ceil","makeSpecialSubscription","showSubscriptionCanceledMessage","expTime","expirationDate","date","msg","notification","showSuccess","matched","match","stripeKey","errorsCode","reg","RegExp","test","plan","period","subscriptionName","productName","upgradeParams","toParams","angular","service","edCO","SubscriptionSvc_1","PREDICT_PRICE_ERROR","SubscriptionPredictPriceContainer","$scope","subscriptionMessageSvc","subscriptionCouponMessageSvc","$stateParams","subscriptionSvc","applyCouponListener","noop","responses","errors","forEach","push","init","setCurrentSubscription","setPrice","hide","e","$onDestroy","$onChanges","onChangesObj","isFirstChange","currentPeriod","currentValue","go","current","notify","finally","loading","all","getStaticSubscription","subscriptions","predictSubscription","staticSubscription","hideMassage","planName","currentPredictPriceData","pricesObj","prices","reduce","price","annual","monthly","currentPrice","annualDiscount","Error","setupDiscount","currentPredictPrice","currentPredictPriceRounded","startingBalance","credit","totalPrice","totalPriceLastValue","amount","percents","amountDiscount","percentsDiscount","component","bindings","controller","templateUrl","gGiH","p"],"mappings":"AAAAA,cAAc,GAAG,MAEXC,KACA,SAAUC,EAAQC,EAASC,GAEjC,YCJAC,QAAOC,eAAeH,EAAS,cAAgBI,OAAO,GACtD,IAAIC,GAAUJ,EAAQ,QAAtBK,EAAAL,EAAA,QACAM,EAAAN,EAAA,OAIaD,GAAAQ,yBAA2B,kCAC3BR,EAAAS,aAAe,mCACfT,EAAAU,sBACTC,MACIC,YACIC,MAAO,WAEXC,gBACID,MAAO,eAEXE,iBACIF,MAAO,eAEXG,gBACIH,MAAO,YAIfI,KACIH,gBACID,MAAO,WAEXK,oBACIL,MAAO,eAEXE,iBACIF,MAAO,eAEXG,gBACIH,MAAO,aAGe,IAElC,IAAAM,GAAA,WAUI,QAAAA,GAAoBC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,GATpB,GAAAC,GAAAC,IAAoBA,MAAAX,KACAW,KAAAV,UACAU,KAAA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uBAAuBxC,KAAKyK,aAAaf,OAGjEW,EAAA5I,UAAAsB,gBAAR,SAAwBE,GACd,GAAAD,GAAAhD,KAAAyK,aAACf,EAAA1G,EAAA0G,KAAMC,EAAA3G,EAAA2G,MACb,OAAO3J,MAAK0K,gBAAgB3H,iBACxB4G,OAAMA,EACN1G,OAAMA,EACNR,YAAaiH,KAGzBW,IAEAL,SAAQhM,OAAO,qDACV6P,UAAU,qCACPC,UACInE,OAAQ,IACRyB,KAAM,KAEV2C,WAAY1D,EACZ2D,YAAa9P,EAAQ,WF8SvB+P,KACA,SAAUjQ,EAAQC,EAASC,GGxfjCF,EAAAC,QAAAC,EAAAgQ,EAAA","file":"javascripts/16-257c10c0995a4d25fa59.min.js","sourcesContent":["webpackJsonp([16,128],{\n\n/***/ \"VXOl\":\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar tslib_1 = __webpack_require__(\"TToO\");\r\nvar underscore_extensions_1 = __webpack_require__(\"R0iF\");\r\nvar AuthenticationSvc_1 = __webpack_require__(\"awAO\");\r\nexports.UPDATE_SUBSCRIPTION_CARD = 'website/subscription/updateCard';\r\nexports.APPLY_COUPON = 'website/subscription/applyCoupon';\r\nexports.CouponCompaniesNames = {\r\n prod: {\r\n AppSumo117: {\r\n title: 'AppSumo'\r\n },\r\n MightyDeals417: {\r\n title: 'MightyDeals'\r\n },\r\n StackSocial0718: {\r\n title: 'StackSocial'\r\n },\r\n defaultCompany: {\r\n title: 'Company'\r\n }\r\n },\r\n dev: {\r\n MightyDeals417: {\r\n title: 'AppSumo'\r\n },\r\n MightyDeals417Test: {\r\n title: 'MightyDeals'\r\n },\r\n StackSocial0718: {\r\n title: 'StackSocial'\r\n },\r\n defaultCompany: {\r\n title: 'Company'\r\n }\r\n }\r\n}[ true ? 'prod' : 'dev'];\r\nvar SubscriptionSvc = (function () {\r\n SubscriptionSvc.$inject = [\"$q\", \"$filter\", \"$http\", \"$rootScope\", \"$state\", \"TranslateSvc\", \"analyticSvc\", \"AuthenticationSvc\", \"affiliateSvc\", \"HttpSvc\"];\r\n function SubscriptionSvc($q, $filter, $http, $rootScope, $state, TranslateSvc, analyticSvc, AuthenticationSvc, affiliateSvc, HttpSvc) {\r\n var _this = this;\r\n this.$q = $q;\r\n this.$filter = $filter;\r\n this.$http = $http;\r\n this.$rootScope = $rootScope;\r\n this.$state = $state;\r\n this.TranslateSvc = TranslateSvc;\r\n this.analyticSvc = analyticSvc;\r\n this.AuthenticationSvc = AuthenticationSvc;\r\n this.affiliateSvc = affiliateSvc;\r\n this.HttpSvc = HttpSvc;\r\n this.specialSubscriptionNames = ['WaveBigAgency', 'WaveSmallAgency'];\r\n this.handlerHttpResponse = function (res) {\r\n var deferred = _this.$q.defer();\r\n if (res && res.data && underscore_extensions_1.Utils.isApiError(res.data)) {\r\n deferred.reject(res.data.errorMessage);\r\n console.error('subscription error: ', res.data);\r\n }\r\n else {\r\n deferred.resolve(res.data);\r\n }\r\n return deferred.promise;\r\n };\r\n this.$rootScope.$on(AuthenticationSvc_1.USER_LOGOUT, function () {\r\n _this.upgradesDiscount = undefined;\r\n _this.cardDetailsCashed = undefined;\r\n _this.cardDetailsErrorMessage = undefined;\r\n });\r\n }\r\n SubscriptionSvc.isStripeError = function (error) {\r\n return error && error.message && error.type;\r\n };\r\n Object.defineProperty(SubscriptionSvc.prototype, \"product\", {\r\n get: function () {\r\n return underscore_extensions_1.Utils.getProduct();\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(SubscriptionSvc.prototype, \"productParams\", {\r\n get: function () {\r\n return { params: { product: this.product } };\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n SubscriptionSvc.prototype.getError = function (error) {\r\n if (!error)\r\n return null;\r\n if (_.isString(error)) {\r\n return this.getStripeCouponError(error)\r\n || this.getRequiredSubscriptionError(error)\r\n || this.getStripeCardError(error)\r\n || (this.TranslateSvc.has(error.toLowerCase()) && this.TranslateSvc.get(error.toLowerCase()))\r\n || error;\r\n }\r\n else if (SubscriptionSvc.isStripeError(error)) {\r\n return error.message;\r\n }\r\n else {\r\n return error;\r\n }\r\n };\r\n SubscriptionSvc.prototype.findSubscriptionByName = function (displayName) {\r\n // search in upgrades\r\n var upgrade = this.getUpgradesByName(displayName);\r\n if (upgrade)\r\n return this.$q.resolve(upgrade);\r\n // search in current subscription\r\n var currentSubscription = this.getDetails();\r\n if (currentSubscription.displayName === displayName)\r\n return this.$q.resolve(currentSubscription);\r\n // search in downgrade\r\n return this.getDowngradesByName(null, displayName);\r\n };\r\n SubscriptionSvc.prototype.getPredictPrice = function (_a) {\r\n var displayName = _a.displayName, coupon = _a.coupon, params = tslib_1.__rest(_a, [\"displayName\", \"coupon\"]);\r\n var _this = this;\r\n return this.findSubscriptionByName(displayName)\r\n .then(function (_a) {\r\n var name = _a.name;\r\n return _this.HttpSvc('subscription/calculate').secureGet({\r\n params: tslib_1.__assign({}, params, { name: name, coupon: coupon || undefined })\r\n });\r\n })\r\n .then(function (r) { return r.data; });\r\n };\r\n SubscriptionSvc.prototype.isStripe = function () {\r\n return !this.isStripeError && options.user.isStripe();\r\n };\r\n SubscriptionSvc.prototype.getAnnualSave = function (upgrade) {\r\n if (upgrade === void 0) { upgrade = this.getDetails(); }\r\n return (upgrade.monthlyPrice * 12 - upgrade.annualPrice) / 100;\r\n };\r\n SubscriptionSvc.prototype.getAnnualPrice = function (details, discountPercentOff) {\r\n if (details === void 0) { details = this.getDetails(); }\r\n if (discountPercentOff === void 0) { discountPercentOff = details.discount && details.discount.percentOff; }\r\n return this.round(details.annualPrice * this.calcDiscount(discountPercentOff) / 100 / 12);\r\n };\r\n SubscriptionSvc.prototype.getMonthlyPrice = function (details, discountPercentOff) {\r\n if (details === void 0) { details = this.getDetails(); }\r\n if (discountPercentOff === void 0) { discountPercentOff = details.discount && details.discount.percentOff; }\r\n return this.round(details.monthlyPrice * this.calcDiscount(discountPercentOff) / 100);\r\n };\r\n SubscriptionSvc.prototype.isFree = function (currentSubscription) {\r\n if (currentSubscription === void 0) { currentSubscription = this.getDetails(); }\r\n var freeSubscriptions = ['WaveFree', 'Free'];\r\n return freeSubscriptions.includes(currentSubscription.name);\r\n };\r\n SubscriptionSvc.prototype.isHigh = function (currentSubscription) {\r\n if (currentSubscription === void 0) { currentSubscription = this.getDetails(); }\r\n var highSubscriptions = ['WaveBusiness', 'Business'];\r\n return highSubscriptions.includes(currentSubscription.name);\r\n };\r\n SubscriptionSvc.prototype.isSpecial = function (currentSubscription) {\r\n if (currentSubscription === void 0) { currentSubscription = this.getDetails(); }\r\n return this.specialSubscriptionNames.includes(currentSubscription.name);\r\n };\r\n SubscriptionSvc.prototype.isAppSumo = function (_a) {\r\n var _b = _a === void 0 ? this.getDetails() : _a, billingPeriod = _b.billingPeriod, discount = _b.discount;\r\n return discount\r\n && (discount.provider === 'AppSumo117'\r\n || (!true && discount.provider === 'MightyDeals417'));\r\n };\r\n SubscriptionSvc.prototype.getDetails = function () {\r\n var product = this.product.toLowerCase();\r\n var subscription = options.user.subscriptionDetails[product];\r\n return this.prepareSubscription(subscription);\r\n };\r\n SubscriptionSvc.prototype.setUpgradesDiscount = function () {\r\n var _this = this;\r\n this.affiliateSvc.getAffiliateUser().then(function (affiliateInfo) {\r\n _this.upgradesDiscount = affiliateInfo.discount;\r\n });\r\n };\r\n SubscriptionSvc.prototype.getCardDetails = function () {\r\n var _this = this;\r\n return this.HttpSvc('subscription', 'history')\r\n .secureGet(this.productParams)\r\n .then(this.handlerHttpResponse)\r\n .then(function (res) {\r\n _this.isStripeError = res.card.type === 'N/A';\r\n _this.checkExpired(res.card.expires);\r\n _this.cardDetailsCashed = res;\r\n return res;\r\n })\r\n .catch(function (errMsg) {\r\n _this.isStripeError = true;\r\n _this.cardDetailsErrorMessage = errMsg;\r\n return _this.$q.reject(errMsg);\r\n });\r\n };\r\n SubscriptionSvc.prototype.getUpgradesByName = function (name) {\r\n var upgrade = this.getDetails().upgrades.filter(function (upgradeItem) { return upgradeItem && (upgradeItem.name === name || upgradeItem.displayName === name); })[0];\r\n return upgrade && this.prepareSubscription(upgrade);\r\n };\r\n SubscriptionSvc.prototype.getDowngradesByName = function (name, displayName) {\r\n var _this = this;\r\n return this.getDowngrades().then(function (downgrades) {\r\n var downgrade = downgrades.filter(function (downgradeItem) { return downgradeItem && (downgradeItem.name === name || downgradeItem.displayName === displayName); })[0];\r\n return downgrade && _this.prepareSubscription(downgrade);\r\n });\r\n };\r\n SubscriptionSvc.prototype.getUpgrades = function () {\r\n return this.getDetails()\r\n .upgrades\r\n .filter(function (upgrade) { return !upgrade.excludeFromUI && !upgrade.hidden && upgrade.name !== 'WaveEnterprise'; });\r\n };\r\n SubscriptionSvc.prototype.getDowngrades = function () {\r\n return this.HttpSvc('subscription', 'downgrade')\r\n .secureGet(this.productParams)\r\n .then(this.handlerHttpResponse)\r\n .then(function (downgrades) {\r\n return downgrades.filter(function (downgrade) { return !downgrade.excludeFromUI && !downgrade.hidden; });\r\n });\r\n };\r\n SubscriptionSvc.prototype.cancelSubscription = function () {\r\n var _this = this;\r\n var _a = this.getDetails(), displayName = _a.displayName, billingPeriod = _a.billingPeriod;\r\n return this.HttpSvc('subscription', 'cancel')\r\n .secureDelete(this.productParams)\r\n .then(this.handlerHttpResponse)\r\n .then(function () {\r\n _this.cardDetailsCashed = null;\r\n _this.cardDetailsErrorMessage = null;\r\n _this.analyticSvc.changeSubscription('downgrade', displayName, billingPeriod);\r\n return _this.AuthenticationSvc.updateUser();\r\n });\r\n };\r\n SubscriptionSvc.prototype.checkExpired = function (expires) {\r\n var dateArr = expires.split('/');\r\n if (dateArr.length === 2) {\r\n var monthDays = underscore_extensions_1.Utils.getMonthDaysCount().toString();\r\n dateArr.splice(1, 0, monthDays);\r\n }\r\n var formattedDate = dateArr.join('/');\r\n var expiredDate = new Date(formattedDate).getTime();\r\n var currentDate = _.now();\r\n this.isExpired = currentDate >= expiredDate;\r\n };\r\n SubscriptionSvc.prototype.changeSubscription = function (params) {\r\n var _this = this;\r\n var request = function () { return _this.HttpSvc('subscription', 'change')\r\n .securePut(params, { headers: _this.analyticSvc.getGaHeader() }); };\r\n return this.changeSubscriptionErrorHandler(request);\r\n };\r\n SubscriptionSvc.prototype.changeSubscriptionErrorHandler = function (request) {\r\n var _this = this;\r\n var getErrorPromise = function () {\r\n var errorMessage = 'credit.card.processing.error.[expired_card]';\r\n var deferred = _this.$q.defer();\r\n deferred.resolve({ data: { errorMessage: errorMessage } });\r\n return deferred.promise;\r\n };\r\n return this.isExpired ? getErrorPromise() : request();\r\n };\r\n SubscriptionSvc.prototype.updateCard = function (token) {\r\n var _this = this;\r\n var url = options.apiDomain + \"/subscription/card/update\";\r\n var headers = _.extend({\r\n 'Content-Type': 'application/json'\r\n }, options.headers);\r\n return this.$http\r\n .post(url, { token: token }, { headers: headers })\r\n .then(function (r) {\r\n _this.$rootScope.$emit(exports.UPDATE_SUBSCRIPTION_CARD);\r\n return r;\r\n })\r\n .catch(function (err) { return err.status !== -1 ? err : {\r\n data: {\r\n errorCode: 400,\r\n errorMessage: 'subscription.update-card.default-error'\r\n }\r\n }; });\r\n };\r\n SubscriptionSvc.prototype.round = function (num) {\r\n return Math.ceil(num);\r\n };\r\n SubscriptionSvc.prototype.calcDiscount = function (discount) {\r\n return discount ? 1 - discount / 100 : 1;\r\n };\r\n SubscriptionSvc.prototype.makeSpecialSubscription = function (subscription) {\r\n subscription.monthlyPrice = undefined;\r\n return subscription;\r\n };\r\n SubscriptionSvc.prototype.prepareSubscription = function (subscription) {\r\n return this.specialSubscriptionNames.includes(subscription.name) ?\r\n this.makeSpecialSubscription(subscription) : subscription;\r\n };\r\n SubscriptionSvc.prototype.showSubscriptionCanceledMessage = function () {\r\n var details = this.getDetails();\r\n var currentPlan = details.displayName;\r\n var expTime = details.expirationDate;\r\n var date = this.$filter('date')(expTime * 1000, 'short');\r\n var msg = expTime ? \"Subscription will be canceled on \" + date : 'Already canceled';\r\n _.notification.showSuccess(msg);\r\n };\r\n SubscriptionSvc.prototype.getStripeCardError = function (error) {\r\n var matched = error.match(/\\[([A-Za-z_]+)\\]/);\r\n var stripeKey = matched && matched[1];\r\n return stripeKey && this.TranslateSvc.has(stripeKey) ? this.TranslateSvc.get(stripeKey) : null;\r\n };\r\n SubscriptionSvc.prototype.getStripeCouponError = function (error) {\r\n var errorsCode = [\r\n 'Coupon expired',\r\n 'No such coupon',\r\n 'Coupon is not valid',\r\n 'Coupon inapplicable'\r\n ];\r\n var reg = new RegExp(errorsCode.join('|'));\r\n var isCouponError = _.isString(error) && reg.test(error);\r\n return isCouponError && this.TranslateSvc.get('coupon.error');\r\n };\r\n SubscriptionSvc.prototype.getRequiredSubscriptionError = function (error) {\r\n var isRequiredSubscriptionError = _.isString(error) && /required subscription:/.test(error);\r\n if (!isRequiredSubscriptionError)\r\n return false;\r\n var _a = error.match(/\\(([0-9a-zA-Z]+)\\|([0-9a-zA-Z]+)\\)/), plan = _a[1], period = _a[2];\r\n var subscriptionName = plan + \" \" + period;\r\n var productName = underscore_extensions_1.Utils.getProduct().toLowerCase();\r\n var coupon = this.$state.params.coupon;\r\n var upgradeParams = underscore_extensions_1.Utils.toParams({\r\n plan: plan,\r\n coupon: coupon,\r\n period: period.toLowerCase()\r\n });\r\n var url = \"/\" + productName + \"/pricing/upgrade?\" + upgradeParams;\r\n return this.TranslateSvc.get('required.subscription.error', url, subscriptionName);\r\n };\r\n return SubscriptionSvc;\r\n}());\r\nexports.SubscriptionSvc = SubscriptionSvc;\r\nangular.module('animatronApp.SubscriptionSvc', []).service('subscriptionSvc', SubscriptionSvc);\r\n\n\n/***/ }),\n\n/***/ \"edCO\":\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar tslib_1 = __webpack_require__(\"TToO\");\r\nvar SubscriptionSvc_1 = __webpack_require__(\"VXOl\");\r\nvar underscore_extensions_1 = __webpack_require__(\"R0iF\");\r\nexports.PREDICT_PRICE_ERROR = 'website/subscription/predictPriceError';\r\nvar SubscriptionPredictPriceContainer = (function () {\r\n SubscriptionPredictPriceContainer.$inject = [\"$q\", \"$scope\", \"$state\", \"subscriptionMessageSvc\", \"subscriptionCouponMessageSvc\", \"$stateParams\", \"$rootScope\", \"subscriptionSvc\"];\r\n function SubscriptionPredictPriceContainer($q, $scope, $state, subscriptionMessageSvc, subscriptionCouponMessageSvc, $stateParams, $rootScope, subscriptionSvc) {\r\n var _this = this;\r\n this.$q = $q;\r\n this.$scope = $scope;\r\n this.$state = $state;\r\n this.subscriptionMessageSvc = subscriptionMessageSvc;\r\n this.subscriptionCouponMessageSvc = subscriptionCouponMessageSvc;\r\n this.$stateParams = $stateParams;\r\n this.$rootScope = $rootScope;\r\n this.subscriptionSvc = subscriptionSvc;\r\n this.applyCouponListener = _.noop;\r\n this.handlerHttpResponse = function (responses) {\r\n var deferred = _this.$q.defer();\r\n var errors = [];\r\n responses.forEach(function (res) {\r\n if (underscore_extensions_1.Utils.isApiError(res)) {\r\n errors.push(_this.subscriptionSvc.getError(res.errorMessage));\r\n }\r\n });\r\n if (errors.length > 0) {\r\n deferred.reject(errors);\r\n }\r\n else {\r\n deferred.resolve(responses);\r\n }\r\n return deferred.promise;\r\n };\r\n var init = function (coupon) { return _this.setCurrentSubscription(coupon)\r\n .then(function () { return _this.setPrice(); }); };\r\n !this.hide && init(this.$stateParams.coupon);\r\n this.applyCouponListener = this.$rootScope.$on(SubscriptionSvc_1.APPLY_COUPON, function (e, coupon) { return init(coupon); });\r\n }\r\n SubscriptionPredictPriceContainer.prototype.$onDestroy = function () {\r\n this.applyCouponListener();\r\n };\r\n SubscriptionPredictPriceContainer.prototype.$onChanges = function (onChangesObj) {\r\n var _this = this;\r\n if (!onChangesObj.period || onChangesObj.period.isFirstChange())\r\n return;\r\n this.$rootScope.$emit(exports.PREDICT_PRICE_ERROR, ''); // clear previous error message\r\n this.currentPeriod = onChangesObj.period.currentValue.toLowerCase();\r\n this.$state\r\n .go(this.$state.current, tslib_1.__assign({}, this.$stateParams, { period: this.currentPeriod }), { notify: false })\r\n .finally(function () { return !_this.loading && _this.setPrice(); });\r\n };\r\n SubscriptionPredictPriceContainer.prototype.setCurrentSubscription = function (coupon) {\r\n var _this = this;\r\n this.loading = true;\r\n return this.$q.all([\r\n this.getPredictPrice(coupon),\r\n this.getStaticSubscription()\r\n ])\r\n .then(this.handlerHttpResponse)\r\n .then(function (subscriptions) {\r\n var predictSubscription = subscriptions[0], staticSubscription = subscriptions[1];\r\n _this.predictSubscription = predictSubscription;\r\n _this.staticSubscription = staticSubscription;\r\n })\r\n .catch(function (errors) {\r\n _this.subscriptionMessageSvc.hideMassage();\r\n _this.$rootScope.$emit(exports.PREDICT_PRICE_ERROR, errors[0]);\r\n return _this.$q.reject(errors);\r\n })\r\n .finally(function () {\r\n _this.loading = false;\r\n });\r\n };\r\n SubscriptionPredictPriceContainer.prototype.setPrice = function () {\r\n var _a = this.$stateParams, period = _a.period, plan = _a.plan;\r\n if (!plan)\r\n return;\r\n this.currentPeriod = this.currentPeriod || period;\r\n var _b = this.staticSubscription, annualPrice = _b.annualPrice, monthlyPrice = _b.monthlyPrice, displayName = _b.displayName;\r\n this.planName = displayName;\r\n // transform prices from array to object\r\n var pricesObj = this.predictSubscription.prices.reduce(function (prices, price) {\r\n if (price.period === 'ANNUAL') {\r\n prices.annual = price;\r\n }\r\n else if (price.period === 'MONTHLY') {\r\n prices.monthly = price;\r\n }\r\n return prices;\r\n }, {});\r\n var currentPredictPriceData;\r\n if (this.currentPeriod === 'annual') {\r\n currentPredictPriceData = pricesObj.annual;\r\n this.currentPrice = monthlyPrice * 12 / 100 || annualPrice / 100;\r\n this.annualDiscount = this.currentPrice - (annualPrice / 100);\r\n }\r\n else if (this.currentPeriod === 'monthly') {\r\n currentPredictPriceData = pricesObj.monthly;\r\n this.currentPrice = monthlyPrice / 100;\r\n this.annualDiscount = null;\r\n }\r\n else {\r\n throw new Error('incorrect period name');\r\n }\r\n this.setupDiscount(currentPredictPriceData);\r\n var currentPredictPrice = currentPredictPriceData.price / 100;\r\n var currentPredictPriceRounded = this.subscriptionSvc.round(currentPredictPrice);\r\n var startingBalance = this.subscriptionSvc.round(this.predictSubscription.startingBalance / 100);\r\n this.credit = startingBalance < 0 ? -startingBalance : 0;\r\n this.totalPrice = currentPredictPriceRounded >= 0 ? currentPredictPriceRounded : 0;\r\n this.subscriptionSvc.totalPriceLastValue = this.totalPrice;\r\n };\r\n SubscriptionPredictPriceContainer.prototype.setupDiscount = function (_a) {\r\n var discount = _a.discount;\r\n this.subscriptionMessageSvc.hideMassage();\r\n if (!discount)\r\n return;\r\n var error = discount.error, amount = discount.amount, percents = discount.percents;\r\n if (error) {\r\n this.$rootScope.$emit(exports.PREDICT_PRICE_ERROR, this.subscriptionSvc.getError(error));\r\n }\r\n else {\r\n this.amountDiscount = amount / 100;\r\n this.percentsDiscount = percents;\r\n var message = this.subscriptionCouponMessageSvc.get(discount);\r\n this.subscriptionMessageSvc.showSuccess(message);\r\n }\r\n };\r\n SubscriptionPredictPriceContainer.prototype.getStaticSubscription = function () {\r\n return this.subscriptionSvc.findSubscriptionByName(this.$stateParams.plan);\r\n };\r\n SubscriptionPredictPriceContainer.prototype.getPredictPrice = function (coupon) {\r\n var _a = this.$stateParams, plan = _a.plan, period = _a.period;\r\n return this.subscriptionSvc.getPredictPrice({\r\n period: period,\r\n coupon: coupon,\r\n displayName: plan\r\n });\r\n };\r\n return SubscriptionPredictPriceContainer;\r\n}());\r\nangular.module('animatronApp.SubscriptionPredictPriceContainer', [])\r\n .component('subscriptionPredictPriceContainer', {\r\n bindings: {\r\n period: '<',\r\n hide: '<'\r\n },\r\n controller: SubscriptionPredictPriceContainer,\r\n templateUrl: __webpack_require__(\"gGiH\")\r\n});\r\n\n\n/***/ }),\n\n/***/ \"gGiH\":\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__.p + \"html/subscription-predict-price-container_c43307d31652cc92c825efb25c575167.html\";\n\n/***/ })\n\n});\n\n\n// WEBPACK FOOTER //\n// javascripts/16-257c10c0995a4d25fa59.min.js","import {TranslateSvc} from '../../services/TranslateSvc';\nimport {HttpSvcFactory} from '../../services/HttpSvc';\nimport {Utils} from '../../underscore-extensions';\nimport {AuthenticationSvc, USER_LOGOUT} from '../../services/AuthenticationSvc';\nimport {AnalyticSvc} from '../../services/AnalyticSvc';\nimport {AffiliateSvc} from '../../services/AffiliateSvc';\n\nexport const UPDATE_SUBSCRIPTION_CARD = 'website/subscription/updateCard';\nexport const APPLY_COUPON = 'website/subscription/applyCoupon';\nexport const CouponCompaniesNames = {\n prod: {\n AppSumo117: {\n title: 'AppSumo'\n },\n MightyDeals417: {\n title: 'MightyDeals'\n },\n StackSocial0718: {\n title: 'StackSocial'\n },\n defaultCompany: {\n title: 'Company'\n }\n },\n\n dev: {\n MightyDeals417: {\n title: 'AppSumo'\n },\n MightyDeals417Test: {\n title: 'MightyDeals'\n },\n StackSocial0718: {\n title: 'StackSocial'\n },\n defaultCompany: {\n title: 'Company'\n }\n }\n}[options.isProduction ? 'prod' : 'dev'];\n\nexport class SubscriptionSvc {\n cardDetailsCashed: anm.CardDetails;\n cardDetailsErrorMessage: string;\n upgradesDiscount: number;\n isExpired: boolean;\n totalPriceLastValue: number;\n\n private isStripeError: boolean;\n private specialSubscriptionNames = ['WaveBigAgency', 'WaveSmallAgency'];\n\n constructor(private $q: ng.IQService,\n private $filter: ng.IFilterService,\n private $http: ng.IHttpService,\n private $rootScope: ng.IRootScopeService,\n private $state: ng.ui.IStateService,\n private TranslateSvc: TranslateSvc,\n private analyticSvc: AnalyticSvc,\n private AuthenticationSvc: AuthenticationSvc,\n private affiliateSvc: AffiliateSvc,\n private HttpSvc: HttpSvcFactory) {\n this.$rootScope.$on(USER_LOGOUT, () => {\n this.upgradesDiscount = undefined;\n this.cardDetailsCashed = undefined;\n this.cardDetailsErrorMessage = undefined;\n });\n }\n\n\n static isStripeError(error: any): error is StripeError {\n return error && error.message && error.type;\n }\n\n get product(): AnimatronProduct {\n return Utils.getProduct();\n }\n\n get productParams() {\n return {params: {product: this.product}};\n }\n\n getError(error?: string | StripeError): string {\n if (!error) return null;\n\n if (_.isString(error)) {\n return this.getStripeCouponError(error)\n || this.getRequiredSubscriptionError(error)\n || this.getStripeCardError(error)\n || (this.TranslateSvc.has(error.toLowerCase()) && this.TranslateSvc.get(error.toLowerCase()))\n || error;\n } else if (SubscriptionSvc.isStripeError(error)) {\n return error.message;\n } else {\n return error as string;\n }\n }\n\n findSubscriptionByName(displayName: string): ng.IPromise {\n // search in upgrades\n const upgrade = this.getUpgradesByName(displayName);\n if (upgrade) return this.$q.resolve(upgrade);\n\n // search in current subscription\n const currentSubscription = this.getDetails();\n if (currentSubscription.displayName === displayName) return this.$q.resolve(currentSubscription);\n\n // search in downgrade\n return this.getDowngradesByName(null, displayName);\n }\n\n getPredictPrice({displayName, coupon, ...params}: SubscriptionPredict.Params): ng.IPromise {\n return this.findSubscriptionByName(displayName)\n .then(({name}) => this.HttpSvc('subscription/calculate').secureGet({\n params: {\n ...params,\n name,\n coupon: coupon || undefined\n }\n }))\n .then(r => r.data);\n }\n\n isStripe() {\n return !this.isStripeError && options.user.isStripe();\n }\n\n getAnnualSave(upgrade = this.getDetails()) {\n return (upgrade.monthlyPrice * 12 - upgrade.annualPrice) / 100;\n }\n\n getAnnualPrice(details: anm.SubscriptionDetails = this.getDetails(),\n discountPercentOff = details.discount && details.discount.percentOff) {\n return this.round(details.annualPrice * this.calcDiscount(discountPercentOff) / 100 / 12);\n }\n\n getMonthlyPrice(details: anm.SubscriptionDetails = this.getDetails(),\n discountPercentOff = details.discount && details.discount.percentOff) {\n return this.round(details.monthlyPrice * this.calcDiscount(discountPercentOff) / 100);\n }\n\n isFree(currentSubscription = this.getDetails()) {\n const freeSubscriptions = ['WaveFree', 'Free'];\n return freeSubscriptions.includes(currentSubscription.name)\n }\n\n isHigh(currentSubscription = this.getDetails()) {\n const highSubscriptions = ['WaveBusiness', 'Business'];\n return highSubscriptions.includes(currentSubscription.name)\n }\n\n isSpecial(currentSubscription = this.getDetails()) {\n return this.specialSubscriptionNames.includes(currentSubscription.name)\n }\n\n isAppSumo({billingPeriod, discount} = this.getDetails()) {\n return discount\n && (discount.provider === 'AppSumo117'\n || (!options.isProduction && discount.provider === 'MightyDeals417'));\n }\n\n getDetails(): anm.SubscriptionDetails {\n const product = this.product.toLowerCase();\n const subscription = options.user.subscriptionDetails[product];\n return this.prepareSubscription(subscription);\n }\n\n setUpgradesDiscount() {\n this.affiliateSvc.getAffiliateUser().then((affiliateInfo: anm.AffiliateInfo) => {\n this.upgradesDiscount = affiliateInfo.discount;\n });\n }\n\n getCardDetails() {\n return this.HttpSvc('subscription', 'history')\n .secureGet(this.productParams)\n .then(this.handlerHttpResponse)\n .then((res: anm.CardDetails) => {\n this.isStripeError = res.card.type === 'N/A';\n this.checkExpired(res.card.expires);\n this.cardDetailsCashed = res;\n return res;\n })\n .catch((errMsg: string) => {\n this.isStripeError = true;\n this.cardDetailsErrorMessage = errMsg;\n return this.$q.reject(errMsg);\n });\n }\n\n getUpgradesByName(name: string) {\n const upgrade = this.getDetails().upgrades.filter(\n upgradeItem => upgradeItem && (upgradeItem.name === name || upgradeItem.displayName === name)\n )[0];\n return upgrade && this.prepareSubscription(upgrade);\n }\n\n getDowngradesByName(name: string, displayName?: string) {\n return this.getDowngrades().then(downgrades => {\n const downgrade = downgrades.filter(\n downgradeItem => downgradeItem && (downgradeItem.name === name || downgradeItem.displayName === displayName)\n )[0];\n return downgrade && this.prepareSubscription(downgrade);\n });\n\n }\n\n getUpgrades() {\n return this.getDetails()\n .upgrades\n .filter(upgrade => !upgrade.excludeFromUI && !upgrade.hidden && upgrade.name !== 'WaveEnterprise');\n }\n\n getDowngrades(): ng.IPromise {\n return this.HttpSvc('subscription', 'downgrade')\n .secureGet(this.productParams)\n .then(this.handlerHttpResponse)\n .then((downgrades: anm.SubscriptionDetails[]) => {\n return downgrades.filter(downgrade => !downgrade.excludeFromUI && !downgrade.hidden);\n });\n }\n\n cancelSubscription() {\n const {displayName, billingPeriod} = this.getDetails();\n\n return this.HttpSvc('subscription', 'cancel')\n .secureDelete(this.productParams)\n .then(this.handlerHttpResponse)\n .then(() => {\n this.cardDetailsCashed = null;\n this.cardDetailsErrorMessage = null;\n\n this.analyticSvc.changeSubscription(\n 'downgrade',\n displayName,\n billingPeriod\n );\n return this.AuthenticationSvc.updateUser();\n });\n }\n\n checkExpired(expires: string) {\n const dateArr = expires.split('/');\n\n if (dateArr.length === 2) {\n const monthDays = Utils.getMonthDaysCount().toString();\n dateArr.splice(1, 0, monthDays);\n }\n\n const formattedDate = dateArr.join('/');\n const expiredDate = new Date(formattedDate).getTime();\n\n const currentDate = _.now();\n\n this.isExpired = currentDate >= expiredDate;\n }\n\n changeSubscription(params: anm.ChangeSubscriptionRequest) {\n const request = () => this.HttpSvc('subscription', 'change')\n .securePut(params, {headers: this.analyticSvc.getGaHeader()});\n\n return this.changeSubscriptionErrorHandler(request);\n }\n\n private changeSubscriptionErrorHandler(request: Function) {\n const getErrorPromise = () => {\n const errorMessage = 'credit.card.processing.error.[expired_card]';\n const deferred = this.$q.defer();\n deferred.resolve({data: {errorMessage}});\n return deferred.promise;\n };\n\n return this.isExpired ? getErrorPromise() : request();\n }\n\n updateCard(token: string) {\n const url = `${options.apiDomain}/subscription/card/update`;\n const headers = _.extend({\n 'Content-Type': 'application/json'\n }, options.headers);\n\n return this.$http\n .post(url, {token}, {headers})\n .then((r: ng.IHttpPromiseCallbackArg) => {\n this.$rootScope.$emit(UPDATE_SUBSCRIPTION_CARD);\n return r;\n })\n .catch((err: ng.IHttpPromiseCallbackArg) => err.status !== -1 ? err : {\n data: {\n errorCode: 400,\n errorMessage: 'subscription.update-card.default-error'\n }\n });\n }\n\n round(num: number) {\n return Math.ceil(num);\n }\n\n calcDiscount(discount: number) {\n return discount ? 1 - discount / 100 : 1;\n }\n\n makeSpecialSubscription(subscription: anm.SubscriptionDetails) {\n subscription.monthlyPrice = undefined;\n return subscription;\n }\n\n private prepareSubscription(subscription: anm.SubscriptionDetails) {\n return this.specialSubscriptionNames.includes(subscription.name) ?\n this.makeSpecialSubscription(subscription) : subscription\n }\n\n showSubscriptionCanceledMessage() {\n const details = this.getDetails();\n const currentPlan = details.displayName;\n const expTime = details.expirationDate;\n const date = this.$filter('date')(expTime * 1000, 'short');\n const msg = expTime ? `Subscription will be canceled on ${date}` : 'Already canceled';\n\n _.notification.showSuccess(msg);\n }\n\n private handlerHttpResponse = (res: ng.IHttpPromiseCallbackArg) => {\n const deferred = this.$q.defer();\n if (res && res.data && Utils.isApiError(res.data)) {\n deferred.reject(res.data.errorMessage);\n console.error('subscription error: ', res.data);\n } else {\n deferred.resolve(res.data);\n }\n return deferred.promise;\n }\n\n private getStripeCardError(error: string) {\n const matched = error.match(/\\[([A-Za-z_]+)\\]/);\n const stripeKey = matched && matched[1];\n return stripeKey && this.TranslateSvc.has(stripeKey) ? this.TranslateSvc.get(stripeKey) : null;\n }\n\n private getStripeCouponError(error: string) {\n const errorsCode = [\n 'Coupon expired',\n 'No such coupon',\n 'Coupon is not valid',\n 'Coupon inapplicable'\n ];\n\n const reg = new RegExp(errorsCode.join('|'));\n const isCouponError = _.isString(error) && reg.test(error);\n return isCouponError && this.TranslateSvc.get('coupon.error');\n }\n\n private getRequiredSubscriptionError(error: string) {\n const isRequiredSubscriptionError = _.isString(error) && /required subscription:/.test(error);\n if (!isRequiredSubscriptionError) return false;\n\n const [, plan, period] = error.match(/\\(([0-9a-zA-Z]+)\\|([0-9a-zA-Z]+)\\)/);\n const subscriptionName = `${plan} ${period}`;\n const productName = Utils.getProduct().toLowerCase();\n const {coupon} = this.$state.params;\n const upgradeParams = Utils.toParams({\n plan,\n coupon,\n period: period.toLowerCase()\n });\n const url = `/${productName}/pricing/upgrade?${upgradeParams}`;\n\n return this.TranslateSvc.get('required.subscription.error', url, subscriptionName);\n }\n}\n\nangular.module('animatronApp.SubscriptionSvc', []).service('subscriptionSvc', SubscriptionSvc);\n\n\n// WEBPACK FOOTER //\n// ./app/assets/javascripts/settings/services/SubscriptionSvc.ts","import {APPLY_COUPON, SubscriptionSvc} from '../../services/SubscriptionSvc';\nimport {SubscriptionsParams} from '../../directives/Subscriptions';\nimport {Utils} from '../../../underscore-extensions';\nimport {SubscriptionMessagesSvc} from '../messages/SubscriptionMessagesSvc';\nimport {SubscriptionCouponMessagesSvc} from '../messages/SubscriptionCouponMessagesSvc';\n\nexport const PREDICT_PRICE_ERROR = 'website/subscription/predictPriceError';\n\nclass SubscriptionPredictPriceContainer implements ng.IComponentController {\n currentPrice: number;\n currentPeriod: string;\n period: string;\n planName: string;\n annualDiscount: number;\n percentsDiscount: number;\n amountDiscount: number;\n totalPrice: number;\n credit: number;\n loading: boolean;\n hide: boolean;\n private applyCouponListener: Function = _.noop;\n private staticSubscription: anm.SubscriptionDetails;\n private predictSubscription: SubscriptionPredict.Details;\n\n constructor(private $q: ng.IQService,\n private $scope: ng.IScope,\n private $state: ng.ui.IStateService,\n private subscriptionMessageSvc: SubscriptionMessagesSvc,\n private subscriptionCouponMessageSvc: SubscriptionCouponMessagesSvc,\n private $stateParams: SubscriptionsParams,\n private $rootScope: ng.IRootScopeService,\n private subscriptionSvc: SubscriptionSvc) {\n const init = (coupon?: string) => this.setCurrentSubscription(coupon)\n .then(() => this.setPrice());\n\n !this.hide && init(this.$stateParams.coupon);\n\n this.applyCouponListener = this.$rootScope.$on(\n APPLY_COUPON,\n (e, coupon: string) => init(coupon)\n );\n }\n\n $onDestroy() {\n this.applyCouponListener();\n }\n\n $onChanges(onChangesObj: ng.IOnChangesObject) {\n if (!onChangesObj.period || onChangesObj.period.isFirstChange()) return;\n this.$rootScope.$emit(PREDICT_PRICE_ERROR, ''); // clear previous error message\n this.currentPeriod = onChangesObj.period.currentValue.toLowerCase();\n\n this.$state\n .go(\n this.$state.current,\n {\n ...this.$stateParams,\n period: this.currentPeriod\n },\n {notify: false}\n )\n .finally(() => !this.loading && this.setPrice());\n }\n\n private setCurrentSubscription(coupon?: string) {\n this.loading = true;\n\n return this.$q.all([\n this.getPredictPrice(coupon),\n this.getStaticSubscription()\n ])\n .then(this.handlerHttpResponse)\n .then(subscriptions => {\n const [predictSubscription, staticSubscription] = subscriptions;\n\n this.predictSubscription = predictSubscription;\n this.staticSubscription = staticSubscription;\n })\n .catch((errors: any[]) => {\n this.subscriptionMessageSvc.hideMassage();\n this.$rootScope.$emit(PREDICT_PRICE_ERROR, errors[0]);\n return this.$q.reject(errors);\n })\n .finally(() => {\n this.loading = false;\n });\n }\n\n private setPrice() {\n const {period, plan} = this.$stateParams;\n if (!plan) return;\n\n this.currentPeriod = this.currentPeriod || period;\n\n const {\n annualPrice,\n monthlyPrice,\n displayName\n } = this.staticSubscription;\n\n this.planName = displayName;\n\n // transform prices from array to object\n const pricesObj: {\n annual: SubscriptionPredict.Price;\n monthly: SubscriptionPredict.Price;\n } = this.predictSubscription.prices.reduce((prices: any, price: SubscriptionPredict.Price) => {\n if (price.period === 'ANNUAL') {\n prices.annual = price;\n } else if (price.period === 'MONTHLY') {\n prices.monthly = price;\n }\n return prices;\n }, {});\n\n let currentPredictPriceData: SubscriptionPredict.Price;\n\n if (this.currentPeriod === 'annual') {\n currentPredictPriceData = pricesObj.annual;\n this.currentPrice = monthlyPrice * 12 / 100 || annualPrice / 100;\n this.annualDiscount = this.currentPrice - (annualPrice / 100);\n } else if (this.currentPeriod === 'monthly') {\n currentPredictPriceData = pricesObj.monthly;\n this.currentPrice = monthlyPrice / 100;\n this.annualDiscount = null;\n } else {\n throw new Error('incorrect period name');\n }\n\n this.setupDiscount(currentPredictPriceData);\n\n const currentPredictPrice = currentPredictPriceData.price / 100;\n const currentPredictPriceRounded = this.subscriptionSvc.round(currentPredictPrice);\n\n const startingBalance = this.subscriptionSvc.round(this.predictSubscription.startingBalance / 100);\n this.credit = startingBalance < 0 ? -startingBalance : 0;\n this.totalPrice = currentPredictPriceRounded >= 0 ? currentPredictPriceRounded : 0;\n this.subscriptionSvc.totalPriceLastValue = this.totalPrice;\n }\n\n private setupDiscount({discount}: SubscriptionPredict.Price) {\n this.subscriptionMessageSvc.hideMassage();\n\n if (!discount) return;\n\n const {error, amount, percents} = discount;\n\n if (error) {\n this.$rootScope.$emit(PREDICT_PRICE_ERROR, this.subscriptionSvc.getError(error));\n } else {\n this.amountDiscount = amount / 100;\n this.percentsDiscount = percents;\n const message = this.subscriptionCouponMessageSvc.get(discount);\n this.subscriptionMessageSvc.showSuccess(message);\n }\n }\n\n\n private handlerHttpResponse = (responses: (any | ApiError)[]): ng.IPromise<[\n SubscriptionPredict.Details,\n anm.SubscriptionDetails\n ]> => {\n const deferred = this.$q.defer();\n const errors: string[] = [];\n\n responses.forEach((res) => {\n if (Utils.isApiError(res)) {\n errors.push(this.subscriptionSvc.getError(res.errorMessage));\n }\n });\n\n if (errors.length > 0) {\n deferred.reject(errors);\n } else {\n deferred.resolve(responses);\n }\n\n return deferred.promise;\n }\n\n private getStaticSubscription() {\n return this.subscriptionSvc.findSubscriptionByName(this.$stateParams.plan);\n }\n\n private getPredictPrice(coupon?: string) {\n const {plan, period} = this.$stateParams;\n return this.subscriptionSvc.getPredictPrice({\n period,\n coupon,\n displayName: plan as anm.SubscriptionDisplayName\n });\n }\n}\n\nangular.module('animatronApp.SubscriptionPredictPriceContainer', [])\n .component('subscriptionPredictPriceContainer', {\n bindings: {\n period: '<',\n hide: '<'\n },\n controller: SubscriptionPredictPriceContainer,\n templateUrl: require('settings/subscription/containers/subscription-predict-price-container.html')\n });\n\n\n\n// WEBPACK FOOTER //\n// ./app/assets/javascripts/settings/subscription/containers/SubscriptionPredictPriceContainer.ts","module.exports = __webpack_public_path__ + \"html/subscription-predict-price-container_c43307d31652cc92c825efb25c575167.html\";\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./app/assets/html/settings/subscription/containers/subscription-predict-price-container.html\n// module id = gGiH\n// module chunks = 3 8 16"],"sourceRoot":""}