ui.shipaid.com 0.2.4 → 0.2.7
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/widget.es.js +578 -0
- package/dist/widget.iife.js +577 -0
- package/dist/widget.umd.js +577 -0
- 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/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/types/scss.d.ts +0 -5
- package/types/shipaid.ts +0 -53
- package/types/shopify.ts +0 -86
- package/types/vite-env.d.ts +0 -9
- package/types/widget.ts +0 -15
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
|
+
```
|