@remit/data-ports 0.0.43 → 0.0.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/data-ports",
3
- "version": "0.0.43",
3
+ "version": "0.0.45",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
package/src/id.test.ts CHANGED
@@ -1,10 +1,19 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { describe, it } from "node:test";
3
3
  import {
4
+ base36uuidv5,
5
+ deriveAddressId,
6
+ deriveBodyPartId,
4
7
  deriveCopyMessageId,
8
+ deriveEnvelopeId,
5
9
  deriveMessageId,
10
+ deriveMessageIdFromSource,
6
11
  deriveQuarantineId,
12
+ deriveThreadId,
13
+ normalizeMessageIdHeader,
7
14
  quarantineMessageIdHash,
15
+ REMIT_NAMESPACE,
16
+ ROOT_PART_PATH,
8
17
  } from "./id.js";
9
18
 
10
19
  const ACCOUNT = "acct-1";
@@ -90,3 +99,97 @@ describe("quarantineMessageIdHash", () => {
90
99
  }
91
100
  });
92
101
  });
102
+
103
+ describe("derived ids are stored primary keys: a changed value orphans every row already written and needs a migration, never a new expectation here", () => {
104
+ const ACCOUNT = "account-golden";
105
+ const MESSAGE = "message-golden";
106
+ const MAILBOX = "mailbox-golden";
107
+ const ABSENT_HEADER_SOURCE = {
108
+ messageId: undefined,
109
+ mailboxId: MAILBOX,
110
+ uid: 40217,
111
+ date: "2026-08-23T00:00:00Z",
112
+ subject: "Golden",
113
+ fromMailbox: "golden",
114
+ fromHost: "example.com",
115
+ };
116
+
117
+ it("REMIT_NAMESPACE is the seed of every derived id and can never change", () => {
118
+ assert.equal(REMIT_NAMESPACE, "9e89694d-214b-4d9b-99f5-214b4d9b99f5");
119
+ });
120
+
121
+ it("base36uuidv5 pins the encoding every derivation below is built on", () => {
122
+ assert.equal(
123
+ base36uuidv5("golden-seed", REMIT_NAMESPACE),
124
+ "67hxxs95ofdk5frbprqyrgwmo",
125
+ );
126
+ });
127
+
128
+ it("deriveAddressId pins the address primary key, lowercased email included", () => {
129
+ assert.equal(
130
+ deriveAddressId(ACCOUNT, "Golden.User@Example.COM"),
131
+ "dzu01kz6aj1ro8fr8l375tfbr",
132
+ );
133
+ });
134
+
135
+ it("deriveMessageId pins the message primary key", () => {
136
+ assert.equal(
137
+ deriveMessageId(ACCOUNT, "<golden@example.com>"),
138
+ "bfthbm5n4279aacb5a1q1c94h",
139
+ );
140
+ });
141
+
142
+ it("normalizeMessageIdHeader pins the synthetic header that seeds a Message-ID-less message", () => {
143
+ assert.equal(
144
+ normalizeMessageIdHeader(ABSENT_HEADER_SOURCE),
145
+ "generated:mailbox-golden:40217:2026-08-23T00:00:00Z:Golden:golden:example.com",
146
+ );
147
+ });
148
+
149
+ it("deriveMessageIdFromSource pins the key of a message that declared no Message-ID", () => {
150
+ assert.equal(
151
+ deriveMessageIdFromSource(ACCOUNT, ABSENT_HEADER_SOURCE),
152
+ "0rae70onzy4ufhlnndqe7lwml",
153
+ );
154
+ });
155
+
156
+ it("deriveCopyMessageId pins the key of a message copied into another folder", () => {
157
+ assert.equal(
158
+ deriveCopyMessageId(MESSAGE, MAILBOX),
159
+ "43cwqvpfh4o1fcbmaciabmqo3",
160
+ );
161
+ });
162
+
163
+ it("deriveThreadId pins the thread primary key, lowercased root header included", () => {
164
+ assert.equal(
165
+ deriveThreadId(ACCOUNT, "<Golden.Root@Example.COM>"),
166
+ "bcy76e2uat5yq3xd1p7j7z4pr",
167
+ );
168
+ });
169
+
170
+ it("deriveEnvelopeId pins the envelope primary key", () => {
171
+ assert.equal(deriveEnvelopeId(MESSAGE), "f1bngysevoxuqt625rd5hvtzt");
172
+ });
173
+
174
+ it("ROOT_PART_PATH is baked into stored body part keys and S3 keys", () => {
175
+ assert.equal(ROOT_PART_PATH, "0");
176
+ });
177
+
178
+ it("deriveBodyPartId pins the body_part primary key", () => {
179
+ assert.equal(deriveBodyPartId(MESSAGE, "1.2"), "363nl1jzgh77ki2ojk1hqvxxe");
180
+ });
181
+
182
+ it("deriveQuarantineId pins the quarantine primary key", () => {
183
+ assert.equal(
184
+ deriveQuarantineId(ACCOUNT, MAILBOX, 1_700_000_000, 40217),
185
+ "4xg2y7x2j7nmvy0wtwgdq8b8p",
186
+ );
187
+ });
188
+
189
+ it("quarantineMessageIdHash pins the stored Message-ID hash that correlates reports", () => {
190
+ assert.equal(
191
+ quarantineMessageIdHash("<golden@example.com>"),
192
+ "sha256:5e888fd63760269e96a61e1a09b83ddec28556d0e3cda7e480897e58c8e6a2f5",
193
+ );
194
+ });
195
+ });
package/src/id.ts CHANGED
@@ -21,16 +21,6 @@ export const deriveAddressId = (
21
21
  REMIT_NAMESPACE,
22
22
  );
23
23
 
24
- export const deriveEnvelopeAddressId = (
25
- messageId: string,
26
- role: string,
27
- order: number,
28
- ): string =>
29
- base36uuidv5(
30
- `envelopeaddress:${messageId}:${role}:${order}`,
31
- REMIT_NAMESPACE,
32
- );
33
-
34
24
  export const isValidMessageId = (messageId: string | undefined): boolean => {
35
25
  if (!messageId) return false;
36
26
  const trimmed = messageId.trim();
package/src/types.ts CHANGED
@@ -295,7 +295,7 @@ export type UpdateAddressInput = Partial<
295
295
  export type CreateEnvelopeAddressInput = Omit<
296
296
  EnvelopeAddressItem,
297
297
  "envelopeAddressId" | "createdAt" | "updatedAt"
298
- > & { envelopeAddressId: string };
298
+ >;
299
299
 
300
300
  export type CreateEnvelopeInput = Omit<
301
301
  EnvelopeItem,