@every-app/sdk 0.3.0-rc.8 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +75 -74
  2. package/dist/cloudflare/catalogSettings.generated.d.ts +20 -6
  3. package/dist/cloudflare/catalogSettings.generated.d.ts.map +1 -1
  4. package/dist/cloudflare/catalogSettings.generated.js +45 -14
  5. package/dist/cloudflare/index.d.ts +1 -1
  6. package/dist/cloudflare/index.d.ts.map +1 -1
  7. package/dist/cloudflare/sentinel.d.ts +3 -0
  8. package/dist/cloudflare/sentinel.d.ts.map +1 -1
  9. package/dist/cloudflare/sentinel.js +10 -0
  10. package/dist/cloudflare/worker.d.ts +67 -23
  11. package/dist/cloudflare/worker.d.ts.map +1 -1
  12. package/dist/cloudflare/worker.js +68 -32
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/internal/aiDefault.d.ts +36 -79
  16. package/dist/internal/aiDefault.d.ts.map +1 -1
  17. package/dist/internal/aiDefault.js +47 -149
  18. package/dist/internal/aiProviders.d.ts +1 -1
  19. package/dist/internal/aiProviders.d.ts.map +1 -1
  20. package/dist/internal/aiProviders.js +2 -2
  21. package/dist/internal/appSettings.d.ts +140 -89
  22. package/dist/internal/appSettings.d.ts.map +1 -1
  23. package/dist/internal/appSettings.js +264 -156
  24. package/dist/internal/capabilities.d.ts +145 -503
  25. package/dist/internal/capabilities.d.ts.map +1 -1
  26. package/dist/internal/capabilities.js +29 -550
  27. package/dist/internal/catalog/commerce.js +1 -1
  28. package/dist/internal/catalog/comms.d.ts +37 -0
  29. package/dist/internal/catalog/comms.d.ts.map +1 -1
  30. package/dist/internal/catalog/comms.js +43 -0
  31. package/dist/internal/catalog/index.d.ts +72 -0
  32. package/dist/internal/catalog/index.d.ts.map +1 -1
  33. package/dist/internal/catalog/infra.d.ts +35 -0
  34. package/dist/internal/catalog/infra.d.ts.map +1 -1
  35. package/dist/internal/catalog/infra.js +65 -0
  36. package/dist/internal/devProviders.d.ts +1 -19
  37. package/dist/internal/devProviders.d.ts.map +1 -1
  38. package/dist/internal/devProviders.js +7 -1
  39. package/dist/internal/events.d.ts +52 -1
  40. package/dist/internal/events.d.ts.map +1 -1
  41. package/dist/internal/events.js +66 -2
  42. package/dist/internal/gatewaySettings.d.ts +6 -16
  43. package/dist/internal/gatewaySettings.d.ts.map +1 -1
  44. package/dist/internal/gatewaySettings.js +6 -24
  45. package/dist/internal/index.d.ts +1 -0
  46. package/dist/internal/index.d.ts.map +1 -1
  47. package/dist/internal/index.js +1 -0
  48. package/dist/internal/mcpOAuth.d.ts +210 -0
  49. package/dist/internal/mcpOAuth.d.ts.map +1 -0
  50. package/dist/internal/mcpOAuth.js +735 -0
  51. package/dist/internal/oauthClient.d.ts +7 -47
  52. package/dist/internal/oauthClient.d.ts.map +1 -1
  53. package/dist/internal/oauthClient.js +1 -115
  54. package/dist/internal/oauthPresets.d.ts +356 -20
  55. package/dist/internal/oauthPresets.d.ts.map +1 -1
  56. package/dist/internal/oauthPresets.js +183 -861
  57. package/dist/internal/oauthScopes.d.ts +43 -155
  58. package/dist/internal/oauthScopes.d.ts.map +1 -1
  59. package/dist/internal/oauthScopes.js +82 -475
  60. package/dist/internal/oauthSpec.d.ts +28 -71
  61. package/dist/internal/oauthSpec.d.ts.map +1 -1
  62. package/dist/internal/oauthSpec.js +172 -448
  63. package/dist/internal/protocol.d.ts +39 -15
  64. package/dist/internal/protocol.d.ts.map +1 -1
  65. package/dist/internal/protocol.js +40 -7
  66. package/dist/internal/providerApps.d.ts +2 -2
  67. package/dist/internal/providerApps.js +2 -2
  68. package/dist/internal/providerRegistry.d.ts +5 -64
  69. package/dist/internal/providerRegistry.d.ts.map +1 -1
  70. package/dist/internal/providerRegistry.js +19 -118
  71. package/dist/internal/providerSpec.d.ts.map +1 -1
  72. package/dist/internal/providerSpec.js +14 -36
  73. package/dist/internal/remoteMcp.d.ts +191 -47
  74. package/dist/internal/remoteMcp.d.ts.map +1 -1
  75. package/dist/internal/remoteMcp.js +338 -133
  76. package/dist/internal/signInProviders.d.ts +1 -1
  77. package/dist/internal/signInProviders.d.ts.map +1 -1
  78. package/dist/internal/tools.d.ts +15 -8
  79. package/dist/internal/tools.d.ts.map +1 -1
  80. package/dist/internal/tools.js +9 -8
  81. package/dist/manifest.d.ts +96 -28
  82. package/dist/manifest.d.ts.map +1 -1
  83. package/dist/manifest.js +1 -1
  84. package/dist/server/ai.d.ts +1 -93
  85. package/dist/server/ai.d.ts.map +1 -1
  86. package/dist/server/ai.js +17 -111
  87. package/dist/server/attribution.d.ts +10 -1
  88. package/dist/server/attribution.d.ts.map +1 -1
  89. package/dist/server/attribution.js +7 -1
  90. package/dist/server/connectUrl.d.ts +4 -9
  91. package/dist/server/connectUrl.d.ts.map +1 -1
  92. package/dist/server/connectUrl.js +17 -14
  93. package/dist/server/context.d.ts +12 -14
  94. package/dist/server/context.d.ts.map +1 -1
  95. package/dist/server/context.js +23 -25
  96. package/dist/server/emit.d.ts.map +1 -1
  97. package/dist/server/emit.js +2 -2
  98. package/dist/server/env.d.ts +3 -0
  99. package/dist/server/env.d.ts.map +1 -1
  100. package/dist/server/eventsEndpoint.d.ts +48 -0
  101. package/dist/server/eventsEndpoint.d.ts.map +1 -0
  102. package/dist/server/eventsEndpoint.js +145 -0
  103. package/dist/server/everyApp.d.ts +16 -26
  104. package/dist/server/everyApp.d.ts.map +1 -1
  105. package/dist/server/everyApp.js +22 -46
  106. package/dist/server/gatewayFetch.d.ts +19 -1
  107. package/dist/server/gatewayFetch.d.ts.map +1 -1
  108. package/dist/server/gatewayFetch.js +45 -3
  109. package/dist/server/index.d.ts +6 -9
  110. package/dist/server/index.d.ts.map +1 -1
  111. package/dist/server/index.js +4 -8
  112. package/dist/server/integrationFetch.d.ts +60 -72
  113. package/dist/server/integrationFetch.d.ts.map +1 -1
  114. package/dist/server/integrationFetch.js +124 -397
  115. package/dist/server/listMembers.d.ts.map +1 -1
  116. package/dist/server/listMembers.js +2 -2
  117. package/dist/server/refusal.d.ts +0 -9
  118. package/dist/server/refusal.d.ts.map +1 -1
  119. package/dist/server/refusal.js +0 -22
  120. package/dist/server/sendEmail.d.ts.map +1 -1
  121. package/dist/server/sendEmail.js +2 -2
  122. package/dist/server/tools.d.ts +17 -6
  123. package/dist/server/tools.d.ts.map +1 -1
  124. package/dist/server/tools.js +14 -4
  125. package/dist/server/toolsEndpoint.d.ts +2 -1
  126. package/dist/server/toolsEndpoint.d.ts.map +1 -1
  127. package/dist/server/toolsEndpoint.js +4 -3
  128. package/dist/server/webhooks.d.ts +56 -0
  129. package/dist/server/webhooks.d.ts.map +1 -0
  130. package/dist/server/webhooks.js +205 -0
  131. package/dist/testing/index.d.ts +2 -3
  132. package/dist/testing/index.d.ts.map +1 -1
  133. package/dist/testing/index.js +2 -6
  134. package/package.json +6 -1
  135. package/dist/server/aiBinding.d.ts +0 -68
  136. package/dist/server/aiBinding.d.ts.map +0 -1
  137. package/dist/server/aiBinding.js +0 -294
  138. package/dist/server/authorizeUrl.d.ts +0 -43
  139. package/dist/server/authorizeUrl.d.ts.map +0 -1
  140. package/dist/server/authorizeUrl.js +0 -106
  141. package/dist/server/emailBinding.d.ts +0 -72
  142. package/dist/server/emailBinding.d.ts.map +0 -1
  143. package/dist/server/emailBinding.js +0 -124
  144. package/dist/server/fromMcpTools.d.ts +0 -89
  145. package/dist/server/fromMcpTools.d.ts.map +0 -1
  146. package/dist/server/fromMcpTools.js +0 -192
@@ -1 +1 @@
1
- {"version":3,"file":"everyApp.d.ts","sourceRoot":"","sources":["../../src/server/everyApp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAGL,kBAAkB,EAElB,aAAa,EAMb,OAAO,EACP,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,OAAO,EAEb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,OA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OAAO,EAC1B,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAW9B;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,OAAO,GAAG,OAAO,EAC1B,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,YAAY,CAAC,CAevB;AA0BD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED,wEAAwE;AACxE,wBAAgB,QAAQ,CACtB,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,IAAI,SAAS,oBAAoB,GAAG,gBAAgB,EAEpD,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,EACpC,OAAO,GAAE,eAAe,CAAC,IAAI,CAAM,GAClC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CA2D5B"}
@@ -13,12 +13,12 @@
13
13
  * `everyapp.config.ts` (the Cloudflare Vite plugin hides every file
14
14
  * `cloudflare.config.ts` imports from the Worker in dev).
15
15
  * It also answers the gateway's internal tools contract
16
- * (`/__everyapp/tools/*`) for the app's `defineTools()` catalog.
16
+ * (`/__everyapp/tools/*`) for the app's `defineTools()` catalog, and the
17
+ * event sink's deliveries (`/__everyapp/events`) for `events: { on }`.
17
18
  *
18
19
  * Around the handler and around each tool call it opens the request
19
- * context (context.ts): `currentUser()` reads the user anywhere below, and
20
- * every call back to the Gateway is attributed to the request without a
21
- * `for`. A deployed Worker is pinned to its organization
20
+ * context (context.ts): every call back to the Gateway is attributed to
21
+ * the request without a `for`. A deployed Worker is pinned to its organization
22
22
  * (`EVERY_APP_ORG_ID`), and an identity for any other is refused on both
23
23
  * paths. The response leaves without `Set-Cookie`: the perimeter strips
24
24
  * every `Cookie` before a request reaches the app, so a cookie the app's
@@ -28,7 +28,8 @@
28
28
  import { APP_ID_ENV, AUDIENCE_ENV, ConfigurationError, DEV_ENV, IdentityError, IDENTITY_HEADER, ISSUER_ENV, ORG_ID_ENV, PUBLIC_KEYS_ENV, getIdentityFromRequest, isAdmin, } from "../internal/index.js";
29
29
  import { currentUser, serveRequest } from "./context.js";
30
30
  import { handleToolsRequest } from "./toolsEndpoint.js";
31
- export { ConfigurationError, IdentityError, isAdmin };
31
+ import { handleEventsRequest, } from "./eventsEndpoint.js";
32
+ export { ConfigurationError, isAdmin };
32
33
  const requestIdentities = new WeakMap();
33
34
  function envValue(env, key) {
34
35
  if (!env || typeof env !== "object")
@@ -36,9 +37,8 @@ function envValue(env, key) {
36
37
  const value = env[key];
37
38
  return typeof value === "string" && value.length > 0 ? value : undefined;
38
39
  }
39
- function configFrom(manifest, options = {}) {
40
+ function configFrom(options) {
40
41
  return {
41
- manifestAppId: manifest?.id,
42
42
  issuer: options.issuer,
43
43
  keysEnvVar: options.keysEnvVar ?? PUBLIC_KEYS_ENV,
44
44
  publicKeys: options.publicKeys,
@@ -46,16 +46,9 @@ function configFrom(manifest, options = {}) {
46
46
  now: options.now,
47
47
  };
48
48
  }
49
- /**
50
- * The app id: EVERYAPP_APP_ID, or a manifest passed to everyApp() for
51
- * Workers without it; the two must agree when both are present.
52
- */
53
- function appIdFor(env, config) {
54
- const fromEnv = envValue(env, APP_ID_ENV);
55
- if (fromEnv && config.manifestAppId && fromEnv !== config.manifestAppId) {
56
- throw new ConfigurationError(`${APP_ID_ENV} ("${fromEnv}") does not match the manifest id ("${config.manifestAppId}").`);
57
- }
58
- return fromEnv ?? config.manifestAppId;
49
+ /** The app id, from EVERYAPP_APP_ID (which `everyAppWorker()` sets). */
50
+ function appIdFor(env) {
51
+ return envValue(env, APP_ID_ENV);
59
52
  }
60
53
  function devIdentitiesAllowed(env, config) {
61
54
  const devEnv = envValue(env, DEV_ENV);
@@ -71,7 +64,7 @@ function devIdentitiesAllowed(env, config) {
71
64
  * app id stand in when EVERYAPP_AUDIENCE is unset.
72
65
  */
73
66
  function audienceFor(env, config) {
74
- const appId = appIdFor(env, config);
67
+ const appId = appIdFor(env);
75
68
  const audience = envValue(env, AUDIENCE_ENV);
76
69
  if (audience)
77
70
  return audience;
@@ -153,7 +146,6 @@ const servedRequests = new WeakMap();
153
146
  * (a framework that hands out headers alone needs no made-up Request).
154
147
  * Answers from the request context or the per-request cache first, then
155
148
  * verifies the identity headers from the audience and public keys in env.
156
- * Inside a handler `everyApp()` serves, `currentUser()` is the shorter way.
157
149
  */
158
150
  export async function getEveryAppUser(request, env) {
159
151
  const cached = requestIdentities.get(request);
@@ -187,19 +179,6 @@ export async function requireEveryAppUser(request, env) {
187
179
  throw error;
188
180
  }
189
181
  }
190
- /**
191
- * The user of the request being served (`currentUser()`), or throw the
192
- * same 401 JSON Response as `requireEveryAppUser()` on a public route.
193
- * Outside a request (`withOrganization()` work, a handler not under
194
- * `everyApp()`) it throws `RequestContextError`, as `currentUser()` does.
195
- */
196
- export function requireCurrentUser() {
197
- const user = currentUser();
198
- if (!user) {
199
- throw unauthorized("this request does not have an authenticated user");
200
- }
201
- return user;
202
- }
203
182
  /**
204
183
  * `response` without `Set-Cookie`: the perimeter strips every `Cookie`
205
184
  * before a request reaches the app, so no cookie the app sets ever comes
@@ -224,26 +203,16 @@ function withoutCookies(response) {
224
203
  export function hasScope(user, scope) {
225
204
  return user.scopes.includes("*") || user.scopes.includes(scope);
226
205
  }
227
- function isManifest(value) {
228
- return (typeof value === "object" &&
229
- value !== null &&
230
- typeof value.id === "string");
231
- }
232
- export function everyApp(handler, manifestOrOptions, legacyOptions = {}) {
233
- const manifest = isManifest(manifestOrOptions)
234
- ? manifestOrOptions
235
- : undefined;
236
- const options = manifest || manifestOrOptions === undefined
237
- ? legacyOptions
238
- : manifestOrOptions;
239
- const config = configFrom(manifest, options);
206
+ /** Wrap a Worker fetch handler with Every App identity verification. */
207
+ export function everyApp(handler, options = {}) {
208
+ const config = configFrom(options);
240
209
  return {
241
210
  async fetch(request, env, ctx) {
242
211
  let audience;
243
212
  let appId;
244
213
  try {
245
214
  audience = audienceFor(env, config);
246
- appId = appIdFor(env, config) ?? audience;
215
+ appId = appIdFor(env) ?? audience;
247
216
  }
248
217
  catch (err) {
249
218
  if (err instanceof ConfigurationError) {
@@ -261,6 +230,13 @@ export function everyApp(handler, manifestOrOptions, legacyOptions = {}) {
261
230
  });
262
231
  if (toolsResponse)
263
232
  return toolsResponse;
233
+ // So does the event sink's delivery path (`/__everyapp/events`).
234
+ const eventsResponse = await handleEventsRequest(request, env, ctx, {
235
+ events: options.events,
236
+ identity: identityOptions(env, config, audience),
237
+ });
238
+ if (eventsResponse)
239
+ return eventsResponse;
264
240
  let identity;
265
241
  try {
266
242
  identity = await getIdentityFromRequest(request, identityOptions(env, config, audience));
@@ -3,6 +3,24 @@ 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
+ /**
7
+ * The Gateway the SDK's services call: the `EVERY_APP_GATEWAY` service
8
+ * binding when deployed; under `everyapp dev --gateway` (linked dev,
9
+ * docs/design/linked-dev.md) a `{ fetch }` that sends the same requests to
10
+ * the gateway-lite's loopback forwarder, which adds the person's token and
11
+ * forwards them to the real Gateway's `/linked-dev/<app>` route. Undefined
12
+ * with neither (stub and mirror modes: the `.dev.vars` fallbacks). A value
13
+ * under the binding's name that isn't one is answered as before by each
14
+ * caller (`ConfigurationError`).
15
+ */
16
+ export declare function gatewayBinding(env: object): GatewayServiceBinding | undefined;
17
+ /**
18
+ * The linked dev shim: a request to the binding's origin goes to the
19
+ * forwarder's URL with the same path and query, the run's nonce on it. The
20
+ * forwarder answers as the Gateway did, refusals included; nothing here
21
+ * falls back to a local key.
22
+ */
23
+ export declare function linkedDevBinding(forwarderUrl: string, nonce: string): GatewayServiceBinding;
6
24
  export interface CreateGatewayFetchOptions {
7
25
  /**
8
26
  * The Worker env, as it is: the EVERY_APP_GATEWAY binding when deployed,
@@ -13,7 +31,7 @@ export interface CreateGatewayFetchOptions {
13
31
  /**
14
32
  * Whom the call is for. Left out, the request `everyApp()` is serving
15
33
  * (its user, while the identity is good) or the organization
16
- * `withOrganization()` named; outside both, `RequestContextError`.
34
+ * an event delivery runs under; outside both, `RequestContextError`.
17
35
  * Explicitly: the inbound request, or `{ background: true,
18
36
  * organizationId }` for work no person started (crons, Workflows,
19
37
  * queues). A shared app's Worker must end up with one or the other
@@ -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,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;AA2HhB,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":"AAiBA,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;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAW7E;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,GACZ,qBAAqB,CAiBvB;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;AA2HhB,sFAAsF;AACtF,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,OAAO,GACf,OAAO,CAUT"}
@@ -1,13 +1,55 @@
1
- import { AI_DEFAULT_MODEL, AI_DEFAULT_PROVIDER, AI_DEFAULT_ROUTES, aiProviderSettings, authorizationOf, ConfigurationError, DEV_AI_PROVIDERS, devAiProvider, joinProviderUrl, resolveAiDefault, } from "../internal/index.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
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
+ * 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`).
14
+ */
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
+ }
5
47
  export function createGatewayFetch({ env: workerEnv, for: explicitTarget, optional = false, }) {
6
48
  const env = workerEnv;
7
49
  // Checked now, so a call nobody's fails where the fetch is made; and
8
50
  // again per call, where an identity may since have neared its expiry.
9
51
  attributionFor(env, explicitTarget, "createGatewayFetch");
10
- const binding = env.EVERY_APP_GATEWAY;
52
+ const binding = gatewayBinding(env);
11
53
  const devProviders = env.EVERYAPP_DEV ? localProviders(env) : {};
12
54
  if (binding && typeof binding.fetch !== "function") {
13
55
  throw new ConfigurationError("EVERY_APP_GATEWAY is configured but is not a valid service binding.");
@@ -137,7 +179,7 @@ function directProviderPath(input, env) {
137
179
  // names a model sends it as it is).
138
180
  const values = env;
139
181
  const resolution = resolveAiDefault({
140
- provider: null,
182
+ choice: null,
141
183
  isSet: (name) => typeof values[name] === "string" &&
142
184
  values[name].trim().length > 0,
143
185
  });
@@ -3,27 +3,24 @@
3
3
  *
4
4
  * There is intentionally no client-side export.
5
5
  */
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";
6
+ export { ConfigurationError, everyApp, getEveryAppUser, hasScope, isAdmin, requireEveryAppUser, type EveryAppOptions, type EveryAppHandler, type EveryAppUser, type IdentityResult, type OrgRole, } from "./everyApp.js";
8
7
  export { AttributionError, type GatewayCallFor } from "./attribution.js";
9
8
  export { gatewayUrl } from "./gatewayUrl.js";
10
9
  export type { EveryAppEnv } from "./env.js";
11
10
  /** The header a Gateway refusal carries its code in; `gatewayRefusal()` reads the rest. */
12
11
  export { GATEWAY_ERROR_HEADER } from "../internal/protocol.js";
13
- export { authorizeUrl, type AuthorizeUrlOptions } from "./authorizeUrl.js";
14
12
  export { connectPath, connectUrl, type ConnectUrlOptions, } from "./connectUrl.js";
15
13
  export { createGatewayFetch, type CreateGatewayFetchOptions, } from "./gatewayFetch.js";
16
- export { ai, aiBaseUrl, aiStatus, providerBaseUrl, AI_DEFAULT_BASE_URL, type AiClient, type AiStatus, } from "./ai.js";
17
- export { AI_NOT_CONFIGURED_CODES, GatewayRefusalError, gatewayRefusal, isAiNotConfigured, refusalFromError, type GatewayRefusal, type SetupInfo, } from "./refusal.js";
14
+ export { aiBaseUrl, providerBaseUrl } from "./ai.js";
15
+ export { GatewayRefusalError, gatewayRefusal, refusalFromError, type GatewayRefusal, type SetupInfo, } from "./refusal.js";
18
16
  export { devAccessTokenName, integrationFetch, integrationStatus, type EmailIntegrationStatus, type IntegrationFetchOptions, type IntegrationStatus, type IntegrationStatusOf, type OAuthClientIntegrationStatus, } from "./integrationFetch.js";
19
17
  export { nodeServerHandler, type NodeServer, type NodeServerHandlerOptions, } from "./nodeServer.js";
20
18
  export { sendEmail, type SendEmailOptions } from "./sendEmail.js";
21
- export { gatewayAiBinding, type GatewayAiBindingOptions } from "./aiBinding.js";
22
- export { gatewayEmailBinding, type GatewayEmailBindingMessage, type GatewayEmailBindingOptions, } from "./emailBinding.js";
23
19
  export { listMembers, type ListMembersOptions } from "./listMembers.js";
24
20
  export { emit, type EmitOptions } from "./emit.js";
25
- export type { ApiKeyCapabilityId, CapabilityId, OAuthClientCapabilityId, ConnectionAccount, EmailAddressInput, EmailAttachmentInput, SendEmailMessage, SendEmailResult, ListMembersResult, OrganizationMember, OrganizationMemberRole, EmitEventResult, } from "../internal/index.js";
21
+ export { WEBHOOK_MAX_BYTES_DEFAULT, verifyWebhook, type VerifyWebhookOptions, type WebhookProvider, type WebhookRefusalReason, type WebhookVerification, } from "./webhooks.js";
22
+ export type { AppEvent, AppEventHandler, AppEventsOptions, } from "./eventsEndpoint.js";
23
+ export type { ApiKeyCapabilityId, CapabilityId, OAuthPresetId, EmailAddressInput, EmailAttachmentInput, SendEmailMessage, SendEmailResult, ListMembersResult, OrganizationMember, OrganizationMemberRole, EmitEventResult, } from "../internal/index.js";
26
24
  export { ToolError, defineTools, toolResult, type DefineToolsOptions, type PlainToolSchema, type StandardSchemaWithJSON, type ToolContext, type ToolDefinition, type ToolResult, type ToolSchema, type ToolSet, } from "./tools.js";
27
25
  export type { ToolRisk } from "../internal/index.js";
28
- export { fromMcpTools, type FromMcpToolsOptions, type McpToolAnnotationsLike, type McpToolLike, type McpToolResultLike, type McpToolSchemaLike, } from "./fromMcpTools.js";
29
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,OAAO,EACP,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,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,GAC/B,MAAM,mBAAmB,CAAC;AAC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AC3B,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,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,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,SAAS,EACT,WAAW,EACX,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC"}
@@ -3,23 +3,19 @@
3
3
  *
4
4
  * There is intentionally no client-side export.
5
5
  */
6
- export { ConfigurationError, IdentityError, everyApp, getEveryAppUser, hasScope, isAdmin, requireCurrentUser, requireEveryAppUser, } from "./everyApp.js";
7
- export { OrganizationMismatchError, RequestContextError, currentUser, withOrganization, } from "./context.js";
6
+ export { ConfigurationError, everyApp, getEveryAppUser, hasScope, isAdmin, requireEveryAppUser, } from "./everyApp.js";
8
7
  export { AttributionError } from "./attribution.js";
9
8
  export { gatewayUrl } from "./gatewayUrl.js";
10
9
  /** The header a Gateway refusal carries its code in; `gatewayRefusal()` reads the rest. */
11
10
  export { GATEWAY_ERROR_HEADER } from "../internal/protocol.js";
12
- export { authorizeUrl } from "./authorizeUrl.js";
13
11
  export { connectPath, connectUrl, } from "./connectUrl.js";
14
12
  export { createGatewayFetch, } from "./gatewayFetch.js";
15
- export { ai, aiBaseUrl, aiStatus, providerBaseUrl, AI_DEFAULT_BASE_URL, } from "./ai.js";
16
- export { AI_NOT_CONFIGURED_CODES, GatewayRefusalError, gatewayRefusal, isAiNotConfigured, refusalFromError, } from "./refusal.js";
13
+ export { aiBaseUrl, providerBaseUrl } from "./ai.js";
14
+ export { GatewayRefusalError, gatewayRefusal, refusalFromError, } from "./refusal.js";
17
15
  export { devAccessTokenName, integrationFetch, integrationStatus, } from "./integrationFetch.js";
18
16
  export { nodeServerHandler, } from "./nodeServer.js";
19
17
  export { sendEmail } from "./sendEmail.js";
20
- export { gatewayAiBinding } from "./aiBinding.js";
21
- export { gatewayEmailBinding, } from "./emailBinding.js";
22
18
  export { listMembers } from "./listMembers.js";
23
19
  export { emit } from "./emit.js";
20
+ export { WEBHOOK_MAX_BYTES_DEFAULT, verifyWebhook, } from "./webhooks.js";
24
21
  export { ToolError, defineTools, toolResult, } from "./tools.js";
25
- export { fromMcpTools, } from "./fromMcpTools.js";
@@ -1,45 +1,47 @@
1
- import { type ApiKeyCapabilityId, type CapabilityId, type ConnectionAccount, type EmailCapabilityStatus, type OAuthClientCapabilityId } from "../internal/index.js";
1
+ import { type ApiKeyCapabilityId, type CapabilityId, type EmailCapabilityStatus, type OAuthPresetId } from "../internal/index.js";
2
2
  import { type GatewayCallFor } from "./attribution.js";
3
3
  import type { SetupInfo } from "./refusal.js";
4
4
  export interface IntegrationFetchOptions {
5
5
  /**
6
6
  * The Worker env: the EVERY_APP_GATEWAY binding when deployed, or in local
7
7
  * dev EVERYAPP_DEV and the provider's key (e.g. DATAFORSEO_API_KEY in
8
- * `.dev.vars`).
8
+ * `.dev.vars`), or for an OAuth provider a token you obtained yourself
9
+ * (`GOOGLE_WORKSPACE_ACCESS_TOKEN`, {@link devAccessTokenName}).
9
10
  */
10
11
  env: object;
11
12
  /**
12
13
  * A provider the app lists in its manifest's `capabilities`: one whose
13
- * key the gateway holds, or one whose OAuth client it holds (its token
14
- * endpoints only). The built-in catalog's ids complete; a provider
15
- * registered on the gateway (`everyapp provider add`) is any other id,
14
+ * key the gateway holds, or an OAuth provider whose connections it
15
+ * holds. The catalog's ids and the OAuth presets' complete; a provider
16
+ * registered on the gateway (an OAuth preset's row among them) is
16
17
  * reached through the binding, which checks it. The `email` capability
17
18
  * is sent with `sendEmail()` instead.
18
19
  */
19
- provider: ApiKeyCapabilityId | OAuthClientCapabilityId | (string & {});
20
+ provider: ApiKeyCapabilityId | OAuthPresetId | (string & {});
20
21
  /**
21
22
  * Whom the call is for. Left out, the request `everyApp()` is serving
22
- * (its user, while the identity is good) or the organization
23
- * `withOrganization()` named; outside both, `RequestContextError`.
23
+ * (its person, while the identity is good) or the organization
24
+ * an event delivery runs under; outside both, `RequestContextError`.
24
25
  * Explicitly: the inbound request, or `{ background: true,
25
26
  * organizationId }` for work no person started (crons, Workflows,
26
27
  * queues). A shared app's Worker must end up with one or the other
27
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.
28
35
  */
29
36
  for?: GatewayCallFor;
30
- /**
31
- * For an OAuth provider the gateway holds connections for: whose
32
- * connection the call uses, the person's (`user`, the default when a
33
- * person is behind the call) or the organization's (`organization`,
34
- * the default for background work). Sent as `x-everyapp-account`.
35
- */
36
- account?: ConnectionAccount;
37
37
  /**
38
38
  * `true`: answer null instead of throwing `ConfigurationError` when the
39
39
  * provider is unavailable (no binding, and in local dev not its
40
40
  * settings in `.dev.vars`), so a feature that can do without it checks
41
41
  * for null. A wrong provider id, a binding that isn't one, and an
42
- * attribution mistake still throw.
42
+ * attribution mistake still throw. An OAuth provider is never
43
+ * unavailable this way: without a connection its calls answer
44
+ * `integration_not_connected`.
43
45
  */
44
46
  optional?: boolean;
45
47
  }
@@ -51,19 +53,19 @@ export interface IntegrationFetchOptions {
51
53
  * sees the key. A refusal the gateway makes itself comes back as a response
52
54
  * {@link gatewayRefusal} recognizes; anything else is the provider's answer.
53
55
  *
54
- * For an OAuth client (`google-workspace`, `slack`, ...) it reaches the
55
- * provider's token endpoints only, and the gateway puts its client on the
56
- * request: send the code (or refresh token) without `client_id` or
57
- * `client_secret`. Build the authorize URL with {@link authorizeUrl} from
58
- * {@link integrationStatus}, and call the provider's API with the user's
59
- * 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}).
60
61
  *
61
- * In local dev only, with no binding, the developer's own key or client
62
- * 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:
63
64
  * a catalog provider's from the catalog, a provider registered on the
64
65
  * gateway from its spec in `.everyapp/providers/<id>.json` (`everyapp
65
66
  * provider show <id> --save` writes it), put on the call as the gateway's
66
- * spec says.
67
+ * spec says. An OAuth provider's calls carry a token you obtained
68
+ * yourself ({@link devAccessTokenName}), to its API hosts only.
67
69
  */
68
70
  export declare function integrationFetch(options: IntegrationFetchOptions & {
69
71
  optional: true;
@@ -92,70 +94,56 @@ export interface IntegrationStatus extends SetupInfo {
92
94
  */
93
95
  export type EmailIntegrationStatus = IntegrationStatus & Pick<EmailCapabilityStatus, "sender" | "senders" | "provider">;
94
96
  /**
95
- * An OAuth client's status: as {@link IntegrationStatus}, plus what the app
96
- * needs to send people to the provider's authorize page, present only when
97
- * 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.
98
101
  */
99
- export interface OAuthClientIntegrationStatus extends IntegrationStatus {
100
- /** The client's public id, for the authorize URL. */
101
- clientId?: string;
102
- /**
103
- * For a client with scope sets (`google-workspace`, `microsoft-365`): the
104
- * set names the app's manifest entry declares, `[]` when the entry voids
105
- * its grant (no `scopes`, or a set this gateway doesn't offer), in which
106
- * case `ready` is false and no token call can complete.
107
- */
108
- scopeSets?: readonly string[];
102
+ export type OAuthClientIntegrationStatus = IntegrationStatus & {
103
+ /** The provider's scopes as the app's `everyapp.config.ts` lists them. */
104
+ scopes: readonly string[];
109
105
  /**
110
- * The provider's scope strings those sets ask for, in the provider's
111
- * spelling and the registry's order, for the authorize URL
112
- * ({@link authorizeUrl} puts them on). The gateway refuses a token that
113
- * carries more.
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).
114
110
  */
115
- scopes?: readonly string[];
116
- /** Slack's `user_scope` strings, when the sets name any. */
117
- userScopes?: readonly string[];
111
+ connectPath: string | null;
118
112
  /**
119
- * Which flows the client supports: `app` (the app runs authorize and
120
- * callback itself and keeps the tokens, the social networks), `gateway`
121
- * (the Gateway holds the connection; API calls go through
122
- * `integrationFetch` with the token injected) or `both` (Google,
123
- * Microsoft, Slack, Discord and every registered OAuth provider).
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).
124
118
  */
125
- flow?: "app" | "gateway" | "both";
126
- /** Where a person connects on the Gateway: `/connect/<id>`; see `connectUrl()`. */
127
- connectPath?: string;
128
- /**
129
- * The connection the caller's account would use (the person's, or the
130
- * organization's for background work), or null when there is none yet;
131
- * `reconnect` when it exists but lacks a set the app declares or has
132
- * expired, so the person has to connect again.
133
- */
134
- connection?: {
135
- account: ConnectionAccount;
119
+ connection: {
120
+ /** The account's name at the provider (an email address, a login). */
136
121
  label: string | null;
137
- scopeSets: readonly string[];
122
+ /** The scopes it holds, canonical. */
123
+ scopes: readonly string[];
138
124
  ready: boolean;
139
- reconnect?: boolean;
125
+ missingScopes?: readonly string[];
126
+ reconnect?: true;
140
127
  } | null;
141
- }
142
- /** The status of a capability: email's carries its senders, an OAuth client's its id. */
143
- export type IntegrationStatusOf<P extends string> = P extends "email" ? EmailIntegrationStatus : P extends OAuthClientCapabilityId ? OAuthClientIntegrationStatus : IntegrationStatus;
128
+ };
129
+ /** The status of a capability: email's carries its senders, an OAuth provider's the connection. */
130
+ export type IntegrationStatusOf<P extends string> = P extends "email" ? EmailIntegrationStatus : P extends OAuthPresetId ? OAuthClientIntegrationStatus : IntegrationStatus;
144
131
  /**
145
132
  * Whether the app can use an integration right now, without calling the
146
133
  * provider: show "an admin needs to set up DataForSEO" (or "sending isn't
147
- * set up") up front instead of failing mid-task. An OAuth client's status
148
- * 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.
149
137
  */
150
138
  export declare function integrationStatus<P extends CapabilityId | (string & {})>({ env, provider, for: explicitTarget, }: {
151
139
  env: object;
152
140
  provider: P;
153
141
  /**
154
142
  * Whom the status is for: the request being served (its person), so an
155
- * OAuth provider's `connection` is that person's; background work
156
- * (`withOrganization()`) its organization, whose own connection is then
157
- * reported. Explicitly the inbound request or `{ background: true,
158
- * organizationId }`, as on every call.
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.
159
147
  */
160
148
  for?: GatewayCallFor;
161
149
  }): Promise<IntegrationStatusOf<P>>;
@@ -1 +1 @@
1
- {"version":3,"file":"integrationFetch.d.ts","sourceRoot":"","sources":["../../src/server/integrationFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EA+BL,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAE1B,KAAK,uBAAuB,EAQ7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAO9C,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;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,uBAAuB,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GACpD,OAAO,KAAK,GAAG,IAAI,CAAC;AACvB,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,KAAK,CAAC;AA+JhB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ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