ui.shipaid.com 0.3.145 → 0.3.147
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/dist/widget.es.js +359 -144
- package/dist/widget.iife.js +112 -112
- package/dist/widget.umd.js +107 -107
- package/dist-types/common/shopify/protection.d.ts +1 -1
- package/dist-types/widget/src/shipaid-widget.old.d.ts +158 -0
- package/dist-types/widget/src/widgets/shared.d.ts +5 -0
- package/dist-types/widget/src/widgets/shipaid-widget-element.d.ts +13 -2
- package/dist-types/widget/types/widget.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ShipAidStore } from '../types/ShipAid';
|
|
2
2
|
import { type ShopifyCart } from './types/ShopifyCart';
|
|
3
3
|
import { type ShopifyProduct, type ShopifyProductVariant } from './types/ShopifyProduct';
|
|
4
|
+
export declare function getIdFromShopifyGid(gid: string): string | null;
|
|
4
5
|
export declare const getExcludedProducts: (store: ShipAidStore) => {
|
|
5
6
|
excludedProductSkus: string[];
|
|
6
7
|
excludedProductTags: string[];
|
|
@@ -9,4 +10,3 @@ export declare const getExcludedProducts: (store: ShipAidStore) => {
|
|
|
9
10
|
/** Given the current cart, it calculates the protection total according to the store protection settings. */
|
|
10
11
|
export declare function calculateProtectionTotal(store: ShipAidStore, protectionProduct: ShopifyProduct, cart: ShopifyCart): number;
|
|
11
12
|
export declare function findProtectionVariant(store: ShipAidStore, protectionProduct: ShopifyProduct, protectionFee: number): ShopifyProductVariant | undefined;
|
|
12
|
-
export declare function getIdFromShopifyGid(gid: string): string | null;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { LitElement, nothing, PropertyValues } from 'lit';
|
|
3
|
+
import './components/confirmation-popup';
|
|
4
|
+
import './components/shipaid-cart-confirmation';
|
|
5
|
+
import './components/checkout-package-protection';
|
|
6
|
+
import './components/shipaid-learn-more-carousel';
|
|
7
|
+
import type { ShopifyCart, ShopifyCartItem } from '../types/shopify';
|
|
8
|
+
/**
|
|
9
|
+
* ShipAid Widget.
|
|
10
|
+
*
|
|
11
|
+
* @description When the <shipaid-widget> element is added to page, it will render this element,
|
|
12
|
+
* allowing a customer to add ShipAid protection to cart (and remove).
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export declare class ShipAidWidget extends LitElement {
|
|
16
|
+
static styles: import("lit").CSSResult;
|
|
17
|
+
env: string;
|
|
18
|
+
useCustomStoreFront: boolean;
|
|
19
|
+
storeDomain: string;
|
|
20
|
+
storeAccessToken: string;
|
|
21
|
+
cartId: string;
|
|
22
|
+
disablePolling: boolean;
|
|
23
|
+
disableActions: boolean;
|
|
24
|
+
pollingInterval: number;
|
|
25
|
+
disableRefresh: boolean;
|
|
26
|
+
refreshCart: boolean;
|
|
27
|
+
persistPopup: boolean;
|
|
28
|
+
defaultToggleButton: boolean;
|
|
29
|
+
lang: string;
|
|
30
|
+
currency: undefined;
|
|
31
|
+
customerId: undefined;
|
|
32
|
+
supportSubscriptions: boolean;
|
|
33
|
+
dataSelector: string;
|
|
34
|
+
buttonId: string;
|
|
35
|
+
buttonTitle: string;
|
|
36
|
+
widgetTitle: string;
|
|
37
|
+
buttonClasses: string;
|
|
38
|
+
shadowRootSelector: string;
|
|
39
|
+
useShipAidCheckout: boolean;
|
|
40
|
+
previewGreenShipAid: boolean;
|
|
41
|
+
/** API Proxy pathname */
|
|
42
|
+
private _apiEndpoint;
|
|
43
|
+
/** The current store domain */
|
|
44
|
+
private _storeDomain;
|
|
45
|
+
/** The current store data object from the ShipAid API */
|
|
46
|
+
private _store;
|
|
47
|
+
/** The current cart data object from the Shopify API */
|
|
48
|
+
private _cart;
|
|
49
|
+
/** The current protection product data object from the Shopify API */
|
|
50
|
+
private _protectionProduct;
|
|
51
|
+
/** When the cart was last updated */
|
|
52
|
+
private _cartLastUpdated;
|
|
53
|
+
/** Whether we have finished the initial setup */
|
|
54
|
+
private _hasFinishedSetup;
|
|
55
|
+
/** Can be used to hide all widget content */
|
|
56
|
+
private _shouldShowWidget;
|
|
57
|
+
/** Can be used to check if page is on Cart */
|
|
58
|
+
/** Whether the ShipAid protection product is currently added to the cart */
|
|
59
|
+
private _hasProtectionInCart;
|
|
60
|
+
/** The protection item from the Shopify cart */
|
|
61
|
+
private _protectionCartItem;
|
|
62
|
+
/** The protection variant that will be used */
|
|
63
|
+
private _protectionVariant;
|
|
64
|
+
hasLoadedStrings: boolean;
|
|
65
|
+
fetchInterceptorCleanup: () => void;
|
|
66
|
+
intervalId: NodeJS.Timeout | null;
|
|
67
|
+
private _sellingPlanId?;
|
|
68
|
+
protected shouldUpdate(props: PropertyValues): boolean;
|
|
69
|
+
protected shouldPersistPopup(): "learn-more" | null;
|
|
70
|
+
protected setPopupKey(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Internal state
|
|
73
|
+
*/
|
|
74
|
+
private _state;
|
|
75
|
+
/**
|
|
76
|
+
* Internal popup state
|
|
77
|
+
*/
|
|
78
|
+
private _popup;
|
|
79
|
+
get nhost(): {
|
|
80
|
+
request: (query: string, variables: Record<string, string>) => Promise<any>;
|
|
81
|
+
};
|
|
82
|
+
/** Runs a GraphQL query and returns the data
|
|
83
|
+
* @param query GraphQL query string
|
|
84
|
+
* @param variables Variables for the query
|
|
85
|
+
* @returns Query response data
|
|
86
|
+
*/
|
|
87
|
+
runStoreFrontQuery<Data>(query: string, variables: any): Promise<Data>;
|
|
88
|
+
/** Getter to check if we should refresh the page or not */
|
|
89
|
+
get shouldRefreshOnUpdate(): boolean;
|
|
90
|
+
/** Getter to check whether to show the widget or not */
|
|
91
|
+
get planActive(): boolean;
|
|
92
|
+
private _currencyFormat;
|
|
93
|
+
/** Emit events */
|
|
94
|
+
private _dispatchEvent;
|
|
95
|
+
private _handleRefreshCart;
|
|
96
|
+
/** Handle cart or page refreshes */
|
|
97
|
+
private _handleRefresh;
|
|
98
|
+
/** Given the current order, it calculates the protection total according to the store protection settings. */
|
|
99
|
+
calculateProtectionTotal(cart?: ShopifyCart): Promise<number>;
|
|
100
|
+
/**
|
|
101
|
+
* Given the current order, it finds the relevant protection product variant, and adds it to cart.
|
|
102
|
+
* This should be run whenever the cart updates, or it is manually triggered.
|
|
103
|
+
*/
|
|
104
|
+
private _findProtectionVariant;
|
|
105
|
+
/** Update State */
|
|
106
|
+
private _setState;
|
|
107
|
+
/** Trigger confirmation popup */
|
|
108
|
+
private _handleConfirmationPopup;
|
|
109
|
+
/** Updates the current protection status, calling the relevant add/remove function. */
|
|
110
|
+
private _updateProtection;
|
|
111
|
+
/** General fetch function, which handles error responses, and returns JSON responses. */
|
|
112
|
+
private _fetch;
|
|
113
|
+
/** Fetches store info from the ShipAid public API. */
|
|
114
|
+
private _fetchShipAidData;
|
|
115
|
+
private _findSellingPlanByName;
|
|
116
|
+
/** Fetches store info from the ShipAid public API. */
|
|
117
|
+
private _fetchSellingPlanFromVariant;
|
|
118
|
+
private _getProductFieldFromCookie;
|
|
119
|
+
private _storeProductFieldInCookie;
|
|
120
|
+
private _fetchProductJSON;
|
|
121
|
+
/** Fetch current cart from the Shopify ajax API */
|
|
122
|
+
private _fetchCart;
|
|
123
|
+
/** Fetch current product from the Shopify ajax API */
|
|
124
|
+
private _fetchProduct;
|
|
125
|
+
/** Whether the cart currently contains Shipping protection from ShipAid. */
|
|
126
|
+
hasProtection(): boolean;
|
|
127
|
+
/** Update the internal cart, which will trigger any protection fee updates */
|
|
128
|
+
updateCart(cart?: ShopifyCart): Promise<void>;
|
|
129
|
+
addCartProtectionVariant(): Promise<any>;
|
|
130
|
+
updateCartProtectionVariant(qty: number, protectionCartItem?: ShopifyCartItem | null): Promise<any>;
|
|
131
|
+
/** Add ShipAid shipping protection. */
|
|
132
|
+
addProtection(): Promise<void>;
|
|
133
|
+
/** Remove ShipAid shipping protection. */
|
|
134
|
+
removeProtection(): Promise<void>;
|
|
135
|
+
/** Try adding ShipAid shipping protection during polling if applicable */
|
|
136
|
+
attemptAddProtection(): Promise<void>;
|
|
137
|
+
handleMultipleProtectionVariants(): Promise<void>;
|
|
138
|
+
/** Templates */
|
|
139
|
+
learnMorePopupTemplate(): import("lit").TemplateResult<1> | undefined;
|
|
140
|
+
confirmationPopupTemplate(): import("lit").TemplateResult<1>;
|
|
141
|
+
getElementsBySelector: (selector: string | null) => never[] | NodeListOf<Element>;
|
|
142
|
+
addStylesIfNeeded: () => void;
|
|
143
|
+
contactlessCheckoutButtonTemplate(): typeof nothing | undefined;
|
|
144
|
+
createRenderRoot(): Element | ShadowRoot;
|
|
145
|
+
getSubscription(_cart: ShopifyCart | undefined): Promise<string | null | undefined>;
|
|
146
|
+
checkoutButtonTemplate(): import("lit").TemplateResult<1> | undefined;
|
|
147
|
+
renderPopups(): import("lit").TemplateResult<1> | null | undefined;
|
|
148
|
+
promptTemplate(): import("lit").TemplateResult<1> | undefined;
|
|
149
|
+
connectedCallback(): Promise<void>;
|
|
150
|
+
disconnectedCallback(): void;
|
|
151
|
+
updateProtection(): Promise<void>;
|
|
152
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
153
|
+
}
|
|
154
|
+
declare global {
|
|
155
|
+
interface HTMLElementTagNameMap {
|
|
156
|
+
'shipaid-widget': ShipAidWidget;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -33,3 +33,8 @@ export declare const removeProtectionWithCheckoutPlus: () => Promise<void>;
|
|
|
33
33
|
export declare const hasProtectionWithCheckoutPlus: () => Promise<boolean>;
|
|
34
34
|
export declare const resetShipAidSharedCache: () => void;
|
|
35
35
|
export declare const openCarousel: (from: string) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Refresh Shopify cart UI sections (drawer, icons, cart page) after cart changes.
|
|
38
|
+
* This ensures the UI stays in sync after ShipAid modifies the cart.
|
|
39
|
+
*/
|
|
40
|
+
export declare const refreshShopifyCartUI: () => Promise<void>;
|
|
@@ -66,6 +66,11 @@ export declare class ShipAidWidget extends LitElement {
|
|
|
66
66
|
fetchInterceptorCleanup: () => void;
|
|
67
67
|
intervalId: NodeJS.Timeout | null;
|
|
68
68
|
private _sellingPlanId?;
|
|
69
|
+
private _isUpdatingShipAid;
|
|
70
|
+
private _lastCartEventAt;
|
|
71
|
+
private _isReplacingCartSections;
|
|
72
|
+
private _onShipAidCartEvent;
|
|
73
|
+
private _onShipAidInternalCartUpdated;
|
|
69
74
|
protected shouldUpdate(props: PropertyValues): boolean;
|
|
70
75
|
protected shouldPersistPopup(): "learn-more" | null;
|
|
71
76
|
protected setPopupKey(): void;
|
|
@@ -132,7 +137,9 @@ export declare class ShipAidWidget extends LitElement {
|
|
|
132
137
|
/** Whether the cart currently contains Shipping protection from ShipAid. */
|
|
133
138
|
hasProtection(): boolean;
|
|
134
139
|
/** Update the internal cart, which will trigger any protection fee updates */
|
|
135
|
-
updateCart(cart?: ShopifyCart
|
|
140
|
+
updateCart(cart?: ShopifyCart, options?: {
|
|
141
|
+
dispatchExternalEvents?: boolean;
|
|
142
|
+
}): Promise<void>;
|
|
136
143
|
addCartProtectionVariant(): Promise<any>;
|
|
137
144
|
updateCartProtectionVariant(qty: number, protectionCartItem?: ShopifyCartItem | null): Promise<any>;
|
|
138
145
|
/** Add ShipAid shipping protection. */
|
|
@@ -142,6 +149,10 @@ export declare class ShipAidWidget extends LitElement {
|
|
|
142
149
|
/** Try adding ShipAid shipping protection during polling if applicable */
|
|
143
150
|
attemptAddProtection(): Promise<void>;
|
|
144
151
|
handleMultipleProtectionVariants(): Promise<void>;
|
|
152
|
+
/** Disable checkout buttons while updating protection */
|
|
153
|
+
private _disableCheckoutButtons;
|
|
154
|
+
/** Re-enable checkout buttons after updating protection */
|
|
155
|
+
private _enableCheckoutButtons;
|
|
145
156
|
/** Templates */
|
|
146
157
|
learnMorePopupTemplate(): import("lit").TemplateResult<1> | undefined;
|
|
147
158
|
confirmationPopupTemplate(): import("lit").TemplateResult<1>;
|
|
@@ -157,6 +168,6 @@ export declare class ShipAidWidget extends LitElement {
|
|
|
157
168
|
promptTemplate(): import("lit").TemplateResult<1> | undefined;
|
|
158
169
|
connectedCallback(): Promise<void>;
|
|
159
170
|
disconnectedCallback(): void;
|
|
160
|
-
updateProtection(): Promise<void>;
|
|
171
|
+
updateProtection(force?: boolean): Promise<void>;
|
|
161
172
|
protected render(): import("lit").TemplateResult<1>;
|
|
162
173
|
}
|