@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.
- package/LICENSE +21 -0
- package/README.md +62 -64
- package/dist/cloudflare/catalogSettings.generated.d.ts +84 -0
- package/dist/cloudflare/catalogSettings.generated.d.ts.map +1 -0
- package/dist/cloudflare/catalogSettings.generated.js +175 -0
- package/dist/cloudflare/index.d.ts +3 -2
- package/dist/cloudflare/index.d.ts.map +1 -1
- package/dist/cloudflare/index.js +4 -1
- package/dist/cloudflare/sentinel.d.ts +60 -2
- package/dist/cloudflare/sentinel.d.ts.map +1 -1
- package/dist/cloudflare/sentinel.js +37 -2
- package/dist/cloudflare/worker.d.ts +391 -63
- package/dist/cloudflare/worker.d.ts.map +1 -1
- package/dist/cloudflare/worker.js +394 -108
- package/dist/dev/index.d.ts +1 -1
- package/dist/dev/index.d.ts.map +1 -1
- package/dist/dev/index.js +1 -1
- package/dist/dev/keypair.d.ts +2 -0
- package/dist/dev/keypair.d.ts.map +1 -1
- package/dist/dev/keypair.js +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/internal/aiDefault.d.ts +205 -0
- package/dist/internal/aiDefault.d.ts.map +1 -0
- package/dist/internal/aiDefault.js +335 -0
- package/dist/internal/aiProviders.d.ts +7 -2
- package/dist/internal/aiProviders.d.ts.map +1 -1
- package/dist/internal/aiProviders.js +19 -6
- package/dist/internal/appSettings.d.ts +82 -4
- package/dist/internal/appSettings.d.ts.map +1 -1
- package/dist/internal/appSettings.js +204 -29
- package/dist/internal/audit.d.ts +108 -0
- package/dist/internal/audit.d.ts.map +1 -0
- package/dist/internal/audit.js +235 -0
- package/dist/internal/capabilities.d.ts +2261 -815
- package/dist/internal/capabilities.d.ts.map +1 -1
- package/dist/internal/capabilities.js +122 -1034
- package/dist/internal/catalog/commerce.d.ts +394 -0
- package/dist/internal/catalog/commerce.d.ts.map +1 -0
- package/dist/internal/catalog/commerce.js +477 -0
- package/dist/internal/catalog/comms.d.ts +375 -0
- package/dist/internal/catalog/comms.d.ts.map +1 -0
- package/dist/internal/catalog/comms.js +520 -0
- package/dist/internal/catalog/index.d.ts +2008 -0
- package/dist/internal/catalog/index.d.ts.map +1 -0
- package/dist/internal/catalog/index.js +19 -0
- package/dist/internal/catalog/inference.d.ts +393 -0
- package/dist/internal/catalog/inference.d.ts.map +1 -0
- package/dist/internal/catalog/inference.js +460 -0
- package/dist/internal/catalog/infra.d.ts +458 -0
- package/dist/internal/catalog/infra.d.ts.map +1 -0
- package/dist/internal/catalog/infra.js +608 -0
- package/dist/internal/catalog/search.d.ts +400 -0
- package/dist/internal/catalog/search.d.ts.map +1 -0
- package/dist/internal/catalog/search.js +463 -0
- package/dist/internal/devProviders.d.ts +2 -2
- package/dist/internal/devProviders.d.ts.map +1 -1
- package/dist/internal/devProviders.js +19 -1
- package/dist/internal/events.d.ts +65 -3
- package/dist/internal/events.d.ts.map +1 -1
- package/dist/internal/events.js +110 -5
- package/dist/internal/gatewaySettings.d.ts +3 -2
- package/dist/internal/gatewaySettings.d.ts.map +1 -1
- package/dist/internal/gatewaySettings.js +12 -6
- package/dist/internal/identity.d.ts +41 -4
- package/dist/internal/identity.d.ts.map +1 -1
- package/dist/internal/identity.js +48 -10
- package/dist/internal/index.d.ts +6 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +6 -1
- package/dist/internal/members.d.ts +3 -2
- package/dist/internal/members.d.ts.map +1 -1
- package/dist/internal/oauthBuiltIns.d.ts +101 -0
- package/dist/internal/oauthBuiltIns.d.ts.map +1 -0
- package/dist/internal/oauthBuiltIns.js +122 -0
- package/dist/internal/oauthClient.d.ts +8 -50
- package/dist/internal/oauthClient.d.ts.map +1 -1
- package/dist/internal/oauthClient.js +2 -177
- package/dist/internal/oauthPresets.d.ts +32 -0
- package/dist/internal/oauthPresets.d.ts.map +1 -0
- package/dist/internal/oauthPresets.js +253 -0
- package/dist/internal/oauthScopes.d.ts +43 -100
- package/dist/internal/oauthScopes.d.ts.map +1 -1
- package/dist/internal/oauthScopes.js +83 -382
- package/dist/internal/oauthSpec.d.ts +103 -0
- package/dist/internal/oauthSpec.d.ts.map +1 -0
- package/dist/internal/oauthSpec.js +520 -0
- package/dist/internal/protocol.d.ts +97 -5
- package/dist/internal/protocol.d.ts.map +1 -1
- package/dist/internal/protocol.js +89 -1
- package/dist/internal/providerRegistry.d.ts +17 -6
- package/dist/internal/providerRegistry.d.ts.map +1 -1
- package/dist/internal/providerRegistry.js +71 -8
- package/dist/internal/providerSpec.d.ts +18 -7
- package/dist/internal/providerSpec.d.ts.map +1 -1
- package/dist/internal/providerSpec.js +420 -34
- package/dist/internal/remoteMcp.d.ts.map +1 -1
- package/dist/internal/remoteMcp.js +1 -5
- package/dist/internal/signInProviders.d.ts +104 -0
- package/dist/internal/signInProviders.d.ts.map +1 -0
- package/dist/internal/signInProviders.js +245 -0
- package/dist/internal/tools.d.ts +5 -4
- package/dist/internal/tools.d.ts.map +1 -1
- package/dist/internal/tools.js +4 -3
- package/dist/manifest.d.ts +267 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +30 -0
- package/dist/server/ai.d.ts +111 -0
- package/dist/server/ai.d.ts.map +1 -0
- package/dist/server/ai.js +145 -0
- package/dist/server/aiBinding.d.ts +68 -0
- package/dist/server/aiBinding.d.ts.map +1 -0
- package/dist/server/aiBinding.js +294 -0
- package/dist/server/attribution.d.ts +18 -5
- package/dist/server/attribution.d.ts.map +1 -1
- package/dist/server/attribution.js +19 -5
- package/dist/server/connectUrl.d.ts +16 -0
- package/dist/server/connectUrl.d.ts.map +1 -0
- package/dist/server/connectUrl.js +40 -0
- package/dist/server/context.d.ts +68 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +117 -0
- package/dist/server/emailBinding.d.ts +72 -0
- package/dist/server/emailBinding.d.ts.map +1 -0
- package/dist/server/emailBinding.js +124 -0
- package/dist/server/emit.d.ts +1 -1
- package/dist/server/emit.d.ts.map +1 -1
- package/dist/server/emit.js +7 -7
- package/dist/server/env.d.ts +44 -0
- package/dist/server/env.d.ts.map +1 -0
- package/dist/server/env.js +1 -0
- 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 +40 -11
- package/dist/server/everyApp.d.ts.map +1 -1
- package/dist/server/everyApp.js +116 -6
- package/dist/server/fromMcpTools.d.ts +89 -0
- package/dist/server/fromMcpTools.d.ts.map +1 -0
- package/dist/server/fromMcpTools.js +192 -0
- package/dist/server/gatewayFetch.d.ts +42 -18
- package/dist/server/gatewayFetch.d.ts.map +1 -1
- package/dist/server/gatewayFetch.js +138 -19
- package/dist/server/gatewayUrl.d.ts +13 -0
- package/dist/server/gatewayUrl.d.ts.map +1 -0
- package/dist/server/gatewayUrl.js +34 -0
- package/dist/server/index.d.ts +16 -4
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +13 -3
- package/dist/server/integrationFetch.d.ts +92 -73
- package/dist/server/integrationFetch.d.ts.map +1 -1
- package/dist/server/integrationFetch.js +206 -319
- package/dist/server/listMembers.d.ts +1 -1
- package/dist/server/listMembers.d.ts.map +1 -1
- package/dist/server/listMembers.js +8 -11
- package/dist/server/refusal.d.ts +55 -0
- package/dist/server/refusal.d.ts.map +1 -0
- package/dist/server/refusal.js +193 -0
- package/dist/server/sendEmail.d.ts +1 -1
- package/dist/server/sendEmail.d.ts.map +1 -1
- package/dist/server/sendEmail.js +7 -7
- package/dist/server/tools.d.ts +7 -2
- package/dist/server/tools.d.ts.map +1 -1
- package/dist/server/tools.js +2 -1
- package/dist/server/toolsEndpoint.d.ts +3 -1
- package/dist/server/toolsEndpoint.d.ts.map +1 -1
- package/dist/server/toolsEndpoint.js +19 -7
- 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/tanstack-start/index.d.ts +9 -0
- package/dist/tanstack-start/index.d.ts.map +1 -0
- package/dist/tanstack-start/index.js +29 -0
- package/dist/testing/index.d.ts +93 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +156 -0
- package/package.json +35 -14
- package/dist/server/authorizeUrl.d.ts +0 -43
- package/dist/server/authorizeUrl.d.ts.map +0 -1
- 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,
|
|
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
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
12
|
-
|
|
13
|
-
const binding =
|
|
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
|
-
|
|
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
|
|
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(),
|
|
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
|
-
|
|
89
|
-
|
|
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
|
+
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -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 {
|
|
9
|
-
export
|
|
10
|
-
|
|
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,
|
|
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,kBAAkB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,2FAA2F;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EACL,WAAW,EACX,UA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,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"}
|
package/dist/server/index.js
CHANGED
|
@@ -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 {
|
|
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 {
|
|
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
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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
|
|
21
|
-
*
|
|
22
|
-
* (
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* `
|
|
40
|
-
* {@link
|
|
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
|
|
44
|
-
*
|
|
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
|
|
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
|
|
68
|
-
*
|
|
69
|
-
*
|
|
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
|
|
72
|
-
/** The
|
|
73
|
-
|
|
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
|
-
*
|
|
76
|
-
*
|
|
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
|
-
|
|
111
|
+
connectPath: string | null;
|
|
79
112
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
102
|
-
* carries
|
|
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,
|
|
1
|
+
{"version":3,"file":"integrationFetch.d.ts","sourceRoot":"","sources":["../../src/server/integrationFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAcL,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAE1B,KAAK,uBAA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