sesame-kit 0.4.2 → 0.5.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.ja.md CHANGED
@@ -8,9 +8,9 @@
8
8
 
9
9
  > **ステータス** — pre-1.0 でありバグが残っている可能性があります。実運用で概ね安定が確認できた時点で 1.0 にします。依存する場合はバージョンを固定してください。
10
10
  >
11
- > **免責** — 非公式。CANDY HOUSE とは無関係で、公式の承認も受けていません。公式アプリと同じ方法でクラウド API を叩くため、予告なく変更・破損する可能性があります。`secretKey` とトークンはロックの全権を握るので外部に漏らさないでください。自己責任で利用してください。
11
+ > **免責** — 非公式。CANDY HOUSE とは無関係・非公認であり、非公式クライアントの利用は同社の利用規約の範囲外となる可能性があります。公式アプリと同じ方法でクラウド API を叩くため、予告なく変更・破損する可能性があります。`secretKey` とトークンはロックの全権を握り、`~/.config/sesame-kit` に暗号化されず保存されるので外部に漏らさないでください。自己責任で利用してください。
12
12
 
13
- 公式 SESAME iOS / Android アプリと同じ Cognito Consumer Client で、SESAME クラウドの WebSocket API を叩く Node.js 実装。ロックの開閉、Hub3 IR の発射・学習、デバイス管理、開閉履歴、電池残量を CLI とライブラリで提供する。`sesame serve` を使えば全機能を JSON-RPC として公開し、任意の言語から組み込める。
13
+ **公式 SESAME アプリでできる操作を、あなたのコードから。** `sesame-kit` は登録済みの SESAME デバイスを公式 iOS / Android アプリと同じように操作します 施錠 / 解錠、Hub3 IR(発射・学習)、デバイス管理、開閉履歴、電池残量。CLI、Node ライブラリ、`sesame serve`(JSON-RPC)で任意の言語から呼べます。`npm install` して、スクリプトやホームオートメーション、自作アプリに SESAME を組み込みましょう。
14
14
 
15
15
  ## 何ができるか
16
16
 
@@ -21,21 +21,21 @@
21
21
  - アクセス制御: NFC カード / キーパッド暗証番号の DB 同期
22
22
  - 予約 / 会社・組織: スケジュール、法人機能 (社員・役割・デバイスグループ・鍵共有)
23
23
  - Hub3 IoT: LED 調光、LTE リレー、ファーム更新、Matter ペアリング
24
- - BLE 直接制御: Bluetooth でロックを直接操作する。autolock 等の設定系は BLE でのみ実機に反映される
25
- - 言語非依存バックエンド: `sesame serve` が全機能を stdio / UDS / HTTP / WS / gRPC に JSON-RPC として公開する
24
+ - BLE 直接制御: Bluetooth でロックを直接操作します。autolock 等の設定系は BLE でのみ実機に反映されます
25
+ - 言語非依存バックエンド: `sesame serve` が全機能を stdio / UDS / HTTP / WS / gRPC に JSON-RPC として公開します
26
26
  - 対話モード、ライブラリ API
27
27
 
28
- 詳細は [コマンドリファレンス](./docs/commands.ja.md) / [ライブラリ利用](./docs/library.ja.md) / [設計ノート](./docs/architecture.ja.md) を参照。
28
+ 詳細は [コマンドリファレンス](./docs/ja/commands.md) / [ライブラリ利用](./docs/ja/library.md) / [設計ノート](./docs/ja/architecture.md) を参照してください。
29
29
 
30
30
  ## 出自 (Lineage)
31
31
 
32
- 公式 biz3 管理 Web ([CANDY-HOUSE/biz.candyhouse.co](https://github.com/CANDY-HOUSE/biz.candyhouse.co), MIT) の Node.js port。biz3 との差分は Cognito Client ID を公式 iOS / Android アプリと同じ Consumer Client にした点のみで、これにより refreshToken が事実上失効しない。biz3 の MIT ライセンスは [LICENSE.biz3](./LICENSE.biz3) に同梱する。port 対応表は [docs/architecture.md](./docs/architecture.ja.md) を参照。
32
+ 公式 biz3 管理 Web ([CANDY-HOUSE/biz.candyhouse.co](https://github.com/CANDY-HOUSE/biz.candyhouse.co), MIT) の Node.js port。biz3 との差分は Cognito Client ID を公式 iOS / Android アプリと同じ Consumer Client にした点のみで、これにより refreshToken が事実上失効しません。biz3 の MIT ライセンスは [LICENSE.biz3](./LICENSE.biz3) に同梱します。port 対応表は [docs/ja/architecture.md](./docs/ja/architecture.md) を参照してください。
33
33
 
34
34
  ---
35
35
 
36
36
  ## インストール
37
37
 
38
- 要件は Node.js 18 以上 (ESM / `node:` プロトコルを使用)。
38
+ 要件は Node.js 18 以上です (ESM / `node:` プロトコルを使用)。
39
39
 
40
40
  ```bash
41
41
  npm install -g sesame-kit # グローバル CLI: `sesame ...`
@@ -54,50 +54,54 @@ cd sesame-kit && npm install && npm link
54
54
 
55
55
  ## セットアップ
56
56
 
57
- `login` `verify` で認証する。`verify` は companyID・ロック・Hub3 IR を自動で取り込む。
57
+ デバイスは公式 SESAME アプリで先に登録済みである必要があります。本ツールは既存デバイスを操作するもので、新規ペアリングは行いません。
58
+
59
+ `login` と `verify` で認証します。`verify` はデバイスを**鍵ごと**(companyID・Hub3 IR リモコンも)`~/.config/sesame-kit/` に取り込むので、以後 `sesame <device> <action>` は追加の鍵設定なしで動きます。
58
60
 
59
61
  ```bash
60
- sesame init # 設定ディレクトリ初期化 (~/.config/sesame-hub3/)
62
+ sesame init # 設定ディレクトリ初期化 (~/.config/sesame-kit/)
61
63
  sesame login your@email.com # email に確認コードを送る
62
- sesame verify # コードを入力。companyID / ロック / Hub3 IR を取り込む
64
+ sesame verify # コードを入力。デバイスを鍵ごと取り込む
65
+ sesame devices # 取り込んだデバイスと名前を一覧 (以降この名前を使う)
63
66
  ```
64
67
 
65
- デバイスを後から追加したら `sesame setup` で取り込みを再実行する。
66
- IR を使うには Hub3 と Remote の両方の登録が必要。ロック開閉だけなら Lock の登録だけでよい。
68
+ 公式アプリでデバイスを後から追加したら `sesame setup` で取り込みを再実行します。
69
+ IR を使うには Hub3 と Remote の両方が登録済みである必要があります。ロック開閉だけなら Lock だけでよいです。
67
70
 
68
71
  ---
69
72
 
70
73
  ## 基本操作
71
74
 
72
- 主語はデバイス: `sesame <device> <action>` (device は部分一致)。
75
+ 引数なしで `sesame` を実行すると対話メニューが出ます。デバイスと各デバイスで使える操作が一覧されます。
76
+
77
+ ```bash
78
+ sesame # デバイス→操作を選ぶ。 ↑↓ 移動 · → 決定 · ← 戻る · q 終了
79
+ ```
80
+
81
+ 操作を直接指定する場合、主語はデバイスです: `sesame <device> <action>`。`sesame devices` で出た自分のデバイス名を使います(部分一致。下の `front` は例)。
73
82
 
74
83
  ```bash
75
84
  sesame front unlock # 解錠 (部分一致: sesame 玄関 unlock)
76
85
  sesame front lock # 施錠
77
- sesame front toggle # 現在状態で反転
78
86
  sesame front status # 状態 (施錠 / 解錠・位置)
79
87
  sesame front autolock 30 # オートロック (BLE 必須。0=無効)
80
88
  sesame send 停止 --remote ac # Hub3 IR 発射
81
- sesame # 全デバイスの対話メニュー (session)
82
89
  ```
83
90
 
84
- 経路 (cloud / BLE) は自動で選ばれる。固定するときは `--ble-only` / `--cloud-only` を付ける。
85
- IR 学習・デバイス管理・予約・アクセス制御・会社組織・IoT・BLE の全コマンドは [docs/commands.md](./docs/commands.ja.md) を参照。
86
-
87
- ### 対話モード
91
+ 経路 (cloud / BLE) は既定で自動選択されます("auto" モード)。固定するときは `--ble-only` / `--cloud-only` を付けます。
92
+ 全コマンドは [CLI リファレンス](./docs/ja/commands.md) を参照してください (IR 学習・デバイス管理・予約・アクセス制御・会社組織・IoT・BLE)。
88
93
 
89
- TTY 環境 (`--json` 指定なし) では、足りない引数を矢印キー (↑↓) で選択できる。`sesame` だけでトップメニュー。
90
- `--json` / 非 TTY では prompt を出さず、引数不足はエラーになる (CI 互換)。
94
+ > TTY では引数不足のコマンドは矢印キーのプロンプトにフォールバックします。`--json` / TTY では prompt を出さず引数不足はエラーです (CI 互換)
91
95
 
92
96
  ---
93
97
 
94
98
  ## JSON 出力契約 (他言語からの subprocess 呼び出し)
95
99
 
96
- `--json` を付けると、subprocess から扱える契約で動く。
100
+ `--json` を付けると、subprocess から扱える契約で動きます。
97
101
 
98
- - 成功: stdout に純 JSON を 1 件だけ出力する (進捗・ログは stderr)。
99
- - エラー: stderr に `{"error": "...", "code": <n>}` を出し、非 0 で終了する。
100
- - `--json` / 非対話では prompt を出さず、引数不足は即エラー。
102
+ - 成功: stdout に純 JSON を 1 件だけ出力します (進捗・ログは stderr)。
103
+ - エラー: stderr に `{"error": "...", "code": <n>}` を出し、非 0 で終了します。
104
+ - `--json` / 非対話では prompt を出さず、引数不足は即エラーです。
101
105
  - 終了コード: `0`=成功 / `1`=実行時エラー / `2`=使い方エラー。
102
106
 
103
107
  ```bash
@@ -105,26 +109,26 @@ sesame front status --json # → stdout: {...} exit 0
105
109
  sesame login --json # → stderr: {"error":"...","code":1} exit≠0
106
110
  ```
107
111
 
108
- 出力 JSON の形は各コマンド固有。互換性の判定には契約バージョンを使う:
112
+ 出力 JSON の形は各コマンド固有です。互換性の判定には契約バージョンを使います:
109
113
  常駐デーモンの `status` が返す `contractVersion`、または `rpc.discover` の `info["x-contractVersion"]`。
110
- 機械契約の SemVer で、破壊的変更でのみ major が上がる。消費者は major を pin して fail-fast できる。
114
+ 機械契約の SemVer で、破壊的変更でのみ major が上がります。消費者は major を pin して fail-fast できます。
111
115
 
112
116
  ---
113
117
 
114
118
  ## 言語非依存バックエンド (`sesame serve`)
115
119
 
116
- `sesame serve` は常駐 JSON-RPC 2.0 デーモン。1 回ログインして WS 接続を保持したまま、何度でも op を実行し、
117
- イベントを push する。全機能を、どの言語からでも同一の API で呼べる。
120
+ `sesame serve` は常駐 JSON-RPC 2.0 デーモンです。1 回ログインして WS 接続を保持したまま、何度でも op を実行し、
121
+ イベントを push します。全機能を、どの言語からでも同一の API で呼べます。
118
122
 
119
123
  ```bash
120
- sesame serve # Unix socket のみ (既定。~/.config/sesame-hub3/sesame.sock)
124
+ sesame serve # Unix socket のみ (既定。~/.config/sesame-kit/sesame.sock)
121
125
  sesame serve --stdio # 埋め込み: 親が子プロセスとして spawn し stdin/stdout で対話
122
126
  sesame serve --http 8080 --ws 8081 --grpc 50051 # ネットワーク経由 (token 認証)
123
127
  ```
124
128
 
125
- 5 つの繋ぎ口があり、どれも同じメソッドを公開する:
129
+ 5 つの接続方式 (トランスポート) があり、どれも同じメソッドを公開します:
126
130
 
127
- | 繋ぎ口 | 用途 | イベント | 認証 |
131
+ | トランスポート | 用途 | イベント | 認証 |
128
132
  |---|---|---|---|
129
133
  | stdio | 埋め込み (子プロセス) | `event.*` 通知 | 親の信頼を継承 |
130
134
  | Unix socket | ローカル常駐・多クライアント | `event.*` 通知 | ファイル権限 0600 |
@@ -132,12 +136,12 @@ sesame serve --http 8080 --ws 8081 --grpc 50051 # ネットワーク経由 (to
132
136
  | WebSocket | 全言語 / ブラウザ (全二重) | `event.*` 通知 | token |
133
137
  | gRPC | 多言語の型付きスタブ生成 | `Subscribe` ストリーム | token (metadata) |
134
138
 
135
- - メソッドは `rpc.discover` で機械可読に全列挙する (OpenRPC)。param 名・必須・型は実コードから抽出済み。
136
- - ロック: `lock.lock` / `lock.unlock` / `lock.toggle` / `lock.status`。名前空間 op は `<ns>.<op>` で全公開する (`org.*` / `iot.*` / `access.*` …)。
137
- - イベント: `events.subscribe {topics:["lockState","deviceUpdate"]}` で以後 `event.<topic>` 通知が届く。
138
- - エラーは `{error:{code, message, data:{kind}}}`。`kind` は `not_authenticated` / `connection_lost` / `timeout` / `bad_params` / `not_implemented` / `internal` の 6 種。
139
+ - メソッドは `rpc.discover` で機械可読に全列挙します (OpenRPC)。param 名・必須・型は実コードから抽出済みです。
140
+ - ロック: `lock.lock` / `lock.unlock` / `lock.toggle` / `lock.status`。名前空間 op は `<ns>.<op>` で全公開します (`org.*` / `iot.*` / `access.*` …)。
141
+ - イベント: `events.subscribe {topics:["lockState","deviceUpdate"]}` で以後 `event.<topic>` 通知が届きます。
142
+ - エラーは `{error:{code, message, data:{kind}}}`。`kind` は `not_authenticated` / `connection_lost` / `timeout` / `bad_params` / `not_implemented` / `internal` の 6 種です。
139
143
 
140
- 別端末で `sesame serve` を起動しておけば、`sesame rpc` が UDS 越しにそのデーモンを叩く:
144
+ 別端末で `sesame serve` を起動しておけば、`sesame rpc` が UDS 越しにそのデーモンを叩きます:
141
145
 
142
146
  ```bash
143
147
  sesame rpc # rpc.discover を人間向けの表で表示
@@ -146,83 +150,112 @@ sesame rpc --subscribe lockState # イベントを表示し続ける
146
150
  sesame rpc --paths # 接続情報 (socket / token のパス) を JSON で出力
147
151
  ```
148
152
 
153
+ HTTP 経由(任意の言語・クライアント不要): `POST /rpc` に Bearer token を付けます。token は起動時に表示され `~/.config/sesame-kit/serve.token` にも保存されます。
154
+
155
+ ```bash
156
+ sesame serve --http 8080 # HTTP リスナを起動 (既定の serve は socket のみ)
157
+ TOKEN=$(cat ~/.config/sesame-kit/serve.token) # 起動時に表示されるトークン
158
+ curl -s -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" \
159
+ -d '{"jsonrpc":"2.0","id":1,"method":"lock.unlock","params":{"name":"front"}}' \
160
+ http://127.0.0.1:8080/rpc
161
+ ```
162
+
149
163
  ### 同梱クライアント
150
164
 
151
- `clients/` に依存ゼロの薄いクライアントを同梱する。
165
+ JSON-RPC をラップした薄いクライアントで、`c.unlock("front")` のように書けます。任意であり、上の `curl` でもクライアント無しで動きます。Node は `npm install sesame-kit` 後に `import { SesameClient } from "sesame-kit/client"`。Python はパッケージ同梱の単一ファイルです。
152
166
 
153
- - Python: `pip install ./clients/python` で、どこからでも `import sesame_client`。試すだけなら `PYTHONPATH=clients/python`。
154
- - JS: `clients/js/sesame-client.mjs` を自プロジェクトにコピー、または相対 import。WebSocket をヘッダ認証で使うなら `npm i ws` (無ければ URL `?token=` にフォールバックする)。
167
+ ```js
168
+ import { SesameClient } from "sesame-kit/client"; // npm install sesame-kit の後
169
+ const c = SesameClient.unix(); // 既定 Unix ソケット
170
+ console.log(await c.unlock("front"));
171
+ console.log(await c.call("device.history", { deviceUUID: "AB12CD34...", pageSize: 10 })); // 任意のメソッド。deviceUUID は `sesame devices` から
172
+ await c.subscribe(["lockState"], (topic, p) => console.log(topic, p)); // 常に await
173
+ ```
155
174
 
156
175
  ```python
176
+ # Python — 連携ガイドの手順でインストールしてから:
157
177
  from sesame_client import SesameClient
158
- c = SesameClient.unix() # 既定 UDS パスを自動解決
159
- print(c.status()); print(c.unlock("front"))
160
- c.subscribe(["lockState"], lambda topic, payload: print("EVENT", topic, payload))
161
- # HTTP: SesameClient.http("http://127.0.0.1:8080") / 埋め込み: SesameClient.stdio()
178
+ c = SesameClient.unix() # 既定 Unix ソケット
179
+ print(c.unlock("front"))
180
+ print(c.call("device.history", deviceUUID="AB12CD34...", pageSize=10)) # 任意のメソッド。deviceUUID は `sesame devices` から
162
181
  ```
163
182
 
183
+ インストール不要の HTTP 経路・Python のインストール(グローバル npm 含む)・メソッド/値の調べ方・イベント・gRPC・セキュリティは [連携ガイド](./docs/ja/integration.md) を参照してください。
184
+
185
+ gRPC は型付きです。`src/serve/sesame.proto` が op ごとに型付きメソッドを持ちます。
186
+ ソースチェックアウトでスタブ生成(`pip install grpcio-tools` 後): `python -m grpc_tools.protoc -I src/serve --python_out=. --grpc_python_out=. src/serve/sesame.proto`。
187
+
188
+ 認証境界: 対話ログインは CLI 専用で、デーモンには載りません。Unix socket は同一ユーザの任意プロセスが操作できます
189
+ (CLI と同じ境界)。HTTP / WS / gRPC は TCP のため、起動時に生成する loopback token を要求します。POSIX 専用です
190
+ (Windows の UDS は非対象です。stdio / HTTP / WS / gRPC は動きます)。
191
+
192
+ ---
193
+
194
+ ## Node から使う(インプロセス)
195
+
196
+ デーモンを別に立てず、Node アプリ内で直接ロックを操作するにはライブラリエントリを使います。CLI のログイン情報(`~/.config/sesame-kit`、`sesame login` を一度実行)を読み、接続と切断を自動で行います。
197
+
164
198
  ```js
165
- import { SesameClient } from "./sesame-client.mjs";
166
- const c = SesameClient.unix(); // UDS (POSIX)
167
- console.log(await c.unlock("front"));
168
- await c.subscribe(["lockState"], (topic, p) => console.log("EVENT", topic, p)); // 常に await
169
- const w = await SesameClient.ws("ws://127.0.0.1:8081"); // WebSocket (全二重)
170
- ```
199
+ import { SesameHub3 } from "sesame-kit";
171
200
 
172
- gRPC は型付き。`src/serve/sesame.proto` op ごとに型付きメソッドを持つ。
173
- スタブ生成: `python -m grpc_tools.protoc -I src/serve --python_out=. --grpc_python_out=. src/serve/sesame.proto`。
201
+ await SesameHub3.use(async (hub) => {
202
+ await hub.unlock("front");
203
+ await hub.send("ac", "停止"); // Hub3 IR
204
+ });
205
+ ```
174
206
 
175
- 認証境界: 対話ログインは CLI 専用で、デーモンには載らない。Unix socket は同一ユーザの任意プロセスが操作できる
176
- (CLI と同じ境界)。HTTP / WS / gRPC は TCP のため、起動時に生成する loopback token を要求する。POSIX 専用
177
- (Windows の UDS は非対象。stdio / HTTP / WS / gRPC は動く)。
207
+ 直接 API(`deviceUUID` / `secretKey` 指定)、イベント購読、config ファイルでなくコードでトークンを渡す方法は [Node ライブラリガイド](./docs/ja/library.md) を参照してください。
178
208
 
179
209
  ---
180
210
 
181
211
  ## 設定ディレクトリ
182
212
 
183
- 優先順位: `--config-dir <path>` → `SESAME_HUB3_HOME` → `$XDG_CONFIG_HOME/sesame-hub3` → `~/.config/sesame-hub3`。
213
+ 優先順位: `--config-dir <path>` → `SESAME_KIT_HOME` → `$XDG_CONFIG_HOME/sesame-kit` → `~/.config/sesame-kit`。
184
214
 
185
215
  ```
186
- ~/.config/sesame-hub3/
216
+ ~/.config/sesame-kit/
187
217
  ├── config.json # devices / remotes / default / apiKeyId
188
218
  ├── tokens.json # Cognito state (gitignore 必須)
189
219
  ├── login_state.json # sign-in 進行中の一時状態
190
220
  └── devices.json # `devices` コマンドの dump
191
221
  ```
192
222
 
193
- config スキーマと「単一 `devices{}` に保存する」設計は [docs/architecture.md](./docs/architecture.ja.md) を参照。
223
+ config スキーマと「単一 `devices{}` に保存する」設計は [docs/ja/architecture.md](./docs/ja/architecture.md) を参照してください。
194
224
 
195
225
  ---
196
226
 
197
227
  ## ドキュメント
198
228
 
199
- - [docs/commands.md](./docs/commands.ja.md) — 全 CLI コマンドのリファレンス
200
- - [docs/library.md](./docs/library.ja.md) — Node ライブラリとしての利用
201
- - [docs/architecture.md](./docs/architecture.ja.md) — 出自・設計判断・ファイル構成
202
- - [docs/migration.md](./docs/migration.ja.md) — 旧版からの移行
229
+ ドキュメント全体: **[docs/ja/](./docs/ja/index.md)** ([English](./docs/en/index.md))。
230
+
231
+ - [クイックスタート](./docs/ja/quickstart.md) — 導入・ログイン・解錠まで
232
+ - [CLI リファレンス](./docs/ja/commands.md) — 全コマンド
233
+ - [BLE 直接制御](./docs/ja/ble.md) — クラウド非経由で Bluetooth 操作
234
+ - [Node ライブラリ](./docs/ja/library.md) — Node.js アプリへ埋め込み
235
+ - [他言語からの組み込み](./docs/ja/integration.md) — `sesame serve` 経由 (Python / JS / HTTP / WS / gRPC)
236
+ - [アーキテクチャ](./docs/ja/architecture.md) · [マイグレーション](./docs/ja/migration.md)
203
237
 
204
238
  ---
205
239
 
206
240
  ## 既知の制限
207
241
 
208
- - 常駐用途では auto-reconnect (exponential backoff 1s→10s)、token refresh callback、idle / sleep 検知が動く。
209
- - 対応リモコンは自己学習 (`learnEmit`) のみ。プリセットリモコン (メーカー DB から選ぶ方式) command 生成は未移植。`sesame ir learn` で物理リモコンを取り込んで使う。
210
- - autolock はクラウド経由では設定できない。BLE `sesame autolock` を使う。
211
- - 未実装 op Stripe 課金切替のみ。それ以外の biz3 op (社員 / グループ / 役割 / デバイスグループ / 鍵共有 / アクセス制御 / 予約 / IoT) はコマンド化済み。
212
- - WS ステージの既定は `/public`。`/production` は使用しない (config に残っていれば load 時に `/public` へ書き換える)。
213
- - AWS IoT WS は IPv4 必須。IPv6-only 回線では繋がらない。
214
- - 新規ペアリング (未登録デバイスの登録) は未対応。登録済みデバイスの操作のみ。
242
+ - 対応リモコンは自己学習 (`learnEmit`) のみです。プリセットリモコン (メーカー DB から選ぶ方式) command 生成は未移植です。`sesame ir learn` で物理リモコンを取り込んで使います。
243
+ - autolock はクラウド経由では設定できません。BLE `sesame <device> autolock <秒>`(例: `sesame front autolock 30`)を使います。
244
+ - 未実装 op Stripe 課金切替のみです。それ以外の biz3 op (社員 / グループ / 役割 / デバイスグループ / 鍵共有 / アクセス制御 / 予約 / IoT) はコマンド化済みです。
245
+ - WS ステージの既定は `/public` です。`/production` は使用しません (config に残っていれば load 時に `/public` へ書き換えます)
246
+ - AWS IoT WS IPv4 必須です。IPv6-only 回線では繋がりません。
247
+ - 新規ペアリング (未登録デバイスの登録) は未対応です。登録済みデバイスの操作のみです。
215
248
 
216
249
  ---
217
250
 
218
251
  ## トラブルシュート
219
252
 
220
253
  - `No tokens stored` / `No config at ...`: `sesame init` → `sesame login`、または `sesame migrate`。
221
- - `UserNotFoundException`: 自動 SignUp は組み込み済み。それでも出る場合は Cognito 側の特殊ケース。
222
- - `Cognito refresh returned no IdToken`: refreshToken が無効化された (公式アプリでログアウト等)。再 sign-in する。
254
+ - `UserNotFoundException`: 自動 SignUp は組み込み済みです。それでも出る場合は Cognito 側の特殊ケースです。
255
+ - `Cognito refresh returned no IdToken`: refreshToken が無効化されました (公式アプリでログアウト等)。再 sign-in します。
223
256
  - `triggerLock timeout`: `secretKey` 不一致、Hub3 オフライン、または WS の半開接続 (自動再接続で復帰)。
224
- - `learn timeout`: Hub3 が REGISTER に入ったが波形を受け取れなかった。距離を縮める、別ボタンを試す。
225
- - `apiKeyId required`: `webapi` 系は config.json に `apiKeyId` を入れる (biz3 dev console で発行)。
257
+ - `learn timeout`: Hub3 が REGISTER に入りましたが波形を受け取れませんでした。距離を縮めるか、別のボタンを試してください。
258
+ - `apiKeyId required`: `webapi` 系は config.json に `apiKeyId` を入れます (biz3 dev console で発行)。
226
259
 
227
260
  ## 関連
228
261
 
package/README.md CHANGED
@@ -4,13 +4,13 @@
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/sesame-kit)](https://www.npmjs.com/package/sesame-kit) [![license](https://img.shields.io/npm/l/sesame-kit)](./LICENSE) [![node](https://img.shields.io/node/v/sesame-kit)](https://nodejs.org)
6
6
 
7
- A Node.js CLI and library that drives the SESAME cloud WebSocket API using the same Cognito consumer client as the official SESAME iOS / Android apps. It covers lock control, Hub3 IR (emit and learn), device management, history, and battery level. With `sesame serve` it exposes every feature as JSON-RPC so you can drive SESAME from any language.
7
+ **Do what the official SESAME app does from your own code.** `sesame-kit` operates your existing SESAME devices the way the official iOS / Android apps do lock / unlock, Hub3 IR (emit and learn), device management, history, battery from a CLI, a Node library, or any language via `sesame serve` (JSON-RPC). `npm install` it and build SESAME into your scripts, home automation, or app.
8
8
 
9
9
  > 日本語版: [README.ja.md](./README.ja.md)
10
10
 
11
11
  > **Status** — Pre-1.0 and may contain bugs. It will reach 1.0 once it has proven stable in real use. Pin a version if you depend on it.
12
12
  >
13
- > **Disclaimer** — Unofficial. Not affiliated with or endorsed by CANDY HOUSE. It drives the cloud API the same way the official apps do, which may change or break without notice. Your `secretKey` and tokens grant full control of your lock; keep them private. Use at your own risk.
13
+ > **Disclaimer** — Unofficial. Not affiliated with or endorsed by CANDY HOUSE, and using an unofficial client may fall outside their terms of service. It drives the cloud API the same way the official apps do, which may change or break without notice. Your `secretKey` and tokens grant full control of your lock and are stored unencrypted under `~/.config/sesame-kit`; keep them private. Use at your own risk.
14
14
 
15
15
  ## Features
16
16
 
@@ -25,11 +25,11 @@ A Node.js CLI and library that drives the SESAME cloud WebSocket API using the s
25
25
  - Language-agnostic backend: `sesame serve` exposes every feature as JSON-RPC over stdio / UDS / HTTP / WS / gRPC
26
26
  - Interactive mode and a library API
27
27
 
28
- See [command reference](./docs/commands.md), [library usage](./docs/library.md), and [design notes](./docs/architecture.md) for details.
28
+ See [command reference](./docs/en/commands.md), [library usage](./docs/en/library.md), and [design notes](./docs/en/architecture.md) for details.
29
29
 
30
30
  ## Lineage
31
31
 
32
- A Node.js port of the official biz3 admin web app ([CANDY-HOUSE/biz.candyhouse.co](https://github.com/CANDY-HOUSE/biz.candyhouse.co), MIT). The only functional difference from biz3 is that the Cognito client ID is set to the same consumer client as the official iOS / Android apps, which keeps the refresh token from effectively expiring. The biz3 MIT license is bundled as [LICENSE.biz3](./LICENSE.biz3). The port mapping is in [docs/architecture.md](./docs/architecture.md).
32
+ A Node.js port of the official biz3 admin web app ([CANDY-HOUSE/biz.candyhouse.co](https://github.com/CANDY-HOUSE/biz.candyhouse.co), MIT). The only functional difference from biz3 is that the Cognito client ID is set to the same consumer client as the official iOS / Android apps, which keeps the refresh token from effectively expiring. The biz3 MIT license is bundled as [LICENSE.biz3](./LICENSE.biz3). The port mapping is in [docs/en/architecture.md](./docs/en/architecture.md).
33
33
 
34
34
  ---
35
35
 
@@ -54,40 +54,44 @@ cd sesame-kit && npm install && npm link
54
54
 
55
55
  ## Setup
56
56
 
57
- Authenticate with `login` and `verify`. `verify` imports your companyID, locks, and Hub3 IR remotes automatically.
57
+ Your devices must already be set up in the official SESAME app — this tool operates existing devices and does not pair new ones.
58
+
59
+ Authenticate with `login` and `verify`. `verify` imports your devices **together with their keys** (and companyID and Hub3 IR remotes) into `~/.config/sesame-kit/`, so `sesame <device> <action>` works afterward with no further key setup.
58
60
 
59
61
  ```bash
60
- sesame init # initialize the config directory (~/.config/sesame-hub3/)
62
+ sesame init # initialize the config directory (~/.config/sesame-kit/)
61
63
  sesame login your@email.com # send a verification code to your email
62
- sesame verify # enter the code; imports companyID / locks / Hub3 IR
64
+ sesame verify # enter the code; imports your devices (with keys)
65
+ sesame devices # list your devices and their names (use these names below)
63
66
  ```
64
67
 
65
- Run `sesame setup` to re-import after adding devices later.
66
- IR requires both a Hub3 and a Remote to be registered. For lock control alone, only the Lock is needed.
68
+ Run `sesame setup` to re-import after adding devices in the official app later.
69
+ IR requires both a Hub3 and a Remote to be set up. For lock control alone, only the Lock is needed.
67
70
 
68
71
  ---
69
72
 
70
73
  ## Basic usage
71
74
 
72
- The subject is the device: `sesame <device> <action>` (device matches by substring).
75
+ Run `sesame` with no arguments for the interactive menu. It lists your devices and the actions each one supports.
76
+
77
+ ```bash
78
+ sesame # pick a device, then an action. ↑↓ move · → confirm · ← back · q quit
79
+ ```
80
+
81
+ To run an action directly, the subject is the device: `sesame <device> <action>`. Use one of your device names from `sesame devices` (matched by substring; `front` below is just an example).
73
82
 
74
83
  ```bash
75
84
  sesame front unlock # unlock (substring match: sesame 玄関 unlock)
76
85
  sesame front lock # lock
77
- sesame front toggle # toggle from current state
78
86
  sesame front status # state (locked / unlocked, position)
79
87
  sesame front autolock 30 # autolock (BLE only. 0 = off)
80
88
  sesame send 停止 --remote ac # Hub3 IR emit
81
- sesame # interactive menu for all devices (session)
82
89
  ```
83
90
 
84
- The route (cloud / BLE) is chosen automatically. Pin it with `--ble-only` / `--cloud-only`.
85
- See [docs/commands.md](./docs/commands.md) for the full command set (IR learning, device management, scheduling, access control, org, IoT, BLE).
86
-
87
- ### Interactive mode
91
+ The route (cloud / BLE) is chosen automatically (**auto**). Pin it with `--ble-only` / `--cloud-only`.
92
+ See the [CLI reference](./docs/en/commands.md) for every command (IR learning, device management, scheduling, access control, org, IoT, BLE).
88
93
 
89
- In a TTY (no `--json`), missing arguments can be selected with the arrow keys (↑↓). `sesame` alone opens the top menu.
90
- With `--json` or in a non-TTY, no prompts are shown and missing arguments are errors (CI-friendly).
94
+ > In a TTY, a command with missing arguments falls back to arrow-key prompts. With `--json` or in a non-TTY, there are no prompts and missing arguments are errors (CI-friendly).
91
95
 
92
96
  ---
93
97
 
@@ -116,7 +120,7 @@ It is a SemVer for the machine contract; only breaking changes bump the major. C
116
120
  `sesame serve` is a long-running JSON-RPC 2.0 daemon. It logs in once, keeps the WS connection alive, runs ops repeatedly, and pushes events. Every feature is callable from any language through the same API.
117
121
 
118
122
  ```bash
119
- sesame serve # Unix socket only (default. ~/.config/sesame-hub3/sesame.sock)
123
+ sesame serve # Unix socket only (default. ~/.config/sesame-kit/sesame.sock)
120
124
  sesame serve --stdio # embedded: a parent spawns it and talks over stdin/stdout
121
125
  sesame serve --http 8080 --ws 8081 --grpc 50051 # over the network (token auth)
122
126
  ```
@@ -145,66 +149,95 @@ sesame rpc --subscribe lockState # keep printing events (Ctrl-C to s
145
149
  sesame rpc --paths # print connection info (socket / token paths) as JSON
146
150
  ```
147
151
 
152
+ Over HTTP (any language, no client): `POST /rpc` with a Bearer token. The token is printed when the daemon starts and saved to `~/.config/sesame-kit/serve.token`.
153
+
154
+ ```bash
155
+ sesame serve --http 8080 # start the HTTP listener (the default serve is socket-only)
156
+ TOKEN=$(cat ~/.config/sesame-kit/serve.token) # the token printed at startup
157
+ curl -s -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" \
158
+ -d '{"jsonrpc":"2.0","id":1,"method":"lock.unlock","params":{"name":"front"}}' \
159
+ http://127.0.0.1:8080/rpc
160
+ ```
161
+
148
162
  ### Bundled clients
149
163
 
150
- Thin zero-dependency clients live under `clients/`.
164
+ Thin clients wrap the JSON-RPC so you can write `c.unlock("front")`. They are optional — the `curl` call above works without any client. Node: `import { SesameClient } from "sesame-kit/client"` after `npm install sesame-kit`. Python: a single file shipped with the package.
151
165
 
152
- - Python: `pip install ./clients/python`, then `import sesame_client` from anywhere. For a quick try, `PYTHONPATH=clients/python`.
153
- - JS: copy `clients/js/sesame-client.mjs` into your project, or import it by relative path. For header-authenticated WebSocket, `npm i ws` (otherwise it falls back to URL `?token=`).
166
+ ```js
167
+ import { SesameClient } from "sesame-kit/client"; // after: npm install sesame-kit
168
+ const c = SesameClient.unix(); // default Unix socket
169
+ console.log(await c.unlock("front"));
170
+ console.log(await c.call("device.history", { deviceUUID: "AB12CD34...", pageSize: 10 })); // any method; deviceUUID from `sesame devices`
171
+ await c.subscribe(["lockState"], (topic, p) => console.log(topic, p)); // always await
172
+ ```
154
173
 
155
174
  ```python
175
+ # Python — install per the integration guide, then:
156
176
  from sesame_client import SesameClient
157
- c = SesameClient.unix() # resolves the default UDS path
158
- print(c.status()); print(c.unlock("front"))
159
- c.subscribe(["lockState"], lambda topic, payload: print("EVENT", topic, payload))
160
- # HTTP: SesameClient.http("http://127.0.0.1:8080") / embedded: SesameClient.stdio()
177
+ c = SesameClient.unix() # default Unix socket
178
+ print(c.unlock("front"))
179
+ print(c.call("device.history", deviceUUID="AB12CD34...", pageSize=10)) # any method; deviceUUID from `sesame devices`
161
180
  ```
162
181
 
163
- ```js
164
- import { SesameClient } from "./sesame-client.mjs";
165
- const c = SesameClient.unix(); // UDS (POSIX)
166
- console.log(await c.unlock("front"));
167
- await c.subscribe(["lockState"], (topic, p) => console.log("EVENT", topic, p)); // always await
168
- const w = await SesameClient.ws("ws://127.0.0.1:8081"); // WebSocket (full-duplex)
169
- ```
182
+ See the [integration guide](./docs/en/integration.md) for the no-install HTTP path, Python install (incl. global npm installs), discovering methods/values, events, gRPC, and security.
170
183
 
171
184
  gRPC is typed. `src/serve/sesame.proto` has a typed method per op.
172
- Generate stubs with: `python -m grpc_tools.protoc -I src/serve --python_out=. --grpc_python_out=. src/serve/sesame.proto`.
185
+ Generate stubs from a source checkout (after `pip install grpcio-tools`): `python -m grpc_tools.protoc -I src/serve --python_out=. --grpc_python_out=. src/serve/sesame.proto`.
173
186
 
174
187
  Auth boundary: interactive login is CLI-only and never runs in the daemon. A Unix socket can be used by any process of the same user (the same boundary as the CLI). HTTP / WS / gRPC are over TCP and require a loopback token generated at startup. POSIX only (Windows UDS is out of scope; stdio / HTTP / WS / gRPC work).
175
188
 
176
189
  ---
177
190
 
191
+ ## Use from Node (in-process)
192
+
193
+ To control locks directly inside a Node app — without a separate daemon — use the library entry. It reads your CLI login from `~/.config/sesame-kit` (run `sesame login` once), then connects and closes automatically.
194
+
195
+ ```js
196
+ import { SesameHub3 } from "sesame-kit";
197
+
198
+ await SesameHub3.use(async (hub) => {
199
+ await hub.unlock("front");
200
+ await hub.send("ac", "停止"); // Hub3 IR
201
+ });
202
+ ```
203
+
204
+ See the [Node library guide](./docs/en/library.md) for the direct API (by `deviceUUID` / `secretKey`), event subscriptions, and supplying tokens in code instead of the config file.
205
+
206
+ ---
207
+
178
208
  ## Config directory
179
209
 
180
- Precedence: `--config-dir <path>` → `SESAME_HUB3_HOME` → `$XDG_CONFIG_HOME/sesame-hub3` → `~/.config/sesame-hub3`.
210
+ Precedence: `--config-dir <path>` → `SESAME_KIT_HOME` → `$XDG_CONFIG_HOME/sesame-kit` → `~/.config/sesame-kit`.
181
211
 
182
212
  ```
183
- ~/.config/sesame-hub3/
213
+ ~/.config/sesame-kit/
184
214
  ├── config.json # devices / remotes / default / apiKeyId
185
215
  ├── tokens.json # Cognito state (must be gitignored)
186
216
  ├── login_state.json # transient state during sign-in
187
217
  └── devices.json # dump from the `devices` command
188
218
  ```
189
219
 
190
- The config schema and the "store all devices in a single `devices{}`" design are in [docs/architecture.md](./docs/architecture.md).
220
+ The config schema and the "store all devices in a single `devices{}`" design are in [docs/en/architecture.md](./docs/en/architecture.md).
191
221
 
192
222
  ---
193
223
 
194
224
  ## Documentation
195
225
 
196
- - [docs/commands.md](./docs/commands.md) — full CLI command reference
197
- - [docs/library.md](./docs/library.md) — using it as a Node library
198
- - [docs/architecture.md](./docs/architecture.md) — lineage, design decisions, file layout
199
- - [docs/migration.md](./docs/migration.md) — migrating from older versions
226
+ Full docs: **[docs/en/](./docs/en/index.md)** ([日本語](./docs/ja/index.md)).
227
+
228
+ - [Quickstart](./docs/en/quickstart.md) — install, sign in, open a lock
229
+ - [CLI reference](./docs/en/commands.md) — every command
230
+ - [BLE direct control](./docs/en/ble.md) — operate over Bluetooth without the cloud
231
+ - [Node library](./docs/en/library.md) — embed in a Node.js app
232
+ - [Integrate from any language](./docs/en/integration.md) — via `sesame serve` (Python / JS / HTTP / WS / gRPC)
233
+ - [Architecture](./docs/en/architecture.md) · [Migration](./docs/en/migration.md)
200
234
 
201
235
  ---
202
236
 
203
237
  ## Known limitations
204
238
 
205
- - For long-running use, auto-reconnect (exponential backoff 1s→10s), a token refresh callback, and idle / sleep detection are in place.
206
239
  - Only self-learned remotes (`learnEmit`) are supported. Command generation for preset remotes (picked from a manufacturer DB) is not ported. Use `sesame ir learn` to capture a physical remote.
207
- - autolock cannot be set over the cloud. Use `sesame autolock` over BLE.
240
+ - autolock cannot be set over the cloud use `sesame <device> autolock <seconds>` over BLE (e.g. `sesame front autolock 30`).
208
241
  - The only unimplemented op is Stripe billing changes. Every other biz3 op (employees / groups / roles / device groups / key sharing / access control / scheduling / IoT) is available as a command.
209
242
  - The default WS stage is `/public`. `/production` is never used (if it lingers in config it is rewritten to `/public` on load).
210
243
  - AWS IoT WS requires IPv4. It will not connect on IPv6-only networks.
@@ -20,11 +20,11 @@ import { readFileSync } from "node:fs";
20
20
 
21
21
  function defaultSocketPath() {
22
22
  const base = process.env.XDG_CONFIG_HOME || join(os.homedir(), ".config");
23
- return join(base, "sesame-hub3", "sesame.sock");
23
+ return join(base, "sesame-kit", "sesame.sock");
24
24
  }
25
25
  function defaultTokenPath() {
26
26
  const base = process.env.XDG_CONFIG_HOME || join(os.homedir(), ".config");
27
- return join(base, "sesame-hub3", "serve.token");
27
+ return join(base, "sesame-kit", "serve.token");
28
28
  }
29
29
  function defaultToken() {
30
30
  try { return readFileSync(defaultTokenPath(), "utf8").trim(); } catch { return null; }
@@ -35,12 +35,12 @@ from typing import Any, Callable, Optional
35
35
 
36
36
  def _default_socket_path() -> str:
37
37
  base = os.environ.get("XDG_CONFIG_HOME") or os.path.join(os.path.expanduser("~"), ".config")
38
- return os.path.join(base, "sesame-hub3", "sesame.sock")
38
+ return os.path.join(base, "sesame-kit", "sesame.sock")
39
39
 
40
40
 
41
41
  def _default_token_path() -> str:
42
42
  base = os.environ.get("XDG_CONFIG_HOME") or os.path.join(os.path.expanduser("~"), ".config")
43
- return os.path.join(base, "sesame-hub3", "serve.token")
43
+ return os.path.join(base, "sesame-kit", "serve.token")
44
44
 
45
45
 
46
46
  class SesameError(RuntimeError):