@nwire/dead-letter 0.7.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alex Gefter / 200apps Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # @nwire/dead-letter
2
+
3
+ > Dead-letter sink contract — destination for messages whose handler exhausted retries.
4
+
5
+ ## What it does
6
+
7
+ Defines `DeadLetterSink` (one method: `record(entry)`) and ships an in-memory default. The runtime calls `sink.record(entry)` once per failed dispatch after `max + 1` attempts have all thrown. Production wires plug in a persistent adapter (BullMQ's failed-jobs board, a Mongo collection, an SNS topic); the contract is identical.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @nwire/dead-letter
13
+ ```
14
+
15
+ ## Quick start
16
+
17
+ ```ts
18
+ import { InMemoryDeadLetterSink } from "@nwire/dead-letter";
19
+ import { createApp } from "@nwire/forge";
20
+
21
+ const dlq = new InMemoryDeadLetterSink();
22
+ const app = createApp("learnflow", { modules, deadLetter: dlq });
23
+
24
+ // In tests:
25
+ const entries = await dlq.list();
26
+ expect(entries.map((e) => e.actionName)).toContain("flakyAction");
27
+ ```
28
+
29
+ ## API surface
30
+
31
+ - `DeadLetterSink` — interface adapters implement.
32
+ - `InMemoryDeadLetterSink` — process-local default; useful in tests.
33
+ - `DeadLetterEntry` — record shape (actionName, input, envelope, attempts, lastError, enteredAt).
34
+ - `buildDeadLetterEntry(...)` — helper for adapters constructing entries.
35
+
36
+ ## When to use
37
+
38
+ Any production deployment — silently dropping retries-exhausted jobs is a production bug. Fits L3 and up.
39
+
40
+ ## Standalone use
41
+
42
+ For developers using `@nwire/dead-letter` **without the rest of Nwire** — pair it with any TypeScript project, any container, any HTTP framework.
43
+
44
+ ```ts
45
+ // See the package's main entry (src/) for the standalone surface.
46
+ // The exports below work without @nwire/app or @nwire/forge.
47
+ import {} from /* ...standalone exports... */ "@nwire/dead-letter";
48
+ ```
49
+
50
+ ## Within nwire-app
51
+
52
+ For developers using this package as part of the Nwire stack — register it via `app.use(...)` or it auto-wires when you compose `createApp({ modules })`.
53
+
54
+ ```ts
55
+ import { createApp } from "@nwire/forge";
56
+
57
+ const app = createApp({
58
+ /* ...config... */
59
+ });
60
+ // Adapter/plugin wiring happens here when applicable.
61
+ ```
62
+
63
+ ## See also
64
+
65
+ - [Architecture sketch §05 — Foundation tier](../../architecture-sketch.html#packages)
66
+ - Sibling packages: [@nwire/queue](../nwire-queue), [@nwire/queue-bullmq](../nwire-queue-bullmq)
@@ -0,0 +1,37 @@
1
+ /**
2
+ * `DeadLetterSink` — destination for messages whose handler exhausted retries.
3
+ *
4
+ * The runtime calls `sink(entry)` once per failed dispatch after `max + 1`
5
+ * attempts have all thrown. Production wires plug in a real DLQ (BullMQ's
6
+ * failed-jobs board, a Mongo collection, an SNS topic). Default is in-memory:
7
+ * collect every entry so tests can assert on what got dead-lettered.
8
+ */
9
+ import type { MessageEnvelope } from "@nwire/envelope";
10
+ export interface DeadLetterEntry {
11
+ readonly actionName: string;
12
+ readonly input: unknown;
13
+ readonly envelope: MessageEnvelope;
14
+ readonly attempts: number;
15
+ readonly lastError: {
16
+ name: string;
17
+ message: string;
18
+ stack?: string;
19
+ };
20
+ readonly enteredAt: string;
21
+ }
22
+ export interface DeadLetterSink {
23
+ record(entry: DeadLetterEntry): Promise<void>;
24
+ /** Return everything dead-lettered so far. Test/dev introspection. */
25
+ list(): Promise<readonly DeadLetterEntry[]>;
26
+ }
27
+ export declare class InMemoryDeadLetterSink implements DeadLetterSink {
28
+ private readonly entries;
29
+ record(entry: DeadLetterEntry): Promise<void>;
30
+ list(): Promise<readonly DeadLetterEntry[]>;
31
+ clear(): void;
32
+ }
33
+ /**
34
+ * Build a DeadLetterEntry from a thrown error and the dispatch state.
35
+ */
36
+ export declare function buildDeadLetterEntry(actionName: string, input: unknown, envelope: MessageEnvelope, attempts: number, error: unknown): DeadLetterEntry;
37
+ //# sourceMappingURL=dead-letter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dead-letter.d.ts","sourceRoot":"","sources":["../src/dead-letter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,sEAAsE;IACtE,IAAI,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC,CAAC;CAC7C;AAED,qBAAa,sBAAuB,YAAW,cAAc;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IAE3C,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,IAAI,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;IAIjD,KAAK,IAAI,IAAI;CAGd;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,eAAe,EACzB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,GACb,eAAe,CAcjB"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * `DeadLetterSink` — destination for messages whose handler exhausted retries.
3
+ *
4
+ * The runtime calls `sink(entry)` once per failed dispatch after `max + 1`
5
+ * attempts have all thrown. Production wires plug in a real DLQ (BullMQ's
6
+ * failed-jobs board, a Mongo collection, an SNS topic). Default is in-memory:
7
+ * collect every entry so tests can assert on what got dead-lettered.
8
+ */
9
+ export class InMemoryDeadLetterSink {
10
+ entries = [];
11
+ async record(entry) {
12
+ this.entries.push(entry);
13
+ }
14
+ async list() {
15
+ return [...this.entries];
16
+ }
17
+ clear() {
18
+ this.entries.length = 0;
19
+ }
20
+ }
21
+ /**
22
+ * Build a DeadLetterEntry from a thrown error and the dispatch state.
23
+ */
24
+ export function buildDeadLetterEntry(actionName, input, envelope, attempts, error) {
25
+ const err = error;
26
+ return {
27
+ actionName,
28
+ input,
29
+ envelope,
30
+ attempts,
31
+ lastError: {
32
+ name: err?.name ?? "Error",
33
+ message: err?.message ?? String(error),
34
+ stack: err?.stack,
35
+ },
36
+ enteredAt: new Date().toISOString(),
37
+ };
38
+ }
39
+ //# sourceMappingURL=dead-letter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dead-letter.js","sourceRoot":"","sources":["../src/dead-letter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAmBH,MAAM,OAAO,sBAAsB;IAChB,OAAO,GAAsB,EAAE,CAAC;IAEjD,KAAK,CAAC,MAAM,CAAC,KAAsB;QACjC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAAkB,EAClB,KAAc,EACd,QAAyB,EACzB,QAAgB,EAChB,KAAc;IAEd,MAAM,GAAG,GAAG,KAA4D,CAAC;IACzE,OAAO;QACL,UAAU;QACV,KAAK;QACL,QAAQ;QACR,QAAQ;QACR,SAAS,EAAE;YACT,IAAI,EAAE,GAAG,EAAE,IAAI,IAAI,OAAO;YAC1B,OAAO,EAAE,GAAG,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC;YACtC,KAAK,EAAE,GAAG,EAAE,KAAK;SAClB;QACD,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAC;AACJ,CAAC"}
package/dist/dlq.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@nwire/dead-letter` — DLQ contract + InMemory default.
3
+ *
4
+ * DeadLetterSink interface — record() per failed dispatch after retries exhausted
5
+ * InMemoryDeadLetterSink — process-local; test-friendly
6
+ *
7
+ * Production deployments use a persistent adapter (`@nwire/dlq-mongo`,
8
+ * `@nwire/dlq-bullmq`). The runtime catches handler throws after retries
9
+ * and routes them here.
10
+ */
11
+ export { InMemoryDeadLetterSink, buildDeadLetterEntry, type DeadLetterSink, type DeadLetterEntry, } from "./dead-letter.js";
12
+ //# sourceMappingURL=dlq.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dlq.d.ts","sourceRoot":"","sources":["../src/dlq.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC"}
package/dist/dlq.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@nwire/dead-letter` — DLQ contract + InMemory default.
3
+ *
4
+ * DeadLetterSink interface — record() per failed dispatch after retries exhausted
5
+ * InMemoryDeadLetterSink — process-local; test-friendly
6
+ *
7
+ * Production deployments use a persistent adapter (`@nwire/dlq-mongo`,
8
+ * `@nwire/dlq-bullmq`). The runtime catches handler throws after retries
9
+ * and routes them here.
10
+ */
11
+ export { InMemoryDeadLetterSink, buildDeadLetterEntry, } from "./dead-letter.js";
12
+ //# sourceMappingURL=dlq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dlq.js","sourceRoot":"","sources":["../src/dlq.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GAGrB,MAAM,eAAe,CAAC"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@nwire/dead-letter",
3
+ "version": "0.7.0",
4
+ "description": "Nwire — DLQ contract + InMemory default. Production adapters: @nwire/dlq-mongo, @nwire/dlq-bullmq. The runtime routes exhausted-retry failures here.",
5
+ "keywords": [
6
+ "dead-letter",
7
+ "dlq",
8
+ "nwire",
9
+ "reliability"
10
+ ],
11
+ "files": [
12
+ "dist",
13
+ "README.md"
14
+ ],
15
+ "type": "module",
16
+ "main": "./dist/dlq.js",
17
+ "types": "./dist/dlq.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/dlq.js",
21
+ "types": "./dist/dlq.d.ts"
22
+ }
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "dependencies": {
28
+ "@nwire/envelope": "0.7.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^22.19.9",
32
+ "typescript": "^5.9.3"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc && node ../../scripts/fix-dist-extensions.mjs dist",
36
+ "dev": "tsc --watch",
37
+ "typecheck": "tsc --noEmit"
38
+ }
39
+ }