hookwright 1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +116 -0
  3. package/dist/cli.js +2890 -0
  4. package/package.json +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # hookwright
2
+
3
+ Build **real, signed e-commerce webhooks** from a live Shopify catalogue — and send them to your own endpoint.
4
+
5
+ Nothing in the payload is invented. Product titles, variant ids, prices and image URLs all come from your Shopify store through the Admin API; totals are computed from those real prices. It is a terminal app built with [Ink](https://github.com/vadimdemedes/ink) — there is no backend and no service to sign up for.
6
+
7
+ ```
8
+ ╭──────────────────────────────────────────────────────────────╮
9
+ │ hookwright Addy Fashion │
10
+ ╰──────────────────────────────────────────────────────────────╯
11
+ real catalogue → signed provider webhooks
12
+
13
+ ❯ Setup Shopify and webhook destination
14
+ Integrations build and send a provider webhook
15
+ History review or re-send a saved payload
16
+ Doctor check credentials and connectivity
17
+ Clear remove cached data
18
+ Quit
19
+ ```
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npx hookwright # no install
25
+ npm i -g hookwright # or install it
26
+ ```
27
+
28
+ Requires Node 20+.
29
+
30
+ ## Quick start
31
+
32
+ ```bash
33
+ hookwright # interactive UI — starts in the setup wizard on first run
34
+ ```
35
+
36
+ **Setup** and **Integrations** sit side by side. Setup is global — configure it once and every integration uses it:
37
+
38
+ | Setup | asks for |
39
+ |---|---|
40
+ | **Shopify** | store domain + Admin API access token (needs `read_products`). Verifies immediately and picks up currency, country, province and contact details from the store record |
41
+ | **Webhook** | just the destination URL, plus the signing secret |
42
+ | **Customer** | the shopper the abandoned cart belongs to |
43
+ | **Defaults** | currency, platform |
44
+
45
+ Stored in `~/.config/hookwright/config.json`, mode `0600` — it holds a Shopify token and a signing secret.
46
+
47
+ Then **Integrations → Cashfree One Click Checkout** builds the payload:
48
+
49
+ 1. Products are fetched live from your store and listed — pick what goes in the cart
50
+ 2. Variant and quantity per product
51
+ 3. Cart discount
52
+ 4. Either accept the suggested values, or **review every field** — each one is pre-filled with the generated suggestion, enter accepts it, typing replaces it
53
+ 5. Pre-flight report, then send
54
+
55
+ ## Headless usage
56
+
57
+ Every command works without a TTY, for CI or scripting:
58
+
59
+ ```bash
60
+ hookwright build --items 2 # build from the 2 first products
61
+ hookwright build --search "cold brew" # only products matching a title
62
+ hookwright build --items 3 --discount 250 --send
63
+ hookwright send --dry-run # print the request + curl, send nothing
64
+ hookwright send --file ~/.local/state/hookwright/payloads/2026-…json
65
+ hookwright doctor --json
66
+ hookwright history
67
+ hookwright clear --payloads --yes # or --logs / --shop-cache / --disconnect / --all
68
+ ```
69
+
70
+ Exit codes: `0` ok · `1` configuration/usage · `2` pre-flight failed · `3` endpoint rejected the webhook.
71
+
72
+ ## What it checks before sending
73
+
74
+ A generated payload is useless if the receiver silently drops it, so every build runs pre-flight:
75
+
76
+ - **Schema gate** — `type` must equal `ABANDONED_CHECKOUT`, or the consumer ignores the event without an error.
77
+ - **JSON round-trip** — receivers that verify `HMAC(secret, timestamp + JSON.stringify(parsedBody))` can only match if `JSON.stringify(JSON.parse(raw)) === raw`. If it doesn't, you're told the exact byte offset.
78
+ - **Phone** — parsed to E.164 using the shipping `country_code`, the same way the consumer does.
79
+ - **Phone allow-list** — refuses to build for a number that isn't an approved test handset, so a live shopper can never be messaged by a test run.
80
+ - **Product images** — every `image_url` is `HEAD`-checked; unreachable images fail the build.
81
+ - **Field coverage** — a table of every field the consumer reads, what it maps to, and its value. Missing required fields are flagged in red.
82
+
83
+ Sending is also blocked when the target looks like production, unless `--force`.
84
+
85
+ ## Safety
86
+
87
+ - The config file is `0600` and secrets are redacted from the log file.
88
+ - Dry-run prints a `curl` that reproduces the request exactly, using `--data-binary` so the signed bytes are preserved.
89
+ - Payload history lives in `~/.local/state/hookwright/payloads/` and can be re-sent (re-signed with a fresh timestamp).
90
+
91
+ Override both locations with `HOOKWRIGHT_HOME`, or point at one config with `--config <path>` / `HOOKWRIGHT_CONFIG`.
92
+
93
+ **Clear** removes local state — saved payloads, the activity log, the cached store record, the Shopify credentials, or everything back to first-run state. It shows exactly what will be deleted and asks before doing it.
94
+
95
+ ## Providers
96
+
97
+ | provider | signature | headers |
98
+ |---|---|---|
99
+ | `cashfree-occ` | base64 HMAC-SHA256 over `timestamp + body` | `x-webhook-signature`, `x-webhook-timestamp` |
100
+
101
+ Adding one is a single file in `src/providers/` exporting `buildPayload`, `sign`, `webhookUrl`, a `gate` and a `fieldMap` — see [docs/cashfree-occ.md](docs/cashfree-occ.md).
102
+
103
+ ## Development
104
+
105
+ ```bash
106
+ npm install
107
+ npm run dev # esbuild watch
108
+ npm test # 54 tests, no network required
109
+ npm start # build + run
110
+ ```
111
+
112
+ The test suite includes an end-to-end run against a stub Shopify API and a stub consumer that verifies the signature exactly as the real one does, asserting the transmitted bytes are identical to the signed bytes.
113
+
114
+ ## License
115
+
116
+ MIT