mailery 0.0.0 → 0.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.
@@ -1,3 +1,64 @@
1
- declare const TESTING_PLACEHOLDER = true;
1
+ import { Db } from 'mongodb';
2
+ import { C as ContactAdapter, a as Contact, A as AdapterFilter, c as Mailer, q as NullProvider } from './null-7gnz1V98.cjs';
3
+ import 'ioredis';
4
+ import 'zod';
5
+ import 'handlebars';
2
6
 
3
- export { TESTING_PLACEHOLDER };
7
+ /**
8
+ * MemoryContactAdapter — drop-in in-process ContactAdapter for tests.
9
+ * Hold contacts in a Map; everything operates synchronously over RAM.
10
+ */
11
+
12
+ declare class MemoryContactAdapter implements ContactAdapter {
13
+ private readonly byId;
14
+ constructor(initial?: Contact[]);
15
+ upsert(contact: Contact): void;
16
+ delete(externalId: string): void;
17
+ getById(externalId: string): Promise<Contact | null>;
18
+ getByEmail(email: string): Promise<Contact | null>;
19
+ getBatch(externalIds: string[]): Promise<Map<string, Contact>>;
20
+ query(filter: AdapterFilter, opts: {
21
+ limit: number;
22
+ cursor?: string;
23
+ }): Promise<{
24
+ contacts: Contact[];
25
+ nextCursor?: string;
26
+ }>;
27
+ count(filter: AdapterFilter): Promise<number>;
28
+ addTags(externalId: string, tags: string[]): Promise<void>;
29
+ removeTags(externalId: string, tags: string[]): Promise<void>;
30
+ }
31
+
32
+ /**
33
+ * Test helpers — `import { ... } from 'mailery/testing'`.
34
+ *
35
+ * const harness = await createTestMailer({ seedContacts: [...] })
36
+ * await harness.mailer.upsertSubscription({ externalId: 'u1', source: 'test' })
37
+ * await harness.mailer.fire('Created', 'u1')
38
+ * // drive the runner directly:
39
+ * const { runTick, processOneRunStep, dispatchSend } = await import('mailery')
40
+ * await runTick(harness.mailer.getRunnerContext())
41
+ * expect(harness.provider.sent.length).toBe(1)
42
+ * await harness.stop()
43
+ *
44
+ * Backed by mongodb-memory-server + ioredis-mock + NullProvider.
45
+ */
46
+
47
+ interface TestMailerOptions {
48
+ adapter?: ContactAdapter;
49
+ seedContacts?: Contact[];
50
+ provider?: NullProvider;
51
+ /** Override Mailer config (excluding required fields the harness fills in). */
52
+ config?: Partial<Omit<Parameters<typeof Mailer.init>[0], 'db' | 'adapter' | 'redis' | 'providers' | 'defaultProvider'>>;
53
+ }
54
+ interface TestMailerHarness {
55
+ mailer: Mailer;
56
+ db: Db;
57
+ provider: NullProvider;
58
+ adapter: ContactAdapter;
59
+ memoryAdapter: MemoryContactAdapter | null;
60
+ stop: () => Promise<void>;
61
+ }
62
+ declare function createTestMailer(opts?: TestMailerOptions): Promise<TestMailerHarness>;
63
+
64
+ export { MemoryContactAdapter, NullProvider, type TestMailerHarness, type TestMailerOptions, createTestMailer };
package/dist/testing.d.ts CHANGED
@@ -1,3 +1,64 @@
1
- declare const TESTING_PLACEHOLDER = true;
1
+ import { Db } from 'mongodb';
2
+ import { C as ContactAdapter, a as Contact, A as AdapterFilter, c as Mailer, q as NullProvider } from './null-7gnz1V98.js';
3
+ import 'ioredis';
4
+ import 'zod';
5
+ import 'handlebars';
2
6
 
3
- export { TESTING_PLACEHOLDER };
7
+ /**
8
+ * MemoryContactAdapter — drop-in in-process ContactAdapter for tests.
9
+ * Hold contacts in a Map; everything operates synchronously over RAM.
10
+ */
11
+
12
+ declare class MemoryContactAdapter implements ContactAdapter {
13
+ private readonly byId;
14
+ constructor(initial?: Contact[]);
15
+ upsert(contact: Contact): void;
16
+ delete(externalId: string): void;
17
+ getById(externalId: string): Promise<Contact | null>;
18
+ getByEmail(email: string): Promise<Contact | null>;
19
+ getBatch(externalIds: string[]): Promise<Map<string, Contact>>;
20
+ query(filter: AdapterFilter, opts: {
21
+ limit: number;
22
+ cursor?: string;
23
+ }): Promise<{
24
+ contacts: Contact[];
25
+ nextCursor?: string;
26
+ }>;
27
+ count(filter: AdapterFilter): Promise<number>;
28
+ addTags(externalId: string, tags: string[]): Promise<void>;
29
+ removeTags(externalId: string, tags: string[]): Promise<void>;
30
+ }
31
+
32
+ /**
33
+ * Test helpers — `import { ... } from 'mailery/testing'`.
34
+ *
35
+ * const harness = await createTestMailer({ seedContacts: [...] })
36
+ * await harness.mailer.upsertSubscription({ externalId: 'u1', source: 'test' })
37
+ * await harness.mailer.fire('Created', 'u1')
38
+ * // drive the runner directly:
39
+ * const { runTick, processOneRunStep, dispatchSend } = await import('mailery')
40
+ * await runTick(harness.mailer.getRunnerContext())
41
+ * expect(harness.provider.sent.length).toBe(1)
42
+ * await harness.stop()
43
+ *
44
+ * Backed by mongodb-memory-server + ioredis-mock + NullProvider.
45
+ */
46
+
47
+ interface TestMailerOptions {
48
+ adapter?: ContactAdapter;
49
+ seedContacts?: Contact[];
50
+ provider?: NullProvider;
51
+ /** Override Mailer config (excluding required fields the harness fills in). */
52
+ config?: Partial<Omit<Parameters<typeof Mailer.init>[0], 'db' | 'adapter' | 'redis' | 'providers' | 'defaultProvider'>>;
53
+ }
54
+ interface TestMailerHarness {
55
+ mailer: Mailer;
56
+ db: Db;
57
+ provider: NullProvider;
58
+ adapter: ContactAdapter;
59
+ memoryAdapter: MemoryContactAdapter | null;
60
+ stop: () => Promise<void>;
61
+ }
62
+ declare function createTestMailer(opts?: TestMailerOptions): Promise<TestMailerHarness>;
63
+
64
+ export { MemoryContactAdapter, NullProvider, type TestMailerHarness, type TestMailerOptions, createTestMailer };