{"version":3,"sources":["node_modules/date-fns/addMilliseconds.mjs","node_modules/date-fns/addSeconds.mjs","node_modules/date-fns/differenceInMilliseconds.mjs","src/app/main/service/base-data.service.ts"],"sourcesContent":["import { toDate } from \"./toDate.mjs\";\nimport { constructFrom } from \"./constructFrom.mjs\";\n\n/**\n * @name addMilliseconds\n * @category Millisecond Helpers\n * @summary Add the specified number of milliseconds to the given date.\n *\n * @description\n * Add the specified number of milliseconds to the given date.\n *\n * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).\n *\n * @param date - The date to be changed\n * @param amount - The amount of milliseconds to be added.\n *\n * @returns The new date with the milliseconds added\n *\n * @example\n * // Add 750 milliseconds to 10 July 2014 12:45:30.000:\n * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)\n * //=> Thu Jul 10 2014 12:45:30.750\n */\nexport function addMilliseconds(date, amount) {\n const timestamp = +toDate(date);\n return constructFrom(date, timestamp + amount);\n}\n\n// Fallback for modularized imports:\nexport default addMilliseconds;","import { addMilliseconds } from \"./addMilliseconds.mjs\";\n\n/**\n * @name addSeconds\n * @category Second Helpers\n * @summary Add the specified number of seconds to the given date.\n *\n * @description\n * Add the specified number of seconds to the given date.\n *\n * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).\n *\n * @param date - The date to be changed\n * @param amount - The amount of seconds to be added.\n *\n * @returns The new date with the seconds added\n *\n * @example\n * // Add 30 seconds to 10 July 2014 12:45:00:\n * const result = addSeconds(new Date(2014, 6, 10, 12, 45, 0), 30)\n * //=> Thu Jul 10 2014 12:45:30\n */\nexport function addSeconds(date, amount) {\n return addMilliseconds(date, amount * 1000);\n}\n\n// Fallback for modularized imports:\nexport default addSeconds;","import { toDate } from \"./toDate.mjs\";\n\n/**\n * @name differenceInMilliseconds\n * @category Millisecond Helpers\n * @summary Get the number of milliseconds between the given dates.\n *\n * @description\n * Get the number of milliseconds between the given dates.\n *\n * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).\n *\n * @param dateLeft - The later date\n * @param dateRight - The earlier date\n *\n * @returns The number of milliseconds\n *\n * @example\n * // How many milliseconds are between\n * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?\n * const result = differenceInMilliseconds(\n * new Date(2014, 6, 2, 12, 30, 21, 700),\n * new Date(2014, 6, 2, 12, 30, 20, 600)\n * )\n * //=> 1100\n */\nexport function differenceInMilliseconds(dateLeft, dateRight) {\n return +toDate(dateLeft) - +toDate(dateRight);\n}\n\n// Fallback for modularized imports:\nexport default differenceInMilliseconds;","import { HttpClient, HttpResponse } from '@angular/common/http';\r\nimport { addDays, addSeconds, differenceInMilliseconds } from 'date-fns';\r\nimport { Observable, throwError } from 'rxjs';\r\nimport { environment } from 'src/environments/environment';\r\nimport { PromoCode, SubmitPaymentPlanDetails } from '../model';\r\nimport { CacheItem, CacheService } from './cache.service';\r\n\r\nexport class BaseDataService {\r\n\r\n constructor(protected httpClient: HttpClient, protected cache: CacheService) { }\r\n\r\n private secondsToWaitForPaymentToSubmit = 60;\r\n\r\n setPromoCodeContext(accountId: number | string, promoCode: PromoCode) {\r\n if (accountId) {\r\n const codes = this.cache.get(this.cache.items.promoCodes) || {};\r\n codes[accountId] = promoCode;\r\n this.cache.set(this.cache.items.promoCodes, codes);\r\n } else {\r\n this.cache.set(this.cache.items.promoCodes, null);\r\n }\r\n }\r\n\r\n setCustomBingEventsContext(page: string) {\r\n if (page) {\r\n const customBingEvents = this.cache.get(this.cache.items.customBingEvents) || {};\r\n customBingEvents[page] = true;\r\n this.cache.set(this.cache.items.customBingEvents, customBingEvents);\r\n } else {\r\n this.cache.set(this.cache.items.customBingEvents, null);\r\n }\r\n }\r\n\r\n public getWaitingForPaymentToSubmitTimeout(payment: string | SubmitPaymentPlanDetails): Promise {\r\n const ms = this.#getWaitingForPaymentToSubmitMilliseconds(payment);\r\n return new Promise(resolve => setTimeout(resolve, ms));\r\n }\r\n\r\n protected isWaitingForPaymentToSubmit(payment: string | SubmitPaymentPlanDetails): boolean {\r\n const ms = this.#getWaitingForPaymentToSubmitMilliseconds(payment);\r\n if (!ms) {\r\n const acctId = this.#getAcctIdFromPayment(payment);\r\n this.cache.lastPaymentSubmitTimes[acctId] = new Date();\r\n }\r\n return !!ms;\r\n }\r\n\r\n protected waitingForPaymentToSubmitMessage(): Observable {\r\n return throwError({ error: 'Waiting for Payment to Process. Please wait a few minutes and try again.'});\r\n }\r\n\r\n protected getData(cacheKey: string, url: string, options?, refresh: boolean = false, transform?: (value: HttpResponse) => T, cacheScopes?: string[]): Observable {\r\n return this.cacheData('GET', cacheKey, url, null, options, refresh, transform, cacheScopes);\r\n }\r\n\r\n protected postData(cacheKey: string, url: string, body: any, options, refresh: boolean = false, transform?: (value: HttpResponse) => T, cacheScopes?: string[]): Observable {\r\n return this.cacheData('POST', cacheKey, url, body, options, refresh, transform, cacheScopes);\r\n }\r\n\r\n protected cacheData(verb: string, cacheKey: string, url: string, body: any, options, refresh: boolean = false, transform?: (value: HttpResponse) => T, cacheScopes?: string[]): Observable {\r\n if (!url.startsWith('https://')) {\r\n url = `${environment.apiEndpoint}${url}`;\r\n }\r\n\r\n const opts = options || {};\r\n opts.observe = 'response';\r\n\r\n if (!transform) {\r\n transform = (res: HttpResponse) => res.body;\r\n }\r\n const trans = (res) => {\r\n value: res ? transform(res) : null,\r\n scopes: cacheScopes\r\n };\r\n\r\n const action = verb === 'GET' ? () => this.httpClient.get(url, opts) : () => this.httpClient.post(url, body, opts);\r\n\r\n return this.cache.getOrFetch(\r\n cacheKey,\r\n action,\r\n trans,\r\n refresh);\r\n }\r\n\r\n #getWaitingForPaymentToSubmitMilliseconds(payment: string | SubmitPaymentPlanDetails): number {\r\n const acctId = this.#getAcctIdFromPayment(payment);\r\n const lastTime = this.cache.lastPaymentSubmitTimes[acctId] || addDays(new Date(), -1);\r\n const nextAvailableTime = addSeconds(lastTime, this.secondsToWaitForPaymentToSubmit);\r\n const ms = differenceInMilliseconds(nextAvailableTime, new Date());\r\n return ms > 0 ? ms : 0;\r\n }\r\n\r\n #getAcctIdFromPayment(payment: string | SubmitPaymentPlanDetails): string {\r\n if (typeof payment === 'string') {\r\n return payment;\r\n }\r\n\r\n const acctId = payment.account?.acctId || payment['acctId'] || 0;\r\n if (!acctId && payment['payment']) {\r\n return payment['payment']['acctId'].toString();\r\n }\r\n\r\n return acctId.toString();\r\n }\r\n\r\n}\r\n"],"mappings":"qLAuBO,SAASA,EAAgBC,EAAMC,EAAQ,CAC5C,IAAMC,EAAY,CAACC,EAAOH,CAAI,EAC9B,OAAOI,EAAcJ,EAAME,EAAYD,CAAM,CAC/C,CCJO,SAASI,EAAWC,EAAMC,EAAQ,CACvC,OAAOC,EAAgBF,EAAMC,EAAS,GAAI,CAC5C,CCEO,SAASE,EAAyBC,EAAUC,EAAW,CAC5D,MAAO,CAACC,EAAOF,CAAQ,EAAI,CAACE,EAAOD,CAAS,CAC9C,CC3BA,IAAAE,EAAAC,EAAAC,EAAAC,EAMaC,EAAP,KAAsB,CAExBC,YAAsBC,EAAkCC,EAAmB,CA2E3EC,EAAA,KAAAR,GAQAQ,EAAA,KAAAN,GAnFsB,KAAAI,WAAAA,EAAkC,KAAAC,MAAAA,EAEhD,KAAAE,gCAAkC,EAFqC,CAI/EC,oBAAoBC,EAA4BC,EAAoB,CAChE,GAAID,EAAW,CACX,IAAME,EAAQ,KAAKN,MAAMO,IAAI,KAAKP,MAAMQ,MAAMC,UAAU,GAAK,CAAA,EAC7DH,EAAMF,CAAS,EAAIC,EACnB,KAAKL,MAAMU,IAAI,KAAKV,MAAMQ,MAAMC,WAAYH,CAAK,CACrD,MACI,KAAKN,MAAMU,IAAI,KAAKV,MAAMQ,MAAMC,WAAY,IAAI,CAExD,CAEAE,2BAA2BC,EAAY,CACnC,GAAIA,EAAM,CACN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KC,QAAU,WAEVV,IACDA,EAAaW,GAA8BA,EAAIP,MAEnD,IAAMQ,EAASD,IAAoB,CAC/BE,MAAOF,EAAMX,EAAUW,CAAG,EAAI,KAC9BG,OAAQb,IAGNc,EAASV,IAAS,MAAQ,IAAM,KAAKvC,WAAWQ,IAASuB,EAAKY,CAAI,EAAI,IAAM,KAAK3C,WAAWkD,KAAUnB,EAAKO,EAAMK,CAAI,EAE3H,OAAO,KAAK1C,MAAMkD,WACdrB,EACAmB,EACAH,EACAb,CAAO,CACf,GAEAvC,EAAA,YAAAC,EAAyCyD,SAACpC,EAA0C,CAChF,IAAMO,EAASL,EAAA,KAAKtB,EAAAC,GAAL,UAA2BmB,GACpCqC,EAAW,KAAKpD,MAAMuB,uBAAuBD,CAAM,GAAK+B,EAAQ,IAAI7B,KAAQ,EAAE,EAC9E8B,EAAoBC,EAAWH,EAAU,KAAKlD,+BAA+B,EAC7Ec,EAAKwC,EAAyBF,EAAmB,IAAI9B,IAAM,EACjE,OAAOR,EAAK,EAAIA,EAAK,CACzB,EAEArB,EAAA,YAAAC,EAAqB6D,SAAC1C,EAA0C,CA3FpE,IAAA2C,EA4FQ,GAAI,OAAO3C,GAAY,SACnB,OAAOA,EAGX,IAAMO,IAASP,EAAAA,EAAQ4C,UAAR5C,YAAAA,EAAiBO,SAAUP,EAAQ,QAAa,EAC/D,MAAI,CAACO,GAAUP,EAAQ,QACZA,EAAQ,QAAW,OAAU6C,SAAQ,EAGzCtC,EAAOsC,SAAQ,CAC1B","names":["addMilliseconds","date","amount","timestamp","toDate","constructFrom","addSeconds","date","amount","addMilliseconds","differenceInMilliseconds","dateLeft","dateRight","toDate","_getWaitingForPaymentToSubmitMilliseconds","getWaitingForPaymentToSubmitMilliseconds_fn","_getAcctIdFromPayment","getAcctIdFromPayment_fn","BaseDataService","constructor","httpClient","cache","__privateAdd","secondsToWaitForPaymentToSubmit","setPromoCodeContext","accountId","promoCode","codes","get","items","promoCodes","set","setCustomBingEventsContext","page","customBingEvents","getWaitingForPaymentToSubmitTimeout","payment","ms","__privateMethod","Promise","resolve","setTimeout","isWaitingForPaymentToSubmit","acctId","lastPaymentSubmitTimes","Date","waitingForPaymentToSubmitMessage","throwError","error","getData","cacheKey","url","options","refresh","transform","cacheScopes","cacheData","postData","body","verb","startsWith","environment","apiEndpoint","opts","observe","res","trans","value","scopes","action","post","getOrFetch","#getWaitingForPaymentToSubmitMilliseconds","lastTime","addDays","nextAvailableTime","addSeconds","differenceInMilliseconds","#getAcctIdFromPayment","_a","account","toString"],"x_google_ignoreList":[0,1,2]}