notefeed 0.1.0 → 0.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/README.md +4 -2
- package/dist/cli.js +7 -1
- package/dist/client.d.ts +4 -5
- package/dist/client.js +11 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,8 +12,10 @@ backup.sh 2>&1 | npx notefeed post -
|
|
|
12
12
|
```js
|
|
13
13
|
import { Client } from "notefeed";
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
console.log(
|
|
15
|
+
const client = new Client({ url: "https://notes.example.com", token }); // URL and token set once
|
|
16
|
+
console.log((await client.post("# Deploy done\nversion 1.4.2")).url);
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
The `notefeed` command reads `--url` / `--token`, or `NOTEFEED_URL` / `NOTEFEED_TOKEN`. The library itself never reads the environment.
|
|
20
|
+
|
|
19
21
|
Full documentation: https://marceltov.github.io/notefeed/clients/
|
package/dist/cli.js
CHANGED
|
@@ -33,7 +33,13 @@ export async function main(argv, io = process) {
|
|
|
33
33
|
if (command !== "post" || rest.length)
|
|
34
34
|
throw new UsageError(USAGE);
|
|
35
35
|
const markdown = await read(text, values.file, io);
|
|
36
|
-
const
|
|
36
|
+
const url = values.url || process.env.NOTEFEED_URL;
|
|
37
|
+
const token = values.token || process.env.NOTEFEED_TOKEN;
|
|
38
|
+
if (!url)
|
|
39
|
+
throw new UsageError("no URL given; pass --url or set NOTEFEED_URL");
|
|
40
|
+
if (!token)
|
|
41
|
+
throw new UsageError("no token given; pass --token or set NOTEFEED_TOKEN");
|
|
42
|
+
const note = await new Client({ url, token }).post(markdown);
|
|
37
43
|
io.stdout.write(`${note.url}\n`);
|
|
38
44
|
return 0;
|
|
39
45
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export type Note = {
|
|
|
4
4
|
url: string;
|
|
5
5
|
};
|
|
6
6
|
export type ClientOptions = {
|
|
7
|
-
url
|
|
8
|
-
token
|
|
7
|
+
url: string;
|
|
8
|
+
token: string;
|
|
9
9
|
timeoutMs?: number;
|
|
10
10
|
};
|
|
11
11
|
/** Any failure talking to notefeed. `status` is the HTTP status, or null (network, config). */
|
|
@@ -29,8 +29,7 @@ export declare class Client {
|
|
|
29
29
|
readonly url: string;
|
|
30
30
|
private readonly token;
|
|
31
31
|
private readonly timeoutMs;
|
|
32
|
-
|
|
32
|
+
/** A notefeed server. URL and token are set once here; post() takes only the note. */
|
|
33
|
+
constructor(options: ClientOptions);
|
|
33
34
|
post(markdown: string): Promise<Note>;
|
|
34
35
|
}
|
|
35
|
-
/** Post one note. Options go to Client (url, token, timeoutMs). */
|
|
36
|
-
export declare function post(markdown: string, options?: ClientOptions): Promise<Note>;
|
package/dist/client.js
CHANGED
|
@@ -26,23 +26,23 @@ const ERRORS = {
|
|
|
26
26
|
401: AuthError,
|
|
27
27
|
413: NoteTooLargeError,
|
|
28
28
|
};
|
|
29
|
-
function setting(value, env) {
|
|
30
|
-
const v = value || process.env[env] || "";
|
|
31
|
-
if (!v)
|
|
32
|
-
throw new ConfigError(`no ${env.split("_")[1].toLowerCase()} given; pass it or set ${env}`);
|
|
33
|
-
return v;
|
|
34
|
-
}
|
|
35
29
|
export class Client {
|
|
36
30
|
url;
|
|
37
31
|
token;
|
|
38
32
|
timeoutMs;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
/** A notefeed server. URL and token are set once here; post() takes only the note. */
|
|
34
|
+
constructor(options) {
|
|
35
|
+
const { url, token, timeoutMs } = options ?? {};
|
|
36
|
+
if (!url)
|
|
37
|
+
throw new ConfigError("no url given");
|
|
38
|
+
if (!token?.trim())
|
|
39
|
+
throw new ConfigError("no token given");
|
|
40
|
+
this.url = url.replace(/\/+$/, "");
|
|
41
|
+
this.token = token.trim();
|
|
42
42
|
// Never echo the value: it would end up in terminals and CI logs.
|
|
43
43
|
if (/[\x00-\x1f\x7f]/.test(this.token))
|
|
44
|
-
throw new ConfigError("
|
|
45
|
-
this.timeoutMs =
|
|
44
|
+
throw new ConfigError("token contains invalid characters");
|
|
45
|
+
this.timeoutMs = timeoutMs ?? 10_000;
|
|
46
46
|
}
|
|
47
47
|
async post(markdown) {
|
|
48
48
|
let res;
|
|
@@ -81,7 +81,3 @@ export class Client {
|
|
|
81
81
|
throw new NotefeedError(`unexpected response from ${this.url} (not a notefeed server?)`, res.status);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
/** Post one note. Options go to Client (url, token, timeoutMs). */
|
|
85
|
-
export function post(markdown, options) {
|
|
86
|
-
return new Client(options).post(markdown);
|
|
87
|
-
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { AuthError, Client, ConfigError, InvalidNoteError, NotefeedError, NoteTooLargeError
|
|
1
|
+
export { AuthError, Client, ConfigError, InvalidNoteError, NotefeedError, NoteTooLargeError } from "./client.js";
|
|
2
2
|
export type { ClientOptions, Note } from "./client.js";
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { AuthError, Client, ConfigError, InvalidNoteError, NotefeedError, NoteTooLargeError
|
|
1
|
+
export { AuthError, Client, ConfigError, InvalidNoteError, NotefeedError, NoteTooLargeError } from "./client.js";
|