fresh-squeezy 0.1.8 → 0.1.9

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 CHANGED
@@ -5,36 +5,44 @@ Validator-first Lemon Squeezy doctor. Catches misconfigurations before they ship
5
5
  ## 30-second start
6
6
 
7
7
  ```bash
8
- npm i -D fresh-squeezy
9
- cp .env.example .env.local # fill in LEMON_SQUEEZY_API_KEY
10
- npx fresh-squeezy doctor --all-stores
8
+ npx fresh-squeezy
11
9
  ```
12
10
 
13
- No store ID to copy from the dashboard — the CLI discovers reachable stores itself.
11
+ The first run adds `fresh-squeezy` to devDependencies when it is missing, then starts the guided setup. No store ID to copy from the dashboard — the CLI discovers reachable stores itself. Use `npx fresh-squeezy --no-install` to run the setup without editing `package.json`.
14
12
 
15
13
  | Exit | Meaning |
16
14
  |------|---------|
17
15
  | `0` | All validators passed |
18
16
  | `1` | One or more validators reported `error`-level issues |
19
17
  | `2` | Fatal (missing key, invalid flags, network failure) |
18
+ | `130` | User cancelled an interactive flow |
20
19
 
21
20
  ## What it catches that Postman and the official SDK won't
22
21
 
23
22
  - **Prod key pointed at staging.** `MODE_MISMATCH` fires when the key's true `meta.test_mode` (API changelog 2024-01-05) disagrees with the declared mode. Doctor exits 1. Neither the SDK nor a hand-rolled wrapper catches this by default.
24
23
  - **Silent store-ownership mismatches.** Products, discounts, license keys, and subscription plans whose `store_id` doesn't match the store you scoped the run to. Stable codes: `PRODUCT_WRONG_STORE`, `DISCOUNT_STORE_MISMATCH`, `LICENSE_KEY_STORE_MISMATCH`, `PLAN_STORE_MISMATCH`.
25
24
  - **Webhook subscribed to the wrong events.** Diff against a manifest of recommended events (order/subscription lifecycle, refunds) and newer-but-optional events the SDK doesn't ship.
26
- - **Platform drift.** A weekly GitHub Action hashes the [Lemon Squeezy API changelog](https://docs.lemonsqueezy.com/api/getting-started/changelog) against `src/support/changelog-snapshot.json` and opens an issue when it moves. Tracked additions beyond the official SDK as of 2026-04-24: `customer_updated` (2026-02-25), `payment_processor` on Subscription (2025-06-11), Affiliates + `affiliate_activated` (2025-01-21), `test_mode` on `/v1/users/me` (2024-01-05).
25
+ - **Platform drift.** A weekly GitHub Action hashes the [Lemon Squeezy API changelog](https://docs.lemonsqueezy.com/api/getting-started/changelog) against `src/support/changelog-snapshot.json`, refreshes docs-derived API types, and opens follow-up work when policy decisions are needed. Tracked additions include `customer_updated` (2026-02-25), `payment_processor` on Subscription (2025-06-11), Affiliates + `affiliate_activated` (2025-01-21), order item `quantity` (2024-12-06), checkout styling / `skip_trial` / `variant_quantities`, subscription invoice refund fields, and `test_mode` on `/v1/users/me` (2024-01-05).
27
26
  - **Postman + dashboard ping-pong.** One `doctor` call replaces the loop of copying IDs out of the UI, pasting them into env files, and verifying each one by hand.
28
27
 
29
28
  ## CLI
30
29
 
31
30
  ```bash
31
+ # First run: install as a dev dependency, then start guided setup
32
+ npx fresh-squeezy
33
+
34
+ # Guided setup only: reuse env values, pick a store, choose one or more resource checks
35
+ npx fresh-squeezy init
36
+
32
37
  # TTY: multi-select stores interactively, run doctor on each
33
38
  npx fresh-squeezy doctor
34
39
 
35
40
  # Non-interactive: every reachable store
36
41
  npx fresh-squeezy doctor --all-stores
37
42
 
43
+ # Full sweep: discover products, webhooks, discounts, license keys, and subscription plans
44
+ npx fresh-squeezy doctor --all-stores --all-resources
45
+
38
46
  # Specific stores
39
47
  npx fresh-squeezy doctor --store-ids 12,34,56
40
48
 
@@ -48,8 +56,8 @@ npx fresh-squeezy validate webhook \
48
56
  --store-ids 12,34 \
49
57
  --webhook-url https://app.example.com/api/webhooks/lemon-squeezy
50
58
 
51
- # Machine-readable output for CI
52
- npx fresh-squeezy doctor --all-stores --json
59
+ # Machine-readable full sweep for CI
60
+ npx fresh-squeezy doctor --all-stores --all-resources --json
53
61
  ```
54
62
 
55
63
  Store resolution order, used by every store-scoped command:
@@ -59,6 +67,8 @@ Store resolution order, used by every store-scoped command:
59
67
  3. TTY: inquirer multi-select prompt
60
68
  4. No TTY + no flag: connection-only run (useful as a CI smoke check)
61
69
 
70
+ By default, `doctor` validates connection and store access plus any explicit resource flags you pass. Add `--all-resources` when you want the CLI to discover and validate every supported resource in the selected store(s).
71
+
62
72
  ## Library
63
73
 
64
74
  ```ts
@@ -84,7 +94,14 @@ if (!report.ok) {
84
94
 
85
95
  For multi-store runs at the library layer, call `doctor()` in a loop. The CLI does exactly this.
86
96
 
87
- Public types: [`FreshSqueezyClient`](src/createFreshSqueezy.ts), [`ValidationResult<T>`](src/core/types.ts), [`DoctorReport`](src/core/types.ts). Switch on `issue.code` in CI logic — codes are stable across minor versions.
97
+ Public types: [`FreshSqueezyClient`](src/createFreshSqueezy.ts), [`ValidationResult<T>`](src/core/types.ts), [`DoctorReport`](src/core/types.ts), resource attribute interfaces under [`src/resources`](src/resources), docs-generated Lemon Squeezy object types in [`src/generated/lemonSqueezyApiTypes.ts`](src/generated/lemonSqueezyApiTypes.ts), and changelog augmentation helpers in [`src/augmentations.ts`](src/augmentations.ts). Switch on `issue.code` in CI logic — codes are stable across minor versions.
98
+ `ValidationResult.target` is optional and identifies the checked resource in human output and JSON when a validator has a product, webhook, store, discount, license key, or variant handle.
99
+
100
+ Generate a local augmentation file when your app uses the official SDK or older hand-rolled types:
101
+
102
+ ```bash
103
+ npx fresh-squeezy types augment
104
+ ```
88
105
 
89
106
  ## Sandbox vs live
90
107
 
@@ -98,6 +115,7 @@ result.resource?.actualMode; // "live" — alarm bell
98
115
  ```
99
116
 
100
117
  The CLI default is `--mode test`. Override with `--mode live`. For nightly platform-drift checks in CI, run `npm run test:live` with `LEMON_SQUEEZY_LIVE_SMOKE=1` and a test-mode key.
118
+ Guided setup asks for explicit confirmation before continuing with a detected live-mode key.
101
119
 
102
120
  ## Issue codes
103
121
 
@@ -122,6 +140,16 @@ For endpoints not yet wrapped, use the raw escape hatch:
122
140
  const user = await lemon.request({ path: "/v1/users/me" });
123
141
  ```
124
142
 
143
+ For wrapped-but-not-validated endpoints, import the exported attribute type and use `request()`:
144
+
145
+ ```ts
146
+ import type { SubscriptionInvoiceAttributes } from "fresh-squeezy";
147
+
148
+ const invoice = await lemon.request<{ data: { attributes: SubscriptionInvoiceAttributes } }>({
149
+ path: "/v1/subscription-invoices/123",
150
+ });
151
+ ```
152
+
125
153
  ## Environment variables
126
154
 
127
155
  | Variable | Required | Purpose |
@@ -144,12 +172,25 @@ The CLI does not read `LEMON_SQUEEZY_STORE_ID`; use `--store-ids` or `--all-stor
144
172
  - **`validateLicenseKey`** — Enabled, not expired, activations available, store ownership matches. [→ source](src/validate/licenseKey.ts)
145
173
  - **`validateSubscriptionPlan`** — Subscription type, valid interval, non-zero price, consistent trial. [→ source](src/validate/subscriptionPlan.ts)
146
174
  - **`doctor`** — Composes the above into one `DoctorReport`. [→ source](src/validate/doctor.ts)
175
+ - **Types/resources** — Changelog-backed interfaces for customers, checkouts, order items, subscription invoices/items, usage records, affiliates, and more. [→ source](src/resources)
147
176
 
148
177
  ### CLI commands
149
178
 
150
- - **`doctor`** — Run every configured validator and emit a report. [→ source](src/cli/commands/doctor.ts)
179
+ - **`doctor`** — Run configured validators; add `--all-resources` for discovery-backed full sweeps. [→ source](src/cli/commands/doctor.ts)
151
180
  - **`validate <name>`** — Run a single validator. [→ source](src/cli/commands/validate.ts)
152
181
  - **`init`** — Interactive setup: ask for credentials, pick a store, run doctor. [→ source](src/cli/commands/init.ts)
182
+ - **`types augment`** — Emit a local `.d.ts` for changelog fields not present in older SDK/local types. [→ source](src/cli/commands/augment.ts)
183
+
184
+ ## Keeping API Types Current
185
+
186
+ Resource coverage is generated from Lemon Squeezy's object docs, so most newly documented fields do not require a hand edit:
187
+
188
+ ```bash
189
+ npm run generate:api-types
190
+ npm run check:api-types
191
+ ```
192
+
193
+ Manual review still applies to validator behavior and webhook policy: new events belong in `RECOMMENDED_WEBHOOK_EVENTS` or `OPTIONAL_WEBHOOK_EVENTS`, and meaningful platform changes should be acknowledged in `ACKNOWLEDGED_CHANGELOG_ENTRIES`.
153
194
 
154
195
  ## Contributing
155
196