@ever-works/ever-email-router-plugin 0.0.0-stage → 1.0.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.
@@ -0,0 +1,66 @@
1
+ import { IEmailInboundPlugin, PluginCategory, EmailInboundAddressPolicy, JsonSchema, EmailOptions, EmailInboundMessage } from '@ever-works/plugin';
2
+
3
+ /** Header the router signs every delivery with: `t=<unix seconds>,v1=<hex HMAC-SHA256>`. */
4
+ declare const EVER_EMAIL_SIGNATURE_HEADER = "x-ever-email-signature";
5
+ /**
6
+ * Shortest secret accepted. A shorter (or absent) one refuses every webhook:
7
+ * the route is public, so a guessable secret would let anyone inject mail.
8
+ */
9
+ declare const EVER_EMAIL_MIN_SECRET_LENGTH = 24;
10
+ /**
11
+ * Most seconds between the router's signing time and ours, either way. A
12
+ * replay inside the window is harmless: the HMAC covers the whole body, so it
13
+ * can only re-deliver the same message to the same recipient, which the
14
+ * `(pluginId, providerMessageId)` unique index answers as a duplicate.
15
+ */
16
+ declare const EVER_EMAIL_MAX_SKEW_SECONDS = 300;
17
+ /** The domain the router delivers when `EVER_EMAIL_DOMAIN` is unset. */
18
+ declare const DEFAULT_EVER_EMAIL_DOMAIN = "ever.email";
19
+ /**
20
+ * The one domain the shared router delivers: `EVER_EMAIL_DOMAIN`
21
+ * (lower-cased), else {@link DEFAULT_EVER_EMAIL_DOMAIN}. Read on every call,
22
+ * so the policy follows the deployment's environment.
23
+ */
24
+ declare function everEmailDomain(env?: Readonly<Record<string, string | undefined>>): string;
25
+ /**
26
+ * Ever Email Router plugin (inbound only).
27
+ *
28
+ * The shared Cloudflare Worker "ever-email-router" receives mail for
29
+ * `@ever.email` addresses and POSTs each message, per recipient, to
30
+ * `/api/email/inbound/ever-email-router`, signed with an HMAC-SHA256 over the
31
+ * exact raw body. The plugin verifies that signature, decodes the RFC 5322
32
+ * message with `postal-mime`, and maps it to the canonical inbound shape.
33
+ *
34
+ * It answers with counts (`inboundAck: 'counts'`): the router tells "taken"
35
+ * from "no such mailbox here" by them, and tries the next product on a drop.
36
+ */
37
+ declare class EverEmailRouterPlugin implements IEmailInboundPlugin {
38
+ readonly id = "ever-email-router";
39
+ readonly name = "Ever Email Router";
40
+ readonly version = "1.0.0";
41
+ readonly category: PluginCategory;
42
+ readonly capabilities: readonly ["email-inbound"];
43
+ readonly inboundAck: "counts";
44
+ /**
45
+ * The router delivers ONE domain, and every mailbox's mail comes from it:
46
+ * an address of this plugin must be on that domain, with one owner per
47
+ * deployment (a second registration of the same mailbox would never
48
+ * receive anything). The platform enforces both on registration.
49
+ */
50
+ get inboundAddressPolicy(): EmailInboundAddressPolicy;
51
+ readonly settingsSchema: JsonSchema;
52
+ onLoad(): Promise<void>;
53
+ onUnload(): Promise<void>;
54
+ /**
55
+ * Authenticate a delivery: `x-ever-email-signature` must carry a fresh `t` and a `v1`
56
+ * equal to HMAC-SHA256(secret, `<t>.` + the exact raw body). Throws on any failure.
57
+ */
58
+ verifyWebhookSignature(rawBody: Buffer, headers: Readonly<Record<string, string>>, options: EmailOptions): void;
59
+ /** The lower-cased envelope recipient the router delivered to (`[]` when unreadable). */
60
+ extractInboundRecipients(rawBody: Buffer, _headers: Readonly<Record<string, string>>): readonly string[];
61
+ /** Decode the delivery's RFC 5322 message into the canonical inbound shape. */
62
+ parseInboundWebhook(rawBody: Buffer, _headers: Readonly<Record<string, string>>, _options: EmailOptions): Promise<EmailInboundMessage>;
63
+ }
64
+ declare const everEmailRouterPlugin: EverEmailRouterPlugin;
65
+
66
+ export { DEFAULT_EVER_EMAIL_DOMAIN, EVER_EMAIL_MAX_SKEW_SECONDS, EVER_EMAIL_MIN_SECRET_LENGTH, EVER_EMAIL_SIGNATURE_HEADER, EverEmailRouterPlugin, everEmailDomain, everEmailRouterPlugin };
@@ -0,0 +1,66 @@
1
+ import { IEmailInboundPlugin, PluginCategory, EmailInboundAddressPolicy, JsonSchema, EmailOptions, EmailInboundMessage } from '@ever-works/plugin';
2
+
3
+ /** Header the router signs every delivery with: `t=<unix seconds>,v1=<hex HMAC-SHA256>`. */
4
+ declare const EVER_EMAIL_SIGNATURE_HEADER = "x-ever-email-signature";
5
+ /**
6
+ * Shortest secret accepted. A shorter (or absent) one refuses every webhook:
7
+ * the route is public, so a guessable secret would let anyone inject mail.
8
+ */
9
+ declare const EVER_EMAIL_MIN_SECRET_LENGTH = 24;
10
+ /**
11
+ * Most seconds between the router's signing time and ours, either way. A
12
+ * replay inside the window is harmless: the HMAC covers the whole body, so it
13
+ * can only re-deliver the same message to the same recipient, which the
14
+ * `(pluginId, providerMessageId)` unique index answers as a duplicate.
15
+ */
16
+ declare const EVER_EMAIL_MAX_SKEW_SECONDS = 300;
17
+ /** The domain the router delivers when `EVER_EMAIL_DOMAIN` is unset. */
18
+ declare const DEFAULT_EVER_EMAIL_DOMAIN = "ever.email";
19
+ /**
20
+ * The one domain the shared router delivers: `EVER_EMAIL_DOMAIN`
21
+ * (lower-cased), else {@link DEFAULT_EVER_EMAIL_DOMAIN}. Read on every call,
22
+ * so the policy follows the deployment's environment.
23
+ */
24
+ declare function everEmailDomain(env?: Readonly<Record<string, string | undefined>>): string;
25
+ /**
26
+ * Ever Email Router plugin (inbound only).
27
+ *
28
+ * The shared Cloudflare Worker "ever-email-router" receives mail for
29
+ * `@ever.email` addresses and POSTs each message, per recipient, to
30
+ * `/api/email/inbound/ever-email-router`, signed with an HMAC-SHA256 over the
31
+ * exact raw body. The plugin verifies that signature, decodes the RFC 5322
32
+ * message with `postal-mime`, and maps it to the canonical inbound shape.
33
+ *
34
+ * It answers with counts (`inboundAck: 'counts'`): the router tells "taken"
35
+ * from "no such mailbox here" by them, and tries the next product on a drop.
36
+ */
37
+ declare class EverEmailRouterPlugin implements IEmailInboundPlugin {
38
+ readonly id = "ever-email-router";
39
+ readonly name = "Ever Email Router";
40
+ readonly version = "1.0.0";
41
+ readonly category: PluginCategory;
42
+ readonly capabilities: readonly ["email-inbound"];
43
+ readonly inboundAck: "counts";
44
+ /**
45
+ * The router delivers ONE domain, and every mailbox's mail comes from it:
46
+ * an address of this plugin must be on that domain, with one owner per
47
+ * deployment (a second registration of the same mailbox would never
48
+ * receive anything). The platform enforces both on registration.
49
+ */
50
+ get inboundAddressPolicy(): EmailInboundAddressPolicy;
51
+ readonly settingsSchema: JsonSchema;
52
+ onLoad(): Promise<void>;
53
+ onUnload(): Promise<void>;
54
+ /**
55
+ * Authenticate a delivery: `x-ever-email-signature` must carry a fresh `t` and a `v1`
56
+ * equal to HMAC-SHA256(secret, `<t>.` + the exact raw body). Throws on any failure.
57
+ */
58
+ verifyWebhookSignature(rawBody: Buffer, headers: Readonly<Record<string, string>>, options: EmailOptions): void;
59
+ /** The lower-cased envelope recipient the router delivered to (`[]` when unreadable). */
60
+ extractInboundRecipients(rawBody: Buffer, _headers: Readonly<Record<string, string>>): readonly string[];
61
+ /** Decode the delivery's RFC 5322 message into the canonical inbound shape. */
62
+ parseInboundWebhook(rawBody: Buffer, _headers: Readonly<Record<string, string>>, _options: EmailOptions): Promise<EmailInboundMessage>;
63
+ }
64
+ declare const everEmailRouterPlugin: EverEmailRouterPlugin;
65
+
66
+ export { DEFAULT_EVER_EMAIL_DOMAIN, EVER_EMAIL_MAX_SKEW_SECONDS, EVER_EMAIL_MIN_SECRET_LENGTH, EVER_EMAIL_SIGNATURE_HEADER, EverEmailRouterPlugin, everEmailDomain, everEmailRouterPlugin };