acrylblends 0.11.0 → 1.0.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/README.md +131 -53
- package/dist/index.d.ts +29 -2
- package/dist/index.js +450 -69
- package/dist/index.js.map +1 -1
- package/docs/framework/README.md +5 -3
- package/docs/framework/agents/index.md +1 -1
- package/docs/framework/api/acryl.md +5 -17
- package/docs/framework/api/context.md +12 -61
- package/docs/framework/api/presets.md +1 -1
- package/docs/framework/api/request.md +3 -3
- package/docs/framework/api/summary.md +1 -1
- package/docs/framework/concepts/web-standard.md +6 -16
- package/docs/framework/cordis/acryl-in-a-cordis-app.md +13 -8
- package/docs/framework/cordis/migration-from-0-4.md +1 -1
- package/docs/framework/cordis/migration-to-1-0.md +45 -0
- package/docs/framework/cordis/node-server.md +2 -2
- package/docs/framework/getting-started/basic.md +15 -10
- package/docs/framework/getting-started/desktop.md +1 -1
- package/docs/framework/getting-started/other-runtimes.md +10 -14
- package/docs/framework/guides/create-acrylblends.md +4 -2
- package/docs/framework/guides/data.md +1 -1
- package/docs/framework/guides/faq.md +1 -1
- package/docs/framework/guides/jsx-dom.md +1 -1
- package/docs/framework/guides/production.md +43 -0
- package/docs/framework/guides/rpc.md +3 -11
- package/docs/framework/helpers/adapter.md +13 -43
- package/docs/framework/helpers/conninfo.md +1 -36
- package/docs/framework/helpers/streaming.md +1 -1
- package/docs/framework/helpers/websocket.md +4 -11
- package/docs/framework/middleware/builtin/basic-auth.md +1 -1
- package/docs/framework/middleware/builtin/cache.md +2 -22
- package/docs/framework/middleware/builtin/compress.md +1 -1
- package/docs/framework/middleware/builtin/context-storage.md +10 -14
- package/docs/framework/middleware/builtin/cors.md +1 -2
- package/docs/framework/middleware/builtin/ip-restriction.md +1 -1
- package/docs/framework/middleware/builtin/jsx-renderer.md +1 -1
- package/docs/framework/middleware/builtin/logger.md +1 -1
- package/docs/framework/middleware/builtin/loopback-only.md +1 -1
- package/docs/framework/middleware/builtin/mount.md +1 -1
- package/docs/framework/middleware/builtin/request-id.md +13 -20
- package/docs/framework/middleware/builtin/timing.md +1 -2
- package/lib/cordis/door.d.ts +5 -0
- package/lib/cordis/door.js +8 -4
- package/lib/cordis/inspect.js +1 -1
- package/lib/cordis/router-http.js +1 -1
- package/lib/cordis/router.d.ts +1 -2
- package/lib/cordis/router.js +2 -3
- package/lib/cordis/state.js +1 -1
- package/lib/door/host.js +1 -1
- package/lib/drivers.d.ts +66 -0
- package/lib/drivers.js +16 -0
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -2
- package/lib/{snapshot-text-yaWlezbd.js → snapshot-text-DmE0YfeZ.js} +2 -2
- package/lib/{src-DNzw0Qsb.js → src-2Z4mJg0x.js} +0 -1
- package/package.json +5 -121
- package/plugins/acryl-door/src/index.ts +8 -0
- package/plugins/acryl-router/src/index.ts +0 -1
- package/plugins/agent-panel/drivers.ts +1 -16
- package/plugins/agent-panel/index.ts +1 -1
- package/plugins/agent-panel/registry.ts +16 -0
- package/plugins/driver-acp/README.md +53 -0
- package/plugins/driver-acp/chat.ts +258 -0
- package/plugins/driver-acp/connection.ts +239 -0
- package/plugins/driver-acp/index.ts +65 -0
- package/plugins/driver-acp/plugin.json +12 -0
- package/plugins/driver-acp/provenance.json +20 -0
- package/plugins/driver-pty/index.ts +1 -0
- package/shared/library-history.json +464 -0
- package/docs/framework/getting-started/aws-lambda.md +0 -115
- package/docs/framework/getting-started/cloudflare-pages.md +0 -53
- package/docs/framework/getting-started/cloudflare-workers.md +0 -67
- package/docs/framework/getting-started/lambda-edge.md +0 -41
- package/docs/framework/getting-started/netlify.md +0 -25
- package/docs/framework/getting-started/service-worker.md +0 -33
- package/docs/framework/getting-started/vercel.md +0 -28
- package/lib/aws-lambda.d.ts +0 -324
- package/lib/aws-lambda.js +0 -357
- package/lib/cloudflare-pages.d.ts +0 -58
- package/lib/cloudflare-pages.js +0 -78
- package/lib/cloudflare-workers.d.ts +0 -21
- package/lib/cloudflare-workers.js +0 -80
- package/lib/deprecated-BP4fPt38.js +0 -10
- package/lib/deprecated-CTy4N7ng.d.ts +0 -12
- package/lib/lambda-edge.d.ts +0 -92
- package/lib/lambda-edge.js +0 -105
- package/lib/netlify.d.ts +0 -29
- package/lib/netlify.js +0 -30
- package/lib/service-worker.d.ts +0 -48
- package/lib/service-worker.js +0 -38
- package/lib/vercel.d.ts +0 -10
- package/lib/vercel.js +0 -9
- package/plugins/acryl-router/src/deprecated.ts +0 -15
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# Cloudflare Workers
|
|
2
|
-
|
|
3
|
-
A Cloudflare Worker is a module that exports a `fetch` handler, which is what an Acryl app has: `export default app` is a Worker. The adapter `acrylblends/cloudflare-workers` adds the pieces that need Cloudflare: the client's address, WebSockets, and (deprecated) serving static files from Workers KV.
|
|
4
|
-
|
|
5
|
-
> **Status.** The adapter is the upstream adapter ported with its test suite, and a Worker with these routes (`export default app`, bindings from `vars`, `getConnInfo`, `waitUntil`) has been run in `workerd` with `wrangler dev --local`, which needs no Cloudflare account. The ACRYL team has not deployed to Cloudflare itself: run `wrangler dev` first.
|
|
6
|
-
|
|
7
|
-
## A Worker
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
import { Acryl } from 'acrylblends'
|
|
11
|
-
|
|
12
|
-
const app = new Acryl()
|
|
13
|
-
|
|
14
|
-
app.get('/', (c) => c.text('Hello Cloudflare Workers!'))
|
|
15
|
-
|
|
16
|
-
export default app
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
With Wrangler: a `wrangler.jsonc` naming the entry file and a compatibility date (`"main": "src/index.ts"`, `"compatibility_date": "2026-01-01"`), then `npx wrangler dev` to run it locally and `npx wrangler deploy` to publish it.
|
|
20
|
-
|
|
21
|
-
## Bindings and the execution context
|
|
22
|
-
|
|
23
|
-
Environment variables, secrets, KV namespaces, D1 databases and R2 buckets arrive as `c.env`; the `ExecutionContext` is `c.executionCtx`:
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import { Acryl } from 'acrylblends'
|
|
27
|
-
|
|
28
|
-
type Bindings = {
|
|
29
|
-
MY_SECRET: string
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const app = new Acryl<{ Bindings: Bindings }>()
|
|
33
|
-
|
|
34
|
-
app.get('/', (c) => {
|
|
35
|
-
c.executionCtx.waitUntil(Promise.resolve()) // work that may finish after the response
|
|
36
|
-
return c.text(c.env.MY_SECRET ? 'configured' : 'missing')
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
export default app
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## The client's address
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
import { Acryl } from 'acrylblends'
|
|
46
|
-
import { getConnInfo } from 'acrylblends/cloudflare-workers'
|
|
47
|
-
|
|
48
|
-
const app = new Acryl()
|
|
49
|
-
|
|
50
|
-
app.get('/ip', (c) => c.text(getConnInfo(c).remote.address ?? 'unknown'))
|
|
51
|
-
|
|
52
|
-
export default app
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
It reads the `cf-connecting-ip` header that Cloudflare sets. See the [ConnInfo helper](../helpers/conninfo.md).
|
|
56
|
-
|
|
57
|
-
## WebSockets
|
|
58
|
-
|
|
59
|
-
`upgradeWebSocket` from `acrylblends/cloudflare-workers` accepts the upgrade with Cloudflare's `WebSocketPair`. Cloudflare does not give an `onOpen` event. See the [WebSocket helper](../helpers/websocket.md).
|
|
60
|
-
|
|
61
|
-
## Static files
|
|
62
|
-
|
|
63
|
-
Prefer Cloudflare's static assets (the `assets` setting of Wrangler), which serve files before your code runs. `serveStatic` from `acrylblends/cloudflare-workers`, which reads files from Workers KV (`__STATIC_CONTENT`), is deprecated by Cloudflare's move to static assets and is kept for existing Workers Sites projects. Cloudflare Pages is the other option: see [Cloudflare Pages](cloudflare-pages.md).
|
|
64
|
-
|
|
65
|
-
## Service Worker syntax
|
|
66
|
-
|
|
67
|
-
A Worker written in the old non-module syntax (`addEventListener('fetch', ...)`) uses `fire` from `acrylblends/service-worker`: see [Service Worker](service-worker.md).
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# Lambda@Edge
|
|
2
|
-
|
|
3
|
-
An Acryl app can answer CloudFront requests from Lambda@Edge. `handle(app)` from `acrylblends/lambda-edge` turns the app into the edge function: it builds a `Request` from the CloudFront event, calls `app.fetch`, and returns a CloudFront response. A viewer-request or origin-request function that answers by itself (a redirect, an HTML page, a JSON answer) is the typical use.
|
|
4
|
-
|
|
5
|
-
> **Status.** The adapter is the upstream adapter ported with its test suite, and the framework's release check calls it with a CloudFront viewer-request event. It has not been deployed to AWS by the ACRYL team.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Acryl } from 'acrylblends'
|
|
9
|
-
import { handle } from 'acrylblends/lambda-edge'
|
|
10
|
-
|
|
11
|
-
const app = new Acryl()
|
|
12
|
-
|
|
13
|
-
app.get('/', (c) => c.text('Hello from the edge'))
|
|
14
|
-
|
|
15
|
-
export const handler = handle(app)
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Lambda@Edge has its own limits: the function must be created in `us-east-1`, has no environment variables, and its size and time limits are lower than Lambda's; check them in the AWS documentation when you choose between this adapter and [AWS Lambda](aws-lambda.md).
|
|
19
|
-
|
|
20
|
-
## The CloudFront event
|
|
21
|
-
|
|
22
|
-
The CloudFront request, response and config are in the bindings:
|
|
23
|
-
|
|
24
|
-
```ts
|
|
25
|
-
import { Acryl } from 'acrylblends'
|
|
26
|
-
import type { Callback, CloudFrontEdgeEvent } from 'acrylblends/lambda-edge'
|
|
27
|
-
|
|
28
|
-
type Bindings = {
|
|
29
|
-
callback: Callback
|
|
30
|
-
event: CloudFrontEdgeEvent
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const app = new Acryl<{ Bindings: Bindings }>()
|
|
34
|
-
|
|
35
|
-
app.get('/country', (c) => {
|
|
36
|
-
const request = c.env.event.Records[0].cf.request
|
|
37
|
-
return c.json({ uri: request.uri, clientIp: request.clientIp })
|
|
38
|
-
})
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
The client's address is available through the [ConnInfo helper](../helpers/conninfo.md).
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Netlify
|
|
2
|
-
|
|
3
|
-
Netlify Functions (version 2) and Edge Functions take a `Request` and a context and return a `Response`. `handle(app)` from `acrylblends/netlify` is that function; the Netlify context is available to the app as `c.env.context`.
|
|
4
|
-
|
|
5
|
-
> **Status.** The adapter is the upstream adapter ported with its test suite, and the framework's release check calls it with a `Request`. It has not been deployed to Netlify by the ACRYL team.
|
|
6
|
-
|
|
7
|
-
## A function
|
|
8
|
-
|
|
9
|
-
`netlify/functions/api.ts`:
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
import { Acryl } from 'acrylblends'
|
|
13
|
-
import { handle } from 'acrylblends/netlify'
|
|
14
|
-
import type { Context } from '@netlify/functions'
|
|
15
|
-
|
|
16
|
-
type Bindings = { context: Context }
|
|
17
|
-
|
|
18
|
-
const app = new Acryl<{ Bindings: Bindings }>().basePath('/.netlify/functions/api')
|
|
19
|
-
|
|
20
|
-
app.get('/hello', (c) => c.json({ hello: 'world', site: c.env.context.site.id }))
|
|
21
|
-
|
|
22
|
-
export default handle(app)
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Run it locally with `netlify dev` and publish with `netlify deploy`. The client's address comes from `getConnInfo` of `acrylblends/netlify` (the Netlify context's `ip`); see the [ConnInfo helper](../helpers/conninfo.md).
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Service Worker
|
|
2
|
-
|
|
3
|
-
An Acryl app can answer `fetch` events in a Service Worker, and in any environment that uses the Service Worker syntax, such as a Cloudflare Worker written without ES modules. `fire(app)` from `acrylblends/service-worker` registers the app on the `fetch` event, and `handle(app)` returns the listener, if you want to register it yourself.
|
|
4
|
-
|
|
5
|
-
> **Status.** The adapter is the upstream adapter ported with its test suite, and the framework's release check calls it with a fetch event. It has not been run inside a browser's Service Worker by the ACRYL team.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Acryl } from 'acrylblends'
|
|
9
|
-
import { fire } from 'acrylblends/service-worker'
|
|
10
|
-
|
|
11
|
-
const app = new Acryl()
|
|
12
|
-
|
|
13
|
-
app.get('/', (c) => c.text('Hello from a Service Worker'))
|
|
14
|
-
|
|
15
|
-
fire(app)
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
A request the app does not answer (`404`) can be passed on to the network by giving `fetch` as an option, so a Service Worker can serve some routes and leave the others to the origin:
|
|
19
|
-
|
|
20
|
-
```ts lib=webworker
|
|
21
|
-
import { Acryl } from 'acrylblends'
|
|
22
|
-
import { handle } from 'acrylblends/service-worker'
|
|
23
|
-
|
|
24
|
-
declare const self: ServiceWorkerGlobalScope
|
|
25
|
-
|
|
26
|
-
const app = new Acryl()
|
|
27
|
-
|
|
28
|
-
app.get('/offline', (c) => c.text('Served by the Service Worker'))
|
|
29
|
-
|
|
30
|
-
self.addEventListener('fetch', handle(app, { fetch: globalThis.fetch }))
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
The example is type-checked with the TypeScript `WebWorker` library: declare `self` as a `ServiceWorkerGlobalScope` as above. `app.fire()` (a method of the app) is deprecated in favour of `fire()` from this module.
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Vercel
|
|
2
|
-
|
|
3
|
-
Vercel runs a function that takes a `Request` and returns a `Response`, which is what `app.fetch` is. `handle(app)` from `acrylblends/vercel` is that function.
|
|
4
|
-
|
|
5
|
-
> **Status.** The adapter is the upstream adapter ported with its test suite, and the framework's release check calls it with a `Request`. It has not been deployed to Vercel by the ACRYL team.
|
|
6
|
-
|
|
7
|
-
## A function
|
|
8
|
-
|
|
9
|
-
Create `api/index.ts`:
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
import { Acryl } from 'acrylblends'
|
|
13
|
-
import { handle } from 'acrylblends/vercel'
|
|
14
|
-
|
|
15
|
-
const app = new Acryl().basePath('/api')
|
|
16
|
-
|
|
17
|
-
app.get('/', (c) => c.text('Hello from Vercel'))
|
|
18
|
-
app.get('/hello', (c) => c.json({ hello: 'world' }))
|
|
19
|
-
|
|
20
|
-
export const GET = handle(app)
|
|
21
|
-
export const POST = handle(app)
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Export one handler per HTTP method the app answers. Run it locally with `vercel dev`, and publish with `vercel deploy`.
|
|
25
|
-
|
|
26
|
-
## The client's address
|
|
27
|
-
|
|
28
|
-
The client's address comes from `getConnInfo` of `acrylblends/vercel`, which reads the `x-real-ip` header Vercel sets; see the [ConnInfo helper](../helpers/conninfo.md).
|
package/lib/aws-lambda.d.ts
DELETED
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
import { Y as Schema, v as Env } from "./context-DS3fYyG-.js";
|
|
2
|
-
import { r as GetConnInfo } from "./types-Dv_nV2cv.js";
|
|
3
|
-
import { t as Acryl } from "./app-D8riatvv.js";
|
|
4
|
-
|
|
5
|
-
//#region ../../plugins/acryl-router/src/core/adapter/aws-lambda/types.d.ts
|
|
6
|
-
interface CognitoIdentity {
|
|
7
|
-
cognitoIdentityId: string;
|
|
8
|
-
cognitoIdentityPoolId: string;
|
|
9
|
-
}
|
|
10
|
-
interface ClientContext {
|
|
11
|
-
client: ClientContextClient;
|
|
12
|
-
Custom?: any;
|
|
13
|
-
env: ClientContextEnv;
|
|
14
|
-
}
|
|
15
|
-
interface ClientContextClient {
|
|
16
|
-
installationId: string;
|
|
17
|
-
appTitle: string;
|
|
18
|
-
appVersionName: string;
|
|
19
|
-
appVersionCode: string;
|
|
20
|
-
appPackageName: string;
|
|
21
|
-
}
|
|
22
|
-
interface ClientContextEnv {
|
|
23
|
-
platformVersion: string;
|
|
24
|
-
platform: string;
|
|
25
|
-
make: string;
|
|
26
|
-
model: string;
|
|
27
|
-
locale: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* {@link Handler} context parameter.
|
|
31
|
-
* See {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html AWS documentation}.
|
|
32
|
-
*/
|
|
33
|
-
interface LambdaContext {
|
|
34
|
-
callbackWaitsForEmptyEventLoop: boolean;
|
|
35
|
-
functionName: string;
|
|
36
|
-
functionVersion: string;
|
|
37
|
-
invokedFunctionArn: string;
|
|
38
|
-
memoryLimitInMB: string;
|
|
39
|
-
awsRequestId: string;
|
|
40
|
-
logGroupName: string;
|
|
41
|
-
logStreamName: string;
|
|
42
|
-
identity?: CognitoIdentity | undefined;
|
|
43
|
-
clientContext?: ClientContext | undefined;
|
|
44
|
-
getRemainingTimeInMillis(): number;
|
|
45
|
-
}
|
|
46
|
-
type Callback<TResult = any> = (error?: Error | string | null, result?: TResult) => void;
|
|
47
|
-
type Handler<TEvent = any, TResult = any> = (event: TEvent, context: LambdaContext, callback: Callback<TResult>) => void | Promise<TResult>;
|
|
48
|
-
interface ClientCert {
|
|
49
|
-
clientCertPem: string;
|
|
50
|
-
subjectDN: string;
|
|
51
|
-
issuerDN: string;
|
|
52
|
-
serialNumber: string;
|
|
53
|
-
validity: {
|
|
54
|
-
notBefore: string;
|
|
55
|
-
notAfter: string;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
interface Identity {
|
|
59
|
-
accessKey?: string;
|
|
60
|
-
accountId?: string;
|
|
61
|
-
caller?: string;
|
|
62
|
-
cognitoAuthenticationProvider?: string;
|
|
63
|
-
cognitoAuthenticationType?: string;
|
|
64
|
-
cognitoIdentityId?: string;
|
|
65
|
-
cognitoIdentityPoolId?: string;
|
|
66
|
-
principalOrgId?: string;
|
|
67
|
-
sourceIp: string;
|
|
68
|
-
user?: string;
|
|
69
|
-
userAgent: string;
|
|
70
|
-
userArn?: string;
|
|
71
|
-
clientCert?: ClientCert;
|
|
72
|
-
}
|
|
73
|
-
interface ApiGatewayRequestContext {
|
|
74
|
-
accountId: string;
|
|
75
|
-
apiId: string;
|
|
76
|
-
authorizer: {
|
|
77
|
-
claims?: unknown;
|
|
78
|
-
scopes?: unknown;
|
|
79
|
-
};
|
|
80
|
-
domainName: string;
|
|
81
|
-
domainPrefix: string;
|
|
82
|
-
extendedRequestId: string;
|
|
83
|
-
httpMethod: string;
|
|
84
|
-
identity: Identity;
|
|
85
|
-
path: string;
|
|
86
|
-
protocol: string;
|
|
87
|
-
requestId: string;
|
|
88
|
-
requestTime: string;
|
|
89
|
-
requestTimeEpoch: number;
|
|
90
|
-
resourceId?: string;
|
|
91
|
-
resourcePath: string;
|
|
92
|
-
stage: string;
|
|
93
|
-
}
|
|
94
|
-
interface Authorizer {
|
|
95
|
-
iam?: {
|
|
96
|
-
accessKey: string;
|
|
97
|
-
accountId: string;
|
|
98
|
-
callerId: string;
|
|
99
|
-
cognitoIdentity: null;
|
|
100
|
-
principalOrgId: null;
|
|
101
|
-
userArn: string;
|
|
102
|
-
userId: string;
|
|
103
|
-
};
|
|
104
|
-
jwt?: {
|
|
105
|
-
claims: Record<string, string | number | boolean | string[]>;
|
|
106
|
-
scopes: string[] | null;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* The `context` object returned by a Lambda (REQUEST) authorizer.
|
|
110
|
-
* It is `null` when the authorizer returns no context.
|
|
111
|
-
*/
|
|
112
|
-
lambda?: Record<string, unknown> | null;
|
|
113
|
-
}
|
|
114
|
-
interface ApiGatewayRequestContextV2 {
|
|
115
|
-
accountId: string;
|
|
116
|
-
apiId: string;
|
|
117
|
-
authentication: null;
|
|
118
|
-
authorizer: Authorizer;
|
|
119
|
-
domainName: string;
|
|
120
|
-
domainPrefix: string;
|
|
121
|
-
http: {
|
|
122
|
-
method: string;
|
|
123
|
-
path: string;
|
|
124
|
-
protocol: string;
|
|
125
|
-
sourceIp: string;
|
|
126
|
-
userAgent: string;
|
|
127
|
-
};
|
|
128
|
-
requestId: string;
|
|
129
|
-
routeKey: string;
|
|
130
|
-
stage: string;
|
|
131
|
-
time: string;
|
|
132
|
-
timeEpoch: number;
|
|
133
|
-
}
|
|
134
|
-
interface ALBRequestContext {
|
|
135
|
-
elb: {
|
|
136
|
-
targetGroupArn: string;
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
interface LatticeRequestContextV2 {
|
|
140
|
-
serviceNetworkArn: string;
|
|
141
|
-
serviceArn: string;
|
|
142
|
-
targetGroupArn: string;
|
|
143
|
-
region: string;
|
|
144
|
-
timeEpoch: string;
|
|
145
|
-
identity: {
|
|
146
|
-
sourceVpcArn?: string;
|
|
147
|
-
type?: string;
|
|
148
|
-
principal?: string;
|
|
149
|
-
principalOrgID?: string;
|
|
150
|
-
sessionName?: string;
|
|
151
|
-
x509IssuerOu?: string;
|
|
152
|
-
x509SanDns?: string;
|
|
153
|
-
x509SanNameCn?: string;
|
|
154
|
-
x509SanUri?: string;
|
|
155
|
-
x509SubjectCn?: string;
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
//#endregion
|
|
159
|
-
//#region ../../plugins/acryl-router/src/core/adapter/aws-lambda/handler.d.ts
|
|
160
|
-
type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2 | ALBProxyEvent | LatticeProxyEventV2;
|
|
161
|
-
interface LatticeProxyEventV2 {
|
|
162
|
-
version: string;
|
|
163
|
-
path: string;
|
|
164
|
-
method: string;
|
|
165
|
-
headers: Record<string, string[] | undefined>;
|
|
166
|
-
queryStringParameters: Record<string, string[] | undefined>;
|
|
167
|
-
body: string | null;
|
|
168
|
-
isBase64Encoded: boolean;
|
|
169
|
-
requestContext: LatticeRequestContextV2;
|
|
170
|
-
}
|
|
171
|
-
interface APIGatewayProxyEventV2 {
|
|
172
|
-
version: string;
|
|
173
|
-
routeKey: string;
|
|
174
|
-
headers: Record<string, string | undefined>;
|
|
175
|
-
multiValueHeaders?: undefined;
|
|
176
|
-
cookies?: string[];
|
|
177
|
-
rawPath: string;
|
|
178
|
-
rawQueryString: string;
|
|
179
|
-
body: string | null;
|
|
180
|
-
isBase64Encoded: boolean;
|
|
181
|
-
requestContext: ApiGatewayRequestContextV2;
|
|
182
|
-
queryStringParameters?: {
|
|
183
|
-
[name: string]: string | undefined;
|
|
184
|
-
};
|
|
185
|
-
pathParameters?: {
|
|
186
|
-
[name: string]: string | undefined;
|
|
187
|
-
};
|
|
188
|
-
stageVariables?: {
|
|
189
|
-
[name: string]: string | undefined;
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
interface APIGatewayProxyEvent {
|
|
193
|
-
version: string;
|
|
194
|
-
httpMethod: string;
|
|
195
|
-
headers: Record<string, string | undefined>;
|
|
196
|
-
multiValueHeaders?: {
|
|
197
|
-
[headerKey: string]: string[];
|
|
198
|
-
};
|
|
199
|
-
path: string;
|
|
200
|
-
body: string | null;
|
|
201
|
-
isBase64Encoded: boolean;
|
|
202
|
-
queryStringParameters?: Record<string, string | undefined>;
|
|
203
|
-
requestContext: ApiGatewayRequestContext;
|
|
204
|
-
resource: string;
|
|
205
|
-
multiValueQueryStringParameters?: {
|
|
206
|
-
[parameterKey: string]: string[];
|
|
207
|
-
};
|
|
208
|
-
pathParameters?: Record<string, string>;
|
|
209
|
-
stageVariables?: Record<string, string>;
|
|
210
|
-
}
|
|
211
|
-
interface ALBProxyEvent {
|
|
212
|
-
httpMethod: string;
|
|
213
|
-
headers?: Record<string, string | undefined>;
|
|
214
|
-
multiValueHeaders?: Record<string, string[] | undefined>;
|
|
215
|
-
path: string;
|
|
216
|
-
body: string | null;
|
|
217
|
-
isBase64Encoded: boolean;
|
|
218
|
-
queryStringParameters?: Record<string, string | undefined>;
|
|
219
|
-
multiValueQueryStringParameters?: {
|
|
220
|
-
[parameterKey: string]: string[];
|
|
221
|
-
};
|
|
222
|
-
requestContext: ALBRequestContext;
|
|
223
|
-
}
|
|
224
|
-
type WithHeaders = {
|
|
225
|
-
headers: Record<string, string | string[]>;
|
|
226
|
-
multiValueHeaders?: undefined;
|
|
227
|
-
};
|
|
228
|
-
type WithMultiValueHeaders = {
|
|
229
|
-
headers?: undefined;
|
|
230
|
-
multiValueHeaders: Record<string, string[]>;
|
|
231
|
-
};
|
|
232
|
-
type APIGatewayProxyResult = {
|
|
233
|
-
statusCode: number;
|
|
234
|
-
statusDescription?: string;
|
|
235
|
-
body: string;
|
|
236
|
-
cookies?: string[];
|
|
237
|
-
isBase64Encoded: boolean;
|
|
238
|
-
} & (WithHeaders | WithMultiValueHeaders);
|
|
239
|
-
declare const streamHandle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Acryl<E, S, BasePath>) => Handler;
|
|
240
|
-
type HandleOptions = {
|
|
241
|
-
isContentTypeBinary: ((contentType: string) => boolean) | undefined;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Converts a Acryl application to an AWS Lambda handler.
|
|
245
|
-
*
|
|
246
|
-
* Accepts events from API Gateway (v1 and v2), Application Load Balancer (ALB),
|
|
247
|
-
* and Lambda Function URLs.
|
|
248
|
-
*
|
|
249
|
-
* @param app - The Acryl application instance
|
|
250
|
-
* @param options - Optional configuration
|
|
251
|
-
* @param options.isContentTypeBinary - A function to determine if the content type is binary.
|
|
252
|
-
* If not provided, the default function will be used.
|
|
253
|
-
* @returns Lambda handler function
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```js
|
|
257
|
-
* import { Acryl } from 'acrylblends'
|
|
258
|
-
* import { handle } from 'acrylblends/aws-lambda'
|
|
259
|
-
*
|
|
260
|
-
* const app = new Acryl()
|
|
261
|
-
*
|
|
262
|
-
* app.get('/', (c) => c.text('Hello from Lambda'))
|
|
263
|
-
* app.get('/json', (c) => c.json({ message: 'Hello JSON' }))
|
|
264
|
-
*
|
|
265
|
-
* export const handler = handle(app)
|
|
266
|
-
* ```
|
|
267
|
-
*
|
|
268
|
-
* @example
|
|
269
|
-
* ```js
|
|
270
|
-
* // With custom binary content type detection
|
|
271
|
-
* import { handle, defaultIsContentTypeBinary } from 'acrylblends/aws-lambda'
|
|
272
|
-
* export const handler = handle(app, {
|
|
273
|
-
* isContentTypeBinary: (contentType) => {
|
|
274
|
-
* if (defaultIsContentTypeBinary(contentType)) {
|
|
275
|
-
* // default logic same as prior to v4.8.4
|
|
276
|
-
* return true
|
|
277
|
-
* }
|
|
278
|
-
* return contentType.startsWith('image/') || contentType === 'application/pdf'
|
|
279
|
-
* }
|
|
280
|
-
* })
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
declare const handle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Acryl<E, S, BasePath>, {
|
|
284
|
-
isContentTypeBinary
|
|
285
|
-
}?: HandleOptions) => (<L extends LambdaEvent>(event: L, lambdaContext?: LambdaContext) => Promise<APIGatewayProxyResult & (L extends {
|
|
286
|
-
multiValueHeaders: Record<string, string[]>;
|
|
287
|
-
} ? WithMultiValueHeaders : WithHeaders)>);
|
|
288
|
-
/**
|
|
289
|
-
* Check if the given content type is binary.
|
|
290
|
-
* This is a default function and may be overwritten by the user via `isContentTypeBinary` option in handler().
|
|
291
|
-
* @param contentType The content type to check.
|
|
292
|
-
* @returns True if the content type is binary, false otherwise.
|
|
293
|
-
*/
|
|
294
|
-
declare const defaultIsContentTypeBinary: (contentType: string) => boolean;
|
|
295
|
-
//#endregion
|
|
296
|
-
//#region ../../plugins/acryl-router/src/core/adapter/aws-lambda/conninfo.d.ts
|
|
297
|
-
/**
|
|
298
|
-
* Get connection information from AWS Lambda
|
|
299
|
-
*
|
|
300
|
-
* Extracts client IP from various Lambda event sources:
|
|
301
|
-
* - API Gateway v1 (REST API): requestContext.identity.sourceIp
|
|
302
|
-
* - API Gateway v2 (HTTP API/Function URLs): requestContext.http.sourceIp
|
|
303
|
-
* - ALB: Falls back to x-forwarded-for header
|
|
304
|
-
*
|
|
305
|
-
* @param c - Context
|
|
306
|
-
* @returns Connection information including remote address
|
|
307
|
-
* @example
|
|
308
|
-
* ```ts
|
|
309
|
-
* import { Acryl } from 'acrylblends'
|
|
310
|
-
* import { handle, getConnInfo } from 'acrylblends/aws-lambda'
|
|
311
|
-
*
|
|
312
|
-
* const app = new Acryl()
|
|
313
|
-
*
|
|
314
|
-
* app.get('/', (c) => {
|
|
315
|
-
* const info = getConnInfo(c)
|
|
316
|
-
* return c.text(`Your IP: ${info.remote.address}`)
|
|
317
|
-
* })
|
|
318
|
-
*
|
|
319
|
-
* export const handler = handle(app)
|
|
320
|
-
* ```
|
|
321
|
-
*/
|
|
322
|
-
declare const getConnInfo: GetConnInfo;
|
|
323
|
-
//#endregion
|
|
324
|
-
export { type ALBRequestContext, type APIGatewayProxyResult, type ApiGatewayRequestContext, type ApiGatewayRequestContextV2, type LambdaContext, type LambdaEvent, defaultIsContentTypeBinary, getConnInfo, handle, streamHandle };
|