@fedify/sveltekit 2.0.0-dev.1604 → 2.0.0-dev.1641

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/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.1604+23a1ea67",
3
+ "version": "2.0.0-dev.1641+6b0c942c",
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.js",
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.ts",
39
- "import": "./dist/mod.js",
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,7 +51,7 @@
53
51
  ],
54
52
  "peerDependencies": {
55
53
  "@sveltejs/kit": "^2.0.0",
56
- "@fedify/fedify": "^2.0.0-dev.1604+23a1ea67"
54
+ "@fedify/fedify": "^2.0.0-dev.1641+6b0c942c"
57
55
  },
58
56
  "devDependencies": {
59
57
  "tsdown": "^0.12.9",