@every-app/sdk 0.3.0-rc.3 → 0.3.0-rc.5

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 (100) hide show
  1. package/README.md +1 -1
  2. package/dist/cloudflare/catalogSettings.generated.d.ts +95 -0
  3. package/dist/cloudflare/catalogSettings.generated.d.ts.map +1 -0
  4. package/dist/cloudflare/catalogSettings.generated.js +221 -0
  5. package/dist/cloudflare/index.d.ts +2 -1
  6. package/dist/cloudflare/index.d.ts.map +1 -1
  7. package/dist/cloudflare/index.js +3 -0
  8. package/dist/cloudflare/sentinel.d.ts +21 -4
  9. package/dist/cloudflare/sentinel.d.ts.map +1 -1
  10. package/dist/cloudflare/sentinel.js +8 -4
  11. package/dist/cloudflare/worker.d.ts +195 -103
  12. package/dist/cloudflare/worker.d.ts.map +1 -1
  13. package/dist/cloudflare/worker.js +220 -137
  14. package/dist/dev/index.d.ts +1 -1
  15. package/dist/dev/index.d.ts.map +1 -1
  16. package/dist/dev/index.js +1 -1
  17. package/dist/dev/keypair.d.ts +2 -0
  18. package/dist/dev/keypair.d.ts.map +1 -1
  19. package/dist/dev/keypair.js +2 -0
  20. package/dist/index.d.ts +6 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +5 -0
  23. package/dist/internal/capabilities.d.ts +1 -1
  24. package/dist/internal/catalog/index.d.ts +1 -1
  25. package/dist/internal/catalog/inference.d.ts +1 -1
  26. package/dist/internal/catalog/inference.js +3 -3
  27. package/dist/internal/events.d.ts +1 -1
  28. package/dist/internal/events.d.ts.map +1 -1
  29. package/dist/internal/events.js +23 -1
  30. package/dist/internal/gatewaySettings.d.ts +7 -1
  31. package/dist/internal/gatewaySettings.d.ts.map +1 -1
  32. package/dist/internal/gatewaySettings.js +12 -1
  33. package/dist/internal/identity.d.ts +29 -3
  34. package/dist/internal/identity.d.ts.map +1 -1
  35. package/dist/internal/identity.js +37 -9
  36. package/dist/internal/index.d.ts +1 -1
  37. package/dist/internal/index.d.ts.map +1 -1
  38. package/dist/internal/index.js +1 -1
  39. package/dist/internal/members.d.ts +3 -2
  40. package/dist/internal/members.d.ts.map +1 -1
  41. package/dist/internal/protocol.d.ts +25 -1
  42. package/dist/internal/protocol.d.ts.map +1 -1
  43. package/dist/internal/protocol.js +21 -1
  44. package/dist/manifest.d.ts +205 -0
  45. package/dist/manifest.d.ts.map +1 -0
  46. package/dist/manifest.js +30 -0
  47. package/dist/server/ai.d.ts +21 -0
  48. package/dist/server/ai.d.ts.map +1 -1
  49. package/dist/server/ai.js +37 -8
  50. package/dist/server/aiBinding.d.ts +68 -0
  51. package/dist/server/aiBinding.d.ts.map +1 -0
  52. package/dist/server/aiBinding.js +294 -0
  53. package/dist/server/attribution.d.ts +9 -5
  54. package/dist/server/attribution.d.ts.map +1 -1
  55. package/dist/server/attribution.js +12 -4
  56. package/dist/server/context.d.ts +68 -0
  57. package/dist/server/context.d.ts.map +1 -0
  58. package/dist/server/context.js +117 -0
  59. package/dist/server/emailBinding.d.ts +72 -0
  60. package/dist/server/emailBinding.d.ts.map +1 -0
  61. package/dist/server/emailBinding.js +124 -0
  62. package/dist/server/emit.d.ts +1 -1
  63. package/dist/server/emit.d.ts.map +1 -1
  64. package/dist/server/emit.js +4 -4
  65. package/dist/server/env.d.ts +41 -0
  66. package/dist/server/env.d.ts.map +1 -0
  67. package/dist/server/env.js +1 -0
  68. package/dist/server/everyApp.d.ts +27 -7
  69. package/dist/server/everyApp.d.ts.map +1 -1
  70. package/dist/server/everyApp.js +106 -5
  71. package/dist/server/fromMcpTools.d.ts +89 -0
  72. package/dist/server/fromMcpTools.d.ts.map +1 -0
  73. package/dist/server/fromMcpTools.js +192 -0
  74. package/dist/server/gatewayFetch.d.ts +24 -18
  75. package/dist/server/gatewayFetch.d.ts.map +1 -1
  76. package/dist/server/gatewayFetch.js +9 -9
  77. package/dist/server/gatewayUrl.d.ts +13 -0
  78. package/dist/server/gatewayUrl.d.ts.map +1 -0
  79. package/dist/server/gatewayUrl.js +34 -0
  80. package/dist/server/index.d.ts +11 -3
  81. package/dist/server/index.d.ts.map +1 -1
  82. package/dist/server/index.js +9 -2
  83. package/dist/server/integrationFetch.d.ts +28 -7
  84. package/dist/server/integrationFetch.d.ts.map +1 -1
  85. package/dist/server/integrationFetch.js +24 -28
  86. package/dist/server/listMembers.d.ts +1 -1
  87. package/dist/server/listMembers.d.ts.map +1 -1
  88. package/dist/server/listMembers.js +5 -8
  89. package/dist/server/sendEmail.d.ts +1 -1
  90. package/dist/server/sendEmail.d.ts.map +1 -1
  91. package/dist/server/sendEmail.js +4 -4
  92. package/dist/server/toolsEndpoint.d.ts.map +1 -1
  93. package/dist/server/toolsEndpoint.js +11 -5
  94. package/dist/tanstack-start/index.d.ts +9 -0
  95. package/dist/tanstack-start/index.d.ts.map +1 -0
  96. package/dist/tanstack-start/index.js +29 -0
  97. package/dist/testing/index.d.ts +93 -0
  98. package/dist/testing/index.d.ts.map +1 -0
  99. package/dist/testing/index.js +156 -0
  100. package/package.json +25 -4
@@ -0,0 +1,192 @@
1
+ /**
2
+ * `fromMcpTools()` — an app's existing MCP tools as `defineTools()` entries.
3
+ *
4
+ * const tools: McpToolLike[] = [];
5
+ * registerMyTools((name, config, handler) =>
6
+ * tools.push({ name, ...config, handler }),
7
+ * );
8
+ * export default everyApp(handler, {
9
+ * tools: defineTools(fromMcpTools(tools), { instructions }),
10
+ * });
11
+ *
12
+ * Takes the shape `McpServer.registerTool(name, config, handler)` is called
13
+ * with (or what a low-level server's `tools/list` returns, plus a handler),
14
+ * structurally: the SDK takes no dependency on `@modelcontextprotocol/sdk`,
15
+ * and a live `McpServer` keeps its registry private, so the app hands over
16
+ * the list it registers from.
17
+ */
18
+ import { TOOL_NAME_PATTERN } from "../internal/index.js";
19
+ import { ToolError, toolResult, } from "./tools.js";
20
+ const JSON_SCHEMA_TARGET = "draft-2020-12";
21
+ /**
22
+ * Adapt MCP tools into `defineTools()` entries, keyed by tool name, to spread
23
+ * beside the app's own: `defineTools({ ...fromMcpTools(list), my_tool })`.
24
+ *
25
+ * - `title`, `description` (the name when absent), `idempotentHint` and
26
+ * `openWorldHint` carry over; risk as {@link FromMcpToolsOptions.risk}.
27
+ * - A result's text blocks, joined by a blank line, are what the model
28
+ * reads; `structuredContent` is sent as structured content (checked
29
+ * against `outputSchema` when there is one). Other blocks are dropped.
30
+ * - `isError: true` becomes a {@link ToolError} with the result's text.
31
+ *
32
+ * Names must already be lowercase snake_case; `defineTools()` checks them.
33
+ */
34
+ export function fromMcpTools(tools, options = {}) {
35
+ const out = {};
36
+ for (const tool of tools) {
37
+ const problem = (message) => new TypeError(`fromMcpTools: tool "${tool?.name}" ${message}`);
38
+ if (!tool || typeof tool.name !== "string") {
39
+ throw new TypeError("fromMcpTools: every tool needs a name");
40
+ }
41
+ if (!TOOL_NAME_PATTERN.test(tool.name)) {
42
+ throw problem("must be named in lowercase snake_case: a letter, then letters, digits or _ (at most 48 characters); rename it in the list");
43
+ }
44
+ if (Object.prototype.hasOwnProperty.call(out, tool.name)) {
45
+ throw problem("is listed twice");
46
+ }
47
+ if (typeof tool.handler !== "function") {
48
+ throw problem("needs a handler function");
49
+ }
50
+ const output = tool.outputSchema === undefined
51
+ ? undefined
52
+ : toToolSchema(tool.outputSchema, problem);
53
+ const annotations = tool.annotations ?? {};
54
+ const title = tool.title ?? annotations.title;
55
+ out[tool.name] = {
56
+ ...(title !== undefined ? { title } : {}),
57
+ description: tool.description?.trim() ? tool.description : tool.name,
58
+ risk: options.risk?.(tool) ?? defaultRisk(annotations),
59
+ input: toToolSchema(tool.inputSchema ?? {}, problem),
60
+ ...(output ? { output } : {}),
61
+ ...(annotations.idempotentHint !== undefined
62
+ ? { idempotent: annotations.idempotentHint }
63
+ : {}),
64
+ ...(annotations.openWorldHint !== undefined
65
+ ? { openWorld: annotations.openWorldHint }
66
+ : {}),
67
+ handler: async (args, context) => {
68
+ const extra = options.context
69
+ ? await options.context(context)
70
+ : context;
71
+ const result = await tool.handler(args, extra);
72
+ return fromCallToolResult(result);
73
+ },
74
+ };
75
+ }
76
+ return out;
77
+ }
78
+ function defaultRisk(annotations) {
79
+ if (annotations.readOnlyHint === true)
80
+ return "read";
81
+ return annotations.destructiveHint === true ? "destructive" : "write";
82
+ }
83
+ function fromCallToolResult(result) {
84
+ if (!isRecord(result)) {
85
+ throw new Error("the MCP tool did not return a CallToolResult");
86
+ }
87
+ const text = (Array.isArray(result.content) ? result.content : [])
88
+ .flatMap((part) => isRecord(part) && part.type === "text" && typeof part.text === "string"
89
+ ? [part.text]
90
+ : [])
91
+ .join("\n\n");
92
+ if (result.isError === true)
93
+ throw new ToolError(text || "The tool failed.");
94
+ const structured = result.structuredContent;
95
+ if (isRecord(structured) && !Array.isArray(structured)) {
96
+ return toolResult({ text, structured });
97
+ }
98
+ return text;
99
+ }
100
+ function isRecord(value) {
101
+ return typeof value === "object" && value !== null;
102
+ }
103
+ function isStandardWithJson(value) {
104
+ if (!isRecord(value))
105
+ return false;
106
+ const standard = value["~standard"];
107
+ return (isRecord(standard) &&
108
+ typeof standard.validate === "function" &&
109
+ isRecord(standard.jsonSchema));
110
+ }
111
+ function isPlainToolSchema(value) {
112
+ return isRecord(value.jsonSchema) && typeof value.validate === "function";
113
+ }
114
+ function toToolSchema(schema, problem) {
115
+ if (!isRecord(schema) || Array.isArray(schema)) {
116
+ throw problem("has a schema that is not an object");
117
+ }
118
+ if (isStandardWithJson(schema) || isPlainToolSchema(schema)) {
119
+ return schema;
120
+ }
121
+ if ("~standard" in schema) {
122
+ throw problem("has a schema that doesn't convert to JSON Schema (zod >= 4.2 does)");
123
+ }
124
+ const values = Object.values(schema);
125
+ if (values.every((value) => isRecord(value) && "~standard" in value)) {
126
+ if (!values.every(isStandardWithJson)) {
127
+ throw problem("has a raw shape whose fields don't convert to JSON Schema (zod >= 4.2 does)");
128
+ }
129
+ return rawShapeSchema(schema);
130
+ }
131
+ return jsonSchemaOnly(schema);
132
+ }
133
+ /** A plain JSON Schema: described as is; any object passes. */
134
+ function jsonSchemaOnly(jsonSchema) {
135
+ return {
136
+ jsonSchema,
137
+ validate: (value) => isRecord(value) && !Array.isArray(value)
138
+ ? { value }
139
+ : { issues: [{ message: "Expected an object" }] },
140
+ };
141
+ }
142
+ /**
143
+ * `{ key: schema }` as an object schema, the way `McpServer` wraps one in
144
+ * `z.object()`: unknown keys are dropped, and a field is optional when its
145
+ * schema accepts `undefined`.
146
+ */
147
+ function rawShapeSchema(shape) {
148
+ const properties = {};
149
+ const required = [];
150
+ for (const [key, field] of Object.entries(shape)) {
151
+ const { $schema: _, ...property } = field["~standard"].jsonSchema.input({
152
+ target: JSON_SCHEMA_TARGET,
153
+ });
154
+ properties[key] = property;
155
+ const absent = field["~standard"].validate(undefined);
156
+ // An async validator can't be asked here; call the field required.
157
+ if (absent instanceof Promise || absent.issues)
158
+ required.push(key);
159
+ }
160
+ return {
161
+ jsonSchema: {
162
+ type: "object",
163
+ properties,
164
+ ...(required.length > 0 ? { required } : {}),
165
+ },
166
+ validate: async (value) => {
167
+ if (!isRecord(value) || Array.isArray(value)) {
168
+ return { issues: [{ message: "Expected an object" }] };
169
+ }
170
+ const parsed = {};
171
+ const issues = [];
172
+ for (const [key, field] of Object.entries(shape)) {
173
+ const result = await field["~standard"].validate(value[key]);
174
+ if (result.issues) {
175
+ for (const issue of result.issues) {
176
+ issues.push({
177
+ message: issue.message,
178
+ path: [
179
+ key,
180
+ ...(issue.path ?? []).map((segment) => typeof segment === "object" ? segment.key : segment),
181
+ ],
182
+ });
183
+ }
184
+ }
185
+ else if (key in value || result.value !== undefined) {
186
+ parsed[key] = result.value;
187
+ }
188
+ }
189
+ return issues.length > 0 ? { issues } : { value: parsed };
190
+ },
191
+ };
192
+ }
@@ -3,27 +3,30 @@ export declare const BINDING_ORIGIN = "http://every-app-gateway.internal";
3
3
  export interface GatewayServiceBinding {
4
4
  fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
5
5
  }
6
- export interface GatewayFetchEnv {
7
- EVERY_APP_GATEWAY?: GatewayServiceBinding;
8
- EVERYAPP_DEV?: string | boolean;
9
- /** `1` on a shared app's Workers (`everyAppWorker()` sets it). */
10
- EVERYAPP_SHARED?: string;
11
- OPENAI_API_KEY?: string;
12
- OPENROUTER_API_KEY?: string;
13
- /** Workers AI: an API token (Workers AI Read and Edit) and the account it bills. */
14
- WORKERS_AI_API_TOKEN?: string;
15
- CLOUDFLARE_ACCOUNT_ID?: string;
16
- }
17
6
  export interface CreateGatewayFetchOptions {
18
- env: GatewayFetchEnv;
19
7
  /**
20
- * Whom the call is for: the inbound request (its user), or
21
- * `{ background: true, organizationId }` for work no person started
22
- * (crons, Workflows, queues). An organization's own app may omit it for
23
- * background work, which is then the app's; a shared app's Worker must
24
- * pass one or the other ({@link AttributionError}).
8
+ * The Worker env, as it is: the EVERY_APP_GATEWAY binding when deployed,
9
+ * or in local dev EVERYAPP_DEV and the provider's settings in
10
+ * `.dev.vars` (`OPENROUTER_API_KEY`, …). No cast needed.
11
+ */
12
+ env: object;
13
+ /**
14
+ * Whom the call is for. Left out, the request `everyApp()` is serving
15
+ * (its user, while the identity is good) or the organization
16
+ * `withOrganization()` named; outside both, `RequestContextError`.
17
+ * Explicitly: the inbound request, or `{ background: true,
18
+ * organizationId }` for work no person started (crons, Workflows,
19
+ * queues). A shared app's Worker must end up with one or the other
20
+ * ({@link AttributionError}).
25
21
  */
26
22
  for?: GatewayCallFor;
23
+ /**
24
+ * `true`: answer null instead of throwing `ConfigurationError` when AI
25
+ * is unavailable (no binding, and in local dev no provider key), so a
26
+ * feature that can do without a model checks for null. A binding that
27
+ * isn't one, and an attribution mistake, still throw.
28
+ */
29
+ optional?: boolean;
27
30
  }
28
31
  /**
29
32
  * Create a fetch for the gateway's AI providers (`/api/ai/<provider>/…`),
@@ -31,7 +34,10 @@ export interface CreateGatewayFetchOptions {
31
34
  * developer's own provider key from `.dev.vars` is a direct-provider
32
35
  * fallback when no binding exists.
33
36
  */
34
- export declare function createGatewayFetch({ env, for: target, }: CreateGatewayFetchOptions): typeof fetch;
37
+ export declare function createGatewayFetch(options: CreateGatewayFetchOptions & {
38
+ optional: true;
39
+ }): typeof fetch | null;
40
+ export declare function createGatewayFetch(options: CreateGatewayFetchOptions): typeof fetch;
35
41
  /** A copy of `source` aimed at `url`, streaming its body rather than buffering it. */
36
42
  export declare function streamingRequest(url: string, source: Request, headers: Headers): Request;
37
43
  //# sourceMappingURL=gatewayFetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gatewayFetch.d.ts","sourceRoot":"","sources":["../../src/server/gatewayFetch.ts"],"names":[],"mappings":"AAaA,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,cAAc,sCAAsC,CAAC;AAGlE,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxE;AAED,MAAM,WAAW,eAAe;IAC9B,iBAAiB,CAAC,EAAE,qBAAqB,CAAC;IAC1C,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,kEAAkE;IAClE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oFAAoF;IACpF,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,yBAAyB;IACxC,GAAG,EAAE,eAAe,CAAC;IACrB;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,GAAG,EACH,GAAG,EAAE,MAAM,GACZ,EAAE,yBAAyB,GAAG,OAAO,KAAK,CAoE1C;AAwCD,sFAAsF;AACtF,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,OAAO,GACf,OAAO,CAUT"}
1
+ {"version":3,"file":"gatewayFetch.d.ts","sourceRoot":"","sources":["../../src/server/gatewayFetch.ts"],"names":[],"mappings":"AAaA,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,cAAc,sCAAsC,CAAC;AAGlE,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxE;AAeD,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,yBAAyB,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GACtD,OAAO,KAAK,GAAG,IAAI,CAAC;AACvB,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,yBAAyB,GACjC,OAAO,KAAK,CAAC;AAsHhB,sFAAsF;AACtF,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,OAAO,GACf,OAAO,CAUT"}
@@ -1,24 +1,24 @@
1
1
  import { AI_DEFAULT_MODEL, AI_DEFAULT_PROVIDER, AI_DEFAULT_ROUTES, aiProviderSettings, authorizationOf, ConfigurationError, DEV_AI_PROVIDERS, devAiProvider, joinProviderUrl, resolveAiDefault, } from "../internal/index.js";
2
- import { applyAttribution, checkAttribution, } from "./attribution.js";
2
+ import { applyAttribution, attributionFor, } from "./attribution.js";
3
3
  export const BINDING_ORIGIN = "http://every-app-gateway.internal";
4
4
  const AI_PROXY_PREFIX = "/api/ai/";
5
- /**
6
- * Create a fetch for the gateway's AI providers (`/api/ai/<provider>/…`),
7
- * backed by the private gateway service binding. In local dev only, the
8
- * developer's own provider key from `.dev.vars` is a direct-provider
9
- * fallback when no binding exists.
10
- */
11
- export function createGatewayFetch({ env, for: target, }) {
12
- checkAttribution(env, target, "createGatewayFetch");
5
+ export function createGatewayFetch({ env: workerEnv, for: explicitTarget, optional = false, }) {
6
+ const env = workerEnv;
7
+ // Checked now, so a call nobody's fails where the fetch is made; and
8
+ // again per call, where an identity may since have neared its expiry.
9
+ attributionFor(env, explicitTarget, "createGatewayFetch");
13
10
  const binding = env.EVERY_APP_GATEWAY;
14
11
  const devProviders = env.EVERYAPP_DEV ? localProviders(env) : {};
15
12
  if (binding && typeof binding.fetch !== "function") {
16
13
  throw new ConfigurationError("EVERY_APP_GATEWAY is configured but is not a valid service binding.");
17
14
  }
18
15
  if (!binding && Object.keys(devProviders).length === 0) {
16
+ if (optional)
17
+ return null;
19
18
  throw new ConfigurationError(`AI gateway unavailable: deploy with the EVERY_APP_GATEWAY binding, or set the provider's key (${listOf(Object.values(DEV_AI_PROVIDERS).map((spec) => settingsNames(spec, "with")), "or")}) in .dev.vars for direct local development.`);
20
19
  }
21
20
  return async (input, init) => {
21
+ const target = attributionFor(env, explicitTarget, "createGatewayFetch");
22
22
  const outbound = new Request(input, init);
23
23
  const headers = new Headers(outbound.headers);
24
24
  headers.delete("authorization");
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The Gateway's URL, with `path` on it: `gatewayUrl(env)` for the launcher,
3
+ * `gatewayUrl(env, "/admin/users")` for the page where owners and admins
4
+ * invite people.
5
+ *
6
+ * Read from `env.GATEWAY_URL`, which the deploy sets on every Worker of the
7
+ * app and `everyapp dev` sets to its local launcher, so the same link works
8
+ * in both. `env` is the Worker's env (any object; only `GATEWAY_URL` is
9
+ * read). Throws {@link ConfigurationError} when it is unset or not an http(s)
10
+ * URL: a Worker no deploy or `everyapp dev` built.
11
+ */
12
+ export declare function gatewayUrl(env: object, path?: string): string;
13
+ //# sourceMappingURL=gatewayUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gatewayUrl.d.ts","sourceRoot":"","sources":["../../src/server/gatewayUrl.ts"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,MAAM,CAgB1D"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * `gatewayUrl()`: the one rule for a link from an app back to its Gateway
3
+ * ("‹ Every App", "Invite people", "Sign out").
4
+ */
5
+ import { ConfigurationError } from "../internal/index.js";
6
+ /** Where the Gateway is: the deploy sets it, and so does `everyapp dev`. */
7
+ const GATEWAY_URL_ENV = "GATEWAY_URL";
8
+ /**
9
+ * The Gateway's URL, with `path` on it: `gatewayUrl(env)` for the launcher,
10
+ * `gatewayUrl(env, "/admin/users")` for the page where owners and admins
11
+ * invite people.
12
+ *
13
+ * Read from `env.GATEWAY_URL`, which the deploy sets on every Worker of the
14
+ * app and `everyapp dev` sets to its local launcher, so the same link works
15
+ * in both. `env` is the Worker's env (any object; only `GATEWAY_URL` is
16
+ * read). Throws {@link ConfigurationError} when it is unset or not an http(s)
17
+ * URL: a Worker no deploy or `everyapp dev` built.
18
+ */
19
+ export function gatewayUrl(env, path = "/") {
20
+ const value = env[GATEWAY_URL_ENV];
21
+ let base;
22
+ if (typeof value === "string" && value) {
23
+ try {
24
+ base = new URL(value);
25
+ }
26
+ catch {
27
+ base = undefined;
28
+ }
29
+ }
30
+ if (!base || (base.protocol !== "https:" && base.protocol !== "http:")) {
31
+ throw new ConfigurationError(`${GATEWAY_URL_ENV} is ${value ? "not an http(s) URL" : "unset"}: everyapp deploy and everyapp dev set it on the app's Worker.`);
32
+ }
33
+ return new URL(path, base.origin).toString();
34
+ }
@@ -3,18 +3,26 @@
3
3
  *
4
4
  * There is intentionally no client-side export.
5
5
  */
6
- export { ConfigurationError, IdentityError, everyApp, getEveryAppUser, hasScope, requireEveryAppUser, type EveryAppOptions, type EveryAppManifestLike, type EveryAppHandler, type EveryAppUser, type IdentityResult, } from "./everyApp.js";
6
+ export { ConfigurationError, IdentityError, everyApp, getEveryAppUser, hasScope, isAdmin, requireCurrentUser, requireEveryAppUser, type EveryAppOptions, type EveryAppManifestLike, type EveryAppHandler, type EveryAppUser, type IdentityResult, type OrgRole, } from "./everyApp.js";
7
+ export { OrganizationMismatchError, RequestContextError, currentUser, withOrganization, } from "./context.js";
7
8
  export { AttributionError, type GatewayCallFor } from "./attribution.js";
9
+ export { gatewayUrl } from "./gatewayUrl.js";
10
+ export type { EveryAppEnv } from "./env.js";
11
+ /** The header a Gateway refusal carries its code in; `gatewayRefusal()` reads the rest. */
12
+ export { GATEWAY_ERROR_HEADER } from "../internal/protocol.js";
8
13
  export { authorizeUrl, type AuthorizeUrlOptions } from "./authorizeUrl.js";
9
14
  export { connectPath, connectUrl, type ConnectUrlOptions, } from "./connectUrl.js";
10
- export { createGatewayFetch, type CreateGatewayFetchOptions, type GatewayFetchEnv, } from "./gatewayFetch.js";
11
- export { ai, AI_DEFAULT_BASE_URL, type AiClient } from "./ai.js";
15
+ export { createGatewayFetch, type CreateGatewayFetchOptions, } from "./gatewayFetch.js";
16
+ export { ai, aiBaseUrl, providerBaseUrl, AI_DEFAULT_BASE_URL, type AiClient, } from "./ai.js";
12
17
  export { GatewayRefusalError, gatewayRefusal, devAccessTokenName, integrationFetch, integrationStatus, type EmailIntegrationStatus, type GatewayRefusal, type IntegrationFetchOptions, type IntegrationStatus, type IntegrationStatusOf, type OAuthClientIntegrationStatus, } from "./integrationFetch.js";
13
18
  export { nodeServerHandler, type NodeServer, type NodeServerHandlerOptions, } from "./nodeServer.js";
14
19
  export { sendEmail, type SendEmailOptions } from "./sendEmail.js";
20
+ export { gatewayAiBinding, type GatewayAiBindingOptions } from "./aiBinding.js";
21
+ export { gatewayEmailBinding, type GatewayEmailBindingMessage, type GatewayEmailBindingOptions, } from "./emailBinding.js";
15
22
  export { listMembers, type ListMembersOptions } from "./listMembers.js";
16
23
  export { emit, type EmitOptions } from "./emit.js";
17
24
  export type { ApiKeyCapabilityId, CapabilityId, OAuthClientCapabilityId, ConnectionAccount, EmailAddressInput, EmailAttachmentInput, SendEmailMessage, SendEmailResult, ListMembersResult, OrganizationMember, OrganizationMemberRole, EmitEventResult, } from "../internal/index.js";
18
25
  export { ToolError, defineTools, toolResult, type DefineToolsOptions, type PlainToolSchema, type StandardSchemaWithJSON, type ToolContext, type ToolDefinition, type ToolResult, type ToolSchema, type ToolSet, } from "./tools.js";
19
26
  export type { ToolRisk } from "../internal/index.js";
27
+ export { fromMcpTools, type FromMcpToolsOptions, type McpToolAnnotationsLike, type McpToolLike, type McpToolResultLike, type McpToolSchemaLike, } from "./fromMcpTools.js";
20
28
  //# 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,aAAa,EACb,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,cAAc,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EACL,WAAW,EACX,UAAU,EACV,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,mBAAmB,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,4BAA4B,GAClC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,wBAAwB,GAC9B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,OAAO,EACP,k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AE,KAAK,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EACL,mBAAmB,EACnB,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,GAChC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,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;AACrD,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,GACvB,MAAM,mBAAmB,CAAC"}
@@ -3,15 +3,22 @@
3
3
  *
4
4
  * There is intentionally no client-side export.
5
5
  */
6
- export { ConfigurationError, IdentityError, everyApp, getEveryAppUser, hasScope, requireEveryAppUser, } from "./everyApp.js";
6
+ export { ConfigurationError, IdentityError, everyApp, getEveryAppUser, hasScope, isAdmin, requireCurrentUser, requireEveryAppUser, } from "./everyApp.js";
7
+ export { OrganizationMismatchError, RequestContextError, currentUser, withOrganization, } from "./context.js";
7
8
  export { AttributionError } from "./attribution.js";
9
+ export { gatewayUrl } from "./gatewayUrl.js";
10
+ /** The header a Gateway refusal carries its code in; `gatewayRefusal()` reads the rest. */
11
+ export { GATEWAY_ERROR_HEADER } from "../internal/protocol.js";
8
12
  export { authorizeUrl } from "./authorizeUrl.js";
9
13
  export { connectPath, connectUrl, } from "./connectUrl.js";
10
14
  export { createGatewayFetch, } from "./gatewayFetch.js";
11
- export { ai, AI_DEFAULT_BASE_URL } from "./ai.js";
15
+ export { ai, aiBaseUrl, providerBaseUrl, AI_DEFAULT_BASE_URL, } from "./ai.js";
12
16
  export { GatewayRefusalError, gatewayRefusal, devAccessTokenName, integrationFetch, integrationStatus, } from "./integrationFetch.js";
13
17
  export { nodeServerHandler, } from "./nodeServer.js";
14
18
  export { sendEmail } from "./sendEmail.js";
19
+ export { gatewayAiBinding } from "./aiBinding.js";
20
+ export { gatewayEmailBinding, } from "./emailBinding.js";
15
21
  export { listMembers } from "./listMembers.js";
16
22
  export { emit } from "./emit.js";
17
23
  export { ToolError, defineTools, toolResult, } from "./tools.js";
24
+ export { fromMcpTools, } from "./fromMcpTools.js";
@@ -17,11 +17,13 @@ export interface IntegrationFetchOptions {
17
17
  */
18
18
  provider: ApiKeyCapabilityId | OAuthClientCapabilityId | (string & {});
19
19
  /**
20
- * Whom the call is for: the inbound request (its user), or
21
- * `{ background: true, organizationId }` for work no person started
22
- * (crons, Workflows, queues). An organization's own app may omit it for
23
- * background work, which is then the app's; a shared app's Worker must
24
- * pass one or the other ({@link AttributionError}).
20
+ * Whom the call is for. Left out, the request `everyApp()` is serving
21
+ * (its user, while the identity is good) or the organization
22
+ * `withOrganization()` named; outside both, `RequestContextError`.
23
+ * Explicitly: the inbound request, or `{ background: true,
24
+ * organizationId }` for work no person started (crons, Workflows,
25
+ * queues). A shared app's Worker must end up with one or the other
26
+ * ({@link AttributionError}).
25
27
  */
26
28
  for?: GatewayCallFor;
27
29
  /**
@@ -31,6 +33,14 @@ export interface IntegrationFetchOptions {
31
33
  * the default for background work). Sent as `x-everyapp-account`.
32
34
  */
33
35
  account?: ConnectionAccount;
36
+ /**
37
+ * `true`: answer null instead of throwing `ConfigurationError` when the
38
+ * provider is unavailable (no binding, and in local dev not its
39
+ * settings in `.dev.vars`), so a feature that can do without it checks
40
+ * for null. A wrong provider id, a binding that isn't one, and an
41
+ * attribution mistake still throw.
42
+ */
43
+ optional?: boolean;
34
44
  }
35
45
  /**
36
46
  * A `fetch` for one of the gateway's capabilities. Call the provider's real
@@ -54,7 +64,10 @@ export interface IntegrationFetchOptions {
54
64
  * provider show <id> --save` writes it), put on the call as the gateway's
55
65
  * spec says.
56
66
  */
57
- export declare function integrationFetch({ env, provider, for: target, account, }: IntegrationFetchOptions): typeof fetch;
67
+ export declare function integrationFetch(options: IntegrationFetchOptions & {
68
+ optional: true;
69
+ }): typeof fetch | null;
70
+ export declare function integrationFetch(options: IntegrationFetchOptions): typeof fetch;
58
71
  /**
59
72
  * The `.dev.vars` name of a held token for `provider` in local dev
60
73
  * (`GOOGLE_WORKSPACE_ACCESS_TOKEN`, `GITHUB_ACCESS_TOKEN`): a token the
@@ -138,9 +151,17 @@ export type IntegrationStatusOf<P extends string> = P extends "email" ? EmailInt
138
151
  * set up") up front instead of failing mid-task. An OAuth client's status
139
152
  * carries its public `clientId` for the authorize URL.
140
153
  */
141
- export declare function integrationStatus<P extends CapabilityId | (string & {})>({ env, provider, }: {
154
+ export declare function integrationStatus<P extends CapabilityId | (string & {})>({ env, provider, for: explicitTarget, }: {
142
155
  env: object;
143
156
  provider: P;
157
+ /**
158
+ * Whom the status is for: the request being served (its person), so an
159
+ * OAuth provider's `connection` is that person's; background work
160
+ * (`withOrganization()`) its organization, whose own connection is then
161
+ * reported. Explicitly the inbound request or `{ background: true,
162
+ * organizationId }`, as on every call.
163
+ */
164
+ for?: GatewayCallFor;
144
165
  }): Promise<IntegrationStatusOf<P>>;
145
166
  /** A refusal the AppGateway binding made itself, not the provider. */
146
167
  export interface GatewayRefusal {
@@ -1 +1 @@
1
- {"version":3,"file":"integrationFetch.d.ts","sourceRo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SAAS,YAAY,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EACtC,EACA,GAAG,EACH,QAAQ,EACR,GAAG,EAAE,cAAc,GACpB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,CAAC,CAAC;IACZ;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;CACtB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAiFlC;AA0HD,sEAAsE;AACtE,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAM,YAAW,cAAc;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,cAAc;CAMtD;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAWhC"}
@@ -1,31 +1,12 @@
1
1
  import { ACCOUNT_HEADER, CATALOG, ConfigurationError, GATEWAY_ERROR_HEADER, INTEGRATION_PROXY_PREFIX, OAUTH_TOKEN_BODY_LIMIT, allowedScopes, apiKeyHosts, authorizationFor, capabilitySettings, carriesToken, declaredScopeSets, describeTokenEndpoints, devProviderFile, grantedScopes, heldTokenCallAllowed, injectClientCredentials, integrationProxyPath, oauthClientCredentials, oauthClientOrigin, oauthReadMethods, oauthWriteMethods, providerSettingPrefix, requestedScopes, requestedTokenScopes, resolveDevProvider, rewriteTokenRequestScope, scopeExcess, tokenEndpointFor, tokenGrantType, EMAIL_SENDERS_ENV, chooseEmailProvider, parseEmailList, parseEmailSender, } from "../internal/index.js";
2
- import { applyAttribution, checkAttribution, } from "./attribution.js";
2
+ import { applyAttribution, attributionFor, } from "./attribution.js";
3
3
  import { BINDING_ORIGIN, streamingRequest, } from "./gatewayFetch.js";
4
- /**
5
- * A `fetch` for one of the gateway's capabilities. Call the provider's real
6
- * URLs (`https://api.dataforseo.com/v3/…`); this sends them over the
7
- * AppGateway binding, which checks the app's manifest lists the capability,
8
- * injects the key the gateway holds and forwards the call. The app never
9
- * sees the key. A refusal the gateway makes itself comes back as a response
10
- * {@link gatewayRefusal} recognizes; anything else is the provider's answer.
11
- *
12
- * For an OAuth client (`linkedin`, `mastodon`, ...) it reaches the
13
- * provider's token endpoints only, and the gateway puts its client on the
14
- * request: send the code (or refresh token) without `client_id` or
15
- * `client_secret`. Build the authorize URL with {@link authorizeUrl} from
16
- * {@link integrationStatus}, and call the provider's API with the user's
17
- * token directly.
18
- *
19
- * In local dev only, with no binding, the developer's own key or client
20
- * from `.dev.vars` reaches the provider directly, under the gateway's names:
21
- * a catalog provider's from the catalog, a provider registered on the
22
- * gateway from its spec in `.everyapp/providers/<id>.json` (`everyapp
23
- * provider show <id> --save` writes it), put on the call as the gateway's
24
- * spec says.
25
- */
26
- export function integrationFetch({ env, provider, for: target, account, }) {
4
+ export function integrationFetch({ env, provider, for: explicitTarget, account, optional = false, }) {
27
5
  const catalogEntry = fetchableCapability(provider);
28
- checkAttribution(env, target, `integrationFetch("${provider}")`);
6
+ const what = `integrationFetch("${provider}")`;
7
+ // Checked now, so a call nobody's fails where the fetch is made; and
8
+ // again per call, where an identity may since have neared its expiry.
9
+ attributionFor(env, explicitTarget, what);
29
10
  const values = env;
30
11
  const binding = values["EVERY_APP_GATEWAY"];
31
12
  if (binding && typeof binding.fetch !== "function") {
@@ -46,6 +27,8 @@ export function integrationFetch({ env, provider, for: target, account, }) {
46
27
  // endpoint call without the client throws when it is made.
47
28
  const decidesLater = integration?.mode === "oauth_client" && integration.flow !== undefined;
48
29
  if (!binding && !local && !devToken && integration && !decidesLater) {
30
+ if (optional)
31
+ return null;
49
32
  const names = [
50
33
  ...capabilitySettings(integration),
51
34
  ...(integration.mode === "oauth_client" && integration.flow
@@ -55,6 +38,7 @@ export function integrationFetch({ env, provider, for: target, account, }) {
55
38
  throw new ConfigurationError(`${integration.label} is unavailable: deploy with the EVERY_APP_GATEWAY binding, or set ${names.join(", ")} in .dev.vars for local development.`);
56
39
  }
57
40
  return async (input, init) => {
41
+ const target = attributionFor(env, explicitTarget, what);
58
42
  const outbound = new Request(input, init);
59
43
  const upstream = new URL(outbound.url);
60
44
  const headers = new Headers(outbound.headers);
@@ -501,7 +485,8 @@ function stringValue(value) {
501
485
  * set up") up front instead of failing mid-task. An OAuth client's status
502
486
  * carries its public `clientId` for the authorize URL.
503
487
  */
504
- export async function integrationStatus({ env, provider, }) {
488
+ export async function integrationStatus({ env, provider, for: explicitTarget, }) {
489
+ const target = attributionFor(env, explicitTarget, `integrationStatus("${String(provider)}")`);
505
490
  const values = env;
506
491
  const binding = values["EVERY_APP_GATEWAY"];
507
492
  // A provider registered on the gateway is the gateway's to answer for;
@@ -529,7 +514,18 @@ export async function integrationStatus({ env, provider, }) {
529
514
  ready: false,
530
515
  });
531
516
  if (binding && typeof binding.fetch === "function") {
532
- const response = await binding.fetch(`${BINDING_ORIGIN}${INTEGRATION_PROXY_PREFIX}/${provider}`);
517
+ const statusUrl = `${BINDING_ORIGIN}${INTEGRATION_PROXY_PREFIX}/${provider}`;
518
+ let response;
519
+ if (target === undefined) {
520
+ response = await binding.fetch(statusUrl);
521
+ }
522
+ else {
523
+ // Whose status: the person's identity (their OAuth connection) or the
524
+ // organization's, as a call would carry it.
525
+ const headers = new Headers();
526
+ applyAttribution(headers, target);
527
+ response = await binding.fetch(statusUrl, { headers });
528
+ }
533
529
  if (!response.ok)
534
530
  return unavailable();
535
531
  return (await response.json());
@@ -685,6 +681,6 @@ export async function gatewayRefusal(response) {
685
681
  typeof body === "object" &&
686
682
  typeof body.message === "string"
687
683
  ? body.message
688
- : `The Every App gateway refused the call (${code}).`;
684
+ : `The EveryApp gateway refused the call (${code}).`;
689
685
  return { status: response.status, code, message };
690
686
  }
@@ -28,5 +28,5 @@ export interface ListMembersOptions {
28
28
  * for a request answers its signed-in user alone, and background work
29
29
  * answers no one.
30
30
  */
31
- export declare function listMembers({ env, for: target, }: ListMembersOptions): Promise<ListMembersResult>;
31
+ export declare function listMembers({ env, for: explicitTarget, }: ListMembersOptions): Promise<ListMembersResult>;
32
32
  //# sourceMappingURL=listMembers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"listMembers.d.ts","sourceRoot":"","sources":["../../src/server/listMembers.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,iBAAiB,EAEvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAK1B,MAAM,WAAW,kBAAkB;IACjC,8FAA8F;IAC9F,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;CACtB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,WAAW,CAAC,EAChC,GAAG,EACH,GAAG,EAAE,MAAM,GACZ,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAoBjD"}
1
+ {"version":3,"file":"listMembers.d.ts","sourceRoot":"","sources":["../../src/server/listMembers.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAK1B,MAAM,WAAW,kBAAkB;IACjC,8FAA8F;IAC9F,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;CACtB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,WAAW,CAAC,EAChC,GAAG,EACH,GAAG,EAAE,cAAc,GACpB,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAoBjD"}