@fedify/sveltekit 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,33 @@
1
+ import { Federation } from "@fedify/fedify/federation";
2
+
3
+ //#region src/mod.d.ts
4
+
5
+ type RequestEvent = {
6
+ request: Request;
7
+ };
8
+ type HookParams = {
9
+ event: RequestEvent;
10
+ resolve: (event: RequestEvent) => Promise<Response>;
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
+ * @template 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
+ declare function fedifyHook<TContextData>(federation: Federation<TContextData>, createContextData: (event: RequestEvent) => TContextData | Promise<TContextData>): (params: HookParams) => Promise<Response>;
32
+ //#endregion
33
+ export { fedifyHook };
package/dist/mod.js ADDED
@@ -0,0 +1,52 @@
1
+ //#region src/mod.ts
2
+ /**
3
+ * Create a SvelteKit hook handler to integrate with the {@link Federation}
4
+ * object.
5
+ *
6
+ * @example hooks.server.ts
7
+ * ``` typescript
8
+ * import { federation } from "./federation"; // Import the `Federation` object
9
+ *
10
+ * export const handle = fedifyHook(federation, () => undefined);
11
+ * ```
12
+ *
13
+ * @template TContextData A type of the context data for the {@link Federation}
14
+ * object.
15
+ * @param federation A {@link Federation} object to integrate with SvelteKit.
16
+ * @param createContextData A function to create a context data for the
17
+ * {@link Federation} object.
18
+ * @returns A SvelteKit hook handler.
19
+ * @since 1.3.0
20
+ */
21
+ function fedifyHook(federation, createContextData) {
22
+ return async ({ event, resolve }) => {
23
+ return await federation.fetch(event.request, {
24
+ contextData: await createContextData(event),
25
+ ...integrateFetchOptions({
26
+ event,
27
+ resolve
28
+ })
29
+ });
30
+ };
31
+ }
32
+ function integrateFetchOptions({ event, resolve }) {
33
+ return {
34
+ async onNotFound() {
35
+ return await resolve(event);
36
+ },
37
+ async onNotAcceptable() {
38
+ const res = await resolve(event);
39
+ if (res.status !== 404) return res;
40
+ return new Response("Not acceptable", {
41
+ status: 406,
42
+ headers: {
43
+ "Content-Type": "text/plain",
44
+ Vary: "Accept"
45
+ }
46
+ });
47
+ }
48
+ };
49
+ }
50
+
51
+ //#endregion
52
+ export { fedifyHook };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@fedify/sveltekit",
3
+ "version": "1.9.0-pr.388.1454+d7cc8c70",
4
+ "description": "Integrate Fedify with SvelteKit",
5
+ "keywords": [
6
+ "Fedify",
7
+ "ActivityPub",
8
+ "Fediverse",
9
+ "SvelteKit",
10
+ "Svelte"
11
+ ],
12
+ "author": {
13
+ "name": "Hong Minhee",
14
+ "email": "hong@minhee.org",
15
+ "url": "https://hongminhee.org/"
16
+ },
17
+ "homepage": "https://fedify.dev/",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/fedify-dev/fedify.git",
21
+ "directory": "packages/sveltekit"
22
+ },
23
+ "license": "MIT",
24
+ "bugs": {
25
+ "url": "https://github.com/fedify-dev/fedify/issues"
26
+ },
27
+ "funding": [
28
+ "https://opencollective.com/fedify",
29
+ "https://github.com/sponsors/dahlia"
30
+ ],
31
+ "type": "module",
32
+ "main": "./dist/index.js",
33
+ "module": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "exports": {
36
+ ".": {
37
+ "require": {
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.js",
40
+ "default": "./dist/index.js"
41
+ },
42
+ "import": {
43
+ "types": "./dist/index.d.ts",
44
+ "import": "./dist/index.js",
45
+ "default": "./dist/index.js"
46
+ }
47
+ },
48
+ "./package.json": "./package.json"
49
+ },
50
+ "files": [
51
+ "dist/",
52
+ "package.json"
53
+ ],
54
+ "peerDependencies": {
55
+ "@sveltejs/kit": "^2.0.0",
56
+ "@fedify/fedify": "1.9.0-pr.388.1454+d7cc8c70"
57
+ },
58
+ "devDependencies": {
59
+ "tsdown": "^0.12.9",
60
+ "typescript": "^5.9.2"
61
+ },
62
+ "scripts": {
63
+ "build": "tsdown",
64
+ "prepublish": "tsdown",
65
+ "test": "deno task codegen && tsdown && cd dist/ && node --test"
66
+ }
67
+ }