@dintero/discounts-web-sdk 0.2.7 → 0.2.8

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.
@@ -3,6 +3,8 @@ name: CI
3
3
  on:
4
4
  pull_request:
5
5
  branches: [master]
6
+ merge_group:
7
+ branches: [master]
6
8
  push:
7
9
  branches:
8
10
  - master
@@ -568,7 +568,7 @@ const createLoading = configuration => {
568
568
 
569
569
  var pkg = {
570
570
  name: "@dintero/discounts-web-sdk",
571
- version: "0.2.7",
571
+ version: "0.2.8",
572
572
  description: "Dintero Discounts SDK for web frontends",
573
573
  main: "dist/dintero-discounts-web-sdk.cjs.js",
574
574
  module: "dist/dintero-discounts-web-sdk.esm.js",
@@ -598,15 +598,15 @@ var pkg = {
598
598
  url: "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
599
599
  },
600
600
  devDependencies: {
601
- "@babel/core": "7.23.9",
602
- "@babel/preset-typescript": "7.23.3",
601
+ "@babel/core": "7.24.4",
602
+ "@babel/preset-typescript": "7.24.1",
603
603
  "@preconstruct/cli": "2.8.3",
604
604
  "@semantic-release/git": "10.0.1",
605
- "happy-dom": "13.3.8",
605
+ "happy-dom": "14.4.0",
606
606
  prettier: "3.2.5",
607
- "semantic-release": "23.0.2",
608
- typescript: "5.3.3",
609
- vitest: "1.3.1"
607
+ "semantic-release": "23.0.7",
608
+ typescript: "5.4.3",
609
+ vitest: "1.4.0"
610
610
  }
611
611
  };
612
612
 
@@ -568,7 +568,7 @@ const createLoading = configuration => {
568
568
 
569
569
  var pkg = {
570
570
  name: "@dintero/discounts-web-sdk",
571
- version: "0.2.7",
571
+ version: "0.2.8",
572
572
  description: "Dintero Discounts SDK for web frontends",
573
573
  main: "dist/dintero-discounts-web-sdk.cjs.js",
574
574
  module: "dist/dintero-discounts-web-sdk.esm.js",
@@ -598,15 +598,15 @@ var pkg = {
598
598
  url: "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
599
599
  },
600
600
  devDependencies: {
601
- "@babel/core": "7.23.9",
602
- "@babel/preset-typescript": "7.23.3",
601
+ "@babel/core": "7.24.4",
602
+ "@babel/preset-typescript": "7.24.1",
603
603
  "@preconstruct/cli": "2.8.3",
604
604
  "@semantic-release/git": "10.0.1",
605
- "happy-dom": "13.3.8",
605
+ "happy-dom": "14.4.0",
606
606
  prettier: "3.2.5",
607
- "semantic-release": "23.0.2",
608
- typescript: "5.3.3",
609
- vitest: "1.3.1"
607
+ "semantic-release": "23.0.7",
608
+ typescript: "5.4.3",
609
+ vitest: "1.4.0"
610
610
  }
611
611
  };
612
612
 
@@ -564,7 +564,7 @@ const createLoading = configuration => {
564
564
 
565
565
  var pkg = {
566
566
  name: "@dintero/discounts-web-sdk",
567
- version: "0.2.7",
567
+ version: "0.2.8",
568
568
  description: "Dintero Discounts SDK for web frontends",
569
569
  main: "dist/dintero-discounts-web-sdk.cjs.js",
570
570
  module: "dist/dintero-discounts-web-sdk.esm.js",
@@ -594,15 +594,15 @@ var pkg = {
594
594
  url: "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
595
595
  },
596
596
  devDependencies: {
597
- "@babel/core": "7.23.9",
598
- "@babel/preset-typescript": "7.23.3",
597
+ "@babel/core": "7.24.4",
598
+ "@babel/preset-typescript": "7.24.1",
599
599
  "@preconstruct/cli": "2.8.3",
600
600
  "@semantic-release/git": "10.0.1",
601
- "happy-dom": "13.3.8",
601
+ "happy-dom": "14.4.0",
602
602
  prettier: "3.2.5",
603
- "semantic-release": "23.0.2",
604
- typescript: "5.3.3",
605
- vitest: "1.3.1"
603
+ "semantic-release": "23.0.7",
604
+ typescript: "5.4.3",
605
+ vitest: "1.4.0"
606
606
  }
607
607
  };
608
608
 
@@ -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))),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.7",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))),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.8",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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dintero/discounts-web-sdk",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
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",
@@ -30,14 +30,14 @@
30
30
  "url": "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
31
31
  },
32
32
  "devDependencies": {
33
- "@babel/core": "7.23.9",
34
- "@babel/preset-typescript": "7.23.3",
33
+ "@babel/core": "7.24.4",
34
+ "@babel/preset-typescript": "7.24.1",
35
35
  "@preconstruct/cli": "2.8.3",
36
36
  "@semantic-release/git": "10.0.1",
37
- "happy-dom": "13.3.8",
37
+ "happy-dom": "14.4.0",
38
38
  "prettier": "3.2.5",
39
- "semantic-release": "23.0.2",
40
- "typescript": "5.3.3",
41
- "vitest": "1.3.1"
39
+ "semantic-release": "23.0.7",
40
+ "typescript": "5.4.3",
41
+ "vitest": "1.4.0"
42
42
  }
43
43
  }
@@ -1,2 +0,0 @@
1
- import { Configuration, Embed } from "./types.js";
2
- export declare const embed: (configuration: Configuration) => Promise<Embed>;
@@ -1,606 +0,0 @@
1
- export interface Item {
2
- /**
3
- * example:
4
- * b714118
5
- */
6
- id?: string;
7
- /**
8
- * example:
9
- * B1
10
- */
11
- group_id?: string;
12
- }
13
- export interface Limitation {
14
- /**
15
- * Limit the discount to hours of the day
16
- *
17
- */
18
- discount_hours?: {
19
- /**
20
- * The timezone identifier for the hour start/end, see
21
- * https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
22
- * for examples. DST is handled when using a Timezone with DST.
23
- *
24
- */
25
- timezone?: string;
26
- /**
27
- * an array of periods, day and time when discount will be
28
- * available. Multiple periods for one day is accepted.
29
- * Any hour of purchase is accepted if the array is empty.
30
- *
31
- */
32
- hours: {
33
- day: "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun";
34
- /**
35
- * example:
36
- * 10:00
37
- */
38
- start: string; // ^([01]?[0-9]|2[0-3]):[0-5][0-9]$
39
- /**
40
- * example:
41
- * 20:00
42
- */
43
- end: string; // ^([01]?[0-9]|2[0-3]):[0-5][0-9]$
44
- }[];
45
- };
46
- /**
47
- * Limit the number of rewards to be given in a purchase
48
- * where multiple receipt items match the requirement
49
- *
50
- * example:
51
- * 1
52
- */
53
- discount_reward_usage?: number;
54
- /**
55
- * Limit how many other discounts can be combined in a purchase
56
- * where multiple discounts are applicable.
57
- *
58
- */
59
- discount_combination?: -1 | 0;
60
- /**
61
- * Limit what items in the purchase is eligible for this discount
62
- *
63
- */
64
- discount_eligible?:
65
- | "item_eligible_for_discount"
66
- | "item_eligible_for_discount_no_discount"
67
- | "receipt_no_discount";
68
- /**
69
- * Limit how many purchases the discount can be used
70
- *
71
- */
72
- discount_repeat_usage?: number;
73
- /**
74
- * Number of days between first and last (exceeding count) stamp
75
- * where reward will be given
76
- *
77
- * example:
78
- * 100
79
- */
80
- stamp_expire_days?: number;
81
- /**
82
- * items not eligible for discount.
83
- *
84
- */
85
- blacklist?: Item[];
86
- }
87
- /**
88
- * Links to resources related to the discount
89
- * example:
90
- * [object Object],[object Object],[object Object],[object Object]
91
- */
92
- export type Links = {
93
- /**
94
- * The URL of the link.
95
- */
96
- href: string; // uri
97
- /**
98
- * Specifies the relationship between the discount and the link
99
- *
100
- * Following `rel` values are reserved for specific usage
101
- *
102
- * - thumbnail_discount_image: link to discount image
103
- * - medium_discount_image: link to discount image
104
- * - large_discount_image: link to discount image
105
- * - webshop: link to site where the discount may be used
106
- *
107
- */
108
- rel?: string;
109
- /**
110
- * Specifies the media type of the link
111
- */
112
- type?: string;
113
- }[];
114
- export interface StoreRequirement {
115
- id?: string[];
116
- /**
117
- * name of the store, aka trade name of the store
118
- *
119
- */
120
- name?: string[];
121
- /**
122
- * Official name of the person or entity that owns the store.
123
- *
124
- */
125
- business_name?: string[];
126
- /**
127
- * Require customer to have one or more addresses matching the properties. All properties defined must match a single address.
128
- */
129
- address?: {
130
- /**
131
- * example:
132
- * NO
133
- */
134
- country?: string[];
135
- /**
136
- * example:
137
- * 4515
138
- */
139
- postal_code?: string[];
140
- /**
141
- * example:
142
- * Oslo
143
- */
144
- postal_place?: string[];
145
- };
146
- chain?: string[];
147
- email?: string[];
148
- gln?: string[];
149
- organization_number?: string[];
150
- phone_number?: string[];
151
- /**
152
- * A four-digit Merchant Category Code (MCC) for the store
153
- * [ISO 18245:2003](https://www.iso.org/standard/33365.html)
154
- *
155
- */
156
- mcc?: string /* iso-18245 */[];
157
- /**
158
- * Ranges of MCC codes to accept the discount for.
159
- * Multiple ranges are possible.
160
- * Prefer `mcc` if not a range.
161
- *
162
- */
163
- mcc_ranges?: {
164
- /**
165
- * example:
166
- * 5814
167
- */
168
- start: string; // iso-18245 ^\d{4}$
169
- /**
170
- * example:
171
- * 5815
172
- */
173
- end: string; // iso-18245 ^\d{4}$
174
- }[];
175
- /**
176
- * Merchant number associated with the stores
177
- * payment terminal
178
- *
179
- */
180
- bax?: string[];
181
- /**
182
- * Id to a specific point-of-sale (POS) terminal
183
- * or workstation
184
- *
185
- */
186
- terminal_id?: string[];
187
- }
188
- export interface ItemMixProperty {
189
- /**
190
- * Acceptable items for the mix "item" (`any`). No wildcard `*` is
191
- * accepted.
192
- *
193
- * example:
194
- * [object Object],[object Object]
195
- */
196
- items?: {
197
- /**
198
- * example:
199
- * b714118
200
- */
201
- id?: string; // ^(\*.+|(?!\*).*)$
202
- /**
203
- * example:
204
- * g4
205
- */
206
- group_id?: string; // ^(\*.+|(?!\*).*)$
207
- }[];
208
- /**
209
- * minimum quantity of given item (match by id or group) by the mix
210
- *
211
- */
212
- quantity: number;
213
- /**
214
- * The item will be eligible for discount when calculating the reward
215
- * Example: The value of `discount_item_new_price` reward will be the
216
- * total price of all items in a mix that has the applicable set to `true`
217
- *
218
- */
219
- reward_eligible: boolean;
220
- }
221
-
222
- export interface CustomerRequirement {
223
- /**
224
- * Require customer to have one or more addresses matching the properties. All properties defined must match a single address.
225
- */
226
- addresses?: {
227
- /**
228
- * example:
229
- * NO
230
- */
231
- country?: string[];
232
- /**
233
- * example:
234
- * 4515
235
- */
236
- postal_code?: string[];
237
- /**
238
- * example:
239
- * Oslo
240
- */
241
- postal_place?: string[];
242
- /**
243
- * example:
244
- * offsite
245
- */
246
- custom_type?: string[];
247
- /**
248
- * example:
249
- * custom
250
- */
251
- type?: string[];
252
- }[];
253
- /**
254
- * Require customer to be a company matching all properties defined.
255
- *
256
- */
257
- company?: {
258
- /**
259
- * example:
260
- * TKP tech AS
261
- */
262
- bussiness_name?: string[];
263
- /**
264
- * example:
265
- * production,research
266
- */
267
- department?: string[];
268
- /**
269
- * example:
270
- * J62.0.1,J62.0.2
271
- */
272
- industry?: string[];
273
- /**
274
- * example:
275
- * 20
276
- */
277
- number_of_employees?: string[];
278
- /**
279
- * example:
280
- * 123456789MVA
281
- */
282
- organization_number?: string[];
283
- /**
284
- * example:
285
- * https://dintero.com
286
- */
287
- website?: string[];
288
- };
289
- /**
290
- * example:
291
- * 1990-09-20,1990-05-10
292
- */
293
- date_of_birth?: string[];
294
- enrolled_by?: {
295
- /**
296
- * example:
297
- * url
298
- */
299
- type?: string[];
300
- /**
301
- * example:
302
- * https://mypage.example.dintero.com
303
- */
304
- value?: string[];
305
- };
306
- /**
307
- * example:
308
- * sc029
309
- */
310
- favorite_store?: string[];
311
- /**
312
- * example:
313
- * John
314
- */
315
- first_name?: string[];
316
- /**
317
- * example:
318
- * male
319
- */
320
- gender?: string[];
321
- /**
322
- * example:
323
- * Doe
324
- */
325
- last_name?: string[];
326
- marketing_consent?: {
327
- email?: {
328
- /**
329
- * example:
330
- * true
331
- */
332
- consent?: string[];
333
- };
334
- sms?: {
335
- /**
336
- * example:
337
- * true
338
- */
339
- consent?: string[];
340
- };
341
- };
342
- /**
343
- * limit discount to only receipt where customer status
344
- * is included in the receipt and match one of the status
345
- * values required by the discount
346
- *
347
- * example:
348
- * vip
349
- */
350
- status?: string[];
351
- term?: {
352
- id?: string[];
353
- };
354
- type?: string[];
355
- }
356
- export interface Requirement {
357
- customer?: CustomerRequirement;
358
- item?: {
359
- /**
360
- * minimum number of items
361
- *
362
- */
363
- quantity?: number;
364
- /**
365
- * Required mix items for the discount.
366
- *
367
- * A purchase must include `all` the items to fulfill the `item.mixes`
368
- * requirement.
369
- *
370
- */
371
- mixes?: ItemMixProperty[];
372
- /**
373
- * Required items for the discount
374
- *
375
- * A purchase can include `any` of the items to fulfill the `item.items`
376
- * requirement.
377
- *
378
- */
379
- items?: Item[];
380
- };
381
- store_ids?: string[];
382
- /**
383
- * Minimum gross amount on purchase.
384
- * Monetary amount in smallest unit for the currency
385
- *
386
- */
387
- gross_amount?: number;
388
- /**
389
- * List of valid currencies, or `[{"anything-but": ["NOK"]}]` to exclude currencies.
390
- * Currency format is the three-character [ISO-4217 currency](https://en.wikipedia.org/wiki/ISO_4217).
391
- *
392
- */
393
- currencies?: any[];
394
- /**
395
- * Stamp count required for the reward
396
- *
397
- * example:
398
- * 5
399
- */
400
- stamp?: number;
401
- /**
402
- * A code required for the reward. The purchase must include the
403
- * promotion code in the `receipt.discount_code` property or as
404
- * an `receipt.item` where the `item.id` is the promotion code.
405
- *
406
- * example:
407
- * TACO
408
- */
409
- discount_code?: string;
410
- store?: StoreRequirement;
411
- purchase_from: string; // date-time
412
- purchase_to: string; // date-time
413
- }
414
- export interface Reward {
415
- /**
416
- *
417
- * Reward Type:
418
- * * `discount_amount` - value as discount
419
- * * `discount_percent` - value percentage of gross amount
420
- * as discount
421
- * * `discount_item_new_price` - discount as old price subtracted with value
422
- * * `discount_item_quantity` - number of items to get as discount (free)
423
- * * `discount_item_percent` - percent discount of the cheapest item (stamp)
424
- * as discount
425
- * * `discount_debit` - value as discount, remaining amount after a
426
- * purchase will be available in future purchases (if not limited by usage)
427
- * * `discount_mix_new_price` - discount as old mix total value (reward_eligible=true)
428
- * subtracted with value
429
- *
430
- */
431
- type:
432
- | "discount_amount"
433
- | "discount_percent"
434
- | "discount_item_new_price"
435
- | "discount_item_quantity"
436
- | "discount_item_percent"
437
- | "discount_mix_new_price"
438
- | "discount_debit";
439
- /**
440
- * The reward value, unit of the value is resolved
441
- * from the reward type
442
- *
443
- * Examples:
444
- * - Percent: 10.5
445
- * - Amount: 10000 (amount in smallest unit for the currency)
446
- * - Quantity: 1
447
- *
448
- * example:
449
- * 10000
450
- */
451
- value: number;
452
- /**
453
- * Let the discount reward be calculated from net or gross price.
454
- * Not applicable for `discount_item_new_price`
455
- *
456
- * *Example*:
457
- * item A à 100,- NOK with existing rebate of 20,-
458
- *
459
- * - 10% net reward is 10% of 80,- : 8,-
460
- * - 10% gross reward is 10% of 100,- : 10,-
461
- *
462
- * * *net*: `gross - "any existing discounts"`
463
- * * *gross*: `"total expense amount, including taxes"`
464
- *
465
- */
466
- base?: "net" | "gross";
467
- }
468
- export interface Discount {
469
- /**
470
- * An UUID that uniquely identifies the resource
471
- *
472
- */
473
- readonly id?: string; // uuid
474
- /**
475
- * The date-time when the resource was created
476
- *
477
- */
478
- readonly created_at?: string; // date-time
479
- /**
480
- * The ID of the user/client created the resource
481
- *
482
- * example:
483
- * 1c92f7e1-2897-4d46-bdcc-c127a914fb4e
484
- */
485
- readonly created_by?: string;
486
- /**
487
- * The date-time when the resource was last updated
488
- *
489
- */
490
- readonly updated_at?: string; // date-time
491
- /**
492
- * The ID of the user/client created the resource
493
- *
494
- * example:
495
- * 1c92f7e1-2897-4d46-bdcc-c127a914fb4e
496
- */
497
- readonly deleted_by?: string;
498
- readonly deleted_at?: string; // date-time
499
- /**
500
- * The campaign the rule belongs to
501
- *
502
- */
503
- campaign_id?: string;
504
- /**
505
- * the discount is active and can be available
506
- * for purchase (if given to any or all customers)
507
- *
508
- */
509
- active?: boolean;
510
- /**
511
- * the discount will be exluded from public discount collection
512
- * (GET /discounts/public/rules).
513
- *
514
- */
515
- private?: boolean;
516
- /**
517
- * The ID of the user/client that last updated the resource
518
- *
519
- * example:
520
- * 3d1e4824-5474-48e7-a369-4f603fa4c5b8
521
- */
522
- readonly updated_by?: string;
523
- /**
524
- * The discount base type * `receipt` discount is given on receipt * `item` discount is given to items
525
- */
526
- readonly type?: "item" | "receipt";
527
- /**
528
- * example:
529
- * Spar 100,-
530
- */
531
- name?: string;
532
- /**
533
- * Text that should be used when displaying
534
- * the discount, e.g. on receipt
535
- *
536
- * example:
537
- * Mai Salg
538
- */
539
- receipt_text?: string;
540
- /**
541
- * Make th discount visible to the customer from
542
- * given date. Default behavior is to only return
543
- * discount to the customer where the current time
544
- * is between purchase_from and purchase_to
545
- *
546
- */
547
- visible_from?: string; // date-time
548
- /**
549
- * example:
550
- * Gjør et Stablestol kupp!
551
- */
552
- description?: string;
553
- limitation?: Limitation;
554
- requirement: Requirement;
555
- reward: Reward;
556
- /**
557
- * Additional metadata about the discount
558
- *
559
- * example:
560
- * [object Object]
561
- */
562
- metadata?: {
563
- [key: string]: any;
564
- };
565
- links?: Links;
566
- }
567
-
568
- export type Theme = {
569
- color?: string;
570
- background?: string;
571
- primary?: string;
572
- secondary?: string;
573
- borderRadius?: string;
574
- fontSize?: string;
575
- };
576
-
577
- export type Configuration = {
578
- container: HTMLElement;
579
- language?: string;
580
- currency?: {
581
- value: string;
582
- position: "prefix" | "suffix";
583
- exponent: 2;
584
- };
585
- theme?: Theme;
586
- api?: {
587
- account: string;
588
- key: string;
589
- secret: string;
590
- url: string;
591
- limit?: number;
592
- discountId?: string;
593
- };
594
- linkTarget?: "_blank" | "_self";
595
- version?: string;
596
- discounts?: Discount[];
597
- };
598
-
599
- type TokenResponse = {
600
- access_token: string;
601
- token_type: string;
602
- };
603
-
604
- export type Embed = {
605
- destroy: () => void;
606
- };