@fedify/fedify 0.12.0-dev.307 → 0.12.0

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/CHANGES.md CHANGED
@@ -6,7 +6,7 @@ Fedify changelog
6
6
  Version 0.12.0
7
7
  --------------
8
8
 
9
- To be released.
9
+ Released on July 24, 2024.
10
10
 
11
11
  - The `fedify` command is now [available on npm][@fedify/cli]. [[#104]]
12
12
 
@@ -131,13 +131,6 @@ To be released.
131
131
  the `getAuthenticatedDocumentLoader()` function, which can be used to
132
132
  allow fetching private network addresses.
133
133
 
134
- - Added `@fedify/fedify/x/astro` module for integrating with [Astro]
135
- middleware. [[#50]]
136
-
137
- - Added `createMiddleware()` function.
138
- - Added `createFetchOptions()` function.
139
- - Added `ContextDataFactory` type.
140
-
141
134
  - Added `fedify init` subcommand. [[#105]]
142
135
 
143
136
  - Added more log messages using the [LogTape] library. Currently the below
@@ -147,7 +140,6 @@ To be released.
147
140
 
148
141
  [@fedify/cli]: https://www.npmjs.com/package/@fedify/cli
149
142
  [#6]: https://github.com/dahlia/fedify/issues/6
150
- [#50]: https://github.com/dahlia/fedify/issues/50
151
143
  [#53]: https://github.com/dahlia/fedify/issues/53
152
144
  [#66]: https://github.com/dahlia/fedify/issues/66
153
145
  [#70]: https://github.com/dahlia/fedify/issues/70
@@ -157,7 +149,6 @@ To be released.
157
149
  [#104]: https://github.com/dahlia/fedify/issues/104
158
150
  [#105]: https://github.com/dahlia/fedify/issues/105
159
151
  [#107]: https://github.com/dahlia/fedify/issues/107
160
- [Astro]: https://astro.build/
161
152
 
162
153
 
163
154
  Version 0.11.3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/fedify",
3
- "version": "0.12.0-dev.307+235629d5",
3
+ "version": "0.12.0",
4
4
  "description": "An ActivityPub server framework",
5
5
  "keywords": [
6
6
  "ActivityPub",
@@ -65,12 +65,6 @@
65
65
  "default": "./esm/webfinger/mod.js"
66
66
  }
67
67
  },
68
- "./x/astro": {
69
- "import": {
70
- "types": "./types/x/astro.d.ts",
71
- "default": "./esm/x/astro.js"
72
- }
73
- },
74
68
  "./x/hono": {
75
69
  "import": {
76
70
  "types": "./types/x/hono.d.ts",
package/esm/x/astro.js DELETED
@@ -1,86 +0,0 @@
1
- /**
2
- * Create options for the {@link Federation.fetch} method to integrate with
3
- * Astro.
4
- *
5
- * @example src/middleware.ts
6
- * ``` typescript
7
- * import { defineMiddleware } from "astro:middleware";
8
- * import { createFetchOptions } from "@fedify/fedify/x/astro";
9
- * import { federation } from "./federation"; // Import the `Federation` object
10
- *
11
- * export const onRequest = defineMiddleware((context, next) => {
12
- * return federation.fetch(context.request, {
13
- * contextData: undefined,
14
- * ...createFetchOptions(context, next),
15
- * });
16
- * });
17
- * ```
18
- *
19
- * @typeParam TAstroContext A type of the Astro context.
20
- * @param context An Astro context.
21
- * @param next A function to call the next middleware.
22
- * @returns Options for the {@link Federation.fetch} method.
23
- * @since 0.12.0
24
- */
25
- export function createFetchOptions(_context, next) {
26
- return {
27
- // If the `federation` object finds a request not responsible for it
28
- // (i.e., not a federation-related request), it will call the `next`
29
- // provided by the Astro framework to continue the request handling
30
- // by Astro:
31
- onNotFound: next,
32
- // Similar to `onNotFound`, but slightly more tricky one.
33
- // When the `federation` object finds a request not acceptable type-wise
34
- // (i.e., a user-agent doesn't want JSON-LD), it will call the `next`
35
- // provided by the Astro framework so that it renders HTML if there's some
36
- // page. Otherwise, it will simply return a 406 Not Acceptable response.
37
- // This kind of trick enables the Fedify and Astro to share the same routes
38
- // and they do content negotiation depending on `Accept` header:
39
- async onNotAcceptable(_request) {
40
- const response = await next();
41
- if (response.status !== 404)
42
- return response;
43
- return new Response("Not acceptable", {
44
- status: 406,
45
- headers: {
46
- "Content-Type": "text/plain",
47
- Vary: "Accept",
48
- },
49
- });
50
- },
51
- };
52
- }
53
- /**
54
- * Create an Astro middleware handler to integrate with the {@link Federation}
55
- * object.
56
- *
57
- * @example src/middleware.ts
58
- * ``` typescript
59
- * import type { MiddlewareHandler } from "astro";
60
- * import { createMiddleware } from "@fedify/fedify/x/astro";
61
- * import { federation } from "./federation"; // Import the `Federation` object
62
- *
63
- * export const onRequest: MiddlewareHandler = createMiddleware(
64
- * federation,
65
- * (astroContext) => "context data",
66
- * );
67
- * ```
68
- *
69
- * @typeParam TContextData A type of the context data for the {@link Federation}
70
- * object.
71
- * @typeParam TAstroContext A type of the Astro context.
72
- * @param federation A {@link Federation} object to integrate with Astro.
73
- * @param contextDataFactory A factory function to create a context data for the
74
- * {@link Federation} object.
75
- * @returns An Astro middleware handler.
76
- * @since 0.12.0
77
- */
78
- export function createMiddleware(federation, contextDataFactory) {
79
- return async (context, next) => {
80
- const contextData = await contextDataFactory(context);
81
- return await federation.fetch(context.request, {
82
- contextData,
83
- ...createFetchOptions(context, next),
84
- });
85
- };
86
- }
@@ -1,90 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /**
4
- * Fedify with Astro
5
- * =================
6
- *
7
- * This module contains some utilities for integrating Fedify with
8
- * the [Astro] framework.
9
- *
10
- * > [!NOTE]
11
- * >
12
- * > Astro integration requires [on-demand server rendering][1].
13
- *
14
- * [Astro]: https://astro.build/
15
- * [1]: https://docs.astro.build/en/guides/server-side-rendering/
16
- *
17
- * @module
18
- * @since 0.12.0
19
- */
20
- import type { Federation, FederationFetchOptions } from "../federation/middleware.js";
21
- interface AstroContext {
22
- request: Request;
23
- }
24
- type RewritePayload = string | URL | Request;
25
- type MiddlewareNext = (rewritePayload?: RewritePayload) => Promise<Response>;
26
- type MiddlewareHandler<TAstroContext extends AstroContext> = (context: TAstroContext, next: MiddlewareNext) => Promise<Response> | Response | Promise<void> | void;
27
- /**
28
- * Create options for the {@link Federation.fetch} method to integrate with
29
- * Astro.
30
- *
31
- * @example src/middleware.ts
32
- * ``` typescript
33
- * import { defineMiddleware } from "astro:middleware";
34
- * import { createFetchOptions } from "@fedify/fedify/x/astro";
35
- * import { federation } from "./federation"; // Import the `Federation` object
36
- *
37
- * export const onRequest = defineMiddleware((context, next) => {
38
- * return federation.fetch(context.request, {
39
- * contextData: undefined,
40
- * ...createFetchOptions(context, next),
41
- * });
42
- * });
43
- * ```
44
- *
45
- * @typeParam TAstroContext A type of the Astro context.
46
- * @param context An Astro context.
47
- * @param next A function to call the next middleware.
48
- * @returns Options for the {@link Federation.fetch} method.
49
- * @since 0.12.0
50
- */
51
- export declare function createFetchOptions<TAstroContext extends AstroContext>(_context: TAstroContext, next: MiddlewareNext): Omit<FederationFetchOptions<void>, "contextData">;
52
- /**
53
- * The factory function to create a context data for
54
- * the {@link Federation.fetch}.
55
- *
56
- * @typeParam TContextData A type of the context data.
57
- * @typeParam TAstroContext A type of the Astro context.
58
- * @param context An Astro context.
59
- * @returns The context data for the {@link Federation.fetch}.
60
- * @since 0.12.0
61
- */
62
- export type ContextDataFactory<TContextData, TAstroContext extends AstroContext> = (context: TAstroContext) => TContextData | Promise<TContextData>;
63
- /**
64
- * Create an Astro middleware handler to integrate with the {@link Federation}
65
- * object.
66
- *
67
- * @example src/middleware.ts
68
- * ``` typescript
69
- * import type { MiddlewareHandler } from "astro";
70
- * import { createMiddleware } from "@fedify/fedify/x/astro";
71
- * import { federation } from "./federation"; // Import the `Federation` object
72
- *
73
- * export const onRequest: MiddlewareHandler = createMiddleware(
74
- * federation,
75
- * (astroContext) => "context data",
76
- * );
77
- * ```
78
- *
79
- * @typeParam TContextData A type of the context data for the {@link Federation}
80
- * object.
81
- * @typeParam TAstroContext A type of the Astro context.
82
- * @param federation A {@link Federation} object to integrate with Astro.
83
- * @param contextDataFactory A factory function to create a context data for the
84
- * {@link Federation} object.
85
- * @returns An Astro middleware handler.
86
- * @since 0.12.0
87
- */
88
- export declare function createMiddleware<TContextData, TAstroContext extends AstroContext>(federation: Federation<TContextData>, contextDataFactory: ContextDataFactory<TContextData, TAstroContext>): MiddlewareHandler<TAstroContext>;
89
- export {};
90
- //# sourceMappingURL=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