freshjots 0.2.0 → 0.2.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
@@ -30,12 +30,16 @@ console.log(note.plain_body);
30
30
  const notes = await client.notes();
31
31
  for (const n of notes) console.log(`${n.filename}\t${n.title}`);
32
32
 
33
- // Create a new note explicitly (errors if the filename is taken).
34
- await client.create({ filename: "research-2026-q2", body: "Initial outline." });
33
+ // Create a note. The API derives the filename from the title — for a
34
+ // note addressable by an exact filename, use append() instead.
35
+ const created = await client.create({ title: "Research 2026 Q2", body: "Initial outline." });
36
+ console.log(created.filename); // server-derived stream name
35
37
  ```
36
38
 
37
39
  The whole API is four methods: `notes()`, `note(filename)`,
38
- `create({ filename, body, title })`, `append(filename, text)`.
40
+ `create({ title, body })`, `append(filename, text)`. `note()` and
41
+ `create()` return the note object directly (no `{ note: … }` wrapper);
42
+ `notes()` returns the array.
39
43
 
40
44
  ## TypeScript
41
45
 
package/index.d.ts CHANGED
@@ -61,10 +61,14 @@ declare module "freshjots" {
61
61
  baseUrl?: string;
62
62
  }
63
63
 
64
+ /**
65
+ * Input for `create()`. The API derives the note's filename from the
66
+ * title (it does not accept a client-supplied filename). For a note
67
+ * addressable by an exact, caller-chosen filename, use `append()`.
68
+ */
64
69
  export interface CreateInput {
65
- filename: string;
70
+ title: string;
66
71
  body?: string;
67
- title?: string;
68
72
  }
69
73
 
70
74
  export class Client {
package/index.js CHANGED
@@ -7,12 +7,18 @@
7
7
  // await client.append("cron-jobs-prod", "backup ok");
8
8
  // const note = await client.note("cron-jobs-prod");
9
9
  // console.log(note.plain_body);
10
+ // const created = await client.create({ title: "Deploy log" });
11
+ // console.log(created.filename); // server-derived from the title
10
12
  //
11
13
  // Requires Node 18+ (uses global fetch). All methods throw ApiError on
12
14
  // non-2xx responses, with the code/status/details from the API's stable
13
15
  // error envelope.
16
+ //
17
+ // Note on response shapes: GET /notes is the only endpoint that wraps its
18
+ // payload ({ "notes": [...] }). show / show-by-filename / create return
19
+ // the note object at the TOP LEVEL — there is no { "note": ... } wrapper.
14
20
 
15
- export const VERSION = "0.1.0";
21
+ export const VERSION = "0.2.1";
16
22
  const DEFAULT_BASE_URL = "https://freshjots.com/api/v1";
17
23
 
18
24
  export class ApiError extends Error {
@@ -39,14 +45,27 @@ export class Client {
39
45
  }
40
46
 
41
47
  async note(filename) {
48
+ // show-by-filename renders the serializer at the top level (no
49
+ // { note: ... } wrapper), so return the response as-is.
42
50
  const path = `/notes/by-filename/${encodeURIComponent(filename)}`;
43
- return (await this._request("GET", path)).note;
51
+ return await this._request("GET", path);
44
52
  }
45
53
 
46
- async create({ filename, body = "", title }) {
47
- const note = { filename, plain_body: body, format: "plain" };
48
- if (title) note.title = title;
49
- return (await this._request("POST", "/notes", { note })).note;
54
+ // Create a note. The API permits note[title, plain_body, format, ...]
55
+ // NOT filename: the server DERIVES the filename from the title. For
56
+ // a note addressable by an exact, caller-chosen filename, use append()
57
+ // (the by-filename endpoint creates it with that exact name on first
58
+ // call). Returns the created note (top level); read `.filename` for
59
+ // the server-derived stream name.
60
+ async create({ title, body = "" }) {
61
+ if (!title) {
62
+ throw new Error(
63
+ "create requires a title — the API derives the filename from it. " +
64
+ "For a note addressable by an exact filename, use append().",
65
+ );
66
+ }
67
+ const note = { title, plain_body: body, format: "plain" };
68
+ return await this._request("POST", "/notes", { note });
50
69
  }
51
70
 
52
71
  async append(filename, text) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freshjots",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Tiny JavaScript client for the Fresh Jots API. Append-only notebooks for cron jobs, deploy scripts, and bots.",
5
5
  "type": "module",
6
6
  "main": "index.js",