@h-ai/capacitor 0.1.0-alpha.66 → 0.1.0-alpha.68

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.en.md CHANGED
@@ -4,9 +4,11 @@
4
4
 
5
5
  [Framework home](../../README.en.md) · Related modules: [@h-ai/api-client](../api-client/README.en.md) · [@h-ai/core](../core/README.en.md)
6
6
 
7
+ ## Introduction
8
+
7
9
  A Capacitor native bridge for hai Framework mobile apps, with a unified API for secure token storage, device information, push notifications, camera, and status bar access.
8
10
 
9
- ## Capabilities
11
+ ## Core features
10
12
 
11
13
  - **Token storage**: `@aparajita/capacitor-secure-storage` (required on native platforms). Android uses KeyStore + encrypted SharedPreferences; iOS uses Keychain. No Web fallback.
12
14
  - **Preferences**: `@capacitor/preferences` (required). General preferences storage for nonsensitive settings, not authentication tokens.
@@ -16,7 +18,9 @@ A Capacitor native bridge for hai Framework mobile apps, with a unified API for
16
18
  - **Camera/gallery**: `@capacitor/camera` (optional). Capture photos or select gallery images.
17
19
  - **Status bar**: `@capacitor/status-bar` (optional). Immersive mode, background color, and style settings.
18
20
 
19
- ## Quick start
21
+ ## Getting started
22
+
23
+ ### Quick start
20
24
 
21
25
  ```ts
22
26
  import { capacitor } from '@h-ai/capacitor'
@@ -28,7 +32,7 @@ if (!result.success) {
28
32
  }
29
33
  ```
30
34
 
31
- ### Secure token storage with api-client
35
+ #### Secure token storage with api-client
32
36
 
33
37
  ```ts
34
38
  import { apiClient } from '@h-ai/api-client'
@@ -43,9 +47,13 @@ await apiClient.init({
43
47
  })
44
48
  ```
45
49
 
46
- `createCapacitorTokenStorage()` persists tokens only on native Android/iOS and requires `@aparajita/capacitor-secure-storage`. On Web it does not fall back to `localStorage`: `get*()` returns `null`, and `set*()` / `clear()` are no-ops.
50
+ `createCapacitorTokenStorage()` persists tokens only on native Android/iOS and requires `@aparajita/capacitor-secure-storage`. Its methods return promises directly: Web calls, an unavailable plugin, and failed reads, writes, or removals reject instead of pretending credentials are absent or an operation succeeded. Web entry points should select api-client cookie or memory storage.
51
+
52
+ `clear()` immediately blocks both old credentials in this adapter instance and waits for all native removals before reporting the result. Failures keep them blocked; a successful write reopens only that key. Update credentials through `apiClient.auth` for serialized writes and handle rejected `setTokens()` / `clear()` calls. The UI must release its loading state, discard the logged-out identity, and display failures. Instance-local blocking does not prove persistent deletion; revocation across restarts still requires server logout/session revocation. Retry with the same instance after the plugin recovers.
47
53
 
48
- ### Device information and push notifications
54
+ A failed credential write blocks both credentials, including an access token already saved before a refresh-token write failed. After failed login or registration persistence, attempt `auth.clear()` to remove partially saved data. Report cleanup failures explicitly instead of claiming device credentials were deleted.
55
+
56
+ #### Device information and push notifications
49
57
 
50
58
  ```ts
51
59
  import { capacitor } from '@h-ai/capacitor'
@@ -61,7 +69,9 @@ if (reg.success) {
61
69
  }
62
70
  ```
63
71
 
64
- ### Status bar
72
+ Push requires an actual native platform. The setup phase of `push.register({ signal? })` and `push.listen(callbacks, { signal? })` has a 30-second deadline including permission requests and listener attachment. Failure, timeout, cancellation and `capacitor.close()` stop callbacks and remove owned handles; late handles are removed when they arrive. Other consumers are not affected through removeAllListeners. After listen succeeds, its signal and returned cleanup can still stop it. Cleanup and close return `HaiResult<void>`; native removal failures return `PUSH_CLEANUP_FAILED` (`capacitor:032`) and retain failed handles for retry without repeating successful removals. Closing disables the module immediately, and initialization retries pending cleanup first. Controlled plugin timing tests do not replace repeated registration, permission and FCM/APNs checks on Android/iOS devices.
73
+
74
+ #### Status bar
65
75
 
66
76
  ```ts
67
77
  import { capacitor } from '@h-ai/capacitor'
@@ -73,7 +83,7 @@ await capacitor.statusBar.configure({
73
83
  })
74
84
  ```
75
85
 
76
- ### Camera
86
+ #### Camera
77
87
 
78
88
  ```ts
79
89
  const photo = await capacitor.camera.takePhoto({
@@ -83,7 +93,7 @@ const photo = await capacitor.camera.takePhoto({
83
93
  })
84
94
  ```
85
95
 
86
- ### Preferences
96
+ #### Preferences
87
97
 
88
98
  ```ts
89
99
  await capacitor.preferences.set('my_key', 'value')
@@ -93,7 +103,7 @@ await capacitor.preferences.remove('my_key')
93
103
 
94
104
  `capacitor.preferences` is for general preferences such as language, theme, and drafts. Use `createCapacitorTokenStorage()` for authentication tokens.
95
105
 
96
- ## Configuration
106
+ ### Configuration
97
107
 
98
108
  This module has no configuration file. `capacitor.init()` only checks whether the Capacitor runtime is available.
99
109
 
@@ -105,9 +115,9 @@ export const prerender = true
105
115
  export const ssr = false
106
116
  ```
107
117
 
108
- ## Error handling
118
+ ### Error handling
109
119
 
110
- All asynchronous APIs return `HaiResult<T>` instead of throwing directly:
120
+ Business operations on `capacitor.*` and `safe*Preference` return `HaiResult<T>`. TokenStorage adapter methods reject their promises on platform or storage errors:
111
121
 
112
122
  ```ts
113
123
  import { capacitor, HaiCapacitorError } from '@h-ai/capacitor'
@@ -138,7 +148,7 @@ Common error codes:
138
148
  | `HaiCapacitorError.CAMERA_FAILED` | `hai:capacitor:040` | Camera operation failed |
139
149
  | `HaiCapacitorError.STATUS_BAR_FAILED` | `hai:capacitor:050` | Status bar operation failed |
140
150
 
141
- ## Tests
151
+ ## Development and testing
142
152
 
143
153
  ```bash
144
154
  pnpm --filter @h-ai/capacitor test
@@ -146,6 +156,8 @@ pnpm --filter @h-ai/capacitor test
146
156
 
147
157
  > Tests must mock `@capacitor/*` modules because they depend on native plugins.
148
158
 
159
+ Public operations, internal resource scopes and types include typechecked examples; see the [JSDoc conventions (Chinese)](../../.agents/instructions/module-conventions.md#jsdoc-与示例验证). Typechecking does not prove device permissions or live FCM/APNs delivery.
160
+
149
161
  ## License
150
162
 
151
163
  Apache-2.0
package/README.ja.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  [フレームワークのホーム](../../README.ja.md) · 関連モジュール:[@h-ai/api-client](../api-client/README.ja.md) · [@h-ai/core](../core/README.ja.md)
6
6
 
7
+ ## 概要
8
+
7
9
  hai Framework のモバイルアプリ向け Capacitor ネイティブブリッジ。安全な Token ストレージ、端末情報、プッシュ通知、カメラ、ステータスバーを共通 API で提供します。
8
10
 
9
11
  ## 主な機能
@@ -16,7 +18,9 @@ hai Framework のモバイルアプリ向け Capacitor ネイティブブリッ
16
18
  - **カメラ/アルバム**:`@capacitor/camera`(任意)。撮影とアルバム画像の選択。
17
19
  - **ステータスバー**:`@capacitor/status-bar`(任意)。没入型表示、背景色、スタイルの設定。
18
20
 
19
- ## クイックスタート
21
+ ## 使い始める
22
+
23
+ ### クイックスタート
20
24
 
21
25
  ```ts
22
26
  import { capacitor } from '@h-ai/capacitor'
@@ -28,7 +32,7 @@ if (!result.success) {
28
32
  }
29
33
  ```
30
34
 
31
- ### api-client と連携する安全な Token ストレージ
35
+ #### api-client と連携する安全な Token ストレージ
32
36
 
33
37
  ```ts
34
38
  import { apiClient } from '@h-ai/api-client'
@@ -43,9 +47,13 @@ await apiClient.init({
43
47
  })
44
48
  ```
45
49
 
46
- `createCapacitorTokenStorage()` は Android/iOS のネイティブ環境でのみ Token を永続化し、`@aparajita/capacitor-secure-storage` が必要です。Web では `localStorage` に切り替わらず、`get*()` は `null` を返し、`set*()` / `clear()` は何もしません。
50
+ `createCapacitorTokenStorage()` は Android/iOS のネイティブ環境でのみ Token を永続化し、`@aparajita/capacitor-secure-storage` が必要です。メソッドは Promise を直接返し、Web 呼び出し、プラグインの利用不可、読み書き・削除の失敗は reject されます。空の認証情報や操作成功として扱わないでください。Web では api-client の Cookie またはメモリーストレージを選びます。
51
+
52
+ `clear()` は開始時にこのインスタンスの古い認証情報を読み取り不可にし、すべてのネイティブ削除が完了してから結果を返します。失敗時は読み取りを禁止したままにし、各キーへの書き込み成功時のみそのキーを再開します。書き込みを直列化する `apiClient.auth` を使い、`setTokens()` / `clear()` の失敗を処理してください。UI は loading を解除し、ログアウトしたユーザー情報を消去して失敗を表示します。この制限はインスタンス内のみで、永続データの削除を保証しません。再起動後の失効にはサーバーでのセッション撤回が必要です。プラグイン復旧後は同じインスタンスで再試行できます。
47
53
 
48
- ### 端末情報とプッシュ通知
54
+ 認証情報の一方の書き込みが失敗すると両方を読み取り不可にするため、access token 保存後に refresh token の保存が失敗しても不完全な認証状態は公開しません。ログイン・登録時の保存失敗後は `auth.clear()` で部分保存データの削除を試み、削除も失敗した場合は端末の認証情報を削除できたと表示しないでください。
55
+
56
+ #### 端末情報とプッシュ通知
49
57
 
50
58
  ```ts
51
59
  import { capacitor } from '@h-ai/capacitor'
@@ -61,7 +69,9 @@ if (reg.success) {
61
69
  }
62
70
  ```
63
71
 
64
- ### ステータスバー
72
+ Push は実際のネイティブ環境が必要です。`push.register({ signal? })` と `push.listen(callbacks, { signal? })` の設定段階は権限要求とリスナー登録を含め30秒で終了します。失敗、タイムアウト、中止、`capacitor.close()` はコールバックを停止し、所有するハンドルを除去します。遅延したハンドルも到着時に除去し、removeAllListeners で他の利用者を巻き込みません。listen 成功後も signal と cleanup が有効です。cleanup と close は `HaiResult<void>` を返し、ネイティブ除去失敗は `PUSH_CLEANUP_FAILED`(`capacitor:032`)です。失敗したハンドルを保持して再試行し、成功済みの除去は繰り返しません。終了直後にモジュールを無効化し、再初期化前に残存ハンドルを処理します。制御したプラグイン試験は Android/iOS 実機の権限、FCM/APNs、反復登録試験を代替しません。
73
+
74
+ #### ステータスバー
65
75
 
66
76
  ```ts
67
77
  import { capacitor } from '@h-ai/capacitor'
@@ -73,7 +83,7 @@ await capacitor.statusBar.configure({
73
83
  })
74
84
  ```
75
85
 
76
- ### カメラ
86
+ #### カメラ
77
87
 
78
88
  ```ts
79
89
  const photo = await capacitor.camera.takePhoto({
@@ -83,7 +93,7 @@ const photo = await capacitor.camera.takePhoto({
83
93
  })
84
94
  ```
85
95
 
86
- ### Preferences
96
+ #### Preferences
87
97
 
88
98
  ```ts
89
99
  await capacitor.preferences.set('my_key', 'value')
@@ -93,7 +103,7 @@ await capacitor.preferences.remove('my_key')
93
103
 
94
104
  `capacitor.preferences` は言語、テーマ、下書きなどの一般的な設定用です。認証 Token には `createCapacitorTokenStorage()` を使用してください。
95
105
 
96
- ## 設定
106
+ ### 設定
97
107
 
98
108
  このモジュールに設定ファイルはありません。`capacitor.init()` は Capacitor の実行環境が利用可能かどうかのみを確認します。
99
109
 
@@ -105,9 +115,9 @@ export const prerender = true
105
115
  export const ssr = false
106
116
  ```
107
117
 
108
- ## エラー処理
118
+ ### エラー処理
109
119
 
110
- すべての非同期 API は直接 throw せず、`HaiResult<T>` を返します:
120
+ `capacitor.*` と `safe*Preference` は `HaiResult<T>` を返します。TokenStorage のメソッドはプラットフォームや保存エラーで Promise を reject します。
111
121
 
112
122
  ```ts
113
123
  import { capacitor, HaiCapacitorError } from '@h-ai/capacitor'
@@ -138,7 +148,7 @@ if (!result.success) {
138
148
  | `HaiCapacitorError.CAMERA_FAILED` | `hai:capacitor:040` | カメラ操作に失敗 |
139
149
  | `HaiCapacitorError.STATUS_BAR_FAILED` | `hai:capacitor:050` | ステータスバー操作に失敗 |
140
150
 
141
- ## テスト
151
+ ## 開発とテスト
142
152
 
143
153
  ```bash
144
154
  pnpm --filter @h-ai/capacitor test
@@ -146,6 +156,8 @@ pnpm --filter @h-ai/capacitor test
146
156
 
147
157
  > ネイティブプラグインへの依存があるため、テストでは `@capacitor/*` モジュールを mock する必要があります。
148
158
 
149
- ## License
159
+ 公開操作、内部リソースと型には型検査できる例があります。[JSDoc 規約(中国語)](../../.agents/instructions/module-conventions.md#jsdoc-与示例验证) を参照してください。型検査は端末権限や FCM/APNs の実配信を保証しません。
160
+
161
+ ## ライセンス
150
162
 
151
163
  Apache-2.0
package/README.md CHANGED
@@ -4,9 +4,11 @@
4
4
 
5
5
  [框架首页](../../README.md) · 相关模块:[@h-ai/api-client](../api-client/README.md) · [@h-ai/core](../core/README.md)
6
6
 
7
+ ## 简介
8
+
7
9
  Capacitor 原生桥接模块,为 hai Framework 移动应用提供原生安全 Token 存储、设备信息、推送通知、相机与状态栏等能力的统一封装。
8
10
 
9
- ## 支持的能力
11
+ ## 核心功能清单
10
12
 
11
13
  - **Token 存储**:`@aparajita/capacitor-secure-storage`(原生必需)。Android 使用 KeyStore + 加密 SharedPreferences,iOS 使用 Keychain;Web 不回退。
12
14
  - **Preferences**:`@capacitor/preferences`(必需)。通用偏好数据存储,适合非敏感配置,不用于认证 Token。
@@ -16,7 +18,9 @@ Capacitor 原生桥接模块,为 hai Framework 移动应用提供原生安全
16
18
  - **相机/相册**:`@capacitor/camera`(可选)。拍照、选取相册图片。
17
19
  - **状态栏**:`@capacitor/status-bar`(可选)。沉浸式、背景色、样式配置。
18
20
 
19
- ## 快速开始
21
+ ## 使用入门
22
+
23
+ ### 快速开始
20
24
 
21
25
  ```ts
22
26
  import { capacitor } from '@h-ai/capacitor'
@@ -28,7 +32,7 @@ if (!result.success) {
28
32
  }
29
33
  ```
30
34
 
31
- ### 与 api-client 配合的 Token 安全存储
35
+ #### 与 api-client 配合的 Token 安全存储
32
36
 
33
37
  ```ts
34
38
  import { apiClient } from '@h-ai/api-client'
@@ -43,9 +47,13 @@ await apiClient.init({
43
47
  })
44
48
  ```
45
49
 
46
- `createCapacitorTokenStorage()` 仅在 Android/iOS 原生环境中持久化 token,并要求已安装 `@aparajita/capacitor-secure-storage`。纯 Web 环境下不会退化到 `localStorage`;`get*()` 返回 `null`,`set*()` / `clear()` 为 no-op。
50
+ `createCapacitorTokenStorage()` 仅在 Android/iOS 原生环境中持久化 token,并要求已安装 `@aparajita/capacitor-secure-storage`。适配器的方法直接返回 Promise:Web 调用、插件不可用、读写或删除失败都会拒绝 Promise,不能当作空凭据或保存/退出成功。Web 入口应选择 api-client 的 Cookie/内存存储。
51
+
52
+ `clear()` 一开始就屏蔽本实例两类旧凭据,并等待所有原生删除结束后才报告结果;失败时保持屏蔽,相应 key 成功写入后才重新开放。通过 `apiClient.auth` 更新凭据以串行提交写入,并处理 `setTokens()` / `clear()` 的拒绝;界面仍须释放 loading、清理退出身份并提示失败。屏蔽只作用于当前适配器实例,不代表持久数据已删除,跨重启撤销依赖服务端退出/撤销会话。插件恢复后可以用同一实例重试,无需重建模块。
47
53
 
48
- ### 设备信息与推送
54
+ 任一凭据写入失败都会屏蔽整对凭据,因此 access 已保存而 refresh 保存失败时也不会留下可读的半完成会话。登录/注册保存失败后应尝试 `auth.clear()` 清理部分持久数据;清理再次失败须明确提示,不得声称设备凭据已删除。
55
+
56
+ #### 设备信息与推送
49
57
 
50
58
  ```ts
51
59
  import { capacitor } from '@h-ai/capacitor'
@@ -61,7 +69,9 @@ if (reg.success) {
61
69
  }
62
70
  ```
63
71
 
64
- ### 状态栏
72
+ 推送仅在实际原生平台调用插件。`push.register({ signal? })` 与 `push.listen(callbacks, { signal? })` 的设置阶段限时 30 秒(包含权限和监听器挂载);失败、超时、取消及 `capacitor.close()` 都会停止回调并移除本次拥有的句柄,迟到的句柄在完成后立即移除,不调用影响其他消费者的 removeAllListeners。listen 成功后信号仍有效,也可调用返回的 cleanup。cleanup 与 close 均返回 `HaiResult<void>`;原生 remove 失败返回 `PUSH_CLEANUP_FAILED`(`capacitor:032`),失败句柄保留供再次调用重试,成功移除的句柄不重复操作。模块关闭后立即不可用;重新初始化前先重试遗留清理。自动化验证控制插件时序,不能代替 Android/iOS 真机 FCM/APNs 权限、注册与反复挂载验收。
73
+
74
+ #### 状态栏
65
75
 
66
76
  ```ts
67
77
  import { capacitor } from '@h-ai/capacitor'
@@ -73,7 +83,7 @@ await capacitor.statusBar.configure({
73
83
  })
74
84
  ```
75
85
 
76
- ### 相机
86
+ #### 相机
77
87
 
78
88
  ```ts
79
89
  const photo = await capacitor.camera.takePhoto({
@@ -83,7 +93,7 @@ const photo = await capacitor.camera.takePhoto({
83
93
  })
84
94
  ```
85
95
 
86
- ### Preferences
96
+ #### Preferences
87
97
 
88
98
  ```ts
89
99
  await capacitor.preferences.set('my_key', 'value')
@@ -93,7 +103,7 @@ await capacitor.preferences.remove('my_key')
93
103
 
94
104
  `capacitor.preferences` 适合保存语言、主题、草稿等普通偏好数据;认证 Token 请使用 `createCapacitorTokenStorage()`。
95
105
 
96
- ## 配置
106
+ ### 配置
97
107
 
98
108
  本模块无配置文件。`capacitor.init()` 仅检测 Capacitor 运行环境是否可用。
99
109
 
@@ -105,9 +115,9 @@ export const prerender = true
105
115
  export const ssr = false
106
116
  ```
107
117
 
108
- ## 错误处理
118
+ ### 错误处理
109
119
 
110
- 所有异步 API 返回 `HaiResult<T>`,不会直接 throw:
120
+ `capacitor.*` 业务操作与 `safe*Preference` 返回 `HaiResult<T>`;TokenStorage 适配器方法以 Promise 拒绝报告平台与存储错误:
111
121
 
112
122
  ```ts
113
123
  import { capacitor, HaiCapacitorError } from '@h-ai/capacitor'
@@ -138,7 +148,7 @@ if (!result.success) {
138
148
  | `HaiCapacitorError.CAMERA_FAILED` | `hai:capacitor:040` | 相机操作失败 |
139
149
  | `HaiCapacitorError.STATUS_BAR_FAILED` | `hai:capacitor:050` | 状态栏操作失败 |
140
150
 
141
- ## 测试
151
+ ## 开发测试
142
152
 
143
153
  ```bash
144
154
  pnpm --filter @h-ai/capacitor test
@@ -146,6 +156,8 @@ pnpm --filter @h-ai/capacitor test
146
156
 
147
157
  > 由于原生插件依赖,测试中需 mock `@capacitor/*` 模块。
148
158
 
149
- ## License
159
+ 公开操作、内部资源作用域与类型均提供可类型检查的示例;见[模块 JSDoc 约定](../../.agents/instructions/module-conventions.md#jsdoc-与示例验证)。推送示例的类型检查不证明设备权限或 FCM/APNs 实际可用。
160
+
161
+ ## 许可证
150
162
 
151
163
  Apache-2.0