sellwavy-cli 0.0.0-stage → 0.1.1

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
@@ -1,3 +1,66 @@
1
- # Temporary Holding Version
1
+ # Sellwavy CLI
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Run your Sellwavy store from the terminal, or let an AI agent (Claude Code, Cursor, Codex, Windsurf) build and manage it for you.
4
+
5
+ ```sh
6
+ npm install -g sellwavy-cli
7
+ sellwavy login # approve this computer in your browser
8
+ sellwavy init # link a folder to a store, pull its pages, write AGENTS.md
9
+ ```
10
+
11
+ Without installing: `npx sellwavy-cli <command>` works the same.
12
+
13
+ ## Connect an AI agent
14
+
15
+ **Claude Code**, as an MCP server:
16
+
17
+ ```sh
18
+ claude mcp add sellwavy -- npx -y sellwavy-cli mcp
19
+ ```
20
+
21
+ Other agents: add an MCP server with command `npx` and args `["-y", "sellwavy-cli", "mcp"]`.
22
+
23
+ Or skip MCP: run `sellwavy init` in a folder and open it in your agent. It reads `AGENTS.md` and uses the CLI.
24
+
25
+ Whatever an agent changes is the same as a change made in the dashboard. Pages it writes open in the visual editor, where you can still click any text, photo or video to change it. Files it uploads show up in your media library.
26
+
27
+ ## Pages as files
28
+
29
+ ```
30
+ site/header.html shared header
31
+ site/footer.html shared footer
32
+ site/home/01-hero.html home page sections, in order
33
+ site/products/… all products page
34
+ site/product/… product page
35
+ site/about/… site/contact/…
36
+ ```
37
+
38
+ Each file is one section, written in HTML with Tailwind classes. `data-sw-*` hooks fill in live products, the cart and the logo; `AGENTS.md` lists them all.
39
+
40
+ ```sh
41
+ sellwavy site pull # download
42
+ sellwavy site push --dry-run # see what would change
43
+ sellwavy site push # save it live
44
+ sellwavy site watch # push on every save
45
+ ```
46
+
47
+ If someone edits the store in the visual editor while you work, `push` merges their changes with yours section by section. If the same section changed in both places, the push stops and names the file.
48
+
49
+ ## Everything else
50
+
51
+ ```sh
52
+ sellwavy products list | get | create | update | delete | import <file.json|csv>
53
+ sellwavy orders list | get <id> | ship <id> --tracking "DHL 123" | mark-paid <id>
54
+ sellwavy media upload hero.mp4 photo.jpg
55
+ sellwavy theme get | set primaryColor=#111111
56
+ sellwavy ai "make the hero darker"
57
+ sellwavy api GET /discounts # any store API route
58
+ ```
59
+
60
+ Every command takes `--json` and `--store <subdomain>`.
61
+
62
+ ## Keys
63
+
64
+ `sellwavy login` creates a key on your computer. Only its hash is sent through the browser to be approved. Manage and revoke keys in **Account → CLI & AI agents**, where you can also create a key for CI or a server. Pass it as `SELLWAVY_TOKEN` or with `sellwavy login --token`.
65
+
66
+ Needs Node.js 18.17 or newer.
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env node
2
+ import { VERSION } from '../lib/version.mjs'
3
+ import { ApiError, createApi } from '../lib/api.mjs'
4
+ import { CliError, c, log } from '../lib/ui.mjs'
5
+ import { readProject, resolveHost, resolveToken } from '../lib/config.mjs'
6
+ import { resolveStore } from '../lib/core.mjs'
7
+ import * as cmd from '../lib/commands.mjs'
8
+
9
+ const HELP = `${c.bold('sellwavy')} ${c.dim(VERSION)}: your Sellwavy store from the terminal, for you and for AI agents.
10
+
11
+ ${c.bold('Get started')}
12
+ login Connect this computer (approve it in your browser)
13
+ init [store] Link this folder to a store, pull its pages, write AGENTS.md
14
+ mcp Run as an MCP server for Claude Code, Cursor, Codex…
15
+
16
+ ${c.bold('Pages')} ${c.dim('(HTML + Tailwind files in site/, the same pages the visual editor edits)')}
17
+ site pull Download the store's pages into site/
18
+ site push [--dry-run] Save site/ to the live store
19
+ site status What changed here and on the store since the last pull
20
+ site watch Push on every save
21
+ ai "<request>" [--page p] Ask Sellwavy AI to change a page
22
+
23
+ ${c.bold('Store')}
24
+ products list|get|create|update|delete|import
25
+ orders list|get|ship|mark-paid
26
+ media list|upload <files…>
27
+ theme get|set key=value…
28
+ api [METHOD] <path> [-d json] Any store API route
29
+
30
+ ${c.bold('Account')}
31
+ stores · link [store] · open [store|editor|admin] · whoami · logout · agents
32
+
33
+ ${c.bold('Flags')}
34
+ --store <subdomain> Work on this store --json Machine-readable output
35
+ --host <url> Sellwavy server (default https://sellwavy.com, or SELLWAVY_HOST)
36
+
37
+ Run ${c.bold('sellwavy <command> --help')} for details. Keys: SELLWAVY_TOKEN works in place of login.`
38
+
39
+ const HELPS = {
40
+ login: `sellwavy login [--no-browser] [--no-wait] [--name "MacBook"]
41
+ Opens Sellwavy in your browser to approve this computer: type the code it shows there.
42
+ sellwavy login --token <key>
43
+ Uses a key made in Account > CLI & AI agents (for servers and CI).`,
44
+ init: `sellwavy init [store]
45
+ Links this folder to a store (asks which if you have several), pulls its pages
46
+ into site/, and writes AGENTS.md + CLAUDE.md so AI agents know how to work on it.`,
47
+ site: `sellwavy site pull [--dir site] [--force]
48
+ Downloads the pages: site/header.html, site/footer.html, site/<page>/NN-<key>.html.
49
+ Unpushed local changes are kept; --force replaces them with the store's.
50
+ sellwavy site push [--dry-run] [--force] [--keep-off]
51
+ Saves site/ live. Changes made on the store since your pull are merged in;
52
+ a section changed on both sides stops the push (--force keeps yours).
53
+ Switches the store's AI-built pages on unless --keep-off.
54
+ sellwavy site status What changed here and on the store.
55
+ sellwavy site watch Pushes on every save.
56
+ Pages: home, products, product, about, contact. See AGENTS.md for the hooks.`,
57
+ ai: `sellwavy ai "<request>" [--page home|products|product|about|contact] [--dry-run]
58
+ Sellwavy AI rewrites the page and saves it. --dry-run shows what it would do.`,
59
+ products: `sellwavy products list [--json]
60
+ sellwavy products get <id|slug>
61
+ sellwavy products create --title "Tee" --price 25 [--description ...] [--inventory 10]
62
+ [--category Shirts] [--status active|draft] [--image ./a.jpg ...]
63
+ sellwavy products update <id|slug> [--price 30] [--inventory 5] [--image ...] ...
64
+ sellwavy products delete <id|slug> [--yes]
65
+ sellwavy products import <file.json|file.csv>
66
+ Prices are in the store's currency (19.99). Images can be files or URLs.`,
67
+ orders: `sellwavy orders list [--status PENDING|PAID|CANCELLED|REFUNDED] [--json]
68
+ sellwavy orders get <id>
69
+ sellwavy orders ship <id> [--tracking "DHL 1234"] Emails the customer once.
70
+ sellwavy orders mark-paid <id>`,
71
+ media: `sellwavy media list [--json]
72
+ sellwavy media upload <files or URLs…>
73
+ Photos (jpg png webp gif avif svg) and videos (mp4 webm mov). They show up in
74
+ the media library and the visual editor; the address printed goes in <img>/<video>.`,
75
+ theme: `sellwavy theme get [--all] [--json]
76
+ sellwavy theme set primaryColor=#111111 font=sans darkMode=true ...`,
77
+ api: `sellwavy api [METHOD] <path> [-d '{"json":1}' | -d @file.json]
78
+ Paths are relative to /api/stores/<store> unless they start with /api/.
79
+ e.g. sellwavy api /discounts · sellwavy api POST /categories -d '{"name":"Hats"}'`,
80
+ mcp: `sellwavy mcp [--store <subdomain>]
81
+ Serves the store as MCP tools on stdio. Add it to Claude Code:
82
+ claude mcp add sellwavy -- npx -y sellwavy-cli mcp
83
+ Other agents: command "npx", args ["-y", "sellwavy-cli", "mcp"].`,
84
+ }
85
+
86
+ const BOOLEAN = new Set(['json', 'force', 'yes', 'dry-run', 'no-browser', 'no-wait', 'help', 'version', 'keep-off', 'no-guide', 'all'])
87
+ const SHORT = { h: 'help', v: 'version', y: 'yes', X: 'method', d: 'data', s: 'store' }
88
+
89
+ function parseArgs(argv) {
90
+ const args = []
91
+ const flags = {}
92
+ const set = (k, v) => { flags[k] = k in flags ? [].concat(flags[k], v) : v }
93
+ for (let i = 0; i < argv.length; i++) {
94
+ const a = argv[i]
95
+ if (a === '--') { args.push(...argv.slice(i + 1)); break }
96
+ const long = a.match(/^--([^=]+)(?:=([\s\S]*))?$/)
97
+ const short = a.match(/^-([A-Za-z])$/)
98
+ if (long || short) {
99
+ const key = long ? long[1] : SHORT[short[1]] || short[1]
100
+ if (long && long[2] !== undefined) set(key, long[2])
101
+ else if (BOOLEAN.has(key)) set(key, true)
102
+ else {
103
+ const v = argv[i + 1]
104
+ if (v === undefined) throw new CliError(`--${key} needs a value.`)
105
+ set(key, v)
106
+ i++
107
+ }
108
+ } else {
109
+ args.push(a)
110
+ }
111
+ }
112
+ return { args, flags }
113
+ }
114
+
115
+ /** Commands with sub-commands: `sellwavy products list`. */
116
+ const GROUPS = {
117
+ site: { pull: cmd.sitePull, push: cmd.sitePush, status: cmd.siteStatus, watch: cmd.siteWatch },
118
+ products: { list: cmd.productsList, get: cmd.productsGet, create: cmd.productsCreate, add: cmd.productsCreate, update: cmd.productsUpdate, delete: cmd.productsDelete, import: cmd.productsImport },
119
+ orders: { list: cmd.ordersList, get: cmd.ordersGet, ship: cmd.ordersShip, 'mark-paid': cmd.ordersMarkPaid },
120
+ media: { list: cmd.mediaList, upload: cmd.mediaUpload },
121
+ theme: { get: cmd.themeGet, set: cmd.themeSet },
122
+ }
123
+
124
+ const SINGLE = {
125
+ login: cmd.login, logout: cmd.logout, whoami: cmd.whoami, stores: cmd.stores, link: cmd.link,
126
+ open: cmd.open, init: cmd.init, agents: cmd.agents, ai: cmd.ai, api: cmd.apiCall, mcp: cmd.mcp,
127
+ }
128
+
129
+ async function main() {
130
+ const [name, ...rest] = process.argv.slice(2)
131
+ if (!name || name === 'help' || name === '--help' || name === '-h') return log(HELP)
132
+ if (name === '--version' || name === '-v' || name === 'version') return log(VERSION)
133
+
134
+ let run = SINGLE[name]
135
+ let argv = rest
136
+ if (!run && GROUPS[name]) {
137
+ const sub = rest[0] && !rest[0].startsWith('-') ? rest[0] : null
138
+ run = sub ? GROUPS[name][sub] : null
139
+ argv = sub ? rest.slice(1) : rest
140
+ if (!run) {
141
+ if (!sub || sub === 'help' || rest.includes('--help')) return log(HELPS[name] ?? HELP)
142
+ throw new CliError(`Unknown command "${name} ${sub}". Try: sellwavy ${name} --help`)
143
+ }
144
+ }
145
+ if (!run) throw new CliError(`Unknown command "${name}". Try: sellwavy --help`)
146
+
147
+ const { args, flags } = parseArgs(argv)
148
+ if (flags.help) return log(HELPS[name] ?? HELP)
149
+
150
+ const host = resolveHost(flags)
151
+ const project = readProject()
152
+ const ctx = {
153
+ args,
154
+ flags,
155
+ host,
156
+ project,
157
+ api() {
158
+ const token = resolveToken()
159
+ if (!token) throw new CliError('Not signed in. Run: sellwavy login')
160
+ return createApi({ host, token })
161
+ },
162
+ async store() {
163
+ return resolveStore(this.api(), { wanted: flags.store, project: this.project })
164
+ },
165
+ }
166
+ await run(ctx)
167
+ }
168
+
169
+ main().catch(err => {
170
+ if (err instanceof CliError || err instanceof ApiError) {
171
+ console.error(`${c.red('✗')} ${err.message}`)
172
+ } else {
173
+ console.error(err)
174
+ }
175
+ // exitCode, not exit(): exiting while a network request's socket is still
176
+ // closing trips a libuv assertion on Windows.
177
+ process.exitCode = 1
178
+ })
package/lib/api.mjs ADDED
@@ -0,0 +1,67 @@
1
+ import { VERSION } from './version.mjs'
2
+
3
+ /**
4
+ * Talks to a Sellwavy server's API with the owner's key.
5
+ *
6
+ * The CLI uses the same routes as the dashboard, so it goes through the same
7
+ * ownership checks, cleaning and plan limits. Errors come back as ApiError
8
+ * carrying the server's own message ("Title and price are required").
9
+ */
10
+
11
+ export class ApiError extends Error {
12
+ constructor(status, message, body) {
13
+ super(message)
14
+ this.status = status
15
+ this.body = body
16
+ }
17
+ }
18
+
19
+ export function createApi({ host, token }) {
20
+ async function request(method, path, body) {
21
+ const url = /^https?:\/\//.test(path) ? path : `${host}${path}`
22
+ const headers = { 'User-Agent': `sellwavy-cli/${VERSION}`, Accept: 'application/json' }
23
+ if (token) headers.Authorization = `Bearer ${token}`
24
+ let payload
25
+ if (body !== undefined) {
26
+ headers['Content-Type'] = 'application/json'
27
+ payload = JSON.stringify(body)
28
+ }
29
+
30
+ let res
31
+ try {
32
+ res = await fetch(url, { method, headers, body: payload })
33
+ } catch (err) {
34
+ const why = err?.cause?.code || err?.cause?.message || err?.message || 'network error'
35
+ throw new ApiError(0, `Could not reach ${host} (${why}).`)
36
+ }
37
+
38
+ const text = await res.text()
39
+ let data = null
40
+ try {
41
+ data = text ? JSON.parse(text) : null
42
+ } catch {
43
+ data = text
44
+ }
45
+
46
+ if (!res.ok) {
47
+ const serverMsg = data && typeof data === 'object' && typeof data.error === 'string' ? data.error : null
48
+ const msg =
49
+ res.status === 401
50
+ ? 'Not signed in, or this key was revoked. Run: sellwavy login'
51
+ : serverMsg || `${method} ${path} failed (HTTP ${res.status}).`
52
+ throw new ApiError(res.status, msg, data)
53
+ }
54
+ return data
55
+ }
56
+
57
+ return {
58
+ host,
59
+ token,
60
+ request,
61
+ get: path => request('GET', path),
62
+ post: (path, body) => request('POST', path, body ?? {}),
63
+ patch: (path, body) => request('PATCH', path, body ?? {}),
64
+ put: (path, body) => request('PUT', path, body ?? {}),
65
+ del: path => request('DELETE', path),
66
+ }
67
+ }