ui.shipaid.com 0.3.146 → 0.3.148

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.
@@ -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,14 @@ 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
+ * Ensures the learn-more carousel is mounted in the DOM.
38
+ * This allows external elements to trigger the modal via events without requiring prior user interaction.
39
+ * @param store - ShipAid store configuration
40
+ */
41
+ export declare const ensureLearnMoreCarousel: (store?: ShipAidStore | null) => void;
42
+ /**
43
+ * Refresh Shopify cart UI sections (drawer, icons, cart page) after cart changes.
44
+ * This ensures the UI stays in sync after ShipAid modifies the cart.
45
+ */
46
+ export declare const refreshShopifyCartUI: () => Promise<void>;
@@ -66,10 +66,14 @@ 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;
72
- private _pendingLearnMoreSource;
73
77
  private _openLearnMore;
74
78
  private _toggleBenefits;
75
79
  private _handleHelpClick;
@@ -132,7 +136,9 @@ export declare class ShipAidWidget extends LitElement {
132
136
  /** Whether the cart currently contains Shipping protection from ShipAid. */
133
137
  hasProtection(): boolean;
134
138
  /** Update the internal cart, which will trigger any protection fee updates */
135
- updateCart(cart?: ShopifyCart): Promise<void>;
139
+ updateCart(cart?: ShopifyCart, options?: {
140
+ dispatchExternalEvents?: boolean;
141
+ }): Promise<void>;
136
142
  addCartProtectionVariant(): Promise<any>;
137
143
  updateCartProtectionVariant(qty: number, protectionCartItem?: ShopifyCartItem | null): Promise<any>;
138
144
  /** Add ShipAid shipping protection. */
@@ -142,8 +148,12 @@ export declare class ShipAidWidget extends LitElement {
142
148
  /** Try adding ShipAid shipping protection during polling if applicable */
143
149
  attemptAddProtection(): Promise<void>;
144
150
  handleMultipleProtectionVariants(): Promise<void>;
151
+ /** Disable checkout buttons while updating protection */
152
+ private _disableCheckoutButtons;
153
+ /** Re-enable checkout buttons after updating protection */
154
+ private _enableCheckoutButtons;
145
155
  /** Templates */
146
- learnMorePopupTemplate(): import("lit").TemplateResult<1> | undefined;
156
+ learnMorePopupTemplate(): null;
147
157
  confirmationPopupTemplate(): import("lit").TemplateResult<1>;
148
158
  getElementsBySelector: (selector: string | null) => never[] | NodeListOf<Element>;
149
159
  addStylesIfNeeded: () => void;
@@ -153,10 +163,10 @@ export declare class ShipAidWidget extends LitElement {
153
163
  renderImpactTitle: (isGreenProtectionEnabled: boolean, isFreeGiftEnabled: boolean) => import("lit").TemplateResult<1>;
154
164
  private _renderBenefitsSection;
155
165
  checkoutButtonTemplate(): import("lit").TemplateResult<1> | undefined;
156
- renderPopups(): import("lit").TemplateResult<1> | null | undefined;
166
+ renderPopups(): import("lit").TemplateResult<1> | null;
157
167
  promptTemplate(): import("lit").TemplateResult<1> | undefined;
158
168
  connectedCallback(): Promise<void>;
159
169
  disconnectedCallback(): void;
160
- updateProtection(): Promise<void>;
170
+ updateProtection(force?: boolean): Promise<void>;
161
171
  protected render(): import("lit").TemplateResult<1>;
162
172
  }
@@ -8,6 +8,7 @@ export declare enum SHIPAID_EVENTS {
8
8
  }
9
9
  export declare enum EXTERNAL_EVENTS {
10
10
  CART_UPDATE = "cart:update",
11
+ CART_UPDATED = "cart:updated",
11
12
  VARIANT_CHANGE = "variant:change"
12
13
  }
13
14
  export interface State {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ui.shipaid.com",
3
3
  "private": false,
4
- "version": "0.3.146",
4
+ "version": "0.3.148",
5
5
  "type": "module",
6
6
  "main": "dist/widget.umd.js",
7
7
  "unpkg": "dist/widget.iife.js",