ui.shipaid.com 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -80
- package/dist-types/src/shipaid-widget.d.ts +85 -0
- package/dist-types/src/styles.d.ts +2 -0
- package/dist-types/types/shipaid.d.ts +57 -0
- package/dist-types/types/shopify.d.ts +84 -0
- package/dist-types/types/widget.d.ts +13 -0
- package/package.json +41 -41
- package/types/scss.d.ts +5 -5
- package/types/shipaid.ts +54 -53
- package/types/shopify.ts +90 -86
- package/types/vite-env.d.ts +9 -9
- package/types/widget.ts +15 -15
- package/dist/ui.shipaid.com.es.js +0 -325
- package/dist/ui.shipaid.com.iife.js +0 -338
- package/dist/ui.shipaid.com.umd.js +0 -338
package/README.md
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
# ShipAid Shopify Widget
|
|
2
|
-
|
|
3
|
-
This is the repository for the ShipAid Shopify (and possibly others in future) widget. It uses the [Lit](https://lit.dev/) web components library, so it is recommended to become familiar with it before contributing to this repository.
|
|
4
|
-
|
|
5
|
-
Using Lit provides a framework that allows us to build a reactive UI, using JSX-like syntax - no need to use JQuery etc. And it can easily be installed in a page by using the custom web component name:
|
|
6
|
-
```html
|
|
7
|
-
<shipaid-widget>Fallback Content</shipaid-widget>
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
## Overview
|
|
11
|
-
|
|
12
|
-
This widget provides an interface where a user can choose to add or remove ShipAid protection - this is actually a product in their store that can be added to cart. When the component is loaded, we immediately run a request to fetch the ShipAid protection product details from our API, as well as the customers current cart from the [Shopify AJAX API](https://shopify.dev/api/ajax/reference/cart).
|
|
13
|
-
Once we have this data, we can check whether the customer currently has the ShipAid product in their cart, and show either the add or remove product buttons based on this.
|
|
14
|
-
|
|
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
|
-
|
|
17
|
-
### Events
|
|
18
|
-
|
|
19
|
-
This is a list of the events emitted by the widget:
|
|
20
|
-
|
|
21
|
-
| Event | Description | Payload |
|
|
22
|
-
|-------|-------------|---------|
|
|
23
|
-
| `shipaid-loaded` | Dispatched when the widget has finished fetching data from the API, and has successfully rendered. | Contains the data from the ShipAid API: [`ShipAidStore`](/types/shipaid.ts) |
|
|
24
|
-
| `shipaid-protection-status` | Dispatched when a user either adds or removes the protection product from their cart. | `{ protection: boolean, cart: ShopifyCart, lineItem: ShopifyCartItem }` |
|
|
25
|
-
|
|
26
|
-
### Methods
|
|
27
|
-
|
|
28
|
-
This is a list of public methods that can be used to change protection settings:
|
|
29
|
-
|
|
30
|
-
| Method | Description | Payload |
|
|
31
|
-
|--------|-------------|---------|
|
|
32
|
-
| `hasProtection` | Returns a boolean which indicates whether the protection item is currently in the cart. | |
|
|
33
|
-
| `updateCart` | Updates the internal cart, and triggers any protection product updates - use this method with with ajax carts, to update protection state without needing to reload the page. | Optional - the cart object from the ajax API. |
|
|
34
|
-
| `addProtection` | Adds the relevant protection item to cart. | |
|
|
35
|
-
| `removeProtection` | Removes the protection item from the cart. | |
|
|
36
|
-
|
|
37
|
-
## Contributing
|
|
38
|
-
|
|
39
|
-
### Requirements
|
|
40
|
-
|
|
41
|
-
- Node v16+
|
|
42
|
-
- PNPM
|
|
43
|
-
- Development Shopify store (with the ShipAid app installed)
|
|
44
|
-
- ShipAid API development/staging instance
|
|
45
|
-
|
|
46
|
-
### Development
|
|
47
|
-
|
|
48
|
-
You will need to make sure your development store has the ShipAid app installed, so the store and its protection product is added to the DB. You will also need to ensure the Shopify app you are testing this with has an app proxy added, and pointed towards an API instance.
|
|
49
|
-
|
|
50
|
-
```sh
|
|
51
|
-
pnpm install
|
|
52
|
-
pnpm run develop
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Once the project is running, add the below to your development Shopify store `theme.liquid`:
|
|
56
|
-
|
|
57
|
-
```html
|
|
58
|
-
<!-- Dev -->
|
|
59
|
-
<script src="http://localhost:3000/src/shipaid-widget.ts"type="module" ></script>
|
|
60
|
-
<!-- Prod -->
|
|
61
|
-
<script src="https://unpkg.com/ui.shipaid.com?module" type="module"></script>
|
|
62
|
-
```
|
|
63
|
-
And add the widget element in your cart (likely `/sections/main-cart-items.liquid`):
|
|
64
|
-
|
|
65
|
-
```html
|
|
66
|
-
<shipaid-widget>
|
|
67
|
-
<p>Loading ShipAid Protection</p>
|
|
68
|
-
</shipaid-widget>
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Build
|
|
72
|
-
|
|
73
|
-
Once the project has been built, you can publish the project to NPM, and users can add the script to their store using a package CDN (I.e. [Unpkg](https://unpkg.com/)).
|
|
74
|
-
|
|
75
|
-
```sh
|
|
76
|
-
pnpm install
|
|
77
|
-
pnpm run lint
|
|
78
|
-
pnpm run build
|
|
79
|
-
pnpm publish
|
|
80
|
-
```
|
|
1
|
+
# ShipAid Shopify Widget
|
|
2
|
+
|
|
3
|
+
This is the repository for the ShipAid Shopify (and possibly others in future) widget. It uses the [Lit](https://lit.dev/) web components library, so it is recommended to become familiar with it before contributing to this repository.
|
|
4
|
+
|
|
5
|
+
Using Lit provides a framework that allows us to build a reactive UI, using JSX-like syntax - no need to use JQuery etc. And it can easily be installed in a page by using the custom web component name:
|
|
6
|
+
```html
|
|
7
|
+
<shipaid-widget>Fallback Content</shipaid-widget>
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
This widget provides an interface where a user can choose to add or remove ShipAid protection - this is actually a product in their store that can be added to cart. When the component is loaded, we immediately run a request to fetch the ShipAid protection product details from our API, as well as the customers current cart from the [Shopify AJAX API](https://shopify.dev/api/ajax/reference/cart).
|
|
13
|
+
Once we have this data, we can check whether the customer currently has the ShipAid product in their cart, and show either the add or remove product buttons based on this.
|
|
14
|
+
|
|
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
|
+
|
|
17
|
+
### Events
|
|
18
|
+
|
|
19
|
+
This is a list of the events emitted by the widget:
|
|
20
|
+
|
|
21
|
+
| Event | Description | Payload |
|
|
22
|
+
|-------|-------------|---------|
|
|
23
|
+
| `shipaid-loaded` | Dispatched when the widget has finished fetching data from the API, and has successfully rendered. | Contains the data from the ShipAid API: [`ShipAidStore`](/types/shipaid.ts) |
|
|
24
|
+
| `shipaid-protection-status` | Dispatched when a user either adds or removes the protection product from their cart. | `{ protection: boolean, cart: ShopifyCart, lineItem: ShopifyCartItem }` |
|
|
25
|
+
|
|
26
|
+
### Methods
|
|
27
|
+
|
|
28
|
+
This is a list of public methods that can be used to change protection settings:
|
|
29
|
+
|
|
30
|
+
| Method | Description | Payload |
|
|
31
|
+
|--------|-------------|---------|
|
|
32
|
+
| `hasProtection` | Returns a boolean which indicates whether the protection item is currently in the cart. | |
|
|
33
|
+
| `updateCart` | Updates the internal cart, and triggers any protection product updates - use this method with with ajax carts, to update protection state without needing to reload the page. | Optional - the cart object from the ajax API. |
|
|
34
|
+
| `addProtection` | Adds the relevant protection item to cart. | |
|
|
35
|
+
| `removeProtection` | Removes the protection item from the cart. | |
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
### Requirements
|
|
40
|
+
|
|
41
|
+
- Node v16+
|
|
42
|
+
- PNPM
|
|
43
|
+
- Development Shopify store (with the ShipAid app installed)
|
|
44
|
+
- ShipAid API development/staging instance
|
|
45
|
+
|
|
46
|
+
### Development
|
|
47
|
+
|
|
48
|
+
You will need to make sure your development store has the ShipAid app installed, so the store and its protection product is added to the DB. You will also need to ensure the Shopify app you are testing this with has an app proxy added, and pointed towards an API instance.
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
pnpm install
|
|
52
|
+
pnpm run develop
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Once the project is running, add the below to your development Shopify store `theme.liquid`:
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<!-- Dev -->
|
|
59
|
+
<script src="http://localhost:3000/src/shipaid-widget.ts"type="module" ></script>
|
|
60
|
+
<!-- Prod -->
|
|
61
|
+
<script src="https://unpkg.com/ui.shipaid.com?module" type="module"></script>
|
|
62
|
+
```
|
|
63
|
+
And add the widget element in your cart (likely `/sections/main-cart-items.liquid`):
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<shipaid-widget>
|
|
67
|
+
<p>Loading ShipAid Protection</p>
|
|
68
|
+
</shipaid-widget>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Build
|
|
72
|
+
|
|
73
|
+
Once the project has been built, you can publish the project to NPM, and users can add the script to their store using a package CDN (I.e. [Unpkg](https://unpkg.com/)).
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
pnpm install
|
|
77
|
+
pnpm run lint
|
|
78
|
+
pnpm run build
|
|
79
|
+
pnpm publish
|
|
80
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
import type { ShopifyCart } from "../types/shopify";
|
|
3
|
+
/**
|
|
4
|
+
* ShipAid Widget.
|
|
5
|
+
*
|
|
6
|
+
* @description When the <shipaid-widget> element is added to page, it will render this element,
|
|
7
|
+
* allowing a customer to add ShipAid protection to cart (and remove).
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare class ShipAidWidget extends LitElement {
|
|
11
|
+
static styles: import("lit").CSSResult;
|
|
12
|
+
disablePolling: boolean;
|
|
13
|
+
pollingInterval: number;
|
|
14
|
+
disableRefresh: boolean;
|
|
15
|
+
/** API Proxy pathname */
|
|
16
|
+
private _apiEndpoint;
|
|
17
|
+
/** The current store domain */
|
|
18
|
+
private _storeDomain;
|
|
19
|
+
/** The current store data object from the ShipAid API */
|
|
20
|
+
private _store;
|
|
21
|
+
/** The current cart data object from the Shopify API */
|
|
22
|
+
private _cart;
|
|
23
|
+
/** When the cart was last updated */
|
|
24
|
+
private _cartLastUpdated;
|
|
25
|
+
/** Whether we have finished the initial setup */
|
|
26
|
+
private _hasFinishedSetup;
|
|
27
|
+
/** Can be used to hide all widget content */
|
|
28
|
+
private _shouldShowWidget;
|
|
29
|
+
/** Whether the ShipAid protection product is currently added to the cart */
|
|
30
|
+
private _hasProtectionInCart;
|
|
31
|
+
/** The last action a user took */
|
|
32
|
+
private _lastAction;
|
|
33
|
+
/** The protection item from the Shopify cart */
|
|
34
|
+
private _protectionCartItem;
|
|
35
|
+
/** The protection variant that will be used */
|
|
36
|
+
private _protectionVariant;
|
|
37
|
+
/**
|
|
38
|
+
* Internal state
|
|
39
|
+
*/
|
|
40
|
+
private _state;
|
|
41
|
+
/**
|
|
42
|
+
* Internal popup state
|
|
43
|
+
*/
|
|
44
|
+
private _popup;
|
|
45
|
+
/** Getter to check if we should refresh the page or not */
|
|
46
|
+
get shouldRefreshOnUpdate(): boolean;
|
|
47
|
+
/** Getter to check whether to show the widget or not */
|
|
48
|
+
get planActive(): boolean;
|
|
49
|
+
private _currencyFormat;
|
|
50
|
+
/** Emit events */
|
|
51
|
+
private _dispatchEvent;
|
|
52
|
+
/** Handle cart or page refreshes */
|
|
53
|
+
private _handleRefresh;
|
|
54
|
+
/** Given the current order, it calculates the protection total according to the store protection settings. */
|
|
55
|
+
calculateProtectionTotal(cart?: ShopifyCart): Promise<number>;
|
|
56
|
+
/**
|
|
57
|
+
* Given the current order, it finds the relevant protection product variant, and adds it to cart.
|
|
58
|
+
* This should be run whenever the cart updates, or it is manually triggered.
|
|
59
|
+
*/
|
|
60
|
+
private _findProtectionVariant;
|
|
61
|
+
/** Update State */
|
|
62
|
+
private _setState;
|
|
63
|
+
/** Updates the current protection status, calling the relevant add/remove function. */
|
|
64
|
+
private _updateProtection;
|
|
65
|
+
/** General fetch function, which handles error responses, and returns JSON responses. */
|
|
66
|
+
private _fetch;
|
|
67
|
+
/** Fetches store info from the ShipAid public API. */
|
|
68
|
+
private _fetchShipAidData;
|
|
69
|
+
/** Fetch current cart from the Shopify ajax API */
|
|
70
|
+
private _fetchCart;
|
|
71
|
+
/** Whether the cart currently contains Shipping protection from ShipAid. */
|
|
72
|
+
hasProtection(): boolean;
|
|
73
|
+
/** Update the internal cart, which will trigger any protection fee updates */
|
|
74
|
+
updateCart(cart?: ShopifyCart): Promise<void>;
|
|
75
|
+
/** Add ShipAid shipping protection. */
|
|
76
|
+
addProtection(): Promise<void>;
|
|
77
|
+
/** Remove ShipAid shipping protection. */
|
|
78
|
+
removeProtection(): Promise<void>;
|
|
79
|
+
render(): import("lit").TemplateResult<1>;
|
|
80
|
+
}
|
|
81
|
+
declare global {
|
|
82
|
+
interface HTMLElementTagNameMap {
|
|
83
|
+
"shipaid-widget": ShipAidWidget;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface ProtectionSettingsProductVariant {
|
|
2
|
+
id?: string;
|
|
3
|
+
sku?: string;
|
|
4
|
+
price?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
selectedOptions?: {
|
|
7
|
+
name?: string;
|
|
8
|
+
value?: string;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
export interface ProtectionSettingsProduct {
|
|
12
|
+
id?: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
options?: {
|
|
15
|
+
name: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}[];
|
|
18
|
+
variants?: {
|
|
19
|
+
edges?: {
|
|
20
|
+
node?: ProtectionSettingsProductVariant;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface ProtectionSettings {
|
|
25
|
+
product?: ProtectionSettingsProduct;
|
|
26
|
+
}
|
|
27
|
+
export interface ProtectionSettingsPercentage extends ProtectionSettings {
|
|
28
|
+
protectionType: 'PERCENTAGE';
|
|
29
|
+
percentage: number;
|
|
30
|
+
minimumFee: number;
|
|
31
|
+
}
|
|
32
|
+
export interface ProtectionSettingsFixed extends ProtectionSettings {
|
|
33
|
+
protectionType: 'FIXED';
|
|
34
|
+
defaultFee?: number;
|
|
35
|
+
rules?: {
|
|
36
|
+
fee?: number;
|
|
37
|
+
rangeLower?: number;
|
|
38
|
+
rangeUpper?: number;
|
|
39
|
+
}[];
|
|
40
|
+
}
|
|
41
|
+
export interface ShipAidStore {
|
|
42
|
+
store: string;
|
|
43
|
+
currency: string;
|
|
44
|
+
widgetAutoOptIn?: boolean;
|
|
45
|
+
widgetShowCart?: boolean;
|
|
46
|
+
excludedProductSkus?: string[];
|
|
47
|
+
planActive: boolean;
|
|
48
|
+
protectionSettings: ProtectionSettingsFixed | ProtectionSettingsPercentage;
|
|
49
|
+
}
|
|
50
|
+
export interface ShipAidStoreQuery {
|
|
51
|
+
data: null | {
|
|
52
|
+
store: ShipAidStore;
|
|
53
|
+
};
|
|
54
|
+
errors?: {
|
|
55
|
+
message: string;
|
|
56
|
+
}[];
|
|
57
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
Shopify?: {
|
|
4
|
+
shop?: string;
|
|
5
|
+
locale?: string;
|
|
6
|
+
designMode?: boolean;
|
|
7
|
+
currency?: {
|
|
8
|
+
active?: string;
|
|
9
|
+
};
|
|
10
|
+
Checkout?: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export interface ShopifyCart {
|
|
15
|
+
token: string;
|
|
16
|
+
note?: null;
|
|
17
|
+
original_total_price: number;
|
|
18
|
+
total_price: number;
|
|
19
|
+
total_discount: number;
|
|
20
|
+
total_weight: number;
|
|
21
|
+
item_count: number;
|
|
22
|
+
items?: ShopifyCartItem[];
|
|
23
|
+
requires_shipping: boolean;
|
|
24
|
+
currency: string;
|
|
25
|
+
items_subtotal_price: number;
|
|
26
|
+
cart_level_discount_applications?: (null)[] | null;
|
|
27
|
+
sections?: Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
export interface ShopifyCartItem {
|
|
30
|
+
id: number;
|
|
31
|
+
index: number;
|
|
32
|
+
position: number;
|
|
33
|
+
properties?: null;
|
|
34
|
+
quantity: number;
|
|
35
|
+
variant_id: number;
|
|
36
|
+
key: string;
|
|
37
|
+
title: string;
|
|
38
|
+
price: number;
|
|
39
|
+
original_price: number;
|
|
40
|
+
discounted_price: number;
|
|
41
|
+
line_price: number;
|
|
42
|
+
original_line_price: number;
|
|
43
|
+
total_discount: number;
|
|
44
|
+
discounts?: (null)[] | null;
|
|
45
|
+
sku: string;
|
|
46
|
+
grams: number;
|
|
47
|
+
vendor: string;
|
|
48
|
+
taxable: boolean;
|
|
49
|
+
product_id: number;
|
|
50
|
+
product_has_only_default_variant: boolean;
|
|
51
|
+
gift_card: boolean;
|
|
52
|
+
final_price: number;
|
|
53
|
+
final_line_price: number;
|
|
54
|
+
url: string;
|
|
55
|
+
featured_image: FeaturedImage;
|
|
56
|
+
image: string;
|
|
57
|
+
handle: string;
|
|
58
|
+
requires_shipping: boolean;
|
|
59
|
+
product_type: string;
|
|
60
|
+
product_title: string;
|
|
61
|
+
product_description: string;
|
|
62
|
+
variant_title?: null;
|
|
63
|
+
variant_options?: (string)[] | null;
|
|
64
|
+
options_with_values?: (OptionsWithValuesEntity)[] | null;
|
|
65
|
+
line_level_discount_allocations?: (null)[] | null;
|
|
66
|
+
line_level_total_discount: number;
|
|
67
|
+
sections?: Record<string, string>;
|
|
68
|
+
}
|
|
69
|
+
export interface FeaturedImage {
|
|
70
|
+
aspect_ratio: number;
|
|
71
|
+
alt: string;
|
|
72
|
+
height: number;
|
|
73
|
+
url: string;
|
|
74
|
+
width: number;
|
|
75
|
+
}
|
|
76
|
+
export interface OptionsWithValuesEntity {
|
|
77
|
+
name: string;
|
|
78
|
+
value: string;
|
|
79
|
+
}
|
|
80
|
+
export interface ShopifyCartAddPayload {
|
|
81
|
+
id: number | string;
|
|
82
|
+
quantity?: number;
|
|
83
|
+
sections?: string;
|
|
84
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum Events {
|
|
2
|
+
LOADED = "shipaid-loaded",
|
|
3
|
+
STATUS_UPDATE = "shipaid-protection-status"
|
|
4
|
+
}
|
|
5
|
+
export interface State {
|
|
6
|
+
loading: boolean;
|
|
7
|
+
success: boolean | null;
|
|
8
|
+
error: boolean | string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface FetchHelper {
|
|
11
|
+
get: <Data>(url: string) => Promise<Data>;
|
|
12
|
+
post: <Data>(url: string, body: unknown) => Promise<Data>;
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ui.shipaid.com",
|
|
3
|
-
"private": false,
|
|
4
|
-
"version": "0.2.
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"types"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"lit": "^
|
|
24
|
-
"lit
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"@typescript-eslint/
|
|
29
|
-
"eslint": "^
|
|
30
|
-
"eslint
|
|
31
|
-
"eslint-
|
|
32
|
-
"eslint-plugin-
|
|
33
|
-
"eslint-plugin-
|
|
34
|
-
"eslint-plugin-lit
|
|
35
|
-
"eslint-plugin-
|
|
36
|
-
"eslint-plugin-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"vite
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ui.shipaid.com",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.2.5",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/ui.shipaid.com.umd.js",
|
|
7
|
+
"unpkg": "dist/ui.shipaid.com.iife.js",
|
|
8
|
+
"module": "dist/ui.shipaid.com.es.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/ui.shipaid.com.es.js"
|
|
11
|
+
},
|
|
12
|
+
"types": "dist-types/src/shipaid-widget.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist-types",
|
|
15
|
+
"types"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"develop": "vite",
|
|
19
|
+
"build": "tsc && node build",
|
|
20
|
+
"lint": "eslint . --ext=ts --fix"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@lit-labs/task": "^1.1.3",
|
|
24
|
+
"lit": "^2.3.1",
|
|
25
|
+
"lit-element-effect": "^1.0.2"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
29
|
+
"@typescript-eslint/parser": "^5.35.1",
|
|
30
|
+
"eslint": "^7.32.0",
|
|
31
|
+
"eslint-config-standard": "^17.0.0",
|
|
32
|
+
"eslint-plugin-html": "^7.1.0",
|
|
33
|
+
"eslint-plugin-import": "^2.26.0",
|
|
34
|
+
"eslint-plugin-lit": "^1.6.1",
|
|
35
|
+
"eslint-plugin-lit-a11y": "^2.2.2",
|
|
36
|
+
"eslint-plugin-node": "^11.1.0",
|
|
37
|
+
"eslint-plugin-promise": "^5.2.0",
|
|
38
|
+
"typescript": "^4.8.2",
|
|
39
|
+
"vite": "^2.9.15"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/types/scss.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare module '*.scss' {
|
|
2
|
-
import { CSSResultGroup } from 'lit'
|
|
3
|
-
const styles: CSSResultGroup
|
|
4
|
-
export default styles
|
|
5
|
-
}
|
|
1
|
+
declare module '*.scss' {
|
|
2
|
+
import { CSSResultGroup } from 'lit'
|
|
3
|
+
const styles: CSSResultGroup
|
|
4
|
+
export default styles
|
|
5
|
+
}
|
package/types/shipaid.ts
CHANGED
|
@@ -1,53 +1,54 @@
|
|
|
1
|
-
export interface ProtectionSettingsProductVariant {
|
|
2
|
-
id?: string
|
|
3
|
-
sku?: string
|
|
4
|
-
price?: string
|
|
5
|
-
title?: string
|
|
6
|
-
selectedOptions?: { name?: string, value?: string }[]
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface ProtectionSettingsProduct {
|
|
10
|
-
// Making these optional, as it is stored as a jsonb field, so we can't guarantee the format it returns.
|
|
11
|
-
id?: string
|
|
12
|
-
title?: string
|
|
13
|
-
options?: { name: string, value: string }[]
|
|
14
|
-
variants?: {
|
|
15
|
-
edges?: {
|
|
16
|
-
node?: ProtectionSettingsProductVariant
|
|
17
|
-
}[]
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ProtectionSettings {
|
|
22
|
-
product?: ProtectionSettingsProduct
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface ProtectionSettingsPercentage extends ProtectionSettings {
|
|
26
|
-
protectionType: 'PERCENTAGE'
|
|
27
|
-
percentage: number
|
|
28
|
-
minimumFee: number
|
|
29
|
-
}
|
|
30
|
-
export interface ProtectionSettingsFixed extends ProtectionSettings {
|
|
31
|
-
protectionType: 'FIXED'
|
|
32
|
-
defaultFee?: number
|
|
33
|
-
// Making these optional, as it is stored as a jsonb field, so we can't guarantee the format it returns.
|
|
34
|
-
rules?: {
|
|
35
|
-
fee?: number
|
|
36
|
-
rangeLower?: number
|
|
37
|
-
rangeUpper?: number
|
|
38
|
-
}[]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface ShipAidStore {
|
|
42
|
-
store: string;
|
|
43
|
-
currency: string
|
|
44
|
-
widgetAutoOptIn?: boolean
|
|
45
|
-
widgetShowCart?: boolean
|
|
46
|
-
excludedProductSkus?: string[]
|
|
47
|
-
|
|
48
|
-
protectionSettings: ProtectionSettingsFixed | ProtectionSettingsPercentage
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface ShipAidStoreQuery {
|
|
52
|
-
|
|
53
|
-
}
|
|
1
|
+
export interface ProtectionSettingsProductVariant {
|
|
2
|
+
id?: string
|
|
3
|
+
sku?: string
|
|
4
|
+
price?: string
|
|
5
|
+
title?: string
|
|
6
|
+
selectedOptions?: { name?: string, value?: string }[]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ProtectionSettingsProduct {
|
|
10
|
+
// Making these optional, as it is stored as a jsonb field, so we can't guarantee the format it returns.
|
|
11
|
+
id?: string
|
|
12
|
+
title?: string
|
|
13
|
+
options?: { name: string, value: string }[]
|
|
14
|
+
variants?: {
|
|
15
|
+
edges?: {
|
|
16
|
+
node?: ProtectionSettingsProductVariant
|
|
17
|
+
}[]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ProtectionSettings {
|
|
22
|
+
product?: ProtectionSettingsProduct
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ProtectionSettingsPercentage extends ProtectionSettings {
|
|
26
|
+
protectionType: 'PERCENTAGE'
|
|
27
|
+
percentage: number
|
|
28
|
+
minimumFee: number
|
|
29
|
+
}
|
|
30
|
+
export interface ProtectionSettingsFixed extends ProtectionSettings {
|
|
31
|
+
protectionType: 'FIXED'
|
|
32
|
+
defaultFee?: number
|
|
33
|
+
// Making these optional, as it is stored as a jsonb field, so we can't guarantee the format it returns.
|
|
34
|
+
rules?: {
|
|
35
|
+
fee?: number
|
|
36
|
+
rangeLower?: number
|
|
37
|
+
rangeUpper?: number
|
|
38
|
+
}[]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ShipAidStore {
|
|
42
|
+
store: string;
|
|
43
|
+
currency: string
|
|
44
|
+
widgetAutoOptIn?: boolean
|
|
45
|
+
widgetShowCart?: boolean
|
|
46
|
+
excludedProductSkus?: string[]
|
|
47
|
+
planActive: boolean
|
|
48
|
+
protectionSettings: ProtectionSettingsFixed | ProtectionSettingsPercentage
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ShipAidStoreQuery {
|
|
52
|
+
data: null | { store: ShipAidStore }
|
|
53
|
+
errors?: { message: string }[]
|
|
54
|
+
}
|