@fedify/hono 1.9.0-pr.388.1454

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 ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright 2024–2025 Hong Minhee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/mod.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { Federation } from "@fedify/fedify/federation";
2
+
3
+ //#region src/mod.d.ts
4
+
5
+ interface HonoRequest {
6
+ raw: Request;
7
+ }
8
+ interface HonoContext {
9
+ req: HonoRequest;
10
+ res: Response;
11
+ }
12
+ type HonoMiddleware<THonoContext extends HonoContext> = (ctx: THonoContext, next: () => Promise<void>) => Promise<Response | void>;
13
+ /**
14
+ * A factory function to create a context data for the {@link Federation}
15
+ * object.
16
+ *
17
+ * @template TContextData A type of the context data for the {@link Federation}
18
+ * object.
19
+ * @template THonoContext A type of the Hono context.
20
+ * @param context A Hono context object.
21
+ * @returns A context data for the {@link Federation} object.
22
+ */
23
+ type ContextDataFactory<TContextData, THonoContext> = (context: THonoContext) => TContextData | Promise<TContextData>;
24
+ /**
25
+ * Create a Hono middleware to integrate with the {@link Federation} object.
26
+ *
27
+ * @template TContextData A type of the context data for the {@link Federation}
28
+ * object.
29
+ * @template THonoContext A type of the Hono context.
30
+ * @param federation A {@link Federation} object to integrate with Hono.
31
+ * @param contextDataFactory A function to create a context data for the
32
+ * {@link Federation} object.
33
+ * @returns A Hono middleware.
34
+ */
35
+ declare function federation<TContextData, THonoContext extends HonoContext>(federation: Federation<TContextData>, contextDataFactory: ContextDataFactory<TContextData, THonoContext>): HonoMiddleware<THonoContext>;
36
+ //#endregion
37
+ export { ContextDataFactory, federation };
package/dist/mod.js ADDED
@@ -0,0 +1,44 @@
1
+ //#region src/mod.ts
2
+ /**
3
+ * Create a Hono middleware to integrate with the {@link Federation} object.
4
+ *
5
+ * @template TContextData A type of the context data for the {@link Federation}
6
+ * object.
7
+ * @template THonoContext A type of the Hono context.
8
+ * @param federation A {@link Federation} object to integrate with Hono.
9
+ * @param contextDataFactory A function to create a context data for the
10
+ * {@link Federation} object.
11
+ * @returns A Hono middleware.
12
+ */
13
+ function federation(federation$1, contextDataFactory) {
14
+ return async (ctx, next) => {
15
+ let contextData = contextDataFactory(ctx);
16
+ if (contextData instanceof Promise) contextData = await contextData;
17
+ return await federation$1.fetch(ctx.req.raw, {
18
+ contextData,
19
+ ...integrateFetchOptions(ctx, next)
20
+ });
21
+ };
22
+ }
23
+ function integrateFetchOptions(ctx, next) {
24
+ return {
25
+ async onNotFound(_req) {
26
+ await next();
27
+ return ctx.res;
28
+ },
29
+ async onNotAcceptable(_req) {
30
+ await next();
31
+ if (ctx.res.status !== 404) return ctx.res;
32
+ return new Response("Not acceptable", {
33
+ status: 406,
34
+ headers: {
35
+ "Content-Type": "text/plain",
36
+ Vary: "Accept"
37
+ }
38
+ });
39
+ }
40
+ };
41
+ }
42
+
43
+ //#endregion
44
+ export { federation };
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@fedify/hono",
3
+ "version": "1.9.0-pr.388.1454+d7cc8c70",
4
+ "description": "Integrate Fedify with Hono",
5
+ "keywords": [
6
+ "Fedify",
7
+ "ActivityPub",
8
+ "Fediverse",
9
+ "Hono"
10
+ ],
11
+ "author": {
12
+ "name": "Hong Minhee",
13
+ "email": "hong@minhee.org",
14
+ "url": "https://hongminhee.org/"
15
+ },
16
+ "homepage": "https://fedify.dev/",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/fedify-dev/fedify.git",
20
+ "directory": "packages/hono"
21
+ },
22
+ "license": "MIT",
23
+ "bugs": {
24
+ "url": "https://github.com/fedify-dev/fedify/issues"
25
+ },
26
+ "funding": [
27
+ "https://opencollective.com/fedify",
28
+ "https://github.com/sponsors/dahlia"
29
+ ],
30
+ "type": "module",
31
+ "main": "./dist/index.js",
32
+ "module": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "require": {
37
+ "types": "./dist/index.d.ts",
38
+ "import": "./dist/index.js",
39
+ "default": "./dist/index.js"
40
+ },
41
+ "import": {
42
+ "types": "./dist/index.d.ts",
43
+ "import": "./dist/index.js",
44
+ "default": "./dist/index.js"
45
+ }
46
+ },
47
+ "./package.json": "./package.json"
48
+ },
49
+ "files": [
50
+ "dist/",
51
+ "package.json"
52
+ ],
53
+ "peerDependencies": {
54
+ "hono": "^4.0.0",
55
+ "@fedify/fedify": "1.9.0-pr.388.1454+d7cc8c70"
56
+ },
57
+ "devDependencies": {
58
+ "tsdown": "^0.12.9",
59
+ "typescript": "^5.9.2"
60
+ },
61
+ "scripts": {
62
+ "build": "tsdown",
63
+ "prepublish": "tsdown",
64
+ "test": "deno task codegen && tsdown && cd dist/ && node --test"
65
+ }
66
+ }