@elchika-inc/todoke-cli 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 todoke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @elchika-inc/todoke-cli
2
+
3
+ Command-line interface for [todoke](https://todoke.dev) — the minimal Web Push notification SaaS with first-class AI (MCP) support.
4
+
5
+ Manage your apps, API keys, and send Web Push notifications from the terminal.
6
+
7
+ ## Install
8
+
9
+ > **Note**: `@elchika-inc/todoke-cli` is not yet published to npm. Until it is, build it from this repository:
10
+ >
11
+ > ```bash
12
+ > # after cloning the todoke monorepo
13
+ > bun install
14
+ > cd apps/cli
15
+ > bun run build # emits dist/
16
+ > ```
17
+
18
+ Once published:
19
+
20
+ ```bash
21
+ npm install -g @elchika-inc/todoke-cli
22
+ # or run without installing
23
+ npx @elchika-inc/todoke-cli --help
24
+ ```
25
+
26
+ ## Getting started
27
+
28
+ Authenticate with a **full**-scope API key (create one from the [dashboard](https://todoke.dev) or `todoke keys add`):
29
+
30
+ ```bash
31
+ todoke login --api-key pk_xxxxxxxx
32
+ ```
33
+
34
+ Credentials are stored in `~/.todoke.json` (file mode `0600`). Point at a different backend with `--api-url` (defaults to `https://api.todoke.dev`).
35
+
36
+ ## Commands
37
+
38
+ | Command | Description |
39
+ |---------|-------------|
40
+ | `todoke login --api-key <key> [--api-url <url>]` | Save an API key and log in (a `full`-scope key is required) |
41
+ | `todoke logout` | Remove saved credentials |
42
+ | `todoke apps list` | List your apps |
43
+ | `todoke apps stats <app-id>` | Show delivery stats for an app |
44
+ | `todoke apps delete <app-id>` | Delete an app |
45
+ | `todoke keys list <app-id>` | List an app's API keys |
46
+ | `todoke keys add <app-id> -n <name> [-s <scope>]` | Create an API key (`scope`: `subscribe_only` / `notify` / `full`, default `notify`) |
47
+ | `todoke keys rm <app-id> <key-id>` | Delete an API key |
48
+ | `todoke notify -t <title> -b <body> [-u <url>] [-e <endpoint>]` | Send a Web Push notification to the logged-in key's app (omit `-e` to broadcast to all subscribers) |
49
+
50
+ Run `todoke <command> --help` for full option details.
51
+
52
+ ## Example
53
+
54
+ ```bash
55
+ # Send a broadcast notification to every subscriber of the logged-in key's app
56
+ todoke notify -t "Deploy complete" -b "v1.2.0 is live" -u https://example.com/changelog
57
+ ```
58
+
59
+ ## License
60
+
61
+ MIT — see [LICENSE](./LICENSE).
package/dist/index.js ADDED
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env node
2
+ import chalk from "chalk";
3
+ import { Command } from "commander";
4
+ import ora from "ora";
5
+ import { apiRequest, CONFIG_PATH, DEFAULT_API_URL, deleteConfig, loadConfig, saveConfig, } from "./lib.js";
6
+ function getConfig() {
7
+ const config = loadConfig();
8
+ if (!config) {
9
+ console.error(chalk.red("ログインしていません。`todoke login --api-key <key>` を実行してください。"));
10
+ process.exit(1);
11
+ }
12
+ return config;
13
+ }
14
+ function handleError(spinner, message) {
15
+ spinner.fail(message);
16
+ process.exitCode = 1;
17
+ }
18
+ const program = new Command();
19
+ program.name("todoke").description("todoke CLI — Web Push通知SaaS").version("0.1.0");
20
+ // login
21
+ program
22
+ .command("login")
23
+ .description("API キーを保存してログイン(full スコープのキーが必要)")
24
+ .requiredOption("--api-key <key>", "API キー (pk_ で始まる文字列、full スコープ)")
25
+ .option("--api-url <url>", "API URL", DEFAULT_API_URL)
26
+ .action(async (opts) => {
27
+ const spinner = ora("接続を確認中...").start();
28
+ const config = { apiKey: opts.apiKey, apiUrl: opts.apiUrl };
29
+ const res = await apiRequest(config, "/api/v1/apps");
30
+ if (!res.ok) {
31
+ if (res.status === 403) {
32
+ handleError(spinner, "このAPIキーのスコープではログインできません。full スコープのAPIキーをダッシュボードで発行して使用してください。");
33
+ }
34
+ else {
35
+ handleError(spinner, `認証に失敗しました: ${res.message}`);
36
+ }
37
+ return;
38
+ }
39
+ saveConfig(config);
40
+ spinner.succeed(chalk.green(`ログインしました。設定を ${CONFIG_PATH} に保存しました。`));
41
+ });
42
+ // logout
43
+ program
44
+ .command("logout")
45
+ .description("保存した認証情報を削除")
46
+ .action(() => {
47
+ if (deleteConfig()) {
48
+ console.log(chalk.green("ログアウトしました。"));
49
+ }
50
+ else {
51
+ console.log(chalk.gray("ログインしていません。"));
52
+ }
53
+ });
54
+ // apps
55
+ const appsCmd = program.command("apps").description("アプリ管理");
56
+ appsCmd
57
+ .command("list")
58
+ .description("アプリ一覧を表示")
59
+ .action(async () => {
60
+ const spinner = ora("取得中...").start();
61
+ const res = await apiRequest(getConfig(), "/api/v1/apps");
62
+ if (!res.ok) {
63
+ handleError(spinner, res.message);
64
+ return;
65
+ }
66
+ spinner.stop();
67
+ if (res.data.length === 0) {
68
+ console.log(chalk.gray("アプリがありません。"));
69
+ return;
70
+ }
71
+ console.log(chalk.bold(`\nアプリ一覧 (${res.data.length}件)\n`));
72
+ for (const app of res.data) {
73
+ console.log(` ${chalk.bold(app.name)} ${chalk.gray(app.id)}`);
74
+ }
75
+ });
76
+ appsCmd
77
+ .command("stats <app-id>")
78
+ .description("アプリの統計を表示")
79
+ .action(async (appId) => {
80
+ const spinner = ora("取得中...").start();
81
+ const res = await apiRequest(getConfig(), `/api/v1/apps/${appId}/stats`);
82
+ if (!res.ok) {
83
+ handleError(spinner, res.message);
84
+ return;
85
+ }
86
+ spinner.stop();
87
+ const { activeSubscribers, totalSent, totalFailed, monthlySent } = res.data;
88
+ console.log(`\n アクティブ購読者: ${chalk.bold(activeSubscribers)}`);
89
+ console.log(` 総送信数: ${chalk.bold(totalSent)}`);
90
+ console.log(` 失敗数: ${chalk.bold(totalFailed)}`);
91
+ console.log(` 今月の配信成功数: ${chalk.bold(monthlySent)}\n`);
92
+ });
93
+ appsCmd
94
+ .command("delete <app-id>")
95
+ .description("アプリを削除")
96
+ .action(async (appId) => {
97
+ const spinner = ora("削除中...").start();
98
+ const res = await apiRequest(getConfig(), `/api/v1/apps/${appId}`, { method: "DELETE" });
99
+ if (!res.ok) {
100
+ handleError(spinner, res.message);
101
+ return;
102
+ }
103
+ spinner.succeed("削除しました。");
104
+ });
105
+ // keys
106
+ const keysCmd = program.command("keys").description("APIキー管理");
107
+ keysCmd
108
+ .command("list <app-id>")
109
+ .description("APIキー一覧を表示")
110
+ .action(async (appId) => {
111
+ const spinner = ora("取得中...").start();
112
+ const res = await apiRequest(getConfig(), `/api/v1/apps/${appId}/keys`);
113
+ if (!res.ok) {
114
+ handleError(spinner, res.message);
115
+ return;
116
+ }
117
+ spinner.stop();
118
+ if (res.data.length === 0) {
119
+ console.log(chalk.gray("APIキーがありません。"));
120
+ return;
121
+ }
122
+ console.log(chalk.bold(`\nAPIキー一覧 (${res.data.length}件)\n`));
123
+ for (const key of res.data) {
124
+ const lastUsed = key.last_used_at
125
+ ? new Date(key.last_used_at).toLocaleString("ja-JP")
126
+ : chalk.gray("未使用");
127
+ console.log(` ${chalk.bold(key.name)} ${chalk.cyan(key.scope)} 最終使用: ${lastUsed}`);
128
+ console.log(` ${chalk.gray(key.id)}`);
129
+ }
130
+ });
131
+ keysCmd
132
+ .command("add <app-id>")
133
+ .description("APIキーを作成")
134
+ .requiredOption("-n, --name <name>", "キー名")
135
+ .option("-s, --scope <scope>", "スコープ (subscribe_only/notify/full)", "notify")
136
+ .action(async (appId, opts) => {
137
+ const spinner = ora("作成中...").start();
138
+ const res = await apiRequest(getConfig(), `/api/v1/apps/${appId}/keys`, {
139
+ method: "POST",
140
+ body: JSON.stringify({ name: opts.name, scope: opts.scope }),
141
+ });
142
+ if (!res.ok) {
143
+ handleError(spinner, res.message);
144
+ return;
145
+ }
146
+ spinner.succeed(`作成しました: ${chalk.bold(res.data.name)} (${chalk.cyan(res.data.scope)})`);
147
+ if (res.data.key) {
148
+ console.log(chalk.yellow(`\n APIキー: ${chalk.bold(res.data.key)}`));
149
+ console.log(chalk.dim(" ※ このキーは一度しか表示されません。必ずコピーしてください。\n"));
150
+ }
151
+ });
152
+ keysCmd
153
+ .command("rm <app-id> <key-id>")
154
+ .description("APIキーを削除")
155
+ .action(async (appId, keyId) => {
156
+ const spinner = ora("削除中...").start();
157
+ const res = await apiRequest(getConfig(), `/api/v1/apps/${appId}/keys/${keyId}`, {
158
+ method: "DELETE",
159
+ });
160
+ if (!res.ok) {
161
+ handleError(spinner, res.message);
162
+ return;
163
+ }
164
+ spinner.succeed("削除しました。");
165
+ });
166
+ // notify
167
+ // 送信先アプリは API キーから導出される(/api/v1/notify は URL に appId を取らない)。
168
+ // app-id を位置引数に取ると「別アプリ ID を渡してもキー所属アプリへ黙って送る」
169
+ // silent misrouting を招くため、引数は取らない。
170
+ program
171
+ .command("notify")
172
+ .description("Push通知を送信(送信先はログイン中の API キーのアプリ)")
173
+ .requiredOption("-t, --title <title>", "通知タイトル")
174
+ .requiredOption("-b, --body <body>", "通知本文")
175
+ .option("-u, --url <url>", "クリック時のURL")
176
+ .option("-e, --endpoint <endpoint>", "特定の購読者のエンドポイント")
177
+ .action(async (opts) => {
178
+ const spinner = ora("送信中...").start();
179
+ const payload = { title: opts.title, body: opts.body };
180
+ if (opts.url)
181
+ payload.url = opts.url;
182
+ if (opts.endpoint)
183
+ payload.endpoint = opts.endpoint;
184
+ const res = await apiRequest(getConfig(), "/api/v1/notify", {
185
+ method: "POST",
186
+ body: JSON.stringify(payload),
187
+ });
188
+ if (!res.ok) {
189
+ handleError(spinner, res.message);
190
+ return;
191
+ }
192
+ spinner.succeed(`通知を送信しました: "${chalk.bold(opts.title)}"`);
193
+ });
194
+ program.parse();
package/dist/lib.js ADDED
@@ -0,0 +1,51 @@
1
+ import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ export const CONFIG_PATH = join(homedir(), ".todoke.json");
5
+ export const DEFAULT_API_URL = "https://api.todoke.dev";
6
+ export function loadConfig() {
7
+ if (!existsSync(CONFIG_PATH))
8
+ return null;
9
+ try {
10
+ const parsed = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
11
+ if (typeof parsed !== "object" ||
12
+ parsed === null ||
13
+ typeof parsed.apiKey !== "string" ||
14
+ typeof parsed.apiUrl !== "string")
15
+ return null;
16
+ return parsed;
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ }
22
+ export function saveConfig(config) {
23
+ writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), { mode: 0o600 });
24
+ }
25
+ export function deleteConfig() {
26
+ if (!existsSync(CONFIG_PATH))
27
+ return false;
28
+ try {
29
+ unlinkSync(CONFIG_PATH);
30
+ return true;
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ }
36
+ export async function apiRequest(config, path, init = {}) {
37
+ const res = await fetch(`${config.apiUrl}${path}`, {
38
+ ...init,
39
+ headers: {
40
+ "Content-Type": "application/json",
41
+ Authorization: `Bearer ${config.apiKey}`,
42
+ ...init.headers,
43
+ },
44
+ });
45
+ if (!res.ok) {
46
+ const body = (await res.json().catch(() => ({})));
47
+ return { ok: false, status: res.status, message: body.error ?? res.statusText };
48
+ }
49
+ const data = (await res.json());
50
+ return { ok: true, data };
51
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@elchika-inc/todoke-cli",
3
+ "version": "0.1.0",
4
+ "description": "Command-line interface for todoke — the minimal Web Push notification SaaS",
5
+ "bin": {
6
+ "todoke": "./dist/index.js"
7
+ },
8
+ "type": "module",
9
+ "scripts": {
10
+ "dev": "tsx src/index.ts",
11
+ "build": "tsc -p tsconfig.build.json",
12
+ "typecheck": "tsc --noEmit",
13
+ "prepublishOnly": "tsc -p tsconfig.build.json"
14
+ },
15
+ "dependencies": {
16
+ "chalk": "^5.4.1",
17
+ "commander": "^13.1.0",
18
+ "ora": "^8.2.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^22.0.0",
22
+ "tsx": "^4.19.3",
23
+ "typescript": "^5.7.2"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "license": "MIT",
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "homepage": "https://todoke.dev",
35
+ "keywords": [
36
+ "web-push",
37
+ "push-notifications",
38
+ "cloudflare",
39
+ "cli",
40
+ "todoke"
41
+ ]
42
+ }