@chrischall/hellofresh-mcp 0.0.0-stage → 0.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/.claude-plugin/marketplace.json +33 -0
- package/.claude-plugin/plugin.json +21 -0
- package/.mcp.json +8 -0
- package/LICENSE +21 -0
- package/README.md +186 -2
- package/dist/bundle.js +74979 -0
- package/dist/client.js +248 -0
- package/dist/config.js +8 -0
- package/dist/index.js +38 -0
- package/dist/normalize.js +235 -0
- package/dist/planner.js +219 -0
- package/dist/profiles.js +121 -0
- package/dist/session.js +287 -0
- package/dist/tools/healthcheck.js +71 -0
- package/dist/tools/hints.js +14 -0
- package/dist/tools/index.js +13 -0
- package/dist/tools/planner.js +281 -0
- package/dist/tools/reads.js +303 -0
- package/dist/tools/shared.js +183 -0
- package/dist/tools/writes.js +572 -0
- package/dist/transport.js +81 -0
- package/dist/types.js +6 -0
- package/dist/version.js +5 -0
- package/dist/weeks.js +33 -0
- package/manifest.json +164 -0
- package/mint.yaml +76 -0
- package/package.json +68 -4
- package/server.json +58 -0
- package/skills/hellofresh/SKILL.md +170 -0
- package/skills/hellofresh-fpx/SKILL.md +78 -0
- package/skills/hellofresh-fpx/references/requests.md +150 -0
- package/skills/hellofresh-fpx/scripts/hf-token.mjs +101 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# HelloFresh read recipes (curl + jq)
|
|
2
|
+
|
|
3
|
+
Prerequisite (SKILL.md § Core pattern): the token loaded into `~/.hellofresh-fpx`
|
|
4
|
+
and the `hf` function defined.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
S=~/.hellofresh-fpx; T=~/.claude/skills/hellofresh-fpx/scripts/hf-token.mjs
|
|
8
|
+
(umask 077; fpx cookies apiV2Auth -p hellofresh --storage-subdomain www > "$S/cookie.json") && node "$T" load "$S"
|
|
9
|
+
hf() { curl -sS --fail-with-body -H @"$S/auth.header" -H 'accept: application/json' "https://www.hellofresh.com/gw$1"; }
|
|
10
|
+
Q='country=US&locale=en-US'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Records carry the account holder's name, email, addresses and payment token.
|
|
14
|
+
Every recipe below projects to the fields it needs; never dump a whole
|
|
15
|
+
subscription or delivery into a chat.
|
|
16
|
+
|
|
17
|
+
Money is in US **cents**. Weeks are ISO weeks (`2026-W49`). `deliveryOption`
|
|
18
|
+
handles read `US-<weekday 1=Mon..7=Sun>-<from HHMM>-<to HHMM>`.
|
|
19
|
+
|
|
20
|
+
## Subscription
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
hf "/api/customers/me/subscriptions?$Q" | jq '.items[] | {id, sku: .product.sku, unitPriceCents: .product.unitPrice,
|
|
24
|
+
preset, deliveryOption: .deliveryOption.handle, deliveryWeekday, deliveryInterval, nextDeliveryWeek,
|
|
25
|
+
nextCutoffDate, nextModifiableDeliveryWeek, customerPlanId, isActive, pausedAt,
|
|
26
|
+
voucher: (.voucherInfo | if . then {code, is_active} else null end)}'
|
|
27
|
+
SUB=$(hf "/api/customers/me/subscriptions?$Q" | jq -r '.items[0].id')
|
|
28
|
+
PLAN=$(hf "/api/customers/me/subscriptions?$Q" | jq -r '.items[0].customerPlanId')
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
One subscription by id (same shape):
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
hf "/api/subscriptions/$SUB?$Q" | jq '{id, sku: .product.sku, deliveryOption: .deliveryOption.handle, deliveryInterval}'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Upcoming deliveries (about 7 weeks)
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
hf "/api/customers/me/deliveries?$Q" | jq '.items | sort_by(.id)[] | {week: .id, deliveryDate, cutoffDate, status,
|
|
41
|
+
sku: .product.handle, meals: .product.specs.meals, people: .product.specs.size,
|
|
42
|
+
priceCents: .product.price, feeCents: .product.specialFee, shippingCents: .product.shippingPrice}'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`status`: `RUNNING` = coming, `PAUSED` = skipped, `DELIVERED`, `DONATED`.
|
|
46
|
+
One line per week:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
hf "/api/customers/me/deliveries?$Q" | jq -r '.items | sort_by(.id)[] |
|
|
50
|
+
"\(.id) — \(.deliveryDate[0:10]) — \(.status | ascii_downcase), \(.product.specs.meals)×\(.product.specs.size), cutoff \(.cutoffDate[5:10])"'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## One delivery week
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
W=2026-W49
|
|
57
|
+
hf "/api/subscriptions/$SUB/delivery_dates/$W?$Q" | jq '{week: .id, deliveryDate, cutoffDate, status, subStatus,
|
|
58
|
+
sku: .product.handle, productName: .product.productName, allowedActions,
|
|
59
|
+
deliveryOption: .deliveryOption.handle, otherDays: [.availableOneOffOptions[]? | {handle, deliveryDate}]}'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Box sizes on offer
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
hf "/api/subscriptions/$SUB/product_options?$Q" | jq -r '.items[].products[] | "\(.handle)\t\(.specs.meals) meals × \(.specs.size) people"'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Customer plan (the permanent box size)
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
hf "/api/plans?$Q" | jq '.[] | {id, planType, productHandle: .planItems[0].productHandle}'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Menu weeks
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
hf "/menus-service/weeks?$Q" | jq -r '.weeks[]'
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## A week's menu (with the current picks)
|
|
81
|
+
|
|
82
|
+
`servings` and `product-sku` are REQUIRED (400 without them) — take both from
|
|
83
|
+
that week's delivery, so a one-week size change is respected:
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
W=2026-W49
|
|
87
|
+
SKU=$(hf "/api/subscriptions/$SUB/delivery_dates/$W?$Q" | jq -r .product.handle)
|
|
88
|
+
PEOPLE=$(hf "/api/subscriptions/$SUB/delivery_dates/$W?$Q" | jq -r .product.specs.size)
|
|
89
|
+
hf "/my-deliveries/menu?subscription=$SUB&week=$W&locale=en-US&servings=$PEOPLE&product-sku=$SKU&customerPlanId=$PLAN&exclude-feedback=true" > "$S/menu-$W.json"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The menu lists base courses AND protein-swap variants (`modularity[].variations[].index`).
|
|
93
|
+
Base courses only, seafood first, with the premium per serving:
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
jq '([.modularity[]?.variations[]?.index]) as $variants | .meals[] | select(.index as $i | $variants | index($i) | not)
|
|
97
|
+
| {index, name: .recipe.name, headline: .recipe.headline, category: .recipe.category,
|
|
98
|
+
totalTime: .recipe.totalTime, kidFriendly: ([.recipe.tags[]? | .type] | index("family-friendly") != null),
|
|
99
|
+
premiumPerServingCents: (.charge.unitAmount // 0), picked: (.selection.quantity // 0)}' "$S/menu-$W.json"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Seafood only (`category == "Seafood"`), or the swaps offered on a course:
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
jq '.meals[] | select(.recipe.category == "Seafood") | {index, name: .recipe.name, premium: .charge.label}' "$S/menu-$W.json"
|
|
106
|
+
jq '.modularity[] | select(.variations | length > 0) | {course: .defaultCourseIndex, swaps: [.variations[] | {index, title}]}' "$S/menu-$W.json"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The current picks (a `selection.quantity` means picked):
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
jq '.meals[] | select(.selection.quantity) | {index, name: .recipe.name, quantity: .selection.quantity}' "$S/menu-$W.json"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Estimated box total
|
|
116
|
+
|
|
117
|
+
There is no single "box total" read. Product price + fee + shipping + premiums,
|
|
118
|
+
before any voucher discount:
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
D=$(hf "/api/subscriptions/$SUB/delivery_dates/$W?$Q")
|
|
122
|
+
jq -n --argjson d "$D" --slurpfile m "$S/menu-$W.json" '
|
|
123
|
+
($d.product.price + ($d.product.specialFee // 0) + ($d.product.shippingPrice // 0)
|
|
124
|
+
+ ([$m[0].meals[] | select(.selection.quantity) | (.charge.totalAmount // 0)] | add // 0)) / 100'
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The voucher (`voucherInfo.discount_settings.discount_rule.box_rule`) gives a
|
|
128
|
+
per-box-number percentage in hundredths (`6500` = 65 %); `applicable_to:
|
|
129
|
+
"products"` discounts the product price only. Label any figure an estimate.
|
|
130
|
+
|
|
131
|
+
## Refresh (only when reloading the tab didn't help)
|
|
132
|
+
|
|
133
|
+
The refresh token **rotates** on every refresh and the response sets no
|
|
134
|
+
cookie, so the new set MUST be written back into the browser right away, or
|
|
135
|
+
the browser keeps a spent refresh token and is signed out. If the
|
|
136
|
+
hellofresh-mcp server is running too, prefer reloading the tab: two refreshers
|
|
137
|
+
fork the session.
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
code=$(curl -sS -o "$S/refreshed.json" -w '%{http_code}' -X POST \
|
|
141
|
+
'https://www.hellofresh.com/gw/refresh?country=us&locale=en-US' \
|
|
142
|
+
-H 'content-type: application/json' --data-binary @<(jq -c '{refresh_token}' "$S/auth.json"))
|
|
143
|
+
echo "refresh: HTTP $code" >&2
|
|
144
|
+
node "$T" store "$S" && fpx write-cookies apiV2Auth=@"$S/cookie.txt" -p hellofresh --storage-subdomain www
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`store` writes `auth.json`, `auth.header` and `cookie.txt` (the value encoded
|
|
148
|
+
exactly as the site's js-cookie does); `fpx write-cookies` prints the cookie
|
|
149
|
+
name once it landed. `400 {"error":"invalid_grant"}` → the refresh token was
|
|
150
|
+
already spent: sign in again at hellofresh.com, then `load`.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// HelloFresh token helper for the hellofresh-fpx skill. Dependency-free.
|
|
3
|
+
//
|
|
4
|
+
// node hf-token.mjs load <dir> <dir>/cookie.json (the `fpx cookies apiV2Auth` output)
|
|
5
|
+
// → <dir>/auth.json + <dir>/auth.header
|
|
6
|
+
// node hf-token.mjs store <dir> <dir>/refreshed.json (the POST /gw/refresh response)
|
|
7
|
+
// → <dir>/auth.json + <dir>/auth.header + <dir>/cookie.txt
|
|
8
|
+
// (cookie.txt = the value to write back with
|
|
9
|
+
// `fpx write-cookies apiV2Auth=@<dir>/cookie.txt`)
|
|
10
|
+
//
|
|
11
|
+
// auth.header is one line, `Authorization: Bearer <token>`, for `curl -H @file`,
|
|
12
|
+
// so the token never sits on a command line. Every file is mode 600. Nothing is
|
|
13
|
+
// printed to stdout and no token value is ever printed: status goes to stderr.
|
|
14
|
+
// Exit codes: 0 ok · 4 signed out / refresh refused · 64 usage.
|
|
15
|
+
|
|
16
|
+
import { chmodSync, readFileSync, writeFileSync } from 'node:fs';
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
|
|
19
|
+
const SIGN_IN = 'Sign in at https://www.hellofresh.com in the browser running ContextMint Bridge, then run load again.';
|
|
20
|
+
|
|
21
|
+
// The cookie JSON's key order, as the web app writes it.
|
|
22
|
+
const KEY_ORDER = ['access_token', 'expires_in', 'refresh_token', 'token_type', 'user_data', 'refresh_expires_in', 'issued_at'];
|
|
23
|
+
|
|
24
|
+
function fail(code, message) {
|
|
25
|
+
process.stderr.write(`hf-token: ${message}\n`);
|
|
26
|
+
process.exit(code);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function writePrivate(path, text) {
|
|
30
|
+
writeFileSync(path, text, { mode: 0o600 });
|
|
31
|
+
chmodSync(path, 0o600);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readJson(path) {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
37
|
+
} catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const isTokenSet = (v) =>
|
|
43
|
+
typeof v === 'object' && v !== null && typeof v.access_token === 'string' && v.access_token !== '' &&
|
|
44
|
+
typeof v.refresh_token === 'string' && v.refresh_token !== '';
|
|
45
|
+
|
|
46
|
+
// js-cookie v3 read: decode %XX runs.
|
|
47
|
+
function decodeCookie(raw) {
|
|
48
|
+
const unquoted = raw.startsWith('"') ? raw.slice(1, -1) : raw;
|
|
49
|
+
return JSON.parse(unquoted.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// js-cookie v3 write: encodeURIComponent, then DE-code # $ & + / : < = > ? @ [ ] ^ ` { | }.
|
|
53
|
+
function encodeCookie(set) {
|
|
54
|
+
const ordered = {};
|
|
55
|
+
for (const k of KEY_ORDER) if (set[k] !== undefined) ordered[k] = set[k];
|
|
56
|
+
for (const [k, v] of Object.entries(set)) if (!(k in ordered)) ordered[k] = v;
|
|
57
|
+
return encodeURIComponent(JSON.stringify(ordered)).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function save(dir, set) {
|
|
61
|
+
writePrivate(join(dir, 'auth.json'), JSON.stringify(set));
|
|
62
|
+
writePrivate(join(dir, 'auth.header'), `Authorization: Bearer ${set.access_token}\n`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function reportExpiry(set) {
|
|
66
|
+
const left = Math.round((set.issued_at + set.expires_in - Date.now() / 1000) / 60);
|
|
67
|
+
process.stderr.write(
|
|
68
|
+
left > 1
|
|
69
|
+
? `hf-token: access token valid for ${left} min\n`
|
|
70
|
+
: 'hf-token: access token expired — reload the hellofresh.com tab and run load again, or refresh (references/requests.md)\n',
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const [cmd, dir] = process.argv.slice(2);
|
|
75
|
+
if (!dir || (cmd !== 'load' && cmd !== 'store')) fail(64, 'usage: hf-token.mjs load|store <dir>');
|
|
76
|
+
|
|
77
|
+
if (cmd === 'load') {
|
|
78
|
+
const raw = readJson(join(dir, 'cookie.json'))?.apiV2Auth;
|
|
79
|
+
let set;
|
|
80
|
+
try {
|
|
81
|
+
set = typeof raw === 'string' && raw !== '' ? decodeCookie(raw) : undefined;
|
|
82
|
+
} catch {
|
|
83
|
+
set = undefined;
|
|
84
|
+
}
|
|
85
|
+
if (!isTokenSet(set)) fail(4, `no HelloFresh session in the apiV2Auth cookie. ${SIGN_IN}`);
|
|
86
|
+
save(dir, set);
|
|
87
|
+
reportExpiry(set);
|
|
88
|
+
} else {
|
|
89
|
+
const fresh = readJson(join(dir, 'refreshed.json'));
|
|
90
|
+
if (!isTokenSet(fresh)) {
|
|
91
|
+
const error = typeof fresh?.error === 'string' ? fresh.error : 'no token set in the response';
|
|
92
|
+
fail(4, `refresh refused (${error}). ${SIGN_IN}`);
|
|
93
|
+
}
|
|
94
|
+
const old = readJson(join(dir, 'auth.json')) ?? {};
|
|
95
|
+
const set = { ...fresh };
|
|
96
|
+
if (set.user_data === undefined && old.user_data !== undefined) set.user_data = old.user_data;
|
|
97
|
+
if (typeof set.issued_at !== 'number') set.issued_at = Math.floor(Date.now() / 1000);
|
|
98
|
+
save(dir, set);
|
|
99
|
+
writePrivate(join(dir, 'cookie.txt'), encodeCookie(set));
|
|
100
|
+
reportExpiry(set);
|
|
101
|
+
}
|