@dintero/discounts-web-sdk 0.2.2 → 0.2.3
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.
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/base.css +0 -0
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/block-navigation.js +0 -0
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/discounts.ts.html +1 -1
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/dom.ts.html +1 -1
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/error.ts.html +1 -1
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/favicon.png +0 -0
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/fetch.ts.html +1 -1
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/formatters.ts.html +1 -1
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/index.html +1 -1
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/index.ts.html +1 -1
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/loading.ts.html +1 -1
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/normalize.ts.html +1 -1
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/prettify.css +0 -0
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/prettify.js +0 -0
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/sort-arrow-sprite.png +0 -0
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/sorter.js +0 -0
- package/coverage/{Chrome Headless 109.0.5412.0 (Linux x86_64) → Chrome Headless 110.0.5478.0 (Linux x86_64)}/html/translations.ts.html +1 -1
- package/dist/dintero-discounts-web-sdk.cjs.dev.js +1 -1
- package/dist/dintero-discounts-web-sdk.cjs.prod.js +1 -1
- package/dist/dintero-discounts-web-sdk.esm.js +1 -1
- package/dist/dintero-discounts-web-sdk.umd.min.js +1 -1
- package/package.json +1 -1
|
File without changes
|
|
File without changes
|
|
@@ -1078,7 +1078,7 @@ export const createDiscount = (
|
|
|
1078
1078
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
1079
1079
|
Code coverage generated by
|
|
1080
1080
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
1081
|
-
at
|
|
1081
|
+
at Sat Feb 04 2023 15:11:14 GMT+0000 (Coordinated Universal Time)
|
|
1082
1082
|
</div>
|
|
1083
1083
|
<script src="prettify.js"></script>
|
|
1084
1084
|
<script>
|
|
@@ -295,7 +295,7 @@ const addEventListeners = <span class="fstat-no" title="function not covered" >(
|
|
|
295
295
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
296
296
|
Code coverage generated by
|
|
297
297
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
298
|
-
at
|
|
298
|
+
at Sat Feb 04 2023 15:11:14 GMT+0000 (Coordinated Universal Time)
|
|
299
299
|
</div>
|
|
300
300
|
<script src="prettify.js"></script>
|
|
301
301
|
<script>
|
|
@@ -229,7 +229,7 @@ export const createError = <span class="fstat-no" title="function not covered" >
|
|
|
229
229
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
230
230
|
Code coverage generated by
|
|
231
231
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
232
|
-
at
|
|
232
|
+
at Sat Feb 04 2023 15:11:14 GMT+0000 (Coordinated Universal Time)
|
|
233
233
|
</div>
|
|
234
234
|
<script src="prettify.js"></script>
|
|
235
235
|
<script>
|
|
File without changes
|
|
@@ -370,7 +370,7 @@ export const fetchDiscounts = <span class="fstat-no" title="function not covered
|
|
|
370
370
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
371
371
|
Code coverage generated by
|
|
372
372
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
373
|
-
at
|
|
373
|
+
at Sat Feb 04 2023 15:11:14 GMT+0000 (Coordinated Universal Time)
|
|
374
374
|
</div>
|
|
375
375
|
<script src="prettify.js"></script>
|
|
376
376
|
<script>
|
|
@@ -208,7 +208,7 @@ export const dateString = <span class="fstat-no" title="function not covered" >(
|
|
|
208
208
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
209
209
|
Code coverage generated by
|
|
210
210
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
211
|
-
at
|
|
211
|
+
at Sat Feb 04 2023 15:11:14 GMT+0000 (Coordinated Universal Time)
|
|
212
212
|
</div>
|
|
213
213
|
<script src="prettify.js"></script>
|
|
214
214
|
<script>
|
|
@@ -221,7 +221,7 @@
|
|
|
221
221
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
222
222
|
Code coverage generated by
|
|
223
223
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
224
|
-
at
|
|
224
|
+
at Sat Feb 04 2023 15:11:14 GMT+0000 (Coordinated Universal Time)
|
|
225
225
|
</div>
|
|
226
226
|
<script src="prettify.js"></script>
|
|
227
227
|
<script>
|
|
@@ -421,7 +421,7 @@ const renderDeals = (configuration: Configuration, discounts: Discount[]):Embed
|
|
|
421
421
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
422
422
|
Code coverage generated by
|
|
423
423
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
424
|
-
at
|
|
424
|
+
at Sat Feb 04 2023 15:11:14 GMT+0000 (Coordinated Universal Time)
|
|
425
425
|
</div>
|
|
426
426
|
<script src="prettify.js"></script>
|
|
427
427
|
<script>
|
|
@@ -199,7 +199,7 @@ export const createLoading = <span class="fstat-no" title="function not covered"
|
|
|
199
199
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
200
200
|
Code coverage generated by
|
|
201
201
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
202
|
-
at
|
|
202
|
+
at Sat Feb 04 2023 15:11:14 GMT+0000 (Coordinated Universal Time)
|
|
203
203
|
</div>
|
|
204
204
|
<script src="prettify.js"></script>
|
|
205
205
|
<script>
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
122
122
|
Code coverage generated by
|
|
123
123
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
124
|
-
at
|
|
124
|
+
at Sat Feb 04 2023 15:11:14 GMT+0000 (Coordinated Universal Time)
|
|
125
125
|
</div>
|
|
126
126
|
<script src="prettify.js"></script>
|
|
127
127
|
<script>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -184,7 +184,7 @@ export const t = <span class="fstat-no" title="function not covered" >(t</span>r
|
|
|
184
184
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
185
185
|
Code coverage generated by
|
|
186
186
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
187
|
-
at
|
|
187
|
+
at Sat Feb 04 2023 15:11:14 GMT+0000 (Coordinated Universal Time)
|
|
188
188
|
</div>
|
|
189
189
|
<script src="prettify.js"></script>
|
|
190
190
|
<script>
|
|
@@ -625,7 +625,7 @@ const createLoading = configuration => {
|
|
|
625
625
|
|
|
626
626
|
var pkg = {
|
|
627
627
|
name: "@dintero/discounts-web-sdk",
|
|
628
|
-
version: "0.2.
|
|
628
|
+
version: "0.2.3",
|
|
629
629
|
description: "Dintero Discounts SDK for web frontends",
|
|
630
630
|
main: "dist/dintero-discounts-web-sdk.cjs.js",
|
|
631
631
|
module: "dist/dintero-discounts-web-sdk.esm.js",
|
|
@@ -625,7 +625,7 @@ const createLoading = configuration => {
|
|
|
625
625
|
|
|
626
626
|
var pkg = {
|
|
627
627
|
name: "@dintero/discounts-web-sdk",
|
|
628
|
-
version: "0.2.
|
|
628
|
+
version: "0.2.3",
|
|
629
629
|
description: "Dintero Discounts SDK for web frontends",
|
|
630
630
|
main: "dist/dintero-discounts-web-sdk.cjs.js",
|
|
631
631
|
module: "dist/dintero-discounts-web-sdk.esm.js",
|
|
@@ -621,7 +621,7 @@ const createLoading = configuration => {
|
|
|
621
621
|
|
|
622
622
|
var pkg = {
|
|
623
623
|
name: "@dintero/discounts-web-sdk",
|
|
624
|
-
version: "0.2.
|
|
624
|
+
version: "0.2.3",
|
|
625
625
|
description: "Dintero Discounts SDK for web frontends",
|
|
626
626
|
main: "dist/dintero-discounts-web-sdk.cjs.js",
|
|
627
627
|
module: "dist/dintero-discounts-web-sdk.esm.js",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).discounts={})}(this,(function(n){"use strict";const e=n=>{const e=document.createElement(n.tag);return n.attributes&&r(e,n.attributes),n.handlers&&i(e,n.handlers),n.styles&&t(e,n.styles,n.theme),n.innerHTML&&(e.innerHTML=n.innerHTML),e},t=(n,e,t)=>{e.forEach((e=>{const r="dintero-deals-"+(n=>{let e=0;for(var t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e&=e;return e.toString(36)})(e("dintero-deals",t));((n,e)=>{n.className.split(" ").includes(e)||(n.className=n.className+" "+e)})(n,r);if(!document.querySelector(`[data-css-hash=${r}]`)){const n=document.createElement("style");n.innerHTML=e(r,t),n.setAttribute("data-css-hash",r),document.head.appendChild(n)}}))},r=(n,e)=>{Object.keys(e).forEach((t=>{n.setAttribute(t,e[t])}))},i=(n,e)=>{Object.keys(e).forEach((t=>{n.addEventListener(t,e[t])}))},a={no:{rewards:{discount_item_quantity:{three_for_two:"3 for 2",generic:"Kjøp {{require}} betal for {{payFor}}"},discount_amount:"{{monetaryAmount}} rabatt"},limitations:{discount_reward_usage:"Antall: <strong>{{discount_reward_usage}}</strong>",discount_repeat_usage:"Maks kjøp: <strong>{{discount_repeat_usage}}</strong>"},requirements:{purchase_from:"Tilbudet starter <strong>{{purchase_from}}</strong>",purchase_to:"Tilbudet utgår <strong>{{purchase_to}}</strong>"},errors:{fetch:"⚠️ <br/>En feil oppstod under lasting av tilbud..."}}},o=/(\{\{)[^}]*(\}\})/g,s=(n,e)=>{const t=n.match(o)||[],r=e||{};return t.reduce(((n,e)=>{const t=e.replace("{{","").replace("}}",""),i=r[t]||"";return n.replace(e,i)}),n)},d=(n,e,t)=>{const r=t||{},i=n.toString(),a=i.length-e.currency.exponent,o=i.slice(0,a)||"0",s=i.slice(a),d="00"!=s||r.decimal?o+"."+s:o;return"short"===r.variant&&"00"===s?o+",-":r.currency?"prefix"===e.currency.position?e.currency.value+" "+d:d+" "+e.currency.value:d},c=n=>n<10?`0${n}`:n.toString(),u=(n,e)=>{try{const t=new Date(n);if("no"===e.language){const n=c(t.getDate()),e=c(t.getMonth()+1);return[n,e,t.getFullYear()].join(".")}return(new Intl.DateTimeFormat).format(t)}catch(e){return n.substr(0,10)}},p=n=>`\n.${n} {\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`,l=n=>n.links&&n.links.find((n=>n.rel&&"webshop"===n.rel)),m=(n,e)=>`\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.${n} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: ${e.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: ${e.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 .${n} {\n width: 100%;\n max-width: 100%;\n } \n }\n`,h=n=>`\n.${n} {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 300px;\n width: 100%,\n}`,g=n=>`\n.${n} {\n max-width: 100%;\n max-height: 100%;\n text-align: center;\n display: inline-block;\n}`,f=(n,e)=>`\n.${n} {\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 ${e.borderRadius} ${e.borderRadius} 0;\n padding: 5px 0;\n background: ${e?.secondary};\n}\n.${n}: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: ${e.secondary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`,b=(n,e)=>`\n.${n} {\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: ${e.borderRadius} 0 0 ${e.borderRadius};\n padding: 5px 0;\n background: ${e?.primary};\n}\n.${n}: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: ${e.primary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`,y=n=>`\n.${n} {\n margin-bottom: 0;\n font-size: 1em;\n margin-bottom: 2px;\n font-size: 1.3em;\n font-weight: 700;\n}`,x=n=>`\n.${n} {\n margin-top: 0;\n}`,w=n=>`\n.${n} {\n font-size: 0.75em;\n}\n.${n} > span{\n display: block;\n}\n`,_=(n,t)=>{const r=((n,e)=>{const t=a[e.language];if("discount_item_new_price"===n.reward.type)return d(n.reward.value,e,{variant:"short"});if("discount_percent"===n.reward.type)return n.reward.value+"%";if("discount_item_quantity"===n.reward.type){if(3===n.requirement.item.quantity&&1===n.reward.value)return t.rewards.discount_item_quantity.three_for_two;{const e=n.requirement.item.quantity,r=n.requirement.item.quantity-n.reward.value;return s(t.rewards.discount_item_quantity.generic,{require:e,payFor:r})}}if("discount_amount"===n.reward.type){const r=d(n.reward.value,e,{decimal:!1});return s(t.rewards.discount_amount,{monetaryAmount:r})}return"discount_item_percent"===n.reward.type?n.reward.value+"%":""})(n,t);return r&&e({tag:"div",innerHTML:r,theme:t.theme,styles:[b]})},$=(n,t)=>{const r=e({tag:l(n)?"a":"div",styles:[p,m],theme:t.theme}),i=((n,t)=>{const r=(n=>n&&n.metadata&&n.metadata.label||void 0)(n);return r&&e({tag:"div",innerHTML:r,theme:t.theme,styles:[f]})})(n,t),o=_(n,t),d=(n=>{const t=e({tag:"div",styles:[p,h]}),r=n.links.find((n=>["medium_discount_image","thumbnail_discount_image".includes(n.rel)])),i=r&&e({tag:"img",attributes:{src:r.href,alt:n.name,loading:"lazy"},styles:[p,g]});return i&&t.appendChild(i),t})(n),c=n?.name&&e({tag:"h4",innerHTML:n.name,styles:[y]}),b=n?.metadata?.subtitle&&e({tag:"p",innerHTML:n.metadata.subtitle,styles:[x]}),$=n.description&&e({tag:"p",innerHTML:n.description}),v=((n,t)=>{const r=a[t.language],i=e({tag:"small",styles:[p,w]});return[n.limitation.discount_reward_usage&&-1!==n.limitation.discount_reward_usage&&e({tag:"span",innerHTML:s(r.limitations.discount_reward_usage,{discount_reward_usage:n.limitation.discount_reward_usage})}),n.limitation.discount_repeat_usage&&-1!==n.limitation.discount_repeat_usage&&e({tag:"span",innerHTML:s(r.limitations.discount_repeat_usage,{discount_repeat_usage:n.limitation.discount_repeat_usage})}),new Date(n.requirement.purchase_from||0)>new Date&&e({tag:"span",innerHTML:s(r.requirements.purchase_from,{purchase_from:u(n.requirement.purchase_from,t)})}),new Date(n.requirement.purchase_to||0)>new Date&&e({tag:"span",innerHTML:s(r.requirements.purchase_to,{purchase_to:u(n.requirement.purchase_to,t)})})].filter((n=>n)).forEach((n=>i.appendChild(n))),console.log({discount:n,wrapper:i}),i})(n,t);return[i,o,d,c,b,$,v].filter((n=>n)).forEach((n=>r.appendChild(n))),r},v=(n,e)=>{const t=new Headers;return Object.entries({...n,"Dintero-System-Name":"deals-web-sdk","Dintero-System-Version":e.version}).forEach((([n,e])=>{t.append(n,e)})),t},k=n=>(n=>{if(!n.api)throw new Error("Authentication configuration missing");const e=window.btoa(`${n.api.key}:${n.api.secret}`),t=v({Authorization:`Basic ${e}`,"content-type":"application/json"},n),r=JSON.stringify({grant_type:"client_credentials",audience:`${n.api.url}/v1/accounts/${n.api.account}`});return window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/auth/token`,{method:"POST",headers:t,body:r}).then((n=>{if(200===n.status)return n.json();throw new Error("Authentication failed")}))})(n).then((e=>{const t=v({Authorization:`${e.token_type} ${e.access_token}`},n);return n.api.discountId?window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/discounts/public/rules/${n.api.discountId}`,{headers:t}).then((n=>{if(200===n.status)return n.json().then((n=>[n]));throw new Error("Authentication failed")})):window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/discounts/public/rules?limit=${n.api.limit}`,{headers:t}).then((n=>{if(200===n.status)return n.json();throw new Error("Authentication failed")}))})),T=(n,e)=>`\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.${n} {\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: ${e.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n}\n`,q=(n,e)=>`\n.${n} {\n margin: 10px auto;\n display: block;\n width: 80px;\n height: 80px;\n}\n\n.${n}: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`;const M={language:"no",version:"0.2.2",linkTarget:"_self",currency:{value:"Kr",position:"suffix",exponent:2},theme:{background:"#fff",primary:"#333",secondary:"#333",color:"inherit",borderRadius:"2px",fontSize:"inherit"},api:{account:"",key:"",secret:"",url:"https://api.dintero.com",limit:50}},z=(n,e)=>`\n.${n} {\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: ${e.fontSize};\n color: ${e.color};\n}`,E=(n,t)=>{const r=e({tag:"div",styles:[p,z],theme:n.theme});return t.forEach((e=>{const t=$(e,n),i=l(e);i&&(t.setAttribute("target",n?.linkTarget||"_self"),t.setAttribute("href",i.href)),r.appendChild(t)})),n.container.appendChild(r),{destroy:()=>{n.container.removeChild(r)}}};n.embed=async n=>{const t=(r=M,i=n,{...r,...i,currency:{...r.currency,...i.currency},theme:{...r.theme,...i.theme},api:{...r.api,...i.api}});var r,i;if(!t.container||!t.container.appendChild)throw console.error("Invalid configuration"),new Error("Invalid configuration");if(t.discounts)return E(t,t.discounts);{const r=(n=>e({tag:"div",styles:[p,q],theme:n.theme}))(t);try{n.container.appendChild(r);const e=await k(t);return t.container.removeChild(r),E(t,e)}catch(i){n.container.removeChild(r);const o=(n=>{const t=a[n.language];return e({tag:"div",styles:[p,T],theme:n.theme,innerHTML:t.errors.fetch})})(t);return t.container.appendChild(o),{destroy:()=>{n.container.removeChild(o)}}}}},Object.defineProperty(n,"__esModule",{value:!0})}));
|
|
1
|
+
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).discounts={})}(this,(function(n){"use strict";const e=n=>{const e=document.createElement(n.tag);return n.attributes&&r(e,n.attributes),n.handlers&&i(e,n.handlers),n.styles&&t(e,n.styles,n.theme),n.innerHTML&&(e.innerHTML=n.innerHTML),e},t=(n,e,t)=>{e.forEach((e=>{const r="dintero-deals-"+(n=>{let e=0;for(var t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e&=e;return e.toString(36)})(e("dintero-deals",t));((n,e)=>{n.className.split(" ").includes(e)||(n.className=n.className+" "+e)})(n,r);if(!document.querySelector(`[data-css-hash=${r}]`)){const n=document.createElement("style");n.innerHTML=e(r,t),n.setAttribute("data-css-hash",r),document.head.appendChild(n)}}))},r=(n,e)=>{Object.keys(e).forEach((t=>{n.setAttribute(t,e[t])}))},i=(n,e)=>{Object.keys(e).forEach((t=>{n.addEventListener(t,e[t])}))},a={no:{rewards:{discount_item_quantity:{three_for_two:"3 for 2",generic:"Kjøp {{require}} betal for {{payFor}}"},discount_amount:"{{monetaryAmount}} rabatt"},limitations:{discount_reward_usage:"Antall: <strong>{{discount_reward_usage}}</strong>",discount_repeat_usage:"Maks kjøp: <strong>{{discount_repeat_usage}}</strong>"},requirements:{purchase_from:"Tilbudet starter <strong>{{purchase_from}}</strong>",purchase_to:"Tilbudet utgår <strong>{{purchase_to}}</strong>"},errors:{fetch:"⚠️ <br/>En feil oppstod under lasting av tilbud..."}}},o=/(\{\{)[^}]*(\}\})/g,s=(n,e)=>{const t=n.match(o)||[],r=e||{};return t.reduce(((n,e)=>{const t=e.replace("{{","").replace("}}",""),i=r[t]||"";return n.replace(e,i)}),n)},d=(n,e,t)=>{const r=t||{},i=n.toString(),a=i.length-e.currency.exponent,o=i.slice(0,a)||"0",s=i.slice(a),d="00"!=s||r.decimal?o+"."+s:o;return"short"===r.variant&&"00"===s?o+",-":r.currency?"prefix"===e.currency.position?e.currency.value+" "+d:d+" "+e.currency.value:d},c=n=>n<10?`0${n}`:n.toString(),u=(n,e)=>{try{const t=new Date(n);if("no"===e.language){const n=c(t.getDate()),e=c(t.getMonth()+1);return[n,e,t.getFullYear()].join(".")}return(new Intl.DateTimeFormat).format(t)}catch(e){return n.substr(0,10)}},p=n=>`\n.${n} {\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`,l=n=>n.links&&n.links.find((n=>n.rel&&"webshop"===n.rel)),m=(n,e)=>`\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.${n} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: ${e.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: ${e.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 .${n} {\n width: 100%;\n max-width: 100%;\n } \n }\n`,h=n=>`\n.${n} {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 300px;\n width: 100%,\n}`,g=n=>`\n.${n} {\n max-width: 100%;\n max-height: 100%;\n text-align: center;\n display: inline-block;\n}`,f=(n,e)=>`\n.${n} {\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 ${e.borderRadius} ${e.borderRadius} 0;\n padding: 5px 0;\n background: ${e?.secondary};\n}\n.${n}: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: ${e.secondary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`,b=(n,e)=>`\n.${n} {\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: ${e.borderRadius} 0 0 ${e.borderRadius};\n padding: 5px 0;\n background: ${e?.primary};\n}\n.${n}: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: ${e.primary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`,y=n=>`\n.${n} {\n margin-bottom: 0;\n font-size: 1em;\n margin-bottom: 2px;\n font-size: 1.3em;\n font-weight: 700;\n}`,x=n=>`\n.${n} {\n margin-top: 0;\n}`,w=n=>`\n.${n} {\n font-size: 0.75em;\n}\n.${n} > span{\n display: block;\n}\n`,_=(n,t)=>{const r=((n,e)=>{const t=a[e.language];if("discount_item_new_price"===n.reward.type)return d(n.reward.value,e,{variant:"short"});if("discount_percent"===n.reward.type)return n.reward.value+"%";if("discount_item_quantity"===n.reward.type){if(3===n.requirement.item.quantity&&1===n.reward.value)return t.rewards.discount_item_quantity.three_for_two;{const e=n.requirement.item.quantity,r=n.requirement.item.quantity-n.reward.value;return s(t.rewards.discount_item_quantity.generic,{require:e,payFor:r})}}if("discount_amount"===n.reward.type){const r=d(n.reward.value,e,{decimal:!1});return s(t.rewards.discount_amount,{monetaryAmount:r})}return"discount_item_percent"===n.reward.type?n.reward.value+"%":""})(n,t);return r&&e({tag:"div",innerHTML:r,theme:t.theme,styles:[b]})},$=(n,t)=>{const r=e({tag:l(n)?"a":"div",styles:[p,m],theme:t.theme}),i=((n,t)=>{const r=(n=>n&&n.metadata&&n.metadata.label||void 0)(n);return r&&e({tag:"div",innerHTML:r,theme:t.theme,styles:[f]})})(n,t),o=_(n,t),d=(n=>{const t=e({tag:"div",styles:[p,h]}),r=n.links.find((n=>["medium_discount_image","thumbnail_discount_image".includes(n.rel)])),i=r&&e({tag:"img",attributes:{src:r.href,alt:n.name,loading:"lazy"},styles:[p,g]});return i&&t.appendChild(i),t})(n),c=n?.name&&e({tag:"h4",innerHTML:n.name,styles:[y]}),b=n?.metadata?.subtitle&&e({tag:"p",innerHTML:n.metadata.subtitle,styles:[x]}),$=n.description&&e({tag:"p",innerHTML:n.description}),v=((n,t)=>{const r=a[t.language],i=e({tag:"small",styles:[p,w]});return[n.limitation.discount_reward_usage&&-1!==n.limitation.discount_reward_usage&&e({tag:"span",innerHTML:s(r.limitations.discount_reward_usage,{discount_reward_usage:n.limitation.discount_reward_usage})}),n.limitation.discount_repeat_usage&&-1!==n.limitation.discount_repeat_usage&&e({tag:"span",innerHTML:s(r.limitations.discount_repeat_usage,{discount_repeat_usage:n.limitation.discount_repeat_usage})}),new Date(n.requirement.purchase_from||0)>new Date&&e({tag:"span",innerHTML:s(r.requirements.purchase_from,{purchase_from:u(n.requirement.purchase_from,t)})}),new Date(n.requirement.purchase_to||0)>new Date&&e({tag:"span",innerHTML:s(r.requirements.purchase_to,{purchase_to:u(n.requirement.purchase_to,t)})})].filter((n=>n)).forEach((n=>i.appendChild(n))),console.log({discount:n,wrapper:i}),i})(n,t);return[i,o,d,c,b,$,v].filter((n=>n)).forEach((n=>r.appendChild(n))),r},v=(n,e)=>{const t=new Headers;return Object.entries({...n,"Dintero-System-Name":"deals-web-sdk","Dintero-System-Version":e.version}).forEach((([n,e])=>{t.append(n,e)})),t},k=n=>(n=>{if(!n.api)throw new Error("Authentication configuration missing");const e=window.btoa(`${n.api.key}:${n.api.secret}`),t=v({Authorization:`Basic ${e}`,"content-type":"application/json"},n),r=JSON.stringify({grant_type:"client_credentials",audience:`${n.api.url}/v1/accounts/${n.api.account}`});return window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/auth/token`,{method:"POST",headers:t,body:r}).then((n=>{if(200===n.status)return n.json();throw new Error("Authentication failed")}))})(n).then((e=>{const t=v({Authorization:`${e.token_type} ${e.access_token}`},n);return n.api.discountId?window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/discounts/public/rules/${n.api.discountId}`,{headers:t}).then((n=>{if(200===n.status)return n.json().then((n=>[n]));throw new Error("Authentication failed")})):window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/discounts/public/rules?limit=${n.api.limit}`,{headers:t}).then((n=>{if(200===n.status)return n.json();throw new Error("Authentication failed")}))})),T=(n,e)=>`\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.${n} {\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: ${e.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n}\n`,q=(n,e)=>`\n.${n} {\n margin: 10px auto;\n display: block;\n width: 80px;\n height: 80px;\n}\n\n.${n}: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`;const M={language:"no",version:"0.2.3",linkTarget:"_self",currency:{value:"Kr",position:"suffix",exponent:2},theme:{background:"#fff",primary:"#333",secondary:"#333",color:"inherit",borderRadius:"2px",fontSize:"inherit"},api:{account:"",key:"",secret:"",url:"https://api.dintero.com",limit:50}},z=(n,e)=>`\n.${n} {\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: ${e.fontSize};\n color: ${e.color};\n}`,E=(n,t)=>{const r=e({tag:"div",styles:[p,z],theme:n.theme});return t.forEach((e=>{const t=$(e,n),i=l(e);i&&(t.setAttribute("target",n?.linkTarget||"_self"),t.setAttribute("href",i.href)),r.appendChild(t)})),n.container.appendChild(r),{destroy:()=>{n.container.removeChild(r)}}};n.embed=async n=>{const t=(r=M,i=n,{...r,...i,currency:{...r.currency,...i.currency},theme:{...r.theme,...i.theme},api:{...r.api,...i.api}});var r,i;if(!t.container||!t.container.appendChild)throw console.error("Invalid configuration"),new Error("Invalid configuration");if(t.discounts)return E(t,t.discounts);{const r=(n=>e({tag:"div",styles:[p,q],theme:n.theme}))(t);try{n.container.appendChild(r);const e=await k(t);return t.container.removeChild(r),E(t,e)}catch(i){n.container.removeChild(r);const o=(n=>{const t=a[n.language];return e({tag:"div",styles:[p,T],theme:n.theme,innerHTML:t.errors.fetch})})(t);return t.container.appendChild(o),{destroy:()=>{n.container.removeChild(o)}}}}},Object.defineProperty(n,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=dintero-discounts-web-sdk.umd.min.js.map
|
package/package.json
CHANGED