@fedify/h3 0.1.2 → 1.8.0-dev.938

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright 2024 Hong Minhee
3
+ Copyright 2024–2025 Hong Minhee
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
+ <!-- deno-fmt-ignore-file -->
2
+
1
3
  @fedify/h3: Integrate Fedify with h3
2
4
  ====================================
3
5
 
6
+ [![JSR][JSR badge]][JSR]
4
7
  [![npm][npm badge]][npm]
5
8
  [![Matrix][Matrix badge]][Matrix]
6
9
  [![Follow @fedify@hollo.social][@fedify@hollo.social badge]][@fedify@hollo.social]
@@ -33,6 +36,8 @@ app.use(router);
33
36
  > If you don't do this, Fedify will not be able to respond with a proper error
34
37
  > status code when a content negotiation fails.
35
38
 
39
+ [JSR]: https://jsr.io/@fedify/h3
40
+ [JSR badge]: https://jsr.io/badges/@fedify/h3
36
41
  [npm]: https://www.npmjs.com/package/@fedify/h3
37
42
  [npm badge]: https://img.shields.io/npm/v/@fedify/h3?logo=npm
38
43
  [Matrix]: https://matrix.to/#/#fedify:matrix.org
@@ -46,23 +51,3 @@ app.use(router);
46
51
  [Vinxi]: https://vinxi.vercel.app/
47
52
  [SolidStart]: https://start.solidjs.com/
48
53
  [TanStack Start]: https://tanstack.com/start
49
-
50
-
51
- Changelog
52
- ---------
53
-
54
- ### Version 0.1.2
55
-
56
- Released on February 28, 2025.
57
-
58
- - Made the package compatible with Fedify 1.0.0 or later.
59
-
60
- ### Version 0.1.1
61
-
62
- Released on August 6, 2024.
63
-
64
- - Added missing entry points to the *package.json*.
65
-
66
- ### Version 0.1.0
67
-
68
- Initial release. Released on July 6, 2024.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { Federation } from '@fedify/fedify';
2
- import { H3Event, EventHandlerRequest, EventHandler, EventHandlerResponse, H3Error } from 'h3';
1
+ import { EventHandler, EventHandlerRequest, EventHandlerResponse, H3Error, H3Event } from "h3";
2
+ import { Federation } from "@fedify/fedify";
3
+
4
+ //#region index.d.ts
3
5
 
4
6
  /**
5
7
  * A factory function that creates the context data that will be passed to the
@@ -27,5 +29,5 @@ declare function integrateFederation<TContextData>(federation: Federation<TConte
27
29
  * @param event The event that triggered the handler.
28
30
  */
29
31
  declare function onError(error: H3Error<unknown>, event: H3Event<EventHandlerResponse>): Promise<void>;
30
-
31
- export { type ContextDataFactory, integrateFederation, onError };
32
+ //#endregion
33
+ export { ContextDataFactory, integrateFederation, onError };
package/dist/index.js CHANGED
@@ -1,31 +1,34 @@
1
- // src/index.ts
2
- import {
3
- defineEventHandler,
4
- toWebRequest
5
- } from "h3";
1
+ import { defineEventHandler, toWebRequest } from "h3";
2
+
3
+ //#region index.ts
4
+ /**
5
+ * Integrates a `Federation` instance with an H3 handler.
6
+ * @param federation
7
+ * @param contextDataFactory
8
+ * @returns
9
+ */
6
10
  function integrateFederation(federation, contextDataFactory) {
7
- return defineEventHandler({
8
- async handler(event) {
9
- const request = toWebRequest(event);
10
- const response = await federation.fetch(request, {
11
- contextData: await contextDataFactory(event, request)
12
- });
13
- if (response.status === 404) return;
14
- if (response.status === 406) {
15
- event.context["__fedify_response__"] = response;
16
- return;
17
- }
18
- await event.respondWith(response);
19
- }
20
- });
11
+ return defineEventHandler({ async handler(event) {
12
+ const request = toWebRequest(event);
13
+ const response = await federation.fetch(request, { contextData: await contextDataFactory(event, request) });
14
+ if (response.status === 404) return;
15
+ if (response.status === 406) {
16
+ event.context["__fedify_response__"] = response;
17
+ return;
18
+ }
19
+ await event.respondWith(response);
20
+ } });
21
21
  }
22
+ /**
23
+ * An error handler that responds with a 406 Not Acceptable if Fedify
24
+ * responded with a 406 Not Acceptable and the actual handler responded with
25
+ * a 404 Not Found.
26
+ * @param error The error that occurred.
27
+ * @param event The event that triggered the handler.
28
+ */
22
29
  async function onError(error, event) {
23
- if ("__fedify_response__" in event.context && event.context["__fedify_response__"].status === 406 && error.statusCode === 404) {
24
- await event.respondWith(event.context["__fedify_response__"]);
25
- }
30
+ if ("__fedify_response__" in event.context && event.context["__fedify_response__"].status === 406 && error.statusCode === 404) await event.respondWith(event.context["__fedify_response__"]);
26
31
  }
27
- export {
28
- integrateFederation,
29
- onError
30
- };
31
- //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2luZGV4LnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJpbXBvcnQgdHlwZSB7IEZlZGVyYXRpb24gfSBmcm9tIFwiQGZlZGlmeS9mZWRpZnlcIjtcbmltcG9ydCB7XG4gIHR5cGUgRXZlbnRIYW5kbGVyLFxuICB0eXBlIEV2ZW50SGFuZGxlclJlcXVlc3QsXG4gIHR5cGUgRXZlbnRIYW5kbGVyUmVzcG9uc2UsXG4gIHR5cGUgSDNFcnJvcixcbiAgdHlwZSBIM0V2ZW50LFxuICBkZWZpbmVFdmVudEhhbmRsZXIsXG4gIHRvV2ViUmVxdWVzdCxcbn0gZnJvbSBcImgzXCI7XG5cbi8qKlxuICogQSBmYWN0b3J5IGZ1bmN0aW9uIHRoYXQgY3JlYXRlcyB0aGUgY29udGV4dCBkYXRhIHRoYXQgd2lsbCBiZSBwYXNzZWQgdG8gdGhlXG4gKiBgRmVkZXJhdGlvbmAgaW5zdGFuY2UuXG4gKiBAdHlwZVBhcmFtIFRDb250ZXh0RGF0YSBUaGUgdHlwZSBvZiB0aGUgY29udGV4dCBkYXRhIHRoYXQgd2lsbCBiZSBwYXNzZWQgdG9cbiAqICAgICAgICAgICAgICAgICAgICAgICAgIHRoZSBgRmVkZXJhdGlvbmAgaW5zdGFuY2UuXG4gKiBAcGFyYW0gZXZlbnQgVGhlIGV2ZW50IHRoYXQgdHJpZ2dlc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1,21 +1,25 @@
1
1
  {
2
2
  "name": "@fedify/h3",
3
- "version": "0.1.2",
3
+ "version": "1.8.0-dev.938+8ac25255",
4
4
  "description": "Integrate Fedify with h3",
5
- "keywords": ["Fedify", "h3"],
5
+ "keywords": [
6
+ "Fedify",
7
+ "h3"
8
+ ],
6
9
  "author": {
7
10
  "name": "Hong Minhee",
8
11
  "email": "hong@minhee.org",
9
12
  "url": "https://hongminhee.org/"
10
13
  },
11
- "homepage": "https://github.com/fedify-dev/h3",
14
+ "homepage": "https://fedify.dev/",
12
15
  "repository": {
13
16
  "type": "git",
14
- "url": "git+https://github.com/fedify-dev/h3.git"
17
+ "url": "git+https://github.com/fedify-dev/fedify.git",
18
+ "directory": "h3"
15
19
  },
16
20
  "license": "MIT",
17
21
  "bugs": {
18
- "url": "https://github.com/fedify-dev/h3/issues"
22
+ "url": "https://github.com/fedify-dev/fedify/issues"
19
23
  },
20
24
  "funding": [
21
25
  "https://opencollective.com/fedify",
@@ -30,21 +34,23 @@
30
34
  "types": "./dist/index.d.ts",
31
35
  "default": "./dist/index.js"
32
36
  }
33
- }
37
+ },
38
+ "./package.json": "./package.json"
34
39
  },
35
- "files": ["src/", "dist/"],
40
+ "files": [
41
+ "dist/",
42
+ "package.json"
43
+ ],
36
44
  "devDependencies": {
37
- "@biomejs/biome": "1.8.3",
38
- "@types/node": "^20.14.10",
39
- "tsup": "^8.1.0",
40
- "typescript": "^5.0.0"
45
+ "tsdown": "^0.12.9",
46
+ "typescript": "^5.8.3"
41
47
  },
42
48
  "peerDependencies": {
43
- "@fedify/fedify": ">=0.10.0, <2",
44
- "h3": "^1.8.0"
49
+ "h3": "^1.15.0",
50
+ "@fedify/fedify": "1.8.0-dev.938+8ac25255"
45
51
  },
46
52
  "scripts": {
47
- "build": "tsup",
48
- "prepack": "tsup"
53
+ "build": "tsdown",
54
+ "prepublish": "tsdown"
49
55
  }
50
- }
56
+ }
package/src/index.ts DELETED
@@ -1,82 +0,0 @@
1
- import type { Federation } from "@fedify/fedify";
2
- import {
3
- type EventHandler,
4
- type EventHandlerRequest,
5
- type EventHandlerResponse,
6
- type H3Error,
7
- type H3Event,
8
- defineEventHandler,
9
- toWebRequest,
10
- } from "h3";
11
-
12
- /**
13
- * A factory function that creates the context data that will be passed to the
14
- * `Federation` instance.
15
- * @typeParam TContextData The type of the context data that will be passed to
16
- * the `Federation` instance.
17
- * @param event The event that triggered the handler.
18
- * @param request The request that triggered the handler.
19
- * @returns The context data that will be passed to the `Federation` instance.
20
- * This can be a promise that resolves to the context data.
21
- */
22
- export type ContextDataFactory<TContextData> = (
23
- event: H3Event<EventHandlerRequest>,
24
- request: Request,
25
- ) => Promise<TContextData> | TContextData;
26
-
27
- /**
28
- * Integrates a `Federation` instance with an H3 handler.
29
- * @param federation
30
- * @param contextDataFactory
31
- * @returns
32
- */
33
- export function integrateFederation<TContextData>(
34
- federation: Federation<TContextData>,
35
- contextDataFactory: ContextDataFactory<TContextData>,
36
- ): EventHandler<EventHandlerRequest, EventHandlerResponse> {
37
- return defineEventHandler({
38
- async handler(event) {
39
- const request = toWebRequest(event);
40
- const response = await federation.fetch(request, {
41
- contextData: await contextDataFactory(event, request),
42
- });
43
- // If the response is 404 Not Found, then we delegate the handling to
44
- // the next handler in the chain. This is because the handler might
45
- // have an endpoint that Fedify does not have, and we want to give the
46
- // handler a chance to respond to the request:
47
- if (response.status === 404) return;
48
- // See also onBeforeResponse() above:
49
- if (response.status === 406) {
50
- event.context["__fedify_response__"] = response;
51
- return;
52
- }
53
- await event.respondWith(response);
54
- },
55
- });
56
- }
57
-
58
- /**
59
- * An error handler that responds with a 406 Not Acceptable if Fedify
60
- * responded with a 406 Not Acceptable and the actual handler responded with
61
- * a 404 Not Found.
62
- * @param error The error that occurred.
63
- * @param event The event that triggered the handler.
64
- */
65
- export async function onError(
66
- error: H3Error<unknown>,
67
- event: H3Event<EventHandlerResponse>,
68
- ): Promise<void> {
69
- // If Fedify responded with a 406 Not Acceptable and later on the actual
70
- // handler responded with a 404 Not Found, then we consider it failed
71
- // to negotiate a response. For example, if Fedify has an endpoint /foo
72
- // that supports only application/activity+json and the handler has no
73
- // endpoint /foo at all, then when a client requests /foo with
74
- // Accept: text/html, it should respond with 406 Not Acceptable:
75
- if (
76
- "__fedify_response__" in event.context &&
77
- event.context["__fedify_response__"].status === 406 &&
78
- error.statusCode === 404
79
- ) {
80
- await event.respondWith(event.context["__fedify_response__"]);
81
- }
82
- }