@whatcha/cli 0.3.0 → 0.6.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 CHANGED
@@ -173,12 +173,42 @@ diary on your personal shelf cannot be published. `--json` prints
173
173
  `diaryId`, `groupId`, `groupName`, `isPublic`, `url` (`null` with `--off`)
174
174
  and `openedToGroup`.
175
175
 
176
+ ### `whatcha diary-cover`
177
+
178
+ ```
179
+ whatcha diary-cover <diary> <file> | --clear [--json]
180
+ ```
181
+
182
+ Sets the picture a diary's page and its share card show (#52), the same
183
+ one the app's cover frame sets: the file (JPEG, PNG, WebP, GIF or AVIF, at
184
+ most 40 MB) is uploaded into the diary's group and saved as the diary's
185
+ cover with `PATCH /diaries/{id}`. `--clear` removes it. Anyone who may edit
186
+ the diary's settings may do this. `--json` prints `diaryId` and
187
+ `coverMediaAssetId` (`null` after `--clear`).
188
+
176
189
  ### `whatcha write`
177
190
 
178
191
  ```
179
- whatcha write <diary> --text "..." [--title "..."] [--tag <tag>]... [--time HH:MM] [--date YYYY-MM-DD] [--json]
192
+ whatcha write <diary> (--text "..." | --text-file <path|->) [--title "..."] [--tag <tag>]...
193
+ [--image <file>]... [--cover <file>] [--mood <mood>] [--location "..."]
194
+ [--lat <deg> --lng <deg>] [--time HH:MM [--end HH:MM]] [--date YYYY-MM-DD] [--json]
180
195
  ```
181
196
 
197
+ `--text-file <path>` (#54) reads the text from a file, or from standard
198
+ input with `-`. Use it for anything longer than a line: on Windows the npm
199
+ command (`whatcha.cmd`) runs through `cmd.exe`, which ends `--text` at its
200
+ first line break and drops every flag after it. The file is read as UTF-8;
201
+ a byte-order mark is dropped and CRLF becomes LF.
202
+
203
+ `--image <file>` (repeat it for several) and `--cover <file>` (#51) add
204
+ pictures: each file is checked first (JPEG, PNG, WebP, GIF or AVIF, at most
205
+ 40 MB), then uploaded into the diary's group. Images go after the ones the
206
+ entry already has -- its own are kept. `--cover` follows the `--title`
207
+ rule: it only fills an entry that has no cover (an existing one is kept,
208
+ reported as `coverKept: true`). With pictures, the text may be left out to
209
+ add them to the day's entry without writing anything. `--json` adds
210
+ `images` (the new ids) and `coverKept`.
211
+
182
212
  `--title` and `--tag` (#1665) set the same `content.title` / `content.tags`
183
213
  the app does, under the same rule as the text -- nothing somebody else
184
214
  wrote is removed: `--title` only fills an entry that has no title yet (an
@@ -186,6 +216,29 @@ existing one is kept, reported as `titleKept: true` and a note on stderr),
186
216
  and `--tag` (repeat it for several) only adds to the entry's tags --
187
217
  trimmed, exact duplicates dropped, at most 32 in all, 64 characters each.
188
218
 
219
+ `--mood`, `--location`, `--lat`/`--lng` and `--end` (#57) fill the rest of
220
+ the entry's header, the fields the app's entry screen shows:
221
+
222
+ - `--mood <mood>` -- the app offers 😊 🥰 😆 😌 😐 😢 😠 😴; any other text
223
+ of at most 64 characters is a custom mood, as in the app.
224
+ - `--location "<place>"` -- the place's name, at most 200 characters.
225
+ - `--lat <deg> --lng <deg>` -- the point on the map (#1520), in decimal
226
+ degrees (-90..90, -180..180), always both. A negative value may follow
227
+ the flag as it is (`--lng -122.42`).
228
+ - `--end HH:MM` -- with `--time` as its start, the entry's time range
229
+ (24h, later than `--time` on the same day). `--end` needs `--time`;
230
+ `--time` alone still only sets when the entry happened, as before.
231
+ `content` on `/entries` has no field for a range, so it is saved with the
232
+ app calendar's own call, `PATCH /diaries/{diaryId}/entries/{entryId}`
233
+ (a details-only commit: the text, header and images are carried over).
234
+
235
+ On a day that already has an entry, each follows the `--title` rule: it
236
+ fills a field the entry does not have yet and never replaces one somebody
237
+ set. What was kept is reported as `moodKept`, `locationKept`,
238
+ `coordinatesKept` and `rangeKept` (plus a note on stderr) and `--json`
239
+ prints the range the entry ends up with as `start`/`end`. An existing range
240
+ is saved again after the append, which would otherwise clear it.
241
+
189
242
  `<diary>` is a diary id or its exact name (case-insensitive; an ambiguous
190
243
  name lists the matches and asks for the id instead). `--date`/`--time`
191
244
  default to today/now in **the diary's own timezone**, not the machine's --
@@ -217,12 +270,62 @@ never sends a body it has not just read:
217
270
  whatcha read <diary> [--date YYYY-MM-DD] [--json]
218
271
  ```
219
272
 
220
- Defaults to today (diary timezone). Prints title/tags/body; a locked (Time
273
+ Defaults to today (diary timezone). Prints title/tags/body and how many
274
+ images the entry has (`--json`: `images`, their ids, and `coverMediaAssetId`); a locked (Time
221
275
  Capsule) entry is reported as locked, never shown early. `GET /entries` has
222
276
  no `?date=` filter, so this pages through the diary's entries
223
277
  newest-first (`src/lib/entry-find.ts`) until it finds that day or passes it
224
278
  -- exact, not fuzzy, but not O(1) for a very old date on a very active diary.
225
279
 
280
+ ### `whatcha entry update` / `whatcha entry delete`
281
+
282
+ ```
283
+ whatcha entry update <entry-id> [--text "..." | --text-file <path|->] [--mine | --all] [--title "..."] [--tag <tag>]...
284
+ [--image <file>]... [--remove-image <media-id>]... [--cover <file>] [--mood <mood>]
285
+ [--location "..."] [--lat <deg> --lng <deg>] [--message "..."] [--json]
286
+ whatcha entry delete <entry-id> [--yes] [--all] [--json]
287
+ ```
288
+
289
+ Change or take back an entry that is already there (#117), by its id --
290
+ `whatcha write` prints it as `entryId`, and so does `whatcha read --json`.
291
+ Both use the app's own calls: `PATCH /entries/{id}` (a new version on top of
292
+ the one just read, so a save that lands in between is refused, never
293
+ overwritten -- run the command again) and `DELETE /entries/{id}`. Who may do
294
+ either is the diary's call; a refusal is the API's own error. Neither needs
295
+ a terminal, so both run from a server or a scheduled job.
296
+
297
+ `update` changes only what you give it; everything else the entry has is
298
+ saved again as it was, including its time range:
299
+
300
+ - `--text` / `--text-file <path|->` -- the new text, read the way `write`
301
+ reads it (a file, or standard input for `-`; BOM dropped, CRLF to LF).
302
+ If somebody else wrote any of the entry's text, replacing all of it
303
+ needs a choice: **`--mine`** replaces only the lines you wrote -- your
304
+ part, from your first line to your last, as the app's blame shows it --
305
+ and leaves everyone else's exactly where it was; `--all` replaces the
306
+ whole text, theirs included. With `--mine`, an empty text removes your
307
+ part. `--mine` refuses when your lines and somebody else's are mixed
308
+ together; edit those in the app.
309
+ - `--title`, `--mood`, `--location`, `--lat`/`--lng` -- replace the field
310
+ (same limits as `write`). `--tag` (repeat it) -- the entry's tags become
311
+ exactly these.
312
+ - `--image <file>` -- adds an image after the entry's own; `--remove-image
313
+ <media-id>` -- takes one off (`read --json` lists them as `images`);
314
+ `--cover <file>` -- uploads an image and makes it the cover.
315
+ - `--message` -- a note on the new version, shown in the entry's history.
316
+
317
+ `--json` prints `entryId`, `headCommitId`, `text` (`mine`, `all` or
318
+ `unchanged`), `title`, `tags`, `images` and `coverMediaAssetId`.
319
+
320
+ `delete` asks before deleting when there is a terminal to ask at; `--yes`
321
+ skips the question. With no terminal (a pipe, a server, an agent) and no
322
+ `--yes`, it deletes nothing and fails -- a script has to say `--yes`. An
323
+ entry somebody else also wrote in is not deleted without `--all`, since
324
+ that would delete their writing too; take back only your part with
325
+ `whatcha entry update <id> --mine --text ""` instead. `--json` prints
326
+ `entryId`, `diaryId` and `deleted`. A declined question exits with
327
+ status 1 and deletes nothing.
328
+
226
329
  ### `whatcha profiles` / `whatcha switch` / `whatcha profile-add` / `whatcha profile-rm`
227
330
 
228
331
  ```
@@ -230,6 +333,7 @@ whatcha profiles [--json]
230
333
  whatcha switch <@handle> [--json]
231
334
  whatcha switch --account [--json]
232
335
  whatcha profile-add <@handle> --name <display name> [--avatar <file>] [--json]
336
+ whatcha profile-avatar <@handle> <file> [--json]
233
337
  whatcha profile-rm <@handle> [--json]
234
338
  ```
235
339
 
@@ -241,6 +345,13 @@ them knows the feature exists. The saved session simply is that profile.
241
345
  `profiles` marks the current one with `*` and labels the account; `--json`
242
346
  adds `remaining`, how many more the plan allows.
243
347
 
348
+ Which profile is "current" is always the server's answer (`GET /me` with
349
+ the saved credential), never an id remembered in the credential store
350
+ (#58): `switch` says "Already writing as" only when the server agrees,
351
+ `switch --account` signs the account's credential back in on the spot and
352
+ records who it is, and `whoami` repairs a saved session whose remembered id
353
+ had drifted from its credential (as 0.4.0's `switch --account` left it).
354
+
244
355
  `profile-add` (#1699) creates one (`POST /me/profiles`, as the app's "Add a
245
356
  profile" does): a `@handle` of 3-30 letters, digits, `_` or `-` starting
246
357
  with a letter or digit, and a `--name` of at most 80 characters. A taken
@@ -254,6 +365,12 @@ is 2. `--json` prints `profile` (`id`, `username`, `displayName`,
254
365
  `avatarUrl`, `parentProfileId`) and `avatarError` (`null`, or
255
366
  `{code, message}`).
256
367
 
368
+ `profile-avatar` (#50) changes the avatar of a profile that already exists,
369
+ with the same checks. The profile in use sets its own; another sub-profile
370
+ is set through a session for it, used once, as `profile-add` does. The
371
+ account's own avatar cannot be reached from a sub-profile -- `switch
372
+ --account` first. `--json` prints `profileId` and `avatarUrl`.
373
+
257
374
  `switch --account` is how you come back. The API refuses to mint an account
258
375
  session from a sub-profile's session on purpose -- a sub-profile that could
259
376
  ask for one would be a way to take the account over -- so `switch` sets the
@@ -317,7 +434,7 @@ it; `--json` adds `media` (`id`, `url`, `mimeType`, `altText`),
317
434
  Every command accepts `--json`. On success it prints exactly one JSON
318
435
  object to stdout: `{"ok": true, ...}`, with the fields documented per
319
436
  command above (`diaries`, `entryId`/`mode`/`verified`/`title`/`tags`/`titleKept`
320
- for `write`, `body`/`title`/`tags`/... for `read`, `pages` / `body` /
437
+ for `write`, `body`/`title`/`tags`/... for `read`, `entryId`/`text`/`deleted` for `entry`, `pages` / `body` /
321
438
  `mode`/`concurrentEdit` for `wiki`, `profile`/`avatarError` for
322
439
  `profile-add`, `diary`/`members` for `diary-new`, `url`/`isPublic` for
323
440
  `publish`). On failure it prints
package/dist/cli.js CHANGED
@@ -9,8 +9,10 @@ const read_1 = require("./commands/read");
9
9
  const profiles_1 = require("./commands/profiles");
10
10
  const shared_diary_1 = require("./commands/shared-diary");
11
11
  const publish_1 = require("./commands/publish");
12
+ const diary_cover_1 = require("./commands/diary-cover");
12
13
  const whoami_1 = require("./commands/whoami");
13
14
  const wiki_1 = require("./commands/wiki");
15
+ const entry_1 = require("./commands/entry");
14
16
  const output_1 = require("./lib/output");
15
17
  const USAGE = `whatcha -- command-line client for what-are-you-do-ing
16
18
 
@@ -23,12 +25,20 @@ Usage:
23
25
  whatcha diary-new <name> [--with <@handle>]... [--timezone <tz>] [--description "..."] [--json]
24
26
  whatcha invite <diary> <@handle> [--json]
25
27
  whatcha publish <diary> [--off] [--json]
26
- whatcha write <diary> --text "..." [--title "..."] [--tag <tag>]... [--time HH:MM] [--date YYYY-MM-DD] [--json]
28
+ whatcha diary-cover <diary> <file> | --clear [--json]
29
+ whatcha write <diary> (--text "..." | --text-file <path|->) [--title "..."] [--tag <tag>]...
30
+ [--image <file>]... [--cover <file>] [--mood <mood>] [--location "..."] [--lat <deg> --lng <deg>]
31
+ [--time HH:MM [--end HH:MM]] [--date YYYY-MM-DD] [--json]
27
32
  whatcha read <diary> [--date YYYY-MM-DD] [--json]
33
+ whatcha entry update <entry-id> [--text "..." | --text-file <path|->] [--mine | --all] [--title "..."] [--tag <tag>]...
34
+ [--image <file>]... [--remove-image <media-id>]... [--cover <file>] [--mood <mood>] [--location "..."]
35
+ [--lat <deg> --lng <deg>] [--message "..."] [--json]
36
+ whatcha entry delete <entry-id> [--yes] [--all] [--json]
28
37
  whatcha profiles [--json]
29
38
  whatcha switch <@handle> [--json]
30
39
  whatcha switch --account [--json]
31
40
  whatcha profile-add <@handle> --name <display name> [--avatar <file>] [--json]
41
+ whatcha profile-avatar <@handle> <file> [--json]
32
42
  whatcha profile-rm <@handle> [--json]
33
43
  whatcha wiki list [--search <text>] [--group <group-id>] [--limit N] [--cursor <c>] [--json]
34
44
  whatcha wiki read <page> [--group <group-id>] [--json]
@@ -78,10 +88,15 @@ async function run(argv) {
78
88
  return (await (0, shared_diary_1.runInvite)((0, shared_diary_1.parseInviteArgs)(rest))).exitCode;
79
89
  case "publish":
80
90
  return (await (0, publish_1.runPublish)((0, publish_1.parsePublishArgs)(rest))).exitCode;
91
+ case "diary-cover":
92
+ return (await (0, diary_cover_1.runDiaryCover)((0, diary_cover_1.parseDiaryCoverArgs)(rest))).exitCode;
81
93
  case "write":
82
94
  return (await (0, write_1.runWrite)((0, write_1.parseWriteArgs)(rest))).exitCode;
83
95
  case "read":
84
96
  return (await (0, read_1.runRead)((0, read_1.parseReadArgs)(rest))).exitCode;
97
+ // Changing or taking back an entry that is already there (#117), by its id.
98
+ case "entry":
99
+ return (await (0, entry_1.runEntry)((0, entry_1.parseEntryArgs)(rest))).exitCode;
85
100
  case "whoami":
86
101
  return (await (0, whoami_1.runWhoami)((0, whoami_1.parseWhoamiArgs)(rest))).exitCode;
87
102
  // Experience Wiki (#1664). Public Square's pages, or a group's with
@@ -96,6 +111,8 @@ async function run(argv) {
96
111
  return (await (0, profiles_1.runSwitch)((0, profiles_1.parseSwitchArgs)(rest))).exitCode;
97
112
  case "profile-add":
98
113
  return (await (0, profiles_1.runAdd)((0, profiles_1.parseAddArgs)(rest))).exitCode;
114
+ case "profile-avatar":
115
+ return (await (0, profiles_1.runAvatar)((0, profiles_1.parseAvatarArgs)(rest))).exitCode;
99
116
  case "profile-rm":
100
117
  return (await (0, profiles_1.runRemove)((0, profiles_1.parseRemoveArgs)(rest))).exitCode;
101
118
  default:
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AA2DA,kBA0DC;AArHD,qCAAmD;AACnD,4CAA4D;AAC5D,gDAAkE;AAClE,4CAA4D;AAC5D,0CAAyD;AACzD,kDAS6B;AAC7B,0DAAqG;AACrG,gDAAkE;AAClE,8CAA+D;AAC/D,0CAAyD;AACzD,yCAAyD;AAEzD,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Bb,CAAC;AAEF;;;;;GAKG;AACI,KAAK,UAAU,GAAG,CAAC,IAAc;IACtC,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAEhC,IAAI,CAAC,OAAO,IA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YAAE,IAAA,kBAAS,EAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;;YACpF,IAAA,uBAAc,EAAC,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACnD,OAAO,CAAC,CAAC;IACX,CAAC;IACD,mEAAmE;IACnE,wEAAwE;IACxE,kDAAkD;IAClD,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,IAAI,SAAS;QAAE,IAAA,kBAAS,EAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;;QACzE,IAAA,uBAAc,EAAC,4BAA4B,OAAO,EAAE,CAAC,CAAC;IAC3D,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseDiaryCoverArgs = parseDiaryCoverArgs;
4
+ exports.runDiaryCover = runDiaryCover;
5
+ const node_util_1 = require("node:util");
6
+ const session_1 = require("../auth/session");
7
+ const errors_1 = require("../errors");
8
+ const diary_resolve_1 = require("../lib/diary-resolve");
9
+ const image_upload_1 = require("../lib/image-upload");
10
+ const output_1 = require("../lib/output");
11
+ const USAGE = "Usage: whatcha diary-cover <diary> <file> | --clear [--json]";
12
+ function parseDiaryCoverArgs(argv) {
13
+ let values, positionals;
14
+ try {
15
+ ({ values, positionals } = (0, node_util_1.parseArgs)({
16
+ args: argv,
17
+ options: {
18
+ json: { type: "boolean", default: false },
19
+ clear: { type: "boolean", default: false },
20
+ },
21
+ allowPositionals: true,
22
+ }));
23
+ }
24
+ catch (err) {
25
+ throw new errors_1.CliUsageError(err.message);
26
+ }
27
+ const [diary, image, extra] = positionals;
28
+ if (!diary)
29
+ throw new errors_1.CliUsageError(USAGE);
30
+ if (extra !== undefined)
31
+ throw new errors_1.CliUsageError(`Unexpected extra argument: "${extra}"`);
32
+ const clear = values.clear;
33
+ if (clear && image !== undefined)
34
+ throw new errors_1.CliUsageError("Give a file or --clear, not both.");
35
+ if (!clear && image === undefined)
36
+ throw new errors_1.CliUsageError(`Which image? Give a file, or --clear to remove the cover.\n${USAGE}`);
37
+ return { json: values.json, diary, image, clear };
38
+ }
39
+ async function runDiaryCover(opts, deps = {}) {
40
+ // Checked before anything is sent, so a wrong file changes nothing.
41
+ const file = opts.image !== undefined ? await (0, image_upload_1.readImageFile)(opts.image) : undefined;
42
+ const client = deps.client ?? (await (0, session_1.authenticatedClient)()).client;
43
+ const diary = await (0, diary_resolve_1.resolveDiary)(client, opts.diary);
44
+ const coverMediaAssetId = file ? await (0, image_upload_1.uploadImage)(client, diary.groupId, file) : null;
45
+ await client.patch(`/diaries/${diary.id}`, { iconKey: coverMediaAssetId ?? "" });
46
+ if (opts.json)
47
+ (0, output_1.printJson)({ ok: true, diaryId: diary.id, coverMediaAssetId });
48
+ else if (coverMediaAssetId)
49
+ (0, output_1.printLine)(`Set the cover of "${diary.name}".`);
50
+ else
51
+ (0, output_1.printLine)(`Removed the cover of "${diary.name}".`);
52
+ return { exitCode: 0 };
53
+ }
54
+ //# sourceMappingURL=diary-cover.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diary-cover.js","sourceRoot":"","sources":["../../src/commands/diary-cover.ts"],"names":[],"mappings":";;AAyBA,kDAqBC;AAED,sCAgBC;AAhED,yCAAsC;AACtC,6CAAsD;AACtD,sCAA0C;AAE1C,wDAAoD;AACpD,sDAAiE;AACjE,0CAAqD;AAiBrD,MAAM,KAAK,GAAG,8DAA8D,CAAC;AAE7E,SAAgB,mBAAmB,CAAC,IAAc;IAChD,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