@basementuniverse/jsonpad-cli 1.0.0 → 1.3.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/CHANGELOG.md CHANGED
@@ -7,7 +7,83 @@ and this package adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  Dates are npm publish dates.
9
9
 
10
- ## [1.0.0] - Unreleased
10
+ ## [1.3.0] - 2026-09-16
11
+
12
+ ### Removed
13
+
14
+ - The `xmlhttprequest-ssl` dependency. `jsonpad listen` needed it only because
15
+ `@basementuniverse/jsonpad-realtime-sdk` couldn't connect from Node before
16
+ version 1.6.0.
17
+
18
+ ## [1.2.0] - 2026-09-16
19
+
20
+ ### Added
21
+
22
+ - `jsonpad lists`, with `list`, `get`, `create`, `update` and `delete`.
23
+ - `jsonpad indexes`, with `list`, `get`, `create`, `update`, `delete`,
24
+ `rebuild` (the same as `rebuild-index`) and `wait`. `create` and `update`
25
+ can `--wait` for the index to be built.
26
+ - `jsonpad items`, with `list` (filter by indexes with `--where`), `get`,
27
+ `create`, `update` and `delete`, and `jsonpad items data` with `get`, `set`,
28
+ `replace`, `patch` and `delete`, for an item's data or part of it.
29
+ - `jsonpad identities`, with `list`, `get`, `create`, `update` and `delete`.
30
+ Identities can be named by id or `group/name`. Passwords are asked for, or
31
+ read from stdin or `JSONPAD_IDENTITY_PASSWORD`, never taken as an option.
32
+ - Options that take JSON accept JSON, `@file`, or `-` for stdin.
33
+ - Deletes ask for confirmation in a terminal, and need `--yes` elsewhere.
34
+ - `--all` and `--max` for commands that list things, to fetch every page.
35
+ - `jsonpad lists search`.
36
+ - `stats`, `events` and `event` for lists, items, indexes and identities, and
37
+ `jsonpad items restore`.
38
+ - `jsonpad items export`, which outputs a list's items as NDJSON, and
39
+ `jsonpad items import`, which creates items from NDJSON or a JSON array.
40
+ Imports check every record first, keep to the plan's rate limits, and can
41
+ `--dry-run` or `--continue-on-error`.
42
+ - Identity mode: `jsonpad identities register`, `login` (with `-o env` to set
43
+ `JSONPAD_IDENTITY_TOKEN` and `JSONPAD_IDENTITY_GROUP`), `logout`, and
44
+ `identities self` with `get`, `update` and `delete`. While
45
+ `JSONPAD_IDENTITY_TOKEN` is set, commands that work with items act as the
46
+ identity, and `whoami` says which one. `--identity-group` sets the group.
47
+ - `jsonpad listen`, which prints realtime events from lists and items. It
48
+ connects to the production realtime server only.
49
+ - `jsonpad completion bash|zsh|fish`, for completing commands and options with
50
+ Tab.
51
+
52
+ ### Changed
53
+
54
+ - Retries after being rate limited are only mentioned on stderr when the wait
55
+ is 5 seconds or more, or with `--verbose`.
56
+ - Piping output to a command that stops reading early (e.g. `head`) no longer
57
+ prints an error.
58
+
59
+ ## [1.1.0] - 2026-09-16
60
+
61
+ ### Added
62
+
63
+ - Profiles: saved API tokens, so you don't need `JSONPAD_TOKEN` on your own
64
+ machine. `jsonpad config set-profile`, `use`, `list`, `remove` and `path`
65
+ manage them, in a config file only you can read. Choose one with
66
+ `--profile` or `JSONPAD_PROFILE`. `JSONPAD_CONFIG` sets the config file.
67
+ - `jsonpad whoami`, which shows the token you're using, its permissions, its
68
+ plan's limits and the account's usage this month.
69
+ - `--api-url`, which sets the API's URL for any command.
70
+ - `--verbose` (`-V`), which logs each request to stderr, and the rate limit and
71
+ quota left after the command.
72
+ - `--output` (`-o`), `--json` and `--quiet` (`-q`) for commands that output
73
+ records. The default is a table in a terminal, and JSON otherwise.
74
+ - Exit codes `5` (needs confirmation: run again with `--yes`), `6` (not
75
+ found), `7` (the token isn't allowed, or isn't valid) and `8` (rate limited,
76
+ or a plan limit or the quota was reached). The schema commands and
77
+ `rebuild-index` still exit with `1` for every API error.
78
+
79
+ ### Changed
80
+
81
+ - Rate limited requests are retried, up to 5 times, after the delay the API
82
+ asks for (at most a minute). This includes the schema commands, which used to
83
+ fail straight away. A request refused because the monthly quota has run out
84
+ isn't retried.
85
+
86
+ ## [1.0.0] - 2026-09-16
11
87
 
12
88
  The `jsonpad` command, moved out of `@basementuniverse/jsonpad-sdk` (where
13
89
  it's deprecated) into its own package.
package/README.md CHANGED
@@ -2,8 +2,12 @@
2
2
 
3
3
  The `jsonpad` command line tool for [JSONPad](https://jsonpad.io).
4
4
 
5
- It syncs schema documents (lists and their indexes) with your account, for
6
- example in a deploy script or CI.
5
+ Use it to manage lists, indexes, items and identities from the command line,
6
+ and to sync schema documents (lists and their indexes) with your account, e.g.
7
+ in a deploy script or CI.
8
+
9
+ There's a guide to it in the JSONPad docs:
10
+ [Command line tool](https://jsonpad.io/docs/command-line-tool).
7
11
 
8
12
  ## Install
9
13
 
@@ -22,20 +26,180 @@ npm install --save-dev @basementuniverse/jsonpad-cli
22
26
 
23
27
  ## Authentication
24
28
 
25
- The tool reads an API token from the `JSONPAD_TOKEN` environment variable.
26
- Create a token in the JSONPad dashboard.
29
+ Every command needs an API token, which you can create in the JSONPad
30
+ dashboard. For schema commands, the token needs the `sync-schema` permission,
31
+ plus permission for each change a sync makes.
32
+
33
+ In CI and scripts, set the `JSONPAD_TOKEN` environment variable:
27
34
 
28
35
  ```bash
29
36
  export JSONPAD_TOKEN=<your token>
30
37
  ```
31
38
 
32
- For schema commands, the token needs the `sync-schema` permission, plus
33
- permission for each change a sync makes.
39
+ On your own machine, save tokens as profiles instead. The token is asked for
40
+ without being shown, or read from stdin:
41
+
42
+ ```bash
43
+ jsonpad config set-profile prod
44
+ jsonpad config set-profile local --api-url http://localhost:3000
45
+
46
+ # Check which token you're using, what it can do, and how much quota is left
47
+ jsonpad whoami
48
+ jsonpad whoami --profile local
49
+ ```
50
+
51
+ The first profile you add is the default. Profiles are saved in a config file
52
+ that only you can read (`jsonpad config path` shows where; set
53
+ `JSONPAD_CONFIG` to use a different file).
54
+
55
+ ```bash
56
+ jsonpad config list # tokens are masked
57
+ jsonpad config use local # change the default profile
58
+ jsonpad config remove local
59
+ ```
34
60
 
35
- Set `JSONPAD_API_URL` to use a different API, e.g. a local server.
61
+ Which token a command uses, in order:
62
+
63
+ 1. a profile chosen with `--profile` or `JSONPAD_PROFILE`
64
+ 2. `JSONPAD_TOKEN`
65
+ 3. the default profile
66
+
67
+ The API URL comes from `--api-url`, then the profile's URL, then
68
+ `JSONPAD_API_URL`, then `https://api.jsonpad.io`.
36
69
 
37
70
  ## Usage
38
71
 
72
+ ### Lists, indexes, items and identities
73
+
74
+ ```bash
75
+ # Lists
76
+ jsonpad lists
77
+ jsonpad lists create --name Recipes --path-name recipes --indexable
78
+ jsonpad lists get recipes
79
+ jsonpad lists update recipes --pinned --tags cookbook,public
80
+ jsonpad lists delete recipes
81
+
82
+ # Indexes, waiting for a new index to be built
83
+ jsonpad indexes recipes
84
+ jsonpad indexes create recipes --path-name title --pointer /title --alias --filtering --wait
85
+ jsonpad indexes wait recipes title
86
+
87
+ # Items: filter by an index with --where, and fetch an item by its alias
88
+ jsonpad items create recipes --data '{"title": "pancakes", "servings": 4}'
89
+ jsonpad items create recipes --data @waffles.json
90
+ jsonpad items recipes --where title=pancakes --order title
91
+ jsonpad items get recipes pancakes
92
+
93
+ # An item's data, or part of it by JSON pointer
94
+ jsonpad items data get recipes pancakes /ingredients
95
+ jsonpad items data set recipes pancakes --data '{"servings": 6}'
96
+ jsonpad items data replace recipes pancakes /ingredients --data '["flour", "eggs"]'
97
+ jsonpad items data patch recipes pancakes --patch @changes.json
98
+ jsonpad items data delete recipes pancakes /ingredients/0
99
+
100
+ # Identities, by id or group/name. Passwords are asked for, or read from stdin
101
+ jsonpad identities create --group staff --name ada
102
+ jsonpad identities get staff/ada
103
+ jsonpad identities update staff/ada --display-name Ada --password
104
+ ```
105
+
106
+ Lists and indexes can be named by id or path name, and items by id or alias.
107
+ Options that take JSON (`--data`, `--schema`, `--patch`) accept JSON, `@file`,
108
+ or `-` to read from stdin. `--data` gives a list or index as a whole object,
109
+ and other options take precedence over it; for an item, `--data` is the item's
110
+ data.
111
+
112
+ Most commands have a short form: `jsonpad lists` is `jsonpad lists list`, and
113
+ `ls` and `rm` work in place of `list` and `delete`. Commands that list things
114
+ fetch one page, with `--page`, `--limit` (up to 100), `--order` and
115
+ `--direction`, or every page with `--all` (output as NDJSON, one record per
116
+ line, unless `--output` says otherwise). `--max` stops `--all` early.
117
+
118
+ ```bash
119
+ # Every item's id, e.g. to pipe to xargs
120
+ jsonpad items recipes --all -q
121
+ ```
122
+
123
+ ### Search, stats and history
124
+
125
+ ```bash
126
+ jsonpad lists search recipes pancake --include-items
127
+
128
+ # Counts by day: items, indexes and events
129
+ jsonpad lists stats recipes --days 30
130
+
131
+ # Lists, items, indexes and identities all have stats, events and event
132
+ jsonpad items events recipes pancakes --type item-updated --start-at 2026-09-01
133
+ jsonpad items event recipes pancakes <event> --include-snapshot
134
+
135
+ # Put an item back how it was after an event (or re-create a deleted item)
136
+ jsonpad items events recipes pancakes --restorable
137
+ jsonpad items restore recipes pancakes <event>
138
+ ```
139
+
140
+ ### Exporting and importing items
141
+
142
+ ```bash
143
+ # Every item in a list as NDJSON, oldest first
144
+ jsonpad items export recipes --out recipes.ndjson
145
+
146
+ # Create the items again, e.g. in another list or account
147
+ jsonpad items import recipes-copy recipes.ndjson --dry-run
148
+ jsonpad items import recipes-copy recipes.ndjson
149
+
150
+ # Just the data, from one list into another
151
+ jsonpad items export recipes --data-only | jsonpad items import archive - --data-only
152
+ ```
153
+
154
+ `import` reads NDJSON (one record per line) or a JSON array. Each record is an
155
+ item as `export` outputs it (its `data`, `description`, `tags` and `readonly`
156
+ are imported; ids and dates aren't), or with `--data-only`, an item's data.
157
+
158
+ Every record is checked before anything is created. Items are created one at a
159
+ time, at the pace the account's plan allows, so a large import can take a
160
+ while: on a plan with 60 requests a minute, about a second per item. The
161
+ import warns if it's bigger than the requests left this month.
162
+
163
+ If an item can't be created, the import stops and says how to import the rest.
164
+ With `--continue-on-error`, it carries on and lists the failures at the end.
165
+
166
+ ### Acting as an identity
167
+
168
+ Apps built on JSONPad often log users in as identities, and items can belong to
169
+ the identity that created them. To see what an identity sees, log in as one:
170
+
171
+ ```bash
172
+ jsonpad identities register --group players --name zed
173
+ eval "$(jsonpad identities login --group players --name zed -o env)"
174
+
175
+ # Items commands now act as players/zed
176
+ jsonpad items create scores --data '{"score": 42}'
177
+ jsonpad whoami # shows the identity too
178
+ jsonpad identities self update --display-name Zed
179
+ jsonpad identities logout
180
+ ```
181
+
182
+ `login -o env` sets `JSONPAD_IDENTITY_TOKEN` (and `JSONPAD_IDENTITY_GROUP`).
183
+ While it's set, commands that work with items send the identity along with
184
+ the API token. Passwords are asked for in a terminal, or read from stdin or
185
+ `JSONPAD_IDENTITY_PASSWORD`.
186
+
187
+ ### Realtime events
188
+
189
+ ```bash
190
+ # Print events from lists with realtime turned on, until Ctrl+C
191
+ jsonpad listen recipes
192
+ jsonpad listen recipes --events item-created,item-deleted -o ndjson
193
+ jsonpad listen --items pancakes --count 1
194
+ ```
195
+
196
+ `listen` connects to JSONPad's realtime server, so it only works with the
197
+ production API, not with `--api-url` or a profile for another API. Each plan
198
+ limits how many realtime connections an account can hold at once; a refused
199
+ connection is retried by itself.
200
+
201
+ ### Schema sync
202
+
39
203
  ```bash
40
204
  # See what a sync would change, then apply it
41
205
  jsonpad sync-schema --dry-run
@@ -56,14 +220,73 @@ jsonpad move-lists --from-scope recipe-app --to cookbook-app
56
220
 
57
221
  # Rebuild an index whose last build failed
58
222
  jsonpad rebuild-index recipes title --wait
223
+
224
+ # Show the token, its plan's limits and this month's usage
225
+ jsonpad whoami
59
226
  ```
60
227
 
61
228
  The schema commands are also available as `jsonpad schema sync`,
62
- `jsonpad schema export` and `jsonpad schema move`.
229
+ `jsonpad schema export` and `jsonpad schema move`, and `rebuild-index` as
230
+ `jsonpad indexes rebuild`.
63
231
 
64
232
  Run `jsonpad --help`, or `jsonpad <command> --help`, for every option. The full
65
233
  command reference is in [REFERENCE.md](REFERENCE.md).
66
234
 
235
+ ### Output
236
+
237
+ Commands that output records print a table in a terminal, and JSON when their
238
+ output is piped or redirected, so `jsonpad lists get recipes | jq .itemCount`
239
+ works. Choose a format with `--output` (`-o`):
240
+
241
+ | Format | Output |
242
+ | -------- | -------------------------------------------------------- |
243
+ | `table` | Columns, for reading |
244
+ | `json` | JSON (also `--json`) |
245
+ | `ndjson` | One JSON record per line |
246
+ | `id` | One id per line, e.g. for `xargs` (also `--quiet`, `-q`) |
247
+
248
+ `jsonpad items data get` always outputs the data itself, as JSON (or NDJSON
249
+ with `-o ndjson`).
250
+
251
+ Data goes to stdout. Messages, warnings and questions go to stderr.
252
+
253
+ The schema commands keep their own output, and their `--json` option.
254
+
255
+ ### Confirmations
256
+
257
+ Commands that delete something ask first. Where they can't ask (e.g. in a
258
+ script or CI), they refuse with exit code `5` unless you pass `--yes`.
259
+
260
+ ### Rate limits
261
+
262
+ A request that's rate limited is retried after the delay the API asks for, up
263
+ to 5 times, which is mentioned on stderr if the wait is 5 seconds or more. A
264
+ request refused because the monthly quota has run out isn't retried.
265
+
266
+ `--verbose` (`-V`) logs each request to stderr, and afterwards, the rate limit
267
+ and quota left:
268
+
269
+ ```bash
270
+ jsonpad whoami --verbose
271
+ ```
272
+
273
+ ### Shell completion
274
+
275
+ ```bash
276
+ # bash: add to ~/.bashrc
277
+ eval "$(jsonpad completion bash)"
278
+
279
+ # zsh: add to ~/.zshrc, after compinit
280
+ eval "$(jsonpad completion zsh)"
281
+
282
+ # fish
283
+ jsonpad completion fish > ~/.config/fish/completions/jsonpad.fish
284
+ ```
285
+
286
+ Commands, options and their choices are completed. Lists, items and other
287
+ names from your account aren't, since that would make a request every time you
288
+ press Tab.
289
+
67
290
  ## Continuous integration
68
291
 
69
292
  ```yaml
@@ -75,21 +298,28 @@ command reference is in [REFERENCE.md](REFERENCE.md).
75
298
 
76
299
  ## Exit codes
77
300
 
78
- | Code | Meaning |
79
- | ---- | -------------------------------------------------------------- |
80
- | `0` | Success |
81
- | `1` | Error, including a sync refused because a change has errors |
82
- | `2` | A sync was refused because it needs `--allow-rebuild` |
83
- | `3` | An index build failed, or didn't finish in time, while waiting |
84
- | `4` | A sync was refused because it needs `--allow-destructive` |
301
+ | Code | Meaning |
302
+ | ---- | ----------------------------------------------------------------------- |
303
+ | `0` | Success |
304
+ | `1` | Error, including a sync refused because a change has errors |
305
+ | `2` | A sync was refused because it needs `--allow-rebuild` |
306
+ | `3` | An index build failed, or didn't finish in time, while waiting |
307
+ | `4` | A sync was refused because it needs `--allow-destructive` |
308
+ | `5` | Refused because it needs confirmation: run again with `--yes` |
309
+ | `6` | Not found |
310
+ | `7` | The token isn't allowed to do this, or isn't valid |
311
+ | `8` | Rate limited (after retrying), or a plan limit or the quota was reached |
85
312
 
86
313
  A dry run exits the same way the real sync would.
87
314
 
315
+ The schema commands (`sync-schema`, `export-schema`, `move-lists`) and
316
+ `rebuild-index` exit with `1` for every API error, as they did in the SDK.
317
+
88
318
  ## Moving from the SDK's `jsonpad` command
89
319
 
90
- Versions 1.12 and 1.13 of `@basementuniverse/jsonpad-sdk` include a `jsonpad`
91
- command. It's deprecated, and it will be removed in SDK 2.0.0. This package has
92
- the same commands, options, output and exit codes, so to switch, replace
320
+ Versions 1.12 to 1.14 of `@basementuniverse/jsonpad-sdk` included a `jsonpad`
321
+ command, which was removed in SDK 2.0.0. This package has the same commands,
322
+ options, output and exit codes, so to switch, replace
93
323
  `npx @basementuniverse/jsonpad-sdk` with `npx @basementuniverse/jsonpad-cli`.
94
324
 
95
325
  If you installed the SDK globally to get the command, uninstall it first.
@@ -112,15 +342,10 @@ npm run reference # regenerates REFERENCE.md after changing a command
112
342
  `npm test` fails when `REFERENCE.md` is out of date.
113
343
 
114
344
  The parity tests check that the commands ported from the SDK behave exactly as
115
- the SDK's `bin/jsonpad.js` does. They run each scenario against a fake API and
116
- compare the output, exit code, requests and files against golden files in
117
- `test/parity/golden`. Those files were recorded from the SDK's command with:
118
-
119
- ```bash
120
- npm run record-parity -- ../jsonpad-sdk-js/bin/jsonpad.js
121
- ```
122
-
123
- Only re-record them to add scenarios while the SDK still has its command.
345
+ the SDK's command did. They run each scenario against a fake API and compare
346
+ the output, exit code, requests and files against golden files in
347
+ `test/parity/golden`, which were recorded from the SDK's command before it was
348
+ removed.
124
349
 
125
350
  ### Publishing
126
351