@fedify/sveltekit 2.0.0-dev.1593 → 2.0.0-dev.160
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 +1 -1
- package/README.md +21 -19
- package/dist/mod.cjs +53 -0
- package/dist/mod.d.cts +27 -0
- package/package.json +7 -9
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -27,23 +27,34 @@ export const handle = fedifyHook(federation, (req) => "context data");
|
|
|
27
27
|
|
|
28
28
|
Put the above code in your *hooks.server.ts* file.
|
|
29
29
|
|
|
30
|
+
[JSR badge]: https://jsr.io/badges/@fedify/sveltekit
|
|
31
|
+
[JSR]: https://jsr.io/@fedify/sveltekit
|
|
32
|
+
[npm badge]: https://img.shields.io/npm/v/@fedify/sveltekit?logo=npm
|
|
33
|
+
[npm]: https://www.npmjs.com/package/@fedify/sveltekit
|
|
34
|
+
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
|
|
35
|
+
[@fedify@hollo.social]: https://hollo.social/@fedify
|
|
36
|
+
[Fedify]: https://fedify.dev/
|
|
37
|
+
[SvelteKit]: https://kit.svelte.dev/
|
|
38
|
+
|
|
39
|
+
|
|
30
40
|
How it works
|
|
31
41
|
------------
|
|
32
42
|
|
|
33
|
-
Fedify behaves as a hook handler that wraps around the SvelteKit request
|
|
34
|
-
The hook intercepts the incoming HTTP requests and dispatches them to
|
|
43
|
+
Fedify behaves as a hook handler that wraps around the SvelteKit request
|
|
44
|
+
handler. The hook intercepts the incoming HTTP requests and dispatches them to
|
|
35
45
|
the appropriate handler based on the request path and the `Accept` header
|
|
36
|
-
(i.e., content negotiation). This architecture allows Fedify and your
|
|
37
|
-
application to coexist in the same domain and port.
|
|
46
|
+
(i.e., content negotiation). This architecture allows Fedify and your
|
|
47
|
+
SvelteKit application to coexist in the same domain and port.
|
|
38
48
|
|
|
39
49
|
For example, if you make a request to */.well-known/webfinger* Fedify will
|
|
40
50
|
handle the request by itself, but if you make a request to */users/alice*
|
|
41
|
-
(assuming your SvelteKit app has a handler for `/users/[handle]`) with
|
|
42
|
-
text/html` header, Fedify will dispatch the request to the SvelteKit
|
|
43
|
-
appropriate handler for `/users/[handle]`. Or if you define an actor
|
|
44
|
-
for `/users/{handle}` in Fedify, and the request is made with
|
|
45
|
-
application/activity+json` header, Fedify will dispatch the request to
|
|
46
|
-
appropriate actor dispatcher.
|
|
51
|
+
(assuming your SvelteKit app has a handler for `/users/[handle]`) with
|
|
52
|
+
`Accept: text/html` header, Fedify will dispatch the request to the SvelteKit
|
|
53
|
+
app's appropriate handler for `/users/[handle]`. Or if you define an actor
|
|
54
|
+
dispatcher for `/users/{handle}` in Fedify, and the request is made with
|
|
55
|
+
`Accept: application/activity+json` header, Fedify will dispatch the request to
|
|
56
|
+
the appropriate actor dispatcher.
|
|
57
|
+
|
|
47
58
|
|
|
48
59
|
Installation
|
|
49
60
|
------------
|
|
@@ -55,12 +66,3 @@ pnpm add @fedify/sveltekit # pnpm
|
|
|
55
66
|
yarn add @fedify/sveltekit # Yarn
|
|
56
67
|
bun add @fedify/sveltekit # Bun
|
|
57
68
|
~~~~
|
|
58
|
-
|
|
59
|
-
[JSR]: https://jsr.io/@fedify/sveltekit
|
|
60
|
-
[JSR badge]: https://jsr.io/badges/@fedify/sveltekit
|
|
61
|
-
[npm]: https://www.npmjs.com/package/@fedify/sveltekit
|
|
62
|
-
[npm badge]: https://img.shields.io/npm/v/@fedify/sveltekit?logo=npm
|
|
63
|
-
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
|
|
64
|
-
[@fedify@hollo.social]: https://hollo.social/@fedify
|
|
65
|
-
[Fedify]: https://fedify.dev/
|
|
66
|
-
[SvelteKit]: https://kit.svelte.dev/
|
package/dist/mod.cjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/mod.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create a SvelteKit hook handler to integrate with the {@link Federation}
|
|
5
|
+
* object.
|
|
6
|
+
*
|
|
7
|
+
* @example hooks.server.ts
|
|
8
|
+
* ``` typescript
|
|
9
|
+
* import { federation } from "./federation"; // Import the `Federation` object
|
|
10
|
+
*
|
|
11
|
+
* export const handle = fedifyHook(federation);
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @template TContextData A type of the context data for the {@link Federation}
|
|
15
|
+
* object.
|
|
16
|
+
* @param federation A {@link Federation} object to integrate with SvelteKit.
|
|
17
|
+
* @param createContextData A function to create a context data for the
|
|
18
|
+
* {@link Federation} object.
|
|
19
|
+
* @returns A SvelteKit hook handler.
|
|
20
|
+
* @since 1.9.0
|
|
21
|
+
*/
|
|
22
|
+
function fedifyHook(federation, createContextData = () => void 0) {
|
|
23
|
+
return async ({ event, resolve }) => {
|
|
24
|
+
return await federation.fetch(event.request, {
|
|
25
|
+
contextData: await createContextData(event),
|
|
26
|
+
...integrateFetchOptions({
|
|
27
|
+
event,
|
|
28
|
+
resolve
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function integrateFetchOptions({ event, resolve }) {
|
|
34
|
+
return {
|
|
35
|
+
async onNotFound() {
|
|
36
|
+
return await resolve(event);
|
|
37
|
+
},
|
|
38
|
+
async onNotAcceptable() {
|
|
39
|
+
const res = await resolve(event);
|
|
40
|
+
if (res.status !== 404) return res;
|
|
41
|
+
return new Response("Not acceptable", {
|
|
42
|
+
status: 406,
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": "text/plain",
|
|
45
|
+
Vary: "Accept"
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.fedifyHook = fedifyHook;
|
package/dist/mod.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Federation } from "@fedify/fedify/federation";
|
|
2
|
+
import { Handle, RequestEvent } from "@sveltejs/kit";
|
|
3
|
+
|
|
4
|
+
//#region src/mod.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create a SvelteKit hook handler to integrate with the {@link Federation}
|
|
8
|
+
* object.
|
|
9
|
+
*
|
|
10
|
+
* @example hooks.server.ts
|
|
11
|
+
* ``` typescript
|
|
12
|
+
* import { federation } from "./federation"; // Import the `Federation` object
|
|
13
|
+
*
|
|
14
|
+
* export const handle = fedifyHook(federation);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @template TContextData A type of the context data for the {@link Federation}
|
|
18
|
+
* object.
|
|
19
|
+
* @param federation A {@link Federation} object to integrate with SvelteKit.
|
|
20
|
+
* @param createContextData A function to create a context data for the
|
|
21
|
+
* {@link Federation} object.
|
|
22
|
+
* @returns A SvelteKit hook handler.
|
|
23
|
+
* @since 1.9.0
|
|
24
|
+
*/
|
|
25
|
+
declare function fedifyHook<TContextData>(federation: Federation<TContextData>, createContextData?: (event: RequestEvent) => TContextData | Promise<TContextData>): Handle;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { fedifyHook };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/sveltekit",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.160+d1f3be74",
|
|
4
4
|
"description": "Integrate Fedify with SvelteKit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fedify",
|
|
@@ -29,19 +29,17 @@
|
|
|
29
29
|
"https://github.com/sponsors/dahlia"
|
|
30
30
|
],
|
|
31
31
|
"type": "module",
|
|
32
|
-
"main": "./dist/mod.
|
|
32
|
+
"main": "./dist/mod.cjs",
|
|
33
33
|
"module": "./dist/mod.js",
|
|
34
34
|
"types": "./dist/mod.d.ts",
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
37
37
|
"require": {
|
|
38
|
-
"types": "./dist/mod.d.
|
|
39
|
-
"
|
|
40
|
-
"default": "./dist/mod.js"
|
|
38
|
+
"types": "./dist/mod.d.cts",
|
|
39
|
+
"default": "./dist/mod.cjs"
|
|
41
40
|
},
|
|
42
41
|
"import": {
|
|
43
42
|
"types": "./dist/mod.d.ts",
|
|
44
|
-
"import": "./dist/mod.js",
|
|
45
43
|
"default": "./dist/mod.js"
|
|
46
44
|
}
|
|
47
45
|
},
|
|
@@ -53,16 +51,16 @@
|
|
|
53
51
|
],
|
|
54
52
|
"peerDependencies": {
|
|
55
53
|
"@sveltejs/kit": "^2.0.0",
|
|
56
|
-
"@fedify/fedify": "^2.0.0-dev.
|
|
54
|
+
"@fedify/fedify": "^2.0.0-dev.160+d1f3be74"
|
|
57
55
|
},
|
|
58
56
|
"devDependencies": {
|
|
59
57
|
"tsdown": "^0.12.9",
|
|
60
|
-
"typescript": "^5.9.
|
|
58
|
+
"typescript": "^5.9.3"
|
|
61
59
|
},
|
|
62
60
|
"scripts": {
|
|
63
61
|
"build": "tsdown",
|
|
64
62
|
"prepublish": "tsdown",
|
|
65
63
|
"dev": "tsdown --watch",
|
|
66
|
-
"test": "
|
|
64
|
+
"test": "node --experimental-transform-types --test"
|
|
67
65
|
}
|
|
68
66
|
}
|