@every-app/sdk 0.3.0-rc.1 → 0.3.0-rc.11

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 (181) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -64
  3. package/dist/cloudflare/catalogSettings.generated.d.ts +84 -0
  4. package/dist/cloudflare/catalogSettings.generated.d.ts.map +1 -0
  5. package/dist/cloudflare/catalogSettings.generated.js +175 -0
  6. package/dist/cloudflare/index.d.ts +3 -2
  7. package/dist/cloudflare/index.d.ts.map +1 -1
  8. package/dist/cloudflare/index.js +4 -1
  9. package/dist/cloudflare/sentinel.d.ts +60 -2
  10. package/dist/cloudflare/sentinel.d.ts.map +1 -1
  11. package/dist/cloudflare/sentinel.js +37 -2
  12. package/dist/cloudflare/worker.d.ts +391 -63
  13. package/dist/cloudflare/worker.d.ts.map +1 -1
  14. package/dist/cloudflare/worker.js +394 -108
  15. package/dist/dev/index.d.ts +1 -1
  16. package/dist/dev/index.d.ts.map +1 -1
  17. package/dist/dev/index.js +1 -1
  18. package/dist/dev/keypair.d.ts +2 -0
  19. package/dist/dev/keypair.d.ts.map +1 -1
  20. package/dist/dev/keypair.js +2 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +5 -0
  24. package/dist/internal/aiDefault.d.ts +205 -0
  25. package/dist/internal/aiDefault.d.ts.map +1 -0
  26. package/dist/internal/aiDefault.js +335 -0
  27. package/dist/internal/aiProviders.d.ts +7 -2
  28. package/dist/internal/aiProviders.d.ts.map +1 -1
  29. package/dist/internal/aiProviders.js +19 -6
  30. package/dist/internal/appSettings.d.ts +82 -4
  31. package/dist/internal/appSettings.d.ts.map +1 -1
  32. package/dist/internal/appSettings.js +204 -29
  33. package/dist/internal/audit.d.ts +108 -0
  34. package/dist/internal/audit.d.ts.map +1 -0
  35. package/dist/internal/audit.js +235 -0
  36. package/dist/internal/capabilities.d.ts +2261 -815
  37. package/dist/internal/capabilities.d.ts.map +1 -1
  38. package/dist/internal/capabilities.js +122 -1034
  39. package/dist/internal/catalog/commerce.d.ts +394 -0
  40. package/dist/internal/catalog/commerce.d.ts.map +1 -0
  41. package/dist/internal/catalog/commerce.js +477 -0
  42. package/dist/internal/catalog/comms.d.ts +375 -0
  43. package/dist/internal/catalog/comms.d.ts.map +1 -0
  44. package/dist/internal/catalog/comms.js +520 -0
  45. package/dist/internal/catalog/index.d.ts +2008 -0
  46. package/dist/internal/catalog/index.d.ts.map +1 -0
  47. package/dist/internal/catalog/index.js +19 -0
  48. package/dist/internal/catalog/inference.d.ts +393 -0
  49. package/dist/internal/catalog/inference.d.ts.map +1 -0
  50. package/dist/internal/catalog/inference.js +460 -0
  51. package/dist/internal/catalog/infra.d.ts +458 -0
  52. package/dist/internal/catalog/infra.d.ts.map +1 -0
  53. package/dist/internal/catalog/infra.js +608 -0
  54. package/dist/internal/catalog/search.d.ts +400 -0
  55. package/dist/internal/catalog/search.d.ts.map +1 -0
  56. package/dist/internal/catalog/search.js +463 -0
  57. package/dist/internal/devProviders.d.ts +2 -2
  58. package/dist/internal/devProviders.d.ts.map +1 -1
  59. package/dist/internal/devProviders.js +19 -1
  60. package/dist/internal/events.d.ts +65 -3
  61. package/dist/internal/events.d.ts.map +1 -1
  62. package/dist/internal/events.js +110 -5
  63. package/dist/internal/gatewaySettings.d.ts +3 -2
  64. package/dist/internal/gatewaySettings.d.ts.map +1 -1
  65. package/dist/internal/gatewaySettings.js +12 -6
  66. package/dist/internal/identity.d.ts +41 -4
  67. package/dist/internal/identity.d.ts.map +1 -1
  68. package/dist/internal/identity.js +48 -10
  69. package/dist/internal/index.d.ts +6 -1
  70. package/dist/internal/index.d.ts.map +1 -1
  71. package/dist/internal/index.js +6 -1
  72. package/dist/internal/members.d.ts +3 -2
  73. package/dist/internal/members.d.ts.map +1 -1
  74. package/dist/internal/oauthBuiltIns.d.ts +101 -0
  75. package/dist/internal/oauthBuiltIns.d.ts.map +1 -0
  76. package/dist/internal/oauthBuiltIns.js +122 -0
  77. package/dist/internal/oauthClient.d.ts +8 -50
  78. package/dist/internal/oauthClient.d.ts.map +1 -1
  79. package/dist/internal/oauthClient.js +2 -177
  80. package/dist/internal/oauthPresets.d.ts +32 -0
  81. package/dist/internal/oauthPresets.d.ts.map +1 -0
  82. package/dist/internal/oauthPresets.js +253 -0
  83. package/dist/internal/oauthScopes.d.ts +43 -100
  84. package/dist/internal/oauthScopes.d.ts.map +1 -1
  85. package/dist/internal/oauthScopes.js +83 -382
  86. package/dist/internal/oauthSpec.d.ts +103 -0
  87. package/dist/internal/oauthSpec.d.ts.map +1 -0
  88. package/dist/internal/oauthSpec.js +520 -0
  89. package/dist/internal/protocol.d.ts +97 -5
  90. package/dist/internal/protocol.d.ts.map +1 -1
  91. package/dist/internal/protocol.js +89 -1
  92. package/dist/internal/providerRegistry.d.ts +17 -6
  93. package/dist/internal/providerRegistry.d.ts.map +1 -1
  94. package/dist/internal/providerRegistry.js +71 -8
  95. package/dist/internal/providerSpec.d.ts +18 -7
  96. package/dist/internal/providerSpec.d.ts.map +1 -1
  97. package/dist/internal/providerSpec.js +420 -34
  98. package/dist/internal/remoteMcp.d.ts.map +1 -1
  99. package/dist/internal/remoteMcp.js +1 -5
  100. package/dist/internal/signInProviders.d.ts +104 -0
  101. package/dist/internal/signInProviders.d.ts.map +1 -0
  102. package/dist/internal/signInProviders.js +245 -0
  103. package/dist/internal/tools.d.ts +5 -4
  104. package/dist/internal/tools.d.ts.map +1 -1
  105. package/dist/internal/tools.js +4 -3
  106. package/dist/manifest.d.ts +267 -0
  107. package/dist/manifest.d.ts.map +1 -0
  108. package/dist/manifest.js +30 -0
  109. package/dist/server/ai.d.ts +111 -0
  110. package/dist/server/ai.d.ts.map +1 -0
  111. package/dist/server/ai.js +145 -0
  112. package/dist/server/aiBinding.d.ts +68 -0
  113. package/dist/server/aiBinding.d.ts.map +1 -0
  114. package/dist/server/aiBinding.js +294 -0
  115. package/dist/server/attribution.d.ts +18 -5
  116. package/dist/server/attribution.d.ts.map +1 -1
  117. package/dist/server/attribution.js +19 -5
  118. package/dist/server/connectUrl.d.ts +16 -0
  119. package/dist/server/connectUrl.d.ts.map +1 -0
  120. package/dist/server/connectUrl.js +40 -0
  121. package/dist/server/context.d.ts +68 -0
  122. package/dist/server/context.d.ts.map +1 -0
  123. package/dist/server/context.js +117 -0
  124. package/dist/server/emailBinding.d.ts +72 -0
  125. package/dist/server/emailBinding.d.ts.map +1 -0
  126. package/dist/server/emailBinding.js +124 -0
  127. package/dist/server/emit.d.ts +1 -1
  128. package/dist/server/emit.d.ts.map +1 -1
  129. package/dist/server/emit.js +7 -7
  130. package/dist/server/env.d.ts +44 -0
  131. package/dist/server/env.d.ts.map +1 -0
  132. package/dist/server/env.js +1 -0
  133. package/dist/server/eventsEndpoint.d.ts +48 -0
  134. package/dist/server/eventsEndpoint.d.ts.map +1 -0
  135. package/dist/server/eventsEndpoint.js +145 -0
  136. package/dist/server/everyApp.d.ts +40 -11
  137. package/dist/server/everyApp.d.ts.map +1 -1
  138. package/dist/server/everyApp.js +116 -6
  139. package/dist/server/fromMcpTools.d.ts +89 -0
  140. package/dist/server/fromMcpTools.d.ts.map +1 -0
  141. package/dist/server/fromMcpTools.js +192 -0
  142. package/dist/server/gatewayFetch.d.ts +42 -18
  143. package/dist/server/gatewayFetch.d.ts.map +1 -1
  144. package/dist/server/gatewayFetch.js +138 -19
  145. package/dist/server/gatewayUrl.d.ts +13 -0
  146. package/dist/server/gatewayUrl.d.ts.map +1 -0
  147. package/dist/server/gatewayUrl.js +34 -0
  148. package/dist/server/index.d.ts +16 -4
  149. package/dist/server/index.d.ts.map +1 -1
  150. package/dist/server/index.js +13 -3
  151. package/dist/server/integrationFetch.d.ts +92 -73
  152. package/dist/server/integrationFetch.d.ts.map +1 -1
  153. package/dist/server/integrationFetch.js +206 -319
  154. package/dist/server/listMembers.d.ts +1 -1
  155. package/dist/server/listMembers.d.ts.map +1 -1
  156. package/dist/server/listMembers.js +8 -11
  157. package/dist/server/refusal.d.ts +55 -0
  158. package/dist/server/refusal.d.ts.map +1 -0
  159. package/dist/server/refusal.js +193 -0
  160. package/dist/server/sendEmail.d.ts +1 -1
  161. package/dist/server/sendEmail.d.ts.map +1 -1
  162. package/dist/server/sendEmail.js +7 -7
  163. package/dist/server/tools.d.ts +7 -2
  164. package/dist/server/tools.d.ts.map +1 -1
  165. package/dist/server/tools.js +2 -1
  166. package/dist/server/toolsEndpoint.d.ts +3 -1
  167. package/dist/server/toolsEndpoint.d.ts.map +1 -1
  168. package/dist/server/toolsEndpoint.js +19 -7
  169. package/dist/server/webhooks.d.ts +56 -0
  170. package/dist/server/webhooks.d.ts.map +1 -0
  171. package/dist/server/webhooks.js +205 -0
  172. package/dist/tanstack-start/index.d.ts +9 -0
  173. package/dist/tanstack-start/index.d.ts.map +1 -0
  174. package/dist/tanstack-start/index.js +29 -0
  175. package/dist/testing/index.d.ts +93 -0
  176. package/dist/testing/index.d.ts.map +1 -0
  177. package/dist/testing/index.js +156 -0
  178. package/package.json +35 -14
  179. package/dist/server/authorizeUrl.d.ts +0 -43
  180. package/dist/server/authorizeUrl.d.ts.map +0 -1
  181. package/dist/server/authorizeUrl.js +0 -110
@@ -1,24 +1,66 @@
1
- import { aiProviderSettings, authorizationOf, ConfigurationError, DEV_AI_PROVIDERS, devAiProvider, joinProviderUrl, } from "../internal/index.js";
2
- import { applyAttribution, checkAttribution, } from "./attribution.js";
1
+ import { AI_DEFAULT_MODEL, AI_DEFAULT_PROVIDER, AI_DEFAULT_ROUTES, aiProviderSettings, authorizationOf, ConfigurationError, DEV_AI_PROVIDERS, DEV_ENV, devAiProvider, joinProviderUrl, LINKED_DEV_HEADER, LINKED_DEV_NONCE_ENV, LINKED_DEV_URL_ENV, resolveAiDefault, } from "../internal/index.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
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.
6
+ * The Gateway the SDK's services call: the `EVERY_APP_GATEWAY` service
7
+ * binding when deployed; under `everyapp dev --gateway` (linked dev,
8
+ * docs/design/linked-dev.md) a `{ fetch }` that sends the same requests to
9
+ * the gateway-lite's loopback forwarder, which adds the person's token and
10
+ * forwards them to the real Gateway's `/linked-dev/<app>` route. Undefined
11
+ * with neither (stub and mirror modes: the `.dev.vars` fallbacks). A value
12
+ * under the binding's name that isn't one is answered as before by each
13
+ * caller (`ConfigurationError`).
10
14
  */
11
- export function createGatewayFetch({ env, for: target, }) {
12
- checkAttribution(env, target, "createGatewayFetch");
13
- const binding = env.EVERY_APP_GATEWAY;
15
+ export function gatewayBinding(env) {
16
+ const values = env;
17
+ const binding = values["EVERY_APP_GATEWAY"];
18
+ if (binding)
19
+ return binding;
20
+ if (!values[DEV_ENV])
21
+ return undefined;
22
+ const url = values[LINKED_DEV_URL_ENV];
23
+ const nonce = values[LINKED_DEV_NONCE_ENV];
24
+ if (typeof url !== "string" || !url.trim() || typeof nonce !== "string") {
25
+ return undefined;
26
+ }
27
+ return linkedDevBinding(url.trim(), nonce);
28
+ }
29
+ /**
30
+ * The linked dev shim: a request to the binding's origin goes to the
31
+ * forwarder's URL with the same path and query, the run's nonce on it. The
32
+ * forwarder answers as the Gateway did, refusals included; nothing here
33
+ * falls back to a local key.
34
+ */
35
+ export function linkedDevBinding(forwarderUrl, nonce) {
36
+ const base = forwarderUrl.replace(/\/+$/, "");
37
+ return {
38
+ fetch(input, init) {
39
+ const outbound = new Request(input, init);
40
+ const url = new URL(outbound.url);
41
+ const headers = new Headers(outbound.headers);
42
+ headers.set(LINKED_DEV_HEADER, nonce);
43
+ return fetch(streamingRequest(`${base}${url.pathname}${url.search}`, outbound, headers));
44
+ },
45
+ };
46
+ }
47
+ export function createGatewayFetch({ env: workerEnv, for: explicitTarget, optional = false, }) {
48
+ const env = workerEnv;
49
+ // Checked now, so a call nobody's fails where the fetch is made; and
50
+ // again per call, where an identity may since have neared its expiry.
51
+ attributionFor(env, explicitTarget, "createGatewayFetch");
52
+ const binding = gatewayBinding(env);
14
53
  const devProviders = env.EVERYAPP_DEV ? localProviders(env) : {};
15
54
  if (binding && typeof binding.fetch !== "function") {
16
55
  throw new ConfigurationError("EVERY_APP_GATEWAY is configured but is not a valid service binding.");
17
56
  }
18
57
  if (!binding && Object.keys(devProviders).length === 0) {
19
- 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.`);
58
+ if (optional)
59
+ return null;
60
+ 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.`, { code: "ai_provider_not_configured" });
20
61
  }
21
62
  return async (input, init) => {
63
+ const target = attributionFor(env, explicitTarget, "createGatewayFetch");
22
64
  const outbound = new Request(input, init);
23
65
  const headers = new Headers(outbound.headers);
24
66
  headers.delete("authorization");
@@ -28,15 +70,24 @@ export function createGatewayFetch({ env, for: target, }) {
28
70
  const bindingRequest = streamingRequest(`${BINDING_ORIGIN}${url.pathname}${url.search}`, outbound, headers);
29
71
  return binding.fetch(bindingRequest);
30
72
  }
31
- const { provider, spec, path, search } = directProviderPath(outbound.url);
73
+ const direct = directProviderPath(outbound.url, env);
74
+ const { provider, spec, path, search } = direct;
32
75
  const dev = devProviders[provider];
33
76
  if (!dev) {
34
- throw new ConfigurationError(`Set ${settingsNames(spec)} in .dev.vars to call ${provider} in local development.`);
77
+ throw new ConfigurationError(`Set ${settingsNames(spec)} in .dev.vars to call ${provider} in local development.`, {
78
+ code: "ai_provider_not_configured",
79
+ settings: aiProviderSettings(spec),
80
+ });
35
81
  }
36
82
  const url = joinProviderUrl(`${spec.origin}${dev.basePath}`, path, search);
37
83
  if (!url)
38
84
  throw new ConfigurationError("Invalid provider proxy path.");
39
85
  applyAttribution(headers, undefined);
86
+ // The default route in dev: the model filled in as the gateway would.
87
+ let body = outbound;
88
+ if (direct.fillModel !== null) {
89
+ body = await withModel(outbound, direct.fillModel, headers);
90
+ }
40
91
  // The developer's key, put where the provider's entry says (a bearer
41
92
  // token for the three today), as the gateway would put its own.
42
93
  const auth = authorizationOf(spec.auth, { [spec.keyEnv]: dev.key });
@@ -46,11 +97,44 @@ export function createGatewayFetch({ env, for: target, }) {
46
97
  for (const [name, value] of Object.entries(auth?.query ?? {})) {
47
98
  url.searchParams.set(name, value);
48
99
  }
49
- const response = await fetch(streamingRequest(url.toString(), outbound, headers));
100
+ const response = await fetch(streamingRequest(url.toString(), body, headers));
50
101
  // What the gateway does to the provider's answer, so dev behaves alike.
51
102
  return spec.normalizeResponse?.(path, response) ?? response;
52
103
  };
53
104
  }
105
+ /**
106
+ * `source` with `model` put into its JSON body where the app named none
107
+ * or named `default`, as the gateway's default route does. A body that
108
+ * isn't a JSON object goes through as it is.
109
+ */
110
+ async function withModel(source, model, headers) {
111
+ if (!canIncludeBody(source.method) || !source.body)
112
+ return source;
113
+ const text = await source.clone().text();
114
+ let payload;
115
+ try {
116
+ payload = JSON.parse(text);
117
+ }
118
+ catch {
119
+ return source;
120
+ }
121
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
122
+ return source;
123
+ }
124
+ const record = payload;
125
+ if (record["model"] === undefined ||
126
+ record["model"] === null ||
127
+ record["model"] === AI_DEFAULT_MODEL) {
128
+ record["model"] = model;
129
+ }
130
+ headers.delete("content-length");
131
+ return new Request(source.url, {
132
+ method: source.method,
133
+ headers,
134
+ body: JSON.stringify(record),
135
+ signal: source.signal,
136
+ });
137
+ }
54
138
  /** A copy of `source` aimed at `url`, streaming its body rather than buffering it. */
55
139
  export function streamingRequest(url, source, headers) {
56
140
  const body = canIncludeBody(source.method) ? source.body : undefined;
@@ -82,19 +166,54 @@ function localProviders(env) {
82
166
  }
83
167
  return providers;
84
168
  }
85
- function directProviderPath(input) {
169
+ function directProviderPath(input, env) {
86
170
  const incoming = new URL(input);
87
171
  const match = incoming.pathname.match(/^\/api\/ai\/([a-z][a-z0-9-]*)(\/.*)?$/);
88
- const provider = match?.[1];
89
- const spec = provider ? devAiProvider(provider) : undefined;
172
+ let provider = match?.[1];
173
+ let path = match?.[2] || "/";
174
+ let fillModel = null;
175
+ if (provider === AI_DEFAULT_PROVIDER) {
176
+ // The default in dev, by the gateway's rule on the developer's own
177
+ // `.dev.vars`: the first provider of the order with every setting set,
178
+ // with its seed models (dev has no operator settings; a request that
179
+ // names a model sends it as it is).
180
+ const values = env;
181
+ const resolution = resolveAiDefault({
182
+ provider: null,
183
+ isSet: (name) => typeof values[name] === "string" &&
184
+ values[name].trim().length > 0,
185
+ });
186
+ if (!resolution.configured) {
187
+ throw new ConfigurationError(`Set ${resolution.settings.join(" and ")} (or another model provider's key) in .dev.vars to call the default model in local development.`, {
188
+ code: "ai_default_not_configured",
189
+ settings: resolution.settings,
190
+ });
191
+ }
192
+ const route = path === AI_DEFAULT_ROUTES.chat
193
+ ? resolution.chat
194
+ : path === AI_DEFAULT_ROUTES.embeddings
195
+ ? resolution.embeddings
196
+ : undefined;
197
+ if (!route) {
198
+ throw new ConfigurationError(`The default model serves ${AI_DEFAULT_ROUTES.chat} and ${AI_DEFAULT_ROUTES.embeddings} only; call /api/ai/<provider>/… for anything else.`);
199
+ }
200
+ provider = resolution.provider;
201
+ path = route.path;
202
+ fillModel =
203
+ route === resolution.chat
204
+ ? resolution.model
205
+ : (resolution.embeddingsModel ?? null);
206
+ }
207
+ const spec = provider
208
+ ? devAiProvider(provider, env)
209
+ : undefined;
90
210
  if (!provider || !spec) {
91
- throw new ConfigurationError(`Direct local provider fallback only supports ${listOf(Object.keys(DEV_AI_PROVIDERS).map((name) => `${AI_PROXY_PREFIX}${name}`), "and")} paths.`);
211
+ throw new ConfigurationError(`Direct local provider fallback only supports ${listOf([AI_DEFAULT_PROVIDER, ...Object.keys(DEV_AI_PROVIDERS)].map((name) => `${AI_PROXY_PREFIX}${name}`), "and")} paths.`);
92
212
  }
93
- const path = match?.[2] || "/";
94
213
  if (path.startsWith("//") || path.includes("\\")) {
95
214
  throw new ConfigurationError("Invalid provider proxy path.");
96
215
  }
97
- return { provider, spec, path, search: incoming.search };
216
+ return { provider, spec, path, search: incoming.search, fillModel };
98
217
  }
99
218
  /** A provider's settings as a person reads them: `KEY`, or `KEY and SETTING`. */
100
219
  function settingsNames(spec, conjunction = "and") {
@@ -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,16 +3,28 @@
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, isAgentCall, 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";
8
- export { authorizeUrl, type AuthorizeUrlOptions } from "./authorizeUrl.js";
9
- export { createGatewayFetch, type CreateGatewayFetchOptions, type GatewayFetchEnv, } from "./gatewayFetch.js";
10
- export { GatewayRefusalError, gatewayRefusal, integrationFetch, integrationStatus, type EmailIntegrationStatus, type GatewayRefusal, type IntegrationFetchOptions, type IntegrationStatus, type IntegrationStatusOf, type OAuthClientIntegrationStatus, } from "./integrationFetch.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";
13
+ export { connectPath, connectUrl, type ConnectUrlOptions, } from "./connectUrl.js";
14
+ export { createGatewayFetch, type CreateGatewayFetchOptions, } from "./gatewayFetch.js";
15
+ export { ai, aiBaseUrl, aiStatus, providerBaseUrl, AI_DEFAULT_BASE_URL, type AiClient, type AiStatus, } from "./ai.js";
16
+ export { AI_NOT_CONFIGURED_CODES, GatewayRefusalError, gatewayRefusal, isAiNotConfigured, refusalFromError, type GatewayRefusal, type SetupInfo, } from "./refusal.js";
17
+ export { devAccessTokenName, integrationFetch, integrationStatus, type EmailIntegrationStatus, type IntegrationFetchOptions, type IntegrationStatus, type IntegrationStatusOf, type OAuthClientIntegrationStatus, } from "./integrationFetch.js";
11
18
  export { nodeServerHandler, type NodeServer, type NodeServerHandlerOptions, } from "./nodeServer.js";
12
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";
13
22
  export { listMembers, type ListMembersOptions } from "./listMembers.js";
14
23
  export { emit, type EmitOptions } from "./emit.js";
24
+ export { WEBHOOK_MAX_BYTES_DEFAULT, verifyWebhook, type VerifyWebhookOptions, type WebhookProvider, type WebhookRefusalReason, type WebhookVerification, } from "./webhooks.js";
25
+ export type { AppEvent, AppEventHandler, AppEventsOptions, } from "./eventsEndpoint.js";
15
26
  export type { ApiKeyCapabilityId, CapabilityId, OAuthClientCapabilityId, EmailAddressInput, EmailAttachmentInput, SendEmailMessage, SendEmailResult, ListMembersResult, OrganizationMember, OrganizationMemberRole, EmitEventResult, } from "../internal/index.js";
16
27
  export { ToolError, defineTools, toolResult, type DefineToolsOptions, type PlainToolSchema, type StandardSchemaWithJSON, type ToolContext, type ToolDefinition, type ToolResult, type ToolSchema, type ToolSet, } from "./tools.js";
17
28
  export type { ToolRisk } from "../internal/index.js";
29
+ export { fromMcpTools, type FromMcpToolsOptions, type McpToolAnnotationsLike, type McpToolLike, type McpToolResultLike, type McpToolSchemaLike, } from "./fromMcpTools.js";
18
30
  //# 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,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,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,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,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,OAAO,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,WAAW,EACX,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,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AAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EACL,yBAAyB,EACzB,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,QAAQ,EACR,eAAe,EACf,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,uBAAuB,EACvB,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,13 +3,23 @@
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, isAgentCall, requireCurrentUser, requireEveryAppUser, } from "./everyApp.js";
7
+ export { OrganizationMismatchError, RequestContextError, currentUser, withOrganization, } from "./context.js";
7
8
  export { AttributionError } from "./attribution.js";
8
- export { authorizeUrl } from "./authorizeUrl.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";
12
+ export { connectPath, connectUrl, } from "./connectUrl.js";
9
13
  export { createGatewayFetch, } from "./gatewayFetch.js";
10
- export { GatewayRefusalError, gatewayRefusal, integrationFetch, integrationStatus, } from "./integrationFetch.js";
14
+ export { ai, aiBaseUrl, aiStatus, providerBaseUrl, AI_DEFAULT_BASE_URL, } from "./ai.js";
15
+ export { AI_NOT_CONFIGURED_CODES, GatewayRefusalError, gatewayRefusal, isAiNotConfigured, refusalFromError, } from "./refusal.js";
16
+ export { devAccessTokenName, integrationFetch, integrationStatus, } from "./integrationFetch.js";
11
17
  export { nodeServerHandler, } from "./nodeServer.js";
12
18
  export { sendEmail } from "./sendEmail.js";
19
+ export { gatewayAiBinding } from "./aiBinding.js";
20
+ export { gatewayEmailBinding, } from "./emailBinding.js";
13
21
  export { listMembers } from "./listMembers.js";
14
22
  export { emit } from "./emit.js";
23
+ export { WEBHOOK_MAX_BYTES_DEFAULT, verifyWebhook, } from "./webhooks.js";
15
24
  export { ToolError, defineTools, toolResult, } from "./tools.js";
25
+ export { fromMcpTools, } from "./fromMcpTools.js";
@@ -1,29 +1,49 @@
1
1
  import { type ApiKeyCapabilityId, type CapabilityId, type EmailCapabilityStatus, type OAuthClientCapabilityId } from "../internal/index.js";
2
2
  import { type GatewayCallFor } from "./attribution.js";
3
+ import type { SetupInfo } from "./refusal.js";
3
4
  export interface IntegrationFetchOptions {
4
5
  /**
5
6
  * The Worker env: the EVERY_APP_GATEWAY binding when deployed, or in local
6
7
  * dev EVERYAPP_DEV and the provider's key (e.g. DATAFORSEO_API_KEY in
7
- * `.dev.vars`).
8
+ * `.dev.vars`), or for an OAuth provider a token you obtained yourself
9
+ * (`GOOGLE_WORKSPACE_ACCESS_TOKEN`, {@link devAccessTokenName}).
8
10
  */
9
11
  env: object;
10
12
  /**
11
13
  * A provider the app lists in its manifest's `capabilities`: one whose
12
- * key the gateway holds, or one whose OAuth client it holds (its token
13
- * endpoints only). The built-in catalog's ids complete; a provider
14
- * registered on the gateway (`everyapp provider add`) is any other id,
15
- * reached through the binding, which checks it. The `email` capability
16
- * is sent with `sendEmail()` instead.
14
+ * key the gateway holds, or an OAuth provider whose connections it
15
+ * holds. The built-in catalog's ids complete; a provider registered on
16
+ * the gateway (`everyapp provider add`) is any other id, reached
17
+ * through the binding, which checks it. The `email` capability is sent
18
+ * with `sendEmail()` instead.
17
19
  */
18
20
  provider: ApiKeyCapabilityId | OAuthClientCapabilityId | (string & {});
19
21
  /**
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}).
22
+ * Whom the call is for. Left out, the request `everyApp()` is serving
23
+ * (its person, while the identity is good) or the organization
24
+ * `withOrganization()` named; outside both, `RequestContextError`.
25
+ * Explicitly: the inbound request, or `{ background: true,
26
+ * organizationId }` for work no person started (crons, Workflows,
27
+ * queues). A shared app's Worker must end up with one or the other
28
+ * ({@link AttributionError}).
29
+ *
30
+ * For an OAuth provider the call uses the connection the person behind
31
+ * it made in this app. `{ background: true, userId }` names another
32
+ * member's connection to this app instead, at any time, even while
33
+ * serving a different person: the call then carries that member and
34
+ * not the person being served. Only an organization's own app may.
25
35
  */
26
36
  for?: GatewayCallFor;
37
+ /**
38
+ * `true`: answer null instead of throwing `ConfigurationError` when the
39
+ * provider is unavailable (no binding, and in local dev not its
40
+ * settings in `.dev.vars`), so a feature that can do without it checks
41
+ * for null. A wrong provider id, a binding that isn't one, and an
42
+ * attribution mistake still throw. An OAuth provider is never
43
+ * unavailable this way: without a connection its calls answer
44
+ * `integration_not_connected`.
45
+ */
46
+ optional?: boolean;
27
47
  }
28
48
  /**
29
49
  * A `fetch` for one of the gateway's capabilities. Call the provider's real
@@ -33,22 +53,32 @@ export interface IntegrationFetchOptions {
33
53
  * sees the key. A refusal the gateway makes itself comes back as a response
34
54
  * {@link gatewayRefusal} recognizes; anything else is the provider's answer.
35
55
  *
36
- * For an OAuth client (`linkedin`, `mastodon`, ...) it reaches the
37
- * provider's token endpoints only, and the gateway puts its client on the
38
- * request: send the code (or refresh token) without `client_id` or
39
- * `client_secret`. Build the authorize URL with {@link authorizeUrl} from
40
- * {@link integrationStatus}, and call the provider's API with the user's
41
- * token directly.
56
+ * For an OAuth provider (`google-workspace`, `github`, ...) the gateway
57
+ * puts the token of the person's connection in this app on the call, to
58
+ * the provider's API hosts only. Without one the answer is a 409
59
+ * `integration_not_connected` refusal with the `connectPath` to send the
60
+ * person to ({@link connectUrl}).
42
61
  *
43
- * In local dev only, with no binding, the developer's own key or client
44
- * from `.dev.vars` reaches the provider directly, under the gateway's names:
62
+ * In local dev only, with no binding, the developer's own key from
63
+ * `.dev.vars` reaches the provider directly, under the gateway's names:
45
64
  * a catalog provider's from the catalog, a provider registered on the
46
65
  * gateway from its spec in `.everyapp/providers/<id>.json` (`everyapp
47
66
  * provider show <id> --save` writes it), put on the call as the gateway's
48
- * spec says.
67
+ * spec says. An OAuth provider's calls carry a token you obtained
68
+ * yourself ({@link devAccessTokenName}), to its API hosts only.
69
+ */
70
+ export declare function integrationFetch(options: IntegrationFetchOptions & {
71
+ optional: true;
72
+ }): typeof fetch | null;
73
+ export declare function integrationFetch(options: IntegrationFetchOptions): typeof fetch;
74
+ /**
75
+ * The `.dev.vars` name of a held token for `provider` in local dev
76
+ * (`GOOGLE_WORKSPACE_ACCESS_TOKEN`, `GITHUB_ACCESS_TOKEN`): a token the
77
+ * developer obtained themselves, standing in for the connection the
78
+ * gateway would hold. Dev-only: the gateway never reads it.
49
79
  */
50
- export declare function integrationFetch({ env, provider, for: target, }: IntegrationFetchOptions): typeof fetch;
51
- export interface IntegrationStatus {
80
+ export declare function devAccessTokenName(provider: string): string;
81
+ export interface IntegrationStatus extends SetupInfo {
52
82
  /** The app's manifest lists the capability. */
53
83
  requested: boolean;
54
84
  /** The gateway holds a key for it (in local dev: `.dev.vars` sets one). */
@@ -64,68 +94,57 @@ export interface IntegrationStatus {
64
94
  */
65
95
  export type EmailIntegrationStatus = IntegrationStatus & Pick<EmailCapabilityStatus, "sender" | "senders" | "provider">;
66
96
  /**
67
- * An OAuth client's status: as {@link IntegrationStatus}, plus what the app
68
- * needs to send people to the provider's authorize page, present only when
69
- * the app lists the capability and the gateway holds the client.
97
+ * An OAuth provider's status: as {@link IntegrationStatus}, plus the
98
+ * scopes the app's manifest lists, where the person connects in this app,
99
+ * and their connection to this app. `configured` means the gateway holds
100
+ * the client; `ready` that a call for this person would go through.
70
101
  */
71
- export interface OAuthClientIntegrationStatus extends IntegrationStatus {
72
- /** The client's public id, for the authorize URL (and Twitch's `Client-Id`). */
73
- clientId?: string;
102
+ export type OAuthClientIntegrationStatus = IntegrationStatus & {
103
+ /** The provider's scopes as the app's `everyapp.config.ts` lists them. */
104
+ scopes: readonly string[];
74
105
  /**
75
- * The provider's origin when the operator chose it (Mastodon's instance,
76
- * `MASTODON_URL`): the authorize page, token endpoint and API are on it.
106
+ * Where the person connects the provider in this app:
107
+ * `/connect/<id>?app=<app>` on the Gateway ({@link connectUrl} builds
108
+ * the absolute URL); null when the app can't connect (the manifest
109
+ * doesn't list it, or the gateway holds no client).
77
110
  */
78
- origin?: string;
111
+ connectPath: string | null;
79
112
  /**
80
- * For a client with scope sets (`google-workspace`, `microsoft-365`): the
81
- * set names the app's manifest entry declares, `[]` when the entry voids
82
- * its grant (no `scopes`, or a set this gateway doesn't offer), in which
83
- * case `ready` is false and no token call can complete.
113
+ * The connection the call would use (the person's in this app, or the
114
+ * member's `for: { background: true, userId }` names), or null when there
115
+ * is none. `ready` false with `missingScopes` when it lacks a scope the
116
+ * app now lists, and `reconnect` when the person has to connect again
117
+ * (missing scopes, or it expired).
84
118
  */
85
- scopeSets?: readonly string[];
86
- /**
87
- * The provider's scope strings those sets ask for, in the provider's
88
- * spelling and the registry's order, for the authorize URL
89
- * ({@link authorizeUrl} puts them on). The gateway refuses a token that
90
- * carries more.
91
- */
92
- scopes?: readonly string[];
93
- /** Slack's `user_scope` strings, when the sets name any. */
94
- userScopes?: readonly string[];
95
- }
96
- /** The status of a capability: email's carries its senders, an OAuth client's its id. */
119
+ connection: {
120
+ /** The account's name at the provider (an email address, a login). */
121
+ label: string | null;
122
+ /** The scopes it holds, canonical. */
123
+ scopes: readonly string[];
124
+ ready: boolean;
125
+ missingScopes?: readonly string[];
126
+ reconnect?: true;
127
+ } | null;
128
+ };
129
+ /** The status of a capability: email's carries its senders, an OAuth provider's the connection. */
97
130
  export type IntegrationStatusOf<P extends string> = P extends "email" ? EmailIntegrationStatus : P extends OAuthClientCapabilityId ? OAuthClientIntegrationStatus : IntegrationStatus;
98
131
  /**
99
132
  * Whether the app can use an integration right now, without calling the
100
133
  * provider: show "an admin needs to set up DataForSEO" (or "sending isn't
101
- * set up") up front instead of failing mid-task. An OAuth client's status
102
- * carries its public `clientId` for the authorize URL.
134
+ * set up", or "connect Google") up front instead of failing mid-task. An
135
+ * OAuth provider's status carries the person's connection in this app and
136
+ * where to connect.
103
137
  */
104
- export declare function integrationStatus<P extends CapabilityId | (string & {})>({ env, provider, }: {
138
+ export declare function integrationStatus<P extends CapabilityId | (string & {})>({ env, provider, for: explicitTarget, }: {
105
139
  env: object;
106
140
  provider: P;
141
+ /**
142
+ * Whom the status is for: the request being served (its person), so an
143
+ * OAuth provider's `connection` is that person's in this app; `{
144
+ * background: true, userId }` that member's. Explicitly the inbound
145
+ * request or `{ background: true, organizationId, userId? }`, as on
146
+ * every call.
147
+ */
148
+ for?: GatewayCallFor;
107
149
  }): Promise<IntegrationStatusOf<P>>;
108
- /** A refusal the AppGateway binding made itself, not the provider. */
109
- export interface GatewayRefusal {
110
- status: number;
111
- /** e.g. `capability_not_requested`, `integration_not_configured`. */
112
- code: string;
113
- message: string;
114
- }
115
- /**
116
- * A refusal the AppGateway binding made, thrown: what `sendEmail()` throws
117
- * when the gateway won't send (`email_sender_not_allowed`,
118
- * `email_budget_exhausted`, ...). The thrown twin of {@link gatewayRefusal}.
119
- */
120
- export declare class GatewayRefusalError extends Error implements GatewayRefusal {
121
- readonly status: number;
122
- readonly code: string;
123
- constructor({ status, code, message }: GatewayRefusal);
124
- }
125
- /**
126
- * The gateway's own refusal in `response`, or null when the response is the
127
- * provider's answer (which may be an error of its own). Reads the body only
128
- * for a refusal, so call it before reading the body yourself.
129
- */
130
- export declare function gatewayRefusal(response: Response): Promise<GatewayRefusal | null>;
131
150
  //# sourceMappingURL=integrationFetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"integrationFetch.d.ts","sourceRoot":"","sources":["../../src/server/integrationFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EA2BL,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAE1B,KAAK,uBAAuB,EAO7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAO1B,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;OAOG;IACH,QAAQ,EAAE,kBAAkB,GAAG,uBAAuB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IACvE;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,GAAG,EACH,QAAQ,EACR,GAAG,EAAE,MAAM,GACZ,EAAE,uBAAuB,GAAG,OAAO,KAAK,CAkGxC;AA+XD,MAAM,WAAW,iBAAiB;IAChC,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAC;IACnB,2EAA2E;IAC3E,UAAU,EAAE,OAAO,CAAC;IACpB,8BAA8B;IAC9B,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;;;GAKG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