@every-app/sdk 0.3.0-rc.4 → 0.3.0-rc.6

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 (98) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cloudflare/catalogSettings.generated.d.ts +80 -0
  3. package/dist/cloudflare/catalogSettings.generated.d.ts.map +1 -0
  4. package/dist/cloudflare/catalogSettings.generated.js +172 -0
  5. package/dist/cloudflare/index.d.ts +1 -0
  6. package/dist/cloudflare/index.d.ts.map +1 -1
  7. package/dist/cloudflare/index.js +3 -0
  8. package/dist/cloudflare/worker.d.ts +29 -98
  9. package/dist/cloudflare/worker.d.ts.map +1 -1
  10. package/dist/cloudflare/worker.js +45 -132
  11. package/dist/index.d.ts +6 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +5 -0
  14. package/dist/internal/aiDefault.d.ts +70 -7
  15. package/dist/internal/aiDefault.d.ts.map +1 -1
  16. package/dist/internal/aiDefault.js +145 -15
  17. package/dist/internal/aiProviders.d.ts +3 -1
  18. package/dist/internal/aiProviders.d.ts.map +1 -1
  19. package/dist/internal/aiProviders.js +12 -3
  20. package/dist/internal/appSettings.d.ts +65 -5
  21. package/dist/internal/appSettings.d.ts.map +1 -1
  22. package/dist/internal/appSettings.js +141 -23
  23. package/dist/internal/capabilities.d.ts +52 -433
  24. package/dist/internal/capabilities.d.ts.map +1 -1
  25. package/dist/internal/capabilities.js +25 -558
  26. package/dist/internal/catalog/index.d.ts +6 -6
  27. package/dist/internal/catalog/inference.d.ts +6 -6
  28. package/dist/internal/catalog/inference.d.ts.map +1 -1
  29. package/dist/internal/catalog/inference.js +9 -6
  30. package/dist/internal/events.d.ts.map +1 -1
  31. package/dist/internal/events.js +1 -0
  32. package/dist/internal/gatewaySettings.d.ts +1 -1
  33. package/dist/internal/gatewaySettings.d.ts.map +1 -1
  34. package/dist/internal/gatewaySettings.js +1 -3
  35. package/dist/internal/identity.d.ts +12 -1
  36. package/dist/internal/identity.d.ts.map +1 -1
  37. package/dist/internal/identity.js +11 -1
  38. package/dist/internal/oauthClient.d.ts +10 -12
  39. package/dist/internal/oauthClient.d.ts.map +1 -1
  40. package/dist/internal/oauthClient.js +20 -81
  41. package/dist/internal/oauthPresets.d.ts +7 -3
  42. package/dist/internal/oauthPresets.d.ts.map +1 -1
  43. package/dist/internal/oauthPresets.js +533 -3
  44. package/dist/internal/oauthSpec.d.ts +44 -1
  45. package/dist/internal/oauthSpec.d.ts.map +1 -1
  46. package/dist/internal/oauthSpec.js +147 -34
  47. package/dist/internal/protocol.d.ts +14 -0
  48. package/dist/internal/protocol.d.ts.map +1 -1
  49. package/dist/internal/protocol.js +7 -0
  50. package/dist/internal/providerRegistry.d.ts +61 -1
  51. package/dist/internal/providerRegistry.d.ts.map +1 -1
  52. package/dist/internal/providerRegistry.js +127 -6
  53. package/dist/internal/providerSpec.d.ts +14 -7
  54. package/dist/internal/providerSpec.d.ts.map +1 -1
  55. package/dist/internal/providerSpec.js +306 -7
  56. package/dist/manifest.d.ts +226 -0
  57. package/dist/manifest.d.ts.map +1 -0
  58. package/dist/manifest.js +30 -0
  59. package/dist/server/ai.d.ts +66 -0
  60. package/dist/server/ai.d.ts.map +1 -1
  61. package/dist/server/ai.js +113 -8
  62. package/dist/server/aiBinding.d.ts +68 -0
  63. package/dist/server/aiBinding.d.ts.map +1 -0
  64. package/dist/server/aiBinding.js +294 -0
  65. package/dist/server/authorizeUrl.d.ts +1 -1
  66. package/dist/server/authorizeUrl.d.ts.map +1 -1
  67. package/dist/server/authorizeUrl.js +2 -6
  68. package/dist/server/emailBinding.d.ts +72 -0
  69. package/dist/server/emailBinding.d.ts.map +1 -0
  70. package/dist/server/emailBinding.js +124 -0
  71. package/dist/server/emit.js +1 -1
  72. package/dist/server/env.d.ts +41 -0
  73. package/dist/server/env.d.ts.map +1 -0
  74. package/dist/server/env.js +1 -0
  75. package/dist/server/gatewayFetch.d.ts +17 -13
  76. package/dist/server/gatewayFetch.d.ts.map +1 -1
  77. package/dist/server/gatewayFetch.js +24 -14
  78. package/dist/server/gatewayUrl.d.ts +13 -0
  79. package/dist/server/gatewayUrl.d.ts.map +1 -0
  80. package/dist/server/gatewayUrl.js +34 -0
  81. package/dist/server/index.d.ts +10 -3
  82. package/dist/server/index.d.ts.map +1 -1
  83. package/dist/server/index.js +8 -2
  84. package/dist/server/integrationFetch.d.ts +16 -32
  85. package/dist/server/integrationFetch.d.ts.map +1 -1
  86. package/dist/server/integrationFetch.js +47 -65
  87. package/dist/server/listMembers.js +1 -1
  88. package/dist/server/refusal.d.ts +55 -0
  89. package/dist/server/refusal.d.ts.map +1 -0
  90. package/dist/server/refusal.js +193 -0
  91. package/dist/server/sendEmail.js +1 -1
  92. package/dist/tanstack-start/index.d.ts +9 -0
  93. package/dist/tanstack-start/index.d.ts.map +1 -0
  94. package/dist/tanstack-start/index.js +29 -0
  95. package/dist/testing/index.d.ts +93 -0
  96. package/dist/testing/index.d.ts.map +1 -0
  97. package/dist/testing/index.js +156 -0
  98. package/package.json +34 -12
@@ -0,0 +1,72 @@
1
+ /**
2
+ * `gatewayEmailBinding(env)`: the Gateway's `email` capability as a
3
+ * `send_email` binding, for code written against `env.EMAIL.send(message)`.
4
+ *
5
+ * An app on Every App binds no `send_email` of its own: the Gateway sends
6
+ * with its sender, checks `from` against the installation's senders and
7
+ * keeps the mail budgets. Code that already calls `env.EMAIL.send()` gets
8
+ * this object in its place:
9
+ *
10
+ * const EMAIL = gatewayEmailBinding(env, { for: request });
11
+ * await EMAIL.send({ from, to, subject, text });
12
+ *
13
+ * Each `send()` is a `sendEmail()` (the manifest lists `capabilities: {
14
+ * email: { access: "write" } }`), so local development works the same way:
15
+ * checked and printed, or sent with the developer's own Email Sending
16
+ * account (EMAIL_REST_API_TOKEN, CLOUDFLARE_ACCOUNT_ID, EMAIL_FROM).
17
+ */
18
+ import { type SendEmailMessage } from "../internal/index.js";
19
+ import type { GatewayCallFor } from "./attribution.js";
20
+ export interface GatewayEmailBindingOptions {
21
+ /**
22
+ * Whom the mail is for: the inbound request, or `{ background: true,
23
+ * organizationId }` (sendEmail's `for`).
24
+ */
25
+ for?: GatewayCallFor;
26
+ }
27
+ /** `name <email>` or a bare address, as the binding takes them. */
28
+ type BindingAddress = string | {
29
+ email: string;
30
+ name?: string;
31
+ };
32
+ type BindingRecipients = BindingAddress | BindingAddress[];
33
+ /** The structured message `send_email`'s `send()` takes (`EmailMessageBuilder`). */
34
+ export interface GatewayEmailBindingMessage {
35
+ from: BindingAddress;
36
+ to?: BindingRecipients;
37
+ cc?: BindingRecipients;
38
+ bcc?: BindingRecipients;
39
+ subject: string;
40
+ replyTo?: BindingAddress;
41
+ headers?: Record<string, string>;
42
+ text?: string;
43
+ html?: string;
44
+ attachments?: {
45
+ disposition?: "inline" | "attachment";
46
+ contentId?: string;
47
+ filename: string;
48
+ type: string;
49
+ content: string | ArrayBuffer | ArrayBufferView;
50
+ }[];
51
+ }
52
+ /**
53
+ * A `send_email` binding (`SendEmail`) over the Gateway: pass it where code
54
+ * takes `env.EMAIL`. `send()` takes the structured message (`from`, `to`,
55
+ * `cc`, `bcc`, `subject`, `text`, `html`, `replyTo`, `headers`,
56
+ * `attachments`) and resolves `{ messageId }`. A raw MIME `EmailMessage`
57
+ * (`new EmailMessage(from, to, raw)`) is refused with `GatewayRefusalError`
58
+ * `email_invalid_message`: the Gateway takes structured mail only.
59
+ *
60
+ * Errors are sendEmail()'s: `GatewayRefusalError` with the Gateway's code
61
+ * (`email_sender_not_allowed`, `email_budget_exhausted`,
62
+ * `integration_not_configured`, …) and `ConfigurationError` with neither a
63
+ * binding nor `everyapp dev`. Nothing is checked when the binding is made.
64
+ */
65
+ export declare function gatewayEmailBinding(env: object, options?: GatewayEmailBindingOptions): SendEmail;
66
+ /**
67
+ * The binding's message as sendEmail()'s: recipients as bare addresses,
68
+ * `from` and `replyTo` with their display names, attachments base64.
69
+ */
70
+ export declare function toSendEmailMessage(message: unknown): SendEmailMessage;
71
+ export {};
72
+ //# sourceMappingURL=emailBinding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emailBinding.d.ts","sourceRoot":"","sources":["../../src/server/emailBinding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;CACtB;AAED,mEAAmE;AACnE,KAAK,cAAc,GAAG,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAChE,KAAK,iBAAiB,GAAG,cAAc,GAAG,cAAc,EAAE,CAAC;AAE3D,oFAAoF;AACpF,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,cAAc,CAAC;IACrB,EAAE,CAAC,EAAE,iBAAiB,CAAC;IACvB,EAAE,CAAC,EAAE,iBAAiB,CAAC;IACvB,GAAG,CAAC,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE;QACZ,WAAW,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAC;QACtC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,eAAe,CAAC;KACjD,EAAE,CAAC;CACL;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,0BAA+B,GACvC,SAAS,CAcX;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CA6BrE"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * `gatewayEmailBinding(env)`: the Gateway's `email` capability as a
3
+ * `send_email` binding, for code written against `env.EMAIL.send(message)`.
4
+ *
5
+ * An app on Every App binds no `send_email` of its own: the Gateway sends
6
+ * with its sender, checks `from` against the installation's senders and
7
+ * keeps the mail budgets. Code that already calls `env.EMAIL.send()` gets
8
+ * this object in its place:
9
+ *
10
+ * const EMAIL = gatewayEmailBinding(env, { for: request });
11
+ * await EMAIL.send({ from, to, subject, text });
12
+ *
13
+ * Each `send()` is a `sendEmail()` (the manifest lists `capabilities: {
14
+ * email: { access: "write" } }`), so local development works the same way:
15
+ * checked and printed, or sent with the developer's own Email Sending
16
+ * account (EMAIL_REST_API_TOKEN, CLOUDFLARE_ACCOUNT_ID, EMAIL_FROM).
17
+ */
18
+ import { ConfigurationError, } from "../internal/index.js";
19
+ import { GatewayRefusalError } from "./refusal.js";
20
+ import { sendEmail } from "./sendEmail.js";
21
+ /**
22
+ * A `send_email` binding (`SendEmail`) over the Gateway: pass it where code
23
+ * takes `env.EMAIL`. `send()` takes the structured message (`from`, `to`,
24
+ * `cc`, `bcc`, `subject`, `text`, `html`, `replyTo`, `headers`,
25
+ * `attachments`) and resolves `{ messageId }`. A raw MIME `EmailMessage`
26
+ * (`new EmailMessage(from, to, raw)`) is refused with `GatewayRefusalError`
27
+ * `email_invalid_message`: the Gateway takes structured mail only.
28
+ *
29
+ * Errors are sendEmail()'s: `GatewayRefusalError` with the Gateway's code
30
+ * (`email_sender_not_allowed`, `email_budget_exhausted`,
31
+ * `integration_not_configured`, …) and `ConfigurationError` with neither a
32
+ * binding nor `everyapp dev`. Nothing is checked when the binding is made.
33
+ */
34
+ export function gatewayEmailBinding(env, options = {}) {
35
+ const binding = {
36
+ async send(message) {
37
+ const result = await sendEmail({
38
+ env,
39
+ ...(options.for === undefined ? {} : { for: options.for }),
40
+ message: toSendEmailMessage(message),
41
+ });
42
+ return { messageId: result.messageId ?? "" };
43
+ },
44
+ };
45
+ // `SendEmail` is the app's own Workers types' interface, whose `send()`
46
+ // overloads change with the version; this `send()` takes both forms.
47
+ return binding;
48
+ }
49
+ /**
50
+ * The binding's message as sendEmail()'s: recipients as bare addresses,
51
+ * `from` and `replyTo` with their display names, attachments base64.
52
+ */
53
+ export function toSendEmailMessage(message) {
54
+ if (!message || typeof message !== "object") {
55
+ throw new ConfigurationError("EMAIL.send() takes a message object.");
56
+ }
57
+ if (!("subject" in message)) {
58
+ throw new GatewayRefusalError({
59
+ status: 400,
60
+ code: "email_invalid_message",
61
+ message: "Raw MIME messages can't be sent through the Every App gateway; send a structured message ({ from, to, subject, text or html }).",
62
+ });
63
+ }
64
+ const m = message;
65
+ return {
66
+ to: addresses(m.to) ?? [],
67
+ ...(m.cc === undefined ? {} : { cc: addresses(m.cc) }),
68
+ ...(m.bcc === undefined ? {} : { bcc: addresses(m.bcc) }),
69
+ subject: m.subject,
70
+ ...(m.text ? { text: m.text } : {}),
71
+ ...(m.html ? { html: m.html } : {}),
72
+ from: named(m.from),
73
+ ...(m.replyTo ? { replyTo: named(m.replyTo) } : {}),
74
+ ...(m.headers && Object.keys(m.headers).length > 0
75
+ ? { headers: m.headers }
76
+ : {}),
77
+ ...(m.attachments?.length
78
+ ? { attachments: m.attachments.map(attachment) }
79
+ : {}),
80
+ };
81
+ }
82
+ /**
83
+ * One attachment in the Gateway's shape. An inline part without a content
84
+ * id can't be referenced (and the Gateway refuses it), so it goes as an
85
+ * ordinary attachment.
86
+ */
87
+ function attachment(a) {
88
+ const contentId = a.contentId?.trim();
89
+ return {
90
+ filename: a.filename,
91
+ contentType: a.type,
92
+ content: base64(a.content),
93
+ ...(a.disposition === "inline" && contentId
94
+ ? { disposition: "inline", contentId }
95
+ : {}),
96
+ };
97
+ }
98
+ function named(address) {
99
+ if (typeof address === "string")
100
+ return { address };
101
+ return {
102
+ address: address.email,
103
+ ...(address.name?.trim() ? { name: address.name } : {}),
104
+ };
105
+ }
106
+ function addresses(recipients) {
107
+ if (recipients === undefined)
108
+ return undefined;
109
+ const of = (a) => (typeof a === "string" ? a : a.email);
110
+ return Array.isArray(recipients) ? recipients.map(of) : of(recipients);
111
+ }
112
+ /** Strings are taken as base64 already, as the binding takes them; bytes are encoded. */
113
+ function base64(content) {
114
+ if (typeof content === "string")
115
+ return content;
116
+ const bytes = content instanceof ArrayBuffer
117
+ ? new Uint8Array(content)
118
+ : new Uint8Array(content.buffer, content.byteOffset, content.byteLength);
119
+ let binary = "";
120
+ for (let i = 0; i < bytes.length; i += 0x8000) {
121
+ binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
122
+ }
123
+ return btoa(binary);
124
+ }
@@ -11,7 +11,7 @@
11
11
  import { APP_EVENT_DATA_MAX_BYTES, APP_ID_ENV, ConfigurationError, EVENTS_EMIT_PATH, appEventNameProblem, appEventType, checkEventData, } from "../internal/index.js";
12
12
  import { applyAttribution, attributionFor, } from "./attribution.js";
13
13
  import { BINDING_ORIGIN } from "./gatewayFetch.js";
14
- import { GatewayRefusalError, gatewayRefusal } from "./integrationFetch.js";
14
+ import { GatewayRefusalError, gatewayRefusal } from "./refusal.js";
15
15
  /**
16
16
  * Put an event on the gateway's event bus, for the organization's webhook
17
17
  * and email subscribers. The gateway names it `app.<app id>.<event>`, so an
@@ -0,0 +1,41 @@
1
+ /**
2
+ * `EveryAppEnv`: what Every App puts in an app Worker's `env`, for an app
3
+ * that types its env by hand. An app built with `everyAppWorker()` needs
4
+ * none of it: `cf workers types` writes the same names into `Env` from the
5
+ * Worker's definition.
6
+ */
7
+ import type { EveryAppManifest } from "../manifest.js";
8
+ /** The `env` keys Every App sets on an app's Worker, deployed and under `everyapp dev`. */
9
+ export interface EveryAppEnv<M extends EveryAppManifest = EveryAppManifest> {
10
+ /** The manifest's `id`. */
11
+ EVERYAPP_APP_ID: string;
12
+ /**
13
+ * The manifest (`everyapp.config.ts`) as JSON: what the app asked for,
14
+ * for a page that shows it. `EveryAppEnv<typeof manifest>` types it as
15
+ * the app's own.
16
+ */
17
+ EVERYAPP_MANIFEST: M;
18
+ /** The Gateway's URL; links back to it go through `gatewayUrl(env)`. */
19
+ GATEWAY_URL: string;
20
+ /** The identity tokens' issuer: the Gateway's URL, or the dev issuer. */
21
+ EVERYAPP_IDENTITY_ISSUER: string;
22
+ /** The public keys (JSON array of PEMs) `everyApp()` verifies identities with. */
23
+ EVERYAPP_IDENTITY_PUBLIC_KEYS: string;
24
+ /** Deployed: the Worker's name, the identity tokens' audience. */
25
+ EVERYAPP_AUDIENCE?: string;
26
+ /** Deployed: the organization the app is installed for. */
27
+ EVERY_APP_ORG_ID?: string;
28
+ /** Deployed, on an app installed for every organization: `"1"`. */
29
+ EVERYAPP_SHARED?: string;
30
+ /** Deployed: the service binding to the Gateway, which capabilities, AI and email go through. */
31
+ EVERY_APP_GATEWAY?: Fetcher;
32
+ /** `"1"` under `everyapp dev`, absent when deployed. */
33
+ EVERYAPP_DEV?: string;
34
+ /** Under `everyapp dev`: the manifest's `capabilities`, as JSON, for the SDK's dev fallbacks. */
35
+ EVERYAPP_DEV_CAPABILITIES?: string;
36
+ /** Under `everyapp dev`: the app's `.everyapp/providers/*.json`, as JSON. */
37
+ EVERYAPP_DEV_PROVIDERS?: string;
38
+ /** Under `everyapp dev`, from `.dev.vars`: the senders standing in for `everyapp email set --sender`. */
39
+ EVERYAPP_EMAIL_SENDERS?: string;
40
+ }
41
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/server/env.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,2FAA2F;AAC3F,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,gBAAgB,GAAG,gBAAgB;IACxE,2BAA2B;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,iBAAiB,EAAE,CAAC,CAAC;IACrB,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,wBAAwB,EAAE,MAAM,CAAC;IACjC,kFAAkF;IAClF,6BAA6B,EAAE,MAAM,CAAC;IACtC,kEAAkE;IAClE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2DAA2D;IAC3D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iGAAiG;IACjG,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,wDAAwD;IACxD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iGAAiG;IACjG,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,6EAA6E;IAC7E,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,yGAAyG;IACzG,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -3,19 +3,13 @@ export declare const BINDING_ORIGIN = "http://every-app-gateway.internal";
3
3
  export interface GatewayServiceBinding {
4
4
  fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
5
5
  }
6
- export interface GatewayFetchEnv {
7
- EVERY_APP_GATEWAY?: GatewayServiceBinding;
8
- EVERYAPP_DEV?: string | boolean;
9
- /** `1` on a shared app's Workers (`everyAppWorker()` sets it). */
10
- EVERYAPP_SHARED?: string;
11
- OPENAI_API_KEY?: string;
12
- OPENROUTER_API_KEY?: string;
13
- /** Workers AI: an API token (Workers AI Read and Edit) and the account it bills. */
14
- WORKERS_AI_API_TOKEN?: string;
15
- CLOUDFLARE_ACCOUNT_ID?: string;
16
- }
17
6
  export interface CreateGatewayFetchOptions {
18
- env: GatewayFetchEnv;
7
+ /**
8
+ * The Worker env, as it is: the EVERY_APP_GATEWAY binding when deployed,
9
+ * or in local dev EVERYAPP_DEV and the provider's settings in
10
+ * `.dev.vars` (`OPENROUTER_API_KEY`, …). No cast needed.
11
+ */
12
+ env: object;
19
13
  /**
20
14
  * Whom the call is for. Left out, the request `everyApp()` is serving
21
15
  * (its user, while the identity is good) or the organization
@@ -26,6 +20,13 @@ export interface CreateGatewayFetchOptions {
26
20
  * ({@link AttributionError}).
27
21
  */
28
22
  for?: GatewayCallFor;
23
+ /**
24
+ * `true`: answer null instead of throwing `ConfigurationError` when AI
25
+ * is unavailable (no binding, and in local dev no provider key), so a
26
+ * feature that can do without a model checks for null. A binding that
27
+ * isn't one, and an attribution mistake, still throw.
28
+ */
29
+ optional?: boolean;
29
30
  }
30
31
  /**
31
32
  * Create a fetch for the gateway's AI providers (`/api/ai/<provider>/…`),
@@ -33,7 +34,10 @@ export interface CreateGatewayFetchOptions {
33
34
  * developer's own provider key from `.dev.vars` is a direct-provider
34
35
  * fallback when no binding exists.
35
36
  */
36
- export declare function createGatewayFetch({ env, for: explicitTarget, }: CreateGatewayFetchOptions): typeof fetch;
37
+ export declare function createGatewayFetch(options: CreateGatewayFetchOptions & {
38
+ optional: true;
39
+ }): typeof fetch | null;
40
+ export declare function createGatewayFetch(options: CreateGatewayFetchOptions): typeof fetch;
37
41
  /** A copy of `source` aimed at `url`, streaming its body rather than buffering it. */
38
42
  export declare function streamingRequest(url: string, source: Request, headers: Headers): Request;
39
43
  //# sourceMappingURL=gatewayFetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gatewayFetch.d.ts","sourceRoot":"","sources":["../../src/server/gatewayFetch.ts"],"names":[],"mappings":"AAaA,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,cAAc,sCAAsC,CAAC;AAGlE,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,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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"}
@@ -2,13 +2,8 @@ import { AI_DEFAULT_MODEL, AI_DEFAULT_PROVIDER, AI_DEFAULT_ROUTES, aiProviderSet
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
- * Create a fetch for the gateway's AI providers (`/api/ai/<provider>/…`),
7
- * backed by the private gateway service binding. In local dev only, the
8
- * developer's own provider key from `.dev.vars` is a direct-provider
9
- * fallback when no binding exists.
10
- */
11
- export function createGatewayFetch({ env, for: explicitTarget, }) {
5
+ export function createGatewayFetch({ env: workerEnv, for: explicitTarget, optional = false, }) {
6
+ const env = workerEnv;
12
7
  // Checked now, so a call nobody's fails where the fetch is made; and
13
8
  // again per call, where an identity may since have neared its expiry.
14
9
  attributionFor(env, explicitTarget, "createGatewayFetch");
@@ -18,7 +13,9 @@ export function createGatewayFetch({ env, for: explicitTarget, }) {
18
13
  throw new ConfigurationError("EVERY_APP_GATEWAY is configured but is not a valid service binding.");
19
14
  }
20
15
  if (!binding && Object.keys(devProviders).length === 0) {
21
- 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.`);
16
+ if (optional)
17
+ return null;
18
+ throw new ConfigurationError(`AI gateway unavailable: deploy with the EVERY_APP_GATEWAY binding, or set the provider's key (${listOf(Object.values(DEV_AI_PROVIDERS).map((spec) => settingsNames(spec, "with")), "or")}) in .dev.vars for direct local development.`, { code: "ai_provider_not_configured" });
22
19
  }
23
20
  return async (input, init) => {
24
21
  const target = attributionFor(env, explicitTarget, "createGatewayFetch");
@@ -35,7 +32,10 @@ export function createGatewayFetch({ env, for: explicitTarget, }) {
35
32
  const { provider, spec, path, search } = direct;
36
33
  const dev = devProviders[provider];
37
34
  if (!dev) {
38
- throw new ConfigurationError(`Set ${settingsNames(spec)} in .dev.vars to call ${provider} in local development.`);
35
+ throw new ConfigurationError(`Set ${settingsNames(spec)} in .dev.vars to call ${provider} in local development.`, {
36
+ code: "ai_provider_not_configured",
37
+ settings: aiProviderSettings(spec),
38
+ });
39
39
  }
40
40
  const url = joinProviderUrl(`${spec.origin}${dev.basePath}`, path, search);
41
41
  if (!url)
@@ -132,15 +132,20 @@ function directProviderPath(input, env) {
132
132
  let fillModel = null;
133
133
  if (provider === AI_DEFAULT_PROVIDER) {
134
134
  // The default in dev, by the gateway's rule on the developer's own
135
- // `.dev.vars`: the first provider of the order with every setting set.
135
+ // `.dev.vars`: the first provider of the order with every setting set,
136
+ // with its seed models (dev has no operator settings; a request that
137
+ // names a model sends it as it is).
136
138
  const values = env;
137
139
  const resolution = resolveAiDefault({
138
- choice: null,
140
+ provider: null,
139
141
  isSet: (name) => typeof values[name] === "string" &&
140
142
  values[name].trim().length > 0,
141
143
  });
142
144
  if (!resolution.configured) {
143
- 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.`);
145
+ 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.`, {
146
+ code: "ai_default_not_configured",
147
+ settings: resolution.settings,
148
+ });
144
149
  }
145
150
  const route = path === AI_DEFAULT_ROUTES.chat
146
151
  ? resolution.chat
@@ -152,9 +157,14 @@ function directProviderPath(input, env) {
152
157
  }
153
158
  provider = resolution.provider;
154
159
  path = route.path;
155
- fillModel = path === resolution.chat.path ? resolution.model : route.model;
160
+ fillModel =
161
+ route === resolution.chat
162
+ ? resolution.model
163
+ : (resolution.embeddingsModel ?? null);
156
164
  }
157
- const spec = provider ? devAiProvider(provider) : undefined;
165
+ const spec = provider
166
+ ? devAiProvider(provider, env)
167
+ : undefined;
158
168
  if (!provider || !spec) {
159
169
  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.`);
160
170
  }
@@ -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
+ }
@@ -6,13 +6,20 @@
6
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
7
  export { OrganizationMismatchError, RequestContextError, currentUser, withOrganization, } from "./context.js";
8
8
  export { AttributionError, type GatewayCallFor } from "./attribution.js";
9
+ export { gatewayUrl } from "./gatewayUrl.js";
10
+ export type { EveryAppEnv } from "./env.js";
11
+ /** The header a Gateway refusal carries its code in; `gatewayRefusal()` reads the rest. */
12
+ export { GATEWAY_ERROR_HEADER } from "../internal/protocol.js";
9
13
  export { authorizeUrl, type AuthorizeUrlOptions } from "./authorizeUrl.js";
10
14
  export { connectPath, connectUrl, type ConnectUrlOptions, } from "./connectUrl.js";
11
- export { createGatewayFetch, type CreateGatewayFetchOptions, type GatewayFetchEnv, } from "./gatewayFetch.js";
12
- export { ai, AI_DEFAULT_BASE_URL, type AiClient } from "./ai.js";
13
- export { GatewayRefusalError, gatewayRefusal, devAccessTokenName, integrationFetch, integrationStatus, type EmailIntegrationStatus, type GatewayRefusal, type IntegrationFetchOptions, type IntegrationStatus, type IntegrationStatusOf, type OAuthClientIntegrationStatus, } from "./integrationFetch.js";
15
+ 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";
18
+ export { devAccessTokenName, integrationFetch, integrationStatus, type EmailIntegrationStatus, type IntegrationFetchOptions, type IntegrationStatus, type IntegrationStatusOf, type OAuthClientIntegrationStatus, } from "./integrationFetch.js";
14
19
  export { nodeServerHandler, type NodeServer, type NodeServerHandlerOptions, } from "./nodeServer.js";
15
20
  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";
16
23
  export { listMembers, type ListMembersOptions } from "./listMembers.js";
17
24
  export { emit, type EmitOptions } from "./emit.js";
18
25
  export type { ApiKeyCapabilityId, CapabilityId, OAuthClientCapabilityId, ConnectionAccount, EmailAddressInput, EmailAttachmentInput, SendEmailMessage, SendEmailResult, ListMembersResult, OrganizationMember, OrganizationMemberRole, EmitEventResult, } from "../internal/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"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AAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,SAAS,EACT,WAAW,EACX,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,GACvB,MAAM,mBAAmB,CAAC"}
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,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AAM,WAAW,CAAC;AACnD,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,SAAS,EACT,WAAW,EACX,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,GACvB,MAAM,mBAAmB,CAAC"}
@@ -6,13 +6,19 @@
6
6
  export { ConfigurationError, IdentityError, everyApp, getEveryAppUser, hasScope, isAdmin, requireCurrentUser, requireEveryAppUser, } from "./everyApp.js";
7
7
  export { OrganizationMismatchError, RequestContextError, currentUser, withOrganization, } from "./context.js";
8
8
  export { AttributionError } from "./attribution.js";
9
+ export { gatewayUrl } from "./gatewayUrl.js";
10
+ /** The header a Gateway refusal carries its code in; `gatewayRefusal()` reads the rest. */
11
+ export { GATEWAY_ERROR_HEADER } from "../internal/protocol.js";
9
12
  export { authorizeUrl } from "./authorizeUrl.js";
10
13
  export { connectPath, connectUrl, } from "./connectUrl.js";
11
14
  export { createGatewayFetch, } from "./gatewayFetch.js";
12
- export { ai, AI_DEFAULT_BASE_URL } from "./ai.js";
13
- export { GatewayRefusalError, gatewayRefusal, devAccessTokenName, integrationFetch, integrationStatus, } from "./integrationFetch.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";
17
+ export { devAccessTokenName, integrationFetch, integrationStatus, } from "./integrationFetch.js";
14
18
  export { nodeServerHandler, } from "./nodeServer.js";
15
19
  export { sendEmail } from "./sendEmail.js";
20
+ export { gatewayAiBinding } from "./aiBinding.js";
21
+ export { gatewayEmailBinding, } from "./emailBinding.js";
16
22
  export { listMembers } from "./listMembers.js";
17
23
  export { emit } from "./emit.js";
18
24
  export { ToolError, defineTools, toolResult, } from "./tools.js";
@@ -1,5 +1,6 @@
1
1
  import { type ApiKeyCapabilityId, type CapabilityId, type ConnectionAccount, 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
@@ -33,6 +34,14 @@ export interface IntegrationFetchOptions {
33
34
  * the default for background work). Sent as `x-everyapp-account`.
34
35
  */
35
36
  account?: ConnectionAccount;
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.
43
+ */
44
+ optional?: boolean;
36
45
  }
37
46
  /**
38
47
  * A `fetch` for one of the gateway's capabilities. Call the provider's real
@@ -42,7 +51,7 @@ export interface IntegrationFetchOptions {
42
51
  * sees the key. A refusal the gateway makes itself comes back as a response
43
52
  * {@link gatewayRefusal} recognizes; anything else is the provider's answer.
44
53
  *
45
- * For an OAuth client (`linkedin`, `mastodon`, ...) it reaches the
54
+ * For an OAuth client (`google-workspace`, `slack`, ...) it reaches the
46
55
  * provider's token endpoints only, and the gateway puts its client on the
47
56
  * request: send the code (or refresh token) without `client_id` or
48
57
  * `client_secret`. Build the authorize URL with {@link authorizeUrl} from
@@ -56,7 +65,10 @@ export interface IntegrationFetchOptions {
56
65
  * provider show <id> --save` writes it), put on the call as the gateway's
57
66
  * spec says.
58
67
  */
59
- export declare function integrationFetch({ env, provider, for: explicitTarget, account, }: IntegrationFetchOptions): typeof fetch;
68
+ export declare function integrationFetch(options: IntegrationFetchOptions & {
69
+ optional: true;
70
+ }): typeof fetch | null;
71
+ export declare function integrationFetch(options: IntegrationFetchOptions): typeof fetch;
60
72
  /**
61
73
  * The `.dev.vars` name of a held token for `provider` in local dev
62
74
  * (`GOOGLE_WORKSPACE_ACCESS_TOKEN`, `GITHUB_ACCESS_TOKEN`): a token the
@@ -64,7 +76,7 @@ export declare function integrationFetch({ env, provider, for: explicitTarget, a
64
76
  * gateway would hold. Dev-only: the gateway never reads it.
65
77
  */
66
78
  export declare function devAccessTokenName(provider: string): string;
67
- export interface IntegrationStatus {
79
+ export interface IntegrationStatus extends SetupInfo {
68
80
  /** The app's manifest lists the capability. */
69
81
  requested: boolean;
70
82
  /** The gateway holds a key for it (in local dev: `.dev.vars` sets one). */
@@ -85,13 +97,8 @@ export type EmailIntegrationStatus = IntegrationStatus & Pick<EmailCapabilitySta
85
97
  * the app lists the capability and the gateway holds the client.
86
98
  */
87
99
  export interface OAuthClientIntegrationStatus extends IntegrationStatus {
88
- /** The client's public id, for the authorize URL (and Twitch's `Client-Id`). */
100
+ /** The client's public id, for the authorize URL. */
89
101
  clientId?: string;
90
- /**
91
- * The provider's origin when the operator chose it (Mastodon's instance,
92
- * `MASTODON_URL`): the authorize page, token endpoint and API are on it.
93
- */
94
- origin?: string;
95
102
  /**
96
103
  * For a client with scope sets (`google-workspace`, `microsoft-365`): the
97
104
  * set names the app's manifest entry declares, `[]` when the entry voids
@@ -152,27 +159,4 @@ export declare function integrationStatus<P extends CapabilityId | (string & {})
152
159
  */
153
160
  for?: GatewayCallFor;
154
161
  }): Promise<IntegrationStatusOf<P>>;
155
- /** A refusal the AppGateway binding made itself, not the provider. */
156
- export interface GatewayRefusal {
157
- status: number;
158
- /** e.g. `capability_not_requested`, `integration_not_configured`. */
159
- code: string;
160
- message: string;
161
- }
162
- /**
163
- * A refusal the AppGateway binding made, thrown: what `sendEmail()` throws
164
- * when the gateway won't send (`email_sender_not_allowed`,
165
- * `email_budget_exhausted`, ...). The thrown twin of {@link gatewayRefusal}.
166
- */
167
- export declare class GatewayRefusalError extends Error implements GatewayRefusal {
168
- readonly status: number;
169
- readonly code: string;
170
- constructor({ status, code, message }: GatewayRefusal);
171
- }
172
- /**
173
- * The gateway's own refusal in `response`, or null when the response is the
174
- * provider's answer (which may be an error of its own). Reads the body only
175
- * for a refusal, so call it before reading the body yourself.
176
- */
177
- export declare function gatewayRefusal(response: Response): Promise<GatewayRefusal | null>;
178
162
  //# sourceMappingURL=integrationFetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"integrationFetch.d.ts","sourceRoot":"","sources":["../../src/server/integrationFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAgCL,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;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;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,GAAG,EACH,Q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