@h-ai/api-contract 0.1.0-alpha.55 → 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,109 @@
1
+ # @h-ai/api-contract
2
+
3
+ [简体中文](./README.md) | [English](./README.en.md) | [日本語](./README.ja.md)
4
+
5
+ [Framework home](../../README.en.md) · Related modules: [@h-ai/core](../core/README.en.md)
6
+
7
+ > Public HTTP API contracts for hai-framework, with oRPC contract + Zod as the single source of truth.
8
+
9
+ ## Capabilities
10
+
11
+ - `apiContract.iam`, `apiContract.storage`, `apiContract.ai`, `apiContract.payment`: domain contracts.
12
+ - `apiContract.create()`: compose enabled domain contracts for an application.
13
+ - `apiContract.route()`: define custom HTTP route metadata for reuse in application contracts.
14
+ - `apiContract.pathOf()`: read the authoritative business path from a contract procedure for middleware/client reuse.
15
+ - `apiContract.haiResultSchema()` / `apiContract.voidResultSchema` / `apiContract.paginatedSchema()`: shared DTO schema factories.
16
+ - Shared DTO schemas: every HTTP output is wrapped in `HaiResult<T>`.
17
+ - IAM token DTOs support httpOnly cookies: `refreshToken` may be absent from the response body and managed by the server through `Set-Cookie`.
18
+ - IAM `auth.currentUser` returns the user profile and the current server session's `roles` / `permissions`; clients need not persist a permission snapshot to restore a session.
19
+
20
+ ## Quick start
21
+
22
+ ```ts
23
+ import { apiContract } from '@h-ai/api-contract'
24
+
25
+ export const contract = apiContract.create({
26
+ iam: apiContract.iam,
27
+ storage: apiContract.storage,
28
+ ai: false,
29
+ })
30
+ ```
31
+
32
+ Custom application contracts also define routes through this package, without depending on `@h-ai/serv`:
33
+
34
+ ```ts
35
+ import { apiContract } from '@h-ai/api-contract'
36
+ import { z } from 'zod'
37
+
38
+ export const appContract = {
39
+ ping: apiContract
40
+ .route({ method: 'POST', path: '/app/ping', operationId: 'app.ping', tags: ['app'] })
41
+ .output(apiContract.haiResultSchema(z.object({ pong: z.boolean() }))),
42
+ }
43
+ ```
44
+
45
+ ## API contracts
46
+
47
+ ```ts
48
+ import { apiContract } from '@h-ai/api-contract'
49
+
50
+ const myContract = apiContract.create({ iam: apiContract.iam, storage: apiContract.storage, ai: apiContract.ai })
51
+
52
+ myContract.iam.auth.login
53
+ myContract.storage.presignedUrls.createUpload
54
+ myContract.ai.chats.createCompletion
55
+ ```
56
+
57
+ Clients call nested methods directly through `@h-ai/api-client`:
58
+
59
+ ```ts
60
+ import { apiClient } from '@h-ai/api-client'
61
+
62
+ await apiClient.init({ baseUrl: 'https://api.example.com/api/v1' })
63
+ const login = await apiClient.iam.auth.login({ identifier: 'alice', password: 'secret' })
64
+ await apiClient.close()
65
+ ```
66
+
67
+ Servers mount contracts through `@h-ai/serv`:
68
+
69
+ ```ts
70
+ import { apiContract } from '@h-ai/api-contract'
71
+ import { serv } from '@h-ai/serv'
72
+
73
+ const contract = apiContract.create({ iam: apiContract.iam, storage: apiContract.storage, ai: apiContract.ai })
74
+
75
+ const app = serv.createApp({
76
+ contract,
77
+ procedures,
78
+ http: { apiPrefix: '/api/v1' },
79
+ })
80
+ ```
81
+
82
+ ## API overview
83
+
84
+ - `apiContract.create(options)`: omit domains set to `false` / `undefined` and compose the application contract.
85
+ - `apiContract.route(routeConfig)`: define method/path/operationId/tags and other route metadata for a custom endpoint.
86
+ - `apiContract.pathOf(procedure)`: read the business path declared in `*-contract.ts`, without maintaining separate route constants.
87
+ - `apiContract.haiResultSchema(dataSchema)` / `apiContract.voidResultSchema` / `apiContract.paginatedSchema(itemSchema)`: shared DTO schema factories.
88
+ - `Iam*Schema` / `Storage*Schema` / `Ai*Schema` / `Payment*Schema`: inputs and data structures reused across APIs and layers.
89
+
90
+ Write each business path directly in its `*-contract.ts` file. Inline output schemas used only once in `.output(...)`; schemas reused within the same contract file may be private constants, but must not be exported from schemas.
91
+
92
+ ## Configuration
93
+
94
+ This package has no runtime configuration and does not read environment variables.
95
+
96
+ ## Error handling
97
+
98
+ Contracts describe input and output structures only. Procedures express business errors with `HaiResult<T>`, so clients need not catch business exceptions.
99
+
100
+ ## Tests
101
+
102
+ ```bash
103
+ pnpm --filter @h-ai/api-contract test
104
+ pnpm --filter @h-ai/api-contract typecheck
105
+ ```
106
+
107
+ ## License
108
+
109
+ Apache-2.0
package/README.ja.md ADDED
@@ -0,0 +1,109 @@
1
+ # @h-ai/api-contract
2
+
3
+ [简体中文](./README.md) | [English](./README.en.md) | [日本語](./README.ja.md)
4
+
5
+ [フレームワークのホーム](../../README.ja.md) · 関連モジュール:[@h-ai/core](../core/README.ja.md)
6
+
7
+ > hai-framework の公開 HTTP API 契約パッケージ。oRPC contract + Zod を唯一の定義元として使用します。
8
+
9
+ ## 機能概要
10
+
11
+ - `apiContract.iam`、`apiContract.storage`、`apiContract.ai`、`apiContract.payment`:ドメイン単位の contract。
12
+ - `apiContract.create()`:アプリケーションに必要なドメインの contract を組み合わせる。
13
+ - `apiContract.route()`:アプリケーションの contract で再利用する独自 HTTP ルートのメタデータを定義。
14
+ - `apiContract.pathOf()`:contract procedure から業務パスを取得し、middleware/client で再利用。
15
+ - `apiContract.haiResultSchema()` / `apiContract.voidResultSchema` / `apiContract.paginatedSchema()`:共通 DTO Schema のファクトリー。
16
+ - 共通 DTO Schema:すべての HTTP 出力を `HaiResult<T>` でラップ。
17
+ - IAM Token DTO は httpOnly cookie に対応。レスポンス本文に `refreshToken` が含まれない場合は、サーバーが `Set-Cookie` で管理します。
18
+ - IAM の `auth.currentUser` はユーザー情報と現在のサーバーセッションの `roles` / `permissions` を返します。セッション復元のためにクライアントが権限のスナップショットを永続化する必要はありません。
19
+
20
+ ## クイックスタート
21
+
22
+ ```ts
23
+ import { apiContract } from '@h-ai/api-contract'
24
+
25
+ export const contract = apiContract.create({
26
+ iam: apiContract.iam,
27
+ storage: apiContract.storage,
28
+ ai: false,
29
+ })
30
+ ```
31
+
32
+ 独自のアプリケーション contract も、このパッケージでルートを定義します。`@h-ai/serv` への依存は不要です:
33
+
34
+ ```ts
35
+ import { apiContract } from '@h-ai/api-contract'
36
+ import { z } from 'zod'
37
+
38
+ export const appContract = {
39
+ ping: apiContract
40
+ .route({ method: 'POST', path: '/app/ping', operationId: 'app.ping', tags: ['app'] })
41
+ .output(apiContract.haiResultSchema(z.object({ pong: z.boolean() }))),
42
+ }
43
+ ```
44
+
45
+ ## API 契約
46
+
47
+ ```ts
48
+ import { apiContract } from '@h-ai/api-contract'
49
+
50
+ const myContract = apiContract.create({ iam: apiContract.iam, storage: apiContract.storage, ai: apiContract.ai })
51
+
52
+ myContract.iam.auth.login
53
+ myContract.storage.presignedUrls.createUpload
54
+ myContract.ai.chats.createCompletion
55
+ ```
56
+
57
+ クライアントは `@h-ai/api-client` でネストしたメソッドを直接呼び出します:
58
+
59
+ ```ts
60
+ import { apiClient } from '@h-ai/api-client'
61
+
62
+ await apiClient.init({ baseUrl: 'https://api.example.com/api/v1' })
63
+ const login = await apiClient.iam.auth.login({ identifier: 'alice', password: 'secret' })
64
+ await apiClient.close()
65
+ ```
66
+
67
+ サーバーは `@h-ai/serv` で contract をマウントします:
68
+
69
+ ```ts
70
+ import { apiContract } from '@h-ai/api-contract'
71
+ import { serv } from '@h-ai/serv'
72
+
73
+ const contract = apiContract.create({ iam: apiContract.iam, storage: apiContract.storage, ai: apiContract.ai })
74
+
75
+ const app = serv.createApp({
76
+ contract,
77
+ procedures,
78
+ http: { apiPrefix: '/api/v1' },
79
+ })
80
+ ```
81
+
82
+ ## API 一覧
83
+
84
+ - `apiContract.create(options)`:`false` / `undefined` のドメインを除外し、アプリケーション contract を構成。
85
+ - `apiContract.route(routeConfig)`:独自 endpoint の method/path/operationId/tags などのルートメタデータを定義。
86
+ - `apiContract.pathOf(procedure)`:`*-contract.ts` に宣言された業務パスを取得。独立した routes 定数の管理は不要です。
87
+ - `apiContract.haiResultSchema(dataSchema)` / `apiContract.voidResultSchema` / `apiContract.paginatedSchema(itemSchema)`:共通 DTO Schema のファクトリー。
88
+ - `Iam*Schema` / `Storage*Schema` / `Ai*Schema` / `Payment*Schema`:複数の API・層で再利用する入力とデータ構造。
89
+
90
+ 業務 path は対応する `*-contract.ts` に直接記述します。一度しか使わない出力 Schema は `.output(...)` にインラインで定義します。同じ contract ファイル内で再利用する場合は非公開の定数にできますが、schemas からエクスポートしてはいけません。
91
+
92
+ ## 設定
93
+
94
+ このパッケージには実行時設定がなく、環境変数も読み込みません。
95
+
96
+ ## エラー処理
97
+
98
+ Contract は入出力構造のみを定義します。業務エラーは procedure が返す `HaiResult<T>` で表し、クライアント側で業務例外を捕捉する必要はありません。
99
+
100
+ ## テスト
101
+
102
+ ```bash
103
+ pnpm --filter @h-ai/api-contract test
104
+ pnpm --filter @h-ai/api-contract typecheck
105
+ ```
106
+
107
+ ## License
108
+
109
+ Apache-2.0
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @h-ai/api-contract
2
2
 
3
+ [简体中文](./README.md) | [English](./README.en.md) | [日本語](./README.ja.md)
4
+
5
+ [框架首页](../../README.md) · 相关模块:[@h-ai/core](../core/README.md)
6
+
3
7
  > hai-framework 的公共 HTTP API 契约包,使用 oRPC contract + Zod 作为唯一真相源。
4
8
 
5
9
  ## 能力概览
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h-ai/api-contract",
3
3
  "type": "module",
4
- "version": "0.1.0-alpha.55",
4
+ "version": "0.1.0-alpha.57",
5
5
  "description": "Hai Framework public API contracts powered by oRPC and Zod.",
6
6
  "license": "Apache-2.0",
7
7
  "exports": {
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "@orpc/contract": "^1.14.3",
43
43
  "zod": "^4.4.3",
44
- "@h-ai/core": "0.1.0-alpha.55"
44
+ "@h-ai/core": "0.1.0-alpha.57"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^25.9.1",