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