@fedify/fedify 1.3.0-dev.553 → 1.3.0-dev.557

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGES.md CHANGED
@@ -61,6 +61,11 @@ To be released.
61
61
 
62
62
  - Added `CreateFederationOptions.tracerProvider` option.
63
63
 
64
+ - Added `@fedify/fedify/x/sveltekit` module for integrating with [SvelteKit]
65
+ hook. [[#171], [#183] by Jiyu Park]
66
+
67
+ - Added `fedifyHook()` function.
68
+
64
69
  - The scaffold project generated by `fedify init` command now enables
65
70
  tracing data into log messages.
66
71
 
@@ -68,10 +73,14 @@ To be released.
68
73
  [[#173], [#186] by PGD]
69
74
 
70
75
 
76
+ [SvelteKit]: https://kit.svelte.dev/
71
77
  [#162]: https://github.com/dahlia/fedify/issues/162
78
+ [#171]: https://github.com/dahlia/fedify/issues/171
72
79
  [#173]: https://github.com/dahlia/fedify/issues/173
80
+ [#183]: https://github.com/dahlia/fedify/pull/183
73
81
  [#186]: https://github.com/dahlia/fedify/pull/186
74
82
 
83
+
75
84
  Version 1.2.8
76
85
  -------------
77
86
 
@@ -2556,4 +2565,4 @@ Version 0.1.0
2556
2565
 
2557
2566
  Initial release. Released on March 8, 2024.
2558
2567
 
2559
- <!-- cSpell: ignore Dogeon Fabien Wressell Emelia Hana Heesun Kyunghee -->
2568
+ <!-- cSpell: ignore Dogeon Fabien Wressell Emelia Hana Heesun Kyunghee Jiyu -->
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "@fedify/fedify",
3
- "version": "1.3.0-dev.553+ad290770",
3
+ "version": "1.3.0-dev.557+fb2366f2",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./mod.ts",
@@ -12,7 +12,8 @@ export default {
12
12
  "./webfinger": "./webfinger/mod.ts",
13
13
  "./x/denokv": "./x/denokv.ts",
14
14
  "./x/fresh": "./x/fresh.ts",
15
- "./x/hono": "./x/hono.ts"
15
+ "./x/hono": "./x/hono.ts",
16
+ "./x/sveltekit": "./x/sveltekit.ts"
16
17
  },
17
18
  "imports": {
18
19
  "@cfworker/json-schema": "npm:@cfworker/json-schema@^2.0.1",
@@ -28,6 +29,7 @@ export default {
28
29
  "@fedify/fedify/x/denokv": "./x/denokv.ts",
29
30
  "@fedify/fedify/x/fresh": "./x/fresh.ts",
30
31
  "@fedify/fedify/x/hono": "./x/hono.ts",
32
+ "@fedify/fedify/x/sveltekit": "./x/sveltekit.ts",
31
33
  "@hongminhee/aitertools": "jsr:@hongminhee/aitertools@^0.6.0",
32
34
  "@hugoalh/http-header-link": "jsr:@hugoalh/http-header-link@^1.0.2",
33
35
  "@logtape/logtape": "jsr:@logtape/logtape@^0.8.0",
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Fedify with SvelteKit
3
+ * =====================
4
+ *
5
+ * This module provides a [SvelteKit] hook to integrate with the Fedify.
6
+ *
7
+ * [SvelteKit]: https://kit.svelte.dev/
8
+ *
9
+ * @module
10
+ * @since 1.3.0
11
+ */
12
+ /**
13
+ * Create a SvelteKit hook handler to integrate with the {@link Federation}
14
+ * object.
15
+ *
16
+ * @example hooks.server.ts
17
+ * ``` typescript
18
+ * import { federation } from "./federation"; // Import the `Federation` object
19
+ *
20
+ * export const handle = fedifyHook(federation, () => undefined);
21
+ * ```
22
+ *
23
+ * @typeParam TContextData A type of the context data for the {@link Federation}
24
+ * object.
25
+ * @param federation A {@link Federation} object to integrate with SvelteKit.
26
+ * @param createContextData A function to create a context data for the
27
+ * {@link Federation} object.
28
+ * @returns A SvelteKit hook handler.
29
+ * @since 1.3.0
30
+ */
31
+ export function fedifyHook(federation, createContextData) {
32
+ return async ({ event, resolve }) => {
33
+ return await federation.fetch(event.request, {
34
+ contextData: await createContextData(event),
35
+ ...integrateFetchOptions({ event, resolve }),
36
+ });
37
+ };
38
+ }
39
+ function integrateFetchOptions({ event, resolve }) {
40
+ return {
41
+ async onNotFound() {
42
+ return await resolve(event);
43
+ },
44
+ // Similar to `onNotFound`, but slightly more tricky one.
45
+ // When the `federation` object finds a request not acceptable type-wise
46
+ // (i.e., a user-agent doesn't want JSON-LD), it will call the `resolve`
47
+ // provided by the SvelteKit framework so that it renders HTML if there's some
48
+ // page. Otherwise, it will simply return a 406 Not Acceptable response.
49
+ // This kind of trick enables the Fedify and SvelteKit to share the same routes
50
+ // and they do content negotiation depending on `Accept` header:
51
+ async onNotAcceptable() {
52
+ const res = await resolve(event);
53
+ if (res.status !== 404)
54
+ return res;
55
+ return new Response("Not acceptable", {
56
+ status: 406,
57
+ headers: {
58
+ "Content-Type": "text/plain",
59
+ Vary: "Accept",
60
+ },
61
+ });
62
+ },
63
+ };
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/fedify",
3
- "version": "1.3.0-dev.553+ad290770",
3
+ "version": "1.3.0-dev.557+fb2366f2",
4
4
  "description": "An ActivityPub server framework",
5
5
  "keywords": [
6
6
  "ActivityPub",
@@ -70,6 +70,12 @@
70
70
  "types": "./types/x/hono.d.ts",
71
71
  "default": "./esm/x/hono.js"
72
72
  }
73
+ },
74
+ "./x/sveltekit": {
75
+ "import": {
76
+ "types": "./types/x/sveltekit.d.ts",
77
+ "default": "./esm/x/sveltekit.js"
78
+ }
73
79
  }
74
80
  },
75
81
  "funding": [
package/types/deno.d.ts CHANGED
@@ -13,6 +13,7 @@ declare namespace _default {
13
13
  "./x/denokv": string;
14
14
  "./x/fresh": string;
15
15
  "./x/hono": string;
16
+ "./x/sveltekit": string;
16
17
  };
17
18
  let imports: {
18
19
  "@cfworker/json-schema": string;
@@ -28,6 +29,7 @@ declare namespace _default {
28
29
  "@fedify/fedify/x/denokv": string;
29
30
  "@fedify/fedify/x/fresh": string;
30
31
  "@fedify/fedify/x/hono": string;
32
+ "@fedify/fedify/x/sveltekit": string;
31
33
  "@hongminhee/aitertools": string;
32
34
  "@hugoalh/http-header-link": string;
33
35
  "@logtape/logtape": string;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Fedify with SvelteKit
3
+ * =====================
4
+ *
5
+ * This module provides a [SvelteKit] hook to integrate with the Fedify.
6
+ *
7
+ * [SvelteKit]: https://kit.svelte.dev/
8
+ *
9
+ * @module
10
+ * @since 1.3.0
11
+ */
12
+ /// <reference types="node" />
13
+ import type { Federation } from "../federation/federation.js";
14
+ type RequestEvent = {
15
+ request: Request;
16
+ };
17
+ type HookParams = {
18
+ event: RequestEvent;
19
+ resolve: (event: RequestEvent) => Promise<Response>;
20
+ };
21
+ /**
22
+ * Create a SvelteKit hook handler to integrate with the {@link Federation}
23
+ * object.
24
+ *
25
+ * @example hooks.server.ts
26
+ * ``` typescript
27
+ * import { federation } from "./federation"; // Import the `Federation` object
28
+ *
29
+ * export const handle = fedifyHook(federation, () => undefined);
30
+ * ```
31
+ *
32
+ * @typeParam TContextData A type of the context data for the {@link Federation}
33
+ * object.
34
+ * @param federation A {@link Federation} object to integrate with SvelteKit.
35
+ * @param createContextData A function to create a context data for the
36
+ * {@link Federation} object.
37
+ * @returns A SvelteKit hook handler.
38
+ * @since 1.3.0
39
+ */
40
+ export declare function fedifyHook<TContextData>(federation: Federation<TContextData>, createContextData: (event: RequestEvent) => TContextData | Promise<TContextData>): (params: HookParams) => Promise<Response>;
41
+ export {};
42
+ //# sourceMappingURL=sveltekit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sveltekit.d.ts","sourceRoot":"","sources":["../../src/x/sveltekit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;;AAEH,OAAO,KAAK,EACV,UAAU,EAEX,MAAM,6BAA6B,CAAC;AAErC,KAAK,YAAY,GAAG;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,YAAY,EACrC,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,EACpC,iBAAiB,EAAE,CACjB,KAAK,EAAE,YAAY,KAChB,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,GACxC,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,QAAQ,CAAC,CAO3C"}