@crvouga/mockingbird-service-resend 3.0.0 → 3.2.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.
package/dist/server.d.ts CHANGED
@@ -1,34 +1,16 @@
1
1
  import { Server } from 'node:http';
2
2
  import { Hono } from 'hono';
3
3
 
4
- /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
5
- type SqliteValue$2 = null | number | bigint | string | Uint8Array | boolean;
6
- /** Mutation counters returned by {@link SqliteStatement.run}. */
7
- type SqliteRunResult$2 = {
8
- changes: number;
9
- lastInsertRowid: number | bigint;
4
+ type MountedAPI$1 = FetchAPI$2 & {
5
+ readonly prefix: string;
6
+ GET: FetchHandler$1;
7
+ POST: FetchHandler$1;
8
+ PUT: FetchHandler$1;
9
+ PATCH: FetchHandler$1;
10
+ DELETE: FetchHandler$1;
11
+ HEAD: FetchHandler$1;
12
+ OPTIONS: FetchHandler$1;
10
13
  };
11
- /**
12
- * Prepared statement bound to a {@link SqliteClient}.
13
- *
14
- * Pass bind values as rest arguments on each call (no sticky `bind()`).
15
- */
16
- interface SqliteStatement$2 {
17
- run(...params: SqliteValue$2[]): SqliteRunResult$2;
18
- all<T = Record<string, unknown>>(...params: SqliteValue$2[]): T[];
19
- get<T = Record<string, unknown>>(...params: SqliteValue$2[]): T | undefined;
20
- }
21
- /**
22
- * Sync SQLite client port owned by Mockingbird.
23
- *
24
- * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
25
- * `bun:sqlite` instances all work when they expose this surface.
26
- */
27
- interface SqliteClient$2 {
28
- exec(sql: string): void;
29
- prepare(sql: string): SqliteStatement$2;
30
- transaction<T>(fn: () => T): T;
31
- }
32
14
 
33
15
  /** A stable identifier for a point in a {@link Timeline}. */
34
16
  type CheckpointId$1 = string;
@@ -119,6 +101,37 @@ declare class Timeline$1<T> {
119
101
  interface FetchAPI$2 {
120
102
  fetch(request: Request): Promise<Response>;
121
103
  }
104
+ /** A bare function form of {@link FetchAPI}, compatible with `Bun.serve`, workerd, and Deno. */
105
+ type FetchHandler$1 = (request: Request) => Promise<Response>;
106
+
107
+ /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
108
+ type SqliteValue$3 = null | number | bigint | string | Uint8Array | boolean;
109
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
110
+ type SqliteRunResult$3 = {
111
+ changes: number;
112
+ lastInsertRowid: number | bigint;
113
+ };
114
+ /**
115
+ * Prepared statement bound to a {@link SqliteClient}.
116
+ *
117
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
118
+ */
119
+ interface SqliteStatement$3 {
120
+ run(...params: SqliteValue$3[]): SqliteRunResult$3;
121
+ all<T = Record<string, unknown>>(...params: SqliteValue$3[]): T[];
122
+ get<T = Record<string, unknown>>(...params: SqliteValue$3[]): T | undefined;
123
+ }
124
+ /**
125
+ * Sync SQLite client port owned by Mockingbird.
126
+ *
127
+ * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
128
+ * `bun:sqlite` instances all work when they expose this surface.
129
+ */
130
+ interface SqliteClient$3 {
131
+ exec(sql: string): void;
132
+ prepare(sql: string): SqliteStatement$3;
133
+ transaction<T>(fn: () => T): T;
134
+ }
122
135
 
123
136
  /**
124
137
  * The single source of time for a service.
@@ -535,7 +548,9 @@ type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$2 & {
535
548
  /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
536
549
  stop?(): void;
537
550
  readonly name: string;
538
- readonly sqlite: SqliteClient$2;
551
+ /** Same-origin Fetch handler and App Router method exports, sharing this runtime. */
552
+ mount(prefix: string): MountedAPI$1;
553
+ readonly sqlite: SqliteClient$3;
539
554
  readonly clock: Clock$1;
540
555
  readonly faults: FaultRegistry$1;
541
556
  readonly metrics: Metrics$1;
@@ -601,6 +616,9 @@ type CommonServeOptions = {
601
616
  adminKey: string | undefined;
602
617
  seed: string | undefined;
603
618
  onLog: ((entry: RequestLog$1) => void) | undefined;
619
+ /** Synthetic provider fixture objects supplied by a fleet entry. */
620
+ fixtures?: Record<string, unknown>;
621
+ baseUrl?: string;
604
622
  };
605
623
  /**
606
624
  * What a service contributes to `serve`: how to build its runtime from CLI flags,
@@ -619,76 +637,16 @@ type ServeTarget = {
619
637
  listening?(server: Listening): void;
620
638
  };
621
639
 
622
- /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
623
- type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
624
- /** Mutation counters returned by {@link SqliteStatement.run}. */
625
- type SqliteRunResult$1 = {
626
- changes: number;
627
- lastInsertRowid: number | bigint;
640
+ type MountedAPI = FetchAPI$1 & {
641
+ readonly prefix: string;
642
+ GET: FetchHandler;
643
+ POST: FetchHandler;
644
+ PUT: FetchHandler;
645
+ PATCH: FetchHandler;
646
+ DELETE: FetchHandler;
647
+ HEAD: FetchHandler;
648
+ OPTIONS: FetchHandler;
628
649
  };
629
- /**
630
- * Prepared statement bound to a {@link SqliteClient}.
631
- *
632
- * Pass bind values as rest arguments on each call (no sticky `bind()`).
633
- */
634
- interface SqliteStatement$1 {
635
- run(...params: SqliteValue$1[]): SqliteRunResult$1;
636
- all<T = Record<string, unknown>>(...params: SqliteValue$1[]): T[];
637
- get<T = Record<string, unknown>>(...params: SqliteValue$1[]): T | undefined;
638
- }
639
- /**
640
- * Sync SQLite client port owned by Mockingbird.
641
- *
642
- * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
643
- * `bun:sqlite` instances all work when they expose this surface.
644
- */
645
- interface SqliteClient$1 {
646
- exec(sql: string): void;
647
- prepare(sql: string): SqliteStatement$1;
648
- transaction<T>(fn: () => T): T;
649
- }
650
-
651
- /** Every stored record carries a monotonically increasing sequence for stable ordering. */
652
- type Stored<T> = {
653
- seq: number;
654
- value: T;
655
- };
656
- type ListRecordsOptions<T> = {
657
- /** Keep only records passing the predicate. */
658
- where?: (value: T, seq: number) => boolean;
659
- /** Sort order; default newest first. */
660
- order?: "newest" | "oldest";
661
- };
662
- /**
663
- * A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
664
- * sequence, never by id lexicographic order, so list semantics stay stable.
665
- */
666
- declare class Collection<T> {
667
- private readonly sqlite;
668
- /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
669
- readonly namespace: string;
670
- /** Table name inside the namespace. Stable across resets of the rows themselves. */
671
- readonly collectionName: string;
672
- constructor(sqlite: SqliteClient$1,
673
- /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
674
- namespace: string,
675
- /** Table name inside the namespace. Stable across resets of the rows themselves. */
676
- collectionName: string);
677
- private bumpCollectionSeq;
678
- nextSequence(): number;
679
- get(id: string): T | undefined;
680
- has(id: string): boolean;
681
- /** Insert a new record, assigning it the next sequence number. */
682
- insert(id: string, value: T): Stored<T>;
683
- /** Replace an existing record's value, keeping its position. */
684
- update(id: string, value: T): Stored<T> | undefined;
685
- delete(id: string): boolean;
686
- /** How many records the collection holds, without reading them. */
687
- count(): number;
688
- list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
689
- id: string;
690
- }>;
691
- }
692
650
 
693
651
  /** A stable identifier for a point in a {@link Timeline}. */
694
652
  type CheckpointId = string;
@@ -779,11 +737,84 @@ declare class Timeline<T> {
779
737
  interface FetchAPI$1 {
780
738
  fetch(request: Request): Promise<Response>;
781
739
  }
740
+ /** A bare function form of {@link FetchAPI}, compatible with `Bun.serve`, workerd, and Deno. */
741
+ type FetchHandler = (request: Request) => Promise<Response>;
742
+
743
+ /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
744
+ type SqliteValue$2 = null | number | bigint | string | Uint8Array | boolean;
745
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
746
+ type SqliteRunResult$2 = {
747
+ changes: number;
748
+ lastInsertRowid: number | bigint;
749
+ };
750
+ /**
751
+ * Prepared statement bound to a {@link SqliteClient}.
752
+ *
753
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
754
+ */
755
+ interface SqliteStatement$2 {
756
+ run(...params: SqliteValue$2[]): SqliteRunResult$2;
757
+ all<T = Record<string, unknown>>(...params: SqliteValue$2[]): T[];
758
+ get<T = Record<string, unknown>>(...params: SqliteValue$2[]): T | undefined;
759
+ }
760
+ /**
761
+ * Sync SQLite client port owned by Mockingbird.
762
+ *
763
+ * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
764
+ * `bun:sqlite` instances all work when they expose this surface.
765
+ */
766
+ interface SqliteClient$2 {
767
+ exec(sql: string): void;
768
+ prepare(sql: string): SqliteStatement$2;
769
+ transaction<T>(fn: () => T): T;
770
+ }
771
+
772
+ /** Every stored record carries a monotonically increasing sequence for stable ordering. */
773
+ type Stored<T> = {
774
+ seq: number;
775
+ value: T;
776
+ };
777
+ type ListRecordsOptions<T> = {
778
+ /** Keep only records passing the predicate. */
779
+ where?: (value: T, seq: number) => boolean;
780
+ /** Sort order; default newest first. */
781
+ order?: "newest" | "oldest";
782
+ };
783
+ /**
784
+ * A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
785
+ * sequence, never by id lexicographic order, so list semantics stay stable.
786
+ */
787
+ declare class Collection<T> {
788
+ private readonly sqlite;
789
+ /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
790
+ readonly namespace: string;
791
+ /** Table name inside the namespace. Stable across resets of the rows themselves. */
792
+ readonly collectionName: string;
793
+ constructor(sqlite: SqliteClient$2,
794
+ /** Storage namespace. Admin introspection uses this to ignore another namespace's tables. */
795
+ namespace: string,
796
+ /** Table name inside the namespace. Stable across resets of the rows themselves. */
797
+ collectionName: string);
798
+ private bumpCollectionSeq;
799
+ nextSequence(): number;
800
+ get(id: string): T | undefined;
801
+ has(id: string): boolean;
802
+ /** Insert a new record, assigning it the next sequence number. */
803
+ insert(id: string, value: T): Stored<T>;
804
+ /** Replace an existing record's value, keeping its position. */
805
+ update(id: string, value: T): Stored<T> | undefined;
806
+ delete(id: string): boolean;
807
+ /** How many records the collection holds, without reading them. */
808
+ count(): number;
809
+ list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
810
+ id: string;
811
+ }>;
812
+ }
782
813
 
783
814
  /** Options every provider constructor accepts. */
784
- type APIOptions = {
815
+ type APIOptions$1 = {
785
816
  /** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
786
- sqlite?: SqliteClient$1;
817
+ sqlite?: SqliteClient$2;
787
818
  /** Clock used for `created`-style fields. Default `Date.now`. */
788
819
  now?: () => number;
789
820
  /**
@@ -1067,7 +1098,7 @@ type IdempotencyErrors = {
1067
1098
  declare class IdempotencyStore {
1068
1099
  private readonly namespace;
1069
1100
  private readonly responses;
1070
- constructor(sqlite: SqliteClient$1, namespace: string, name?: string);
1101
+ constructor(sqlite: SqliteClient$2, namespace: string, name?: string);
1071
1102
  /**
1072
1103
  * Run `handler` once per `key`. `fingerprint` identifies the request's parameters (e.g.
1073
1104
  * the method, path and canonical body). Only `replayable` responses are stored (default:
@@ -1226,7 +1257,9 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
1226
1257
  /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
1227
1258
  stop?(): void;
1228
1259
  readonly name: string;
1229
- readonly sqlite: SqliteClient$1;
1260
+ /** Same-origin Fetch handler and App Router method exports, sharing this runtime. */
1261
+ mount(prefix: string): MountedAPI;
1262
+ readonly sqlite: SqliteClient$2;
1230
1263
  readonly clock: Clock;
1231
1264
  readonly faults: FaultRegistry;
1232
1265
  readonly metrics: Metrics;
@@ -1293,7 +1326,7 @@ type OutboxQuery = {
1293
1326
  };
1294
1327
  declare class OutboxStore<T extends OutboxItem = OutboxItem> {
1295
1328
  private readonly items;
1296
- constructor(sqlite: SqliteClient$1, namespace: string, name?: string);
1329
+ constructor(sqlite: SqliteClient$2, namespace: string, name?: string);
1297
1330
  record(item: T): T;
1298
1331
  get(id: string): T | undefined;
1299
1332
  update(id: string, item: T): void;
@@ -1302,9 +1335,9 @@ declare class OutboxStore<T extends OutboxItem = OutboxItem> {
1302
1335
  }
1303
1336
 
1304
1337
  /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
1305
- type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
1338
+ type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
1306
1339
  /** Mutation counters returned by {@link SqliteStatement.run}. */
1307
- type SqliteRunResult = {
1340
+ type SqliteRunResult$1 = {
1308
1341
  changes: number;
1309
1342
  lastInsertRowid: number | bigint;
1310
1343
  };
@@ -1313,10 +1346,10 @@ type SqliteRunResult = {
1313
1346
  *
1314
1347
  * Pass bind values as rest arguments on each call (no sticky `bind()`).
1315
1348
  */
1316
- interface SqliteStatement {
1317
- run(...params: SqliteValue[]): SqliteRunResult;
1318
- all<T = Record<string, unknown>>(...params: SqliteValue[]): T[];
1319
- get<T = Record<string, unknown>>(...params: SqliteValue[]): T | undefined;
1349
+ interface SqliteStatement$1 {
1350
+ run(...params: SqliteValue$1[]): SqliteRunResult$1;
1351
+ all<T = Record<string, unknown>>(...params: SqliteValue$1[]): T[];
1352
+ get<T = Record<string, unknown>>(...params: SqliteValue$1[]): T | undefined;
1320
1353
  }
1321
1354
  /**
1322
1355
  * Sync SQLite client port owned by Mockingbird.
@@ -1324,9 +1357,9 @@ interface SqliteStatement {
1324
1357
  * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
1325
1358
  * `bun:sqlite` instances all work when they expose this surface.
1326
1359
  */
1327
- interface SqliteClient {
1360
+ interface SqliteClient$1 {
1328
1361
  exec(sql: string): void;
1329
- prepare(sql: string): SqliteStatement;
1362
+ prepare(sql: string): SqliteStatement$1;
1330
1363
  transaction<T>(fn: () => T): T;
1331
1364
  }
1332
1365
 
@@ -1340,6 +1373,91 @@ interface FetchAPI {
1340
1373
  fetch(request: Request): Promise<Response>;
1341
1374
  }
1342
1375
 
1376
+ /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
1377
+ type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
1378
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
1379
+ type SqliteRunResult = {
1380
+ changes: number;
1381
+ lastInsertRowid: number | bigint;
1382
+ };
1383
+ /**
1384
+ * Prepared statement bound to a {@link SqliteClient}.
1385
+ *
1386
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
1387
+ */
1388
+ interface SqliteStatement {
1389
+ run(...params: SqliteValue[]): SqliteRunResult;
1390
+ all<T = Record<string, unknown>>(...params: SqliteValue[]): T[];
1391
+ get<T = Record<string, unknown>>(...params: SqliteValue[]): T | undefined;
1392
+ }
1393
+ /**
1394
+ * Sync SQLite client port owned by Mockingbird.
1395
+ *
1396
+ * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
1397
+ * `bun:sqlite` instances all work when they expose this surface.
1398
+ */
1399
+ interface SqliteClient {
1400
+ exec(sql: string): void;
1401
+ prepare(sql: string): SqliteStatement;
1402
+ transaction<T>(fn: () => T): T;
1403
+ }
1404
+
1405
+ /** Options every provider constructor accepts. */
1406
+ type APIOptions = {
1407
+ /** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
1408
+ sqlite?: SqliteClient;
1409
+ /** Clock used for `created`-style fields. Default `Date.now`. */
1410
+ now?: () => number;
1411
+ /**
1412
+ * Storage namespace for this instance's records. Instances sharing one SQLite
1413
+ * client stay isolated when their namespaces differ. Defaults to the service name.
1414
+ */
1415
+ namespace?: string;
1416
+ };
1417
+
1418
+ interface AuthUser {
1419
+ login: string;
1420
+ id: number;
1421
+ scopes: string[];
1422
+ installation?: AuthInstallation;
1423
+ }
1424
+ interface AuthInstallation {
1425
+ installationId: number;
1426
+ appId: number;
1427
+ accountId: number;
1428
+ accountType: "User" | "Organization";
1429
+ permissions: Record<string, string>;
1430
+ repositoryIds: number[];
1431
+ repositorySelection: "all" | "selected";
1432
+ }
1433
+ interface AuthFallback {
1434
+ login: string;
1435
+ id: number;
1436
+ scopes: string[];
1437
+ }
1438
+
1439
+ interface ResendSeedConfig {
1440
+ port?: number;
1441
+ domains?: Array<{
1442
+ name: string;
1443
+ region?: string;
1444
+ }>;
1445
+ contacts?: Array<{
1446
+ email: string;
1447
+ first_name?: string;
1448
+ last_name?: string;
1449
+ audience?: string;
1450
+ }>;
1451
+ }
1452
+
1453
+ type ProviderOptions = APIOptions & {
1454
+ baseUrl?: string;
1455
+ tokens?: Record<string, AuthUser>;
1456
+ fallbackUser?: AuthFallback;
1457
+ publicNamespace?: string;
1458
+ adminPrefix?: string;
1459
+ };
1460
+
1343
1461
  /**
1344
1462
  * One email the app "sent" (`POST /emails`): what `GET /__admin/outbox` returns. `to`, `cc` and
1345
1463
  * `bcc` hold bare lower-cased addresses (so `?to=` matches `Name <a@b.co>` recipients);
@@ -1369,6 +1487,7 @@ type SentEmail = {
1369
1487
  idempotencyKey: string | null;
1370
1488
  scheduledAt: string | null;
1371
1489
  createdAt: string;
1490
+ lastEvent?: string;
1372
1491
  };
1373
1492
  type ReceivedAttachmentRecord = {
1374
1493
  id: string;
@@ -1405,7 +1524,7 @@ declare class ResendState {
1405
1524
  }>;
1406
1525
  readonly idempotency: IdempotencyStore;
1407
1526
  private readonly ids;
1408
- constructor(sqlite: SqliteClient, namespace: string);
1527
+ constructor(sqlite: SqliteClient$1, namespace: string);
1409
1528
  /** A UUID-shaped id, deterministic for a given history (Resend ids are UUIDs). */
1410
1529
  nextId(kind: "email" | "received" | "attachment"): string;
1411
1530
  }
@@ -1474,7 +1593,8 @@ type SendOutcomeEvent = {
1474
1593
  namespace: string;
1475
1594
  emailId?: string;
1476
1595
  };
1477
- type ResendAPIOptions = APIOptions & {
1596
+ type ResendAPIOptions = APIOptions$1 & Pick<ProviderOptions, "tokens" | "baseUrl" | "publicNamespace" | "adminPrefix"> & {
1597
+ fixtures?: ResendSeedConfig;
1478
1598
  /** The public namespace name, for `/__admin/ns/<name>` download URLs. Default: the default namespace. */
1479
1599
  adminPrefix?: string;
1480
1600
  publicNamespace?: string;
@@ -1490,8 +1610,10 @@ type ResendAPIOptions = APIOptions & {
1490
1610
  */
1491
1611
  declare class ResendAPI implements FetchAPI {
1492
1612
  readonly app: Hono;
1493
- readonly sqlite: SqliteClient;
1613
+ readonly sqlite: SqliteClient$1;
1494
1614
  readonly state: ResendState;
1615
+ private tail;
1616
+ private readonly expansion;
1495
1617
  private readonly service;
1496
1618
  private readonly now;
1497
1619
  private readonly adminPrefix;
@@ -1502,6 +1624,7 @@ declare class ResendAPI implements FetchAPI {
1502
1624
  private readonly outcomeCounts;
1503
1625
  constructor(options?: ResendAPIOptions);
1504
1626
  fetch(request: Request): Promise<Response>;
1627
+ private handleFetch;
1505
1628
  reset(): Promise<void>;
1506
1629
  /** Accepted sends whose response was lost, those lost responses, and idempotent replays. */
1507
1630
  sendOutcomes(): Record<SendOutcome, number>;
@@ -1546,8 +1669,8 @@ type ForwardStats = {
1546
1669
  failed: number;
1547
1670
  lastError: string | null;
1548
1671
  };
1549
- type ResendRuntimeOptions = {
1550
- sqlite?: SqliteClient;
1672
+ type ResendRuntimeOptions = Pick<ResendAPIOptions, "fixtures" | "baseUrl" | "tokens"> & {
1673
+ sqlite?: SqliteClient$1;
1551
1674
  clock?: Clock;
1552
1675
  seed?: number | string;
1553
1676
  adminPrefix?: string;
package/dist/server.js CHANGED
@@ -2,8 +2,9 @@ import {
2
2
  DEFAULT_PORT,
3
3
  createServer,
4
4
  serveTarget
5
- } from "./chunk-SF5RM4JA.js";
6
- import "./chunk-U5432PUK.js";
5
+ } from "./chunk-WMQIKI4U.js";
6
+ import "./chunk-XQ4BQDIK.js";
7
+ import "./chunk-M73LWCCP.js";
7
8
  export {
8
9
  DEFAULT_PORT,
9
10
  createServer,