@h-ai/capacitor 0.1.0-alpha.56 → 0.1.0-alpha.57

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 ADDED
@@ -0,0 +1,151 @@
1
+ # @h-ai/capacitor
2
+
3
+ [简体中文](./README.md) | [English](./README.en.md) | [日本語](./README.ja.md)
4
+
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
+
7
+ 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
+
9
+ ## Capabilities
10
+
11
+ - **Token storage**: `@aparajita/capacitor-secure-storage` (required on native platforms). Android uses KeyStore + encrypted SharedPreferences; iOS uses Keychain. No Web fallback.
12
+ - **Preferences**: `@capacitor/preferences` (required). General preferences storage for nonsensitive settings, not authentication tokens.
13
+ - **Device information**: `@capacitor/device` (optional). Platform, version, and model detection.
14
+ - **App version**: `@capacitor/app` (optional). Read appVersion / appBuild.
15
+ - **Push notifications**: `@capacitor/push-notifications` (optional). Register FCM/APNs tokens and listen for push events.
16
+ - **Camera/gallery**: `@capacitor/camera` (optional). Capture photos or select gallery images.
17
+ - **Status bar**: `@capacitor/status-bar` (optional). Immersive mode, background color, and style settings.
18
+
19
+ ## Quick start
20
+
21
+ ```ts
22
+ import { capacitor } from '@h-ai/capacitor'
23
+
24
+ // 应用启动时初始化(检测 Capacitor 环境)
25
+ const result = await capacitor.init()
26
+ if (!result.success) {
27
+ // 非 Capacitor 环境(纯 Web)
28
+ }
29
+ ```
30
+
31
+ ### Secure token storage with api-client
32
+
33
+ ```ts
34
+ import { apiClient } from '@h-ai/api-client'
35
+ import { createCapacitorTokenStorage } from '@h-ai/capacitor'
36
+
37
+ await apiClient.init({
38
+ baseUrl: 'https://api.example.com/v1',
39
+ auth: {
40
+ storage: createCapacitorTokenStorage(),
41
+ refreshPath: '/auth/refresh',
42
+ },
43
+ })
44
+ ```
45
+
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.
47
+
48
+ ### Device information and push notifications
49
+
50
+ ```ts
51
+ import { capacitor } from '@h-ai/capacitor'
52
+
53
+ const info = await capacitor.device.getInfo()
54
+ if (info.success) {
55
+ // info.data.platform — 'android' | 'ios' | 'web'
56
+ }
57
+
58
+ const reg = await capacitor.push.register()
59
+ if (reg.success) {
60
+ // reg.data.token — FCM/APNs 推送 Token
61
+ }
62
+ ```
63
+
64
+ ### Status bar
65
+
66
+ ```ts
67
+ import { capacitor } from '@h-ai/capacitor'
68
+
69
+ await capacitor.statusBar.configure({
70
+ style: 'dark',
71
+ overlay: true,
72
+ backgroundColor: '#ffffff',
73
+ })
74
+ ```
75
+
76
+ ### Camera
77
+
78
+ ```ts
79
+ const photo = await capacitor.camera.takePhoto({
80
+ source: 'camera',
81
+ resultType: 'base64',
82
+ quality: 80,
83
+ })
84
+ ```
85
+
86
+ ### Preferences
87
+
88
+ ```ts
89
+ await capacitor.preferences.set('my_key', 'value')
90
+ const result = await capacitor.preferences.get('my_key')
91
+ await capacitor.preferences.remove('my_key')
92
+ ```
93
+
94
+ `capacitor.preferences` is for general preferences such as language, theme, and drafts. Use `createCapacitorTokenStorage()` for authentication tokens.
95
+
96
+ ## Configuration
97
+
98
+ This module has no configuration file. `capacitor.init()` only checks whether the Capacitor runtime is available.
99
+
100
+ Capacitor applications must use SPA mode:
101
+
102
+ ```ts
103
+ // src/routes/+layout.ts
104
+ export const prerender = true
105
+ export const ssr = false
106
+ ```
107
+
108
+ ## Error handling
109
+
110
+ All asynchronous APIs return `HaiResult<T>` instead of throwing directly:
111
+
112
+ ```ts
113
+ import { capacitor, HaiCapacitorError } from '@h-ai/capacitor'
114
+
115
+ const result = await capacitor.camera.takePhoto({ source: 'camera' })
116
+ if (!result.success) {
117
+ if (result.error.code === HaiCapacitorError.CAMERA_FAILED.code) {
118
+ // 相机权限被拒绝或插件未安装
119
+ }
120
+ }
121
+ ```
122
+
123
+ Common error codes:
124
+
125
+ | Error code | code | Description |
126
+ | --------------------------------------------- | ------------------- | ----------------------------------- |
127
+ | `HaiCapacitorError.INIT_FAILED` | `hai:capacitor:001` | Initialization failed |
128
+ | `HaiCapacitorError.NOT_AVAILABLE` | `hai:capacitor:002` | Capability unavailable |
129
+ | `HaiCapacitorError.INIT_IN_PROGRESS` | `hai:capacitor:003` | Initialization in progress |
130
+ | `HaiCapacitorError.NOT_INITIALIZED` | `hai:capacitor:010` | Not initialized |
131
+ | `HaiCapacitorError.PREFERENCES_GET_FAILED` | `hai:capacitor:011` | Preferences read failed |
132
+ | `HaiCapacitorError.PREFERENCES_SET_FAILED` | `hai:capacitor:012` | Preferences write failed |
133
+ | `HaiCapacitorError.PREFERENCES_REMOVE_FAILED` | `hai:capacitor:013` | Preferences removal failed |
134
+ | `HaiCapacitorError.DEVICE_INFO_FAILED` | `hai:capacitor:020` | Device information retrieval failed |
135
+ | `HaiCapacitorError.APP_VERSION_FAILED` | `hai:capacitor:021` | App version retrieval failed |
136
+ | `HaiCapacitorError.PUSH_REGISTER_FAILED` | `hai:capacitor:030` | Push registration failed |
137
+ | `HaiCapacitorError.PUSH_LISTEN_FAILED` | `hai:capacitor:031` | Push listener failed |
138
+ | `HaiCapacitorError.CAMERA_FAILED` | `hai:capacitor:040` | Camera operation failed |
139
+ | `HaiCapacitorError.STATUS_BAR_FAILED` | `hai:capacitor:050` | Status bar operation failed |
140
+
141
+ ## Tests
142
+
143
+ ```bash
144
+ pnpm --filter @h-ai/capacitor test
145
+ ```
146
+
147
+ > Tests must mock `@capacitor/*` modules because they depend on native plugins.
148
+
149
+ ## License
150
+
151
+ Apache-2.0
package/README.ja.md ADDED
@@ -0,0 +1,151 @@
1
+ # @h-ai/capacitor
2
+
3
+ [简体中文](./README.md) | [English](./README.en.md) | [日本語](./README.ja.md)
4
+
5
+ [フレームワークのホーム](../../README.ja.md) · 関連モジュール:[@h-ai/api-client](../api-client/README.ja.md) · [@h-ai/core](../core/README.ja.md)
6
+
7
+ hai Framework のモバイルアプリ向け Capacitor ネイティブブリッジ。安全な Token ストレージ、端末情報、プッシュ通知、カメラ、ステータスバーを共通 API で提供します。
8
+
9
+ ## 主な機能
10
+
11
+ - **Token ストレージ**:`@aparajita/capacitor-secure-storage`(ネイティブで必須)。Android は KeyStore + 暗号化 SharedPreferences、iOS は Keychain を使用。Web へのフォールバックはありません。
12
+ - **Preferences**:`@capacitor/preferences`(必須)。機密情報を含まない一般設定の保存用で、認証 Token には使用しません。
13
+ - **端末情報**:`@capacitor/device`(任意)。プラットフォーム、バージョン、機種を取得。
14
+ - **アプリバージョン**:`@capacitor/app`(任意)。appVersion / appBuild を取得。
15
+ - **プッシュ通知**:`@capacitor/push-notifications`(任意)。FCM/APNs Token の登録と通知イベントの監視。
16
+ - **カメラ/アルバム**:`@capacitor/camera`(任意)。撮影とアルバム画像の選択。
17
+ - **ステータスバー**:`@capacitor/status-bar`(任意)。没入型表示、背景色、スタイルの設定。
18
+
19
+ ## クイックスタート
20
+
21
+ ```ts
22
+ import { capacitor } from '@h-ai/capacitor'
23
+
24
+ // 应用启动时初始化(检测 Capacitor 环境)
25
+ const result = await capacitor.init()
26
+ if (!result.success) {
27
+ // 非 Capacitor 环境(纯 Web)
28
+ }
29
+ ```
30
+
31
+ ### api-client と連携する安全な Token ストレージ
32
+
33
+ ```ts
34
+ import { apiClient } from '@h-ai/api-client'
35
+ import { createCapacitorTokenStorage } from '@h-ai/capacitor'
36
+
37
+ await apiClient.init({
38
+ baseUrl: 'https://api.example.com/v1',
39
+ auth: {
40
+ storage: createCapacitorTokenStorage(),
41
+ refreshPath: '/auth/refresh',
42
+ },
43
+ })
44
+ ```
45
+
46
+ `createCapacitorTokenStorage()` は Android/iOS のネイティブ環境でのみ Token を永続化し、`@aparajita/capacitor-secure-storage` が必要です。Web では `localStorage` に切り替わらず、`get*()` は `null` を返し、`set*()` / `clear()` は何もしません。
47
+
48
+ ### 端末情報とプッシュ通知
49
+
50
+ ```ts
51
+ import { capacitor } from '@h-ai/capacitor'
52
+
53
+ const info = await capacitor.device.getInfo()
54
+ if (info.success) {
55
+ // info.data.platform — 'android' | 'ios' | 'web'
56
+ }
57
+
58
+ const reg = await capacitor.push.register()
59
+ if (reg.success) {
60
+ // reg.data.token — FCM/APNs 推送 Token
61
+ }
62
+ ```
63
+
64
+ ### ステータスバー
65
+
66
+ ```ts
67
+ import { capacitor } from '@h-ai/capacitor'
68
+
69
+ await capacitor.statusBar.configure({
70
+ style: 'dark',
71
+ overlay: true,
72
+ backgroundColor: '#ffffff',
73
+ })
74
+ ```
75
+
76
+ ### カメラ
77
+
78
+ ```ts
79
+ const photo = await capacitor.camera.takePhoto({
80
+ source: 'camera',
81
+ resultType: 'base64',
82
+ quality: 80,
83
+ })
84
+ ```
85
+
86
+ ### Preferences
87
+
88
+ ```ts
89
+ await capacitor.preferences.set('my_key', 'value')
90
+ const result = await capacitor.preferences.get('my_key')
91
+ await capacitor.preferences.remove('my_key')
92
+ ```
93
+
94
+ `capacitor.preferences` は言語、テーマ、下書きなどの一般的な設定用です。認証 Token には `createCapacitorTokenStorage()` を使用してください。
95
+
96
+ ## 設定
97
+
98
+ このモジュールに設定ファイルはありません。`capacitor.init()` は Capacitor の実行環境が利用可能かどうかのみを確認します。
99
+
100
+ Capacitor アプリケーションは SPA モードを使用してください:
101
+
102
+ ```ts
103
+ // src/routes/+layout.ts
104
+ export const prerender = true
105
+ export const ssr = false
106
+ ```
107
+
108
+ ## エラー処理
109
+
110
+ すべての非同期 API は直接 throw せず、`HaiResult<T>` を返します:
111
+
112
+ ```ts
113
+ import { capacitor, HaiCapacitorError } from '@h-ai/capacitor'
114
+
115
+ const result = await capacitor.camera.takePhoto({ source: 'camera' })
116
+ if (!result.success) {
117
+ if (result.error.code === HaiCapacitorError.CAMERA_FAILED.code) {
118
+ // 相机权限被拒绝或插件未安装
119
+ }
120
+ }
121
+ ```
122
+
123
+ 主なエラーコード:
124
+
125
+ | エラーコード | code | 説明 |
126
+ | --------------------------------------------- | ------------------- | ---------------------------- |
127
+ | `HaiCapacitorError.INIT_FAILED` | `hai:capacitor:001` | 初期化に失敗 |
128
+ | `HaiCapacitorError.NOT_AVAILABLE` | `hai:capacitor:002` | 機能が利用できない |
129
+ | `HaiCapacitorError.INIT_IN_PROGRESS` | `hai:capacitor:003` | 初期化中 |
130
+ | `HaiCapacitorError.NOT_INITIALIZED` | `hai:capacitor:010` | 未初期化 |
131
+ | `HaiCapacitorError.PREFERENCES_GET_FAILED` | `hai:capacitor:011` | Preferences の読み取りに失敗 |
132
+ | `HaiCapacitorError.PREFERENCES_SET_FAILED` | `hai:capacitor:012` | Preferences の書き込みに失敗 |
133
+ | `HaiCapacitorError.PREFERENCES_REMOVE_FAILED` | `hai:capacitor:013` | Preferences の削除に失敗 |
134
+ | `HaiCapacitorError.DEVICE_INFO_FAILED` | `hai:capacitor:020` | 端末情報の取得に失敗 |
135
+ | `HaiCapacitorError.APP_VERSION_FAILED` | `hai:capacitor:021` | アプリバージョンの取得に失敗 |
136
+ | `HaiCapacitorError.PUSH_REGISTER_FAILED` | `hai:capacitor:030` | プッシュ登録に失敗 |
137
+ | `HaiCapacitorError.PUSH_LISTEN_FAILED` | `hai:capacitor:031` | プッシュ通知の監視に失敗 |
138
+ | `HaiCapacitorError.CAMERA_FAILED` | `hai:capacitor:040` | カメラ操作に失敗 |
139
+ | `HaiCapacitorError.STATUS_BAR_FAILED` | `hai:capacitor:050` | ステータスバー操作に失敗 |
140
+
141
+ ## テスト
142
+
143
+ ```bash
144
+ pnpm --filter @h-ai/capacitor test
145
+ ```
146
+
147
+ > ネイティブプラグインへの依存があるため、テストでは `@capacitor/*` モジュールを mock する必要があります。
148
+
149
+ ## License
150
+
151
+ Apache-2.0
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @h-ai/capacitor
2
2
 
3
+ [简体中文](./README.md) | [English](./README.en.md) | [日本語](./README.ja.md)
4
+
5
+ [框架首页](../../README.md) · 相关模块:[@h-ai/api-client](../api-client/README.md) · [@h-ai/core](../core/README.md)
6
+
3
7
  Capacitor 原生桥接模块,为 hai Framework 移动应用提供原生安全 Token 存储、设备信息、推送通知、相机与状态栏等能力的统一封装。
4
8
 
5
9
  ## 支持的能力
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h-ai/capacitor",
3
3
  "type": "module",
4
- "version": "0.1.0-alpha.56",
4
+ "version": "0.1.0-alpha.57",
5
5
  "description": "Hai Framework Capacitor bridge module for native mobile capabilities.",
6
6
  "license": "Apache-2.0",
7
7
  "exports": {
@@ -47,8 +47,8 @@
47
47
  }
48
48
  },
49
49
  "dependencies": {
50
- "@h-ai/api-client": "0.1.0-alpha.56",
51
- "@h-ai/core": "0.1.0-alpha.56"
50
+ "@h-ai/api-client": "0.1.0-alpha.57",
51
+ "@h-ai/core": "0.1.0-alpha.57"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@aparajita/capacitor-secure-storage": "^8.0.0",