ui.shipaid.com 0.2.10 → 0.2.11
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 +28 -2
- package/dist/widget.es.js +59 -58
- package/dist/widget.iife.js +16 -16
- package/dist/widget.umd.js +16 -16
- package/dist-types/src/shipaid-widget.d.ts +4 -0
- package/dist-types/types/shipaid.d.ts +2 -2
- package/dist-types/types/shopify.d.ts +63 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,30 @@ Once we have this data, we can check whether the customer currently has the Ship
|
|
|
14
14
|
|
|
15
15
|
We also emit various [custom events](https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events#adding_custom_data_%E2%80%93_customevent) when we add or remove the ShipAid product from the cart, so other developers can listen to these events, and update AJAX carts.
|
|
16
16
|
|
|
17
|
+
### Installation
|
|
18
|
+
|
|
19
|
+
Add the script tag to the theme - if the theme has an ajax cart, you'll likely want to add this to the `theme.liquid` file, otherwise if the store has only a cart page (`/cart`), then you can add it to just that page, to save it being unecessarily loaded when it isn't needed.
|
|
20
|
+
As we don't want to affect a stores speed at all, you should add it to the bottom of the page just before the ending body tag (`</body>`), rather than inside the `<head>` block.
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<!-- ShipAid Widget -->
|
|
24
|
+
<script src="https://unpkg.com/ui.shipaid.com/dist/widget.es.js" type="module"></script>
|
|
25
|
+
```
|
|
26
|
+
Then add the widget element where needed:
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<shipaid-widget></shipaid-widget>
|
|
30
|
+
|
|
31
|
+
<!-- Disable polling example -->
|
|
32
|
+
<shipaid-widget disablePolling></shipaid-widget>
|
|
33
|
+
|
|
34
|
+
<!-- With customised text -->
|
|
35
|
+
<shipaid-widget>
|
|
36
|
+
<p>Loading ShipAid Protection</p>
|
|
37
|
+
</shipaid-widget>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
17
41
|
### Events
|
|
18
42
|
|
|
19
43
|
This is a list of the events emitted by the widget:
|
|
@@ -42,7 +66,7 @@ This is a list of props that can be used to configure the widget:
|
|
|
42
66
|
|--------|-------------|---------|
|
|
43
67
|
| `disablePolling` | Sets whether the cart should disable polling (enabled by default) - should be disabled if integrating manually with an ajax cart. | `boolean` |
|
|
44
68
|
| `pollingInterval` | If polling is enabled, it sets the interval (in ms) between API updates. | `number` in milliseconds |
|
|
45
|
-
| `disableRefresh ` | Sets whether the store cart should be updated when the protection item is added/removed.
|
|
69
|
+
| `disableRefresh ` | Sets whether the store cart should be updated when the protection item is added/removed. Add if you want to initially hide the protection product from the cart, even if it has just been added. | `boolean` |
|
|
46
70
|
|
|
47
71
|
## Contributing
|
|
48
72
|
|
|
@@ -67,10 +91,12 @@ Once the project is running, add the below to your development Shopify store `th
|
|
|
67
91
|
```html
|
|
68
92
|
<!-- Dev -->
|
|
69
93
|
<script src="http://localhost:3000/src/shipaid-widget.ts"type="module" ></script>
|
|
94
|
+
|
|
70
95
|
<!-- Prod -->
|
|
96
|
+
<!-- ShipAid Widget -->
|
|
71
97
|
<script src="https://unpkg.com/ui.shipaid.com/dist/widget.es.js" type="module"></script>
|
|
72
98
|
```
|
|
73
|
-
And add the widget element
|
|
99
|
+
And add the widget element where needed:
|
|
74
100
|
|
|
75
101
|
```html
|
|
76
102
|
<shipaid-widget>
|
package/dist/widget.es.js
CHANGED
|
@@ -1086,6 +1086,8 @@ const logger = {
|
|
|
1086
1086
|
};
|
|
1087
1087
|
const POLL_INTERVAL_DEFAULT = 2500;
|
|
1088
1088
|
const LOCAL_STORAGE_KEY = "shipaid-protection";
|
|
1089
|
+
const PRODUCT_HANDLE = "shipaid-protection";
|
|
1090
|
+
const PREVIEW_FLAG = "shipaid-test";
|
|
1089
1091
|
const StoreQuery = `query StoreByDomain ($store: String!) {
|
|
1090
1092
|
store: storeByDomain (input: {store: $store}) {
|
|
1091
1093
|
currency
|
|
@@ -1125,9 +1127,6 @@ let ShipAidWidget = class extends s {
|
|
|
1125
1127
|
};
|
|
1126
1128
|
}
|
|
1127
1129
|
get shouldRefreshOnUpdate() {
|
|
1128
|
-
var _a;
|
|
1129
|
-
if ((_a = window.Shopify) == null ? void 0 : _a.Checkout)
|
|
1130
|
-
return true;
|
|
1131
1130
|
if (this.disablePolling)
|
|
1132
1131
|
return false;
|
|
1133
1132
|
if (this.disableRefresh)
|
|
@@ -1136,8 +1135,11 @@ let ShipAidWidget = class extends s {
|
|
|
1136
1135
|
}
|
|
1137
1136
|
get planActive() {
|
|
1138
1137
|
var _a, _b;
|
|
1139
|
-
|
|
1138
|
+
const { searchParams } = new URL(window.location.href);
|
|
1139
|
+
if (((_a = window.Shopify) == null ? void 0 : _a.designMode) || searchParams.has(PREVIEW_FLAG)) {
|
|
1140
|
+
logger.warn("Currently in preview mode.");
|
|
1140
1141
|
return true;
|
|
1142
|
+
}
|
|
1141
1143
|
return !!((_b = this._store) == null ? void 0 : _b.planActive);
|
|
1142
1144
|
}
|
|
1143
1145
|
_currencyFormat(value) {
|
|
@@ -1173,33 +1175,23 @@ let ShipAidWidget = class extends s {
|
|
|
1173
1175
|
if (!this._store)
|
|
1174
1176
|
throw new Error("Missing store settings.");
|
|
1175
1177
|
const settings = (_a = this._store) == null ? void 0 : _a.protectionSettings;
|
|
1176
|
-
if (!settings || !
|
|
1177
|
-
throw new Error(
|
|
1178
|
-
"Tried to find protection variant, but protection settings for this store are missing."
|
|
1179
|
-
);
|
|
1178
|
+
if (!settings || !this._protectionProduct) {
|
|
1179
|
+
throw new Error("Tried to find protection variant, but protection settings for this store are missing.");
|
|
1180
1180
|
}
|
|
1181
1181
|
const itemTotal = ((_b = this._store) == null ? void 0 : _b.excludedProductSkus) && cart.items ? cart.items.reduce((total, item) => {
|
|
1182
1182
|
if (!item.sku)
|
|
1183
1183
|
return total;
|
|
1184
|
-
const itemIsExcluded = this._store.excludedProductSkus.find(
|
|
1185
|
-
(sku) => sku === item.sku
|
|
1186
|
-
);
|
|
1184
|
+
const itemIsExcluded = this._store.excludedProductSkus.find((sku) => sku === item.sku);
|
|
1187
1185
|
return itemIsExcluded ? total - item.final_price : total;
|
|
1188
1186
|
}, cart.total_price) : cart.total_price;
|
|
1189
1187
|
const protectionVariantsInCart = (_d = (_c = cart.items) == null ? void 0 : _c.filter((item) => {
|
|
1190
|
-
var _a2, _b2
|
|
1191
|
-
return (
|
|
1192
|
-
var _a3;
|
|
1193
|
-
return (_a3 = node == null ? void 0 : node.id) == null ? void 0 : _a3.includes(item.variant_id.toString());
|
|
1194
|
-
});
|
|
1188
|
+
var _a2, _b2;
|
|
1189
|
+
return (_b2 = (_a2 = this._protectionProduct) == null ? void 0 : _a2.variants) == null ? void 0 : _b2.some((variant) => variant.id === item.variant_id);
|
|
1195
1190
|
})) != null ? _d : [];
|
|
1196
|
-
const protectionVariantsInCartTotal = protectionVariantsInCart.reduce(
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
},
|
|
1201
|
-
0
|
|
1202
|
-
);
|
|
1191
|
+
const protectionVariantsInCartTotal = protectionVariantsInCart.reduce((total, item) => {
|
|
1192
|
+
const updatedTotal = total += item.final_line_price;
|
|
1193
|
+
return updatedTotal;
|
|
1194
|
+
}, 0);
|
|
1203
1195
|
const cartTotal = itemTotal - protectionVariantsInCartTotal;
|
|
1204
1196
|
if (settings.protectionType === "FIXED") {
|
|
1205
1197
|
if (!settings.defaultFee)
|
|
@@ -1229,20 +1221,18 @@ let ShipAidWidget = class extends s {
|
|
|
1229
1221
|
throw new Error("No protection type handler found for this store.");
|
|
1230
1222
|
}
|
|
1231
1223
|
_findProtectionVariant(protectionFee) {
|
|
1232
|
-
var _a, _b, _c;
|
|
1224
|
+
var _a, _b, _c, _d;
|
|
1233
1225
|
const settings = (_a = this._store) == null ? void 0 : _a.protectionSettings;
|
|
1234
|
-
if (!settings || !((_c = (_b =
|
|
1226
|
+
if (!settings || !((_c = (_b = this._protectionProduct) == null ? void 0 : _b.variants) == null ? void 0 : _c.length)) {
|
|
1235
1227
|
throw new Error("Missing product and variants from protection settings.");
|
|
1236
1228
|
}
|
|
1237
|
-
const formattedVariants =
|
|
1229
|
+
const formattedVariants = (_d = this._protectionProduct) == null ? void 0 : _d.variants.flatMap((variant) => {
|
|
1238
1230
|
if (!variant || !variant.price)
|
|
1239
1231
|
return [];
|
|
1240
1232
|
const formattedPrice = Number(variant.price);
|
|
1241
1233
|
return [{ ...variant, formattedPrice }];
|
|
1242
1234
|
}).sort((a2, b2) => a2.formattedPrice - b2.formattedPrice);
|
|
1243
|
-
const matchingVariant = formattedVariants.find(
|
|
1244
|
-
(variant) => variant.formattedPrice >= protectionFee
|
|
1245
|
-
);
|
|
1235
|
+
const matchingVariant = formattedVariants.find((variant) => variant.formattedPrice >= protectionFee);
|
|
1246
1236
|
if (!matchingVariant) {
|
|
1247
1237
|
return formattedVariants[formattedVariants.length - 1];
|
|
1248
1238
|
}
|
|
@@ -1297,6 +1287,16 @@ let ShipAidWidget = class extends s {
|
|
|
1297
1287
|
throw new Error("Could not fetch cart for current domain.");
|
|
1298
1288
|
}
|
|
1299
1289
|
}
|
|
1290
|
+
async _fetchProduct() {
|
|
1291
|
+
try {
|
|
1292
|
+
const { product } = await this._fetch.get(`/products/${PRODUCT_HANDLE}.json`);
|
|
1293
|
+
return product;
|
|
1294
|
+
} catch (err) {
|
|
1295
|
+
const error = err;
|
|
1296
|
+
logger.error(error.message);
|
|
1297
|
+
throw new Error("Could not fetch protection product for current domain.");
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
1300
|
hasProtection() {
|
|
1301
1301
|
return this._hasProtectionInCart;
|
|
1302
1302
|
}
|
|
@@ -1317,12 +1317,8 @@ let ShipAidWidget = class extends s {
|
|
|
1317
1317
|
}
|
|
1318
1318
|
this._setState("loading");
|
|
1319
1319
|
const payload = {
|
|
1320
|
-
id: this._protectionVariant.id.replace(
|
|
1321
|
-
"gid://shopify/ProductVariant/",
|
|
1322
|
-
""
|
|
1323
|
-
),
|
|
1324
1320
|
quantity: 1,
|
|
1325
|
-
|
|
1321
|
+
id: this._protectionVariant.id
|
|
1326
1322
|
};
|
|
1327
1323
|
const cartItem = await this._fetch.post(
|
|
1328
1324
|
"/cart/add.js",
|
|
@@ -1349,9 +1345,8 @@ let ShipAidWidget = class extends s {
|
|
|
1349
1345
|
}
|
|
1350
1346
|
this._setState("loading");
|
|
1351
1347
|
const payload = {
|
|
1352
|
-
id: this._protectionCartItem.key,
|
|
1353
1348
|
quantity: 0,
|
|
1354
|
-
|
|
1349
|
+
id: this._protectionCartItem.key
|
|
1355
1350
|
};
|
|
1356
1351
|
const cart = await this._fetch.post(
|
|
1357
1352
|
"/cart/change.js",
|
|
@@ -1373,7 +1368,7 @@ let ShipAidWidget = class extends s {
|
|
|
1373
1368
|
render() {
|
|
1374
1369
|
var _a;
|
|
1375
1370
|
useOnce(this, async () => {
|
|
1376
|
-
var _a2, _b
|
|
1371
|
+
var _a2, _b;
|
|
1377
1372
|
const linkEl = document.createElement("link");
|
|
1378
1373
|
linkEl.setAttribute(
|
|
1379
1374
|
"href",
|
|
@@ -1390,12 +1385,14 @@ let ShipAidWidget = class extends s {
|
|
|
1390
1385
|
logger.warn("Failed to parse local storage.");
|
|
1391
1386
|
}
|
|
1392
1387
|
try {
|
|
1393
|
-
const [storeData, cartData] = await Promise.all([
|
|
1388
|
+
const [storeData, cartData, productData] = await Promise.all([
|
|
1394
1389
|
this._fetchShipAidData(),
|
|
1395
|
-
this._fetchCart()
|
|
1390
|
+
this._fetchCart(),
|
|
1391
|
+
this._fetchProduct()
|
|
1396
1392
|
]);
|
|
1397
1393
|
this._store = storeData;
|
|
1398
1394
|
this._cart = cartData;
|
|
1395
|
+
this._protectionProduct = productData;
|
|
1399
1396
|
} catch (error) {
|
|
1400
1397
|
this._hasFinishedSetup = true;
|
|
1401
1398
|
this._shouldShowWidget = false;
|
|
@@ -1413,7 +1410,7 @@ let ShipAidWidget = class extends s {
|
|
|
1413
1410
|
this._shouldShowWidget = false;
|
|
1414
1411
|
return;
|
|
1415
1412
|
}
|
|
1416
|
-
if (!
|
|
1413
|
+
if (!this._protectionProduct) {
|
|
1417
1414
|
logger.warn("No protection settings product for this store - skipping setup.");
|
|
1418
1415
|
this._hasFinishedSetup = true;
|
|
1419
1416
|
this._shouldShowWidget = false;
|
|
@@ -1457,20 +1454,15 @@ let ShipAidWidget = class extends s {
|
|
|
1457
1454
|
useEffect(
|
|
1458
1455
|
this,
|
|
1459
1456
|
async () => {
|
|
1460
|
-
var _a2, _b, _c
|
|
1457
|
+
var _a2, _b, _c;
|
|
1461
1458
|
this._cartLastUpdated = new Date();
|
|
1462
1459
|
if (!((_a2 = this._cart) == null ? void 0 : _a2.items))
|
|
1463
1460
|
return;
|
|
1464
|
-
const protectionCartItemIndex = (
|
|
1465
|
-
var _a3, _b2
|
|
1466
|
-
return (
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
return (_a4 = node == null ? void 0 : node.id) == null ? void 0 : _a4.includes(item.variant_id.toString());
|
|
1470
|
-
}
|
|
1471
|
-
);
|
|
1472
|
-
})) != null ? _c : [];
|
|
1473
|
-
const protectionCartItem = (_d = this._cart) == null ? void 0 : _d.items[protectionCartItemIndex];
|
|
1461
|
+
const protectionCartItemIndex = (_b = this._cart.items) == null ? void 0 : _b.findIndex((item) => {
|
|
1462
|
+
var _a3, _b2;
|
|
1463
|
+
return (_b2 = (_a3 = this._protectionProduct) == null ? void 0 : _a3.variants) == null ? void 0 : _b2.some((variant) => variant.id === item.variant_id);
|
|
1464
|
+
});
|
|
1465
|
+
const protectionCartItem = (_c = this._cart) == null ? void 0 : _c.items[protectionCartItemIndex];
|
|
1474
1466
|
this._hasProtectionInCart = !!protectionCartItem;
|
|
1475
1467
|
if (this._cart.item_count === 1 && !!protectionCartItem) {
|
|
1476
1468
|
const removePayload2 = {
|
|
@@ -1493,13 +1485,20 @@ let ShipAidWidget = class extends s {
|
|
|
1493
1485
|
}
|
|
1494
1486
|
if (!protectionCartItem)
|
|
1495
1487
|
return;
|
|
1496
|
-
if (
|
|
1488
|
+
if (protectionVariant.id === protectionCartItem.id) {
|
|
1497
1489
|
this._protectionCartItem = {
|
|
1498
1490
|
...protectionCartItem,
|
|
1499
1491
|
index: protectionCartItemIndex,
|
|
1500
1492
|
position: protectionCartItemIndex + 1
|
|
1501
1493
|
};
|
|
1502
|
-
|
|
1494
|
+
if (protectionCartItem.quantity === 1)
|
|
1495
|
+
return;
|
|
1496
|
+
const updatePayload = {
|
|
1497
|
+
id: protectionCartItem.key,
|
|
1498
|
+
quantity: 1
|
|
1499
|
+
};
|
|
1500
|
+
const cart = await this._fetch.post("/cart/change.js", updatePayload);
|
|
1501
|
+
return await this._handleRefresh(cart);
|
|
1503
1502
|
}
|
|
1504
1503
|
const removePayload = {
|
|
1505
1504
|
id: protectionCartItem.key,
|
|
@@ -1507,9 +1506,8 @@ let ShipAidWidget = class extends s {
|
|
|
1507
1506
|
};
|
|
1508
1507
|
await this._fetch.post("/cart/change.js", removePayload);
|
|
1509
1508
|
const addPayload = {
|
|
1510
|
-
id: protectionVariant.id.replace("gid://shopify/ProductVariant/", ""),
|
|
1511
1509
|
quantity: 1,
|
|
1512
|
-
|
|
1510
|
+
id: protectionVariant.id
|
|
1513
1511
|
};
|
|
1514
1512
|
const cartItem = await this._fetch.post(
|
|
1515
1513
|
"/cart/add.js",
|
|
@@ -1592,10 +1590,10 @@ let ShipAidWidget = class extends s {
|
|
|
1592
1590
|
</div>
|
|
1593
1591
|
<div class="prompt-product-details">
|
|
1594
1592
|
<p class="prompt-product-details-title">
|
|
1595
|
-
Package Protection
|
|
1593
|
+
<slot name="title">Package Protection</slot>
|
|
1596
1594
|
</p>
|
|
1597
1595
|
<p class="prompt-product-details-description">
|
|
1598
|
-
from Loss, Damage or Theft
|
|
1596
|
+
<slot name="subtitle">from Loss, Damage or Theft</slot>
|
|
1599
1597
|
</p>
|
|
1600
1598
|
</div>
|
|
1601
1599
|
<div class="prompt-product-actions">
|
|
@@ -1648,7 +1646,7 @@ let ShipAidWidget = class extends s {
|
|
|
1648
1646
|
() => y``
|
|
1649
1647
|
);
|
|
1650
1648
|
},
|
|
1651
|
-
() => y`<p><slot>Loading ShipAid Widget...</slot></p>`
|
|
1649
|
+
() => y`<p><slot name="loading" default>Loading ShipAid Widget...</slot></p>`
|
|
1652
1650
|
)}
|
|
1653
1651
|
</div>
|
|
1654
1652
|
`;
|
|
@@ -1673,6 +1671,9 @@ __decorateClass([
|
|
|
1673
1671
|
__decorateClass([
|
|
1674
1672
|
t$2()
|
|
1675
1673
|
], ShipAidWidget.prototype, "_cart", 2);
|
|
1674
|
+
__decorateClass([
|
|
1675
|
+
t$2()
|
|
1676
|
+
], ShipAidWidget.prototype, "_protectionProduct", 2);
|
|
1676
1677
|
__decorateClass([
|
|
1677
1678
|
t$2()
|
|
1678
1679
|
], ShipAidWidget.prototype, "_cartLastUpdated", 2);
|
package/dist/widget.iife.js
CHANGED
|
@@ -24,7 +24,7 @@ var ShipAidWidget=function(t){"use strict";
|
|
|
24
24
|
* Copyright 2019 Google LLC
|
|
25
25
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
26
26
|
*/
|
|
27
|
-
const s=window,n=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,a=Symbol(),
|
|
27
|
+
const s=window,n=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,a=Symbol(),p=new WeakMap;class l{constructor(t,e,i){if(this._$cssResult$=!0,i!==a)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(n&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=p.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&p.set(e,t))}return t}toString(){return this.cssText}}const d=n?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return(t=>new l("string"==typeof t?t:t+"",void 0,a))(e)})(t):t
|
|
28
28
|
/**
|
|
29
29
|
* @license
|
|
30
30
|
* Copyright 2017 Google LLC
|
|
@@ -35,19 +35,19 @@ const s=window,n=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"
|
|
|
35
35
|
* Copyright 2017 Google LLC
|
|
36
36
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
37
37
|
*/
|
|
38
|
-
var y;C.finalized=!0,C.elementProperties=new Map,C.elementStyles=[],C.shadowRootOptions={mode:"open"},null==v||v({ReactiveElement:C}),(null!==(h=c.reactiveElementVersions)&&void 0!==h?h:c.reactiveElementVersions=[]).push("1.4.1");const w=window,$=w.trustedTypes,L=$?$.createPolicy("lit-html",{createHTML:t=>t}):void 0,A=`lit$${(Math.random()+"").slice(9)}$`,S="?"+A,b=`<${S}>`,x=document,E=(t="")=>x.createComment(t),P=t=>null===t||"object"!=typeof t&&"function"!=typeof t,k=Array.isArray,M=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,T=/-->/g,U=/>/g,z=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),O=/'/g,N=/"/g,
|
|
38
|
+
var y;C.finalized=!0,C.elementProperties=new Map,C.elementStyles=[],C.shadowRootOptions={mode:"open"},null==v||v({ReactiveElement:C}),(null!==(h=c.reactiveElementVersions)&&void 0!==h?h:c.reactiveElementVersions=[]).push("1.4.1");const w=window,$=w.trustedTypes,L=$?$.createPolicy("lit-html",{createHTML:t=>t}):void 0,A=`lit$${(Math.random()+"").slice(9)}$`,S="?"+A,b=`<${S}>`,x=document,E=(t="")=>x.createComment(t),P=t=>null===t||"object"!=typeof t&&"function"!=typeof t,k=Array.isArray,M=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,T=/-->/g,U=/>/g,z=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),O=/'/g,N=/"/g,R=/^(?:script|style|textarea|title)$/i,I=(B=1,(t,...e)=>({_$litType$:B,strings:t,values:e})),W=Symbol.for("lit-noChange"),H=Symbol.for("lit-nothing"),D=new WeakMap,j=x.createTreeWalker(x,129,null,!1);var B;class F{constructor({strings:t,_$litType$:e},i){let o;this.parts=[];let r=0,s=0;const n=t.length-1,a=this.parts,[p,l]=((t,e)=>{const i=t.length-1,o=[];let r,s=2===e?"<svg>":"",n=M;for(let p=0;p<i;p++){const e=t[p];let i,a,l=-1,d=0;for(;d<e.length&&(n.lastIndex=d,a=n.exec(e),null!==a);)d=n.lastIndex,n===M?"!--"===a[1]?n=T:void 0!==a[1]?n=U:void 0!==a[2]?(R.test(a[2])&&(r=RegExp("</"+a[2],"g")),n=z):void 0!==a[3]&&(n=z):n===z?">"===a[0]?(n=null!=r?r:M,l=-1):void 0===a[1]?l=-2:(l=n.lastIndex-a[2].length,i=a[1],n=void 0===a[3]?z:'"'===a[3]?N:O):n===N||n===O?n=z:n===T||n===U?n=M:(n=z,r=void 0);const h=n===z&&t[p+1].startsWith("/>")?" ":"";s+=n===M?e+b:l>=0?(o.push(i),e.slice(0,l)+"$lit$"+e.slice(l)+A+h):e+A+(-2===l?(o.push(void 0),p):h)}const a=s+(t[i]||"<?>")+(2===e?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==L?L.createHTML(a):a,o]})(t,e);if(this.el=F.createElement(p,i),j.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(o=j.nextNode())&&a.length<n;){if(1===o.nodeType){if(o.hasAttributes()){const t=[];for(const e of o.getAttributeNames())if(e.endsWith("$lit$")||e.startsWith(A)){const i=l[s++];if(t.push(e),void 0!==i){const t=o.getAttribute(i.toLowerCase()+"$lit$").split(A),e=/([.?@])?(.*)/.exec(i);a.push({type:1,index:r,name:e[2],strings:t,ctor:"."===e[1]?K:"?"===e[1]?G:"@"===e[1]?X:J})}else a.push({type:6,index:r})}for(const e of t)o.removeAttribute(e)}if(R.test(o.tagName)){const t=o.textContent.split(A),e=t.length-1;if(e>0){o.textContent=$?$.emptyScript:"";for(let i=0;i<e;i++)o.append(t[i],E()),j.nextNode(),a.push({type:2,index:++r});o.append(t[e],E())}}}else if(8===o.nodeType)if(o.data===S)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=o.data.indexOf(A,t+1));)a.push({type:7,index:r}),t+=A.length-1}r++}}static createElement(t,e){const i=x.createElement("template");return i.innerHTML=t,i}}function Z(t,e,i=t,o){var r,s,n,a;if(e===W)return e;let p=void 0!==o?null===(r=i._$Cl)||void 0===r?void 0:r[o]:i._$Cu;const l=P(e)?void 0:e._$litDirective$;return(null==p?void 0:p.constructor)!==l&&(null===(s=null==p?void 0:p._$AO)||void 0===s||s.call(p,!1),void 0===l?p=void 0:(p=new l(t),p._$AT(t,i,o)),void 0!==o?(null!==(n=(a=i)._$Cl)&&void 0!==n?n:a._$Cl=[])[o]=p:i._$Cu=p),void 0!==p&&(e=Z(t,p._$AS(t,e.values),p,o)),e}class q{constructor(t,e){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var e;const{el:{content:i},parts:o}=this._$AD,r=(null!==(e=null==t?void 0:t.creationScope)&&void 0!==e?e:x).importNode(i,!0);j.currentNode=r;let s=j.nextNode(),n=0,a=0,p=o[0];for(;void 0!==p;){if(n===p.index){let e;2===p.type?e=new V(s,s.nextSibling,this,t):1===p.type?e=new p.ctor(s,p.name,p.strings,this,t):6===p.type&&(e=new Q(s,this,t)),this.v.push(e),p=o[++a]}n!==(null==p?void 0:p.index)&&(s=j.nextNode(),n++)}return r}m(t){let e=0;for(const i of this.v)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class V{constructor(t,e,i,o){var r;this.type=2,this._$AH=H,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=o,this._$C_=null===(r=null==o?void 0:o.isConnected)||void 0===r||r}get _$AU(){var t,e;return null!==(e=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==e?e:this._$C_}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=Z(this,t,e),P(t)?t===H||null==t||""===t?(this._$AH!==H&&this._$AR(),this._$AH=H):t!==this._$AH&&t!==W&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.k(t):(t=>k(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]))(t)?this.O(t):this.$(t)}S(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.S(t))}$(t){this._$AH!==H&&P(this._$AH)?this._$AA.nextSibling.data=t:this.k(x.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:o}=t,r="number"==typeof o?this._$AC(t):(void 0===o.el&&(o.el=F.createElement(o.h,this.options)),o);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(i);else{const t=new q(r,this),e=t.p(this.options);t.m(i),this.k(e),this._$AH=t}}_$AC(t){let e=D.get(t.strings);return void 0===e&&D.set(t.strings,e=new F(t)),e}O(t){k(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,o=0;for(const r of t)o===e.length?e.push(i=new V(this.S(E()),this.S(E()),this,this.options)):i=e[o],i._$AI(r),o++;o<e.length&&(this._$AR(i&&i._$AB.nextSibling,o),e.length=o)}_$AR(t=this._$AA.nextSibling,e){var i;for(null===(i=this._$AP)||void 0===i||i.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$C_=t,null===(e=this._$AP)||void 0===e||e.call(this,t))}}class J{constructor(t,e,i,o,r){this.type=1,this._$AH=H,this._$AN=void 0,this.element=t,this.name=e,this._$AM=o,this.options=r,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=H}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,o){const r=this.strings;let s=!1;if(void 0===r)t=Z(this,t,e,0),s=!P(t)||t!==this._$AH&&t!==W,s&&(this._$AH=t);else{const o=t;let n,a;for(t=r[0],n=0;n<r.length-1;n++)a=Z(this,o[i+n],e,n),a===W&&(a=this._$AH[n]),s||(s=!P(a)||a!==this._$AH[n]),a===H?t=H:t!==H&&(t+=(null!=a?a:"")+r[n+1]),this._$AH[n]=a}s&&!o&&this.P(t)}P(t){t===H?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class K extends J{constructor(){super(...arguments),this.type=3}P(t){this.element[this.name]=t===H?void 0:t}}const Y=$?$.emptyScript:"";class G extends J{constructor(){super(...arguments),this.type=4}P(t){t&&t!==H?this.element.setAttribute(this.name,Y):this.element.removeAttribute(this.name)}}class X extends J{constructor(t,e,i,o,r){super(t,e,i,o,r),this.type=5}_$AI(t,e=this){var i;if((t=null!==(i=Z(this,t,e,0))&&void 0!==i?i:H)===W)return;const o=this._$AH,r=t===H&&o!==H||t.capture!==o.capture||t.once!==o.once||t.passive!==o.passive,s=t!==H&&(o===H||r);r&&this.element.removeEventListener(this.name,this,o),s&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;"function"==typeof this._$AH?this._$AH.call(null!==(i=null===(e=this.options)||void 0===e?void 0:e.host)&&void 0!==i?i:this.element,t):this._$AH.handleEvent(t)}}class Q{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){Z(this,t)}}const tt=w.litHtmlPolyfillSupport;
|
|
39
39
|
/**
|
|
40
40
|
* @license
|
|
41
41
|
* Copyright 2017 Google LLC
|
|
42
42
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
43
43
|
*/
|
|
44
|
-
var et,it;null==tt||tt(F,
|
|
44
|
+
var et,it;null==tt||tt(F,V),(null!==(y=w.litHtmlVersions)&&void 0!==y?y:w.litHtmlVersions=[]).push("2.3.1");class ot extends C{constructor(){super(...arguments),this.renderOptions={host:this},this._$Dt=void 0}createRenderRoot(){var t,e;const i=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=i.firstChild),i}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Dt=((t,e,i)=>{var o,r;const s=null!==(o=null==i?void 0:i.renderBefore)&&void 0!==o?o:e;let n=s._$litPart$;if(void 0===n){const t=null!==(r=null==i?void 0:i.renderBefore)&&void 0!==r?r:null;s._$litPart$=n=new V(e.insertBefore(E(),t),t,void 0,null!=i?i:{})}return n._$AI(t),n})(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!1)}render(){return W}}ot.finalized=!0,ot._$litElement$=!0,null===(et=globalThis.litElementHydrateSupport)||void 0===et||et.call(globalThis,{LitElement:ot});const rt=globalThis.litElementPolyfillSupport;null==rt||rt({LitElement:ot}),(null!==(it=globalThis.litElementVersions)&&void 0!==it?it:globalThis.litElementVersions=[]).push("3.2.0");const st="__registered_effects";function nt(t){const e=t;if(e[st])return e;const i=function(t){if(!t.dispatchEvent||!t.requestUpdate)throw new Error("Element missing required functions (dispatchEvent/requestUpdate)");return t}(t),o=i.updated;return e[st]={index:0,count:0,effects:[]},i.updated=t=>(e[st].index=0,o(t)),e}function at(t,e,i){const o=function(t,e){const i=nt(t),{index:o,count:r}=i[st];return o===r?(i[st].index++,i[st].count++,i[st].effects.push(e),e):(i[st].index++,i[st].effects[o])}(t,{on:e,observe:["__initial__dirty"]});o.observe.some(((t,e)=>i[e]!==t))&&o.on(),o.observe=i}
|
|
45
45
|
/**
|
|
46
46
|
* @license
|
|
47
47
|
* Copyright 2021 Google LLC
|
|
48
48
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
49
49
|
*/
|
|
50
|
-
function
|
|
50
|
+
function pt(t,e,i){return t?e():null==i?void 0:i()}const lt=((t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,o)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[o+1]),t[0]);return new l(i,t,a)})`
|
|
51
51
|
:host {
|
|
52
52
|
--shipaid-primary: #002bd6;
|
|
53
53
|
--shipaid-secondary: #0076ff;
|
|
@@ -311,14 +311,14 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
311
311
|
color: var(--shipaid-text-grey);
|
|
312
312
|
font-weight: var(--shipaid-font-heavy);
|
|
313
313
|
}
|
|
314
|
-
`,dt=
|
|
314
|
+
`,dt=I`
|
|
315
315
|
<svg viewBox="0 0 453 511" version="1.1" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
|
316
316
|
<g transform="matrix(1,0,0,1,-29.4375,-0.984384)">
|
|
317
317
|
<path d="M468.297,67.385L262.417,2C258.177,0.646 253.63,0.646 249.391,2L43.51,67.385C35.188,69.708 29.438,77.318 29.438,85.979C32.302,157.156 52.266,370.036 52.266,370.036C52.906,378.188 57.297,385.568 64.167,390.01L248.807,509.156C253.12,511.943 258.688,511.943 263.005,509.156L447.641,390.01C454.51,385.568 458.901,378.188 459.542,370.036C459.542,370.036 479.51,157.156 482.37,85.979C482.37,77.318 476.625,69.708 468.297,67.385" style="fill:rgb(47,52,61);fill-rule:nonzero;"/>
|
|
318
318
|
<path d="M256.01,120.969C286.193,120.969 314.057,130.87 336.536,147.604L309.406,174.656C294.073,164.573 275.729,158.708 256.01,158.708C229.141,158.708 204.823,169.604 187.214,187.198C169.615,204.797 158.719,229.125 158.719,255.995C158.719,282.865 169.615,307.182 187.214,324.792C204.813,342.406 229.141,353.286 256.01,353.286C282.88,353.286 307.208,342.406 324.807,324.792C342.406,307.193 353.297,282.865 353.297,255.995C353.297,251.818 353.036,247.719 352.526,243.688L383.859,212.458C388.51,226.115 391.036,240.766 391.036,255.995C391.036,293.286 375.927,327.047 351.49,351.479C327.057,375.911 293.302,391.021 256.01,391.021C218.729,391.021 184.964,375.911 160.526,351.479C136.094,327.047 120.984,293.286 120.984,255.995C120.984,218.719 136.094,184.948 160.526,160.516C184.964,136.083 218.719,120.969 256.01,120.969ZM218.141,220.906L253.615,259.729L354.844,158.813L381.375,185.484L252.396,314.068L190.422,246.255L218.13,220.906L218.141,220.906Z" style="fill:white;fill-rule:nonzero;"/>
|
|
319
319
|
</g>
|
|
320
320
|
</svg>
|
|
321
|
-
`,ht=
|
|
321
|
+
`,ht=I`
|
|
322
322
|
<svg
|
|
323
323
|
viewBox="0 0 384 383.999986"
|
|
324
324
|
preserveAspectRatio="xMidYMid meet"
|
|
@@ -360,7 +360,7 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
360
360
|
/>
|
|
361
361
|
</g>
|
|
362
362
|
</svg>
|
|
363
|
-
`,ct=
|
|
363
|
+
`,ct=I`
|
|
364
364
|
<svg
|
|
365
365
|
viewBox="0 0 423 62"
|
|
366
366
|
version="1.1"
|
|
@@ -442,7 +442,7 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
442
442
|
/>
|
|
443
443
|
</g>
|
|
444
444
|
</svg>
|
|
445
|
-
`;var ut=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(ut||{}),ft=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,mt=(t,e,i,o)=>{for(var r,s=o>1?void 0:o?vt(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(s=(o?r(e,i,s):r(s))||s);return o&&s&&ft(e,i,s),s};const gt=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},_t=t=>console.warn(`[ShipAid] ${t}`),Ct=t=>console.error(`[ShipAid] ${t}`),yt="shipaid-protection";var wt;return t.ShipAidWidget=class extends ot{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this.disableRefresh=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>gt(t),post:(t,e)=>gt(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}get shouldRefreshOnUpdate(){
|
|
445
|
+
`;var ut=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(ut||{}),ft=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,mt=(t,e,i,o)=>{for(var r,s=o>1?void 0:o?vt(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(s=(o?r(e,i,s):r(s))||s);return o&&s&&ft(e,i,s),s};const gt=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},_t=t=>console.warn(`[ShipAid] ${t}`),Ct=t=>console.error(`[ShipAid] ${t}`),yt="shipaid-protection";var wt;return t.ShipAidWidget=class extends ot{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this.disableRefresh=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>gt(t),post:(t,e)=>gt(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}get shouldRefreshOnUpdate(){return!this.disablePolling&&!this.disableRefresh}get planActive(){var t,e;const{searchParams:i}=new URL(window.location.href);return(null==(t=window.Shopify)?void 0:t.designMode)||i.has("shipaid-test")?(_t("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,o,r,s;return new Intl.NumberFormat(null!=(i=null==(e=window.Shopify)?void 0:e.locale)?i:void 0,{currency:(null==(o=this._store)?void 0:o.currency)||(null==(s=null==(r=window.Shopify)?void 0:r.currency)?void 0:s.active)||"USD",style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(ut.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){var e,i,o,r,s;if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const n=null==(e=this._store)?void 0:e.protectionSettings;if(!n||!this._protectionProduct)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const a=((null==(i=this._store)?void 0:i.excludedProductSkus)&&t.items?t.items.reduce(((t,e)=>{if(!e.sku)return t;return this._store.excludedProductSkus.find((t=>t===e.sku))?t-e.final_price:t}),t.total_price):t.total_price)-(null!=(r=null==(o=t.items)?void 0:o.filter((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})))?r:[]).reduce(((t,e)=>t+=e.final_line_price),0);if("FIXED"===n.protectionType){if(!n.defaultFee)throw new Error("Missing default fee amount.");if(!(null==(s=n.rules)?void 0:s.length))return n.defaultFee;const t=a/100,e=n.rules.sort(((t,e)=>t.rangeLower&&e.rangeLower?t.rangeLower-e.rangeLower:0)).find((e=>{const i=Boolean(e.rangeLower&&e.rangeLower<t);return e.rangeUpper?i&&e.rangeUpper>=t:i}));return"number"==typeof(null==e?void 0:e.fee)?e.fee:n.defaultFee}if("PERCENTAGE"===n.protectionType){const t=a*n.percentage/100;return t>=n.minimumFee?t:n.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(t){var e,i,o,r;if(!(null==(e=this._store)?void 0:e.protectionSettings)||!(null==(o=null==(i=this._protectionProduct)?void 0:i.variants)?void 0:o.length))throw new Error("Missing product and variants from protection settings.");const s=null==(r=this._protectionProduct)?void 0:r.variants.flatMap((t=>{if(!t||!t.price)return[];const e=Number(t.price);return[{...t,formattedPrice:e}]})).sort(((t,e)=>t.formattedPrice-e.formattedPrice)),n=s.find((e=>e.formattedPrice>=t));return n||s[s.length-1]}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){var t,e,i;const o=null==(t=window.Shopify)?void 0:t.shop;if(!o)throw new Error("No shop found in Shopify object.");try{const t=new URL(window.location.href);t.pathname=this._apiEndpoint;const r={query:"query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetShowCart\n excludedProductSkus\n protectionSettings\n }\n}",variables:{store:o}},s=await this._fetch.post(t.toString(),r);if(!s)throw new Error("Missing response for store query.");if(null==(e=s.errors)?void 0:e.length)throw new Error(s.errors[0].message);if(!(null==(i=s.data)?void 0:i.store))throw new Error("Missing store from store query response.");return s.data.store}catch(r){throw console.error(r),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(t){throw Ct(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){try{const{product:t}=await this._fetch.get("/products/shipaid-protection.json");return t}catch(t){throw Ct(t.message),new Error("Could not fetch protection product for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addProtection(){var t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!(null==(t=this._cart)?void 0:t.items))throw new Error("Cart has not been loaded.");if(!(null==(e=this._protectionVariant)?void 0:e.id))throw new Error("No protection variant found.");this._setState("loading");const i={quantity:1,id:this._protectionVariant.id},o=await this._fetch.post("/cart/add.js",i);await this._handleRefresh(o),this._lastAction="added",this._setState("success")}catch(i){Ct(i.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const t={quantity:0,id:this._protectionCartItem.key},e=await this._fetch.post("/cart/change.js",t);await this._handleRefresh(e),this._lastAction="removed",this._cart=e,this._setState("success")}catch(t){Ct(t.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}render(){var t;at(this,(async()=>{var t,e;const i=document.createElement("link");i.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),i.setAttribute("rel","stylesheet"),document.head.appendChild(i);try{const t=sessionStorage.getItem(yt),{lastAction:e}=t?JSON.parse(t):{};e&&(this._lastAction=e)}catch(o){_t("Failed to parse local storage.")}try{const[t,e,i]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=t,this._cart=e,this._protectionProduct=i}catch(o){return this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return this.planActive?(null==(e=null==(t=this._store)?void 0:t.protectionSettings)?void 0:e.protectionType)?this._protectionProduct?(this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(ut.LOADED,this._store),setTimeout((async()=>{var t,e;const i=sessionStorage.getItem(yt),{lastAction:o}=i?JSON.parse(i):{};"removed"!==o&&!this._hasProtectionInCart&&(null==(t=this._cart)?void 0:t.item_count)&&(null==(e=this._store)?void 0:e.widgetAutoOptIn)&&this._store.widgetShowCart&&await this.addProtection()}),500),void(this.disablePolling||setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval))):(_t("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(_t("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(_t("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))}),[]),at(this,(()=>{const t={hasProtection:this._hasProtectionInCart,lastAction:this._lastAction};sessionStorage.setItem(yt,JSON.stringify(t))}),[this._lastAction]),at(this,(async()=>{var t,e,i;if(this._cartLastUpdated=new Date,!(null==(t=this._cart)?void 0:t.items))return;const o=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),r=null==(i=this._cart)?void 0:i.items[o];if(this._hasProtectionInCart=!!r,1===this._cart.item_count&&r){const t={id:r.key,quantity:0},e=await this._fetch.post("/cart/change.js",t);return await this._handleRefresh(e)}const s=await this.calculateProtectionTotal(this._cart),n=this._findProtectionVariant(s);if(this._protectionVariant=n,!(null==n?void 0:n.id))return this._shouldShowWidget=!1,void Ct("No matching protection variant found.");if(!r)return;if(n.id===r.id){if(this._protectionCartItem={...r,index:o,position:o+1},1===r.quantity)return;const t={id:r.key,quantity:1},e=await this._fetch.post("/cart/change.js",t);return await this._handleRefresh(e)}const a={id:r.key,quantity:0};await this._fetch.post("/cart/change.js",a);const p={quantity:1,id:n.id},l=await this._fetch.post("/cart/add.js",p);await this._handleRefresh(l)}),[this._store,this._cart]);const e=I`
|
|
446
446
|
<div class=${`shipaid-popup ${"learn-more"===this._popup&&"active"}`}>
|
|
447
447
|
<div class="popup">
|
|
448
448
|
<button
|
|
@@ -500,18 +500,18 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
500
500
|
</div>
|
|
501
501
|
</div>
|
|
502
502
|
</div>
|
|
503
|
-
`,i=
|
|
503
|
+
`,i=I`
|
|
504
504
|
<div class="shipaid-prompt">
|
|
505
505
|
<div class="prompt-product">
|
|
506
506
|
<div class="prompt-product-image">
|
|
507
|
-
${
|
|
507
|
+
${pt(this._hasProtectionInCart,(()=>dt),(()=>ht))}
|
|
508
508
|
</div>
|
|
509
509
|
<div class="prompt-product-details">
|
|
510
510
|
<p class="prompt-product-details-title">
|
|
511
|
-
Package Protection
|
|
511
|
+
<slot name="title">Package Protection</slot>
|
|
512
512
|
</p>
|
|
513
513
|
<p class="prompt-product-details-description">
|
|
514
|
-
from Loss, Damage or Theft
|
|
514
|
+
<slot name="subtitle">from Loss, Damage or Theft</slot>
|
|
515
515
|
</p>
|
|
516
516
|
</div>
|
|
517
517
|
<div class="prompt-product-actions">
|
|
@@ -527,7 +527,7 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
527
527
|
</button>
|
|
528
528
|
</div>
|
|
529
529
|
</div>
|
|
530
|
-
${
|
|
530
|
+
${pt(this._state.error,(()=>I`<p class="error">${this._state.error}</p>`))}
|
|
531
531
|
<div class="prompt-footer">
|
|
532
532
|
<a
|
|
533
533
|
class="prompt-footer-badge"
|
|
@@ -544,8 +544,8 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
544
544
|
</button>
|
|
545
545
|
</div>
|
|
546
546
|
</div>
|
|
547
|
-
`;return
|
|
547
|
+
`;return I`
|
|
548
548
|
<div class="shipaid">
|
|
549
|
-
${
|
|
549
|
+
${pt(this._hasFinishedSetup,(()=>{var t;return pt(this._shouldShowWidget&&this.planActive&&(null==(t=this._store)?void 0:t.widgetShowCart),(()=>[e,i]),(()=>I``))}),(()=>I`<p><slot name="loading" default>Loading ShipAid Widget...</slot></p>`))}
|
|
550
550
|
</div>
|
|
551
|
-
`}},t.ShipAidWidget.styles=
|
|
551
|
+
`}},t.ShipAidWidget.styles=lt,mt([i({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disablePolling",2),mt([i({type:Number,attribute:!0})],t.ShipAidWidget.prototype,"pollingInterval",2),mt([i({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disableRefresh",2),mt([o()],t.ShipAidWidget.prototype,"_storeDomain",2),mt([o()],t.ShipAidWidget.prototype,"_store",2),mt([o()],t.ShipAidWidget.prototype,"_cart",2),mt([o()],t.ShipAidWidget.prototype,"_protectionProduct",2),mt([o()],t.ShipAidWidget.prototype,"_cartLastUpdated",2),mt([o()],t.ShipAidWidget.prototype,"_hasFinishedSetup",2),mt([o()],t.ShipAidWidget.prototype,"_shouldShowWidget",2),mt([o()],t.ShipAidWidget.prototype,"_hasProtectionInCart",2),mt([o()],t.ShipAidWidget.prototype,"_lastAction",2),mt([o()],t.ShipAidWidget.prototype,"_protectionCartItem",2),mt([o()],t.ShipAidWidget.prototype,"_protectionVariant",2),mt([o()],t.ShipAidWidget.prototype,"_state",2),mt([o()],t.ShipAidWidget.prototype,"_popup",2),t.ShipAidWidget=mt([(wt="shipaid-widget",t=>{return"function"==typeof t?(e=wt,i=t,customElements.define(e,i),i):((t,e)=>{const{kind:i,elements:o}=e;return{kind:i,elements:o,finisher(e){customElements.define(t,e)}}})(wt,t);var e,i})],t.ShipAidWidget),Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),t}({});
|
package/dist/widget.umd.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* Copyright 2019 Google LLC
|
|
25
25
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
26
26
|
*/
|
|
27
|
-
const s=window,n=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,a=Symbol(),
|
|
27
|
+
const s=window,n=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,a=Symbol(),p=new WeakMap;class l{constructor(t,e,i){if(this._$cssResult$=!0,i!==a)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(n&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=p.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&p.set(e,t))}return t}toString(){return this.cssText}}const d=n?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return(t=>new l("string"==typeof t?t:t+"",void 0,a))(e)})(t):t
|
|
28
28
|
/**
|
|
29
29
|
* @license
|
|
30
30
|
* Copyright 2017 Google LLC
|
|
@@ -35,19 +35,19 @@ const s=window,n=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"
|
|
|
35
35
|
* Copyright 2017 Google LLC
|
|
36
36
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
37
37
|
*/
|
|
38
|
-
var y;C.finalized=!0,C.elementProperties=new Map,C.elementStyles=[],C.shadowRootOptions={mode:"open"},null==v||v({ReactiveElement:C}),(null!==(h=c.reactiveElementVersions)&&void 0!==h?h:c.reactiveElementVersions=[]).push("1.4.1");const w=window,$=w.trustedTypes,L=$?$.createPolicy("lit-html",{createHTML:t=>t}):void 0,A=`lit$${(Math.random()+"").slice(9)}$`,S="?"+A,b=`<${S}>`,x=document,E=(t="")=>x.createComment(t),P=t=>null===t||"object"!=typeof t&&"function"!=typeof t,k=Array.isArray,M=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,T=/-->/g,U=/>/g,z=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),O=/'/g,N=/"/g,
|
|
38
|
+
var y;C.finalized=!0,C.elementProperties=new Map,C.elementStyles=[],C.shadowRootOptions={mode:"open"},null==v||v({ReactiveElement:C}),(null!==(h=c.reactiveElementVersions)&&void 0!==h?h:c.reactiveElementVersions=[]).push("1.4.1");const w=window,$=w.trustedTypes,L=$?$.createPolicy("lit-html",{createHTML:t=>t}):void 0,A=`lit$${(Math.random()+"").slice(9)}$`,S="?"+A,b=`<${S}>`,x=document,E=(t="")=>x.createComment(t),P=t=>null===t||"object"!=typeof t&&"function"!=typeof t,k=Array.isArray,M=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,T=/-->/g,U=/>/g,z=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),O=/'/g,N=/"/g,R=/^(?:script|style|textarea|title)$/i,I=(B=1,(t,...e)=>({_$litType$:B,strings:t,values:e})),W=Symbol.for("lit-noChange"),H=Symbol.for("lit-nothing"),j=new WeakMap,D=x.createTreeWalker(x,129,null,!1);var B;class F{constructor({strings:t,_$litType$:e},i){let o;this.parts=[];let r=0,s=0;const n=t.length-1,a=this.parts,[p,l]=((t,e)=>{const i=t.length-1,o=[];let r,s=2===e?"<svg>":"",n=M;for(let p=0;p<i;p++){const e=t[p];let i,a,l=-1,d=0;for(;d<e.length&&(n.lastIndex=d,a=n.exec(e),null!==a);)d=n.lastIndex,n===M?"!--"===a[1]?n=T:void 0!==a[1]?n=U:void 0!==a[2]?(R.test(a[2])&&(r=RegExp("</"+a[2],"g")),n=z):void 0!==a[3]&&(n=z):n===z?">"===a[0]?(n=null!=r?r:M,l=-1):void 0===a[1]?l=-2:(l=n.lastIndex-a[2].length,i=a[1],n=void 0===a[3]?z:'"'===a[3]?N:O):n===N||n===O?n=z:n===T||n===U?n=M:(n=z,r=void 0);const h=n===z&&t[p+1].startsWith("/>")?" ":"";s+=n===M?e+b:l>=0?(o.push(i),e.slice(0,l)+"$lit$"+e.slice(l)+A+h):e+A+(-2===l?(o.push(void 0),p):h)}const a=s+(t[i]||"<?>")+(2===e?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==L?L.createHTML(a):a,o]})(t,e);if(this.el=F.createElement(p,i),D.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(o=D.nextNode())&&a.length<n;){if(1===o.nodeType){if(o.hasAttributes()){const t=[];for(const e of o.getAttributeNames())if(e.endsWith("$lit$")||e.startsWith(A)){const i=l[s++];if(t.push(e),void 0!==i){const t=o.getAttribute(i.toLowerCase()+"$lit$").split(A),e=/([.?@])?(.*)/.exec(i);a.push({type:1,index:r,name:e[2],strings:t,ctor:"."===e[1]?K:"?"===e[1]?G:"@"===e[1]?X:J})}else a.push({type:6,index:r})}for(const e of t)o.removeAttribute(e)}if(R.test(o.tagName)){const t=o.textContent.split(A),e=t.length-1;if(e>0){o.textContent=$?$.emptyScript:"";for(let i=0;i<e;i++)o.append(t[i],E()),D.nextNode(),a.push({type:2,index:++r});o.append(t[e],E())}}}else if(8===o.nodeType)if(o.data===S)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=o.data.indexOf(A,t+1));)a.push({type:7,index:r}),t+=A.length-1}r++}}static createElement(t,e){const i=x.createElement("template");return i.innerHTML=t,i}}function Z(t,e,i=t,o){var r,s,n,a;if(e===W)return e;let p=void 0!==o?null===(r=i._$Cl)||void 0===r?void 0:r[o]:i._$Cu;const l=P(e)?void 0:e._$litDirective$;return(null==p?void 0:p.constructor)!==l&&(null===(s=null==p?void 0:p._$AO)||void 0===s||s.call(p,!1),void 0===l?p=void 0:(p=new l(t),p._$AT(t,i,o)),void 0!==o?(null!==(n=(a=i)._$Cl)&&void 0!==n?n:a._$Cl=[])[o]=p:i._$Cu=p),void 0!==p&&(e=Z(t,p._$AS(t,e.values),p,o)),e}class q{constructor(t,e){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var e;const{el:{content:i},parts:o}=this._$AD,r=(null!==(e=null==t?void 0:t.creationScope)&&void 0!==e?e:x).importNode(i,!0);D.currentNode=r;let s=D.nextNode(),n=0,a=0,p=o[0];for(;void 0!==p;){if(n===p.index){let e;2===p.type?e=new V(s,s.nextSibling,this,t):1===p.type?e=new p.ctor(s,p.name,p.strings,this,t):6===p.type&&(e=new Q(s,this,t)),this.v.push(e),p=o[++a]}n!==(null==p?void 0:p.index)&&(s=D.nextNode(),n++)}return r}m(t){let e=0;for(const i of this.v)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class V{constructor(t,e,i,o){var r;this.type=2,this._$AH=H,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=o,this._$C_=null===(r=null==o?void 0:o.isConnected)||void 0===r||r}get _$AU(){var t,e;return null!==(e=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==e?e:this._$C_}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=Z(this,t,e),P(t)?t===H||null==t||""===t?(this._$AH!==H&&this._$AR(),this._$AH=H):t!==this._$AH&&t!==W&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.k(t):(t=>k(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]))(t)?this.O(t):this.$(t)}S(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.S(t))}$(t){this._$AH!==H&&P(this._$AH)?this._$AA.nextSibling.data=t:this.k(x.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:o}=t,r="number"==typeof o?this._$AC(t):(void 0===o.el&&(o.el=F.createElement(o.h,this.options)),o);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(i);else{const t=new q(r,this),e=t.p(this.options);t.m(i),this.k(e),this._$AH=t}}_$AC(t){let e=j.get(t.strings);return void 0===e&&j.set(t.strings,e=new F(t)),e}O(t){k(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,o=0;for(const r of t)o===e.length?e.push(i=new V(this.S(E()),this.S(E()),this,this.options)):i=e[o],i._$AI(r),o++;o<e.length&&(this._$AR(i&&i._$AB.nextSibling,o),e.length=o)}_$AR(t=this._$AA.nextSibling,e){var i;for(null===(i=this._$AP)||void 0===i||i.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$C_=t,null===(e=this._$AP)||void 0===e||e.call(this,t))}}class J{constructor(t,e,i,o,r){this.type=1,this._$AH=H,this._$AN=void 0,this.element=t,this.name=e,this._$AM=o,this.options=r,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=H}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,o){const r=this.strings;let s=!1;if(void 0===r)t=Z(this,t,e,0),s=!P(t)||t!==this._$AH&&t!==W,s&&(this._$AH=t);else{const o=t;let n,a;for(t=r[0],n=0;n<r.length-1;n++)a=Z(this,o[i+n],e,n),a===W&&(a=this._$AH[n]),s||(s=!P(a)||a!==this._$AH[n]),a===H?t=H:t!==H&&(t+=(null!=a?a:"")+r[n+1]),this._$AH[n]=a}s&&!o&&this.P(t)}P(t){t===H?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class K extends J{constructor(){super(...arguments),this.type=3}P(t){this.element[this.name]=t===H?void 0:t}}const Y=$?$.emptyScript:"";class G extends J{constructor(){super(...arguments),this.type=4}P(t){t&&t!==H?this.element.setAttribute(this.name,Y):this.element.removeAttribute(this.name)}}class X extends J{constructor(t,e,i,o,r){super(t,e,i,o,r),this.type=5}_$AI(t,e=this){var i;if((t=null!==(i=Z(this,t,e,0))&&void 0!==i?i:H)===W)return;const o=this._$AH,r=t===H&&o!==H||t.capture!==o.capture||t.once!==o.once||t.passive!==o.passive,s=t!==H&&(o===H||r);r&&this.element.removeEventListener(this.name,this,o),s&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;"function"==typeof this._$AH?this._$AH.call(null!==(i=null===(e=this.options)||void 0===e?void 0:e.host)&&void 0!==i?i:this.element,t):this._$AH.handleEvent(t)}}class Q{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){Z(this,t)}}const tt=w.litHtmlPolyfillSupport;
|
|
39
39
|
/**
|
|
40
40
|
* @license
|
|
41
41
|
* Copyright 2017 Google LLC
|
|
42
42
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
43
43
|
*/
|
|
44
|
-
var et,it;null==tt||tt(F,
|
|
44
|
+
var et,it;null==tt||tt(F,V),(null!==(y=w.litHtmlVersions)&&void 0!==y?y:w.litHtmlVersions=[]).push("2.3.1");class ot extends C{constructor(){super(...arguments),this.renderOptions={host:this},this._$Dt=void 0}createRenderRoot(){var t,e;const i=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=i.firstChild),i}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Dt=((t,e,i)=>{var o,r;const s=null!==(o=null==i?void 0:i.renderBefore)&&void 0!==o?o:e;let n=s._$litPart$;if(void 0===n){const t=null!==(r=null==i?void 0:i.renderBefore)&&void 0!==r?r:null;s._$litPart$=n=new V(e.insertBefore(E(),t),t,void 0,null!=i?i:{})}return n._$AI(t),n})(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!1)}render(){return W}}ot.finalized=!0,ot._$litElement$=!0,null===(et=globalThis.litElementHydrateSupport)||void 0===et||et.call(globalThis,{LitElement:ot});const rt=globalThis.litElementPolyfillSupport;null==rt||rt({LitElement:ot}),(null!==(it=globalThis.litElementVersions)&&void 0!==it?it:globalThis.litElementVersions=[]).push("3.2.0");const st="__registered_effects";function nt(t){const e=t;if(e[st])return e;const i=function(t){if(!t.dispatchEvent||!t.requestUpdate)throw new Error("Element missing required functions (dispatchEvent/requestUpdate)");return t}(t),o=i.updated;return e[st]={index:0,count:0,effects:[]},i.updated=t=>(e[st].index=0,o(t)),e}function at(t,e,i){const o=function(t,e){const i=nt(t),{index:o,count:r}=i[st];return o===r?(i[st].index++,i[st].count++,i[st].effects.push(e),e):(i[st].index++,i[st].effects[o])}(t,{on:e,observe:["__initial__dirty"]});o.observe.some(((t,e)=>i[e]!==t))&&o.on(),o.observe=i}
|
|
45
45
|
/**
|
|
46
46
|
* @license
|
|
47
47
|
* Copyright 2021 Google LLC
|
|
48
48
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
49
49
|
*/
|
|
50
|
-
function
|
|
50
|
+
function pt(t,e,i){return t?e():null==i?void 0:i()}const lt=((t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,o)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[o+1]),t[0]);return new l(i,t,a)})`
|
|
51
51
|
:host {
|
|
52
52
|
--shipaid-primary: #002bd6;
|
|
53
53
|
--shipaid-secondary: #0076ff;
|
|
@@ -311,14 +311,14 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
311
311
|
color: var(--shipaid-text-grey);
|
|
312
312
|
font-weight: var(--shipaid-font-heavy);
|
|
313
313
|
}
|
|
314
|
-
`,dt=
|
|
314
|
+
`,dt=I`
|
|
315
315
|
<svg viewBox="0 0 453 511" version="1.1" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
|
316
316
|
<g transform="matrix(1,0,0,1,-29.4375,-0.984384)">
|
|
317
317
|
<path d="M468.297,67.385L262.417,2C258.177,0.646 253.63,0.646 249.391,2L43.51,67.385C35.188,69.708 29.438,77.318 29.438,85.979C32.302,157.156 52.266,370.036 52.266,370.036C52.906,378.188 57.297,385.568 64.167,390.01L248.807,509.156C253.12,511.943 258.688,511.943 263.005,509.156L447.641,390.01C454.51,385.568 458.901,378.188 459.542,370.036C459.542,370.036 479.51,157.156 482.37,85.979C482.37,77.318 476.625,69.708 468.297,67.385" style="fill:rgb(47,52,61);fill-rule:nonzero;"/>
|
|
318
318
|
<path d="M256.01,120.969C286.193,120.969 314.057,130.87 336.536,147.604L309.406,174.656C294.073,164.573 275.729,158.708 256.01,158.708C229.141,158.708 204.823,169.604 187.214,187.198C169.615,204.797 158.719,229.125 158.719,255.995C158.719,282.865 169.615,307.182 187.214,324.792C204.813,342.406 229.141,353.286 256.01,353.286C282.88,353.286 307.208,342.406 324.807,324.792C342.406,307.193 353.297,282.865 353.297,255.995C353.297,251.818 353.036,247.719 352.526,243.688L383.859,212.458C388.51,226.115 391.036,240.766 391.036,255.995C391.036,293.286 375.927,327.047 351.49,351.479C327.057,375.911 293.302,391.021 256.01,391.021C218.729,391.021 184.964,375.911 160.526,351.479C136.094,327.047 120.984,293.286 120.984,255.995C120.984,218.719 136.094,184.948 160.526,160.516C184.964,136.083 218.719,120.969 256.01,120.969ZM218.141,220.906L253.615,259.729L354.844,158.813L381.375,185.484L252.396,314.068L190.422,246.255L218.13,220.906L218.141,220.906Z" style="fill:white;fill-rule:nonzero;"/>
|
|
319
319
|
</g>
|
|
320
320
|
</svg>
|
|
321
|
-
`,ht=
|
|
321
|
+
`,ht=I`
|
|
322
322
|
<svg
|
|
323
323
|
viewBox="0 0 384 383.999986"
|
|
324
324
|
preserveAspectRatio="xMidYMid meet"
|
|
@@ -360,7 +360,7 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
360
360
|
/>
|
|
361
361
|
</g>
|
|
362
362
|
</svg>
|
|
363
|
-
`,ct=
|
|
363
|
+
`,ct=I`
|
|
364
364
|
<svg
|
|
365
365
|
viewBox="0 0 423 62"
|
|
366
366
|
version="1.1"
|
|
@@ -442,7 +442,7 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
442
442
|
/>
|
|
443
443
|
</g>
|
|
444
444
|
</svg>
|
|
445
|
-
`;var ut=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(ut||{}),ft=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,mt=(t,e,i,o)=>{for(var r,s=o>1?void 0:o?vt(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(s=(o?r(e,i,s):r(s))||s);return o&&s&&ft(e,i,s),s};const gt=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},_t=t=>console.warn(`[ShipAid] ${t}`),Ct=t=>console.error(`[ShipAid] ${t}`),yt="shipaid-protection";var wt;t.ShipAidWidget=class extends ot{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this.disableRefresh=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>gt(t),post:(t,e)=>gt(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}get shouldRefreshOnUpdate(){
|
|
445
|
+
`;var ut=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(ut||{}),ft=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,mt=(t,e,i,o)=>{for(var r,s=o>1?void 0:o?vt(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(s=(o?r(e,i,s):r(s))||s);return o&&s&&ft(e,i,s),s};const gt=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},_t=t=>console.warn(`[ShipAid] ${t}`),Ct=t=>console.error(`[ShipAid] ${t}`),yt="shipaid-protection";var wt;t.ShipAidWidget=class extends ot{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this.disableRefresh=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>gt(t),post:(t,e)=>gt(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}get shouldRefreshOnUpdate(){return!this.disablePolling&&!this.disableRefresh}get planActive(){var t,e;const{searchParams:i}=new URL(window.location.href);return(null==(t=window.Shopify)?void 0:t.designMode)||i.has("shipaid-test")?(_t("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,o,r,s;return new Intl.NumberFormat(null!=(i=null==(e=window.Shopify)?void 0:e.locale)?i:void 0,{currency:(null==(o=this._store)?void 0:o.currency)||(null==(s=null==(r=window.Shopify)?void 0:r.currency)?void 0:s.active)||"USD",style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(ut.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){var e,i,o,r,s;if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const n=null==(e=this._store)?void 0:e.protectionSettings;if(!n||!this._protectionProduct)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const a=((null==(i=this._store)?void 0:i.excludedProductSkus)&&t.items?t.items.reduce(((t,e)=>{if(!e.sku)return t;return this._store.excludedProductSkus.find((t=>t===e.sku))?t-e.final_price:t}),t.total_price):t.total_price)-(null!=(r=null==(o=t.items)?void 0:o.filter((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})))?r:[]).reduce(((t,e)=>t+=e.final_line_price),0);if("FIXED"===n.protectionType){if(!n.defaultFee)throw new Error("Missing default fee amount.");if(!(null==(s=n.rules)?void 0:s.length))return n.defaultFee;const t=a/100,e=n.rules.sort(((t,e)=>t.rangeLower&&e.rangeLower?t.rangeLower-e.rangeLower:0)).find((e=>{const i=Boolean(e.rangeLower&&e.rangeLower<t);return e.rangeUpper?i&&e.rangeUpper>=t:i}));return"number"==typeof(null==e?void 0:e.fee)?e.fee:n.defaultFee}if("PERCENTAGE"===n.protectionType){const t=a*n.percentage/100;return t>=n.minimumFee?t:n.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(t){var e,i,o,r;if(!(null==(e=this._store)?void 0:e.protectionSettings)||!(null==(o=null==(i=this._protectionProduct)?void 0:i.variants)?void 0:o.length))throw new Error("Missing product and variants from protection settings.");const s=null==(r=this._protectionProduct)?void 0:r.variants.flatMap((t=>{if(!t||!t.price)return[];const e=Number(t.price);return[{...t,formattedPrice:e}]})).sort(((t,e)=>t.formattedPrice-e.formattedPrice)),n=s.find((e=>e.formattedPrice>=t));return n||s[s.length-1]}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){var t,e,i;const o=null==(t=window.Shopify)?void 0:t.shop;if(!o)throw new Error("No shop found in Shopify object.");try{const t=new URL(window.location.href);t.pathname=this._apiEndpoint;const r={query:"query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetShowCart\n excludedProductSkus\n protectionSettings\n }\n}",variables:{store:o}},s=await this._fetch.post(t.toString(),r);if(!s)throw new Error("Missing response for store query.");if(null==(e=s.errors)?void 0:e.length)throw new Error(s.errors[0].message);if(!(null==(i=s.data)?void 0:i.store))throw new Error("Missing store from store query response.");return s.data.store}catch(r){throw console.error(r),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(t){throw Ct(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){try{const{product:t}=await this._fetch.get("/products/shipaid-protection.json");return t}catch(t){throw Ct(t.message),new Error("Could not fetch protection product for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addProtection(){var t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!(null==(t=this._cart)?void 0:t.items))throw new Error("Cart has not been loaded.");if(!(null==(e=this._protectionVariant)?void 0:e.id))throw new Error("No protection variant found.");this._setState("loading");const i={quantity:1,id:this._protectionVariant.id},o=await this._fetch.post("/cart/add.js",i);await this._handleRefresh(o),this._lastAction="added",this._setState("success")}catch(i){Ct(i.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const t={quantity:0,id:this._protectionCartItem.key},e=await this._fetch.post("/cart/change.js",t);await this._handleRefresh(e),this._lastAction="removed",this._cart=e,this._setState("success")}catch(t){Ct(t.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}render(){var t;at(this,(async()=>{var t,e;const i=document.createElement("link");i.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),i.setAttribute("rel","stylesheet"),document.head.appendChild(i);try{const t=sessionStorage.getItem(yt),{lastAction:e}=t?JSON.parse(t):{};e&&(this._lastAction=e)}catch(o){_t("Failed to parse local storage.")}try{const[t,e,i]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=t,this._cart=e,this._protectionProduct=i}catch(o){return this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return this.planActive?(null==(e=null==(t=this._store)?void 0:t.protectionSettings)?void 0:e.protectionType)?this._protectionProduct?(this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(ut.LOADED,this._store),setTimeout((async()=>{var t,e;const i=sessionStorage.getItem(yt),{lastAction:o}=i?JSON.parse(i):{};"removed"!==o&&!this._hasProtectionInCart&&(null==(t=this._cart)?void 0:t.item_count)&&(null==(e=this._store)?void 0:e.widgetAutoOptIn)&&this._store.widgetShowCart&&await this.addProtection()}),500),void(this.disablePolling||setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval))):(_t("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(_t("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(_t("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))}),[]),at(this,(()=>{const t={hasProtection:this._hasProtectionInCart,lastAction:this._lastAction};sessionStorage.setItem(yt,JSON.stringify(t))}),[this._lastAction]),at(this,(async()=>{var t,e,i;if(this._cartLastUpdated=new Date,!(null==(t=this._cart)?void 0:t.items))return;const o=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),r=null==(i=this._cart)?void 0:i.items[o];if(this._hasProtectionInCart=!!r,1===this._cart.item_count&&r){const t={id:r.key,quantity:0},e=await this._fetch.post("/cart/change.js",t);return await this._handleRefresh(e)}const s=await this.calculateProtectionTotal(this._cart),n=this._findProtectionVariant(s);if(this._protectionVariant=n,!(null==n?void 0:n.id))return this._shouldShowWidget=!1,void Ct("No matching protection variant found.");if(!r)return;if(n.id===r.id){if(this._protectionCartItem={...r,index:o,position:o+1},1===r.quantity)return;const t={id:r.key,quantity:1},e=await this._fetch.post("/cart/change.js",t);return await this._handleRefresh(e)}const a={id:r.key,quantity:0};await this._fetch.post("/cart/change.js",a);const p={quantity:1,id:n.id},l=await this._fetch.post("/cart/add.js",p);await this._handleRefresh(l)}),[this._store,this._cart]);const e=I`
|
|
446
446
|
<div class=${`shipaid-popup ${"learn-more"===this._popup&&"active"}`}>
|
|
447
447
|
<div class="popup">
|
|
448
448
|
<button
|
|
@@ -500,18 +500,18 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
500
500
|
</div>
|
|
501
501
|
</div>
|
|
502
502
|
</div>
|
|
503
|
-
`,i=
|
|
503
|
+
`,i=I`
|
|
504
504
|
<div class="shipaid-prompt">
|
|
505
505
|
<div class="prompt-product">
|
|
506
506
|
<div class="prompt-product-image">
|
|
507
|
-
${
|
|
507
|
+
${pt(this._hasProtectionInCart,(()=>dt),(()=>ht))}
|
|
508
508
|
</div>
|
|
509
509
|
<div class="prompt-product-details">
|
|
510
510
|
<p class="prompt-product-details-title">
|
|
511
|
-
Package Protection
|
|
511
|
+
<slot name="title">Package Protection</slot>
|
|
512
512
|
</p>
|
|
513
513
|
<p class="prompt-product-details-description">
|
|
514
|
-
from Loss, Damage or Theft
|
|
514
|
+
<slot name="subtitle">from Loss, Damage or Theft</slot>
|
|
515
515
|
</p>
|
|
516
516
|
</div>
|
|
517
517
|
<div class="prompt-product-actions">
|
|
@@ -527,7 +527,7 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
527
527
|
</button>
|
|
528
528
|
</div>
|
|
529
529
|
</div>
|
|
530
|
-
${
|
|
530
|
+
${pt(this._state.error,(()=>I`<p class="error">${this._state.error}</p>`))}
|
|
531
531
|
<div class="prompt-footer">
|
|
532
532
|
<a
|
|
533
533
|
class="prompt-footer-badge"
|
|
@@ -544,8 +544,8 @@ function lt(t,e,i){return t?e():null==i?void 0:i()}const pt=((t,...e)=>{const i=
|
|
|
544
544
|
</button>
|
|
545
545
|
</div>
|
|
546
546
|
</div>
|
|
547
|
-
`;return
|
|
547
|
+
`;return I`
|
|
548
548
|
<div class="shipaid">
|
|
549
|
-
${
|
|
549
|
+
${pt(this._hasFinishedSetup,(()=>{var t;return pt(this._shouldShowWidget&&this.planActive&&(null==(t=this._store)?void 0:t.widgetShowCart),(()=>[e,i]),(()=>I``))}),(()=>I`<p><slot name="loading" default>Loading ShipAid Widget...</slot></p>`))}
|
|
550
550
|
</div>
|
|
551
|
-
`}},t.ShipAidWidget.styles=
|
|
551
|
+
`}},t.ShipAidWidget.styles=lt,mt([i({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disablePolling",2),mt([i({type:Number,attribute:!0})],t.ShipAidWidget.prototype,"pollingInterval",2),mt([i({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disableRefresh",2),mt([o()],t.ShipAidWidget.prototype,"_storeDomain",2),mt([o()],t.ShipAidWidget.prototype,"_store",2),mt([o()],t.ShipAidWidget.prototype,"_cart",2),mt([o()],t.ShipAidWidget.prototype,"_protectionProduct",2),mt([o()],t.ShipAidWidget.prototype,"_cartLastUpdated",2),mt([o()],t.ShipAidWidget.prototype,"_hasFinishedSetup",2),mt([o()],t.ShipAidWidget.prototype,"_shouldShowWidget",2),mt([o()],t.ShipAidWidget.prototype,"_hasProtectionInCart",2),mt([o()],t.ShipAidWidget.prototype,"_lastAction",2),mt([o()],t.ShipAidWidget.prototype,"_protectionCartItem",2),mt([o()],t.ShipAidWidget.prototype,"_protectionVariant",2),mt([o()],t.ShipAidWidget.prototype,"_state",2),mt([o()],t.ShipAidWidget.prototype,"_popup",2),t.ShipAidWidget=mt([(wt="shipaid-widget",t=>{return"function"==typeof t?(e=wt,i=t,customElements.define(e,i),i):((t,e)=>{const{kind:i,elements:o}=e;return{kind:i,elements:o,finisher(e){customElements.define(t,e)}}})(wt,t);var e,i})],t.ShipAidWidget),Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
@@ -20,6 +20,8 @@ export declare class ShipAidWidget extends LitElement {
|
|
|
20
20
|
private _store;
|
|
21
21
|
/** The current cart data object from the Shopify API */
|
|
22
22
|
private _cart;
|
|
23
|
+
/** The current protection product data object from the Shopify API */
|
|
24
|
+
private _protectionProduct;
|
|
23
25
|
/** When the cart was last updated */
|
|
24
26
|
private _cartLastUpdated;
|
|
25
27
|
/** Whether we have finished the initial setup */
|
|
@@ -68,6 +70,8 @@ export declare class ShipAidWidget extends LitElement {
|
|
|
68
70
|
private _fetchShipAidData;
|
|
69
71
|
/** Fetch current cart from the Shopify ajax API */
|
|
70
72
|
private _fetchCart;
|
|
73
|
+
/** Fetch current product from the Shopify ajax API */
|
|
74
|
+
private _fetchProduct;
|
|
71
75
|
/** Whether the cart currently contains Shipping protection from ShipAid. */
|
|
72
76
|
hasProtection(): boolean;
|
|
73
77
|
/** Update the internal cart, which will trigger any protection fee updates */
|
|
@@ -24,12 +24,12 @@ export interface ProtectionSettingsProduct {
|
|
|
24
24
|
export interface ProtectionSettings {
|
|
25
25
|
product?: ProtectionSettingsProduct;
|
|
26
26
|
}
|
|
27
|
-
export interface ProtectionSettingsPercentage
|
|
27
|
+
export interface ProtectionSettingsPercentage {
|
|
28
28
|
protectionType: 'PERCENTAGE';
|
|
29
29
|
percentage: number;
|
|
30
30
|
minimumFee: number;
|
|
31
31
|
}
|
|
32
|
-
export interface ProtectionSettingsFixed
|
|
32
|
+
export interface ProtectionSettingsFixed {
|
|
33
33
|
protectionType: 'FIXED';
|
|
34
34
|
defaultFee?: number;
|
|
35
35
|
rules?: {
|
|
@@ -80,5 +80,67 @@ export interface OptionsWithValuesEntity {
|
|
|
80
80
|
export interface ShopifyCartAddPayload {
|
|
81
81
|
id: number | string;
|
|
82
82
|
quantity?: number;
|
|
83
|
-
|
|
83
|
+
}
|
|
84
|
+
export interface ShopifyProductResponse {
|
|
85
|
+
product: ShopifyProduct;
|
|
86
|
+
}
|
|
87
|
+
export interface ShopifyProduct {
|
|
88
|
+
id: number;
|
|
89
|
+
title: string;
|
|
90
|
+
body_html: string;
|
|
91
|
+
vendor: string;
|
|
92
|
+
product_type: string;
|
|
93
|
+
created_at: string;
|
|
94
|
+
handle: string;
|
|
95
|
+
updated_at: string;
|
|
96
|
+
published_at: string;
|
|
97
|
+
template_suffix: string;
|
|
98
|
+
published_scope: string;
|
|
99
|
+
tags: string;
|
|
100
|
+
variants?: ShopifyProductVariant[];
|
|
101
|
+
options?: (OptionsEntity)[] | null;
|
|
102
|
+
images?: (ImagesEntityOrImage)[] | null;
|
|
103
|
+
image: ImagesEntityOrImage;
|
|
104
|
+
}
|
|
105
|
+
export interface ShopifyProductVariant {
|
|
106
|
+
id: number;
|
|
107
|
+
product_id: number;
|
|
108
|
+
title: string;
|
|
109
|
+
price: string;
|
|
110
|
+
sku: string;
|
|
111
|
+
position: number;
|
|
112
|
+
compare_at_price: string;
|
|
113
|
+
fulfillment_service: string;
|
|
114
|
+
inventory_management?: null;
|
|
115
|
+
option1: string;
|
|
116
|
+
option2?: null;
|
|
117
|
+
option3?: null;
|
|
118
|
+
created_at: string;
|
|
119
|
+
updated_at: string;
|
|
120
|
+
taxable: boolean;
|
|
121
|
+
barcode?: null;
|
|
122
|
+
grams: number;
|
|
123
|
+
image_id?: null;
|
|
124
|
+
weight: number;
|
|
125
|
+
weight_unit: string;
|
|
126
|
+
requires_shipping: boolean;
|
|
127
|
+
}
|
|
128
|
+
export interface OptionsEntity {
|
|
129
|
+
id: number;
|
|
130
|
+
product_id: number;
|
|
131
|
+
name: string;
|
|
132
|
+
position: number;
|
|
133
|
+
values?: (string)[] | null;
|
|
134
|
+
}
|
|
135
|
+
export interface ImagesEntityOrImage {
|
|
136
|
+
id: number;
|
|
137
|
+
product_id: number;
|
|
138
|
+
position: number;
|
|
139
|
+
created_at: string;
|
|
140
|
+
updated_at: string;
|
|
141
|
+
alt?: null;
|
|
142
|
+
width: number;
|
|
143
|
+
height: number;
|
|
144
|
+
src: string;
|
|
145
|
+
variant_ids?: (null)[] | null;
|
|
84
146
|
}
|