@dintero/discounts-web-sdk 0.2.4 → 0.2.5
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/.github/workflows/build.yml +14 -10
- package/.github/workflows/release.yml +6 -6
- package/README.md +2 -2
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/dintero-discounts-web-sdk.cjs.d.ts +1 -0
- package/dist/dintero-discounts-web-sdk.cjs.d.ts.map +1 -0
- package/dist/dintero-discounts-web-sdk.cjs.dev.js +12 -25
- package/dist/dintero-discounts-web-sdk.cjs.prod.js +12 -25
- package/dist/dintero-discounts-web-sdk.esm.js +12 -25
- package/dist/dintero-discounts-web-sdk.umd.min.js +1 -1
- package/dist/dintero-discounts-web-sdk.umd.min.js.map +1 -1
- package/package.json +12 -21
- package/dist/declarations/src/discounts.d.ts +0 -7
- package/dist/declarations/src/dom.d.ts +0 -15
- package/dist/declarations/src/error.d.ts +0 -2
- package/dist/declarations/src/fetch.d.ts +0 -2
- package/dist/declarations/src/formatters.d.ts +0 -7
- package/dist/declarations/src/loading.d.ts +0 -2
- package/dist/declarations/src/normalize.d.ts +0 -1
- package/dist/declarations/src/translations.d.ts +0 -25
- package/karma.conf.js +0 -33
|
@@ -11,13 +11,17 @@ jobs:
|
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
12
|
|
|
13
13
|
steps:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
- name: Checkout
|
|
15
|
+
uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Setup Node.js
|
|
18
|
+
uses: actions/setup-node@v3
|
|
19
|
+
with:
|
|
20
|
+
node-version: 'lts/*'
|
|
21
|
+
cache: yarn
|
|
22
|
+
|
|
23
|
+
- name: yarn install, build and test
|
|
24
|
+
run: |
|
|
25
|
+
yarn install
|
|
26
|
+
yarn run test
|
|
27
|
+
yarn run build
|
|
@@ -18,22 +18,22 @@ jobs:
|
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
20
|
- name: Checkout
|
|
21
|
-
uses: actions/checkout@
|
|
21
|
+
uses: actions/checkout@v3
|
|
22
22
|
with:
|
|
23
23
|
fetch-depth: 0
|
|
24
24
|
|
|
25
25
|
- name: Setup Node.js
|
|
26
|
-
uses: actions/setup-node@
|
|
26
|
+
uses: actions/setup-node@v3
|
|
27
27
|
with:
|
|
28
28
|
node-version: 'lts/*'
|
|
29
29
|
|
|
30
|
-
- name:
|
|
30
|
+
- name: yarn install and test
|
|
31
31
|
run: |
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
yarn install
|
|
33
|
+
yarn run test
|
|
34
34
|
|
|
35
35
|
- name: Release
|
|
36
36
|
env:
|
|
37
37
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
38
38
|
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
|
39
|
-
run:
|
|
39
|
+
run: yarn run semantic-release
|
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Configuration, Embed } from "./types";
|
|
1
|
+
import { Configuration, Embed } from "./types.js";
|
|
2
2
|
export declare const embed: (configuration: Configuration) => Promise<Embed>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dintero-discounts-web-sdk.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -391,10 +391,6 @@ const createLimitations = (discount, configuration) => {
|
|
|
391
391
|
});
|
|
392
392
|
const children = [quantity, repeat, start, end].filter(child => child);
|
|
393
393
|
children.forEach(child => wrapper.appendChild(child));
|
|
394
|
-
console.log({
|
|
395
|
-
discount,
|
|
396
|
-
wrapper
|
|
397
|
-
});
|
|
398
394
|
return wrapper;
|
|
399
395
|
};
|
|
400
396
|
const createDiscount = (discount, configuration) => {
|
|
@@ -572,7 +568,7 @@ const createLoading = configuration => {
|
|
|
572
568
|
|
|
573
569
|
var pkg = {
|
|
574
570
|
name: "@dintero/discounts-web-sdk",
|
|
575
|
-
version: "0.2.
|
|
571
|
+
version: "0.2.5",
|
|
576
572
|
description: "Dintero Discounts SDK for web frontends",
|
|
577
573
|
main: "dist/dintero-discounts-web-sdk.cjs.js",
|
|
578
574
|
module: "dist/dintero-discounts-web-sdk.esm.js",
|
|
@@ -583,10 +579,10 @@ var pkg = {
|
|
|
583
579
|
umdName: "discounts"
|
|
584
580
|
},
|
|
585
581
|
scripts: {
|
|
586
|
-
test: "
|
|
582
|
+
test: "vitest --dom",
|
|
587
583
|
watch: "preconstruct watch",
|
|
588
584
|
build: "preconstruct build",
|
|
589
|
-
prepublishOnly: "
|
|
585
|
+
prepublishOnly: "yarn build",
|
|
590
586
|
"semantic-release": "semantic-release"
|
|
591
587
|
},
|
|
592
588
|
"private": false,
|
|
@@ -601,24 +597,15 @@ var pkg = {
|
|
|
601
597
|
url: "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
|
|
602
598
|
},
|
|
603
599
|
devDependencies: {
|
|
604
|
-
"@babel/
|
|
605
|
-
"@babel/preset-typescript": "
|
|
606
|
-
"@preconstruct/cli": "
|
|
607
|
-
"@semantic-release/git": "
|
|
608
|
-
"
|
|
609
|
-
|
|
610
|
-
"
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
"ts-jest": "^29.0.5",
|
|
614
|
-
typescript: "^4.2.4"
|
|
615
|
-
},
|
|
616
|
-
jest: {
|
|
617
|
-
preset: "ts-jest",
|
|
618
|
-
testMatch: [
|
|
619
|
-
"**/test/**/*.test.ts"
|
|
620
|
-
],
|
|
621
|
-
testEnvironment: "jsdom"
|
|
600
|
+
"@babel/core": "7.13.0",
|
|
601
|
+
"@babel/preset-typescript": "7.13.0",
|
|
602
|
+
"@preconstruct/cli": "2.8.1",
|
|
603
|
+
"@semantic-release/git": "10.0.1",
|
|
604
|
+
"happy-dom": "12.9.0",
|
|
605
|
+
prettier: "3.0.3",
|
|
606
|
+
"semantic-release": "22.0.5",
|
|
607
|
+
typescript: "5.2.2",
|
|
608
|
+
vitest: "0.34.6"
|
|
622
609
|
}
|
|
623
610
|
};
|
|
624
611
|
|
|
@@ -391,10 +391,6 @@ const createLimitations = (discount, configuration) => {
|
|
|
391
391
|
});
|
|
392
392
|
const children = [quantity, repeat, start, end].filter(child => child);
|
|
393
393
|
children.forEach(child => wrapper.appendChild(child));
|
|
394
|
-
console.log({
|
|
395
|
-
discount,
|
|
396
|
-
wrapper
|
|
397
|
-
});
|
|
398
394
|
return wrapper;
|
|
399
395
|
};
|
|
400
396
|
const createDiscount = (discount, configuration) => {
|
|
@@ -572,7 +568,7 @@ const createLoading = configuration => {
|
|
|
572
568
|
|
|
573
569
|
var pkg = {
|
|
574
570
|
name: "@dintero/discounts-web-sdk",
|
|
575
|
-
version: "0.2.
|
|
571
|
+
version: "0.2.5",
|
|
576
572
|
description: "Dintero Discounts SDK for web frontends",
|
|
577
573
|
main: "dist/dintero-discounts-web-sdk.cjs.js",
|
|
578
574
|
module: "dist/dintero-discounts-web-sdk.esm.js",
|
|
@@ -583,10 +579,10 @@ var pkg = {
|
|
|
583
579
|
umdName: "discounts"
|
|
584
580
|
},
|
|
585
581
|
scripts: {
|
|
586
|
-
test: "
|
|
582
|
+
test: "vitest --dom",
|
|
587
583
|
watch: "preconstruct watch",
|
|
588
584
|
build: "preconstruct build",
|
|
589
|
-
prepublishOnly: "
|
|
585
|
+
prepublishOnly: "yarn build",
|
|
590
586
|
"semantic-release": "semantic-release"
|
|
591
587
|
},
|
|
592
588
|
"private": false,
|
|
@@ -601,24 +597,15 @@ var pkg = {
|
|
|
601
597
|
url: "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
|
|
602
598
|
},
|
|
603
599
|
devDependencies: {
|
|
604
|
-
"@babel/
|
|
605
|
-
"@babel/preset-typescript": "
|
|
606
|
-
"@preconstruct/cli": "
|
|
607
|
-
"@semantic-release/git": "
|
|
608
|
-
"
|
|
609
|
-
|
|
610
|
-
"
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
"ts-jest": "^29.0.5",
|
|
614
|
-
typescript: "^4.2.4"
|
|
615
|
-
},
|
|
616
|
-
jest: {
|
|
617
|
-
preset: "ts-jest",
|
|
618
|
-
testMatch: [
|
|
619
|
-
"**/test/**/*.test.ts"
|
|
620
|
-
],
|
|
621
|
-
testEnvironment: "jsdom"
|
|
600
|
+
"@babel/core": "7.13.0",
|
|
601
|
+
"@babel/preset-typescript": "7.13.0",
|
|
602
|
+
"@preconstruct/cli": "2.8.1",
|
|
603
|
+
"@semantic-release/git": "10.0.1",
|
|
604
|
+
"happy-dom": "12.9.0",
|
|
605
|
+
prettier: "3.0.3",
|
|
606
|
+
"semantic-release": "22.0.5",
|
|
607
|
+
typescript: "5.2.2",
|
|
608
|
+
vitest: "0.34.6"
|
|
622
609
|
}
|
|
623
610
|
};
|
|
624
611
|
|
|
@@ -387,10 +387,6 @@ const createLimitations = (discount, configuration) => {
|
|
|
387
387
|
});
|
|
388
388
|
const children = [quantity, repeat, start, end].filter(child => child);
|
|
389
389
|
children.forEach(child => wrapper.appendChild(child));
|
|
390
|
-
console.log({
|
|
391
|
-
discount,
|
|
392
|
-
wrapper
|
|
393
|
-
});
|
|
394
390
|
return wrapper;
|
|
395
391
|
};
|
|
396
392
|
const createDiscount = (discount, configuration) => {
|
|
@@ -568,7 +564,7 @@ const createLoading = configuration => {
|
|
|
568
564
|
|
|
569
565
|
var pkg = {
|
|
570
566
|
name: "@dintero/discounts-web-sdk",
|
|
571
|
-
version: "0.2.
|
|
567
|
+
version: "0.2.5",
|
|
572
568
|
description: "Dintero Discounts SDK for web frontends",
|
|
573
569
|
main: "dist/dintero-discounts-web-sdk.cjs.js",
|
|
574
570
|
module: "dist/dintero-discounts-web-sdk.esm.js",
|
|
@@ -579,10 +575,10 @@ var pkg = {
|
|
|
579
575
|
umdName: "discounts"
|
|
580
576
|
},
|
|
581
577
|
scripts: {
|
|
582
|
-
test: "
|
|
578
|
+
test: "vitest --dom",
|
|
583
579
|
watch: "preconstruct watch",
|
|
584
580
|
build: "preconstruct build",
|
|
585
|
-
prepublishOnly: "
|
|
581
|
+
prepublishOnly: "yarn build",
|
|
586
582
|
"semantic-release": "semantic-release"
|
|
587
583
|
},
|
|
588
584
|
"private": false,
|
|
@@ -597,24 +593,15 @@ var pkg = {
|
|
|
597
593
|
url: "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
|
|
598
594
|
},
|
|
599
595
|
devDependencies: {
|
|
600
|
-
"@babel/
|
|
601
|
-
"@babel/preset-typescript": "
|
|
602
|
-
"@preconstruct/cli": "
|
|
603
|
-
"@semantic-release/git": "
|
|
604
|
-
"
|
|
605
|
-
|
|
606
|
-
"
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
"ts-jest": "^29.0.5",
|
|
610
|
-
typescript: "^4.2.4"
|
|
611
|
-
},
|
|
612
|
-
jest: {
|
|
613
|
-
preset: "ts-jest",
|
|
614
|
-
testMatch: [
|
|
615
|
-
"**/test/**/*.test.ts"
|
|
616
|
-
],
|
|
617
|
-
testEnvironment: "jsdom"
|
|
596
|
+
"@babel/core": "7.13.0",
|
|
597
|
+
"@babel/preset-typescript": "7.13.0",
|
|
598
|
+
"@preconstruct/cli": "2.8.1",
|
|
599
|
+
"@semantic-release/git": "10.0.1",
|
|
600
|
+
"happy-dom": "12.9.0",
|
|
601
|
+
prettier: "3.0.3",
|
|
602
|
+
"semantic-release": "22.0.5",
|
|
603
|
+
typescript: "5.2.2",
|
|
604
|
+
vitest: "0.34.6"
|
|
618
605
|
}
|
|
619
606
|
};
|
|
620
607
|
|
|
@@ -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.4",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.5",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
|
|
@@ -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 console.log({discount, wrapper});\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","split","includes","addClass","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","tStrings","reward","type","requirement","item","quantity","require","payFor","monetaryAmount","getBottomRibbonText","createDiscount","discountElem","ribbonTop","metadata","label","undefined","getTopRibbonText","createTopRibbon","ribbonBottom","image","imageWrapper","imageSrc","link","src","href","alt","name","loading","createImage","title","subtitle","description","wrapper","limitation","filter","child","console","log","createLimitations","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","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,EAAY,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,IArBxD,EAACT,EAAkBa,KAClBb,EAAKa,UAAUO,MAAM,KACxBC,SAASR,KAChBb,EAAKa,UAAYb,EAAKa,UAAY,IAAMA,EAC5C,EAkBIS,CAAStB,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,EAAgB,CAACJ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5C,OAPkBhF,EAAc,CAC5BI,IAAK,MACLK,OAAQ,CAACmF,EAAW6F,GACpB9K,MAAOmD,EAAcnD,MACrBC,UAAWkM,EAAQ/J,OAAOC,OAGd,EEqCa+J,CAAYR,GAEjC,OADAA,EAAeJ,UAAUtK,YAAYgL,GAC9B,CACHT,QAAS,KACLtI,EAAcqI,UAAUE,YAAYQ,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 = (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,E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CAAC,MAAMW,GACJ5I,EAAcmI,UAAUE,YAAYQ,GACpC,MAAME,EF/Cd/I,KAEA,MAAMgJ,EAAW5K,EAAa4B,EAAckB,UAQ5C,OAPkBhF,EAAc,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dintero/discounts-web-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
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",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"umdName": "discounts"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"test": "
|
|
14
|
+
"test": "vitest --dom",
|
|
15
15
|
"watch": "preconstruct watch",
|
|
16
16
|
"build": "preconstruct build",
|
|
17
|
-
"prepublishOnly": "
|
|
17
|
+
"prepublishOnly": "yarn build",
|
|
18
18
|
"semantic-release": "semantic-release"
|
|
19
19
|
},
|
|
20
20
|
"private": false,
|
|
@@ -29,23 +29,14 @@
|
|
|
29
29
|
"url": "https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@babel/
|
|
33
|
-
"@babel/preset-typescript": "
|
|
34
|
-
"@preconstruct/cli": "
|
|
35
|
-
"@semantic-release/git": "
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"ts-jest": "^29.0.5",
|
|
42
|
-
"typescript": "^4.2.4"
|
|
43
|
-
},
|
|
44
|
-
"jest": {
|
|
45
|
-
"preset": "ts-jest",
|
|
46
|
-
"testMatch": [
|
|
47
|
-
"**/test/**/*.test.ts"
|
|
48
|
-
],
|
|
49
|
-
"testEnvironment": "jsdom"
|
|
32
|
+
"@babel/core": "7.13.0",
|
|
33
|
+
"@babel/preset-typescript": "7.13.0",
|
|
34
|
+
"@preconstruct/cli": "2.8.1",
|
|
35
|
+
"@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"
|
|
50
41
|
}
|
|
51
42
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Discount, Configuration } from "./types";
|
|
2
|
-
export declare const findWebshopLink: (discount: Discount) => {
|
|
3
|
-
href: string;
|
|
4
|
-
rel?: string;
|
|
5
|
-
type?: string;
|
|
6
|
-
};
|
|
7
|
-
export declare const createDiscount: (discount: Discount, configuration: Configuration) => HTMLElement;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Theme } from './types';
|
|
2
|
-
type CreateElementOptions = {
|
|
3
|
-
tag: string;
|
|
4
|
-
attributes?: {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
};
|
|
7
|
-
styles?: ((className: string, theme?: Theme) => string)[];
|
|
8
|
-
handlers?: {
|
|
9
|
-
[key: string]: EventListenerOrEventListenerObject;
|
|
10
|
-
};
|
|
11
|
-
innerHTML?: string;
|
|
12
|
-
theme?: Theme;
|
|
13
|
-
};
|
|
14
|
-
export declare const createElement: (options: CreateElementOptions) => HTMLElement;
|
|
15
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Configuration } from './types';
|
|
2
|
-
export declare const monetaryString: (amount: number, configuration: Configuration, options?: {
|
|
3
|
-
decimal?: boolean;
|
|
4
|
-
currency?: boolean;
|
|
5
|
-
variant?: 'short';
|
|
6
|
-
}) => string;
|
|
7
|
-
export declare const dateString: (isoString: string, configuration: Configuration) => string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const normalize: (className: string) => string;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export declare const translations: {
|
|
2
|
-
no: {
|
|
3
|
-
rewards: {
|
|
4
|
-
discount_item_quantity: {
|
|
5
|
-
three_for_two: string;
|
|
6
|
-
generic: string;
|
|
7
|
-
};
|
|
8
|
-
discount_amount: string;
|
|
9
|
-
};
|
|
10
|
-
limitations: {
|
|
11
|
-
discount_reward_usage: string;
|
|
12
|
-
discount_repeat_usage: string;
|
|
13
|
-
};
|
|
14
|
-
requirements: {
|
|
15
|
-
purchase_from: string;
|
|
16
|
-
purchase_to: string;
|
|
17
|
-
};
|
|
18
|
-
errors: {
|
|
19
|
-
fetch: string;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
export declare const t: (translateString: string, values?: {
|
|
24
|
-
[key: string]: any;
|
|
25
|
-
}) => string;
|
package/karma.conf.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const puppeteer = require("puppeteer");
|
|
2
|
-
|
|
3
|
-
process.env.CHROME_BIN = puppeteer.executablePath();
|
|
4
|
-
|
|
5
|
-
module.exports = function(config) {
|
|
6
|
-
config.set({
|
|
7
|
-
frameworks: ["mocha", "chai", "karma-typescript"],
|
|
8
|
-
browsers: ["ChromeHeadless"],
|
|
9
|
-
preprocessors: {
|
|
10
|
-
"**/*.ts": "karma-typescript",
|
|
11
|
-
},
|
|
12
|
-
reporters: ["progress", "karma-typescript"],
|
|
13
|
-
basePath: process.cwd(),
|
|
14
|
-
colors: true,
|
|
15
|
-
files: ["test/**/*.ts", "src/**/*.ts"],
|
|
16
|
-
port: 9999,
|
|
17
|
-
singleRun: true,
|
|
18
|
-
concurrency: Infinity,
|
|
19
|
-
// logLevel: config.LOG_DEBUG,
|
|
20
|
-
karmaTypescriptConfig: {
|
|
21
|
-
tsconfig: "./tsconfig.json",
|
|
22
|
-
compilerOptions: {
|
|
23
|
-
emitDecoratorMetadata: true,
|
|
24
|
-
experimentalDecorators: true,
|
|
25
|
-
jsx: "react",
|
|
26
|
-
module: "commonjs",
|
|
27
|
-
sourceMap: true,
|
|
28
|
-
target: "ES5",
|
|
29
|
-
},
|
|
30
|
-
exclude: ["node_modules"],
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
};
|