@dintero/discounts-web-sdk 0.2.5 → 0.2.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"dintero-discounts-web-sdk.umd.min.js","sources":["../src/dom.ts","../src/translations.ts","../src/formatters.ts","../src/normalize.ts","../src/discounts.ts","../src/fetch.ts","../src/error.ts","../src/loading.ts","../src/index.ts"],"sourcesContent":["import { Theme } from './types';\n\ntype CreateElementOptions ={\n tag: string,\n attributes?: {[key: string]: any};\n styles?:((className:string, theme?: Theme) => string)[];\n handlers?:{[key: string]: EventListenerOrEventListenerObject};\n innerHTML?: string;\n theme?: Theme,\n}\n\nexport const createElement = (options: CreateElementOptions) => {\n const elem = document.createElement(options.tag);\n if (options.attributes) {\n addAttributes(elem, options.attributes)\n }\n if (options.handlers) {\n addEventListeners(elem, options.handlers)\n }\n if(options.styles){\n addStyles(elem, options.styles, options.theme);\n }\n if(options.innerHTML){\n elem.innerHTML = options.innerHTML;\n }\n return elem;\n};\n\nconst addClass = (elem:HTMLElement, className:string) => {\n const names = elem.className.split(\" \");\n if (!names.includes(className)) {\n elem.className = elem.className + \" \" + className;\n }\n};\n\nconst hash = (input: string) => {\n let hash = 0;\n for (var i = 0; i < input.length; i++) {\n var char = input.charCodeAt(i);\n hash = ((hash<<5)-hash)+char;\n hash = hash & hash;\n }\n return hash.toString(36);\n}\n\nconst addStyles = (elem: HTMLElement , styles: ((className:string, theme?: Theme) => string)[], theme: Theme | undefined) => {\n // \"styled components\" light\n styles.forEach((cssFn)=> {\n // get class name from hash\n const className = 'dintero-deals-' + hash(cssFn('dintero-deals', theme));\n addClass(elem, className);\n // add style tag to DOM if not exists\n const hit = document.querySelector(`[data-css-hash=${className}]`);\n if (!hit) {\n const style = document.createElement('style')\n style.innerHTML = cssFn(className, theme);\n style.setAttribute('data-css-hash', className);\n document.head.appendChild(style);\n }\n });\n};\n\nconst addAttributes = (elem:HTMLElement , attributes: {[key: string]: string}) => {\n Object.keys(attributes).forEach((key) => {\n elem.setAttribute(key, attributes[key]);\n });\n};\n\nconst addEventListeners = (elem:HTMLElement , handlers: {[key: string]: EventListenerOrEventListenerObject}) => {\n Object.keys(handlers).forEach((key) => {\n elem.addEventListener(key, handlers[key]);\n });\n};\n\n\n","const no = {\n rewards: {\n discount_item_quantity: {\n three_for_two: '3 for 2',\n generic: \"Kjøp {{require}} betal for {{payFor}}\"\n },\n discount_amount: \"{{monetaryAmount}} rabatt\",\n },\n limitations: {\n discount_reward_usage: \"Antall: <strong>{{discount_reward_usage}}</strong>\",\n discount_repeat_usage: \"Maks kjøp: <strong>{{discount_repeat_usage}}</strong>\"\n },\n requirements: {\n purchase_from: \"Tilbudet starter <strong>{{purchase_from}}</strong>\",\n purchase_to: \"Tilbudet utgår <strong>{{purchase_to}}</strong>\"\n },\n errors: {\n fetch: \"⚠️ <br/>En feil oppstod under lasting av tilbud...\"\n }\n} \n\nexport const translations ={\n no\n}\n\nconst findValuesRegex = /(\\{\\{)[^}]*(\\}\\})/g;\n// i18n light\nexport const t = (translateString: string, values?: {[key:string]: any}):string => {\n const matches: string[] = translateString.match(findValuesRegex) || [];\n const _values = values || {};\n return matches.reduce<string>((interpolated, match) => {\n const key = match.replace('{{', '').replace('}}', '');\n const value = _values[key] || '';\n return interpolated.replace(match, value);\n }, translateString);\n}\n\n\n","import { Configuration } from './types';\n\nexport const monetaryString = (amount:number, configuration: Configuration, options?: {\n decimal?: boolean,\n currency?: boolean,\n variant?: 'short'\n}) =>{\n const opt = options || {};\n const amountString = amount.toString();\n const dotIndex = amountString.length - configuration.currency.exponent;\n const beforeDot = amountString.slice(0, dotIndex) || '0';\n const afterDot = amountString.slice(dotIndex);\n const exponentAmount = (afterDot == \"00\" && !opt.decimal) ? beforeDot : beforeDot + '.' + afterDot;\n if(opt.variant === 'short' && afterDot === '00'){\n return beforeDot + ',-';\n }\n if(!opt.currency){\n return exponentAmount;\n }\n if(configuration.currency.position === 'prefix'){\n return configuration.currency.value + ' ' + exponentAmount\n }\n return exponentAmount + ' ' + configuration.currency.value; \n}\n\nconst padZero = (value:number) =>{\n if( value< 10){\n return `0${value}`;\n }\n return value.toString();\n}\n\nexport const dateString = (isoString: string, configuration: Configuration) => {\n try{\n const date = new Date(isoString);\n if(configuration.language === 'no'){\n const dd = padZero(date.getDate());\n const mm = padZero(date.getMonth() + 1);\n const yyyy = date.getFullYear();\n return [dd,mm,yyyy].join('.');\n }\n return new Intl.DateTimeFormat().format(date)\n } catch(e) {\n return isoString.substr(0, 10);\n }\n}\n","export const normalize = (className: string) => `\n.${className} {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n outline: none;\n border: none;\n box-shadow: none;\n line-height: auto;\n background: transparent;\n opacity: 1;\n border-radius: 0;\n display: block;\n position: relative;\n font-weight: normal;\n}\n`;\n","import { createElement } from \"./dom\";\nimport { Discount, Configuration, Theme } from \"./types\";\nimport { translations, t } from \"./translations\";\nimport { monetaryString, dateString } from \"./formatters\";\nimport { normalize } from \"./normalize\";\n\nexport const findWebshopLink = (discount: Discount) => discount.links && discount.links.find(x => x.rel && x.rel === 'webshop');\n\nconst discountStyle = (className: string, theme: Theme) => `\n@keyframes appear {\n from {\n transform: scaleY(0%);\n height: 0;\n opacity: 0;\n }\n \n to {\n transform: scaleY(100%);\n height: auto;\n opacity: 1;\n }\n }\n.${className} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: ${theme.borderRadius};\n text-align: center;\n padding-top: 5px;\n padding-bottom: 105px;\n padding-left: 5px;\n padding-right: 5px;\n max-width: 300px;\n width: 250px;\n font-size: 1em;\n margin: 5px 20px;\n background: ${theme.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n color: inherit;\n text-decoration: none;\n}\n\n@media screen and (max-width: 679px) {\n .${className} {\n width: 100%;\n max-width: 100%;\n } \n }\n`;\n\nconst imageWrapperStyles = (className: string) => `\n.${className} {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 300px;\n width: 100%,\n}`;\n\nconst imageStyle = (className: string) => `\n.${className} {\n max-width: 100%;\n max-height: 100%;\n text-align: center;\n display: inline-block;\n}`;\n\nconst ribbonTopStyle = (className: string, theme?: Theme) => `\n.${className} {\n position: absolute;\n bottom: 60px;\n left: -20px;\n color: #fff;\n z-index: 9;\n width: 80%;\n font-size: 1.3em;\n border-radius: 0 ${theme.borderRadius} ${theme.borderRadius} 0;\n padding: 5px 0;\n background: ${theme?.secondary};\n}\n.${className}:after {\n position: absolute;\n content: \"\";\n bottom: -10px;\n left: 0;\n border-color: transparent;\n border-style: solid;\n border-width: 0 20px 10px 0;\n border-right-color: ${theme.secondary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`;\n\nconst ribbonBottomStyle = (className: string, theme?: Theme) => `\n.${className} {\n position: absolute;\n right: -20px;\n bottom: 15px;\n color: #fff;\n z-index: 9;\n width: 80%;\n font-size: 1.3em;\n border-radius: ${theme.borderRadius} 0 0 ${theme.borderRadius};\n padding: 5px 0;\n background: ${theme?.primary};\n}\n.${className}:after {\n position: absolute;\n content: \"\";\n right: 0;\n bottom: -10px;\n border-color: transparent;\n border-style: solid;\n border-width: 10px 20px 0 0;\n border-top-color: ${theme.primary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`;\n\nconst titleStyle = (className: string) => `\n.${className} {\n margin-bottom: 0;\n font-size: 1em;\n margin-bottom: 2px;\n font-size: 1.3em;\n font-weight: 700;\n}`;\n\nconst subtitleStyle = (className: string) => `\n.${className} {\n margin-top: 0;\n}`;\n\nconst limitationsWrapperStyle = (className: string) => `\n.${className} {\n font-size: 0.75em;\n}\n.${className} > span{\n display: block;\n}\n`;\n\n\nconst getTopRibbonText = (discount: Discount) => {\n return (\n (discount && discount.metadata && discount.metadata.label) || undefined\n );\n};\n\nconst createTopRibbon = (discount: Discount, configuration: Configuration) => {\n const text = getTopRibbonText(discount);\n return (\n text &&\n createElement({\n tag: \"div\",\n innerHTML: text,\n theme: configuration.theme,\n styles: [ribbonTopStyle],\n })\n );\n};\n\nconst getBottomRibbonText = (\n discount: Discount,\n configuration: Configuration\n) => {\n const tStrings = translations[configuration.language];\n if (discount.reward.type === \"discount_item_new_price\") {\n return monetaryString(discount.reward.value, configuration, {\n variant: \"short\",\n });\n } else if (discount.reward.type === \"discount_percent\") {\n return discount.reward.value + \"%\";\n } else if (discount.reward.type === \"discount_item_quantity\") {\n if (\n discount.requirement.item.quantity === 3 &&\n discount.reward.value === 1\n ) {\n // Show custom 3 for 2 message\n return tStrings.rewards.discount_item_quantity.three_for_two;\n } else {\n const require = discount.requirement.item.quantity;\n const payFor =\n discount.requirement.item.quantity - discount.reward.value;\n return t(tStrings.rewards.discount_item_quantity.generic, {\n require,\n payFor,\n });\n }\n } else if (discount.reward.type === \"discount_amount\") {\n const monetaryAmount = monetaryString(\n discount.reward.value,\n configuration,\n { decimal: false }\n );\n return t(tStrings.rewards.discount_amount, { monetaryAmount });\n } else if (discount.reward.type === \"discount_item_percent\") {\n return discount.reward.value + \"%\";\n }\n return \"\";\n};\n\nconst createBottomRibbon = (\n discount: Discount,\n configuration: Configuration\n) => {\n const text = getBottomRibbonText(discount, configuration);\n return (\n text &&\n createElement({\n tag: \"div\",\n innerHTML: text,\n theme: configuration.theme,\n styles: [ribbonBottomStyle],\n })\n );\n};\n\nconst createImage = (discount: Discount) => {\n const imageWrapper = createElement({\n tag: \"div\",\n styles: [normalize, imageWrapperStyles],\n });\n const imageSrc = discount.links.find((link) => [\n \"medium_discount_image\",\n \"thumbnail_discount_image\".includes(link.rel),\n ]);\n const image =\n imageSrc &&\n createElement({\n tag: \"img\",\n attributes: { src: imageSrc.href, alt: discount.name, loading: \"lazy\"},\n styles: [normalize, imageStyle],\n });\n if (image) {\n imageWrapper.appendChild(image);\n }\n return imageWrapper;\n};\n\nconst createLimitations = (\n discount: Discount,\n configuration: Configuration\n) => {\n const tStrings = translations[configuration.language];\n\n const wrapper = createElement({\n tag: \"small\",\n styles: [normalize, limitationsWrapperStyle],\n });\n\n const quantity =\n discount.limitation.discount_reward_usage &&\n discount.limitation.discount_reward_usage !== -1 &&\n createElement({\n tag: \"span\",\n innerHTML: t(tStrings.limitations.discount_reward_usage, {\n discount_reward_usage: discount.limitation.discount_reward_usage,\n }),\n });\n const repeat =\n discount.limitation.discount_repeat_usage &&\n discount.limitation.discount_repeat_usage !== -1 &&\n createElement({\n tag: \"span\",\n innerHTML: t(tStrings.limitations.discount_repeat_usage, {\n discount_repeat_usage: discount.limitation.discount_repeat_usage,\n }),\n });\n\n const startDate = new Date(discount.requirement.purchase_from || 0);\n const start = startDate > new Date() && createElement({\n tag: \"span\",\n innerHTML: t(tStrings.requirements.purchase_from, {\n purchase_from: dateString(discount.requirement.purchase_from, configuration),\n }),\n });\n const endDate = new Date(discount.requirement.purchase_to || 0);\n const end = endDate > new Date() && createElement({\n tag: \"span\",\n innerHTML: t(tStrings.requirements.purchase_to, {\n purchase_to: dateString(discount.requirement.purchase_to, configuration),\n }),\n });\n const children = [\n quantity,\n repeat,\n start,\n end\n ].filter((child) => child);\n children.forEach((child) => wrapper.appendChild(child));\n return wrapper;\n};\n\nexport const createDiscount = (\n discount: Discount,\n configuration: Configuration\n): HTMLElement => {\n const discountElem = createElement({\n tag: findWebshopLink(discount) ? \"a\" : \"div\",\n styles: [normalize, discountStyle],\n theme: configuration.theme\n });\n const ribbonTop = createTopRibbon(discount, configuration);\n const ribbonBottom = createBottomRibbon(discount, configuration);\n const image = createImage(discount);\n const title =\n discount?.name &&\n createElement({ tag: \"h4\", innerHTML: discount.name , styles:[titleStyle]});\n const subtitle =\n discount?.metadata?.subtitle &&\n createElement({ tag: \"p\", innerHTML: discount.metadata.subtitle, styles: [subtitleStyle] });\n const description =\n discount.description &&\n createElement({ tag: \"p\", innerHTML: discount.description });\n\n const limitations = createLimitations(discount, configuration);\n // add children to discount wrapper\n const children = [\n ribbonTop,\n ribbonBottom,\n image,\n title,\n subtitle,\n description,\n limitations\n ].filter((child) => child);\n children.forEach((child) => discountElem.appendChild(child));\n return discountElem;\n};\n","import { Configuration, Discount, TokenResponse } from \"./types\";\n\nconst createHeaders = (\n keyValues: { [key: string]: string },\n configuration: Configuration\n) => {\n const headers: HeadersInit = new Headers();\n Object.entries({\n ...keyValues,\n \"Dintero-System-Name\": \"deals-web-sdk\",\n \"Dintero-System-Version\": configuration.version,\n }).forEach(([key, value]) => {\n headers.append(key, value);\n });\n return headers;\n};\n\nconst fetchAccessToken = (\n configuration: Configuration\n): Promise<TokenResponse> => {\n if (!configuration.api) {\n throw new Error(\"Authentication configuration missing\");\n }\n const basicAuthCredentials = window.btoa(\n `${configuration.api.key}:${configuration.api.secret}`\n );\n const headers = createHeaders(\n {\n Authorization: `Basic ${basicAuthCredentials}`,\n \"content-type\": \"application/json\",\n },\n configuration\n );\n const body = JSON.stringify({\n grant_type: \"client_credentials\",\n audience: `${configuration.api.url}/v1/accounts/${configuration.api.account}`,\n });\n return window\n .fetch(\n `${configuration.api.url}/v1/accounts/${configuration.api.account}/auth/token`,\n {\n method: \"POST\",\n headers,\n body,\n }\n )\n .then((response) => {\n if (response.status === 200) {\n return response.json() as Promise<TokenResponse>;\n }\n throw new Error(\"Authentication failed\");\n });\n};\n\nexport const fetchDiscounts = (\n configuration: Configuration\n): Promise<Discount[]> => {\n return fetchAccessToken(configuration).then((tokenResponse) => {\n const headers = createHeaders(\n {\n Authorization: `${tokenResponse.token_type} ${tokenResponse.access_token}`,\n },\n configuration\n );\n \n if (configuration.api.discountId) {\n return window\n .fetch(\n `${configuration.api.url}/v1/accounts/${configuration.api.account}/discounts/public/rules/${configuration.api.discountId}`,\n {\n headers,\n }\n )\n .then((response) => {\n if (response.status === 200) {\n return response\n .json()\n .then((discount) => [discount]) as Promise<\n Discount[]\n >;\n }\n throw new Error(\"Authentication failed\");\n });\n }\n\n return window\n .fetch(\n `${configuration.api.url}/v1/accounts/${configuration.api.account}/discounts/public/rules?limit=${configuration.api.limit}`,\n {\n headers,\n }\n )\n .then((response) => {\n if (response.status === 200) {\n return response.json() as Promise<Discount[]>;\n }\n throw new Error(\"Authentication failed\");\n });\n });\n};\n","import { createElement } from \"./dom\";\nimport { Configuration, Theme } from \"./types\";\nimport { translations } from \"./translations\";\nimport { normalize } from \"./normalize\";\n\nconst errorStyle = (className: string, theme: Theme) => `\n@keyframes appear {\n from {\n transform: scaleY(0%);\n height: 0;\n opacity: 0;\n }\n \n to {\n transform: scaleY(100%);\n height: auto;\n opacity: 1;\n }\n }\n.${className} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: 3px;\n text-align: center;\n padding-top: 65px;\n padding-bottom: 70px;\n padding-left: 5px;\n padding-right: 5px;\n max-width: 300px;\n width: 250px;\n font-size: 14px;\n margin: 5px auto;\n background: ${theme.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n}\n`;\n\n\nexport const createError = (\n configuration: Configuration\n): HTMLElement => {\n const tString = translations[configuration.language];\n const errorElem = createElement({\n tag: \"div\",\n styles: [normalize, errorStyle],\n theme: configuration.theme,\n innerHTML: tString.errors.fetch\n });\n \n return errorElem;\n};\n","import { createElement } from \"./dom\";\nimport { Configuration, Theme } from \"./types\";\nimport { normalize } from \"./normalize\";\n\nconst loadingStyle = (className: string, theme: Theme) => `\n.${className} {\n margin: 10px auto;\n display: block;\n width: 80px;\n height: 80px;\n}\n\n.${className}:after {\n content: \" \";\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #000;\n border-color: rgba(0,0,0,0.2) transparent rgba(0,0,0,0.2) transparent;\n animation: loading 0.6s linear infinite;\n}\n\n@keyframes loading {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n`;\n\nexport const createLoading = (configuration: Configuration): HTMLElement => {\n const errorElem = createElement({\n tag: \"div\",\n styles: [normalize, loadingStyle],\n theme: configuration.theme,\n });\n\n return errorElem;\n};\n","import { createDiscount, findWebshopLink } from \"./discounts\";\nimport { Discount, Configuration, Theme, Embed } from \"./types\";\nimport { createElement } from \"./dom\";\nimport { fetchDiscounts } from \"./fetch\";\nimport { createError } from \"./error\";\nimport { createLoading } from \"./loading\";\nimport { normalize } from \"./normalize\";\nimport pkg from \"../package.json\";\n\n\n\nconst defaultConfig:Partial<Configuration> = {\n language: 'no',\n version: pkg?.version || \"SNAPSHOT\",\n linkTarget: '_self',\n currency: {\n value: 'Kr',\n position: 'suffix',\n exponent: 2\n },\n theme: {\n background: \"#fff\",\n primary: \"#333\",\n secondary: \"#333\",\n color: \"inherit\",\n borderRadius: \"2px\",\n fontSize: \"inherit\",\n },\n api: {\n account: \"\",\n key: \"\",\n secret: \"\",\n url: \"https://api.dintero.com\",\n limit: 50,\n },\n}\n\nconst mergeConfig = (a:Partial<Configuration>, b:Configuration): Configuration =>{\n return {\n ...a,\n ...b,\n currency:{\n ...a.currency,\n ...b.currency,\n },\n theme: {\n ...a.theme,\n ...b.theme\n },\n api:{\n ...a.api,\n ...b.api\n }\n }\n}\n\nconst wrapperStyles = (className: string, theme:Theme) => `\n.${className} {\n display: flex;\n flex-flow: wrap;\n align-items: stretch;\n justify-content: center;\n position: relative;\n font-weight: normal;\n width: 100%;\n font-size: ${theme.fontSize};\n color: ${theme.color};\n}`;\n\nexport const embed = async (configuration: Configuration):Promise<Embed> => {\n\n const _configuration = mergeConfig(defaultConfig, configuration);\n if(!_configuration.container ||!_configuration.container.appendChild){\n console.error(\"Invalid configuration\");\n throw new Error(\"Invalid configuration\");\n }\n if (_configuration.discounts) {\n return renderDeals(_configuration, _configuration.discounts);\n } else {\n\n const loader = createLoading(_configuration);\n try{\n configuration.container.appendChild(loader);\n const discounts = await fetchDiscounts(_configuration);\n _configuration.container.removeChild(loader);\n return renderDeals(_configuration, discounts);\n } catch(error) {\n configuration.container.removeChild(loader);\n const errorMessage = createError(_configuration);\n _configuration.container.appendChild(errorMessage);\n return {\n destroy: () => {\n configuration.container.removeChild(errorMessage);\n }\n }\n }\n }\n};\n\nconst renderDeals = (configuration: Configuration, discounts: Discount[]):Embed => {\n const wrapper = createElement({ tag: \"div\", styles: [normalize, wrapperStyles], theme: configuration.theme });\n discounts.forEach((discount) => {\n const elem = createDiscount(discount, configuration);\n const webShopLink = findWebshopLink(discount);\n if (webShopLink) {\n elem.setAttribute('target', configuration?.linkTarget || '_self');\n elem.setAttribute('href', webShopLink.href);\n }\n wrapper.appendChild(elem);\n });\n configuration.container.appendChild(wrapper);\n return {\n destroy: () => {\n configuration.container.removeChild(wrapper);\n }\n }\n};\n"],"names":["createElement","options","elem","document","tag","attributes","addAttributes","handlers","addEventListeners","styles","addStyles","theme","innerHTML","forEach","cssFn","className","input","hash","i","length","charCodeAt","toString","addClass","split","includes","querySelector","style","setAttribute","head","appendChild","Object","keys","key","addEventListener","translations","no","rewards","discount_item_quantity","three_for_two","generic","discount_amount","limitations","discount_reward_usage","discount_repeat_usage","requirements","purchase_from","purchase_to","errors","fetch","findValuesRegex","t","translateString","values","matches","match","_values","reduce","interpolated","replace","value","monetaryString","amount","configuration","opt","amountString","dotIndex","currency","exponent","beforeDot","slice","afterDot","exponentAmount","decimal","variant","position","padZero","dateString","isoString","date","Date","language","dd","getDate","mm","getMonth","getFullYear","join","Intl","DateTimeFormat","format","e","substr","normalize","findWebshopLink","discount","links","find","x","rel","discountStyle","borderRadius","background","imageWrapperStyles","imageStyle","ribbonTopStyle","secondary","ribbonBottomStyle","primary","titleStyle","subtitleStyle","limitationsWrapperStyle","createBottomRibbon","text","getBottomRibbonText","tStrings","reward","type","requirement","item","quantity","require","payFor","monetaryAmount","createDiscount","discountElem","ribbonTop","createTopRibbon","metadata","label","undefined","getTopRibbonText","ribbonBottom","image","imageWrapper","imageSrc","link","src","href","alt","name","loading","createImage","title","subtitle","description","createLimitations","wrapper","limitation","filter","child","createHeaders","keyValues","headers","Headers","entries","version","append","fetchDiscounts","api","Error","basicAuthCredentials","window","btoa","secret","Authorization","body","JSON","stringify","grant_type","audience","url","account","method","then","response","status","json","fetchAccessToken","tokenResponse","token_type","access_token","discountId","limit","errorStyle","loadingStyle","defaultConfig","linkTarget","color","fontSize","wrapperStyles","renderDeals","discounts","webShopLink","container","destroy","removeChild","async","_configuration","a","b","mergeConfig","console","error","loader","createLoading","errorMessage","tString","createError"],"mappings":"iPAWO,MAAMA,EAAiBC,IAC1B,MAAMC,EAAOC,SAASH,cAAcC,EAAQG,KAa5C,OAZIH,EAAQI,YACRC,EAAcJ,EAAMD,EAAQI,YAE5BJ,EAAQM,UACRC,EAAkBN,EAAMD,EAAQM,UAEjCN,EAAQQ,QACPC,EAAUR,EAAMD,EAAQQ,OAAQR,EAAQU,OAEzCV,EAAQW,YACPV,EAAKU,UAAYX,EAAQW,WAEtBV,CAAI,EAoBTQ,EAAYA,CAACR,EAAoBO,EAAyDE,KAE5FF,EAAOI,SAASC,IAEZ,MAAMC,EAAY,iBAdZC,KACV,IAAIC,EAAO,EACX,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAMG,OAAQD,IAE9BD,GAASA,GAAM,GAAGA,EADPD,EAAMI,WAAWF,GAE5BD,GAAcA,EAElB,OAAOA,EAAKI,SAAS,GAAG,EAOiBJ,CAAKH,EAAM,gBAAiBH,IArBxDW,EAACpB,EAAkBa,KAClBb,EAAKa,UAAUQ,MAAM,KACxBC,SAAST,KAChBb,EAAKa,UAAYb,EAAKa,UAAY,IAAMA,EAC5C,EAkBIO,CAASpB,EAAMa,GAGf,IADYZ,SAASsB,cAAe,kBAAiBV,MAC3C,CACN,MAAMW,EAAQvB,SAASH,cAAc,SACrC0B,EAAMd,UAAYE,EAAMC,EAAWJ,GACnCe,EAAMC,aAAa,gBAAiBZ,GACpCZ,SAASyB,KAAKC,YAAYH,EAC9B,IACF,EAGApB,EAAgBA,CAACJ,EAAmBG,KACtCyB,OA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c,CAC5BI,IAAK,MACLK,OAAQ,CAACmF,EAAW2F,GACpB5K,MAAOmD,EAAcnD,MACrBC,UAAWkM,EAAQ/J,OAAOC,OAGd,EEqCa+J,CAAYV,GAEjC,OADAA,EAAeJ,UAAUpK,YAAYgL,GAC9B,CACHX,QAASA,KACLpI,EAAcmI,UAAUE,YAAYU,EAAa,EAG7D,CACJ"}
1
+ {"version":3,"file":"dintero-discounts-web-sdk.umd.min.js","sources":["../src/dom.ts","../src/translations.ts","../src/formatters.ts","../src/normalize.ts","../src/discounts.ts","../src/fetch.ts","../src/error.ts","../src/loading.ts","../src/index.ts"],"sourcesContent":["import { Theme } from \"./types\";\n\ntype CreateElementOptions = {\n tag: string;\n attributes?: { [key: string]: any };\n styles?: ((className: string, theme?: Theme) => string)[];\n handlers?: { [key: string]: EventListenerOrEventListenerObject };\n innerHTML?: string;\n theme?: Theme;\n};\n\nexport const createElement = (options: CreateElementOptions) => {\n const elem = document.createElement(options.tag);\n if (options.attributes) {\n addAttributes(elem, options.attributes);\n }\n if (options.handlers) {\n addEventListeners(elem, options.handlers);\n }\n if (options.styles) {\n addStyles(elem, options.styles, options.theme);\n }\n if (options.innerHTML) {\n elem.innerHTML = options.innerHTML;\n }\n return elem;\n};\n\nconst addClass = (elem: HTMLElement, className: string) => {\n const names = elem.className.split(\" \");\n if (!names.includes(className)) {\n elem.className = elem.className + \" \" + className;\n }\n};\n\nconst hash = (input: string) => {\n let hash = 0;\n for (var i = 0; i < input.length; i++) {\n var char = input.charCodeAt(i);\n hash = (hash << 5) - hash + char;\n hash = hash & hash;\n }\n return hash.toString(36);\n};\n\nconst addStyles = (\n elem: HTMLElement,\n styles: ((className: string, theme?: Theme) => string)[],\n theme: Theme | undefined,\n) => {\n // \"styled components\" light\n styles.forEach((cssFn) => {\n // get class name from hash\n const className =\n \"dintero-deals-\" + hash(cssFn(\"dintero-deals\", theme));\n addClass(elem, className);\n // add style tag to DOM if not exists\n const hit = document.querySelector(`[data-css-hash=${className}]`);\n if (!hit) {\n const style = document.createElement(\"style\");\n style.innerHTML = cssFn(className, theme);\n style.setAttribute(\"data-css-hash\", className);\n document.head.appendChild(style);\n }\n });\n};\n\nconst addAttributes = (\n elem: HTMLElement,\n attributes: { [key: string]: string },\n) => {\n Object.keys(attributes).forEach((key) => {\n elem.setAttribute(key, attributes[key]);\n });\n};\n\nconst addEventListeners = (\n elem: HTMLElement,\n handlers: { [key: string]: EventListenerOrEventListenerObject },\n) => {\n Object.keys(handlers).forEach((key) => {\n elem.addEventListener(key, handlers[key]);\n });\n};\n","const no = {\n rewards: {\n discount_item_quantity: {\n three_for_two: \"3 for 2\",\n generic: \"Kjøp {{require}} betal for {{payFor}}\",\n },\n discount_amount: \"{{monetaryAmount}} rabatt\",\n },\n limitations: {\n discount_reward_usage:\n \"Antall: <strong>{{discount_reward_usage}}</strong>\",\n discount_repeat_usage:\n \"Maks kjøp: <strong>{{discount_repeat_usage}}</strong>\",\n },\n requirements: {\n purchase_from: \"Tilbudet starter <strong>{{purchase_from}}</strong>\",\n purchase_to: \"Tilbudet utgår <strong>{{purchase_to}}</strong>\",\n },\n errors: {\n fetch: \"⚠️ <br/>En feil oppstod under lasting av tilbud...\",\n },\n};\n\nexport const translations = {\n no,\n};\n\nconst findValuesRegex = /(\\{\\{)[^}]*(\\}\\})/g;\n// i18n light\nexport const t = (\n translateString: string,\n values?: { [key: string]: any },\n): string => {\n const matches: string[] = translateString.match(findValuesRegex) || [];\n const _values = values || {};\n return matches.reduce<string>((interpolated, match) => {\n const key = match.replace(\"{{\", \"\").replace(\"}}\", \"\");\n const value = _values[key] || \"\";\n return interpolated.replace(match, value);\n }, translateString);\n};\n","import { Configuration } from \"./types\";\n\nexport const monetaryString = (\n amount: number,\n configuration: Configuration,\n options?: {\n decimal?: boolean;\n currency?: boolean;\n variant?: \"short\";\n },\n) => {\n const opt = options || {};\n const amountString = amount.toString();\n const dotIndex = amountString.length - configuration.currency.exponent;\n const beforeDot = amountString.slice(0, dotIndex) || \"0\";\n const afterDot = amountString.slice(dotIndex);\n const exponentAmount =\n afterDot == \"00\" && !opt.decimal\n ? beforeDot\n : beforeDot + \".\" + afterDot;\n if (opt.variant === \"short\" && afterDot === \"00\") {\n return beforeDot + \",-\";\n }\n if (!opt.currency) {\n return exponentAmount;\n }\n if (configuration.currency.position === \"prefix\") {\n return configuration.currency.value + \" \" + exponentAmount;\n }\n return exponentAmount + \" \" + configuration.currency.value;\n};\n\nconst padZero = (value: number) => {\n if (value < 10) {\n return `0${value}`;\n }\n return value.toString();\n};\n\nexport const dateString = (isoString: string, configuration: Configuration) => {\n try {\n const date = new Date(isoString);\n if (configuration.language === \"no\") {\n const dd = padZero(date.getDate());\n const mm = padZero(date.getMonth() + 1);\n const yyyy = date.getFullYear();\n return [dd, mm, yyyy].join(\".\");\n }\n return new Intl.DateTimeFormat().format(date);\n } catch (e) {\n return isoString.substr(0, 10);\n }\n};\n","export const normalize = (className: string) => `\n.${className} {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n outline: none;\n border: none;\n box-shadow: none;\n line-height: auto;\n background: transparent;\n opacity: 1;\n border-radius: 0;\n display: block;\n position: relative;\n font-weight: normal;\n}\n`;\n","import { createElement } from \"./dom\";\nimport { Discount, Configuration, Theme } from \"./types\";\nimport { translations, t } from \"./translations\";\nimport { monetaryString, dateString } from \"./formatters\";\nimport { normalize } from \"./normalize\";\n\nexport const findWebshopLink = (discount: Discount) =>\n discount.links && discount.links.find((x) => x.rel && x.rel === \"webshop\");\n\nconst discountStyle = (className: string, theme: Theme) => `\n@keyframes appear {\n from {\n transform: scaleY(0%);\n height: 0;\n opacity: 0;\n }\n \n to {\n transform: scaleY(100%);\n height: auto;\n opacity: 1;\n }\n }\n.${className} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: ${theme.borderRadius};\n text-align: center;\n padding-top: 5px;\n padding-bottom: 105px;\n padding-left: 5px;\n padding-right: 5px;\n max-width: 300px;\n width: 250px;\n font-size: 1em;\n margin: 5px 20px;\n background: ${theme.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n color: inherit;\n text-decoration: none;\n}\n\n@media screen and (max-width: 679px) {\n .${className} {\n width: 100%;\n max-width: 100%;\n } \n }\n`;\n\nconst imageWrapperStyles = (className: string) => `\n.${className} {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 300px;\n width: 100%,\n}`;\n\nconst imageStyle = (className: string) => `\n.${className} {\n max-width: 100%;\n max-height: 100%;\n text-align: center;\n display: inline-block;\n}`;\n\nconst ribbonTopStyle = (className: string, theme?: Theme) => `\n.${className} {\n position: absolute;\n bottom: 60px;\n left: -20px;\n color: #fff;\n z-index: 9;\n width: 80%;\n font-size: 1.3em;\n border-radius: 0 ${theme.borderRadius} ${theme.borderRadius} 0;\n padding: 5px 0;\n background: ${theme?.secondary};\n}\n.${className}:after {\n position: absolute;\n content: \"\";\n bottom: -10px;\n left: 0;\n border-color: transparent;\n border-style: solid;\n border-width: 0 20px 10px 0;\n border-right-color: ${theme.secondary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`;\n\nconst ribbonBottomStyle = (className: string, theme?: Theme) => `\n.${className} {\n position: absolute;\n right: -20px;\n bottom: 15px;\n color: #fff;\n z-index: 9;\n width: 80%;\n font-size: 1.3em;\n border-radius: ${theme.borderRadius} 0 0 ${theme.borderRadius};\n padding: 5px 0;\n background: ${theme?.primary};\n}\n.${className}:after {\n position: absolute;\n content: \"\";\n right: 0;\n bottom: -10px;\n border-color: transparent;\n border-style: solid;\n border-width: 10px 20px 0 0;\n border-top-color: ${theme.primary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`;\n\nconst titleStyle = (className: string) => `\n.${className} {\n margin-bottom: 0;\n font-size: 1em;\n margin-bottom: 2px;\n font-size: 1.3em;\n font-weight: 700;\n}`;\n\nconst subtitleStyle = (className: string) => `\n.${className} {\n margin-top: 0;\n}`;\n\nconst limitationsWrapperStyle = (className: string) => `\n.${className} {\n font-size: 0.75em;\n}\n.${className} > span{\n display: block;\n}\n`;\n\nconst getTopRibbonText = (discount: Discount) => {\n return (\n (discount && discount.metadata && discount.metadata.label) || undefined\n );\n};\n\nconst createTopRibbon = (discount: Discount, configuration: Configuration) => {\n const text = getTopRibbonText(discount);\n return (\n text &&\n createElement({\n tag: \"div\",\n innerHTML: text,\n theme: configuration.theme,\n styles: [ribbonTopStyle],\n })\n );\n};\n\nconst getBottomRibbonText = (\n discount: Discount,\n configuration: Configuration,\n) => {\n const tStrings = translations[configuration.language];\n if (discount.reward.type === \"discount_item_new_price\") {\n return monetaryString(discount.reward.value, configuration, {\n variant: \"short\",\n });\n } else if (discount.reward.type === \"discount_percent\") {\n return discount.reward.value + \"%\";\n } else if (discount.reward.type === \"discount_item_quantity\") {\n if (\n discount.requirement.item.quantity === 3 &&\n discount.reward.value === 1\n ) {\n // Show custom 3 for 2 message\n return tStrings.rewards.discount_item_quantity.three_for_two;\n } else {\n const require = discount.requirement.item.quantity;\n const payFor =\n discount.requirement.item.quantity - discount.reward.value;\n return t(tStrings.rewards.discount_item_quantity.generic, {\n require,\n payFor,\n });\n }\n } else if (discount.reward.type === \"discount_amount\") {\n const monetaryAmount = monetaryString(\n discount.reward.value,\n configuration,\n { decimal: false },\n );\n return t(tStrings.rewards.discount_amount, { monetaryAmount });\n } else if (discount.reward.type === \"discount_item_percent\") {\n return discount.reward.value + \"%\";\n }\n return \"\";\n};\n\nconst createBottomRibbon = (\n discount: Discount,\n configuration: Configuration,\n) => {\n const text = getBottomRibbonText(discount, configuration);\n return (\n text &&\n createElement({\n tag: \"div\",\n innerHTML: text,\n theme: configuration.theme,\n styles: [ribbonBottomStyle],\n })\n );\n};\n\nconst createImage = (discount: Discount) => {\n const imageWrapper = createElement({\n tag: \"div\",\n styles: [normalize, imageWrapperStyles],\n });\n const imageSrc = discount.links.find((link) => [\n \"medium_discount_image\",\n \"thumbnail_discount_image\".includes(link.rel),\n ]);\n const image =\n imageSrc &&\n createElement({\n tag: \"img\",\n attributes: {\n src: imageSrc.href,\n alt: discount.name,\n loading: \"lazy\",\n },\n styles: [normalize, imageStyle],\n });\n if (image) {\n imageWrapper.appendChild(image);\n }\n return imageWrapper;\n};\n\nconst createLimitations = (\n discount: Discount,\n configuration: Configuration,\n) => {\n const tStrings = translations[configuration.language];\n\n const wrapper = createElement({\n tag: \"small\",\n styles: [normalize, limitationsWrapperStyle],\n });\n\n const quantity =\n discount.limitation.discount_reward_usage &&\n discount.limitation.discount_reward_usage !== -1 &&\n createElement({\n tag: \"span\",\n innerHTML: t(tStrings.limitations.discount_reward_usage, {\n discount_reward_usage:\n discount.limitation.discount_reward_usage,\n }),\n });\n const repeat =\n discount.limitation.discount_repeat_usage &&\n discount.limitation.discount_repeat_usage !== -1 &&\n createElement({\n tag: \"span\",\n innerHTML: t(tStrings.limitations.discount_repeat_usage, {\n discount_repeat_usage:\n discount.limitation.discount_repeat_usage,\n }),\n });\n\n const startDate = new Date(discount.requirement.purchase_from || 0);\n const start =\n startDate > new Date() &&\n createElement({\n tag: \"span\",\n innerHTML: t(tStrings.requirements.purchase_from, {\n purchase_from: dateString(\n discount.requirement.purchase_from,\n configuration,\n ),\n }),\n });\n const endDate = new Date(discount.requirement.purchase_to || 0);\n const end =\n endDate > new Date() &&\n createElement({\n tag: \"span\",\n innerHTML: t(tStrings.requirements.purchase_to, {\n purchase_to: dateString(\n discount.requirement.purchase_to,\n configuration,\n ),\n }),\n });\n const children = [quantity, repeat, start, end].filter((child) => child);\n children.forEach((child) => wrapper.appendChild(child));\n return wrapper;\n};\n\nexport const createDiscount = (\n discount: Discount,\n configuration: Configuration,\n): HTMLElement => {\n const discountElem = createElement({\n tag: findWebshopLink(discount) ? \"a\" : \"div\",\n styles: [normalize, discountStyle],\n theme: configuration.theme,\n });\n const ribbonTop = createTopRibbon(discount, configuration);\n const ribbonBottom = createBottomRibbon(discount, configuration);\n const image = createImage(discount);\n const title =\n discount?.name &&\n createElement({\n tag: \"h4\",\n innerHTML: discount.name,\n styles: [titleStyle],\n });\n const subtitle =\n discount?.metadata?.subtitle &&\n createElement({\n tag: \"p\",\n innerHTML: discount.metadata.subtitle,\n styles: [subtitleStyle],\n });\n const description =\n discount.description &&\n createElement({ tag: \"p\", innerHTML: discount.description });\n\n const limitations = createLimitations(discount, configuration);\n // add children to discount wrapper\n const children = [\n ribbonTop,\n ribbonBottom,\n image,\n title,\n subtitle,\n description,\n limitations,\n ].filter((child) => child);\n children.forEach((child) => discountElem.appendChild(child));\n return discountElem;\n};\n","import { Configuration, Discount, TokenResponse } from \"./types\";\n\nconst createHeaders = (\n keyValues: { [key: string]: string },\n configuration: Configuration,\n) => {\n const headers: HeadersInit = new Headers();\n Object.entries({\n ...keyValues,\n \"Dintero-System-Name\": \"deals-web-sdk\",\n \"Dintero-System-Version\": configuration.version,\n }).forEach(([key, value]) => {\n headers.append(key, value);\n });\n return headers;\n};\n\nconst fetchAccessToken = (\n configuration: Configuration,\n): Promise<TokenResponse> => {\n if (!configuration.api) {\n throw new Error(\"Authentication configuration missing\");\n }\n const basicAuthCredentials = window.btoa(\n `${configuration.api.key}:${configuration.api.secret}`,\n );\n const headers = createHeaders(\n {\n Authorization: `Basic ${basicAuthCredentials}`,\n \"content-type\": \"application/json\",\n },\n configuration,\n );\n const body = JSON.stringify({\n grant_type: \"client_credentials\",\n audience: `${configuration.api.url}/v1/accounts/${configuration.api.account}`,\n });\n return window\n .fetch(\n `${configuration.api.url}/v1/accounts/${configuration.api.account}/auth/token`,\n {\n method: \"POST\",\n headers,\n body,\n },\n )\n .then((response) => {\n if (response.status === 200) {\n return response.json() as Promise<TokenResponse>;\n }\n throw new Error(\"Authentication failed\");\n });\n};\n\nexport const fetchDiscounts = (\n configuration: Configuration,\n): Promise<Discount[]> => {\n return fetchAccessToken(configuration).then((tokenResponse) => {\n const headers = createHeaders(\n {\n Authorization: `${tokenResponse.token_type} ${tokenResponse.access_token}`,\n },\n configuration,\n );\n\n if (configuration.api.discountId) {\n return window\n .fetch(\n `${configuration.api.url}/v1/accounts/${configuration.api.account}/discounts/public/rules/${configuration.api.discountId}`,\n {\n headers,\n },\n )\n .then((response) => {\n if (response.status === 200) {\n return response\n .json()\n .then((discount) => [discount]) as Promise<\n Discount[]\n >;\n }\n throw new Error(\"Authentication failed\");\n });\n }\n\n return window\n .fetch(\n `${configuration.api.url}/v1/accounts/${configuration.api.account}/discounts/public/rules?limit=${configuration.api.limit}`,\n {\n headers,\n },\n )\n .then((response) => {\n if (response.status === 200) {\n return response.json() as Promise<Discount[]>;\n }\n throw new Error(\"Authentication failed\");\n });\n });\n};\n","import { createElement } from \"./dom\";\nimport { Configuration, Theme } from \"./types\";\nimport { translations } from \"./translations\";\nimport { normalize } from \"./normalize\";\n\nconst errorStyle = (className: string, theme: Theme) => `\n@keyframes appear {\n from {\n transform: scaleY(0%);\n height: 0;\n opacity: 0;\n }\n \n to {\n transform: scaleY(100%);\n height: auto;\n opacity: 1;\n }\n }\n.${className} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: 3px;\n text-align: center;\n padding-top: 65px;\n padding-bottom: 70px;\n padding-left: 5px;\n padding-right: 5px;\n max-width: 300px;\n width: 250px;\n font-size: 14px;\n margin: 5px auto;\n background: ${theme.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n}\n`;\n\nexport const createError = (configuration: Configuration): HTMLElement => {\n const tString = translations[configuration.language];\n const errorElem = createElement({\n tag: \"div\",\n styles: [normalize, errorStyle],\n theme: configuration.theme,\n innerHTML: tString.errors.fetch,\n });\n\n return errorElem;\n};\n","import { createElement } from \"./dom\";\nimport { Configuration, Theme } from \"./types\";\nimport { normalize } from \"./normalize\";\n\nconst loadingStyle = (className: string, theme: Theme) => `\n.${className} {\n margin: 10px auto;\n display: block;\n width: 80px;\n height: 80px;\n}\n\n.${className}:after {\n content: \" \";\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #000;\n border-color: rgba(0,0,0,0.2) transparent rgba(0,0,0,0.2) transparent;\n animation: loading 0.6s linear infinite;\n}\n\n@keyframes loading {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n`;\n\nexport const createLoading = (configuration: Configuration): HTMLElement => {\n const errorElem = createElement({\n tag: \"div\",\n styles: [normalize, loadingStyle],\n theme: configuration.theme,\n });\n\n return errorElem;\n};\n","import { createDiscount, findWebshopLink } from \"./discounts\";\nimport { Discount, Configuration, Theme, Embed } from \"./types\";\nimport { createElement } from \"./dom\";\nimport { fetchDiscounts } from \"./fetch\";\nimport { createError } from \"./error\";\nimport { createLoading } from \"./loading\";\nimport { normalize } from \"./normalize\";\nimport pkg from \"../package.json\";\n\nconst defaultConfig: Partial<Configuration> = {\n language: \"no\",\n version: pkg?.version || \"SNAPSHOT\",\n linkTarget: \"_self\",\n currency: {\n value: \"Kr\",\n position: \"suffix\",\n exponent: 2,\n },\n theme: {\n background: \"#fff\",\n primary: \"#333\",\n secondary: \"#333\",\n color: \"inherit\",\n borderRadius: \"2px\",\n fontSize: \"inherit\",\n },\n api: {\n account: \"\",\n key: \"\",\n secret: \"\",\n url: \"https://api.dintero.com\",\n limit: 50,\n },\n};\n\nconst mergeConfig = (\n a: Partial<Configuration>,\n b: Configuration,\n): Configuration => {\n return {\n ...a,\n ...b,\n currency: {\n ...a.currency,\n ...b.currency,\n },\n theme: {\n ...a.theme,\n ...b.theme,\n },\n api: {\n ...a.api,\n ...b.api,\n },\n };\n};\n\nconst wrapperStyles = (className: string, theme: Theme) => `\n.${className} {\n display: flex;\n flex-flow: wrap;\n align-items: stretch;\n justify-content: center;\n position: relative;\n font-weight: normal;\n width: 100%;\n font-size: ${theme.fontSize};\n color: ${theme.color};\n}`;\n\nexport const embed = async (configuration: Configuration): Promise<Embed> => {\n const _configuration = mergeConfig(defaultConfig, configuration);\n if (!_configuration.container || !_configuration.container.appendChild) {\n console.error(\"Invalid configuration\");\n throw new Error(\"Invalid configuration\");\n }\n if (_configuration.discounts) {\n return renderDeals(_configuration, _configuration.discounts);\n } else {\n const loader = createLoading(_configuration);\n try {\n configuration.container.appendChild(loader);\n const discounts = await fetchDiscounts(_configuration);\n _configuration.container.removeChild(loader);\n return renderDeals(_configuration, discounts);\n } catch (error) {\n configuration.container.removeChild(loader);\n const errorMessage = createError(_configuration);\n _configuration.container.appendChild(errorMessage);\n return {\n destroy: () => {\n configuration.container.removeChild(errorMessage);\n },\n };\n }\n }\n};\n\nconst renderDeals = (\n configuration: Configuration,\n discounts: Discount[],\n): Embed => {\n const wrapper = createElement({\n tag: \"div\",\n styles: [normalize, wrapperStyles],\n theme: configuration.theme,\n });\n discounts.forEach((discount) => {\n const elem = createDiscount(discount, configuration);\n const webShopLink = findWebshopLink(discount);\n if (webShopLink) {\n elem.setAttribute(\"target\", configuration?.linkTarget || \"_self\");\n elem.setAttribute(\"href\", webShopLink.href);\n }\n wrapper.appendChild(elem);\n });\n configuration.container.appendChild(wrapper);\n return {\n destroy: () => {\n configuration.container.removeChild(wrapper);\n },\n };\n};\n"],"names":["createElement","options","elem","document","tag","attributes","addAttributes","handlers","addEventListeners","styles","addStyles","theme","innerHTML","forEach","cssFn","className","input","hash","i","length","charCodeAt","toString","addClass","split","includes","querySelector","style","setAttribute","head","appendChild","Object","keys","key","addEventListener","translations","no","rewards","discount_item_quantity","three_for_two","generic","discount_amount","limitations","discount_reward_usage","discount_repeat_usage","requirements","purchase_from","purchase_to","errors","fetch","findValuesRegex","t","translateString","values","matches","match","_values","reduce","interpolated","replace","value","monetaryString","amount","configuration","opt","amountString","dotIndex","currency","exponent","beforeDot","slice","afterDot","exponentAmount","decimal","variant","position","padZero","dateString","isoString","date","Date","language","dd","getDate","mm","getMonth","getFullYear","join","Intl","DateTimeFormat","format","e","substr","normalize","findWebshopLink","discount","links","find","x","rel","discountStyle","borderRadius","background","imageWrapperStyles","imageStyle","ribbonTopStyle","secondary","ribbonBottomStyle","primary","titleStyle","subtitleStyle","limitationsWrapperStyle","createBottomRibbon","text","getBottomRibbonText","tStrings","reward","type","requirement","item","quantity","require","payFor","monetaryAmount","createDiscount","discountElem","ribbonTop","createTopRibbon","metadata","label","undefined","getTopRibbonText","ribbonBottom","image","imageWrapper","imageSrc","link","src","href","alt","name","loading","createImage","title","subtitle","description","createLimitations","wrapper","limitation","filter","child","createHeaders","keyValues","headers","Headers","entries","version","append","fetchDiscounts","api","Error","basicAuthCredentials","window","btoa","secret","Authorization","body","JSON","stringify","grant_type","audience","url","account","method","then","response","status","json","fetchAccessToken","tokenResponse","token_type","access_token","discountId","limit","errorStyle","loadingStyle","defaultConfig","linkTarget","color","fontSize","wrapperStyles","renderDeals","discounts","webShopLink","container","destroy","removeChild","async","_configuration","a","b","mergeConfig","console","error","loader","createLoading","errorMessage","tString","createError"],"mappings":"iPAWO,MAAMA,EAAiBC,IAC1B,MAAMC,EAAOC,SAASH,cAAcC,EAAQG,KAa5C,OAZIH,EAAQI,YACRC,EAAcJ,EAAMD,EAAQI,YAE5BJ,EAAQM,UACRC,EAAkBN,EAAMD,EAAQM,UAEhCN,EAAQQ,QACRC,EAAUR,EAAMD,EAAQQ,OAAQR,EAAQU,OAExCV,EAAQW,YACRV,EAAKU,UAAYX,EAAQW,WAEtBV,CAAI,EAoBTQ,EAAYA,CACdR,EACAO,EACAE,KAGAF,EAAOI,SAASC,IAEZ,MAAMC,EACF,iBAnBEC,KACV,IAAIC,EAAO,EACX,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAMG,OAAQD,IAE9BD,GAAQA,GAAQ,GAAKA,EADVD,EAAMI,WAAWF,GAE5BD,GAAcA,EAElB,OAAOA,EAAKI,SAAS,GAAG,EAYGJ,CAAKH,EAAM,gBAAiBH,IA1B1CW,EAACpB,EAAmBa,KACnBb,EAAKa,UAAUQ,MAAM,KACxBC,SAAST,KAChBb,EA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AcmI,UAAUpK,YAAY8K,GACpC,MAAMZ,QAAkBlC,EAAewC,GAEvC,OADAA,EAAeJ,UAAUE,YAAYQ,GAC9Bb,EAAYO,EAAgBN,EACtC,CAAC,MAAOW,GACL5I,EAAcmI,UAAUE,YAAYQ,GACpC,MAAME,EFhDU/I,KACxB,MAAMgJ,EAAU5K,EAAa4B,EAAckB,UAQ3C,OAPkBhF,EAAc,CAC5BI,IAAK,MACLK,OAAQ,CAACmF,EAAW2F,GACpB5K,MAAOmD,EAAcnD,MACrBC,UAAWkM,EAAQ/J,OAAOC,OAGd,EEuCa+J,CAAYV,GAEjC,OADAA,EAAeJ,UAAUpK,YAAYgL,GAC9B,CACHX,QAASA,KACLpI,EAAcmI,UAAUE,YAAYU,EAAa,EAG7D,CACJ"}
package/index.html CHANGED
@@ -5,8 +5,7 @@
5
5
  name="viewport"
6
6
  content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1, user-scalable=0"
7
7
  />
8
- <meta charset="UTF-8">
9
-
8
+ <meta charset="UTF-8" />
10
9
 
11
10
  <style>
12
11
  body {
@@ -121,7 +120,7 @@
121
120
  function (event) {
122
121
  console.log("embed received message", event);
123
122
  },
124
- false
123
+ false,
125
124
  );
126
125
  function changeBackground() {
127
126
  if (document.body.className === "color") {
@@ -131,9 +130,12 @@
131
130
  }
132
131
  }
133
132
  </script>
134
- <script src="./dist/dintero-discounts-web-sdk.umd.min.js" charset="UTF-8"></script>
133
+ <script
134
+ src="./dist/dintero-discounts-web-sdk.umd.min.js"
135
+ charset="UTF-8"
136
+ ></script>
135
137
  </head>
136
- <bod
138
+ <body>
137
139
  <div class="main">
138
140
  <h1>Mock for embed</h1>
139
141
  <div class="mb-10">
@@ -148,78 +150,97 @@
148
150
  <label for="checkbox">Change background color</label>
149
151
  </div>
150
152
  <h2>API test</h2>
151
- <p>In this example the SDK will try to fetch data from the discount service.</p>
153
+ <p>
154
+ In this example the SDK will try to fetch data from the discount
155
+ service.
156
+ </p>
152
157
  <div id="deals-container-api"></div>
153
158
  <script type="text/javascript">
154
- discounts.embed({
155
- container: document.getElementById("deals-container-api"),
156
- api:{
157
- account: 'P00000000',
158
- key: 'public_api_key',
159
- secret: 'abcdef01-2345-6789-abcd-ef0123456789',
160
- },
161
- theme: {
162
- fontSize: "14px",
163
- color: "rgba(0,0,0,1)",
164
- primary: "hotpink",
165
- secondary: "aqua",
166
- background: "#fff",
167
- }
168
- }).then(result => {
169
- window.setTimeout(result.destroy, 50000);
170
- });
159
+ discounts
160
+ .embed({
161
+ container: document.getElementById(
162
+ "deals-container-api",
163
+ ),
164
+ api: {
165
+ account: "P00000000",
166
+ key: "public_api_key",
167
+ secret: "abcdef01-2345-6789-abcd-ef0123456789",
168
+ },
169
+ theme: {
170
+ fontSize: "14px",
171
+ color: "rgba(0,0,0,1)",
172
+ primary: "hotpink",
173
+ secondary: "aqua",
174
+ background: "#fff",
175
+ },
176
+ })
177
+ .then((result) => {
178
+ window.setTimeout(result.destroy, 50000);
179
+ });
171
180
  </script>
172
- <H2>Static test</h2>
173
- <p>In this example the SDK is supplied with a list of discount objects directly.</p>
181
+ <h2>Static test</h2>
182
+ <p>
183
+ In this example the SDK is supplied with a list of discount
184
+ objects directly.
185
+ </p>
174
186
  <div id="deals-container-static"></div>
175
187
  <script type="text/javascript">
176
- discounts.embed({
177
- container: document.getElementById("deals-container-static"),
178
- discounts:[{
179
- "id": "1",
180
- "name": "Testvare",
181
- "description": "Beskrivelse av testvare",
182
- "requirement": {
183
- "item": { "items": [{ "id": "testvare-1" }] },
184
- "customer": {},
185
- "store_ids": ["*"],
186
- "purchase_to": "2030-06-13T21:59:00Z",
187
- "purchase_from": "2080-06-06T22:00:00Z"
188
- },
189
- "limitation": {},
190
- "reward": { "type": "discount_item_new_price", "value": 5000 },
191
- "created_by": "DinteroTest",
192
- "created_at": "2021-06-04T10:21:18.029Z",
193
- "updated_at": "2021-06-04T10:21:18.029Z",
194
- "receipt_text": "Ukens tilbud",
195
- "type": "item",
196
- "links": [
188
+ discounts
189
+ .embed({
190
+ container: document.getElementById(
191
+ "deals-container-static",
192
+ ),
193
+ discounts: [
197
194
  {
198
- "rel": "medium_discount_image",
199
- "href": "https://uploads-ssl.webflow.com/5f023ba9549ac22870f32943/5f1333ae5a496b0e0476975e_dintero-logo.svg"
195
+ id: "1",
196
+ name: "Testvare",
197
+ description: "Beskrivelse av testvare",
198
+ requirement: {
199
+ item: { items: [{ id: "testvare-1" }] },
200
+ customer: {},
201
+ store_ids: ["*"],
202
+ purchase_to: "2030-06-13T21:59:00Z",
203
+ purchase_from: "2080-06-06T22:00:00Z",
204
+ },
205
+ limitation: {},
206
+ reward: {
207
+ type: "discount_item_new_price",
208
+ value: 5000,
209
+ },
210
+ created_by: "DinteroTest",
211
+ created_at: "2021-06-04T10:21:18.029Z",
212
+ updated_at: "2021-06-04T10:21:18.029Z",
213
+ receipt_text: "Ukens tilbud",
214
+ type: "item",
215
+ links: [
216
+ {
217
+ rel: "medium_discount_image",
218
+ href: "https://uploads-ssl.webflow.com/5f023ba9549ac22870f32943/5f1333ae5a496b0e0476975e_dintero-logo.svg",
219
+ },
220
+ {
221
+ rel: "webshop",
222
+ href: "https://example.dintero.com/shop?utm_source=dintero&utm_medium=email&utm_campaign=spring-summer",
223
+ },
224
+ ],
225
+ metadata: {
226
+ label: "Før: 100,-",
227
+ subtitle: "Ukens tilbud",
228
+ campaign_id: 1,
229
+ },
230
+ active: true,
200
231
  },
201
- {
202
- "rel": "webshop",
203
- "href": "https://example.dintero.com/shop?utm_source=dintero&utm_medium=email&utm_campaign=spring-summer"
204
- }
205
232
  ],
206
- "metadata": {
207
- "label": "Før: 100,-",
208
- "subtitle": "Ukens tilbud",
209
- "campaign_id": 1
233
+ theme: {
234
+ fontSize: "14px",
235
+ color: "rgba(0,0,0,1)",
236
+ primary: "hotpink",
237
+ secondary: "aqua",
238
+ background: "#fff",
210
239
  },
211
- "active": true
212
- }],
213
- theme: {
214
- fontSize: "14px",
215
- color: "rgba(0,0,0,1)",
216
- primary: "hotpink",
217
- secondary: "aqua",
218
- background: "#fff",
219
- }
220
- }).then(result => {
221
- window.setTimeout(result.destroy, 50000);
222
- });
240
+ })
241
+ .then((result) => {
242
+ window.setTimeout(result.destroy, 50000);
243
+ });
223
244
  </script>
224
245
  </div>
225
246
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dintero/discounts-web-sdk",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Dintero Discounts SDK for web frontends",
5
5
  "main": "dist/dintero-discounts-web-sdk.cjs.js",
6
6
  "module": "dist/dintero-discounts-web-sdk.esm.js",
@@ -14,6 +14,7 @@
14
14
  "test": "vitest --dom",
15
15
  "watch": "preconstruct watch",
16
16
  "build": "preconstruct build",
17
+ "lint": "prettier --cache --log-level warn -c --config .prettierrc.yml .",
17
18
  "prepublishOnly": "yarn build",
18
19
  "semantic-release": "semantic-release"
19
20
  },
@@ -29,14 +30,14 @@
29
30
  "url": "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
30
31
  },
31
32
  "devDependencies": {
32
- "@babel/core": "7.13.0",
33
- "@babel/preset-typescript": "7.13.0",
34
- "@preconstruct/cli": "2.8.1",
33
+ "@babel/core": "7.23.9",
34
+ "@babel/preset-typescript": "7.23.3",
35
+ "@preconstruct/cli": "2.8.3",
35
36
  "@semantic-release/git": "10.0.1",
36
- "happy-dom": "12.9.0",
37
- "prettier": "3.0.3",
38
- "semantic-release": "22.0.5",
39
- "typescript": "5.2.2",
40
- "vitest": "0.34.6"
37
+ "happy-dom": "13.3.8",
38
+ "prettier": "3.2.5",
39
+ "semantic-release": "23.0.2",
40
+ "typescript": "5.3.3",
41
+ "vitest": "1.3.1"
41
42
  }
42
43
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"dintero-discounts-web-sdk.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}