@every-app/sdk 0.3.0-rc.9 → 0.3.1
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 +79 -74
- package/dist/cloudflare/catalogSettings.generated.d.ts +19 -6
- package/dist/cloudflare/catalogSettings.generated.d.ts.map +1 -1
- package/dist/cloudflare/catalogSettings.generated.js +43 -14
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.d.ts.map +1 -1
- package/dist/cloudflare/worker.d.ts +63 -9
- package/dist/cloudflare/worker.d.ts.map +1 -1
- package/dist/cloudflare/worker.js +45 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/internal/aiDefault.d.ts +36 -79
- package/dist/internal/aiDefault.d.ts.map +1 -1
- package/dist/internal/aiDefault.js +47 -149
- package/dist/internal/aiProviders.d.ts +1 -1
- package/dist/internal/aiProviders.d.ts.map +1 -1
- package/dist/internal/aiProviders.js +2 -2
- package/dist/internal/appSettings.d.ts +140 -89
- package/dist/internal/appSettings.d.ts.map +1 -1
- package/dist/internal/appSettings.js +264 -156
- package/dist/internal/capabilities.d.ts +109 -503
- package/dist/internal/capabilities.d.ts.map +1 -1
- package/dist/internal/capabilities.js +30 -550
- package/dist/internal/catalog/commerce.js +1 -1
- package/dist/internal/catalog/index.d.ts +35 -0
- package/dist/internal/catalog/index.d.ts.map +1 -1
- package/dist/internal/catalog/infra.d.ts +35 -0
- package/dist/internal/catalog/infra.d.ts.map +1 -1
- package/dist/internal/catalog/infra.js +65 -0
- package/dist/internal/devProviders.d.ts +1 -19
- package/dist/internal/devProviders.d.ts.map +1 -1
- package/dist/internal/devProviders.js +7 -1
- package/dist/internal/events.d.ts +52 -1
- package/dist/internal/events.d.ts.map +1 -1
- package/dist/internal/events.js +66 -4
- package/dist/internal/gatewaySettings.d.ts +6 -16
- package/dist/internal/gatewaySettings.d.ts.map +1 -1
- package/dist/internal/gatewaySettings.js +5 -23
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +1 -0
- package/dist/internal/mcpOAuth.d.ts +210 -0
- package/dist/internal/mcpOAuth.d.ts.map +1 -0
- package/dist/internal/mcpOAuth.js +735 -0
- package/dist/internal/oauthClient.d.ts +36 -44
- package/dist/internal/oauthClient.d.ts.map +1 -1
- package/dist/internal/oauthClient.js +30 -113
- package/dist/internal/oauthPresets.d.ts +356 -20
- package/dist/internal/oauthPresets.d.ts.map +1 -1
- package/dist/internal/oauthPresets.js +183 -861
- package/dist/internal/oauthScopes.d.ts +43 -155
- package/dist/internal/oauthScopes.d.ts.map +1 -1
- package/dist/internal/oauthScopes.js +82 -475
- package/dist/internal/oauthSpec.d.ts +28 -71
- package/dist/internal/oauthSpec.d.ts.map +1 -1
- package/dist/internal/oauthSpec.js +172 -448
- package/dist/internal/protocol.d.ts +24 -14
- package/dist/internal/protocol.d.ts.map +1 -1
- package/dist/internal/protocol.js +26 -7
- package/dist/internal/providerApps.d.ts +2 -2
- package/dist/internal/providerApps.js +2 -2
- package/dist/internal/providerRegistry.d.ts +5 -64
- package/dist/internal/providerRegistry.d.ts.map +1 -1
- package/dist/internal/providerRegistry.js +19 -118
- package/dist/internal/providerSpec.d.ts.map +1 -1
- package/dist/internal/providerSpec.js +14 -36
- package/dist/internal/remoteMcp.d.ts +191 -47
- package/dist/internal/remoteMcp.d.ts.map +1 -1
- package/dist/internal/remoteMcp.js +338 -133
- package/dist/internal/signInProviders.d.ts +1 -1
- package/dist/internal/signInProviders.d.ts.map +1 -1
- package/dist/internal/tools.d.ts +15 -8
- package/dist/internal/tools.d.ts.map +1 -1
- package/dist/internal/tools.js +9 -8
- package/dist/manifest.d.ts +96 -40
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +1 -1
- package/dist/server/ai.d.ts +1 -93
- package/dist/server/ai.d.ts.map +1 -1
- package/dist/server/ai.js +17 -111
- package/dist/server/attribution.d.ts +11 -1
- package/dist/server/attribution.d.ts.map +1 -1
- package/dist/server/attribution.js +7 -1
- package/dist/server/connectUrl.d.ts +5 -10
- package/dist/server/connectUrl.d.ts.map +1 -1
- package/dist/server/connectUrl.js +22 -14
- package/dist/server/context.d.ts +12 -14
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/context.js +23 -25
- package/dist/server/eventsEndpoint.d.ts +48 -0
- package/dist/server/eventsEndpoint.d.ts.map +1 -0
- package/dist/server/eventsEndpoint.js +145 -0
- package/dist/server/everyApp.d.ts +16 -26
- package/dist/server/everyApp.d.ts.map +1 -1
- package/dist/server/everyApp.js +22 -46
- package/dist/server/gatewayFetch.d.ts +1 -1
- package/dist/server/gatewayFetch.js +1 -1
- package/dist/server/index.d.ts +6 -9
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -8
- package/dist/server/integrationFetch.d.ts +66 -72
- package/dist/server/integrationFetch.d.ts.map +1 -1
- package/dist/server/integrationFetch.js +120 -392
- package/dist/server/refusal.d.ts +0 -9
- package/dist/server/refusal.d.ts.map +1 -1
- package/dist/server/refusal.js +0 -22
- package/dist/server/tools.d.ts +18 -7
- package/dist/server/tools.d.ts.map +1 -1
- package/dist/server/tools.js +15 -5
- package/dist/server/toolsEndpoint.d.ts +2 -1
- package/dist/server/toolsEndpoint.d.ts.map +1 -1
- package/dist/server/toolsEndpoint.js +4 -3
- package/dist/server/webhooks.d.ts +56 -0
- package/dist/server/webhooks.d.ts.map +1 -0
- package/dist/server/webhooks.js +205 -0
- package/dist/testing/index.d.ts +2 -3
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +2 -6
- package/package.json +6 -1
- package/dist/server/aiBinding.d.ts +0 -68
- package/dist/server/aiBinding.d.ts.map +0 -1
- package/dist/server/aiBinding.js +0 -294
- package/dist/server/authorizeUrl.d.ts +0 -43
- package/dist/server/authorizeUrl.d.ts.map +0 -1
- package/dist/server/authorizeUrl.js +0 -106
- package/dist/server/emailBinding.d.ts +0 -72
- package/dist/server/emailBinding.d.ts.map +0 -1
- package/dist/server/emailBinding.js +0 -124
- package/dist/server/fromMcpTools.d.ts +0 -89
- package/dist/server/fromMcpTools.d.ts.map +0 -1
- package/dist/server/fromMcpTools.js +0 -192
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app side of the `app` event sink (docs/design/2026-11-birds-decisions/app-event-sink.md).
|
|
3
|
+
*
|
|
4
|
+
* `everyApp()` answers the reserved `POST /__everyapp/events` here, before
|
|
5
|
+
* any app code runs and whether or not the app passed `events`:
|
|
6
|
+
*
|
|
7
|
+
* - the request needs the Gateway's system token for this app (purpose
|
|
8
|
+
* `events.deliver`), whose `bh` claim is the SHA-256 of this exact body,
|
|
9
|
+
* so a token opens one delivery and nothing else;
|
|
10
|
+
* - the envelope must name the organization this Worker serves
|
|
11
|
+
* (`EVERY_APP_ORG_ID`), when it is pinned;
|
|
12
|
+
* - only then is `events.on` called, under `withOrganization()`, so every
|
|
13
|
+
* Gateway call it makes is that organization's background work.
|
|
14
|
+
*
|
|
15
|
+
* The perimeter refuses the path from outside and strips inbound
|
|
16
|
+
* `x-everyapp-*` headers, so only the Gateway's event bus reaches it, over
|
|
17
|
+
* the service binding.
|
|
18
|
+
*/
|
|
19
|
+
import { APP_EVENTS_PATH, ConfigurationError, EVENT_HEADERS, IdentityError, SYSTEM_HEADER, bodyHash, resolveVerifyOptions, verifySystemJwt, } from "../internal/index.js";
|
|
20
|
+
import { withOrganization } from "./context.js";
|
|
21
|
+
/** The most body the endpoint reads: an envelope's data is at most 16 KiB. */
|
|
22
|
+
const MAX_BODY_BYTES = 64 * 1024;
|
|
23
|
+
function answer(status, body) {
|
|
24
|
+
return Response.json(body, {
|
|
25
|
+
status,
|
|
26
|
+
headers: { "cache-control": "no-store" },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function isEnvelope(value) {
|
|
30
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const v = value;
|
|
34
|
+
const org = v.organization;
|
|
35
|
+
return (typeof v.id === "string" &&
|
|
36
|
+
typeof v.type === "string" &&
|
|
37
|
+
typeof v.version === "number" &&
|
|
38
|
+
typeof v.time === "string" &&
|
|
39
|
+
!!org &&
|
|
40
|
+
typeof org === "object" &&
|
|
41
|
+
typeof org.id === "string" &&
|
|
42
|
+
!!v.data &&
|
|
43
|
+
typeof v.data === "object" &&
|
|
44
|
+
!Array.isArray(v.data));
|
|
45
|
+
}
|
|
46
|
+
function handlerFor(on, type) {
|
|
47
|
+
if (typeof on === "function")
|
|
48
|
+
return on;
|
|
49
|
+
return Object.prototype.hasOwnProperty.call(on, type) ? on[type] : undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Answer a request to the reserved events path, or return null for any
|
|
53
|
+
* other path so the app's own handler runs.
|
|
54
|
+
*/
|
|
55
|
+
export async function handleEventsRequest(request, env, ctx, options) {
|
|
56
|
+
const { pathname } = new URL(request.url);
|
|
57
|
+
if (pathname !== APP_EVENTS_PATH)
|
|
58
|
+
return null;
|
|
59
|
+
if (request.method !== "POST") {
|
|
60
|
+
return answer(405, { error: "method_not_allowed" });
|
|
61
|
+
}
|
|
62
|
+
let verify;
|
|
63
|
+
try {
|
|
64
|
+
verify = resolveVerifyOptions(options.identity);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (error instanceof ConfigurationError) {
|
|
68
|
+
console.error(error);
|
|
69
|
+
return answer(500, { error: "misconfigured", message: error.message });
|
|
70
|
+
}
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
let claims;
|
|
74
|
+
try {
|
|
75
|
+
claims = await verifySystemJwt(request.headers.get(SYSTEM_HEADER) ?? "", {
|
|
76
|
+
...verify,
|
|
77
|
+
purpose: "events.deliver",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error instanceof IdentityError) {
|
|
82
|
+
return answer(401, { error: "unauthenticated", message: error.message });
|
|
83
|
+
}
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
const declared = Number(request.headers.get("content-length") ?? "0");
|
|
87
|
+
if (declared > MAX_BODY_BYTES) {
|
|
88
|
+
return answer(413, { error: "too_large" });
|
|
89
|
+
}
|
|
90
|
+
const body = await request.text();
|
|
91
|
+
if (body.length > MAX_BODY_BYTES) {
|
|
92
|
+
return answer(413, { error: "too_large" });
|
|
93
|
+
}
|
|
94
|
+
// The token was minted for this exact body: another body, even one the
|
|
95
|
+
// Gateway sent, is refused.
|
|
96
|
+
if (claims.bh !== (await bodyHash(body))) {
|
|
97
|
+
return answer(401, {
|
|
98
|
+
error: "unauthenticated",
|
|
99
|
+
message: "the token was minted for another delivery",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
let parsed;
|
|
103
|
+
try {
|
|
104
|
+
parsed = JSON.parse(body);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
parsed = undefined;
|
|
108
|
+
}
|
|
109
|
+
if (!isEnvelope(parsed)) {
|
|
110
|
+
return answer(400, { error: "invalid_request" });
|
|
111
|
+
}
|
|
112
|
+
const pinned = options.identity.organizationId;
|
|
113
|
+
if (pinned && parsed.organization.id !== pinned) {
|
|
114
|
+
return answer(403, {
|
|
115
|
+
error: "forbidden",
|
|
116
|
+
message: `the event is for organization "${parsed.organization.id}", and this Worker serves "${pinned}"`,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (!options.events) {
|
|
120
|
+
// The manifest subscribes, but the Worker passes no `events` to
|
|
121
|
+
// everyApp(): say so, and let the Gateway retry once it does.
|
|
122
|
+
return answer(404, {
|
|
123
|
+
error: "no_handler",
|
|
124
|
+
message: "everyApp() was given no events: { on }",
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const handler = handlerFor(options.events.on, parsed.type);
|
|
128
|
+
if (!handler)
|
|
129
|
+
return answer(200, { ok: true, handled: false });
|
|
130
|
+
const event = {
|
|
131
|
+
...parsed,
|
|
132
|
+
delivery: {
|
|
133
|
+
id: request.headers.get(EVENT_HEADERS.delivery) ?? "",
|
|
134
|
+
attempt: Number(request.headers.get(EVENT_HEADERS.attempt) ?? "0") || 0,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
try {
|
|
138
|
+
await withOrganization(parsed.organization.id, () => handler(event, env, ctx));
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error(error);
|
|
142
|
+
return answer(500, { error: "handler_failed" });
|
|
143
|
+
}
|
|
144
|
+
return answer(200, { ok: true, handled: true });
|
|
145
|
+
}
|
|
@@ -13,21 +13,22 @@
|
|
|
13
13
|
* `everyapp.config.ts` (the Cloudflare Vite plugin hides every file
|
|
14
14
|
* `cloudflare.config.ts` imports from the Worker in dev).
|
|
15
15
|
* It also answers the gateway's internal tools contract
|
|
16
|
-
* (`/__everyapp/tools/*`) for the app's `defineTools()` catalog
|
|
16
|
+
* (`/__everyapp/tools/*`) for the app's `defineTools()` catalog, and the
|
|
17
|
+
* event sink's deliveries (`/__everyapp/events`) for `events: { on }`.
|
|
17
18
|
*
|
|
18
19
|
* Around the handler and around each tool call it opens the request
|
|
19
|
-
* context (context.ts):
|
|
20
|
-
*
|
|
21
|
-
* `for`. A deployed Worker is pinned to its organization
|
|
20
|
+
* context (context.ts): every call back to the Gateway is attributed to
|
|
21
|
+
* the request without a `for`. A deployed Worker is pinned to its organization
|
|
22
22
|
* (`EVERY_APP_ORG_ID`), and an identity for any other is refused on both
|
|
23
23
|
* paths. The response leaves without `Set-Cookie`: the perimeter strips
|
|
24
24
|
* every `Cookie` before a request reaches the app, so a cookie the app's
|
|
25
25
|
* framework sets could never come back, and one named like the Gateway's
|
|
26
26
|
* session cookie would lock the person out of the app host.
|
|
27
27
|
*/
|
|
28
|
-
import { ConfigurationError,
|
|
28
|
+
import { ConfigurationError, isAdmin, type EveryAppUser, type IdentityResult, type OrgRole } from "../internal/index.js";
|
|
29
29
|
import type { ToolSet } from "./tools.js";
|
|
30
|
-
|
|
30
|
+
import { type AppEventsOptions } from "./eventsEndpoint.js";
|
|
31
|
+
export { ConfigurationError, isAdmin };
|
|
31
32
|
export type { EveryAppUser, IdentityResult, OrgRole };
|
|
32
33
|
/**
|
|
33
34
|
* The runtime's `ExecutionContext`, which `everyApp()` passes to the handler
|
|
@@ -36,11 +37,7 @@ export type { EveryAppUser, IdentityResult, OrgRole };
|
|
|
36
37
|
* `fetch` themselves pass a stub cast to it.
|
|
37
38
|
*/
|
|
38
39
|
export type ExecutionContextLike = ExecutionContext;
|
|
39
|
-
export interface
|
|
40
|
-
id: string;
|
|
41
|
-
[key: string]: unknown;
|
|
42
|
-
}
|
|
43
|
-
export interface EveryAppOptions {
|
|
40
|
+
export interface EveryAppOptions<TEnv = Record<string, unknown>> {
|
|
44
41
|
/** Optional expected issuer (gateway URL). Defaults to env.EVERYAPP_IDENTITY_ISSUER when set. */
|
|
45
42
|
issuer?: string;
|
|
46
43
|
/** Env var holding the public key set. Defaults to EVERYAPP_IDENTITY_PUBLIC_KEYS. */
|
|
@@ -57,6 +54,13 @@ export interface EveryAppOptions {
|
|
|
57
54
|
* and serves them to MCP clients; see `defineTools`.
|
|
58
55
|
*/
|
|
59
56
|
tools?: ToolSet;
|
|
57
|
+
/**
|
|
58
|
+
* The Gateway's events this app subscribes to (`events.subscribe` in its
|
|
59
|
+
* manifest), delivered to `on` over the service binding: one function, or
|
|
60
|
+
* one per type. The SDK verifies the Gateway's `events.deliver` token
|
|
61
|
+
* before `on` runs.
|
|
62
|
+
*/
|
|
63
|
+
events?: AppEventsOptions<TEnv>;
|
|
60
64
|
/** Override for tests. */
|
|
61
65
|
now?: number;
|
|
62
66
|
}
|
|
@@ -74,7 +78,6 @@ interface EveryAppExport<TEnv, TCtx extends ExecutionContextLike> {
|
|
|
74
78
|
* (a framework that hands out headers alone needs no made-up Request).
|
|
75
79
|
* Answers from the request context or the per-request cache first, then
|
|
76
80
|
* verifies the identity headers from the audience and public keys in env.
|
|
77
|
-
* Inside a handler `everyApp()` serves, `currentUser()` is the shorter way.
|
|
78
81
|
*/
|
|
79
82
|
export declare function getEveryAppUser(request: Request | Headers, env: object): Promise<EveryAppUser | null>;
|
|
80
83
|
/**
|
|
@@ -82,20 +85,7 @@ export declare function getEveryAppUser(request: Request | Headers, env: object)
|
|
|
82
85
|
* everyApp() when the request is public or unauthenticated.
|
|
83
86
|
*/
|
|
84
87
|
export declare function requireEveryAppUser(request: Request | Headers, env: object): Promise<EveryAppUser>;
|
|
85
|
-
/**
|
|
86
|
-
* The user of the request being served (`currentUser()`), or throw the
|
|
87
|
-
* same 401 JSON Response as `requireEveryAppUser()` on a public route.
|
|
88
|
-
* Outside a request (`withOrganization()` work, a handler not under
|
|
89
|
-
* `everyApp()`) it throws `RequestContextError`, as `currentUser()` does.
|
|
90
|
-
*/
|
|
91
|
-
export declare function requireCurrentUser(): EveryAppUser;
|
|
92
88
|
export declare function hasScope(user: EveryAppUser, scope: string): boolean;
|
|
93
89
|
/** Wrap a Worker fetch handler with Every App identity verification. */
|
|
94
|
-
export declare function everyApp<TEnv = Record<string, unknown>, TCtx extends ExecutionContextLike = ExecutionContext>(handler: EveryAppHandler<TEnv, TCtx>, options?: EveryAppOptions): EveryAppExport<TEnv, TCtx>;
|
|
95
|
-
/**
|
|
96
|
-
* @deprecated Drop the manifest: the app id now comes from
|
|
97
|
-
* `env.EVERYAPP_APP_ID` and the audience from `env.EVERYAPP_AUDIENCE`.
|
|
98
|
-
* When passed, it must match the app id.
|
|
99
|
-
*/
|
|
100
|
-
export declare function everyApp<TEnv = Record<string, unknown>, TCtx extends ExecutionContextLike = ExecutionContext>(handler: EveryAppHandler<TEnv, TCtx>, manifest: EveryAppManifestLike | undefined, options?: EveryAppOptions): EveryAppExport<TEnv, TCtx>;
|
|
90
|
+
export declare function everyApp<TEnv = Record<string, unknown>, TCtx extends ExecutionContextLike = ExecutionContext>(handler: EveryAppHandler<TEnv, TCtx>, options?: EveryAppOptions<TEnv>): EveryAppExport<TEnv, TCtx>;
|
|
101
91
|
//# sourceMappingURL=everyApp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"everyApp.d.ts","sourceRoot":"","sources":["../../src/server/everyApp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAGL,kBAAkB,
|
|
1
|
+
{"version":3,"file":"everyApp.d.ts","sourceRoot":"","sources":["../../src/server/everyApp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAGL,kBAAkB,EAQlB,OAAO,EACP,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,OAAO,EAEb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC;AACvC,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAEpD,MAAM,WAAW,eAAe,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7D,iGAAiG;IACjG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACh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
|
|
13
13
|
* `everyapp.config.ts` (the Cloudflare Vite plugin hides every file
|
|
14
14
|
* `cloudflare.config.ts` imports from the Worker in dev).
|
|
15
15
|
* It also answers the gateway's internal tools contract
|
|
16
|
-
* (`/__everyapp/tools/*`) for the app's `defineTools()` catalog
|
|
16
|
+
* (`/__everyapp/tools/*`) for the app's `defineTools()` catalog, and the
|
|
17
|
+
* event sink's deliveries (`/__everyapp/events`) for `events: { on }`.
|
|
17
18
|
*
|
|
18
19
|
* Around the handler and around each tool call it opens the request
|
|
19
|
-
* context (context.ts):
|
|
20
|
-
*
|
|
21
|
-
* `for`. A deployed Worker is pinned to its organization
|
|
20
|
+
* context (context.ts): every call back to the Gateway is attributed to
|
|
21
|
+
* the request without a `for`. A deployed Worker is pinned to its organization
|
|
22
22
|
* (`EVERY_APP_ORG_ID`), and an identity for any other is refused on both
|
|
23
23
|
* paths. The response leaves without `Set-Cookie`: the perimeter strips
|
|
24
24
|
* every `Cookie` before a request reaches the app, so a cookie the app's
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
import { APP_ID_ENV, AUDIENCE_ENV, ConfigurationError, DEV_ENV, IdentityError, IDENTITY_HEADER, ISSUER_ENV, ORG_ID_ENV, PUBLIC_KEYS_ENV, getIdentityFromRequest, isAdmin, } from "../internal/index.js";
|
|
29
29
|
import { currentUser, serveRequest } from "./context.js";
|
|
30
30
|
import { handleToolsRequest } from "./toolsEndpoint.js";
|
|
31
|
-
|
|
31
|
+
import { handleEventsRequest, } from "./eventsEndpoint.js";
|
|
32
|
+
export { ConfigurationError, isAdmin };
|
|
32
33
|
const requestIdentities = new WeakMap();
|
|
33
34
|
function envValue(env, key) {
|
|
34
35
|
if (!env || typeof env !== "object")
|
|
@@ -36,9 +37,8 @@ function envValue(env, key) {
|
|
|
36
37
|
const value = env[key];
|
|
37
38
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
38
39
|
}
|
|
39
|
-
function configFrom(
|
|
40
|
+
function configFrom(options) {
|
|
40
41
|
return {
|
|
41
|
-
manifestAppId: manifest?.id,
|
|
42
42
|
issuer: options.issuer,
|
|
43
43
|
keysEnvVar: options.keysEnvVar ?? PUBLIC_KEYS_ENV,
|
|
44
44
|
publicKeys: options.publicKeys,
|
|
@@ -46,16 +46,9 @@ function configFrom(manifest, options = {}) {
|
|
|
46
46
|
now: options.now,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*/
|
|
53
|
-
function appIdFor(env, config) {
|
|
54
|
-
const fromEnv = envValue(env, APP_ID_ENV);
|
|
55
|
-
if (fromEnv && config.manifestAppId && fromEnv !== config.manifestAppId) {
|
|
56
|
-
throw new ConfigurationError(`${APP_ID_ENV} ("${fromEnv}") does not match the manifest id ("${config.manifestAppId}").`);
|
|
57
|
-
}
|
|
58
|
-
return fromEnv ?? config.manifestAppId;
|
|
49
|
+
/** The app id, from EVERYAPP_APP_ID (which `everyAppWorker()` sets). */
|
|
50
|
+
function appIdFor(env) {
|
|
51
|
+
return envValue(env, APP_ID_ENV);
|
|
59
52
|
}
|
|
60
53
|
function devIdentitiesAllowed(env, config) {
|
|
61
54
|
const devEnv = envValue(env, DEV_ENV);
|
|
@@ -71,7 +64,7 @@ function devIdentitiesAllowed(env, config) {
|
|
|
71
64
|
* app id stand in when EVERYAPP_AUDIENCE is unset.
|
|
72
65
|
*/
|
|
73
66
|
function audienceFor(env, config) {
|
|
74
|
-
const appId = appIdFor(env
|
|
67
|
+
const appId = appIdFor(env);
|
|
75
68
|
const audience = envValue(env, AUDIENCE_ENV);
|
|
76
69
|
if (audience)
|
|
77
70
|
return audience;
|
|
@@ -153,7 +146,6 @@ const servedRequests = new WeakMap();
|
|
|
153
146
|
* (a framework that hands out headers alone needs no made-up Request).
|
|
154
147
|
* Answers from the request context or the per-request cache first, then
|
|
155
148
|
* verifies the identity headers from the audience and public keys in env.
|
|
156
|
-
* Inside a handler `everyApp()` serves, `currentUser()` is the shorter way.
|
|
157
149
|
*/
|
|
158
150
|
export async function getEveryAppUser(request, env) {
|
|
159
151
|
const cached = requestIdentities.get(request);
|
|
@@ -187,19 +179,6 @@ export async function requireEveryAppUser(request, env) {
|
|
|
187
179
|
throw error;
|
|
188
180
|
}
|
|
189
181
|
}
|
|
190
|
-
/**
|
|
191
|
-
* The user of the request being served (`currentUser()`), or throw the
|
|
192
|
-
* same 401 JSON Response as `requireEveryAppUser()` on a public route.
|
|
193
|
-
* Outside a request (`withOrganization()` work, a handler not under
|
|
194
|
-
* `everyApp()`) it throws `RequestContextError`, as `currentUser()` does.
|
|
195
|
-
*/
|
|
196
|
-
export function requireCurrentUser() {
|
|
197
|
-
const user = currentUser();
|
|
198
|
-
if (!user) {
|
|
199
|
-
throw unauthorized("this request does not have an authenticated user");
|
|
200
|
-
}
|
|
201
|
-
return user;
|
|
202
|
-
}
|
|
203
182
|
/**
|
|
204
183
|
* `response` without `Set-Cookie`: the perimeter strips every `Cookie`
|
|
205
184
|
* before a request reaches the app, so no cookie the app sets ever comes
|
|
@@ -224,26 +203,16 @@ function withoutCookies(response) {
|
|
|
224
203
|
export function hasScope(user, scope) {
|
|
225
204
|
return user.scopes.includes("*") || user.scopes.includes(scope);
|
|
226
205
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
typeof value.id === "string");
|
|
231
|
-
}
|
|
232
|
-
export function everyApp(handler, manifestOrOptions, legacyOptions = {}) {
|
|
233
|
-
const manifest = isManifest(manifestOrOptions)
|
|
234
|
-
? manifestOrOptions
|
|
235
|
-
: undefined;
|
|
236
|
-
const options = manifest || manifestOrOptions === undefined
|
|
237
|
-
? legacyOptions
|
|
238
|
-
: manifestOrOptions;
|
|
239
|
-
const config = configFrom(manifest, options);
|
|
206
|
+
/** Wrap a Worker fetch handler with Every App identity verification. */
|
|
207
|
+
export function everyApp(handler, options = {}) {
|
|
208
|
+
const config = configFrom(options);
|
|
240
209
|
return {
|
|
241
210
|
async fetch(request, env, ctx) {
|
|
242
211
|
let audience;
|
|
243
212
|
let appId;
|
|
244
213
|
try {
|
|
245
214
|
audience = audienceFor(env, config);
|
|
246
|
-
appId = appIdFor(env
|
|
215
|
+
appId = appIdFor(env) ?? audience;
|
|
247
216
|
}
|
|
248
217
|
catch (err) {
|
|
249
218
|
if (err instanceof ConfigurationError) {
|
|
@@ -261,6 +230,13 @@ export function everyApp(handler, manifestOrOptions, legacyOptions = {}) {
|
|
|
261
230
|
});
|
|
262
231
|
if (toolsResponse)
|
|
263
232
|
return toolsResponse;
|
|
233
|
+
// So does the event sink's delivery path (`/__everyapp/events`).
|
|
234
|
+
const eventsResponse = await handleEventsRequest(request, env, ctx, {
|
|
235
|
+
events: options.events,
|
|
236
|
+
identity: identityOptions(env, config, audience),
|
|
237
|
+
});
|
|
238
|
+
if (eventsResponse)
|
|
239
|
+
return eventsResponse;
|
|
264
240
|
let identity;
|
|
265
241
|
try {
|
|
266
242
|
identity = await getIdentityFromRequest(request, identityOptions(env, config, audience));
|
|
@@ -31,7 +31,7 @@ export interface CreateGatewayFetchOptions {
|
|
|
31
31
|
/**
|
|
32
32
|
* Whom the call is for. Left out, the request `everyApp()` is serving
|
|
33
33
|
* (its user, while the identity is good) or the organization
|
|
34
|
-
*
|
|
34
|
+
* an event delivery runs under; outside both, `RequestContextError`.
|
|
35
35
|
* Explicitly: the inbound request, or `{ background: true,
|
|
36
36
|
* organizationId }` for work no person started (crons, Workflows,
|
|
37
37
|
* queues). A shared app's Worker must end up with one or the other
|
|
@@ -179,7 +179,7 @@ function directProviderPath(input, env) {
|
|
|
179
179
|
// names a model sends it as it is).
|
|
180
180
|
const values = env;
|
|
181
181
|
const resolution = resolveAiDefault({
|
|
182
|
-
|
|
182
|
+
choice: null,
|
|
183
183
|
isSet: (name) => typeof values[name] === "string" &&
|
|
184
184
|
values[name].trim().length > 0,
|
|
185
185
|
});
|
package/dist/server/index.d.ts
CHANGED
|
@@ -3,27 +3,24 @@
|
|
|
3
3
|
*
|
|
4
4
|
* There is intentionally no client-side export.
|
|
5
5
|
*/
|
|
6
|
-
export { ConfigurationError,
|
|
7
|
-
export { OrganizationMismatchError, RequestContextError, currentUser, withOrganization, } from "./context.js";
|
|
6
|
+
export { ConfigurationError, everyApp, getEveryAppUser, hasScope, isAdmin, requireEveryAppUser, type EveryAppOptions, type EveryAppHandler, type EveryAppUser, type IdentityResult, type OrgRole, } from "./everyApp.js";
|
|
8
7
|
export { AttributionError, type GatewayCallFor } from "./attribution.js";
|
|
9
8
|
export { gatewayUrl } from "./gatewayUrl.js";
|
|
10
9
|
export type { EveryAppEnv } from "./env.js";
|
|
11
10
|
/** The header a Gateway refusal carries its code in; `gatewayRefusal()` reads the rest. */
|
|
12
11
|
export { GATEWAY_ERROR_HEADER } from "../internal/protocol.js";
|
|
13
|
-
export { authorizeUrl, type AuthorizeUrlOptions } from "./authorizeUrl.js";
|
|
14
12
|
export { connectPath, connectUrl, type ConnectUrlOptions, } from "./connectUrl.js";
|
|
15
13
|
export { createGatewayFetch, type CreateGatewayFetchOptions, } from "./gatewayFetch.js";
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
14
|
+
export { aiBaseUrl, providerBaseUrl } from "./ai.js";
|
|
15
|
+
export { GatewayRefusalError, gatewayRefusal, refusalFromError, type GatewayRefusal, type SetupInfo, } from "./refusal.js";
|
|
18
16
|
export { devAccessTokenName, integrationFetch, integrationStatus, type EmailIntegrationStatus, type IntegrationFetchOptions, type IntegrationStatus, type IntegrationStatusOf, type OAuthClientIntegrationStatus, } from "./integrationFetch.js";
|
|
19
17
|
export { nodeServerHandler, type NodeServer, type NodeServerHandlerOptions, } from "./nodeServer.js";
|
|
20
18
|
export { sendEmail, type SendEmailOptions } from "./sendEmail.js";
|
|
21
|
-
export { gatewayAiBinding, type GatewayAiBindingOptions } from "./aiBinding.js";
|
|
22
|
-
export { gatewayEmailBinding, type GatewayEmailBindingMessage, type GatewayEmailBindingOptions, } from "./emailBinding.js";
|
|
23
19
|
export { listMembers, type ListMembersOptions } from "./listMembers.js";
|
|
24
20
|
export { emit, type EmitOptions } from "./emit.js";
|
|
25
|
-
export
|
|
21
|
+
export { WEBHOOK_MAX_BYTES_DEFAULT, verifyWebhook, type VerifyWebhookOptions, type WebhookProvider, type WebhookRefusalReason, type WebhookVerification, } from "./webhooks.js";
|
|
22
|
+
export type { AppEvent, AppEventHandler, AppEventsOptions, } from "./eventsEndpoint.js";
|
|
23
|
+
export type { ApiKeyCapabilityId, CapabilityId, OAuthPresetId, EmailAddressInput, EmailAttachmentInput, SendEmailMessage, SendEmailResult, ListMembersResult, OrganizationMember, OrganizationMemberRole, EmitEventResult, } from "../internal/index.js";
|
|
26
24
|
export { ToolError, defineTools, toolResult, type DefineToolsOptions, type PlainToolSchema, type StandardSchemaWithJSON, type ToolContext, type ToolDefinition, type ToolResult, type ToolSchema, type ToolSet, } from "./tools.js";
|
|
27
25
|
export type { ToolRisk } from "../internal/index.js";
|
|
28
|
-
export { fromMcpTools, type FromMcpToolsOptions, type McpToolAnnotationsLike, type McpToolLike, type McpToolResultLike, type McpToolSchemaLike, } from "./fromMcpTools.js";
|
|
29
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,OAAO,EACP,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,OAAO,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC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,EACZ,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,SAAS,EACT,WAAW,EACX,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -3,23 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* There is intentionally no client-side export.
|
|
5
5
|
*/
|
|
6
|
-
export { ConfigurationError,
|
|
7
|
-
export { OrganizationMismatchError, RequestContextError, currentUser, withOrganization, } from "./context.js";
|
|
6
|
+
export { ConfigurationError, everyApp, getEveryAppUser, hasScope, isAdmin, requireEveryAppUser, } from "./everyApp.js";
|
|
8
7
|
export { AttributionError } from "./attribution.js";
|
|
9
8
|
export { gatewayUrl } from "./gatewayUrl.js";
|
|
10
9
|
/** The header a Gateway refusal carries its code in; `gatewayRefusal()` reads the rest. */
|
|
11
10
|
export { GATEWAY_ERROR_HEADER } from "../internal/protocol.js";
|
|
12
|
-
export { authorizeUrl } from "./authorizeUrl.js";
|
|
13
11
|
export { connectPath, connectUrl, } from "./connectUrl.js";
|
|
14
12
|
export { createGatewayFetch, } from "./gatewayFetch.js";
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
13
|
+
export { aiBaseUrl, providerBaseUrl } from "./ai.js";
|
|
14
|
+
export { GatewayRefusalError, gatewayRefusal, refusalFromError, } from "./refusal.js";
|
|
17
15
|
export { devAccessTokenName, integrationFetch, integrationStatus, } from "./integrationFetch.js";
|
|
18
16
|
export { nodeServerHandler, } from "./nodeServer.js";
|
|
19
17
|
export { sendEmail } from "./sendEmail.js";
|
|
20
|
-
export { gatewayAiBinding } from "./aiBinding.js";
|
|
21
|
-
export { gatewayEmailBinding, } from "./emailBinding.js";
|
|
22
18
|
export { listMembers } from "./listMembers.js";
|
|
23
19
|
export { emit } from "./emit.js";
|
|
20
|
+
export { WEBHOOK_MAX_BYTES_DEFAULT, verifyWebhook, } from "./webhooks.js";
|
|
24
21
|
export { ToolError, defineTools, toolResult, } from "./tools.js";
|
|
25
|
-
export { fromMcpTools, } from "./fromMcpTools.js";
|