@takuhon/vercel 0.19.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/LICENSE +202 -0
- package/NOTICE +10 -0
- package/README.md +88 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Takuhon contributors
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
@takuhon/vercel
|
|
2
|
+
Copyright 2026 Takuhon contributors
|
|
3
|
+
|
|
4
|
+
This product includes software developed by the Takuhon project
|
|
5
|
+
(https://github.com/takuhon-dev/takuhon).
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
8
|
+
|
|
9
|
+
Third-party dependencies retain their own licenses; see this package's
|
|
10
|
+
node_modules listing for details.
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @takuhon/vercel
|
|
2
|
+
|
|
3
|
+
Read-only [Vercel](https://vercel.com/) adapter for [takuhon](https://github.com/takuhon-dev/takuhon).
|
|
4
|
+
|
|
5
|
+
It publishes a profile on Vercel by mounting the framework-agnostic public app
|
|
6
|
+
from [`@takuhon/api`](https://www.npmjs.com/package/@takuhon/api) on the Vercel
|
|
7
|
+
runtime: the server-rendered profile page (with embedded Schema.org JSON-LD),
|
|
8
|
+
the public read API, and the canonical `takuhon.json`. There is **no database,
|
|
9
|
+
admin UI, or auth** — you edit `takuhon.json` in Git, push, and Vercel
|
|
10
|
+
redeploys.
|
|
11
|
+
|
|
12
|
+
## What it serves
|
|
13
|
+
|
|
14
|
+
- `GET /` and `GET /<locale>/` — the server-rendered profile page with JSON-LD
|
|
15
|
+
- `GET /api/profile` · `GET /api/jsonld` · `GET /api/schema`
|
|
16
|
+
- `GET /takuhon.json` · `GET /.well-known/takuhon.json`
|
|
17
|
+
- `GET /health`
|
|
18
|
+
|
|
19
|
+
The same public privacy filter as every other surface is applied, so
|
|
20
|
+
`settings.publicVisibility` and the field-level controls behave identically to a
|
|
21
|
+
Cloudflare deployment.
|
|
22
|
+
|
|
23
|
+
### Not included (use the Cloudflare adapter for these)
|
|
24
|
+
|
|
25
|
+
Image uploads (`/assets/*`), the MCP endpoint (`/mcp`), and the activity badge /
|
|
26
|
+
sync (`/activity.svg`, cron) are Cloudflare-only. On Vercel, `GET /api/activity`
|
|
27
|
+
answers `404` and the discovery document omits `mcp`.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @takuhon/vercel
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick start (Next.js App Router)
|
|
36
|
+
|
|
37
|
+
Add a catch-all route that mounts the app, and bundle your `takuhon.json`:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// app/[[...route]]/route.ts
|
|
41
|
+
import { createTakuhonVercelApp, BundledTakuhonStorage } from '@takuhon/vercel';
|
|
42
|
+
import { handle } from 'hono/vercel';
|
|
43
|
+
import profile from '../../takuhon.json';
|
|
44
|
+
|
|
45
|
+
const app = createTakuhonVercelApp({ storage: new BundledTakuhonStorage(profile) });
|
|
46
|
+
|
|
47
|
+
export const GET = handle(app);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
// vercel.json
|
|
52
|
+
{ "framework": "nextjs" }
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
That's it — `vercel deploy` publishes the profile. To change it, edit
|
|
56
|
+
`takuhon.json`, commit, and push.
|
|
57
|
+
|
|
58
|
+
## Data source
|
|
59
|
+
|
|
60
|
+
The canonical `takuhon.json` can come from two places:
|
|
61
|
+
|
|
62
|
+
- **Bundled (default).** Import the file and pass it to `BundledTakuhonStorage`,
|
|
63
|
+
as above. The document is validated once at startup, so an invalid profile
|
|
64
|
+
fails fast.
|
|
65
|
+
- **Fetched from a URL.** Set `TAKUHON_DATA_URL` and use `UrlTakuhonStorage`; the
|
|
66
|
+
profile is fetched once per serverless instance and cached.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { createTakuhonVercelApp, UrlTakuhonStorage } from '@takuhon/vercel';
|
|
70
|
+
import { handle } from 'hono/vercel';
|
|
71
|
+
|
|
72
|
+
const app = createTakuhonVercelApp({
|
|
73
|
+
storage: new UrlTakuhonStorage(process.env.TAKUHON_DATA_URL!),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const GET = handle(app);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API
|
|
80
|
+
|
|
81
|
+
- `createTakuhonVercelApp({ storage, fallback? })` — returns a [Hono](https://hono.dev/)
|
|
82
|
+
app to mount with `hono/vercel`'s `handle`.
|
|
83
|
+
- `BundledTakuhonStorage(profile)` — read-only storage over an in-memory profile.
|
|
84
|
+
- `UrlTakuhonStorage(url, { fetch? })` — read-only storage fetched once from `url`.
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
Apache-2.0. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { PublicAppDeps } from '@takuhon/api';
|
|
2
|
+
import { Hono } from 'hono';
|
|
3
|
+
import { TakuhonStorage, Takuhon } from '@takuhon/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Read-only profile storage for the Vercel adapter.
|
|
7
|
+
*
|
|
8
|
+
* The Vercel adapter publishes a profile without a database: the canonical
|
|
9
|
+
* `takuhon.json` is either bundled into the repository or fetched once from
|
|
10
|
+
* `TAKUHON_DATA_URL`. Both are read-only — the public surface only ever calls
|
|
11
|
+
* `getProfile()`. Writes are unsupported, so the optimistic-locking
|
|
12
|
+
* `saveProfile` / `deleteProfile` methods reject; editing goes through Git
|
|
13
|
+
* (edit `takuhon.json`, push, let Vercel redeploy).
|
|
14
|
+
*
|
|
15
|
+
* Each storage validates its document so a malformed profile fails fast — at
|
|
16
|
+
* construction for the bundled case, at first request for the URL case — rather
|
|
17
|
+
* than surfacing a confusing render error later.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A read-only {@link TakuhonStorage} backed by an in-memory profile document,
|
|
22
|
+
* typically the repository's bundled `takuhon.json`.
|
|
23
|
+
*
|
|
24
|
+
* The document is validated once at construction, so an invalid profile throws
|
|
25
|
+
* at cold start instead of on the first request.
|
|
26
|
+
*/
|
|
27
|
+
declare class BundledTakuhonStorage implements TakuhonStorage {
|
|
28
|
+
#private;
|
|
29
|
+
constructor(profile: unknown);
|
|
30
|
+
getProfile(): Promise<{
|
|
31
|
+
data: Takuhon;
|
|
32
|
+
version: string;
|
|
33
|
+
}>;
|
|
34
|
+
saveProfile(): Promise<{
|
|
35
|
+
version: string;
|
|
36
|
+
}>;
|
|
37
|
+
deleteProfile(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/** Options for {@link UrlTakuhonStorage}. */
|
|
40
|
+
interface UrlTakuhonStorageOptions {
|
|
41
|
+
/** HTTP client. Defaults to the global `fetch`. Injectable for tests. */
|
|
42
|
+
fetch?: typeof fetch;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A read-only {@link TakuhonStorage} that fetches the profile once from a URL
|
|
46
|
+
* (`TAKUHON_DATA_URL`) and caches it for the lifetime of the serverless
|
|
47
|
+
* instance. The fetch is lazy and de-duplicated: concurrent first calls share a
|
|
48
|
+
* single in-flight request, and a failed fetch clears the cache so a later
|
|
49
|
+
* request can retry.
|
|
50
|
+
*/
|
|
51
|
+
declare class UrlTakuhonStorage implements TakuhonStorage {
|
|
52
|
+
#private;
|
|
53
|
+
constructor(url: string, options?: UrlTakuhonStorageOptions);
|
|
54
|
+
getProfile(): Promise<{
|
|
55
|
+
data: Takuhon;
|
|
56
|
+
version: string;
|
|
57
|
+
}>;
|
|
58
|
+
saveProfile(): Promise<{
|
|
59
|
+
version: string;
|
|
60
|
+
}>;
|
|
61
|
+
deleteProfile(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* `@takuhon/vercel` — read-only Vercel adapter for takuhon.
|
|
66
|
+
*
|
|
67
|
+
* Publishes a profile on Vercel by mounting the framework-agnostic public app
|
|
68
|
+
* from `@takuhon/api` — the server-rendered profile page (with embedded
|
|
69
|
+
* JSON-LD), the public read API (`/api/profile`, `/api/jsonld`, `/api/schema`),
|
|
70
|
+
* and `GET /takuhon.json` / `/.well-known/takuhon.json` — on the Vercel
|
|
71
|
+
* runtime. It carries no database, admin UI, or auth: the canonical
|
|
72
|
+
* `takuhon.json` is bundled into the repository or fetched from
|
|
73
|
+
* `TAKUHON_DATA_URL`, and editing happens through Git (edit, push, redeploy).
|
|
74
|
+
*
|
|
75
|
+
* Cloudflare-only surfaces are intentionally absent: image uploads
|
|
76
|
+
* (`/assets/*`), the MCP endpoint (`/mcp`), and the activity badge / sync
|
|
77
|
+
* (`/activity.svg`, cron). `createPublicApp` answers 404 for `GET /api/activity`
|
|
78
|
+
* when no activity snapshot is supplied, and omits `mcp` from the discovery
|
|
79
|
+
* document, so a Vercel deployment never advertises an endpoint it does not
|
|
80
|
+
* host.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Options for {@link createTakuhonVercelApp}: a read-only subset of
|
|
85
|
+
* {@link PublicAppDeps}. Only `storage` (required) and `fallback` (optional)
|
|
86
|
+
* are accepted; `activityStorage` and `mcpPath` are deliberately omitted
|
|
87
|
+
* because those surfaces are not part of a read-only Vercel deployment.
|
|
88
|
+
*/
|
|
89
|
+
interface CreateTakuhonVercelAppOptions {
|
|
90
|
+
/** Read-only profile source (e.g. {@link BundledTakuhonStorage}). */
|
|
91
|
+
storage: PublicAppDeps['storage'];
|
|
92
|
+
/**
|
|
93
|
+
* Profile returned when `storage` reports {@link import('@takuhon/core').NotFoundError}.
|
|
94
|
+
* Rarely needed for the bundled case, where the document is always present.
|
|
95
|
+
*/
|
|
96
|
+
fallback?: PublicAppDeps['fallback'];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Build the Hono app for a read-only Vercel deployment.
|
|
100
|
+
*
|
|
101
|
+
* Mount it with `hono/vercel`'s `handle` in an App Router catch-all route:
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* // app/[[...route]]/route.ts
|
|
105
|
+
* import { createTakuhonVercelApp, BundledTakuhonStorage } from '@takuhon/vercel';
|
|
106
|
+
* import { handle } from 'hono/vercel';
|
|
107
|
+
* import profile from '../../takuhon.json';
|
|
108
|
+
*
|
|
109
|
+
* const app = createTakuhonVercelApp({ storage: new BundledTakuhonStorage(profile) });
|
|
110
|
+
* export const GET = handle(app);
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* The top-level router sets the same `getPath` as the public app so that
|
|
114
|
+
* locale-prefixed URLs (e.g. `/ja/api/profile`) dispatch correctly: Hono
|
|
115
|
+
* flattens a `route()`d sub-app into the parent and dispatches using the
|
|
116
|
+
* parent's `getPath`, so it must be set here too — setting it only inside
|
|
117
|
+
* `createPublicApp` is honored for direct `app.fetch()` but not once mounted.
|
|
118
|
+
*/
|
|
119
|
+
declare function createTakuhonVercelApp(options: CreateTakuhonVercelAppOptions): Hono;
|
|
120
|
+
|
|
121
|
+
export { BundledTakuhonStorage, type CreateTakuhonVercelAppOptions, UrlTakuhonStorage, type UrlTakuhonStorageOptions, createTakuhonVercelApp };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createPublicApp, localePrefixGetPath } from "@takuhon/api";
|
|
3
|
+
import { Hono } from "hono";
|
|
4
|
+
|
|
5
|
+
// src/storage.ts
|
|
6
|
+
import { validate } from "@takuhon/core";
|
|
7
|
+
var READ_ONLY_VERSION = "read-only";
|
|
8
|
+
var ReadOnlyError = class extends Error {
|
|
9
|
+
constructor() {
|
|
10
|
+
super("The Vercel adapter is read-only. Edit takuhon.json and redeploy to publish changes.");
|
|
11
|
+
this.name = "ReadOnlyError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function assertValid(profile, source) {
|
|
15
|
+
const result = validate(profile);
|
|
16
|
+
if (!result.ok) {
|
|
17
|
+
const detail = result.errors.map((e) => `${e.pointer || "/"}: ${e.message}`).join("; ");
|
|
18
|
+
throw new Error(`${source} is not a valid takuhon profile: ${detail}`);
|
|
19
|
+
}
|
|
20
|
+
return result.data;
|
|
21
|
+
}
|
|
22
|
+
var BundledTakuhonStorage = class {
|
|
23
|
+
#profile;
|
|
24
|
+
constructor(profile) {
|
|
25
|
+
this.#profile = assertValid(profile, "Bundled takuhon.json");
|
|
26
|
+
}
|
|
27
|
+
getProfile() {
|
|
28
|
+
return Promise.resolve({ data: this.#profile, version: READ_ONLY_VERSION });
|
|
29
|
+
}
|
|
30
|
+
saveProfile() {
|
|
31
|
+
return Promise.reject(new ReadOnlyError());
|
|
32
|
+
}
|
|
33
|
+
deleteProfile() {
|
|
34
|
+
return Promise.reject(new ReadOnlyError());
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var UrlTakuhonStorage = class {
|
|
38
|
+
#url;
|
|
39
|
+
#fetch;
|
|
40
|
+
#cached;
|
|
41
|
+
constructor(url, options) {
|
|
42
|
+
this.#url = url;
|
|
43
|
+
this.#fetch = options?.fetch ?? fetch;
|
|
44
|
+
}
|
|
45
|
+
getProfile() {
|
|
46
|
+
this.#cached ??= this.#load().catch((e) => {
|
|
47
|
+
this.#cached = void 0;
|
|
48
|
+
throw e;
|
|
49
|
+
});
|
|
50
|
+
return this.#cached;
|
|
51
|
+
}
|
|
52
|
+
async #load() {
|
|
53
|
+
const res = await this.#fetch(this.#url);
|
|
54
|
+
if (!res.ok) {
|
|
55
|
+
throw new Error(`Failed to fetch TAKUHON_DATA_URL (${this.#url}): HTTP ${res.status}`);
|
|
56
|
+
}
|
|
57
|
+
const json = await res.json();
|
|
58
|
+
return { data: assertValid(json, "TAKUHON_DATA_URL profile"), version: READ_ONLY_VERSION };
|
|
59
|
+
}
|
|
60
|
+
saveProfile() {
|
|
61
|
+
return Promise.reject(new ReadOnlyError());
|
|
62
|
+
}
|
|
63
|
+
deleteProfile() {
|
|
64
|
+
return Promise.reject(new ReadOnlyError());
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/index.ts
|
|
69
|
+
function createTakuhonVercelApp(options) {
|
|
70
|
+
const app = new Hono({ getPath: localePrefixGetPath });
|
|
71
|
+
app.route("/", createPublicApp({ storage: options.storage, fallback: options.fallback }));
|
|
72
|
+
return app;
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
BundledTakuhonStorage,
|
|
76
|
+
UrlTakuhonStorage,
|
|
77
|
+
createTakuhonVercelApp
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/storage.ts"],"sourcesContent":["/**\n * `@takuhon/vercel` — read-only Vercel adapter for takuhon.\n *\n * Publishes a profile on Vercel by mounting the framework-agnostic public app\n * from `@takuhon/api` — the server-rendered profile page (with embedded\n * JSON-LD), the public read API (`/api/profile`, `/api/jsonld`, `/api/schema`),\n * and `GET /takuhon.json` / `/.well-known/takuhon.json` — on the Vercel\n * runtime. It carries no database, admin UI, or auth: the canonical\n * `takuhon.json` is bundled into the repository or fetched from\n * `TAKUHON_DATA_URL`, and editing happens through Git (edit, push, redeploy).\n *\n * Cloudflare-only surfaces are intentionally absent: image uploads\n * (`/assets/*`), the MCP endpoint (`/mcp`), and the activity badge / sync\n * (`/activity.svg`, cron). `createPublicApp` answers 404 for `GET /api/activity`\n * when no activity snapshot is supplied, and omits `mcp` from the discovery\n * document, so a Vercel deployment never advertises an endpoint it does not\n * host.\n */\n\nimport { createPublicApp, localePrefixGetPath, type PublicAppDeps } from '@takuhon/api';\nimport { Hono } from 'hono';\n\nexport { BundledTakuhonStorage, UrlTakuhonStorage } from './storage.js';\nexport type { UrlTakuhonStorageOptions } from './storage.js';\n\n/**\n * Options for {@link createTakuhonVercelApp}: a read-only subset of\n * {@link PublicAppDeps}. Only `storage` (required) and `fallback` (optional)\n * are accepted; `activityStorage` and `mcpPath` are deliberately omitted\n * because those surfaces are not part of a read-only Vercel deployment.\n */\nexport interface CreateTakuhonVercelAppOptions {\n /** Read-only profile source (e.g. {@link BundledTakuhonStorage}). */\n storage: PublicAppDeps['storage'];\n /**\n * Profile returned when `storage` reports {@link import('@takuhon/core').NotFoundError}.\n * Rarely needed for the bundled case, where the document is always present.\n */\n fallback?: PublicAppDeps['fallback'];\n}\n\n/**\n * Build the Hono app for a read-only Vercel deployment.\n *\n * Mount it with `hono/vercel`'s `handle` in an App Router catch-all route:\n *\n * ```ts\n * // app/[[...route]]/route.ts\n * import { createTakuhonVercelApp, BundledTakuhonStorage } from '@takuhon/vercel';\n * import { handle } from 'hono/vercel';\n * import profile from '../../takuhon.json';\n *\n * const app = createTakuhonVercelApp({ storage: new BundledTakuhonStorage(profile) });\n * export const GET = handle(app);\n * ```\n *\n * The top-level router sets the same `getPath` as the public app so that\n * locale-prefixed URLs (e.g. `/ja/api/profile`) dispatch correctly: Hono\n * flattens a `route()`d sub-app into the parent and dispatches using the\n * parent's `getPath`, so it must be set here too — setting it only inside\n * `createPublicApp` is honored for direct `app.fetch()` but not once mounted.\n */\nexport function createTakuhonVercelApp(options: CreateTakuhonVercelAppOptions): Hono {\n const app = new Hono({ getPath: localePrefixGetPath });\n app.route('/', createPublicApp({ storage: options.storage, fallback: options.fallback }));\n return app;\n}\n","/**\n * Read-only profile storage for the Vercel adapter.\n *\n * The Vercel adapter publishes a profile without a database: the canonical\n * `takuhon.json` is either bundled into the repository or fetched once from\n * `TAKUHON_DATA_URL`. Both are read-only — the public surface only ever calls\n * `getProfile()`. Writes are unsupported, so the optimistic-locking\n * `saveProfile` / `deleteProfile` methods reject; editing goes through Git\n * (edit `takuhon.json`, push, let Vercel redeploy).\n *\n * Each storage validates its document so a malformed profile fails fast — at\n * construction for the bundled case, at first request for the URL case — rather\n * than surfacing a confusing render error later.\n */\n\nimport { validate, type Takuhon, type TakuhonStorage } from '@takuhon/core';\n\n/**\n * Opaque version token for a read-only profile. Reads never use optimistic\n * locking, so a constant is sufficient (it only feeds response ETags).\n */\nconst READ_ONLY_VERSION = 'read-only';\n\n/** Raised when a write is attempted against the read-only Vercel adapter. */\nclass ReadOnlyError extends Error {\n constructor() {\n super('The Vercel adapter is read-only. Edit takuhon.json and redeploy to publish changes.');\n this.name = 'ReadOnlyError';\n }\n}\n\nfunction assertValid(profile: unknown, source: string): Takuhon {\n const result = validate(profile);\n if (!result.ok) {\n const detail = result.errors.map((e) => `${e.pointer || '/'}: ${e.message}`).join('; ');\n throw new Error(`${source} is not a valid takuhon profile: ${detail}`);\n }\n return result.data;\n}\n\n/**\n * A read-only {@link TakuhonStorage} backed by an in-memory profile document,\n * typically the repository's bundled `takuhon.json`.\n *\n * The document is validated once at construction, so an invalid profile throws\n * at cold start instead of on the first request.\n */\nexport class BundledTakuhonStorage implements TakuhonStorage {\n readonly #profile: Takuhon;\n\n constructor(profile: unknown) {\n this.#profile = assertValid(profile, 'Bundled takuhon.json');\n }\n\n getProfile(): Promise<{ data: Takuhon; version: string }> {\n return Promise.resolve({ data: this.#profile, version: READ_ONLY_VERSION });\n }\n\n saveProfile(): Promise<{ version: string }> {\n return Promise.reject(new ReadOnlyError());\n }\n\n deleteProfile(): Promise<void> {\n return Promise.reject(new ReadOnlyError());\n }\n}\n\n/** Options for {@link UrlTakuhonStorage}. */\nexport interface UrlTakuhonStorageOptions {\n /** HTTP client. Defaults to the global `fetch`. Injectable for tests. */\n fetch?: typeof fetch;\n}\n\n/**\n * A read-only {@link TakuhonStorage} that fetches the profile once from a URL\n * (`TAKUHON_DATA_URL`) and caches it for the lifetime of the serverless\n * instance. The fetch is lazy and de-duplicated: concurrent first calls share a\n * single in-flight request, and a failed fetch clears the cache so a later\n * request can retry.\n */\nexport class UrlTakuhonStorage implements TakuhonStorage {\n readonly #url: string;\n readonly #fetch: typeof fetch;\n #cached?: Promise<{ data: Takuhon; version: string }>;\n\n constructor(url: string, options?: UrlTakuhonStorageOptions) {\n this.#url = url;\n this.#fetch = options?.fetch ?? fetch;\n }\n\n getProfile(): Promise<{ data: Takuhon; version: string }> {\n this.#cached ??= this.#load().catch((e: unknown) => {\n this.#cached = undefined;\n throw e;\n });\n return this.#cached;\n }\n\n async #load(): Promise<{ data: Takuhon; version: string }> {\n const res = await this.#fetch(this.#url);\n if (!res.ok) {\n throw new Error(`Failed to fetch TAKUHON_DATA_URL (${this.#url}): HTTP ${res.status}`);\n }\n const json: unknown = await res.json();\n return { data: assertValid(json, 'TAKUHON_DATA_URL profile'), version: READ_ONLY_VERSION };\n }\n\n saveProfile(): Promise<{ version: string }> {\n return Promise.reject(new ReadOnlyError());\n }\n\n deleteProfile(): Promise<void> {\n return Promise.reject(new ReadOnlyError());\n }\n}\n"],"mappings":";AAmBA,SAAS,iBAAiB,2BAA+C;AACzE,SAAS,YAAY;;;ACLrB,SAAS,gBAAmD;AAM5D,IAAM,oBAAoB;AAG1B,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAChC,cAAc;AACZ,UAAM,qFAAqF;AAC3F,SAAK,OAAO;AAAA,EACd;AACF;AAEA,SAAS,YAAY,SAAkB,QAAyB;AAC9D,QAAM,SAAS,SAAS,OAAO;AAC/B,MAAI,CAAC,OAAO,IAAI;AACd,UAAM,SAAS,OAAO,OAAO,IAAI,CAAC,MAAM,GAAG,EAAE,WAAW,GAAG,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,IAAI;AACtF,UAAM,IAAI,MAAM,GAAG,MAAM,oCAAoC,MAAM,EAAE;AAAA,EACvE;AACA,SAAO,OAAO;AAChB;AASO,IAAM,wBAAN,MAAsD;AAAA,EAClD;AAAA,EAET,YAAY,SAAkB;AAC5B,SAAK,WAAW,YAAY,SAAS,sBAAsB;AAAA,EAC7D;AAAA,EAEA,aAA0D;AACxD,WAAO,QAAQ,QAAQ,EAAE,MAAM,KAAK,UAAU,SAAS,kBAAkB,CAAC;AAAA,EAC5E;AAAA,EAEA,cAA4C;AAC1C,WAAO,QAAQ,OAAO,IAAI,cAAc,CAAC;AAAA,EAC3C;AAAA,EAEA,gBAA+B;AAC7B,WAAO,QAAQ,OAAO,IAAI,cAAc,CAAC;AAAA,EAC3C;AACF;AAeO,IAAM,oBAAN,MAAkD;AAAA,EAC9C;AAAA,EACA;AAAA,EACT;AAAA,EAEA,YAAY,KAAa,SAAoC;AAC3D,SAAK,OAAO;AACZ,SAAK,SAAS,SAAS,SAAS;AAAA,EAClC;AAAA,EAEA,aAA0D;AACxD,SAAK,YAAY,KAAK,MAAM,EAAE,MAAM,CAAC,MAAe;AAClD,WAAK,UAAU;AACf,YAAM;AAAA,IACR,CAAC;AACD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,QAAqD;AACzD,UAAM,MAAM,MAAM,KAAK,OAAO,KAAK,IAAI;AACvC,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,IAAI,MAAM,qCAAqC,KAAK,IAAI,WAAW,IAAI,MAAM,EAAE;AAAA,IACvF;AACA,UAAM,OAAgB,MAAM,IAAI,KAAK;AACrC,WAAO,EAAE,MAAM,YAAY,MAAM,0BAA0B,GAAG,SAAS,kBAAkB;AAAA,EAC3F;AAAA,EAEA,cAA4C;AAC1C,WAAO,QAAQ,OAAO,IAAI,cAAc,CAAC;AAAA,EAC3C;AAAA,EAEA,gBAA+B;AAC7B,WAAO,QAAQ,OAAO,IAAI,cAAc,CAAC;AAAA,EAC3C;AACF;;;ADpDO,SAAS,uBAAuB,SAA8C;AACnF,QAAM,MAAM,IAAI,KAAK,EAAE,SAAS,oBAAoB,CAAC;AACrD,MAAI,MAAM,KAAK,gBAAgB,EAAE,SAAS,QAAQ,SAAS,UAAU,QAAQ,SAAS,CAAC,CAAC;AACxF,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@takuhon/vercel",
|
|
3
|
+
"version": "0.19.0",
|
|
4
|
+
"description": "Vercel adapter for takuhon — read-only public profile page, API, and JSON-LD on the Vercel runtime",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Takuhon contributors",
|
|
7
|
+
"homepage": "https://github.com/takuhon-dev/takuhon/tree/main/adapters/vercel#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/takuhon-dev/takuhon.git",
|
|
11
|
+
"directory": "adapters/vercel"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/takuhon-dev/takuhon/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"takuhon",
|
|
18
|
+
"profile",
|
|
19
|
+
"vercel",
|
|
20
|
+
"adapter",
|
|
21
|
+
"hono"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE",
|
|
36
|
+
"NOTICE"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"provenance": true
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=22.0.0"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"hono": "^4.12.21",
|
|
47
|
+
"@takuhon/api": "0.19.0",
|
|
48
|
+
"@takuhon/core": "0.19.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"typecheck": "tsc",
|
|
52
|
+
"build": "tsup src/index.ts --format esm --dts --clean --sourcemap",
|
|
53
|
+
"test": "vitest run"
|
|
54
|
+
}
|
|
55
|
+
}
|