@remit/backend 0.0.33 → 0.0.34

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/backend",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "Remit Mail Inspector API backend",
5
5
  "license": "MIT",
6
6
  "author": "",
@@ -0,0 +1,68 @@
1
+ import { existsSync } from "node:fs";
2
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { dirname } from "node:path";
4
+ import { logger } from "@remit/logger-lambda";
5
+ import {
6
+ backfillListIds,
7
+ type ListIdBackfillCheckpoint,
8
+ type ListIdBackfillCheckpointStore,
9
+ } from "@remit/mailbox-service";
10
+ import { getClient } from "../src/service/dynamodb.js";
11
+
12
+ /**
13
+ * One-time, full-corpus `ThreadMessage.listId` backfill (issue #263). Ships as
14
+ * an alternate entrypoint baked into the backend image — "the backend image
15
+ * with a command", the same shape `migrate.mjs` uses — rather than a service
16
+ * of its own. Unlike `migrate`, it is never wired into a compose one-shot: a
17
+ * full pass runs once per install, not on every restart. Invoke it by hand:
18
+ *
19
+ * docker compose -f docker-compose.sqlite.yml run --rm backend \
20
+ * node backfill-list-id.mjs
21
+ *
22
+ * Safe to interrupt: progress is checkpointed to disk after every page and
23
+ * picked back up on the next run, and every row it touches is read-only
24
+ * against the stored message, so a rerun after a partial pass is a no-op for
25
+ * everything already done.
26
+ */
27
+
28
+ const CHECKPOINT_PATH =
29
+ process.env.LIST_ID_BACKFILL_CHECKPOINT_PATH ??
30
+ "/data/sqlite/list-id-backfill-checkpoint.json";
31
+
32
+ const fileCheckpointStore: ListIdBackfillCheckpointStore = {
33
+ load: async () => {
34
+ if (!existsSync(CHECKPOINT_PATH)) return undefined;
35
+ const raw = await readFile(CHECKPOINT_PATH, "utf8");
36
+ return JSON.parse(raw) as ListIdBackfillCheckpoint;
37
+ },
38
+ save: async (checkpoint) => {
39
+ await mkdir(dirname(CHECKPOINT_PATH), { recursive: true });
40
+ await writeFile(CHECKPOINT_PATH, JSON.stringify(checkpoint));
41
+ },
42
+ clear: async () => {
43
+ await rm(CHECKPOINT_PATH, { force: true });
44
+ },
45
+ };
46
+
47
+ const run = async (): Promise<void> => {
48
+ const client = await getClient();
49
+
50
+ const result = await backfillListIds(
51
+ {
52
+ accountConfigService: client.accountConfig,
53
+ threadMessageService: client.threadMessage,
54
+ messageService: client.message,
55
+ storageService: client.storage,
56
+ },
57
+ { checkpointStore: fileCheckpointStore, logger },
58
+ );
59
+
60
+ console.log("[backfill-list-id] done", result);
61
+ };
62
+
63
+ run()
64
+ .then(() => process.exit(0))
65
+ .catch((error: unknown) => {
66
+ console.error("[backfill-list-id] failed", error);
67
+ process.exit(1);
68
+ });
package/tsconfig.json CHANGED
@@ -3,5 +3,5 @@
3
3
  "compilerOptions": {
4
4
  "outDir": "dist"
5
5
  },
6
- "include": ["src/**/*.ts", "dev-server/**/*.ts"]
6
+ "include": ["src/**/*.ts", "dev-server/**/*.ts", "scripts/**/*.ts"]
7
7
  }