@purpleturret/cli 0.1.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 +197 -0
- package/bin/purpleturret.mjs +14 -0
- package/dist/cli.js +1952 -0
- package/dist/cli.js.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# @purpleturret/cli
|
|
2
|
+
|
|
3
|
+
Manage your [Purpleturret](https://purpleturret.com) checkout products as code. Declare them once in `purpleturret.config.ts`, review a plan, push. Available as `purpleturret` and the shorter `pt`.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@purpleturret/cli)
|
|
6
|
+
|
|
7
|
+
> **Early access.** The CLI, SDK, and management API are under active development. They work, but expect rough edges and read the plan before you apply it. Feedback: https://purpleturret.com/contact
|
|
8
|
+
|
|
9
|
+
## What is Purpleturret?
|
|
10
|
+
|
|
11
|
+
Purpleturret gives creators and small software teams hosted checkout links (`https://purpleturret.com/c/<slug>`) that charge straight into their own Stripe or PayPal account. Each link sells one product: a one-time purchase or a monthly or yearly subscription, with delivery by redirect, instructions, or file. Products can belong to a **group** with **tiers** so your app can ask "does this customer have access, and at what level?" through the entitlements API, and they can grant **credits** that your backend meters.
|
|
12
|
+
|
|
13
|
+
Most sellers create products in the dashboard. This CLI is for people who would rather keep them in a file next to their code: reviewed in pull requests, deployed from CI, identical across environments.
|
|
14
|
+
|
|
15
|
+
## What the CLI does
|
|
16
|
+
|
|
17
|
+
- `purpleturret init` writes a typed `purpleturret.config.ts`.
|
|
18
|
+
- `purpleturret push` diffs it against your account and applies the changes, Terraform-style, after showing you the plan.
|
|
19
|
+
- `purpleturret pull` brings dashboard-managed products into the file.
|
|
20
|
+
- `purpleturret status`, `whoami`, and `products list` tell you where things stand.
|
|
21
|
+
|
|
22
|
+
Everything the CLI does goes through the public REST API, so anything you can do here you can also do from your own scripts with [`@purpleturret/sdk`](https://www.npmjs.com/package/@purpleturret/sdk).
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm add -D @purpleturret/cli @purpleturret/sdk
|
|
28
|
+
# or
|
|
29
|
+
npm install --save-dev @purpleturret/cli @purpleturret/sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Node 20 or newer. The SDK is only needed for the typed `defineConfig` helpers your config file imports; a JSON config works without it.
|
|
33
|
+
|
|
34
|
+
## Quick start
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx purpleturret init # writes purpleturret.config.ts with an example product
|
|
38
|
+
npx purpleturret login # paste a seller API key (pt_sk_…); stored with mode 0600
|
|
39
|
+
npx purpleturret push --dry-run # see what would change
|
|
40
|
+
npx purpleturret push # apply after confirming the plan
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Your checkout links are printed after a successful push.
|
|
44
|
+
|
|
45
|
+
## Authentication
|
|
46
|
+
|
|
47
|
+
Mint a **seller API key** in [Dashboard → Settings → Developers](https://purpleturret.com/dashboard/settings). Keys start with `pt_sk_` and carry scopes: `config:read`, `config:write`, `credits:read`, `credits:write`, `entitlements:read`. The CLI needs the two `config` scopes. Hosting keys (`pt_host_…`) are a different product and are rejected.
|
|
48
|
+
|
|
49
|
+
The key is resolved in this order:
|
|
50
|
+
|
|
51
|
+
1. `--api-key <key>`
|
|
52
|
+
2. `PURPLETURRET_API_KEY` from the environment, or from `.env.local` / `.env` in the current directory
|
|
53
|
+
3. The profile saved by `purpleturret login` in `$XDG_CONFIG_HOME/purpleturret/credentials.json` (default `~/.config/…`). Use `--profile <name>` to keep several accounts.
|
|
54
|
+
|
|
55
|
+
The API origin follows the same order with `--api-url` and `PURPLETURRET_API_URL`. When a non-default origin is in use the CLI says so in yellow.
|
|
56
|
+
|
|
57
|
+
## The config file
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { defineConfig, product, usd } from "@purpleturret/sdk";
|
|
61
|
+
|
|
62
|
+
export default defineConfig({
|
|
63
|
+
products: [
|
|
64
|
+
product({
|
|
65
|
+
key: "pro_monthly", // stable identifier; never rename it
|
|
66
|
+
name: "Pro",
|
|
67
|
+
description: "Everything you need to get started.",
|
|
68
|
+
price: usd(29), // { amount: 2900, currency: "usd" }
|
|
69
|
+
billing: { type: "recurring", interval: "month" }, // or { type: "one_time" }
|
|
70
|
+
slug: "acme-pro-monthly", // https://purpleturret.com/c/acme-pro-monthly
|
|
71
|
+
group: { key: "acme", tier: { key: "pro", name: "Pro", rank: 50 } },
|
|
72
|
+
credits: [{ meter: "messages", amount: 1000, renewal: "reset" }],
|
|
73
|
+
delivery: { method: "redirect", url: "https://app.acme.com/welcome" },
|
|
74
|
+
theme: { primaryColor: "#5F34CC" },
|
|
75
|
+
}),
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The CLI finds `purpleturret.config.{ts,mts,js,mjs,json}` in the current directory or any parent up to the git root; `--config <path>` overrides that. TypeScript configs are transpiled on the fly, so `process.env` works inside them.
|
|
81
|
+
|
|
82
|
+
| Field | Type | Notes |
|
|
83
|
+
| ------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
84
|
+
| `key` | `string` | Required. 1–64 chars of `a-z 0-9 _ -`. Identity of the product; unique per account. |
|
|
85
|
+
| `name` | `string` | Required, up to 120 chars. Shown on the checkout and in Stripe. |
|
|
86
|
+
| `description` | `string` | Optional, up to 5,000 chars. |
|
|
87
|
+
| `price` | `{ amount, currency }` | Required. Integer minor units, minimum 50. `usd(29)` → 2900. `currency` is immutable. |
|
|
88
|
+
| `billing` | `{ type: "one_time" } \| { type: "recurring", interval }` | Required. `interval` is `"month"` or `"year"`. Immutable. |
|
|
89
|
+
| `slug` | `string` | Optional public path. 3–64 chars of `a-z 0-9 -`. Create-only. |
|
|
90
|
+
| `group` | `{ key, tier?: { key, name, rank } }` | Optional. Powers the entitlements API. Higher `rank` means more access. |
|
|
91
|
+
| `credits` | `{ meter, amount, renewal, expiresAfterDays? }[]` | Optional. Granted on every paid invoice. `renewal` is `"reset"` or `"accumulate"`. |
|
|
92
|
+
| `delivery` | `{ method: "none" \| "redirect" (url) \| "instructions" (text) }` | Optional. Redirect URLs must be `https://`. File delivery stays in the dashboard. |
|
|
93
|
+
| `checkout` | `{ layoutMode?, paymentStyle?, providerMode?, contactFields? }` | Optional checkout settings. |
|
|
94
|
+
| `theme` | `{ primaryColor?, buttonRadius?, accentMode? }` | Optional. Hex color; `sm \| md \| lg`; `light \| dark \| system`. |
|
|
95
|
+
| `stripe` | `{ priceId }` | Optional. Adopt an existing Stripe price on create. Immutable. |
|
|
96
|
+
| `active` | `boolean` | Optional. Inactive products stop accepting checkouts. |
|
|
97
|
+
|
|
98
|
+
**Rules to know before you edit:**
|
|
99
|
+
|
|
100
|
+
- `price.currency`, `billing`, `slug`, and `stripe.priceId` cannot change after create. The push reports a `conflict` and applies nothing. Add a new product under a new `key` and archive the old one with `push --prune`.
|
|
101
|
+
- Changing `price.amount` creates a new Stripe price and retires the old one. Existing subscribers keep their price.
|
|
102
|
+
- Fields you omit are not managed: dashboard-only settings such as file delivery, order bumps, and logos survive a push.
|
|
103
|
+
- Products created in the dashboard have no `key`. The CLI lists them but never modifies or archives them, even with `--prune`.
|
|
104
|
+
|
|
105
|
+
## Commands
|
|
106
|
+
|
|
107
|
+
| Command | What it does |
|
|
108
|
+
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
109
|
+
| `init [--from-remote] [--format ts\|json] [--force]` | Write a starter config, or seed it with the products already managed on your account. |
|
|
110
|
+
| `login [--api-key <key>] [--profile <name>]` | Validate a seller key and save it. Non-interactive runs must pass `--api-key` or set the env var. |
|
|
111
|
+
| `logout [--profile <name>]` | Delete the saved profile. |
|
|
112
|
+
| `whoami` | Account, key prefix and scopes, Stripe and PayPal status, API URL, credential source. |
|
|
113
|
+
| `status` | Dry-run the local config and print a summary of pending changes. Never applies anything. |
|
|
114
|
+
| `push [--dry-run] [--prune] [--yes\|-y]` | Plan, confirm, apply. Every push starts with a server-side dry run. |
|
|
115
|
+
| `pull [--out <file>] [--force]` | Write the account's managed products to a config file. `.json` extension writes JSON. |
|
|
116
|
+
| `products list [--all]` | Table of every product with key, name, price, status, and URL. `--all` includes archived ones. |
|
|
117
|
+
|
|
118
|
+
Global flags accepted before or after the subcommand: `--config <path>`, `--api-key <key>`, `--api-url <origin>`, `--profile <name>`, `--json` (machine-readable stdout, diagnostics on stderr), `--no-color` (also `NO_COLOR`), `--verbose` (log every request and stack traces).
|
|
119
|
+
|
|
120
|
+
### What a push looks like
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
Config: purpleturret.config.ts (3 products)
|
|
124
|
+
+ create team_yearly Team (yearly) — $990.00/year
|
|
125
|
+
~ update pro_monthly
|
|
126
|
+
~ price.amount 2900 → 3900 (new Stripe price; existing subscriptions keep the old price)
|
|
127
|
+
~ name "Pro" → "Pro plan"
|
|
128
|
+
= unchanged pro_yearly Pro (yearly) — $269.00/year
|
|
129
|
+
- archive legacy Legacy — $9.00/month
|
|
130
|
+
|
|
131
|
+
Plan: 1 to create, 1 to update, 1 to archive, 1 unchanged.
|
|
132
|
+
Apply these changes? … yes
|
|
133
|
+
|
|
134
|
+
Apply complete: 1 created, 1 updated, 1 archived, 1 unchanged.
|
|
135
|
+
|
|
136
|
+
Checkout links:
|
|
137
|
+
team_yearly https://purpleturret.com/c/acme-team-yearly
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Applies carry an `Idempotency-Key` and are retried once on a network error, so re-running an interrupted push is safe.
|
|
141
|
+
|
|
142
|
+
## CI
|
|
143
|
+
|
|
144
|
+
```yaml
|
|
145
|
+
# GitHub Actions
|
|
146
|
+
- run: pnpm purpleturret push --dry-run # on pull requests; exit 4 on conflicts
|
|
147
|
+
env:
|
|
148
|
+
PURPLETURRET_API_KEY: ${{ secrets.PURPLETURRET_API_KEY }}
|
|
149
|
+
- run: pnpm purpleturret push --yes # on main
|
|
150
|
+
if: github.ref == 'refs/heads/main'
|
|
151
|
+
env:
|
|
152
|
+
PURPLETURRET_API_KEY: ${{ secrets.PURPLETURRET_API_KEY }}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Without a TTY, `push` refuses to apply unless `--yes` is given. Use `--json` to parse the plan.
|
|
156
|
+
|
|
157
|
+
## Exit codes
|
|
158
|
+
|
|
159
|
+
| Code | Meaning |
|
|
160
|
+
| ----- | ------------------------------------------------------------------------------------------- |
|
|
161
|
+
| `0` | Success, including a plan with no changes. |
|
|
162
|
+
| `1` | API or apply error: network failure, rate limit, Stripe not connected, a product failed. |
|
|
163
|
+
| `2` | Usage or validation error: bad flags, config not found or invalid, confirmation needed. |
|
|
164
|
+
| `3` | Authentication: missing or rejected key, wrong key type, or missing scope. |
|
|
165
|
+
| `4` | Conflict: an immutable field changed or an Idempotency-Key was reused. Nothing was applied. |
|
|
166
|
+
| `130` | Aborted at the confirmation prompt. |
|
|
167
|
+
|
|
168
|
+
## Troubleshooting
|
|
169
|
+
|
|
170
|
+
- **`No API key found`**: run `purpleturret login`, pass `--api-key`, or set `PURPLETURRET_API_KEY`. Check `purpleturret whoami` to see which source is in effect.
|
|
171
|
+
- **`stripe_not_connected`**: connect Stripe in Dashboard → Settings → Payments. Products cannot be created until then.
|
|
172
|
+
- **`immutable_field_changed`**: you changed currency, billing, slug, or the adopted Stripe price. Add a new `key` instead.
|
|
173
|
+
- **`insufficient_scope`**: the key lacks `config:write`. Mint a new key with the scope.
|
|
174
|
+
- **Config not found**: the search stops at the git root. Pass `--config <path>` from elsewhere.
|
|
175
|
+
|
|
176
|
+
## Working with an AI coding agent?
|
|
177
|
+
|
|
178
|
+
Install the Purpleturret skill so Claude Code, Codex, or Cursor knows these commands and their guardrails:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
curl -fsSL https://purpleturret.com/skills/purpleturret/SKILL.md \
|
|
182
|
+
--create-dirs -o .claude/skills/purpleturret/SKILL.md
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Details and other agents: https://purpleturret.com/docs/ai-skills
|
|
186
|
+
|
|
187
|
+
## Documentation
|
|
188
|
+
|
|
189
|
+
- **CLI and SDK guide** (full reference, this README in more depth): https://purpleturret.com/docs/cli
|
|
190
|
+
- **Developer docs** (apps, entitlements API, webhooks, signature verification): https://purpleturret.com/docs
|
|
191
|
+
- **AI skills** (agent skill, AGENTS.md snippet, example prompts): https://purpleturret.com/docs/ai-skills
|
|
192
|
+
- **OpenAPI 3.1** for every REST endpoint: https://api.purpleturret.com/v1/openapi.json
|
|
193
|
+
- **`@purpleturret/sdk`** (typed client for entitlements and credits): https://www.npmjs.com/package/@purpleturret/sdk
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Runs the built CLI (dist/cli.js). Inside the monorepo, before a build, falls back to loading the
|
|
3
|
+
// TypeScript sources through jiti so `pnpm pt …` works without a build step.
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const dist = new URL("../dist/cli.js", import.meta.url);
|
|
8
|
+
if (existsSync(fileURLToPath(dist))) {
|
|
9
|
+
await import(dist.href);
|
|
10
|
+
} else {
|
|
11
|
+
const { createJiti } = await import("jiti");
|
|
12
|
+
const jiti = createJiti(import.meta.url);
|
|
13
|
+
await jiti.import(new URL("../src/cli.ts", import.meta.url).href);
|
|
14
|
+
}
|