@vtecx/vtecxdocument 1.0.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.
@@ -0,0 +1,259 @@
1
+ # vtecxnext API クイックリファレンス
2
+
3
+ `@vtecx/vtecxnext` SDK の **よく使うメソッドの抜粋と実装例** です。
4
+ アプリ実装でまず参照する入口として使ってください。
5
+
6
+ > **全メソッドの網羅リファレンスは [api/](api/index.md) を参照してください。**
7
+ > シグネチャ・引数・戻り値・型定義はカテゴリ別ファイル(`api/*.md`)に集約しています。
8
+ > このファイルは重複を避け、頻出メソッドの使い方に絞っています。
9
+
10
+ 公式リファレンス: https://zenn.dev/vtecx/articles/6a02ab2440ef05
11
+
12
+ | カテゴリ | 網羅リファレンス |
13
+ | --- | --- |
14
+ | 認証・セッション | [api/auth.md](api/auth.md) |
15
+ | データ操作(取得・登録・削除・ページング) | [api/data.md](api/data.md) |
16
+ | ユーザー管理 | [api/user.md](api/user.md) |
17
+ | グループ管理 | [api/group.md](api/group.md) |
18
+ | 採番・カウンタ | [api/counter.md](api/counter.md) |
19
+ | サーバーセッション | [api/session.md](api/session.md) |
20
+ | コンテンツ・ファイル | [api/content.md](api/content.md) |
21
+ | メール・通知 | [api/notify.md](api/notify.md) |
22
+ | 外部DB連携(BigQuery / RDB) | [api/db.md](api/db.md) |
23
+ | PDF・署名 | [api/pdf.md](api/pdf.md) |
24
+ | OAuth・TOTP | [api/oauth.md](api/oauth.md) |
25
+ | ACL・エイリアス | [api/acl.md](api/acl.md) |
26
+ | ユーティリティ | [api/util.md](api/util.md) |
27
+
28
+ ---
29
+
30
+ ## 初期化
31
+
32
+ ```typescript
33
+ import { VtecxNext } from '@vtecx/vtecxnext'
34
+
35
+ // Next.js API Route 内で初期化
36
+ export const GET = async (req: NextRequest): Promise<Response> => {
37
+ const vtecxnext = new VtecxNext(req)
38
+ // ...
39
+ }
40
+ ```
41
+
42
+ コンストラクタは `req?: NextRequest` と `accessToken?: string` を受け取る。
43
+
44
+ ---
45
+
46
+ ## 認証・セッション情報の取得
47
+
48
+ → 一覧は [api/auth.md](api/auth.md)
49
+
50
+ ```typescript
51
+ const uid = await vtecxnext.uid() // ログインユーザーの UID(未ログインはエラー)
52
+ const email = await vtecxnext.account() // アカウント名(メールアドレス)
53
+ const serviceName = await vtecxnext.service() // サービス名
54
+
55
+ const loggedIn = await vtecxnext.isLoggedin()
56
+ if (!loggedIn) {
57
+ return vtecxnext.response(401, { feed: { title: 'Unauthorized.' } })
58
+ }
59
+ ```
60
+
61
+ ---
62
+
63
+ ## データ取得
64
+
65
+ → 一覧・戻り値の型は [api/data.md](api/data.md)
66
+
67
+ ```typescript
68
+ // 一覧(ページング不要)。データなしは null / undefined(204)
69
+ const entries = await vtecxnext.getFeed('/crm/customer')
70
+
71
+ // 1件取得。データなしは null(204)
72
+ const entry = await vtecxnext.getEntry('/crm/customer/0000000001')
73
+
74
+ // 件数取得。0件は null
75
+ const total = await vtecxnext.count('/crm/customer?f&customer.status-eq-active')
76
+ ```
77
+
78
+ ### ページング
79
+
80
+ `getPageWithPagination` が「カーソル作成 → ページ取得」の2ステップを内部で自動処理する。
81
+
82
+ ```typescript
83
+ const n = parseInt(vtecxnext.getParameter('n') ?? '1', 10)
84
+ const entries = await vtecxnext.getPageWithPagination('/crm/customer?l=25', n)
85
+ // n=1 のとき自動的に pagination() を呼び出す。データなし: undefined
86
+ ```
87
+
88
+ カーソルを手動作成する場合は `pagination()`。
89
+
90
+ ```typescript
91
+ const info = await vtecxnext.pagination('/crm/customer?l=25', '1,50')
92
+ // info.lastPageNumber: 最終ページ番号(0 = データなし)
93
+ // info.hasNext: true = 50ページ以降にもデータがある
94
+ ```
95
+
96
+ ---
97
+
98
+ ## データ登録・更新
99
+
100
+ → 一覧は [api/data.md](api/data.md) / まとめ方の方針は [framework.md](framework.md#データ登録更新)
101
+
102
+ `post` はキーを自動採番、`put` はキー(`link` の `___href`)を指定して登録・更新する。
103
+ **複数エントリは1回の `put()` にまとめること。**
104
+
105
+ ```typescript
106
+ // post: uri 配下に自動採番して登録
107
+ await vtecxnext.post({
108
+ feed: {
109
+ entry: [{
110
+ customer: { name: '株式会社テスト' },
111
+ contributor: [{ uri: 'urn:vte.cx:acl:/_group/$admin,CURD' }],
112
+ }]
113
+ }
114
+ }, '/crm/customer')
115
+
116
+ // put: キーを指定して登録・更新
117
+ await vtecxnext.put({
118
+ feed: {
119
+ entry: [
120
+ {
121
+ link: [{ ___rel: 'self', ___href: '/crm/customer/0000000001' }],
122
+ customer: { name: '株式会社テスト', status: 'active' },
123
+ contributor: [
124
+ { uri: 'urn:vte.cx:acl:/_group/$admin,CURD' },
125
+ { uri: `urn:vte.cx:acl:${uid},CURD` },
126
+ ],
127
+ },
128
+ ]
129
+ }
130
+ })
131
+ ```
132
+
133
+ ---
134
+
135
+ ## データ削除
136
+
137
+ → 一覧は [api/data.md](api/data.md)
138
+
139
+ ```typescript
140
+ // 1件削除(revision を渡すと競合チェックあり)
141
+ await vtecxnext.deleteEntry('/crm/customer/0000000001')
142
+
143
+ // 複数一括削除
144
+ await vtecxnext.deleteEntries({
145
+ feed: {
146
+ entry: [
147
+ { link: [{ ___rel: 'self', ___href: '/crm/customer/0000000001' }] },
148
+ { link: [{ ___rel: 'self', ___href: '/crm/customer/0000000002' }] },
149
+ ]
150
+ }
151
+ })
152
+ ```
153
+
154
+ ---
155
+
156
+ ## パスワード変更
157
+
158
+ → 一覧は [api/user.md](api/user.md) / 2フローの詳細は [framework.md](framework.md#パスワード変更)
159
+
160
+ ```typescript
161
+ // ログイン済みフロー(現在のパスワードで変更)
162
+ await vtecxnext.changepass(newpswd, oldpswd)
163
+
164
+ // メールリセットフロー(未ログイン)
165
+ await vtecxnext.loginWithRxid(rxid)
166
+ await vtecxnext.changepass(newpswd, undefined, passresetToken)
167
+ ```
168
+
169
+ パスワードは `getHashpass(password)`(`@vtecx/vtecxauth`)でハッシュしてから渡す。
170
+
171
+ ---
172
+
173
+ ## 採番・カウンタ
174
+
175
+ → 一覧は [api/counter.md](api/counter.md)
176
+
177
+ ```typescript
178
+ // 連番採番("開始,終了" 形式の文字列を返す)
179
+ const range = await vtecxnext.allocids('/crm/customer/_ids', 1)
180
+ const id = range.split(',')[0].padStart(10, '0') // "0000000042"
181
+
182
+ // カウンタ加算・参照
183
+ const count = await vtecxnext.addids('/crm/counter', 1)
184
+ const current = await vtecxnext.getids('/crm/counter')
185
+ ```
186
+
187
+ ---
188
+
189
+ ## グループ管理
190
+
191
+ → 一覧は [api/group.md](api/group.md) / グループ設計は [framework.md](framework.md#グループ管理)
192
+
193
+ ```typescript
194
+ const isAdmin = await vtecxnext.isAdmin()
195
+ // isGroupMember('/_group/$admin') の省略形。true: 所属, false: 非所属
196
+
197
+ const isSales = await vtecxnext.isGroupMember('/_group/sales')
198
+ ```
199
+
200
+ ---
201
+
202
+ ## ユーティリティ
203
+
204
+ → 一覧は [api/util.md](api/util.md)
205
+
206
+ ```typescript
207
+ // クエリパラメータ取得
208
+ const rxid = vtecxnext.getParameter('_RXID') ?? ''
209
+ const page = parseInt(vtecxnext.getParameter('n') ?? '1', 10)
210
+
211
+ // CSRF 対策(API ルートの先頭で必ず呼ぶ)
212
+ const result = vtecxnext.checkXRequestedWith()
213
+ if (result) return result
214
+
215
+ // レスポンス生成
216
+ return vtecxnext.response(200, { feed: { title: 'ok' } })
217
+ return vtecxnext.response(401, { feed: { title: 'Unauthorized.' } })
218
+
219
+ // ログ登録(title デフォルト: 'JavaScript')
220
+ await vtecxnext.log('処理完了', 'MyApp', 'INFO')
221
+ ```
222
+
223
+ ---
224
+
225
+ ## @vtecx/vtecxauth
226
+
227
+ クライアントサイド(ブラウザ)向けユーティリティ。
228
+
229
+ ```typescript
230
+ import { getHashpass } from '@vtecx/vtecxauth'
231
+
232
+ const hashedPassword = getHashpass(rawPassword)
233
+ // パスワードをハッシュ化(API 送信前に使用)
234
+ ```
235
+
236
+ ---
237
+
238
+ ## エラーハンドリング
239
+
240
+ エラー時の戻り値: `{ feed: { title: string } }`
241
+
242
+ ```typescript
243
+ try {
244
+ const entries = await vtecxnext.getFeed('/crm/customer')
245
+ return vtecxnext.response(200, { feed: { entry: entries } })
246
+ } catch (e) {
247
+ return apiutil.responseError(e, 'api customers')
248
+ }
249
+ ```
250
+
251
+ エラー型判定:
252
+
253
+ ```typescript
254
+ import { isVtecxNextError } from '@vtecx/vtecxnext'
255
+
256
+ if (isVtecxNextError(e)) {
257
+ // e.status / e.message でステータス・メッセージ取得
258
+ }
259
+ ```
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@vtecx/vtecxdocument",
3
+ "version": "1.0.0",
4
+ "description": "vte.cx BaaS framework and API documentation",
5
+ "main": "",
6
+ "files": [
7
+ "docs"
8
+ ],
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/reflexworks/vtecxdocument.git"
12
+ },
13
+ "keywords": [
14
+ "vtecx",
15
+ "documentation",
16
+ "api"
17
+ ],
18
+ "author": "",
19
+ "license": "ISC",
20
+ "bugs": {
21
+ "url": "https://github.com/reflexworks/vtecxdocument/issues"
22
+ },
23
+ "homepage": "https://github.com/reflexworks/vtecxdocument#readme"
24
+ }