@terreno/api 57.20.0 → 57.21.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/biome.jsonc +1 -0
  3. package/dist/api.d.ts +3 -3
  4. package/dist/frameworkModelNames.d.ts +4 -0
  5. package/dist/frameworkModelNames.js +4 -0
  6. package/dist/index.d.ts +4 -0
  7. package/dist/index.js +9 -3
  8. package/dist/mcp/adminTracking.d.ts +28 -0
  9. package/dist/mcp/adminTracking.js +80 -0
  10. package/dist/mcp/auth.d.ts +6 -0
  11. package/dist/mcp/auth.js +12 -2
  12. package/dist/mcp/server.d.ts +8 -0
  13. package/dist/mcp/server.js +48 -4
  14. package/dist/models/mcpOAuthToken.js +27 -0
  15. package/dist/models/mcpRequestLog.d.ts +2 -0
  16. package/dist/models/mcpRequestLog.js +73 -0
  17. package/dist/models/mcpServiceToken.js +4 -0
  18. package/dist/models/mcpToolSetting.d.ts +2 -0
  19. package/dist/models/mcpToolSetting.js +119 -0
  20. package/dist/models/versionConfig.d.ts +2 -0
  21. package/dist/rbac/auditModel.d.ts +2 -1
  22. package/dist/terrenoApp.d.ts +12 -0
  23. package/dist/terrenoApp.js +3 -0
  24. package/dist/tests/models.d.ts +17 -22
  25. package/dist/tests/models.js +7 -1
  26. package/dist/tests/testHelper.d.ts +6 -12
  27. package/dist/tests.d.ts +1 -0
  28. package/dist/tests.js +3 -1
  29. package/dist/types/mcpAdmin.d.ts +58 -0
  30. package/dist/types/mcpAdmin.js +2 -0
  31. package/dist/types/mcpOAuth.d.ts +2 -0
  32. package/dist/types/mcpServiceToken.d.ts +2 -0
  33. package/e2e/smoke.ts +193 -0
  34. package/package.json +7 -5
  35. package/src/adminModelRouter.test.ts +8 -6
  36. package/src/api.arrayOperations.test.ts +31 -22
  37. package/src/api.hooks.test.ts +12 -11
  38. package/src/api.query.test.ts +2 -2
  39. package/src/api.test.ts +8 -7
  40. package/src/api.ts +3 -3
  41. package/src/audit/auditApp.test.ts +1 -1
  42. package/src/audit/cloudTasksEnqueue.test.ts +19 -14
  43. package/src/auth.test.ts +21 -7
  44. package/src/authRecovery.test.ts +10 -10
  45. package/src/authVerification.test.ts +7 -7
  46. package/src/betterAuthFeatures.test.ts +3 -2
  47. package/src/betterAuthLinking.test.ts +3 -1
  48. package/src/betterAuthSetup.test.ts +77 -51
  49. package/src/collectionRegistry.test.ts +4 -4
  50. package/src/frameworkModelNames.test.ts +8 -0
  51. package/src/frameworkModelNames.ts +4 -0
  52. package/src/githubAuth.test.ts +11 -11
  53. package/src/index.ts +8 -0
  54. package/src/isolated/migrateCliConnect.isolated.ts +3 -2
  55. package/src/mcp/actionTools.test.ts +11 -5
  56. package/src/mcp/adminTracking.test.ts +272 -0
  57. package/src/mcp/adminTracking.ts +104 -0
  58. package/src/mcp/auth.ts +18 -2
  59. package/src/mcp/oauth.test.ts +1 -1
  60. package/src/mcp/server.ts +67 -4
  61. package/src/mcp/serviceTokens.test.ts +2 -1
  62. package/src/mcp/toolGenerator.test.ts +9 -5
  63. package/src/migrations/cli.test.ts +15 -14
  64. package/src/migrations/cli.ts +1 -1
  65. package/src/migrations/generate.test.ts +2 -2
  66. package/src/migrations/load.test.ts +1 -1
  67. package/src/migrations/lock.test.ts +8 -3
  68. package/src/migrations/runner.test.ts +16 -5
  69. package/src/migrations/schemaCatalog.test.ts +4 -1
  70. package/src/models/mcpOAuthToken.test.ts +42 -0
  71. package/src/models/mcpOAuthToken.ts +32 -0
  72. package/src/models/mcpRequestLog.ts +81 -0
  73. package/src/models/mcpServiceToken.test.ts +23 -0
  74. package/src/models/mcpServiceToken.ts +10 -0
  75. package/src/models/mcpToolSetting.test.ts +69 -0
  76. package/src/models/mcpToolSetting.ts +138 -0
  77. package/src/models/versionConfig.ts +2 -0
  78. package/src/notifications/notificationsApp.test.ts +5 -8
  79. package/src/notifiers/slackWebApi.test.ts +30 -8
  80. package/src/openApi.test.ts +4 -4
  81. package/src/openApiValidator.test.ts +3 -3
  82. package/src/orgs/orgPermissions.test.ts +2 -2
  83. package/src/orgs/orgPlugin.test.ts +4 -3
  84. package/src/orgs/orgSecurityDefects.test.ts +3 -1
  85. package/src/orgs/organizationSettings.test.ts +1 -1
  86. package/src/orgs/orgsApp.test.ts +5 -3
  87. package/src/permissions.test.ts +2 -2
  88. package/src/rateLimit/redisStore.ioredis.test.ts +3 -2
  89. package/src/rbac/assertAllowed.test.ts +1 -1
  90. package/src/rbac/auditModel.ts +10 -2
  91. package/src/rbac/realtimeAccess.test.ts +3 -2
  92. package/src/rbac/routes.test.ts +1 -1
  93. package/src/rbac/userWriteGuards.test.ts +8 -5
  94. package/src/realtime/realtime.test.ts +35 -31
  95. package/src/scrubAdminFields.test.ts +1 -1
  96. package/src/sync/adminWindowMutation.test.ts +4 -3
  97. package/src/sync/executors.test.ts +1 -1
  98. package/src/sync/scripts/compactTombstones.test.ts +4 -3
  99. package/src/sync/sync.test.ts +1 -1
  100. package/src/sync/syncPhaseC.test.ts +14 -11
  101. package/src/sync/syncRoutes.test.ts +8 -8
  102. package/src/sync/syncSeqPlugin.test.ts +1 -2
  103. package/src/sync/syncSocket.test.ts +5 -4
  104. package/src/terrenoApp.mcpServiceTokens.test.ts +2 -2
  105. package/src/terrenoApp.migrations.test.ts +8 -7
  106. package/src/terrenoApp.ts +14 -0
  107. package/src/tests/betterAuthStubs.ts +3 -2
  108. package/src/tests/bunSetup.ts +1 -1
  109. package/src/tests/models.ts +10 -0
  110. package/src/tests/testEnv.ts +7 -0
  111. package/src/tests.ts +1 -0
  112. package/src/types/mcpAdmin.ts +80 -0
  113. package/src/types/mcpOAuth.ts +5 -0
  114. package/src/types/mcpServiceToken.ts +5 -0
  115. package/src/webhooks/verifiers/hmac.test.ts +1 -1
  116. package/tsconfig.typecheck.json +14 -0
@@ -635,7 +635,9 @@ describe("realtimeRegistry", () => {
635
635
  describe("updateRealtimeRegistryOptions", () => {
636
636
  it("replaces options on an existing entry by route path", () => {
637
637
  registerRealtime(makeEntry({routePath: "/todos"}));
638
- const updatedOptions = {permissions: {list: []}} as ModelRouterOptions<unknown>;
638
+ const updatedOptions: ModelRouterOptions<unknown> = {
639
+ permissions: {create: [], delete: [], list: [], read: [], update: []},
640
+ };
639
641
  updateRealtimeRegistryOptions("/todos", updatedOptions);
640
642
 
641
643
  expect(getRealtimeRegistry()[0]?.options).toBe(updatedOptions);
@@ -1449,32 +1451,32 @@ describe("resolveRooms", () => {
1449
1451
  };
1450
1452
 
1451
1453
  it("returns user-specific room for owner strategy with ownerId", () => {
1452
- const entry = {...baseEntry, config: {...baseEntry.config, roomStrategy: "owner"}};
1454
+ const entry = {...baseEntry, config: {...baseEntry.config, roomStrategy: "owner" as const}};
1453
1455
  const rooms = resolveRooms(entry, {ownerId: "user-1"}, "create");
1454
1456
  expect(rooms).toEqual(["user:user-1"]);
1455
1457
  });
1456
1458
 
1457
1459
  it("converts ObjectId-like ownerId to string", () => {
1458
- const entry = {...baseEntry, config: {...baseEntry.config, roomStrategy: "owner"}};
1460
+ const entry = {...baseEntry, config: {...baseEntry.config, roomStrategy: "owner" as const}};
1459
1461
  const ownerId = {toString: (): string => "owner-from-obj"};
1460
1462
  const rooms = resolveRooms(entry, {ownerId}, "create");
1461
1463
  expect(rooms).toEqual(["user:owner-from-obj"]);
1462
1464
  });
1463
1465
 
1464
1466
  it("falls back to model room when owner strategy has no ownerId", () => {
1465
- const entry = {...baseEntry, config: {...baseEntry.config, roomStrategy: "owner"}};
1467
+ const entry = {...baseEntry, config: {...baseEntry.config, roomStrategy: "owner" as const}};
1466
1468
  const rooms = resolveRooms(entry, {}, "create");
1467
1469
  expect(rooms).toEqual(["model:todos"]);
1468
1470
  });
1469
1471
 
1470
1472
  it("returns model room for model strategy", () => {
1471
- const entry = {...baseEntry, config: {...baseEntry.config, roomStrategy: "model"}};
1473
+ const entry = {...baseEntry, config: {...baseEntry.config, roomStrategy: "model" as const}};
1472
1474
  const rooms = resolveRooms(entry, {}, "create");
1473
1475
  expect(rooms).toEqual(["model:todos"]);
1474
1476
  });
1475
1477
 
1476
1478
  it("returns authenticated room for broadcast strategy", () => {
1477
- const entry = {...baseEntry, config: {...baseEntry.config, roomStrategy: "broadcast"}};
1479
+ const entry = {...baseEntry, config: {...baseEntry.config, roomStrategy: "broadcast" as const}};
1478
1480
  const rooms = resolveRooms(entry, {}, "create");
1479
1481
  expect(rooms).toEqual(["authenticated"]);
1480
1482
  });
@@ -1841,7 +1843,7 @@ describe("emitToDocumentAndQueryRooms", () => {
1841
1843
  }
1842
1844
 
1843
1845
  return {
1844
- ...(doc as Record<string, unknown>),
1846
+ ...(doc as unknown as Record<string, unknown>),
1845
1847
  visibleTo: req.user?.id,
1846
1848
  } as unknown as JSONValue;
1847
1849
  },
@@ -2168,7 +2170,7 @@ describe("startChangeStreamWatcher", () => {
2168
2170
  setConnectionDb(originalDb);
2169
2171
  clearRealtimeRegistry();
2170
2172
  // Ensure the watcher is stopped between tests
2171
- const {stopChangeStreamWatcher: stop} = await import("./changeStreamWatcher");
2173
+ const {stopChangeStreamWatcher: stop} = await import("./changeStreamWatcher.js");
2172
2174
  await stop();
2173
2175
  });
2174
2176
 
@@ -2222,7 +2224,7 @@ describe("startChangeStreamWatcher", () => {
2222
2224
  };
2223
2225
  setConnectionDb(mockDb);
2224
2226
 
2225
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2227
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2226
2228
  const io = createMockIo();
2227
2229
 
2228
2230
  startChangeStreamWatcher(io, {}, true);
@@ -2237,7 +2239,7 @@ describe("startChangeStreamWatcher", () => {
2237
2239
  it("throws when mongoose connection db is unavailable", async () => {
2238
2240
  setConnectionDb(undefined);
2239
2241
 
2240
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2242
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2241
2243
  const io = createMockIo();
2242
2244
 
2243
2245
  expect(() => startChangeStreamWatcher(io)).toThrow(
@@ -2251,7 +2253,7 @@ describe("startChangeStreamWatcher", () => {
2251
2253
  };
2252
2254
  setConnectionDb(mockDb);
2253
2255
 
2254
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2256
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2255
2257
  const io = createMockIo();
2256
2258
 
2257
2259
  expect(() => startChangeStreamWatcher(io)).toThrow("Failed to create change stream watcher");
@@ -2283,7 +2285,7 @@ describe("startChangeStreamWatcher", () => {
2283
2285
  routePath: "/todos",
2284
2286
  });
2285
2287
 
2286
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2288
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2287
2289
  const io = createMockIo();
2288
2290
 
2289
2291
  startChangeStreamWatcher(io, {}, true);
@@ -2304,7 +2306,7 @@ describe("startChangeStreamWatcher", () => {
2304
2306
  };
2305
2307
  setConnectionDb(mockDb);
2306
2308
 
2307
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2309
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2308
2310
  const io = createMockIo();
2309
2311
 
2310
2312
  startChangeStreamWatcher(io, {}, true);
@@ -2344,7 +2346,7 @@ describe("startChangeStreamWatcher", () => {
2344
2346
  routePath: "/todos",
2345
2347
  });
2346
2348
 
2347
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2349
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2348
2350
  const io = createMockIo();
2349
2351
 
2350
2352
  startChangeStreamWatcher(io, {}, true);
@@ -2385,7 +2387,7 @@ describe("startChangeStreamWatcher", () => {
2385
2387
  routePath: "/todos",
2386
2388
  });
2387
2389
 
2388
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2390
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2389
2391
  const io = createMockIo();
2390
2392
 
2391
2393
  startChangeStreamWatcher(io, {}, true);
@@ -2424,7 +2426,7 @@ describe("startChangeStreamWatcher", () => {
2424
2426
  routePath: "/broadcasts",
2425
2427
  });
2426
2428
 
2427
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2429
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2428
2430
  const io = createMockIo();
2429
2431
 
2430
2432
  startChangeStreamWatcher(io, {}, true);
@@ -2494,7 +2496,7 @@ describe("startChangeStreamWatcher", () => {
2494
2496
  routePath: "/todos",
2495
2497
  });
2496
2498
 
2497
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2499
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2498
2500
  const {emissions, io} = createRecordingIo("model:todos");
2499
2501
 
2500
2502
  startChangeStreamWatcher(io, {}, true);
@@ -2535,7 +2537,7 @@ describe("startChangeStreamWatcher", () => {
2535
2537
  routePath: "/todos",
2536
2538
  });
2537
2539
 
2538
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2540
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2539
2541
  const roomLookup = mock(() => {
2540
2542
  throw new Error("adapter unavailable");
2541
2543
  });
@@ -2583,7 +2585,7 @@ describe("startChangeStreamWatcher", () => {
2583
2585
  routePath: "/todos",
2584
2586
  });
2585
2587
 
2586
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2588
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2587
2589
  const io = createMockIo();
2588
2590
 
2589
2591
  startChangeStreamWatcher(io, {}, true);
@@ -2604,7 +2606,7 @@ describe("startChangeStreamWatcher", () => {
2604
2606
  };
2605
2607
  setConnectionDb(mockDb);
2606
2608
 
2607
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2609
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2608
2610
  const io = createMockIo();
2609
2611
 
2610
2612
  startChangeStreamWatcher(io, {ignoredCollections: ["audit_logs"]}, true);
@@ -2645,7 +2647,7 @@ describe("startChangeStreamWatcher", () => {
2645
2647
  routePath: "/todos",
2646
2648
  });
2647
2649
 
2648
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2650
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2649
2651
  const io = createMockIo();
2650
2652
 
2651
2653
  startChangeStreamWatcher(io, {ignoredOperations: ["insert"]}, true);
@@ -2666,7 +2668,7 @@ describe("startChangeStreamWatcher", () => {
2666
2668
  };
2667
2669
  setConnectionDb(mockDb);
2668
2670
 
2669
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2671
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2670
2672
  const io = createMockIo();
2671
2673
 
2672
2674
  startChangeStreamWatcher(io, {}, true);
@@ -2692,7 +2694,7 @@ describe("startChangeStreamWatcher", () => {
2692
2694
  };
2693
2695
  setConnectionDb(mockDb);
2694
2696
 
2695
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2697
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2696
2698
  const io = createMockIo();
2697
2699
 
2698
2700
  startChangeStreamWatcher(io, {}, true);
@@ -2721,7 +2723,7 @@ describe("startChangeStreamWatcher", () => {
2721
2723
  routePath: "/todos",
2722
2724
  });
2723
2725
 
2724
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2726
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2725
2727
  const {emissions, io} = createRecordingIo("model:todos");
2726
2728
  let operationTypeReads = 0;
2727
2729
  startChangeStreamWatcher(io, {}, true);
@@ -2747,7 +2749,7 @@ describe("startChangeStreamWatcher", () => {
2747
2749
  };
2748
2750
  setConnectionDb(mockDb);
2749
2751
 
2750
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2752
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2751
2753
  const io = createMockIo();
2752
2754
 
2753
2755
  startChangeStreamWatcher(io, {}, true);
@@ -2833,7 +2835,7 @@ describe("startChangeStreamWatcher", () => {
2833
2835
  setConnectionDb(mockDb);
2834
2836
  registerTodos();
2835
2837
 
2836
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2838
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2837
2839
  const {deliveries, io} = createRecordingIo();
2838
2840
  startChangeStreamWatcher(io, {}, true);
2839
2841
 
@@ -2873,7 +2875,9 @@ describe("startChangeStreamWatcher", () => {
2873
2875
  const mockDb = {watch: mock(() => streams.shift() ?? secondStream)};
2874
2876
  setConnectionDb(mockDb);
2875
2877
 
2876
- const {SYNC_RESYNC_EVENT, startChangeStreamWatcher} = await import("./changeStreamWatcher");
2878
+ const {SYNC_RESYNC_EVENT, startChangeStreamWatcher} = await import(
2879
+ "./changeStreamWatcher.js"
2880
+ );
2877
2881
  const {io, serverEmissions} = createRecordingIo();
2878
2882
  startChangeStreamWatcher(io, {}, true);
2879
2883
 
@@ -2907,7 +2911,7 @@ describe("startChangeStreamWatcher", () => {
2907
2911
  setConnectionDb(mockDb);
2908
2912
 
2909
2913
  const {startChangeStreamWatcher, stopChangeStreamWatcher: stop} = await import(
2910
- "./changeStreamWatcher"
2914
+ "./changeStreamWatcher.js"
2911
2915
  );
2912
2916
  const {io} = createRecordingIo();
2913
2917
  startChangeStreamWatcher(io, {}, true);
@@ -2926,7 +2930,7 @@ describe("startChangeStreamWatcher", () => {
2926
2930
  };
2927
2931
  setConnectionDb(mockDb);
2928
2932
 
2929
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2933
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2930
2934
  const io = createMockIo();
2931
2935
 
2932
2936
  startChangeStreamWatcher(io, {batchSize: 100, fullDocument: "whenAvailable"}, true);
@@ -2970,7 +2974,7 @@ describe("startChangeStreamWatcher", () => {
2970
2974
  routePath: "/todos",
2971
2975
  });
2972
2976
 
2973
- const {startChangeStreamWatcher} = await import("./changeStreamWatcher");
2977
+ const {startChangeStreamWatcher} = await import("./changeStreamWatcher.js");
2974
2978
 
2975
2979
  // Create an IO with a socket in the target room
2976
2980
  const emissions: Array<{_data: unknown; _event: string}> = [];
@@ -3018,7 +3022,7 @@ describe("stopChangeStreamWatcher", () => {
3018
3022
  setConnectionDb(mockDb);
3019
3023
 
3020
3024
  const {startChangeStreamWatcher, stopChangeStreamWatcher} = await import(
3021
- "./changeStreamWatcher"
3025
+ "./changeStreamWatcher.js"
3022
3026
  );
3023
3027
  const io = {
3024
3028
  sockets: {
@@ -176,7 +176,7 @@ describe("stripAdminBodyFields", () => {
176
176
  {internal: "n", role: "admin", slug: "fixed", title: "x"},
177
177
  admin
178
178
  );
179
- expect(result).toEqual({title: "x"});
179
+ expect<unknown>(result).toEqual({title: "x"});
180
180
  });
181
181
 
182
182
  it("strips keys from every object in an array body and leaves non-objects alone", () => {
@@ -2,7 +2,7 @@ import {afterEach, beforeEach, describe, expect, it} from "bun:test";
2
2
  import {assert} from "chai";
3
3
  import mongoose from "mongoose";
4
4
 
5
- import {addAuthRoutes, setupAuth, type UserModel as UserModelType} from "../auth";
5
+ import {addAuthRoutes, setupAuth, type User, type UserModel as UserModelType} from "../auth";
6
6
  import {Permissions} from "../permissions";
7
7
  import {createdUpdatedPlugin, findOneOrNoneFor, isDeletedPlugin} from "../plugins";
8
8
  import {authAsUser, getBaseServer, setupDb, UserModel} from "../tests";
@@ -88,7 +88,7 @@ describe("adminWindowMutation", () => {
88
88
  await WindowTodoModel.deleteMany({});
89
89
  });
90
90
 
91
- const loadUser = async (type: "admin" | "notAdmin") => {
91
+ const loadUser = async (type: "admin" | "notAdmin"): Promise<User> => {
92
92
  const app = getBaseServer();
93
93
  setupAuth(app, UserModel as unknown as UserModelType);
94
94
  addAuthRoutes(app, UserModel as unknown as UserModelType);
@@ -96,7 +96,7 @@ describe("adminWindowMutation", () => {
96
96
  const email = type === "admin" ? "admin@example.com" : "notAdmin@example.com";
97
97
  const doc = await findOneOrNoneFor(UserModel, {email});
98
98
  expect(doc).toBeTruthy();
99
- return doc as {admin?: boolean; id: string};
99
+ return doc as unknown as User;
100
100
  };
101
101
 
102
102
  it("returns undefined for product mutations without a marker", async () => {
@@ -398,6 +398,7 @@ describe("adminWindowMutation", () => {
398
398
  const options = buildAdminWindowExecutorOptions({
399
399
  productOptions: {
400
400
  maxLimit: 123,
401
+ permissions: {create: [], delete: [], list: [], read: [], update: []},
401
402
  preCreate: productPreCreate,
402
403
  preUpdate: productPreCreate,
403
404
  },
@@ -1293,7 +1293,7 @@ describe("soft-delete flag in client write bodies", () => {
1293
1293
  body: {name: "archived"},
1294
1294
  id: doc._id.toString(),
1295
1295
  model: ExecStuffModel,
1296
- options: baseOptions({preUpdate: (body) => ({...body, deleted: true})}),
1296
+ options: baseOptions({preUpdate: (body) => ({...body, deleted: true}) as ExecStuff}),
1297
1297
  user: owner,
1298
1298
  });
1299
1299
  expect(await ExecStuffModel.countDocuments({_id: doc._id})).toBe(0);
@@ -6,7 +6,7 @@ import {Permissions} from "../../permissions";
6
6
  import {createdUpdatedPlugin, type IsDeleted, isDeletedPlugin} from "../../plugins";
7
7
  import {setupDb} from "../../tests";
8
8
  import {getCompactedThroughSeq, SyncCounter, SyncScopeMove} from "../models";
9
- import {clearSyncRegistry, registerSync} from "../registry";
9
+ import {clearSyncRegistry, registerSync, type SyncRegistryEntry} from "../registry";
10
10
  import {syncPlugin} from "../syncSeqPlugin";
11
11
  import {
12
12
  compactEntryTombstones,
@@ -228,7 +228,7 @@ describe("compactTombstones (C7 retention)", () => {
228
228
  });
229
229
 
230
230
  // Helper: re-register and return the entry (retentionDays override) for compactEntryTombstones.
231
- const clearSyncRegistryAndReRegister = (retentionDays: number) => {
231
+ const clearSyncRegistryAndReRegister = (retentionDays: number): SyncRegistryEntry => {
232
232
  clearSyncRegistry();
233
233
  registerSync({
234
234
  config: {retentionDays, scope: {type: "owner"}},
@@ -241,7 +241,8 @@ const clearSyncRegistryAndReRegister = (retentionDays: number) => {
241
241
  collectionTag: "compactStuff",
242
242
  config: {retentionDays, scope: {type: "owner"} as const},
243
243
  modelName: CompactStuffModel.modelName,
244
- options,
244
+ // The registry stores entries type-erased, as registerSync does.
245
+ options: options as unknown as ModelRouterOptions<unknown>,
245
246
  routePath: "/compactStuff",
246
247
  };
247
248
  };
@@ -347,7 +347,7 @@ describe("modelRouter sync option", () => {
347
347
  });
348
348
 
349
349
  const after = findSyncEntryByCollectionTag("syncStuff");
350
- expect(after?.options.accessControl).toBe(accessControl);
350
+ expect<unknown>(after?.options.accessControl).toBe(accessControl);
351
351
  expect(after?.options.permissions.list).not.toBe(before);
352
352
  });
353
353
  });
@@ -1,11 +1,12 @@
1
1
  import {beforeEach, describe, expect, it} from "bun:test";
2
2
  import type express from "express";
3
+ import type {Collection} from "mongodb";
3
4
  import {type Model, model, Schema} from "mongoose";
4
5
  import supertest from "supertest";
5
6
  import type TestAgent from "supertest/lib/agent";
6
- import type {ModelRouterOptions} from "../api";
7
+ import type {ModelRouterOptions, RESTMethod} from "../api";
7
8
  import {type UserModel as AuthUserModel, addAuthRoutes, setupAuth, type User} from "../auth";
8
- import {Permissions, type RESTMethod} from "../permissions";
9
+ import {Permissions} from "../permissions";
9
10
  import {createdUpdatedPlugin, type IsDeleted, isDeletedPlugin} from "../plugins";
10
11
  import {DEFAULT_IGNORED_COLLECTIONS} from "../realtime/changeStreamWatcher";
11
12
  import {authAsUser, getBaseServer, setupDb, UserModel} from "../tests";
@@ -247,7 +248,7 @@ describe("Phase C sync routes", () => {
247
248
  ownerId: notAdminId,
248
249
  title: `legacy-${String(i).padStart(4, "0")}`,
249
250
  }));
250
- await PhaseCTodoModel.collection.insertMany(legacy as unknown as PhaseCTodo[]);
251
+ await PhaseCTodoModel.collection.insertMany(legacy);
251
252
  // A couple of modern (stamped) docs after the legacy stratum.
252
253
  await PhaseCTodoModel.create({ownerId: notAdminId, title: "modern-1"});
253
254
  await PhaseCTodoModel.create({ownerId: notAdminId, title: "modern-2"});
@@ -291,7 +292,7 @@ describe("Phase C sync routes", () => {
291
292
  await PhaseCTodoModel.collection.insertMany([
292
293
  {deleted: false, ownerId: notAdminId, title: "legacy-a"},
293
294
  {deleted: false, ownerId: notAdminId, title: "legacy-b"},
294
- ] as unknown as PhaseCTodo[]);
295
+ ]);
295
296
  await PhaseCTodoModel.create({ownerId: notAdminId, title: "stamped"});
296
297
 
297
298
  const page1 = await agent
@@ -319,7 +320,7 @@ describe("Phase C sync routes", () => {
319
320
  await PhaseCTodoModel.collection.insertMany([
320
321
  {deleted: true, ownerId: notAdminId, title: "DUMMY-deleted-legacy"},
321
322
  {deleted: false, ownerId: notAdminId, title: "DUMMY-live-legacy"},
322
- ] as unknown as PhaseCTodo[]);
323
+ ]);
323
324
 
324
325
  const page = await agent
325
326
  .get(`/sync/snapshot?stream=${enc(ownerStream())}&limit=10`)
@@ -341,13 +342,15 @@ describe("Phase C sync routes", () => {
341
342
  const noteStream = `phaseCNotes|owner:${notAdminId}`;
342
343
  const total = 25;
343
344
  const limit = 10;
344
- await PhaseCNoteModel.collection.insertMany(
345
+ // The driver collection defaults to ObjectId keys; this model mints string ids.
346
+ const rawNotes = PhaseCNoteModel.collection as unknown as Collection<PhaseCNote>;
347
+ await rawNotes.insertMany(
345
348
  Array.from({length: total}, (_v, i) => ({
346
349
  _id: `note-${String(i).padStart(3, "0")}`,
347
350
  deleted: false,
348
351
  ownerId: notAdminId,
349
352
  title: `legacy note ${i}`,
350
- })) as unknown as PhaseCNote[]
353
+ }))
351
354
  );
352
355
  await PhaseCNoteModel.create({
353
356
  _id: "note-modern",
@@ -389,7 +392,7 @@ describe("Phase C sync routes", () => {
389
392
  it("Task 9.14: 400s (not 500s) on a malformed legacyCursor for an ObjectId-keyed model", async () => {
390
393
  await PhaseCTodoModel.collection.insertMany([
391
394
  {deleted: false, ownerId: notAdminId, title: "legacy-a"},
392
- ] as unknown as PhaseCTodo[]);
395
+ ]);
393
396
  await agent
394
397
  .get(`/sync/snapshot?stream=${enc(ownerStream())}&legacyCursor=not-an-object-id`)
395
398
  .expect(400);
@@ -475,7 +478,7 @@ describe("Phase C sync routes", () => {
475
478
  await PhaseCTodoModel.create({ownerId: notAdminId, title: "visible-2"});
476
479
 
477
480
  const res = await agent.get(`/sync/snapshot?stream=${enc(ownerStream())}`).expect(200);
478
- const titles = res.body.entities.map((e: SnapshotEntity) => e.data.title);
481
+ const titles = res.body.entities.map((e: SnapshotEntity) => e.data?.title);
479
482
  expect(titles).toEqual(["visible-1", "visible-2"]);
480
483
  // The cursor advanced past the denied doc (seq 3), so it is never re-fetched.
481
484
  expect(res.body.cursor).toBe(3);
@@ -496,7 +499,7 @@ describe("Phase C sync routes", () => {
496
499
  if (!doc) {
497
500
  return true;
498
501
  }
499
- return !String(doc.title).startsWith("denied-");
502
+ return !String((doc as {title?: string}).title).startsWith("denied-");
500
503
  },
501
504
  ],
502
505
  },
@@ -564,7 +567,7 @@ describe("Phase C sync routes", () => {
564
567
  // "other" is excluded by the $or filter; "mine" appears as a tombstone (data null).
565
568
  const titles = res.body.entities
566
569
  .filter((e: SnapshotEntity) => !e.deleted)
567
- .map((e: SnapshotEntity) => e.data.title)
570
+ .map((e: SnapshotEntity) => e.data?.title)
568
571
  .sort();
569
572
  expect(titles).toEqual(["shared"]);
570
573
  const tombstone = byTitle.get(String(mine._id));
@@ -95,7 +95,7 @@ interface SnapshotEntity {
95
95
  id: string;
96
96
  seq: number;
97
97
  deleted: boolean;
98
- data: {name: string} | null;
98
+ data: {name?: string; title?: string} | null;
99
99
  }
100
100
 
101
101
  interface StreamInfo {
@@ -287,7 +287,7 @@ describe("sync routes", () => {
287
287
  .expect(200);
288
288
  expect(res.body.stream).toBe(ownerStream());
289
289
  expect(res.body.entities).toHaveLength(2);
290
- expect(res.body.entities.map((e: SnapshotEntity) => e.data.name)).toEqual([
290
+ expect(res.body.entities.map((e: SnapshotEntity) => e.data?.name)).toEqual([
291
291
  "mine 1",
292
292
  "mine 2",
293
293
  ]);
@@ -349,7 +349,7 @@ describe("sync routes", () => {
349
349
  expect(page3.body.hasMore).toBe(false);
350
350
 
351
351
  const names = [...page1.body.entities, ...page2.body.entities, ...page3.body.entities].map(
352
- (e: SnapshotEntity) => e.data.name
352
+ (e: SnapshotEntity) => e.data?.name
353
353
  );
354
354
  expect(names).toEqual(["item 1", "item 2", "item 3", "item 4", "item 5"]);
355
355
  });
@@ -388,7 +388,7 @@ describe("sync routes", () => {
388
388
  clearSyncRegistry();
389
389
  registerSync({
390
390
  config: {
391
- responseHandler: (doc) => ({redactedName: `x-${(doc as RouteStuff).name}`}),
391
+ responseHandler: (doc) => ({redactedName: `x-${(doc as unknown as RouteStuff).name}`}),
392
392
  scope: {type: "owner"},
393
393
  },
394
394
  model: RouteStuffModel as unknown as Model<unknown>,
@@ -429,10 +429,10 @@ describe("sync routes", () => {
429
429
  tenantStream,
430
430
  ownerStream(),
431
431
  ]);
432
- expect(res.body.pages[0].entities.map((e: SnapshotEntity) => e.data.title)).toEqual([
432
+ expect(res.body.pages[0].entities.map((e: SnapshotEntity) => e.data?.title)).toEqual([
433
433
  "visible",
434
434
  ]);
435
- expect(res.body.pages[1].entities.map((e: SnapshotEntity) => e.data.name)).toEqual(["mine"]);
435
+ expect(res.body.pages[1].entities.map((e: SnapshotEntity) => e.data?.name)).toEqual(["mine"]);
436
436
  expect(res.body.pages[1].hasMore).toBe(false);
437
437
  expect(res.body.pages[1].cursor).toBe(res.body.pages[1].frontierSeq);
438
438
  });
@@ -457,7 +457,7 @@ describe("sync routes", () => {
457
457
  .post("/sync/snapshot/batch")
458
458
  .send({limit: 4, streams: [{cursor: ownerPage.cursor, stream: ownerStream()}]})
459
459
  .expect(200);
460
- expect(second.body.pages[0].entities.map((e: SnapshotEntity) => e.data.name)).toEqual([
460
+ expect(second.body.pages[0].entities.map((e: SnapshotEntity) => e.data?.name)).toEqual([
461
461
  "item 3",
462
462
  "item 4",
463
463
  "item 5",
@@ -1279,7 +1279,7 @@ describe("sync routes", () => {
1279
1279
  const res = await agent
1280
1280
  .get(`/sync/snapshot?stream=${encodeURIComponent(`routeStuff|owner:${notAdminId}`)}`)
1281
1281
  .expect(200);
1282
- expect(res.body.entities.map((e: SnapshotEntity) => e.data.name)).toEqual(["keep"]);
1282
+ expect(res.body.entities.map((e: SnapshotEntity) => e.data?.name)).toEqual(["keep"]);
1283
1283
  });
1284
1284
  });
1285
1285
  });
@@ -1,6 +1,5 @@
1
1
  import {beforeAll, beforeEach, describe, expect, it} from "bun:test";
2
2
  import {type Model, model, Schema} from "mongoose";
3
- import type {ModelRouterOptions} from "../api";
4
3
  import {createdUpdatedPlugin, type IsDeleted, isDeletedPlugin} from "../plugins";
5
4
  import {setupDb} from "../tests";
6
5
  import {SyncCounter, SyncScopeMove} from "./models";
@@ -85,7 +84,7 @@ const UnregisteredModel = model<SeqBroadcastThing>(
85
84
 
86
85
  const stubOptions = {
87
86
  permissions: {create: [], delete: [], list: [], read: [], update: []},
88
- } as unknown as ModelRouterOptions<SeqTenantThing>;
87
+ };
89
88
 
90
89
  const TENANT_TAG = "seqPluginTenantThings";
91
90
  const CUSTOM_TAG = "seqPluginCustomThings";
@@ -1267,7 +1267,7 @@ describe("emitSyncDeltaForChange", () => {
1267
1267
  const deltas = io.emissions.filter((e) => e.event === "sync:delta");
1268
1268
  expect(deltas).toHaveLength(1);
1269
1269
  const receiver = io.sockets.sockets.get(deltas[0].socketId);
1270
- expect(receiver.decodedToken.id).toBe("user1");
1270
+ expect(receiver?.decodedToken.id).toBe("user1");
1271
1271
  });
1272
1272
 
1273
1273
  it("C7: soft delete emits a delete delta with deleted true and NO data (tombstone stripped)", async () => {
@@ -1697,9 +1697,10 @@ describe("sync:delta — change stream integration", () => {
1697
1697
  const docId = String(doc._id);
1698
1698
  await waitForDelta(io, (d) => d.id === docId);
1699
1699
 
1700
- const legacy = io.emissions.filter(
1701
- (e) => e.event === "sync" && e.payload?.id === docId && e.payload?.method === "create"
1702
- );
1700
+ const legacy = io.emissions.filter((e) => {
1701
+ const payload = e.payload as {id?: string; method?: string} | undefined;
1702
+ return e.event === "sync" && payload?.id === docId && payload?.method === "create";
1703
+ });
1703
1704
  const deltas = io.emissions.filter(
1704
1705
  (e) => e.event === "sync:delta" && (e.payload as SyncDelta).id === docId
1705
1706
  );
@@ -27,9 +27,9 @@ const getNoteModel = (): mongoose.Model<{title?: string}> => {
27
27
  if (mongoose.models.TokenMcpNote) {
28
28
  return mongoose.models.TokenMcpNote as mongoose.Model<{title?: string}>;
29
29
  }
30
- const schema = new Schema({title: {description: "Note title", type: String}});
30
+ const schema = new Schema<{title?: string}>({title: {description: "Note title", type: String}});
31
31
  schema.plugin(createdUpdatedPlugin);
32
- return model("TokenMcpNote", schema);
32
+ return model<{title?: string}>("TokenMcpNote", schema);
33
33
  };
34
34
 
35
35
  const TokenMcpNote = getNoteModel();
@@ -6,17 +6,18 @@ import {join} from "node:path";
6
6
  import mongoose from "mongoose";
7
7
  import type {UserModel as UserModelType} from "./auth";
8
8
  import {runStartupMigrations} from "./migrations/runner";
9
- import {MIGRATION_LOCK_ID, MIGRATIONS_COLLECTION} from "./migrations/types";
9
+ import {MIGRATION_LOCK_ID, MIGRATIONS_COLLECTION, type MigrationStoreDoc} from "./migrations/types";
10
10
  import {TerrenoApp} from "./terrenoApp";
11
11
  import {setupDb, UserModel} from "./tests";
12
+ import {partialEnv} from "./tests/testEnv";
12
13
 
13
14
  const fixtures = (...parts: string[]): string => {
14
- return join(import.meta.dir, "migrations", "fixtures", ...parts);
15
+ return join(__dirname, "migrations", "fixtures", ...parts);
15
16
  };
16
17
 
17
18
  const appliedIds = async (): Promise<string[]> => {
18
19
  const docs = await mongoose.connection
19
- .collection(MIGRATIONS_COLLECTION)
20
+ .collection<MigrationStoreDoc>(MIGRATIONS_COLLECTION)
20
21
  .find({_id: {$ne: MIGRATION_LOCK_ID}})
21
22
  .project({id: 1})
22
23
  .toArray();
@@ -31,7 +32,7 @@ describe("runStartupMigrations", () => {
31
32
 
32
33
  it("does not run when migrations option is omitted", async () => {
33
34
  const result = await runStartupMigrations({
34
- env: {NODE_ENV: "test"},
35
+ env: partialEnv({NODE_ENV: "test"}),
35
36
  mongoose,
36
37
  });
37
38
  expect(result.ran).toBe(false);
@@ -40,7 +41,7 @@ describe("runStartupMigrations", () => {
40
41
 
41
42
  it("does not run when runOnStart is omitted", async () => {
42
43
  const result = await runStartupMigrations({
43
- env: {NODE_ENV: "test"},
44
+ env: partialEnv({NODE_ENV: "test"}),
44
45
  migrations: {dir: fixtures("valid")},
45
46
  mongoose,
46
47
  });
@@ -50,7 +51,7 @@ describe("runStartupMigrations", () => {
50
51
 
51
52
  it("applies pending files when runOnStart is true", async () => {
52
53
  const result = await runStartupMigrations({
53
- env: {NODE_ENV: "test"},
54
+ env: partialEnv({NODE_ENV: "test"}),
54
55
  migrations: {dir: fixtures("valid"), runOnStart: true},
55
56
  mongoose,
56
57
  });
@@ -62,7 +63,7 @@ describe("runStartupMigrations", () => {
62
63
  it("throws in production without ALLOW_MIGRATIONS before applying", async () => {
63
64
  await expect(
64
65
  runStartupMigrations({
65
- env: {NODE_ENV: "production"},
66
+ env: partialEnv({NODE_ENV: "production"}),
66
67
  migrations: {dir: fixtures("valid"), runOnStart: true},
67
68
  mongoose,
68
69
  })