acrylblends 0.7.3 → 0.7.4

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.
Files changed (87) hide show
  1. package/docs/framework/README.md +4 -3
  2. package/docs/framework/UPSTREAM.md +1 -1
  3. package/docs/framework/getting-started/aws-lambda.md +115 -0
  4. package/docs/framework/getting-started/bun.md +1 -3
  5. package/docs/framework/getting-started/cloudflare-pages.md +53 -0
  6. package/docs/framework/getting-started/cloudflare-workers.md +67 -0
  7. package/docs/framework/getting-started/lambda-edge.md +41 -0
  8. package/docs/framework/getting-started/netlify.md +25 -0
  9. package/docs/framework/getting-started/other-runtimes.md +20 -9
  10. package/docs/framework/getting-started/service-worker.md +31 -0
  11. package/docs/framework/getting-started/vercel.md +28 -0
  12. package/docs/framework/guides/create-acrylblends.md +40 -2
  13. package/docs/framework/guides/faq.md +2 -2
  14. package/docs/framework/helpers/conninfo.md +1 -1
  15. package/docs/framework/helpers/ssg.md +1 -1
  16. package/docs/framework/helpers/streaming.md +3 -2
  17. package/docs/framework/helpers/websocket.md +2 -2
  18. package/docs/framework/middleware/builtin/ip-restriction.md +1 -1
  19. package/docs/framework/upstream.json +3 -3
  20. package/lib/aws-lambda.d.ts +324 -0
  21. package/lib/aws-lambda.js +357 -0
  22. package/lib/bun.d.ts +75 -0
  23. package/lib/bun.js +134 -0
  24. package/lib/cloudflare-pages.d.ts +58 -0
  25. package/lib/cloudflare-pages.js +78 -0
  26. package/lib/cloudflare-workers.d.ts +21 -0
  27. package/lib/cloudflare-workers.js +80 -0
  28. package/lib/index-CseujaYI.d.ts +31 -0
  29. package/lib/index-DaJtL7ci.d.ts +156 -0
  30. package/lib/lambda-edge.d.ts +92 -0
  31. package/lib/lambda-edge.js +105 -0
  32. package/lib/netlify.d.ts +29 -0
  33. package/lib/netlify.js +30 -0
  34. package/lib/node-server/register.js +1 -1
  35. package/lib/node-server/serve-static.js +1 -1
  36. package/lib/node-server.js +3 -3
  37. package/lib/serve-static-Cp5adzGo.js +77 -0
  38. package/lib/serve-static.d.ts +1 -30
  39. package/lib/serve-static.js +1 -76
  40. package/lib/service-worker.d.ts +48 -0
  41. package/lib/service-worker.js +38 -0
  42. package/lib/ssg.d.ts +1 -155
  43. package/lib/vercel.d.ts +10 -0
  44. package/lib/vercel.js +9 -0
  45. package/package.json +33 -1
  46. package/plugins/acryl-inspect/upstream.json +1 -1
  47. package/plugins/acryl-node-server/upstream.json +1 -1
  48. package/plugins/acryl-router/src/core/adapter/aws-lambda/conninfo.ts +73 -0
  49. package/plugins/acryl-router/src/core/adapter/aws-lambda/handler.ts +682 -0
  50. package/plugins/acryl-router/src/core/adapter/aws-lambda/index.ts +14 -0
  51. package/plugins/acryl-router/src/core/adapter/aws-lambda/types.ts +173 -0
  52. package/plugins/acryl-router/src/core/adapter/bun/conninfo.ts +43 -0
  53. package/plugins/acryl-router/src/core/adapter/bun/index.ts +11 -0
  54. package/plugins/acryl-router/src/core/adapter/bun/serve-static.ts +32 -0
  55. package/plugins/acryl-router/src/core/adapter/bun/server.ts +14 -0
  56. package/plugins/acryl-router/src/core/adapter/bun/ssg.ts +26 -0
  57. package/plugins/acryl-router/src/core/adapter/bun/websocket.ts +113 -0
  58. package/plugins/acryl-router/src/core/adapter/cloudflare-pages/conninfo.ts +26 -0
  59. package/plugins/acryl-router/src/core/adapter/cloudflare-pages/handler.ts +122 -0
  60. package/plugins/acryl-router/src/core/adapter/cloudflare-pages/index.ts +11 -0
  61. package/plugins/acryl-router/src/core/adapter/cloudflare-workers/conninfo.ts +7 -0
  62. package/plugins/acryl-router/src/core/adapter/cloudflare-workers/index.ts +8 -0
  63. package/plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static-module.ts +12 -0
  64. package/plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static.ts +41 -0
  65. package/plugins/acryl-router/src/core/adapter/cloudflare-workers/utils.ts +50 -0
  66. package/plugins/acryl-router/src/core/adapter/cloudflare-workers/websocket.ts +52 -0
  67. package/plugins/acryl-router/src/core/adapter/lambda-edge/conninfo.ts +15 -0
  68. package/plugins/acryl-router/src/core/adapter/lambda-edge/handler.ts +239 -0
  69. package/plugins/acryl-router/src/core/adapter/lambda-edge/index.ts +14 -0
  70. package/plugins/acryl-router/src/core/adapter/netlify/conninfo.ts +57 -0
  71. package/plugins/acryl-router/src/core/adapter/netlify/handler.ts +10 -0
  72. package/plugins/acryl-router/src/core/adapter/netlify/index.ts +6 -0
  73. package/plugins/acryl-router/src/core/adapter/netlify/mod.ts +2 -0
  74. package/plugins/acryl-router/src/core/adapter/service-worker/handler.ts +37 -0
  75. package/plugins/acryl-router/src/core/adapter/service-worker/index.ts +36 -0
  76. package/plugins/acryl-router/src/core/adapter/service-worker/types.ts +14 -0
  77. package/plugins/acryl-router/src/core/adapter/vercel/conninfo.ts +8 -0
  78. package/plugins/acryl-router/src/core/adapter/vercel/handler.ts +8 -0
  79. package/plugins/acryl-router/src/core/adapter/vercel/index.ts +7 -0
  80. package/plugins/acryl-router/upstream.json +2 -2
  81. package/plugins/acryl-router-http/upstream.json +1 -1
  82. package/plugins/acryl-state/upstream.json +1 -1
  83. package/plugins/desktop/upstream.json +1 -1
  84. package/plugins/desktop-web/upstream.json +1 -1
  85. package/templates/todo/upstream.json +1 -1
  86. package/lib/{serve-static-B14MF1Va.js → serve-static-B849HlX2.js} +1 -1
  87. package/lib/{transpile-CTnWof4z.js → transpile-QUK9b3eG.js} +1 -1
package/lib/ssg.d.ts CHANGED
@@ -1,156 +1,2 @@
1
- import { L as MiddlewareHandler, Y as Schema, t as Context, v as Env } from "./context-DS3fYyG-.js";
2
- import { t as Acryl } from "./app-D8riatvv.js";
3
-
4
- //#region ../../plugins/acryl-router/src/core/helper/ssg/ssg.d.ts
5
- declare const DEFAULT_OUTPUT_DIR = "./static";
6
- /**
7
- * @experimental
8
- * `FileSystemModule` is an experimental feature.
9
- * The API might be changed.
10
- */
11
- interface FileSystemModule {
12
- writeFile(path: string, data: string | Uint8Array): Promise<void>;
13
- mkdir(path: string, options: {
14
- recursive: boolean;
15
- }): Promise<void | string>;
16
- }
17
- /**
18
- * @experimental
19
- * `ToSSGResult` is an experimental feature.
20
- * The API might be changed.
21
- */
22
- interface ToSSGResult {
23
- success: boolean;
24
- files: string[];
25
- error?: Error;
26
- }
27
- declare const defaultExtensionMap: Record<string, string>;
28
- type BeforeRequestHook = (req: Request) => Request | false | Promise<Request | false>;
29
- type AfterResponseHook = (res: Response) => Response | false | Promise<Response | false>;
30
- type AfterGenerateHook = (result: ToSSGResult, fsModule: FileSystemModule, options?: ToSSGOptions) => void | Promise<void>;
31
- declare const combineBeforeRequestHooks: (hooks: BeforeRequestHook | BeforeRequestHook[]) => BeforeRequestHook;
32
- declare const combineAfterResponseHooks: (hooks: AfterResponseHook | AfterResponseHook[]) => AfterResponseHook;
33
- declare const combineAfterGenerateHooks: (hooks: AfterGenerateHook | AfterGenerateHook[], fsModule: FileSystemModule, options?: ToSSGOptions) => AfterGenerateHook;
34
- interface SSGPlugin {
35
- beforeRequestHook?: BeforeRequestHook | BeforeRequestHook[];
36
- afterResponseHook?: AfterResponseHook | AfterResponseHook[];
37
- afterGenerateHook?: AfterGenerateHook | AfterGenerateHook[];
38
- }
39
- interface ToSSGOptions {
40
- dir?: string;
41
- /**
42
- * @deprecated Use plugins[].beforeRequestHook instead.
43
- */
44
- beforeRequestHook?: BeforeRequestHook | BeforeRequestHook[];
45
- /**
46
- * @deprecated Use plugins[].afterResponseHook instead.
47
- */
48
- afterResponseHook?: AfterResponseHook | AfterResponseHook[];
49
- /**
50
- * @deprecated Use plugins[].afterGenerateHook instead.
51
- */
52
- afterGenerateHook?: AfterGenerateHook | AfterGenerateHook[];
53
- concurrency?: number;
54
- extensionMap?: Record<string, string>;
55
- plugins?: SSGPlugin[];
56
- }
57
- /**
58
- * @experimental
59
- * `fetchRoutesContent` is an experimental feature.
60
- * The API might be changed.
61
- */
62
- declare const fetchRoutesContent: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Acryl<E, S, BasePath>, beforeRequestHook?: BeforeRequestHook, afterResponseHook?: AfterResponseHook, concurrency?: number) => Generator<Promise<Generator<Promise<{
63
- routePath: string;
64
- mimeType: string;
65
- content: string | ArrayBuffer;
66
- } | undefined>> | undefined>>;
67
- declare const saveContentToFile: (data: Promise<{
68
- routePath: string;
69
- content: string | ArrayBuffer;
70
- mimeType: string;
71
- } | undefined>, fsModule: FileSystemModule, outDir: string, extensionMap?: Record<string, string>) => Promise<string | undefined>;
72
- /**
73
- * @experimental
74
- * `ToSSGInterface` is an experimental feature.
75
- * The API might be changed.
76
- */
77
- interface ToSSGInterface {
78
- (app: Acryl<any, any, any>, fsModule: FileSystemModule, options?: ToSSGOptions): Promise<ToSSGResult>;
79
- }
80
- /**
81
- * @experimental
82
- * `ToSSGAdaptorInterface` is an experimental feature.
83
- * The API might be changed.
84
- */
85
- interface ToSSGAdaptorInterface<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> {
86
- (app: Acryl<E, S, BasePath>, options?: ToSSGOptions): Promise<ToSSGResult>;
87
- }
88
- /**
89
- * @experimental
90
- * `toSSG` is an experimental feature.
91
- * The API might be changed.
92
- */
93
- declare const toSSG: ToSSGInterface;
94
- //#endregion
95
- //#region ../../plugins/acryl-router/src/core/helper/ssg/middleware.d.ts
96
- declare const X_ACRYL_DISABLE_SSG_HEADER_KEY = "x-acryl-disable-ssg";
97
- interface SSGParam {
98
- [key: string]: string;
99
- }
100
- type SSGParams = SSGParam[];
101
- interface SSGParamsMiddleware {
102
- <E extends Env = Env>(generateParams: (c: Context<E>) => SSGParams | Promise<SSGParams>): MiddlewareHandler<E>;
103
- <E extends Env = Env>(params: SSGParams): MiddlewareHandler<E>;
104
- }
105
- /**
106
- * Define SSG Route
107
- */
108
- declare const ssgParams: SSGParamsMiddleware;
109
- /**
110
- * @experimental
111
- * `isSSGContext` is an experimental feature.
112
- * The API might be changed.
113
- */
114
- declare const isSSGContext: (c: Context) => boolean;
115
- /**
116
- * @experimental
117
- * `disableSSG` is an experimental feature.
118
- * The API might be changed.
119
- */
120
- declare const disableSSG: () => MiddlewareHandler;
121
- /**
122
- * @experimental
123
- * `onlySSG` is an experimental feature.
124
- * The API might be changed.
125
- */
126
- declare const onlySSG: () => MiddlewareHandler;
127
- //#endregion
128
- //#region ../../plugins/acryl-router/src/core/helper/ssg/plugins.d.ts
129
- /**
130
- * The default plugin that defines the recommended behavior.
131
- *
132
- * @experimental
133
- * `defaultPlugin` is an experimental feature.
134
- * The API might be changed.
135
- */
136
- declare const defaultPlugin: () => SSGPlugin;
137
- /**
138
- * The redirect plugin that generates HTML redirect pages for HTTP redirect responses for status codes 301, 302, 303, 307 and 308.
139
- *
140
- * When used with `defaultPlugin`, place `redirectPlugin` before it, because `defaultPlugin` skips non-200 responses.
141
- *
142
- * ```ts
143
- * // ✅ Will work as expected
144
- * toSSG(app, fs, { plugins: [redirectPlugin(), defaultPlugin()] })
145
- *
146
- * // ❌ Will not work as expected
147
- * toSSG(app, fs, { plugins: [defaultPlugin(), redirectPlugin()] })
148
- * ```
149
- *
150
- * @experimental
151
- * `redirectPlugin` is an experimental feature.
152
- * The API might be changed.
153
- */
154
- declare const redirectPlugin: () => SSGPlugin;
155
- //#endregion
1
+ import { C as saveContentToFile, S as fetchRoutesContent, _ as ToSSGResult, a as isSSGContext, b as combineBeforeRequestHooks, c as AfterGenerateHook, d as DEFAULT_OUTPUT_DIR, f as FileSystemModule, g as ToSSGOptions, h as ToSSGInterface, i as disableSSG, l as AfterResponseHook, m as ToSSGAdaptorInterface, n as redirectPlugin, o as onlySSG, p as SSGPlugin, r as X_ACRYL_DISABLE_SSG_HEADER_KEY, s as ssgParams, t as defaultPlugin, u as BeforeRequestHook, v as combineAfterGenerateHooks, w as toSSG, x as defaultExtensionMap, y as combineAfterResponseHooks } from "./index-DaJtL7ci.js";
156
2
  export { AfterGenerateHook, AfterResponseHook, BeforeRequestHook, DEFAULT_OUTPUT_DIR, FileSystemModule, SSGPlugin, ToSSGAdaptorInterface, ToSSGInterface, ToSSGOptions, ToSSGResult, X_ACRYL_DISABLE_SSG_HEADER_KEY, combineAfterGenerateHooks, combineAfterResponseHooks, combineBeforeRequestHooks, defaultExtensionMap, defaultPlugin, disableSSG, fetchRoutesContent, isSSGContext, onlySSG, redirectPlugin, saveContentToFile, ssgParams, toSSG };
@@ -0,0 +1,10 @@
1
+ import { r as GetConnInfo } from "./types-Dv_nV2cv.js";
2
+ import { t as Acryl } from "./app-D8riatvv.js";
3
+
4
+ //#region ../../plugins/acryl-router/src/core/adapter/vercel/handler.d.ts
5
+ declare const handle: (app: Acryl<any, any, any>) => (req: Request) => Response | Promise<Response>;
6
+ //#endregion
7
+ //#region ../../plugins/acryl-router/src/core/adapter/vercel/conninfo.d.ts
8
+ declare const getConnInfo: GetConnInfo;
9
+ //#endregion
10
+ export { getConnInfo, handle };
package/lib/vercel.js ADDED
@@ -0,0 +1,9 @@
1
+ //#region ../../plugins/acryl-router/src/core/adapter/vercel/handler.ts
2
+ const handle = (app) => (req) => {
3
+ return app.fetch(req);
4
+ };
5
+ //#endregion
6
+ //#region ../../plugins/acryl-router/src/core/adapter/vercel/conninfo.ts
7
+ const getConnInfo = (c) => ({ remote: { address: c.req.header("x-real-ip") } });
8
+ //#endregion
9
+ export { getConnInfo, handle };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acrylblends",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "The Acryl web framework (import { Acryl } from \"acrylblends\") and the acrylblends command that scaffolds Cordis apps.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -190,6 +190,38 @@
190
190
  "types": "./lib/testing.d.ts",
191
191
  "default": "./lib/testing.js"
192
192
  },
193
+ "./aws-lambda": {
194
+ "types": "./lib/aws-lambda.d.ts",
195
+ "default": "./lib/aws-lambda.js"
196
+ },
197
+ "./bun": {
198
+ "types": "./lib/bun.d.ts",
199
+ "default": "./lib/bun.js"
200
+ },
201
+ "./cloudflare-pages": {
202
+ "types": "./lib/cloudflare-pages.d.ts",
203
+ "default": "./lib/cloudflare-pages.js"
204
+ },
205
+ "./cloudflare-workers": {
206
+ "types": "./lib/cloudflare-workers.d.ts",
207
+ "default": "./lib/cloudflare-workers.js"
208
+ },
209
+ "./lambda-edge": {
210
+ "types": "./lib/lambda-edge.d.ts",
211
+ "default": "./lib/lambda-edge.js"
212
+ },
213
+ "./netlify": {
214
+ "types": "./lib/netlify.d.ts",
215
+ "default": "./lib/netlify.js"
216
+ },
217
+ "./service-worker": {
218
+ "types": "./lib/service-worker.d.ts",
219
+ "default": "./lib/service-worker.js"
220
+ },
221
+ "./vercel": {
222
+ "types": "./lib/vercel.d.ts",
223
+ "default": "./lib/vercel.js"
224
+ },
193
225
  "./ws": {
194
226
  "types": "./lib/ws.d.ts",
195
227
  "default": "./lib/ws.js"
@@ -2,7 +2,7 @@
2
2
  "source": {
3
3
  "repo": "acryldev/acryl",
4
4
  "path": "plugins/acryl-inspect",
5
- "commit": "e79bf3de59c700667ae617f5d367cc1fd2f8e037"
5
+ "commit": "eada6fb06a5cafb6c2c92a97effeba567dbd44ba"
6
6
  },
7
7
  "vendored": [
8
8
  "src",
@@ -2,7 +2,7 @@
2
2
  "source": {
3
3
  "repo": "acryldev/acryl",
4
4
  "path": "plugins/acryl-node-server",
5
- "commit": "e79bf3de59c700667ae617f5d367cc1fd2f8e037"
5
+ "commit": "eada6fb06a5cafb6c2c92a97effeba567dbd44ba"
6
6
  },
7
7
  "vendored": [
8
8
  "src",
@@ -0,0 +1,73 @@
1
+ import type { Context } from '../../context.ts'
2
+ import type { GetConnInfo } from '../../helper/conninfo/index.ts'
3
+ import type {
4
+ ApiGatewayRequestContext,
5
+ ApiGatewayRequestContextV2,
6
+ ALBRequestContext,
7
+ } from './types.ts'
8
+
9
+ type LambdaRequestContext =
10
+ | ApiGatewayRequestContext
11
+ | ApiGatewayRequestContextV2
12
+ | ALBRequestContext
13
+
14
+ type Env = {
15
+ Bindings: {
16
+ requestContext: LambdaRequestContext
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Get connection information from AWS Lambda
22
+ *
23
+ * Extracts client IP from various Lambda event sources:
24
+ * - API Gateway v1 (REST API): requestContext.identity.sourceIp
25
+ * - API Gateway v2 (HTTP API/Function URLs): requestContext.http.sourceIp
26
+ * - ALB: Falls back to x-forwarded-for header
27
+ *
28
+ * @param c - Context
29
+ * @returns Connection information including remote address
30
+ * @example
31
+ * ```ts
32
+ * import { Acryl } from 'acrylblends'
33
+ * import { handle, getConnInfo } from 'acrylblends/aws-lambda'
34
+ *
35
+ * const app = new Acryl()
36
+ *
37
+ * app.get('/', (c) => {
38
+ * const info = getConnInfo(c)
39
+ * return c.text(`Your IP: ${info.remote.address}`)
40
+ * })
41
+ *
42
+ * export const handler = handle(app)
43
+ * ```
44
+ */
45
+ export const getConnInfo: GetConnInfo = (c: Context<Env>) => {
46
+ const requestContext = c.env.requestContext
47
+
48
+ let address: string | undefined
49
+
50
+ // API Gateway v1 - has identity object
51
+ if ('identity' in requestContext && requestContext.identity?.sourceIp) {
52
+ address = requestContext.identity.sourceIp
53
+ }
54
+ // API Gateway v2 - has http object
55
+ else if ('http' in requestContext && requestContext.http?.sourceIp) {
56
+ address = requestContext.http.sourceIp
57
+ }
58
+ // ALB - use X-Forwarded-For header
59
+ else {
60
+ const xff = c.req.header('x-forwarded-for')
61
+ if (xff) {
62
+ const ips = xff.split(',')
63
+ // ALB appends the real client IP to the end of the header
64
+ address = ips[ips.length - 1].trim()
65
+ }
66
+ }
67
+
68
+ return {
69
+ remote: {
70
+ address,
71
+ },
72
+ }
73
+ }