notify-me-wl 1.4.3 → 2.0.0
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 +26 -9
- package/build/notify-me-wl.js +667 -0
- package/build/notify-me-wl.min.js +1 -0
- package/package.json +17 -3
- package/CLAUDE.md +0 -199
- package/index.html +0 -21
- package/index.js +0 -553
package/README.md
CHANGED
|
@@ -3,19 +3,36 @@
|
|
|
3
3
|
This JavaScript widget allows users to register their interest in a product that is either "coming soon" or "out of stock" (aka "notify me"). Depending on the `data-type` attribute provided, the widget will display appropriate messages and functionality.
|
|
4
4
|
|
|
5
5
|
#### Features:
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
6
|
+
- Clean, centered modal that inherits the host store's font and stays out of the theme's way (all styles are namespaced under `#twc-nm-overlay`).
|
|
7
|
+
- Dynamically display a labeled form to collect user information (email, mobile, first/last name, country, province).
|
|
8
|
+
- Adjust form copy and button text based on the widget type (`notify-me` or `coming-soon`).
|
|
9
|
+
- Inline success/error feedback (no browser `alert`s); the submit button shows a "Sending…" loading state.
|
|
10
|
+
- Closes on the × button, clicking the backdrop, or pressing `Esc`; locks background scroll while open and respects `prefers-reduced-motion`.
|
|
11
|
+
- Optional email/SMS marketing opt-ins.
|
|
12
|
+
- Two auth modes: bundled server token (default) or Shopify App Proxy — see [Configuration](#configuration).
|
|
10
13
|
|
|
11
14
|
### Installation
|
|
12
15
|
|
|
13
16
|
Add the following script to your HTML to include the widget:
|
|
14
17
|
|
|
15
18
|
```html
|
|
16
|
-
<script src="https://cdn.jsdelivr.net/npm/notify-me-wl/
|
|
19
|
+
<script src="https://cdn.jsdelivr.net/npm/notify-me-wl/build/notify-me-wl.min.js"></script>
|
|
17
20
|
```
|
|
18
21
|
|
|
22
|
+
### Development / Build
|
|
23
|
+
|
|
24
|
+
Source lives in `src/` (TypeScript) and is bundled with Rollup into `build/`.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install # install dev dependencies
|
|
28
|
+
npm run build # emit build/notify-me-wl.js and build/notify-me-wl.min.js
|
|
29
|
+
npm run dev # rebuild on change (watch mode)
|
|
30
|
+
npm run typecheck # type-check without emitting
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
> **v2.0.0 path change:** the distributed bundle moved from `index.js` to
|
|
34
|
+
> `build/notify-me-wl.min.js`. Update embeds to the new CDN URL above.
|
|
35
|
+
|
|
19
36
|
### Usage
|
|
20
37
|
|
|
21
38
|
Add a button to your HTML where you want the widget to appear. The button should have an `id` of `popup-open`, a `data-fields` attribute with the fields you want to include in the form (as a JSON string), and a `data-type` attribute to specify the widget type (`notify-me` or `coming-soon`).
|
|
@@ -27,7 +44,7 @@ Add a button to your HTML where you want the widget to appear. The button should
|
|
|
27
44
|
|
|
28
45
|
### Configuration
|
|
29
46
|
|
|
30
|
-
- `data-fields`: A JSON array specifying the fields to include in the form. Possible values are `"mobile"`, `"firstName"`, and `"
|
|
47
|
+
- `data-fields`: A JSON array specifying the optional fields to include in the form. Possible values are `"email"`, `"mobile"`, `"firstName"`, `"lastName"`, `"countryCode"`, and `"provinceCode"`. Defaults to `["email"]`. (A required Size selector is always shown and populated from the product's variants.)
|
|
31
48
|
- `data-type`: Specifies the type of the widget. Possible values are `"notify-me"` and `"coming-soon"`.
|
|
32
49
|
- `data-auth`: Auth mode. `"token"` (default) uses the bundled server-issued access token. `"proxy"` uses the Shopify App Proxy at `/apps/twc-sdk/auth/token` to obtain a tenant-scoped token (requires the customer to be logged in to the storefront).
|
|
33
50
|
- `data-tenant`: The TWC tenant sent as the `X-Twc-Tenant` header. Used in both auth modes. Falls back to the bundled `TENANT_ID` if omitted.
|
|
@@ -52,10 +69,10 @@ Because the proxy only issues a token for a logged-in customer, if the token can
|
|
|
52
69
|
### How It Works
|
|
53
70
|
|
|
54
71
|
1. **Initialization**: The script listens for the `DOMContentLoaded` event to initialize the widget.
|
|
55
|
-
2. **Styles Injection**: It injects
|
|
72
|
+
2. **Styles Injection**: It injects the modal/form styles, all namespaced under `#twc-nm-overlay` so they don't collide with the host theme.
|
|
56
73
|
3. **Modal Creation**: Creates the modal structure and appends it to the `notification-widget` div.
|
|
57
|
-
4. **Dynamic Content**: Based on the `data-type`, it sets the appropriate
|
|
58
|
-
5. **Form Submission**:
|
|
74
|
+
4. **Dynamic Content**: Based on the `data-type`, it sets the appropriate copy and button text, and builds the fields listed in `data-fields` plus the always-present Size selector.
|
|
75
|
+
5. **Form Submission**: On submit, the button enters a "Sending…" state, the configured auth token is resolved, and the form data is POSTed to the API. The result is shown inline (success message then auto-close, or an error message); the popup is never closed on failure.
|
|
59
76
|
|
|
60
77
|
### API Request Example
|
|
61
78
|
|