@tgoliveira/outpost 1.1.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 (54) hide show
  1. package/AGENTS.md +268 -0
  2. package/LICENSE +21 -0
  3. package/README.md +117 -0
  4. package/dist/adapters/drizzle/index.cjs +405 -0
  5. package/dist/adapters/drizzle/index.cjs.map +1 -0
  6. package/dist/adapters/drizzle/index.d.cts +1765 -0
  7. package/dist/adapters/drizzle/index.d.ts +1765 -0
  8. package/dist/adapters/drizzle/index.js +387 -0
  9. package/dist/adapters/drizzle/index.js.map +1 -0
  10. package/dist/adapters/index.cjs +584 -0
  11. package/dist/adapters/index.cjs.map +1 -0
  12. package/dist/adapters/index.d.cts +232 -0
  13. package/dist/adapters/index.d.ts +232 -0
  14. package/dist/adapters/index.js +565 -0
  15. package/dist/adapters/index.js.map +1 -0
  16. package/dist/fake-BY6t7UXb.d.cts +30 -0
  17. package/dist/fake-en-oOdg0.d.ts +30 -0
  18. package/dist/http/index.cjs +224 -0
  19. package/dist/http/index.cjs.map +1 -0
  20. package/dist/http/index.d.cts +49 -0
  21. package/dist/http/index.d.ts +49 -0
  22. package/dist/http/index.js +221 -0
  23. package/dist/http/index.js.map +1 -0
  24. package/dist/index-CVUvaJms.d.ts +179 -0
  25. package/dist/index-Dmt-aLH2.d.cts +179 -0
  26. package/dist/index.cjs +1387 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/index.d.cts +153 -0
  29. package/dist/index.d.ts +153 -0
  30. package/dist/index.js +1331 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/outpost-client-yUijE00q.d.cts +271 -0
  33. package/dist/outpost-client-ymTJISpu.d.ts +271 -0
  34. package/dist/repositories-Bck6wJNS.d.ts +180 -0
  35. package/dist/repositories-DhUe8f2R.d.cts +180 -0
  36. package/dist/services-CQINhAGo.d.cts +90 -0
  37. package/dist/services-CfTEsetF.d.ts +90 -0
  38. package/dist/template-CREUq7bB.d.ts +260 -0
  39. package/dist/template-DxI_p2Ny.d.cts +260 -0
  40. package/dist/testing/index.cjs +321 -0
  41. package/dist/testing/index.cjs.map +1 -0
  42. package/dist/testing/index.d.cts +97 -0
  43. package/dist/testing/index.d.ts +97 -0
  44. package/dist/testing/index.js +312 -0
  45. package/dist/testing/index.js.map +1 -0
  46. package/dist/webhook-kp6CiXk-.d.cts +149 -0
  47. package/dist/webhook-kp6CiXk-.d.ts +149 -0
  48. package/dist/workers/index.cjs +430 -0
  49. package/dist/workers/index.cjs.map +1 -0
  50. package/dist/workers/index.d.cts +5 -0
  51. package/dist/workers/index.d.ts +5 -0
  52. package/dist/workers/index.js +427 -0
  53. package/dist/workers/index.js.map +1 -0
  54. package/package.json +114 -0
@@ -0,0 +1,153 @@
1
+ import { E as Encryptor, C as ConfigOverrides, R as RateLimitConfig, T as TemplateRenderer, M as MxResolver } from './template-CREUq7bB.js';
2
+ export { A as AttachmentPolicy, a as AttachmentSpec, D as DEFAULT_ATTACHMENT_POLICY, b as DEFAULT_DOMAIN_VALIDATION, c as DEFAULT_RETENTION, d as DEFAULT_RETRY, e as DEFAULT_SANITIZE_LIMITS, f as DomainValidationConfig, g as MxCache, h as RateBudget, i as RecipientHasher, j as RenderedTemplate, k as ResolvedConfig, l as RetentionPolicy, m as RetryConfig, S as SanitizeLimits, n as assertBodyWithinLimits, o as assertNoHeaderInjection, p as backoffMs, q as extractDomain, r as isExhausted, s as nextAttemptAt, t as purgeCutoff, u as resolveConfig, v as sanitizeHeaders, w as sanitizeRecipient, x as sanitizeSubject, y as stripDangerousHtml, z as validateAttachment, B as validateRecipient, F as validateSyntax } from './template-CREUq7bB.js';
3
+ import { O as Outpost } from './outpost-client-ymTJISpu.js';
4
+ export { A as AuthContext, a as Authenticate, C as CreatedApiKey, E as EnqueueInput, b as EnqueueMessage, c as EnqueueResult, G as GetMessage, I as IngestWebhook, d as IngestWebhookResult, L as ListMessages, M as ManageApiKey, e as ManageSuppression, f as MessageView, R as ReplayMessage, g as generateApiKeySecret, h as hashApiKey, t as toView } from './outpost-client-ymTJISpu.js';
5
+ import { O as OutboxRepository, S as SuppressionRepository, A as AuditRepository, a as ApiKeyRepository, W as WebhookEventRepository } from './repositories-Bck6wJNS.js';
6
+ export { b as API_SCOPES, c as ApiKey, d as ApiScope, e as AuditEvent, f as AuditEventType, L as ListMessagesQuery, M as MessageStatePatch, N as NewApiKey, g as NewAuditEvent, h as NewMessage, i as SUPPRESSION_REASONS, j as SuppressionEntry, k as SuppressionReason, l as hasScope, m as isKeyActive } from './repositories-Bck6wJNS.js';
7
+ import { E as EmailProvider, T as Telemetry, L as Logger, C as Clock, I as IdGenerator, a as RateLimiter } from './services-CfTEsetF.js';
8
+ export { b as LogLevel, P as ProviderReceipt, c as RateLimitScope, R as RawWebhook } from './services-CfTEsetF.js';
9
+ export { D as DispatchableMessage, L as LIFECYCLE_STATES, a as LifecycleState, M as Message, b as MessageBody, S as Sealed, T as TERMINAL_STATES, W as WebhookEvent, c as WebhookEventType, d as canTransition, i as isTerminal, s as shouldSuppressOn, w as webhookToState } from './webhook-kp6CiXk-.js';
10
+ export { C as CoreDeps, D as DispatchMessage, a as DispatchOutcome, P as PurgeReport, b as PurgeRetention } from './index-CVUvaJms.js';
11
+
12
+ /**
13
+ * Encryption posture (TDR §5.4). Pick one:
14
+ *
15
+ * - `none` — encryption disabled (`alg: "plain"`). Dev default.
16
+ * - `symmetric` — AES-256-GCM; one 32-byte key seals and opens. Simple,
17
+ * single-process. Key MUST come from KMS/secrets.
18
+ * - `asymmetric` — least-privilege split: the web tier seals with the
19
+ * PUBLIC key and can never read back; the send worker opens
20
+ * with the PRIVATE key. Omit `privateKey` on the web tier.
21
+ * - bring-your-own `Encryptor` pair — back it with AWS KMS / GCP KMS / Vault.
22
+ */
23
+ type EncryptionOptions = {
24
+ mode: "none";
25
+ } | {
26
+ mode: "symmetric";
27
+ key: Buffer | string;
28
+ keyId?: string;
29
+ } | {
30
+ mode: "asymmetric";
31
+ publicKey: string;
32
+ privateKey?: string;
33
+ keyId?: string;
34
+ } | {
35
+ sealEncryptor: Encryptor;
36
+ openEncryptor: Encryptor;
37
+ };
38
+ interface OutpostOptions extends ConfigOverrides {
39
+ /**
40
+ * Persistence. Build these from your Drizzle db via the helpers in
41
+ * `@tgoliveira/outpost/drizzle`, or use the in-memory ones from
42
+ * `@tgoliveira/outpost/testing`.
43
+ */
44
+ repositories: {
45
+ outbox: OutboxRepository;
46
+ suppressions: SuppressionRepository;
47
+ audit: AuditRepository;
48
+ apiKeys: ApiKeyRepository;
49
+ webhookEvents: WebhookEventRepository;
50
+ };
51
+ /** One or more transport adapters. The first is the default unless overridden. */
52
+ providers: EmailProvider[];
53
+ defaultProvider?: string;
54
+ /**
55
+ * Key for the deterministic recipient HMAC (TDR §5.4). REQUIRED — it backs
56
+ * suppression matching and recipient-keyed lookups even when encryption is
57
+ * off. Must be ≥16 bytes of entropy and live OUTSIDE the database.
58
+ */
59
+ recipientHmacKey: string | Buffer;
60
+ /** Encryption-at-rest posture. Defaults to `{ mode: "none" }`. */
61
+ encryption?: EncryptionOptions;
62
+ rateLimits?: RateLimitConfig;
63
+ /** Template renderer (e.g. InMemoryTemplateRenderer). Optional. */
64
+ templates?: TemplateRenderer;
65
+ /** Pre-built telemetry. For OTel: `telemetry: await OtelTelemetry.create()`. */
66
+ telemetry?: Telemetry;
67
+ logger?: Logger;
68
+ clock?: Clock;
69
+ ids?: IdGenerator;
70
+ rateLimiter?: RateLimiter;
71
+ mxResolver?: MxResolver;
72
+ /** Strong HTML sanitizer (e.g. sanitize-html). Falls back to a built-in. */
73
+ sanitizeHtml?: (html: string) => string;
74
+ /** Random source for retry jitter. Defaults to Math.random. */
75
+ random?: () => number;
76
+ /** Default audit actor for programmatic calls. Default "programmatic". */
77
+ defaultActor?: string;
78
+ }
79
+ /**
80
+ * Composition root (TDR §6, Dependency Inversion). Resolves config, wires the
81
+ * adapters into a `CoreDeps`, and returns the high-level `Outpost` client.
82
+ *
83
+ * This is the ONLY place concrete adapters are assembled — everything inward
84
+ * depends on ports. Swapping a provider, storage backend, or KMS is a change
85
+ * here, never in the core.
86
+ */
87
+ declare function createOutpost(options: OutpostOptions): Outpost;
88
+
89
+ /**
90
+ * Domain error taxonomy.
91
+ *
92
+ * Errors are classified so the dispatch pipeline can decide retry vs. fail
93
+ * without inspecting provider-specific error shapes (TDR §3.4). Adapters map
94
+ * their native errors onto these classes; the core never sees raw SDK errors.
95
+ */
96
+ type ErrorClass = "transient" | "permanent";
97
+ /** Base class for all errors Outpost raises. Carries a stable machine `code`. */
98
+ declare class OutpostError extends Error {
99
+ readonly code: string;
100
+ constructor(code: string, message: string, options?: {
101
+ cause?: unknown;
102
+ });
103
+ }
104
+ /** A request failed authentication (missing/expired/revoked key). → HTTP 401. */
105
+ declare class UnauthorizedError extends OutpostError {
106
+ constructor(message?: string);
107
+ }
108
+ /** A valid key lacked the required scope. → HTTP 403. */
109
+ declare class ForbiddenError extends OutpostError {
110
+ constructor(message?: string);
111
+ }
112
+ /** Caller input failed validation/sanitization. Never retried. → HTTP 400. */
113
+ declare class ValidationError extends OutpostError {
114
+ readonly details?: unknown;
115
+ constructor(message: string, details?: unknown);
116
+ }
117
+ /** A referenced resource does not exist. → HTTP 404. */
118
+ declare class NotFoundError extends OutpostError {
119
+ constructor(message?: string);
120
+ }
121
+ /** A lifecycle transition violated the state machine. Programming/state bug. */
122
+ declare class InvalidStateTransitionError extends OutpostError {
123
+ constructor(from: string, to: string);
124
+ }
125
+ /** Webhook signature verification failed. → HTTP 401, logged. */
126
+ declare class WebhookVerificationError extends OutpostError {
127
+ constructor(message?: string);
128
+ }
129
+ /**
130
+ * Raised by `EmailProvider` implementations. The `errorClass` drives retry:
131
+ * `transient` errors go back to the queue with backoff; `permanent` errors go
132
+ * straight to `failed` and the Dead Letter Queue.
133
+ */
134
+ declare class ProviderError extends OutpostError {
135
+ readonly errorClass: ErrorClass;
136
+ readonly providerCode?: string;
137
+ constructor(errorClass: ErrorClass, message: string, options?: {
138
+ providerCode?: string;
139
+ cause?: unknown;
140
+ });
141
+ static transient(message: string, options?: {
142
+ providerCode?: string;
143
+ cause?: unknown;
144
+ }): ProviderError;
145
+ static permanent(message: string, options?: {
146
+ providerCode?: string;
147
+ cause?: unknown;
148
+ }): ProviderError;
149
+ }
150
+ /** Returns true when an unknown thrown value should be treated as retryable. */
151
+ declare function isTransient(err: unknown): boolean;
152
+
153
+ export { ApiKeyRepository, AuditRepository, Clock, ConfigOverrides, EmailProvider, type EncryptionOptions, Encryptor, type ErrorClass, ForbiddenError, IdGenerator, InvalidStateTransitionError, Logger, MxResolver, NotFoundError, OutboxRepository, Outpost, OutpostError, type OutpostOptions, ProviderError, RateLimitConfig, RateLimiter, SuppressionRepository, Telemetry, TemplateRenderer, UnauthorizedError, ValidationError, WebhookEventRepository, WebhookVerificationError, createOutpost, isTransient };