@dintero/discounts-web-sdk 0.1.0 → 0.2.0
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/README.md +34 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/base.css +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/block-navigation.js +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/discounts.ts.html +24 -12
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/dom.ts.html +4 -4
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/error.ts.html +1 -1
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/favicon.png +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/fetch.ts.html +1 -1
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/formatters.ts.html +1 -1
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/index.html +26 -26
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/index.ts.html +31 -10
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/loading.ts.html +1 -1
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/normalize.ts.html +1 -1
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/prettify.css +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/prettify.js +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/sort-arrow-sprite.png +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/sorter.js +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 106.0.5249.0 (Linux x86_64)}/html/translations.ts.html +1 -1
- package/dist/declarations/src/discounts.d.ts +5 -0
- package/dist/declarations/src/types.d.ts +1 -0
- package/dist/dintero-discounts-web-sdk.cjs.dev.js +16 -3
- package/dist/dintero-discounts-web-sdk.cjs.prod.js +16 -3
- package/dist/dintero-discounts-web-sdk.esm.js +16 -3
- package/dist/dintero-discounts-web-sdk.umd.min.js +1 -1
- package/dist/dintero-discounts-web-sdk.umd.min.js.map +1 -1
- package/index.html +4 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -120,6 +120,40 @@ In this example the SDK is supplied with a list of discount objects directly.
|
|
|
120
120
|
});
|
|
121
121
|
</script>
|
|
122
122
|
```
|
|
123
|
+
|
|
124
|
+
### Inline HTML JavaScript example with discount webshop links and their link behaviour
|
|
125
|
+
|
|
126
|
+
In this example the SDK will try to fetch data from the discount service with webshop links.
|
|
127
|
+
|
|
128
|
+
The behaviour of opening links can be adjusted using `linkTarget` in the configuration.
|
|
129
|
+
|
|
130
|
+
`_self` (default) will open the webshop link directly on the same tab.
|
|
131
|
+
|
|
132
|
+
`_blank` will open the webshop link in a new tab.
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
```html
|
|
136
|
+
<script type="text/javascript">
|
|
137
|
+
const container = document.getElementById("checkout-container");
|
|
138
|
+
discounts.embed({
|
|
139
|
+
container: document.getElementById("deals-container"),
|
|
140
|
+
linkTarget: '_blank'
|
|
141
|
+
api:{
|
|
142
|
+
account: 'P00000000',
|
|
143
|
+
key: 'public_api_key',
|
|
144
|
+
secret: 'abcdef01-2345-6789-abcd-ef0123456789',
|
|
145
|
+
},
|
|
146
|
+
theme: {
|
|
147
|
+
fontSize: "14px",
|
|
148
|
+
color: "rgba(0,0,0,1)",
|
|
149
|
+
primary: "hotpink",
|
|
150
|
+
secondary: "aqua",
|
|
151
|
+
background: "#fff",
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
</script>
|
|
155
|
+
```
|
|
156
|
+
|
|
123
157
|
## Bugs
|
|
124
158
|
|
|
125
159
|
Bugs can be reported to https://github.com/Dintero/Dintero.Discounts.Web.SDK/issues
|
|
File without changes
|
|
File without changes
|
|
@@ -23,30 +23,30 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">82.
|
|
26
|
+
<span class="strong">82.95% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>73/88</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">
|
|
33
|
+
<span class="strong">59.72% </span>
|
|
34
34
|
<span class="quiet">Branches</span>
|
|
35
|
-
<span class='fraction'>
|
|
35
|
+
<span class='fraction'>43/72</span>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
<div class='fl pad1y space-right2'>
|
|
40
|
-
<span class="strong">95% </span>
|
|
40
|
+
<span class="strong">95.45% </span>
|
|
41
41
|
<span class="quiet">Functions</span>
|
|
42
|
-
<span class='fraction'>
|
|
42
|
+
<span class='fraction'>21/22</span>
|
|
43
43
|
</div>
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">80.
|
|
47
|
+
<span class="strong">80.82% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>59/73</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -395,12 +395,18 @@
|
|
|
395
395
|
<a name='L330'></a><a href='#L330'>330</a>
|
|
396
396
|
<a name='L331'></a><a href='#L331'>331</a>
|
|
397
397
|
<a name='L332'></a><a href='#L332'>332</a>
|
|
398
|
-
<a name='L333'></a><a href='#L333'>333</a
|
|
398
|
+
<a name='L333'></a><a href='#L333'>333</a>
|
|
399
|
+
<a name='L334'></a><a href='#L334'>334</a>
|
|
400
|
+
<a name='L335'></a><a href='#L335'>335</a>
|
|
401
|
+
<a name='L336'></a><a href='#L336'>336</a>
|
|
402
|
+
<a name='L337'></a><a href='#L337'>337</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
|
|
399
403
|
<span class="cline-any cline-neutral"> </span>
|
|
400
404
|
<span class="cline-any cline-yes">1x</span>
|
|
401
405
|
<span class="cline-any cline-yes">1x</span>
|
|
402
406
|
<span class="cline-any cline-yes">1x</span>
|
|
403
407
|
<span class="cline-any cline-neutral"> </span>
|
|
408
|
+
<span class="cline-any cline-yes">4x</span>
|
|
409
|
+
<span class="cline-any cline-neutral"> </span>
|
|
404
410
|
<span class="cline-any cline-yes">3x</span>
|
|
405
411
|
<span class="cline-any cline-neutral"> </span>
|
|
406
412
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -442,6 +448,8 @@
|
|
|
442
448
|
<span class="cline-any cline-neutral"> </span>
|
|
443
449
|
<span class="cline-any cline-neutral"> </span>
|
|
444
450
|
<span class="cline-any cline-neutral"> </span>
|
|
451
|
+
<span class="cline-any cline-neutral"> </span>
|
|
452
|
+
<span class="cline-any cline-neutral"> </span>
|
|
445
453
|
<span class="cline-any cline-yes">3x</span>
|
|
446
454
|
<span class="cline-any cline-neutral"> </span>
|
|
447
455
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -733,6 +741,8 @@ import { translations, t } from "./translations";
|
|
|
733
741
|
import { monetaryString, dateString } from "./formatters";
|
|
734
742
|
import { normalize } from "./normalize";
|
|
735
743
|
|
|
744
|
+
export const findWebshopLink = (discount: Discount) => discount.links && discount.links.find(x => x.rel && x.rel === 'webshop');
|
|
745
|
+
|
|
736
746
|
const discountStyle = (className: string, theme: Theme) => `
|
|
737
747
|
@keyframes appear {
|
|
738
748
|
from {
|
|
@@ -764,6 +774,8 @@ const discountStyle = (className: string, theme: Theme) => `
|
|
|
764
774
|
animation-name: appear;
|
|
765
775
|
animation-timing-function: ease-in;
|
|
766
776
|
transform-origin: top center;
|
|
777
|
+
color: inherit;
|
|
778
|
+
text-decoration: none;
|
|
767
779
|
}
|
|
768
780
|
|
|
769
781
|
@media screen and (max-width: 679px) {
|
|
@@ -1028,9 +1040,9 @@ export const createDiscount = (
|
|
|
1028
1040
|
configuration: Configuration
|
|
1029
1041
|
): HTMLElement => {
|
|
1030
1042
|
const discountElem = createElement({
|
|
1031
|
-
tag: "div",
|
|
1043
|
+
tag: findWebshopLink(discount) ? <span class="branch-0 cbranch-no" title="branch not covered" >"a" </span>: "div",
|
|
1032
1044
|
styles: [normalize, discountStyle],
|
|
1033
|
-
theme: configuration.theme
|
|
1045
|
+
theme: configuration.theme
|
|
1034
1046
|
});
|
|
1035
1047
|
const ribbonTop = createTopRibbon(discount, configuration);
|
|
1036
1048
|
const ribbonBottom = createBottomRibbon(discount, configuration);
|
|
@@ -1066,7 +1078,7 @@ export const createDiscount = (
|
|
|
1066
1078
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
1067
1079
|
Code coverage generated by
|
|
1068
1080
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
1069
|
-
at
|
|
1081
|
+
at Mon Sep 12 2022 08:24:26 GMT+0000 (Coordinated Universal Time)
|
|
1070
1082
|
</div>
|
|
1071
1083
|
<script src="prettify.js"></script>
|
|
1072
1084
|
<script>
|
|
@@ -176,9 +176,9 @@
|
|
|
176
176
|
<span class="cline-any cline-yes">1x</span>
|
|
177
177
|
<span class="cline-any cline-yes">28x</span>
|
|
178
178
|
<span class="cline-any cline-yes">28x</span>
|
|
179
|
-
<span class="cline-any cline-yes">
|
|
180
|
-
<span class="cline-any cline-yes">
|
|
181
|
-
<span class="cline-any cline-yes">
|
|
179
|
+
<span class="cline-any cline-yes">8052x</span>
|
|
180
|
+
<span class="cline-any cline-yes">8052x</span>
|
|
181
|
+
<span class="cline-any cline-yes">8052x</span>
|
|
182
182
|
<span class="cline-any cline-neutral"> </span>
|
|
183
183
|
<span class="cline-any cline-yes">28x</span>
|
|
184
184
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -295,7 +295,7 @@ const addEventListeners = <span class="fstat-no" title="function not covered" >(
|
|
|
295
295
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
296
296
|
Code coverage generated by
|
|
297
297
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
298
|
-
at
|
|
298
|
+
at Mon Sep 12 2022 08:24:26 GMT+0000 (Coordinated Universal Time)
|
|
299
299
|
</div>
|
|
300
300
|
<script src="prettify.js"></script>
|
|
301
301
|
<script>
|
|
@@ -229,7 +229,7 @@ export const createError = <span class="fstat-no" title="function not covered" >
|
|
|
229
229
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
230
230
|
Code coverage generated by
|
|
231
231
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
232
|
-
at
|
|
232
|
+
at Mon Sep 12 2022 08:24:26 GMT+0000 (Coordinated Universal Time)
|
|
233
233
|
</div>
|
|
234
234
|
<script src="prettify.js"></script>
|
|
235
235
|
<script>
|
|
File without changes
|
|
@@ -370,7 +370,7 @@ export const fetchDiscounts = <span class="fstat-no" title="function not covered
|
|
|
370
370
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
371
371
|
Code coverage generated by
|
|
372
372
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
373
|
-
at
|
|
373
|
+
at Mon Sep 12 2022 08:24:26 GMT+0000 (Coordinated Universal Time)
|
|
374
374
|
</div>
|
|
375
375
|
<script src="prettify.js"></script>
|
|
376
376
|
<script>
|
|
@@ -208,7 +208,7 @@ export const dateString = <span class="fstat-no" title="function not covered" >(
|
|
|
208
208
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
209
209
|
Code coverage generated by
|
|
210
210
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
211
|
-
at
|
|
211
|
+
at Mon Sep 12 2022 08:24:26 GMT+0000 (Coordinated Universal Time)
|
|
212
212
|
</div>
|
|
213
213
|
<script src="prettify.js"></script>
|
|
214
214
|
<script>
|
|
@@ -23,30 +23,30 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">
|
|
26
|
+
<span class="strong">66.03% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>175/265</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">
|
|
33
|
+
<span class="strong">49.25% </span>
|
|
34
34
|
<span class="quiet">Branches</span>
|
|
35
|
-
<span class='fraction'>
|
|
35
|
+
<span class='fraction'>66/134</span>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
<div class='fl pad1y space-right2'>
|
|
40
|
-
<span class="strong">
|
|
40
|
+
<span class="strong">63.79% </span>
|
|
41
41
|
<span class="quiet">Functions</span>
|
|
42
|
-
<span class='fraction'>
|
|
42
|
+
<span class='fraction'>37/58</span>
|
|
43
43
|
</div>
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">63.
|
|
47
|
+
<span class="strong">63.51% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>148/233</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -80,17 +80,17 @@
|
|
|
80
80
|
</thead>
|
|
81
81
|
<tbody><tr>
|
|
82
82
|
<td class="file high" data-value="discounts.ts"><a href="discounts.ts.html">discounts.ts</a></td>
|
|
83
|
-
<td data-value="82.
|
|
83
|
+
<td data-value="82.95" class="pic high">
|
|
84
84
|
<div class="chart"><div class="cover-fill" style="width: 82%"></div><div class="cover-empty" style="width: 18%"></div></div>
|
|
85
85
|
</td>
|
|
86
|
-
<td data-value="82.
|
|
87
|
-
<td data-value="
|
|
88
|
-
<td data-value="
|
|
89
|
-
<td data-value="
|
|
90
|
-
<td data-value="95" class="pct high">95%</td>
|
|
91
|
-
<td data-value="
|
|
92
|
-
<td data-value="80.
|
|
93
|
-
<td data-value="
|
|
86
|
+
<td data-value="82.95" class="pct high">82.95%</td>
|
|
87
|
+
<td data-value="88" class="abs high">73/88</td>
|
|
88
|
+
<td data-value="59.72" class="pct medium">59.72%</td>
|
|
89
|
+
<td data-value="72" class="abs medium">43/72</td>
|
|
90
|
+
<td data-value="95.45" class="pct high">95.45%</td>
|
|
91
|
+
<td data-value="22" class="abs high">21/22</td>
|
|
92
|
+
<td data-value="80.82" class="pct high">80.82%</td>
|
|
93
|
+
<td data-value="73" class="abs high">59/73</td>
|
|
94
94
|
</tr>
|
|
95
95
|
|
|
96
96
|
<tr>
|
|
@@ -155,17 +155,17 @@
|
|
|
155
155
|
|
|
156
156
|
<tr>
|
|
157
157
|
<td class="file medium" data-value="index.ts"><a href="index.ts.html">index.ts</a></td>
|
|
158
|
-
<td data-value="
|
|
159
|
-
<div class="chart"><div class="cover-fill" style="width:
|
|
158
|
+
<td data-value="65.9" class="pic medium">
|
|
159
|
+
<div class="chart"><div class="cover-fill" style="width: 65%"></div><div class="cover-empty" style="width: 35%"></div></div>
|
|
160
160
|
</td>
|
|
161
|
-
<td data-value="
|
|
162
|
-
<td data-value="
|
|
163
|
-
<td data-value="
|
|
164
|
-
<td data-value="
|
|
161
|
+
<td data-value="65.9" class="pct medium">65.9%</td>
|
|
162
|
+
<td data-value="44" class="abs medium">29/44</td>
|
|
163
|
+
<td data-value="35.71" class="pct low">35.71%</td>
|
|
164
|
+
<td data-value="14" class="abs low">5/14</td>
|
|
165
165
|
<td data-value="87.5" class="pct high">87.5%</td>
|
|
166
166
|
<td data-value="8" class="abs high">7/8</td>
|
|
167
|
-
<td data-value="
|
|
168
|
-
<td data-value="
|
|
167
|
+
<td data-value="65" class="pct medium">65%</td>
|
|
168
|
+
<td data-value="40" class="abs medium">26/40</td>
|
|
169
169
|
</tr>
|
|
170
170
|
|
|
171
171
|
<tr>
|
|
@@ -221,7 +221,7 @@
|
|
|
221
221
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
222
222
|
Code coverage generated by
|
|
223
223
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
224
|
-
at
|
|
224
|
+
at Mon Sep 12 2022 08:24:26 GMT+0000 (Coordinated Universal Time)
|
|
225
225
|
</div>
|
|
226
226
|
<script src="prettify.js"></script>
|
|
227
227
|
<script>
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">
|
|
26
|
+
<span class="strong">65.9% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>29/44</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">
|
|
33
|
+
<span class="strong">35.71% </span>
|
|
34
34
|
<span class="quiet">Branches</span>
|
|
35
|
-
<span class='fraction'>
|
|
35
|
+
<span class='fraction'>5/14</span>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">
|
|
47
|
+
<span class="strong">65% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>26/40</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -173,7 +173,14 @@
|
|
|
173
173
|
<a name='L108'></a><a href='#L108'>108</a>
|
|
174
174
|
<a name='L109'></a><a href='#L109'>109</a>
|
|
175
175
|
<a name='L110'></a><a href='#L110'>110</a>
|
|
176
|
-
<a name='L111'></a><a href='#L111'>111</a
|
|
176
|
+
<a name='L111'></a><a href='#L111'>111</a>
|
|
177
|
+
<a name='L112'></a><a href='#L112'>112</a>
|
|
178
|
+
<a name='L113'></a><a href='#L113'>113</a>
|
|
179
|
+
<a name='L114'></a><a href='#L114'>114</a>
|
|
180
|
+
<a name='L115'></a><a href='#L115'>115</a>
|
|
181
|
+
<a name='L116'></a><a href='#L116'>116</a>
|
|
182
|
+
<a name='L117'></a><a href='#L117'>117</a>
|
|
183
|
+
<a name='L118'></a><a href='#L118'>118</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
|
|
177
184
|
<span class="cline-any cline-neutral"> </span>
|
|
178
185
|
<span class="cline-any cline-yes">1x</span>
|
|
179
186
|
<span class="cline-any cline-yes">1x</span>
|
|
@@ -183,6 +190,7 @@
|
|
|
183
190
|
<span class="cline-any cline-yes">1x</span>
|
|
184
191
|
<span class="cline-any cline-neutral"> </span>
|
|
185
192
|
<span class="cline-any cline-neutral"> </span>
|
|
193
|
+
<span class="cline-any cline-neutral"> </span>
|
|
186
194
|
<span class="cline-any cline-yes">1x</span>
|
|
187
195
|
<span class="cline-any cline-neutral"> </span>
|
|
188
196
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -208,6 +216,7 @@
|
|
|
208
216
|
<span class="cline-any cline-neutral"> </span>
|
|
209
217
|
<span class="cline-any cline-neutral"> </span>
|
|
210
218
|
<span class="cline-any cline-neutral"> </span>
|
|
219
|
+
<span class="cline-any cline-neutral"> </span>
|
|
211
220
|
<span class="cline-any cline-yes">1x</span>
|
|
212
221
|
<span class="cline-any cline-yes">2x</span>
|
|
213
222
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -275,6 +284,11 @@
|
|
|
275
284
|
<span class="cline-any cline-yes">2x</span>
|
|
276
285
|
<span class="cline-any cline-yes">2x</span>
|
|
277
286
|
<span class="cline-any cline-yes">2x</span>
|
|
287
|
+
<span class="cline-any cline-yes">2x</span>
|
|
288
|
+
<span class="cline-any cline-no"> </span>
|
|
289
|
+
<span class="cline-any cline-no"> </span>
|
|
290
|
+
<span class="cline-any cline-neutral"> </span>
|
|
291
|
+
<span class="cline-any cline-yes">2x</span>
|
|
278
292
|
<span class="cline-any cline-neutral"> </span>
|
|
279
293
|
<span class="cline-any cline-yes">2x</span>
|
|
280
294
|
<span class="cline-any cline-yes">2x</span>
|
|
@@ -283,7 +297,7 @@
|
|
|
283
297
|
<span class="cline-any cline-neutral"> </span>
|
|
284
298
|
<span class="cline-any cline-neutral"> </span>
|
|
285
299
|
<span class="cline-any cline-neutral"> </span>
|
|
286
|
-
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import { createDiscount } from "./discounts";
|
|
300
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import { createDiscount, findWebshopLink } from "./discounts";
|
|
287
301
|
import { Discount, Configuration, Theme, Embed } from "./types";
|
|
288
302
|
import { createElement } from "./dom";
|
|
289
303
|
import { fetchDiscounts } from "./fetch";
|
|
@@ -293,9 +307,11 @@ import { normalize } from "./normalize";
|
|
|
293
307
|
import pkg from "../package.json";
|
|
294
308
|
|
|
295
309
|
|
|
310
|
+
|
|
296
311
|
const defaultConfig:Partial<Configuration> = {
|
|
297
312
|
language: 'no',
|
|
298
313
|
version: pkg.version,
|
|
314
|
+
linkTarget: '_self',
|
|
299
315
|
currency: {
|
|
300
316
|
value: 'Kr',
|
|
301
317
|
position: 'suffix',
|
|
@@ -361,7 +377,7 @@ export const embed = async (configuration: Configuration):Promise<Embed> =
|
|
|
361
377
|
return renderDeals(_configuration, _configuration.discounts);
|
|
362
378
|
} else {
|
|
363
379
|
|
|
364
|
-
const <span class="cstat-no" title="statement not covered" >loader =createLoading(_configuration);</span>
|
|
380
|
+
const <span class="cstat-no" title="statement not covered" >loader = createLoading(_configuration);</span>
|
|
365
381
|
try{
|
|
366
382
|
<span class="cstat-no" title="statement not covered" > configuration.container.appendChild(loader);</span>
|
|
367
383
|
const <span class="cstat-no" title="statement not covered" >discounts = <span class="cstat-no" title="statement not covered" >await fetchDiscounts(_configuration);</span></span>
|
|
@@ -384,6 +400,11 @@ const renderDeals = (configuration: Configuration, discounts: Discount[]):Embed
|
|
|
384
400
|
const wrapper = createElement({ tag: "div", styles: [normalize, wrapperStyles], theme: configuration.theme });
|
|
385
401
|
discounts.forEach((discount) => {
|
|
386
402
|
const elem = createDiscount(discount, configuration);
|
|
403
|
+
const webShopLink = findWebshopLink(discount);
|
|
404
|
+
<span class="missing-if-branch" title="if path not taken" >I</span>if (webShopLink) {
|
|
405
|
+
<span class="cstat-no" title="statement not covered" > elem.setAttribute('target', configuration?.linkTarget || '_self');</span>
|
|
406
|
+
<span class="cstat-no" title="statement not covered" > elem.setAttribute('href', webShopLink.href);</span>
|
|
407
|
+
}
|
|
387
408
|
wrapper.appendChild(elem);
|
|
388
409
|
});
|
|
389
410
|
configuration.container.appendChild(wrapper);
|
|
@@ -400,7 +421,7 @@ const renderDeals = (configuration: Configuration, discounts: Discount[]):Embed
|
|
|
400
421
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
401
422
|
Code coverage generated by
|
|
402
423
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
403
|
-
at
|
|
424
|
+
at Mon Sep 12 2022 08:24:26 GMT+0000 (Coordinated Universal Time)
|
|
404
425
|
</div>
|
|
405
426
|
<script src="prettify.js"></script>
|
|
406
427
|
<script>
|
|
@@ -199,7 +199,7 @@ export const createLoading = <span class="fstat-no" title="function not covered"
|
|
|
199
199
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
200
200
|
Code coverage generated by
|
|
201
201
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
202
|
-
at
|
|
202
|
+
at Mon Sep 12 2022 08:24:26 GMT+0000 (Coordinated Universal Time)
|
|
203
203
|
</div>
|
|
204
204
|
<script src="prettify.js"></script>
|
|
205
205
|
<script>
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
122
122
|
Code coverage generated by
|
|
123
123
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
124
|
-
at
|
|
124
|
+
at Mon Sep 12 2022 08:24:26 GMT+0000 (Coordinated Universal Time)
|
|
125
125
|
</div>
|
|
126
126
|
<script src="prettify.js"></script>
|
|
127
127
|
<script>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -184,7 +184,7 @@ export const t = <span class="fstat-no" title="function not covered" >(t</span>r
|
|
|
184
184
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
185
185
|
Code coverage generated by
|
|
186
186
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
187
|
-
at
|
|
187
|
+
at Mon Sep 12 2022 08:24:26 GMT+0000 (Coordinated Universal Time)
|
|
188
188
|
</div>
|
|
189
189
|
<script src="prettify.js"></script>
|
|
190
190
|
<script>
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { Discount, Configuration } from "./types";
|
|
2
|
+
export declare const findWebshopLink: (discount: Discount) => {
|
|
3
|
+
href: string;
|
|
4
|
+
rel?: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
};
|
|
2
7
|
export declare const createDiscount: (discount: Discount, configuration: Configuration) => HTMLElement;
|
|
@@ -177,6 +177,8 @@ const normalize = className => `
|
|
|
177
177
|
}
|
|
178
178
|
`;
|
|
179
179
|
|
|
180
|
+
const findWebshopLink = discount => discount.links && discount.links.find(x => x.rel && x.rel === 'webshop');
|
|
181
|
+
|
|
180
182
|
const discountStyle = (className, theme) => `
|
|
181
183
|
@keyframes appear {
|
|
182
184
|
from {
|
|
@@ -208,6 +210,8 @@ const discountStyle = (className, theme) => `
|
|
|
208
210
|
animation-name: appear;
|
|
209
211
|
animation-timing-function: ease-in;
|
|
210
212
|
transform-origin: top center;
|
|
213
|
+
color: inherit;
|
|
214
|
+
text-decoration: none;
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
@media screen and (max-width: 679px) {
|
|
@@ -439,7 +443,7 @@ const createLimitations = (discount, configuration) => {
|
|
|
439
443
|
|
|
440
444
|
const createDiscount = (discount, configuration) => {
|
|
441
445
|
const discountElem = createElement({
|
|
442
|
-
tag: "div",
|
|
446
|
+
tag: findWebshopLink(discount) ? "a" : "div",
|
|
443
447
|
styles: [normalize, discountStyle],
|
|
444
448
|
theme: configuration.theme
|
|
445
449
|
});
|
|
@@ -621,7 +625,7 @@ const createLoading = configuration => {
|
|
|
621
625
|
|
|
622
626
|
var pkg = {
|
|
623
627
|
name: "@dintero/discounts-web-sdk",
|
|
624
|
-
version: "0.
|
|
628
|
+
version: "0.2.0",
|
|
625
629
|
description: "Dintero Discounts SDK for web frontends",
|
|
626
630
|
main: "dist/dintero-discounts-web-sdk.cjs.js",
|
|
627
631
|
module: "dist/dintero-discounts-web-sdk.esm.js",
|
|
@@ -633,6 +637,7 @@ var pkg = {
|
|
|
633
637
|
},
|
|
634
638
|
scripts: {
|
|
635
639
|
test: "karma start",
|
|
640
|
+
watch: "preconstruct watch",
|
|
636
641
|
build: "preconstruct build",
|
|
637
642
|
prepublishOnly: "npm run build",
|
|
638
643
|
"semantic-release": "semantic-release"
|
|
@@ -661,7 +666,7 @@ var pkg = {
|
|
|
661
666
|
"karma-typescript": "^5.0.3",
|
|
662
667
|
mocha: "^8.1.1",
|
|
663
668
|
prettier: "^2.7.0",
|
|
664
|
-
puppeteer: "^
|
|
669
|
+
puppeteer: "^17.1.1",
|
|
665
670
|
"semantic-release": "^19.0.3",
|
|
666
671
|
typescript: "^4.2.4"
|
|
667
672
|
}
|
|
@@ -670,6 +675,7 @@ var pkg = {
|
|
|
670
675
|
const defaultConfig = {
|
|
671
676
|
language: 'no',
|
|
672
677
|
version: pkg.version,
|
|
678
|
+
linkTarget: '_self',
|
|
673
679
|
currency: {
|
|
674
680
|
value: 'Kr',
|
|
675
681
|
position: 'suffix',
|
|
@@ -763,6 +769,13 @@ const renderDeals = (configuration, discounts) => {
|
|
|
763
769
|
});
|
|
764
770
|
discounts.forEach(discount => {
|
|
765
771
|
const elem = createDiscount(discount, configuration);
|
|
772
|
+
const webShopLink = findWebshopLink(discount);
|
|
773
|
+
|
|
774
|
+
if (webShopLink) {
|
|
775
|
+
elem.setAttribute('target', configuration?.linkTarget || '_self');
|
|
776
|
+
elem.setAttribute('href', webShopLink.href);
|
|
777
|
+
}
|
|
778
|
+
|
|
766
779
|
wrapper.appendChild(elem);
|
|
767
780
|
});
|
|
768
781
|
configuration.container.appendChild(wrapper);
|
|
@@ -177,6 +177,8 @@ const normalize = className => `
|
|
|
177
177
|
}
|
|
178
178
|
`;
|
|
179
179
|
|
|
180
|
+
const findWebshopLink = discount => discount.links && discount.links.find(x => x.rel && x.rel === 'webshop');
|
|
181
|
+
|
|
180
182
|
const discountStyle = (className, theme) => `
|
|
181
183
|
@keyframes appear {
|
|
182
184
|
from {
|
|
@@ -208,6 +210,8 @@ const discountStyle = (className, theme) => `
|
|
|
208
210
|
animation-name: appear;
|
|
209
211
|
animation-timing-function: ease-in;
|
|
210
212
|
transform-origin: top center;
|
|
213
|
+
color: inherit;
|
|
214
|
+
text-decoration: none;
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
@media screen and (max-width: 679px) {
|
|
@@ -439,7 +443,7 @@ const createLimitations = (discount, configuration) => {
|
|
|
439
443
|
|
|
440
444
|
const createDiscount = (discount, configuration) => {
|
|
441
445
|
const discountElem = createElement({
|
|
442
|
-
tag: "div",
|
|
446
|
+
tag: findWebshopLink(discount) ? "a" : "div",
|
|
443
447
|
styles: [normalize, discountStyle],
|
|
444
448
|
theme: configuration.theme
|
|
445
449
|
});
|
|
@@ -621,7 +625,7 @@ const createLoading = configuration => {
|
|
|
621
625
|
|
|
622
626
|
var pkg = {
|
|
623
627
|
name: "@dintero/discounts-web-sdk",
|
|
624
|
-
version: "0.
|
|
628
|
+
version: "0.2.0",
|
|
625
629
|
description: "Dintero Discounts SDK for web frontends",
|
|
626
630
|
main: "dist/dintero-discounts-web-sdk.cjs.js",
|
|
627
631
|
module: "dist/dintero-discounts-web-sdk.esm.js",
|
|
@@ -633,6 +637,7 @@ var pkg = {
|
|
|
633
637
|
},
|
|
634
638
|
scripts: {
|
|
635
639
|
test: "karma start",
|
|
640
|
+
watch: "preconstruct watch",
|
|
636
641
|
build: "preconstruct build",
|
|
637
642
|
prepublishOnly: "npm run build",
|
|
638
643
|
"semantic-release": "semantic-release"
|
|
@@ -661,7 +666,7 @@ var pkg = {
|
|
|
661
666
|
"karma-typescript": "^5.0.3",
|
|
662
667
|
mocha: "^8.1.1",
|
|
663
668
|
prettier: "^2.7.0",
|
|
664
|
-
puppeteer: "^
|
|
669
|
+
puppeteer: "^17.1.1",
|
|
665
670
|
"semantic-release": "^19.0.3",
|
|
666
671
|
typescript: "^4.2.4"
|
|
667
672
|
}
|
|
@@ -670,6 +675,7 @@ var pkg = {
|
|
|
670
675
|
const defaultConfig = {
|
|
671
676
|
language: 'no',
|
|
672
677
|
version: pkg.version,
|
|
678
|
+
linkTarget: '_self',
|
|
673
679
|
currency: {
|
|
674
680
|
value: 'Kr',
|
|
675
681
|
position: 'suffix',
|
|
@@ -763,6 +769,13 @@ const renderDeals = (configuration, discounts) => {
|
|
|
763
769
|
});
|
|
764
770
|
discounts.forEach(discount => {
|
|
765
771
|
const elem = createDiscount(discount, configuration);
|
|
772
|
+
const webShopLink = findWebshopLink(discount);
|
|
773
|
+
|
|
774
|
+
if (webShopLink) {
|
|
775
|
+
elem.setAttribute('target', configuration?.linkTarget || '_self');
|
|
776
|
+
elem.setAttribute('href', webShopLink.href);
|
|
777
|
+
}
|
|
778
|
+
|
|
766
779
|
wrapper.appendChild(elem);
|
|
767
780
|
});
|
|
768
781
|
configuration.container.appendChild(wrapper);
|
|
@@ -173,6 +173,8 @@ const normalize = className => `
|
|
|
173
173
|
}
|
|
174
174
|
`;
|
|
175
175
|
|
|
176
|
+
const findWebshopLink = discount => discount.links && discount.links.find(x => x.rel && x.rel === 'webshop');
|
|
177
|
+
|
|
176
178
|
const discountStyle = (className, theme) => `
|
|
177
179
|
@keyframes appear {
|
|
178
180
|
from {
|
|
@@ -204,6 +206,8 @@ const discountStyle = (className, theme) => `
|
|
|
204
206
|
animation-name: appear;
|
|
205
207
|
animation-timing-function: ease-in;
|
|
206
208
|
transform-origin: top center;
|
|
209
|
+
color: inherit;
|
|
210
|
+
text-decoration: none;
|
|
207
211
|
}
|
|
208
212
|
|
|
209
213
|
@media screen and (max-width: 679px) {
|
|
@@ -435,7 +439,7 @@ const createLimitations = (discount, configuration) => {
|
|
|
435
439
|
|
|
436
440
|
const createDiscount = (discount, configuration) => {
|
|
437
441
|
const discountElem = createElement({
|
|
438
|
-
tag: "div",
|
|
442
|
+
tag: findWebshopLink(discount) ? "a" : "div",
|
|
439
443
|
styles: [normalize, discountStyle],
|
|
440
444
|
theme: configuration.theme
|
|
441
445
|
});
|
|
@@ -617,7 +621,7 @@ const createLoading = configuration => {
|
|
|
617
621
|
|
|
618
622
|
var pkg = {
|
|
619
623
|
name: "@dintero/discounts-web-sdk",
|
|
620
|
-
version: "0.
|
|
624
|
+
version: "0.2.0",
|
|
621
625
|
description: "Dintero Discounts SDK for web frontends",
|
|
622
626
|
main: "dist/dintero-discounts-web-sdk.cjs.js",
|
|
623
627
|
module: "dist/dintero-discounts-web-sdk.esm.js",
|
|
@@ -629,6 +633,7 @@ var pkg = {
|
|
|
629
633
|
},
|
|
630
634
|
scripts: {
|
|
631
635
|
test: "karma start",
|
|
636
|
+
watch: "preconstruct watch",
|
|
632
637
|
build: "preconstruct build",
|
|
633
638
|
prepublishOnly: "npm run build",
|
|
634
639
|
"semantic-release": "semantic-release"
|
|
@@ -657,7 +662,7 @@ var pkg = {
|
|
|
657
662
|
"karma-typescript": "^5.0.3",
|
|
658
663
|
mocha: "^8.1.1",
|
|
659
664
|
prettier: "^2.7.0",
|
|
660
|
-
puppeteer: "^
|
|
665
|
+
puppeteer: "^17.1.1",
|
|
661
666
|
"semantic-release": "^19.0.3",
|
|
662
667
|
typescript: "^4.2.4"
|
|
663
668
|
}
|
|
@@ -666,6 +671,7 @@ var pkg = {
|
|
|
666
671
|
const defaultConfig = {
|
|
667
672
|
language: 'no',
|
|
668
673
|
version: pkg.version,
|
|
674
|
+
linkTarget: '_self',
|
|
669
675
|
currency: {
|
|
670
676
|
value: 'Kr',
|
|
671
677
|
position: 'suffix',
|
|
@@ -759,6 +765,13 @@ const renderDeals = (configuration, discounts) => {
|
|
|
759
765
|
});
|
|
760
766
|
discounts.forEach(discount => {
|
|
761
767
|
const elem = createDiscount(discount, configuration);
|
|
768
|
+
const webShopLink = findWebshopLink(discount);
|
|
769
|
+
|
|
770
|
+
if (webShopLink) {
|
|
771
|
+
elem.setAttribute('target', configuration?.linkTarget || '_self');
|
|
772
|
+
elem.setAttribute('href', webShopLink.href);
|
|
773
|
+
}
|
|
774
|
+
|
|
762
775
|
wrapper.appendChild(elem);
|
|
763
776
|
});
|
|
764
777
|
configuration.container.appendChild(wrapper);
|
|
@@ -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,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}\n\n@media screen and (max-width: 679px) {\n .${n} {\n width: 100%;\n max-width: 100%;\n } \n }\n`,m=n=>`\n.${n} {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 300px;\n width: 100%,\n}`,h=n=>`\n.${n} {\n max-width: 100%;\n max-height: 100%;\n text-align: center;\n display: inline-block;\n}`,g=(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`,f=(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`,b=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}`,y=n=>`\n.${n} {\n margin-top: 0;\n}`,x=n=>`\n.${n} {\n font-size: 0.75em;\n}\n.${n} > span{\n display: block;\n}\n`,w=(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:[f]})},_=(n,t)=>{const r=e({tag:"div",styles:[p,l],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:[g]})})(n,t),o=w(n,t),d=(n=>{const t=e({tag:"div",styles:[p,m]}),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,h]});return i&&t.appendChild(i),t})(n),c=n?.name&&e({tag:"h4",innerHTML:n.name,styles:[b]}),f=n?.metadata?.subtitle&&e({tag:"p",innerHTML:n.metadata.subtitle,styles:[y]}),_=n.description&&e({tag:"p",innerHTML:n.description}),$=((n,t)=>{const r=a[t.language],i=e({tag:"small",styles:[p,x]});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,f,_,$].filter((n=>n)).forEach((n=>r.appendChild(n))),r},$=(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},v=n=>(n=>{if(!n.api)throw new Error("Authentication configuration missing");const e=window.btoa(`${n.api.key}:${n.api.secret}`),t=$({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=$({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")}))})),k=(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 T={language:"no",version:"0.1.0",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}},M=(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}`,z=(n,t)=>{const r=e({tag:"div",styles:[p,M],theme:n.theme});return t.forEach((e=>{const t=_(e,n);r.appendChild(t)})),n.container.appendChild(r),{destroy:()=>{n.container.removeChild(r)}}};n.embed=async n=>{const t=(r=T,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 z(t,t.discounts);{const r=(n=>e({tag:"div",styles:[p,q],theme:n.theme}))(t);try{n.container.appendChild(r);const e=await v(t);return t.container.removeChild(r),z(t,e)}catch(i){n.container.removeChild(r);const o=(n=>{const t=a[n.language];return e({tag:"div",styles:[p,k],theme:n.theme,innerHTML:t.errors.fetch})})(t);return t.container.appendChild(o),{destroy:()=>{n.container.removeChild(o)}}}}},Object.defineProperty(n,"__esModule",{value:!0})}));
|
|
1
|
+
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).discounts={})}(this,(function(n){"use strict";const e=n=>{const e=document.createElement(n.tag);return n.attributes&&r(e,n.attributes),n.handlers&&i(e,n.handlers),n.styles&&t(e,n.styles,n.theme),n.innerHTML&&(e.innerHTML=n.innerHTML),e},t=(n,e,t)=>{e.forEach((e=>{const r="dintero-deals-"+(n=>{let e=0;for(var t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e&=e;return e.toString(36)})(e("dintero-deals",t));((n,e)=>{n.className.split(" ").includes(e)||(n.className=n.className+" "+e)})(n,r);if(!document.querySelector(`[data-css-hash=${r}]`)){const n=document.createElement("style");n.innerHTML=e(r,t),n.setAttribute("data-css-hash",r),document.head.appendChild(n)}}))},r=(n,e)=>{Object.keys(e).forEach((t=>{n.setAttribute(t,e[t])}))},i=(n,e)=>{Object.keys(e).forEach((t=>{n.addEventListener(t,e[t])}))},a={no:{rewards:{discount_item_quantity:{three_for_two:"3 for 2",generic:"Kjøp {{require}} betal for {{payFor}}"},discount_amount:"{{monetaryAmount}} rabatt"},limitations:{discount_reward_usage:"Antall: <strong>{{discount_reward_usage}}</strong>",discount_repeat_usage:"Maks kjøp: <strong>{{discount_repeat_usage}}</strong>"},requirements:{purchase_from:"Tilbudet starter <strong>{{purchase_from}}</strong>",purchase_to:"Tilbudet utgår <strong>{{purchase_to}}</strong>"},errors:{fetch:"⚠️ <br/>En feil oppstod under lasting av tilbud..."}}},o=/(\{\{)[^}]*(\}\})/g,s=(n,e)=>{const t=n.match(o)||[],r=e||{};return t.reduce(((n,e)=>{const t=e.replace("{{","").replace("}}",""),i=r[t]||"";return n.replace(e,i)}),n)},d=(n,e,t)=>{const r=t||{},i=n.toString(),a=i.length-e.currency.exponent,o=i.slice(0,a)||"0",s=i.slice(a),d="00"!=s||r.decimal?o+"."+s:o;return"short"===r.variant&&"00"===s?o+",-":r.currency?"prefix"===e.currency.position?e.currency.value+" "+d:d+" "+e.currency.value:d},c=n=>n<10?`0${n}`:n.toString(),u=(n,e)=>{try{const t=new Date(n);if("no"===e.language){const n=c(t.getDate()),e=c(t.getMonth()+1);return[n,e,t.getFullYear()].join(".")}return(new Intl.DateTimeFormat).format(t)}catch(e){return n.substr(0,10)}},p=n=>`\n.${n} {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n outline: none;\n border: none;\n box-shadow: none;\n line-height: auto;\n background: transparent;\n opacity: 1;\n border-radius: 0;\n display: block;\n position: relative;\n font-weight: normal;\n}\n`,l=n=>n.links&&n.links.find((n=>n.rel&&"webshop"===n.rel)),m=(n,e)=>`\n@keyframes appear {\n from {\n transform: scaleY(0%);\n height: 0;\n opacity: 0;\n }\n \n to {\n transform: scaleY(100%);\n height: auto;\n opacity: 1;\n }\n }\n.${n} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: ${e.borderRadius};\n text-align: center;\n padding-top: 5px;\n padding-bottom: 105px;\n padding-left: 5px;\n padding-right: 5px;\n max-width: 300px;\n width: 250px;\n font-size: 1em;\n margin: 5px 20px;\n background: ${e.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n color: inherit;\n text-decoration: none;\n}\n\n@media screen and (max-width: 679px) {\n .${n} {\n width: 100%;\n max-width: 100%;\n } \n }\n`,h=n=>`\n.${n} {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 300px;\n width: 100%,\n}`,g=n=>`\n.${n} {\n max-width: 100%;\n max-height: 100%;\n text-align: center;\n display: inline-block;\n}`,f=(n,e)=>`\n.${n} {\n position: absolute;\n bottom: 60px;\n left: -20px;\n color: #fff;\n z-index: 9;\n width: 80%;\n font-size: 1.3em;\n border-radius: 0 ${e.borderRadius} ${e.borderRadius} 0;\n padding: 5px 0;\n background: ${e?.secondary};\n}\n.${n}:after {\n position: absolute;\n content: "";\n bottom: -10px;\n left: 0;\n border-color: transparent;\n border-style: solid;\n border-width: 0 20px 10px 0;\n border-right-color: ${e.secondary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`,b=(n,e)=>`\n.${n} {\n position: absolute;\n right: -20px;\n bottom: 15px;\n color: #fff;\n z-index: 9;\n width: 80%;\n font-size: 1.3em;\n border-radius: ${e.borderRadius} 0 0 ${e.borderRadius};\n padding: 5px 0;\n background: ${e?.primary};\n}\n.${n}:after {\n position: absolute;\n content: "";\n right: 0;\n bottom: -10px;\n border-color: transparent;\n border-style: solid;\n border-width: 10px 20px 0 0;\n border-top-color: ${e.primary};\n width: 0;\n height: 0;\n opacity: 0.5;\n}\n`,y=n=>`\n.${n} {\n margin-bottom: 0;\n font-size: 1em;\n margin-bottom: 2px;\n font-size: 1.3em;\n font-weight: 700;\n}`,x=n=>`\n.${n} {\n margin-top: 0;\n}`,w=n=>`\n.${n} {\n font-size: 0.75em;\n}\n.${n} > span{\n display: block;\n}\n`,_=(n,t)=>{const r=((n,e)=>{const t=a[e.language];if("discount_item_new_price"===n.reward.type)return d(n.reward.value,e,{variant:"short"});if("discount_percent"===n.reward.type)return n.reward.value+"%";if("discount_item_quantity"===n.reward.type){if(3===n.requirement.item.quantity&&1===n.reward.value)return t.rewards.discount_item_quantity.three_for_two;{const e=n.requirement.item.quantity,r=n.requirement.item.quantity-n.reward.value;return s(t.rewards.discount_item_quantity.generic,{require:e,payFor:r})}}if("discount_amount"===n.reward.type){const r=d(n.reward.value,e,{decimal:!1});return s(t.rewards.discount_amount,{monetaryAmount:r})}return"discount_item_percent"===n.reward.type?n.reward.value+"%":""})(n,t);return r&&e({tag:"div",innerHTML:r,theme:t.theme,styles:[b]})},$=(n,t)=>{const r=e({tag:l(n)?"a":"div",styles:[p,m],theme:t.theme}),i=((n,t)=>{const r=(n=>n&&n.metadata&&n.metadata.label||void 0)(n);return r&&e({tag:"div",innerHTML:r,theme:t.theme,styles:[f]})})(n,t),o=_(n,t),d=(n=>{const t=e({tag:"div",styles:[p,h]}),r=n.links.find((n=>["medium_discount_image","thumbnail_discount_image".includes(n.rel)])),i=r&&e({tag:"img",attributes:{src:r.href,alt:n.name,loading:"lazy"},styles:[p,g]});return i&&t.appendChild(i),t})(n),c=n?.name&&e({tag:"h4",innerHTML:n.name,styles:[y]}),b=n?.metadata?.subtitle&&e({tag:"p",innerHTML:n.metadata.subtitle,styles:[x]}),$=n.description&&e({tag:"p",innerHTML:n.description}),v=((n,t)=>{const r=a[t.language],i=e({tag:"small",styles:[p,w]});return[n.limitation.discount_reward_usage&&-1!==n.limitation.discount_reward_usage&&e({tag:"span",innerHTML:s(r.limitations.discount_reward_usage,{discount_reward_usage:n.limitation.discount_reward_usage})}),n.limitation.discount_repeat_usage&&-1!==n.limitation.discount_repeat_usage&&e({tag:"span",innerHTML:s(r.limitations.discount_repeat_usage,{discount_repeat_usage:n.limitation.discount_repeat_usage})}),new Date(n.requirement.purchase_from||0)>new Date&&e({tag:"span",innerHTML:s(r.requirements.purchase_from,{purchase_from:u(n.requirement.purchase_from,t)})}),new Date(n.requirement.purchase_to||0)>new Date&&e({tag:"span",innerHTML:s(r.requirements.purchase_to,{purchase_to:u(n.requirement.purchase_to,t)})})].filter((n=>n)).forEach((n=>i.appendChild(n))),console.log({discount:n,wrapper:i}),i})(n,t);return[i,o,d,c,b,$,v].filter((n=>n)).forEach((n=>r.appendChild(n))),r},v=(n,e)=>{const t=new Headers;return Object.entries({...n,"Dintero-System-Name":"deals-web-sdk","Dintero-System-Version":e.version}).forEach((([n,e])=>{t.append(n,e)})),t},k=n=>(n=>{if(!n.api)throw new Error("Authentication configuration missing");const e=window.btoa(`${n.api.key}:${n.api.secret}`),t=v({Authorization:`Basic ${e}`,"content-type":"application/json"},n),r=JSON.stringify({grant_type:"client_credentials",audience:`${n.api.url}/v1/accounts/${n.api.account}`});return window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/auth/token`,{method:"POST",headers:t,body:r}).then((n=>{if(200===n.status)return n.json();throw new Error("Authentication failed")}))})(n).then((e=>{const t=v({Authorization:`${e.token_type} ${e.access_token}`},n);return n.api.discountId?window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/discounts/public/rules/${n.api.discountId}`,{headers:t}).then((n=>{if(200===n.status)return n.json().then((n=>[n]));throw new Error("Authentication failed")})):window.fetch(`${n.api.url}/v1/accounts/${n.api.account}/discounts/public/rules?limit=${n.api.limit}`,{headers:t}).then((n=>{if(200===n.status)return n.json();throw new Error("Authentication failed")}))})),T=(n,e)=>`\n@keyframes appear {\n from {\n transform: scaleY(0%);\n height: 0;\n opacity: 0;\n }\n \n to {\n transform: scaleY(100%);\n height: auto;\n opacity: 1;\n }\n }\n.${n} {\n box-shadow: rgb(212, 212, 213) 0px 1px 3px 0px, rgb(212, 212, 213) 0px 0px 0px 1px;\n border-radius: 3px;\n text-align: center;\n padding-top: 65px;\n padding-bottom: 70px;\n padding-left: 5px;\n padding-right: 5px;\n max-width: 300px;\n width: 250px;\n font-size: 14px;\n margin: 5px auto;\n background: ${e.background};\n animation-duration: 0.2s;\n animation-name: appear;\n animation-timing-function: ease-in;\n transform-origin: top center;\n}\n`,q=(n,e)=>`\n.${n} {\n margin: 10px auto;\n display: block;\n width: 80px;\n height: 80px;\n}\n\n.${n}:after {\n content: " ";\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #000;\n border-color: rgba(0,0,0,0.2) transparent rgba(0,0,0,0.2) transparent;\n animation: loading 0.6s linear infinite;\n}\n\n@keyframes loading {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n`;const M={language:"no",version:"0.2.0",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 = 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\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}\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: \"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 } 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\nconst defaultConfig:Partial<Configuration> = {\n language: 'no',\n version: pkg.version,\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 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","discountStyle","borderRadius","background","imageWrapperStyles","imageStyle","ribbonTopStyle","secondary","ribbonBottomStyle","primary","titleStyle","subtitleStyle","limitationsWrapperStyle","createBottomRibbon","discount","text","tStrings","reward","type","requirement","item","quantity","require","payFor","monetaryAmount","getBottomRibbonText","createDiscount","discountElem","ribbonTop","metadata","label","undefined","getTopRibbonText","createTopRibbon","ribbonBottom","image","imageWrapper","imageSrc","links","find","link","rel","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","color","fontSize","wrapperStyles","renderDeals","discounts","container","destroy","removeChild","async","_configuration","a","b","error","loader","createLoading","errorMessage","tString","createError"],"mappings":"iPAWO,MAAMA,EAAiBC,IACpBC,MAAAA,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,GAoBLQ,EAAY,CAACR,EAAoBO,EAAyDE,KAE5FF,EAAOI,SAASC,IAENC,MAAAA,EAAY,iBAdZC,KACNC,IAAAA,EAAO,EACX,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAMG,OAAQD,IAE9BD,GAASA,GAAM,GAAGA,EADPD,EAAMI,WAAWF,GAE5BD,GAAcA,EAElB,OAAOA,EAAKI,SAAS,KAOoBJ,CAAKH,EAAM,gBAAiBH,IArBxD,EAACT,EAAkBa,KAClBb,EAAKa,UAAUO,MAAM,KACxBC,SAASR,KAChBb,EAAKa,UAAYb,EAAKa,UAAY,IAAMA,IAmBxCS,CAAStB,EAAMa,GAGX,IADQZ,SAASsB,cAAe,kBAAiBV,MAC3C,CACN,MAAMW,EAAQvB,SAASH,cAAc,SACrC0B,EAAMd,UAAYE,EAAMC,EAAWJ,GACnCe,EAAMC,aAAa,gBAAiBZ,GACpCZ,SAASyB,KAAKC,YAAYH,QAKhCpB,EAAgB,CAACJ,EAAmBG,KACtCyB,OAAOC,KAAK1B,GAAYQ,SAASmB,IAC7B9B,EAAKyB,aAAaK,EAAK3B,EAAW2B,QAIpCxB,EAAoB,CAACN,EAAmBK,KAC1CuB,OAAOC,KAAKxB,GAAUM,SAASmB,IAC3B9B,E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E1L,OAETmJ,IAAI,IACGsC,EAAEtC,OACFuC,EAAEvC,OAdG,IAACsC,EAA0BC,EAmCxC,IAACF,EAAeJ,YAAaI,EAAeJ,UAAUlK,YAErD,MADAsH,QAAQmD,MAAM,yBACR,IAAIvC,MAAM,yBAEhBoC,GAAAA,EAAeL,UACf,OAAOD,EAAYM,EAAgBA,EAAeL,WAC/C,CAEH,MAAMS,ED5CgBzI,IACR9D,EAAc,CAC5BI,IAAK,MACLK,OAAQ,CAACmF,EAAW4F,GACpB7K,MAAOmD,EAAcnD,QCwCP6L,CAAcL,GACzB,IACCrI,EAAciI,UAAUlK,YAAY0K,GACpC,MAAMT,QAAkBjC,EAAesC,GAEvC,OADAA,EAAeJ,UAAUE,YAAYM,GAC9BV,EAAYM,EAAgBL,GACrC,MAAMQ,GACJxI,EAAciI,UAAUE,YAAYM,GACpC,MAAME,EF7Cd3I,KAEA,MAAM4I,EAAWxK,EAAa4B,EAAckB,UAQ5C,OAPkBhF,EAAc,CAC5BI,IAAK,MACLK,OAAQ,CAACmF,EAAW2F,GACpB5K,MAAOmD,EAAcnD,MACrBC,UAAW8L,EAAQ3J,OAAOC,SEsCD2J,CAAYR,GAE1B,OADPA,EAAeJ,UAAUlK,YAAY4K,GAC9B,CACHT,QAAS,KACLlI,EAAciI,UAAUE,YAAYQ"}
|
|
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 = 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,\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,IACpBC,MAAAA,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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sI,EAAEtI,YACFuI,EAAEvI,UAETvD,MAAO,IACA6L,EAAE7L,SACF8L,EAAE9L,OAETqJ,IAAI,IACGwC,EAAExC,OACFyC,EAAEzC,OAdG,IAACwC,EAA0BC,EAmCxC,IAACF,EAAeJ,YAAaI,EAAeJ,UAAUtK,YAErD,MADAwH,QAAQqD,MAAM,yBACR,IAAIzC,MAAM,yBAEhBsC,GAAAA,EAAeN,UACf,OAAOD,EAAYO,EAAgBA,EAAeN,WAC/C,CAEH,MAAMU,ED9CgB7I,IACR9D,EAAc,CAC5BI,IAAK,MACLK,OAAQ,CAACmF,EAAW8F,GACpB/K,MAAOmD,EAAcnD,QC0CNiM,CAAcL,GAC1B,IACCzI,EAAcqI,UAAUtK,YAAY8K,GACpC,MAAMV,QAAkBlC,EAAewC,GAEvC,OADAA,EAAeJ,UAAUE,YAAYM,GAC9BX,EAAYO,EAAgBN,EAUtC,CATC,MAAMS,GACJ5I,EAAcqI,UAAUE,YAAYM,GACpC,MAAME,EF/Cd/I,KAEA,MAAMgJ,EAAW5K,EAAa4B,EAAckB,UAQ5C,OAPkBhF,EAAc,CAC5BI,IAAK,MACLK,OAAQ,CAACmF,EAAW6F,GACpB9K,MAAOmD,EAAcnD,MACrBC,UAAWkM,EAAQ/J,OAAOC,OAG9B,EEqC6B+J,CAAYR,GAE1B,OADPA,EAAeJ,UAAUtK,YAAYgL,GAC9B,CACHT,QAAS,KACLtI,EAAcqI,UAAUE,YAAYQ,EAApC,EAGX,CACJ"}
|
package/index.html
CHANGED
|
@@ -197,6 +197,10 @@
|
|
|
197
197
|
{
|
|
198
198
|
"rel": "medium_discount_image",
|
|
199
199
|
"href": "https://uploads-ssl.webflow.com/5f023ba9549ac22870f32943/5f1333ae5a496b0e0476975e_dintero-logo.svg"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"rel": "webshop",
|
|
203
|
+
"href": "https://example.dintero.com/shop?utm_source=dintero&utm_medium=email&utm_campaign=spring-summer"
|
|
200
204
|
}
|
|
201
205
|
],
|
|
202
206
|
"metadata": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dintero/discounts-web-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"test": "karma start",
|
|
15
|
+
"watch": "preconstruct watch",
|
|
15
16
|
"build": "preconstruct build",
|
|
16
17
|
"prepublishOnly": "npm run build",
|
|
17
18
|
"semantic-release": "semantic-release"
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"karma-typescript": "^5.0.3",
|
|
41
42
|
"mocha": "^8.1.1",
|
|
42
43
|
"prettier": "^2.7.0",
|
|
43
|
-
"puppeteer": "^
|
|
44
|
+
"puppeteer": "^17.1.1",
|
|
44
45
|
"semantic-release": "^19.0.3",
|
|
45
46
|
"typescript": "^4.2.4"
|
|
46
47
|
}
|