@terreno/api 57.19.2 → 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.
- package/CHANGELOG.md +443 -0
- package/biome.jsonc +1 -0
- package/dist/accountSecurity/accessActions.d.ts +38 -0
- package/dist/accountSecurity/accessActions.js +157 -0
- package/dist/accountSecurity/accountSecurityApp.d.ts +219 -0
- package/dist/accountSecurity/accountSecurityApp.js +438 -0
- package/dist/accountSecurity/accountSecurityService.d.ts +200 -0
- package/dist/accountSecurity/accountSecurityService.js +481 -0
- package/dist/accountSecurity/credentialActions.d.ts +16 -0
- package/dist/accountSecurity/credentialActions.js +189 -0
- package/dist/accountSecurity/membershipActions.d.ts +15 -0
- package/dist/accountSecurity/membershipActions.js +81 -0
- package/dist/accountSecurity/orgSecurityRoutes.d.ts +50 -0
- package/dist/accountSecurity/orgSecurityRoutes.js +149 -0
- package/dist/accountSecurity/securityEventHooks.d.ts +44 -0
- package/dist/accountSecurity/securityEventHooks.js +223 -0
- package/dist/accountSecurity/securityEvents.d.ts +162 -0
- package/dist/accountSecurity/securityEvents.js +114 -0
- package/dist/accountSecurity/securityNotifications.d.ts +125 -0
- package/dist/accountSecurity/securityNotifications.js +333 -0
- package/dist/api.d.ts +3 -3
- package/dist/api.js +38 -6
- package/dist/audit/auditEventModel.d.ts +5 -3
- package/dist/audit/auditEventModel.js +8 -6
- package/dist/audit/processQueue.js +4 -2
- package/dist/audit/record.d.ts +2 -2
- package/dist/audit/record.js +3 -0
- package/dist/authRecovery.js +29 -1
- package/dist/betterAuth.d.ts +179 -10
- package/dist/betterAuthApp.d.ts +15 -0
- package/dist/betterAuthApp.js +23 -0
- package/dist/betterAuthChallengeHeaders.d.ts +37 -0
- package/dist/betterAuthChallengeHeaders.js +180 -0
- package/dist/betterAuthFeatures.d.ts +54 -0
- package/dist/betterAuthFeatures.js +239 -0
- package/dist/betterAuthMethods.d.ts +73 -0
- package/dist/betterAuthMethods.js +55 -0
- package/dist/betterAuthOAuthHandoff.d.ts +10 -2
- package/dist/betterAuthOAuthHandoff.js +222 -24
- package/dist/betterAuthSetPassword.d.ts +33 -0
- package/dist/betterAuthSetPassword.js +166 -0
- package/dist/betterAuthSetup.d.ts +57 -8
- package/dist/betterAuthSetup.js +327 -36
- package/dist/consentApp.d.ts +9 -4
- package/dist/consentApp.js +344 -28
- package/dist/consentStatus.d.ts +60 -0
- package/dist/consentStatus.js +111 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +41 -2
- package/dist/expressServer.js +3 -2
- package/dist/frameworkModelNames.d.ts +4 -0
- package/dist/frameworkModelNames.js +4 -0
- package/dist/index.d.ts +18 -2
- package/dist/index.js +29 -3
- package/dist/mcp/adminTracking.d.ts +28 -0
- package/dist/mcp/adminTracking.js +80 -0
- package/dist/mcp/auth.d.ts +6 -0
- package/dist/mcp/auth.js +12 -2
- package/dist/mcp/oauth.js +151 -11
- package/dist/mcp/oauthMetadata.d.ts +2 -1
- package/dist/mcp/oauthMetadata.js +7 -4
- package/dist/mcp/server.d.ts +8 -0
- package/dist/mcp/server.js +48 -4
- package/dist/models/consentResponse.js +51 -0
- package/dist/models/mcpOAuthClient.js +78 -2
- package/dist/models/mcpOAuthToken.js +55 -4
- package/dist/models/mcpRequestLog.d.ts +2 -0
- package/dist/models/mcpRequestLog.js +73 -0
- package/dist/models/mcpServiceToken.js +4 -0
- package/dist/models/mcpToolSetting.d.ts +2 -0
- package/dist/models/mcpToolSetting.js +119 -0
- package/dist/models/versionConfig.d.ts +2 -0
- package/dist/orgs/membershipGuards.d.ts +7 -0
- package/dist/orgs/membershipGuards.js +32 -0
- package/dist/orgs/orgsApp.d.ts +19 -1
- package/dist/orgs/orgsApp.js +55 -24
- package/dist/rateLimit/policies.js +8 -0
- package/dist/rbac/access.js +2 -1
- package/dist/rbac/auditModel.d.ts +2 -1
- package/dist/rbac/resolve.d.ts +9 -1
- package/dist/rbac/resolve.js +21 -16
- package/dist/rbac/roleManager.d.ts +6 -0
- package/dist/rbac/roleManager.js +8 -7
- package/dist/rbac/roleModel.d.ts +1 -0
- package/dist/rbac/roleModel.js +45 -3
- package/dist/rbac/statements.d.ts +2 -2
- package/dist/rbac/statements.js +10 -1
- package/dist/rbac/types.d.ts +6 -0
- package/dist/rbac/userWriteGuards.js +2 -1
- package/dist/schemaMetadata.js +8 -1
- package/dist/seedRunner.js +7 -2
- package/dist/terrenoApp.d.ts +16 -0
- package/dist/terrenoApp.js +18 -0
- package/dist/tests/models.d.ts +22 -22
- package/dist/tests/models.js +15 -1
- package/dist/tests/testHelper.d.ts +6 -12
- package/dist/tests.d.ts +1 -0
- package/dist/tests.js +3 -1
- package/dist/types/consentResponse.d.ts +8 -0
- package/dist/types/mcpAdmin.d.ts +58 -0
- package/dist/types/mcpAdmin.js +2 -0
- package/dist/types/mcpOAuth.d.ts +37 -2
- package/dist/types/mcpServiceToken.d.ts +2 -0
- package/e2e/smoke.ts +193 -0
- package/package.json +10 -5
- package/src/__snapshots__/openApi.test.ts.snap +288 -0
- package/src/__snapshots__/openApiBuilder.test.ts.snap +96 -0
- package/src/accountSecurity/accessActions.test.ts +723 -0
- package/src/accountSecurity/accessActions.ts +173 -0
- package/src/accountSecurity/accountSecurity.test.ts +947 -0
- package/src/accountSecurity/accountSecurityApp.ts +720 -0
- package/src/accountSecurity/accountSecurityService.ts +826 -0
- package/src/accountSecurity/credentialActions.test.ts +867 -0
- package/src/accountSecurity/credentialActions.ts +260 -0
- package/src/accountSecurity/membershipActions.ts +89 -0
- package/src/accountSecurity/orgSecurityRoutes.test.ts +841 -0
- package/src/accountSecurity/orgSecurityRoutes.ts +232 -0
- package/src/accountSecurity/securityEventHooks.ts +294 -0
- package/src/accountSecurity/securityEvents.ts +165 -0
- package/src/accountSecurity/securityNotifications.test.ts +1323 -0
- package/src/accountSecurity/securityNotifications.ts +516 -0
- package/src/adminModelRouter.test.ts +8 -6
- package/src/api.arrayOperations.test.ts +102 -22
- package/src/api.hooks.test.ts +12 -11
- package/src/api.query.test.ts +2 -2
- package/src/api.test.ts +8 -7
- package/src/api.ts +41 -10
- package/src/audit/auditApp.test.ts +1 -1
- package/src/audit/auditEventModel.ts +10 -7
- package/src/audit/cloudTasksEnqueue.test.ts +19 -14
- package/src/audit/processQueue.ts +4 -2
- package/src/audit/record.test.ts +15 -0
- package/src/audit/record.ts +10 -2
- package/src/auth.test.ts +21 -7
- package/src/authRecovery.test.ts +33 -10
- package/src/authRecovery.ts +34 -1
- package/src/authRecoveryBetterAuth.test.ts +169 -0
- package/src/authVerification.test.ts +7 -7
- package/src/betterAuth.ts +194 -8
- package/src/betterAuthApp.ts +32 -0
- package/src/betterAuthChallengeHeaders.test.ts +476 -0
- package/src/betterAuthChallengeHeaders.ts +227 -0
- package/src/betterAuthFeatures.test.ts +490 -0
- package/src/betterAuthFeatures.ts +283 -0
- package/src/betterAuthLinking.test.ts +846 -0
- package/src/betterAuthMethods.test.ts +138 -0
- package/src/betterAuthMethods.ts +98 -0
- package/src/betterAuthOAuthHandoff.test.ts +482 -69
- package/src/betterAuthOAuthHandoff.ts +293 -33
- package/src/betterAuthOAuthProxy.test.ts +421 -0
- package/src/betterAuthPasswordReset.test.ts +190 -0
- package/src/betterAuthSetPassword.test.ts +378 -0
- package/src/betterAuthSetPassword.ts +213 -0
- package/src/betterAuthSetup.test.ts +115 -57
- package/src/betterAuthSetup.ts +457 -38
- package/src/collectionRegistry.test.ts +4 -4
- package/src/consentApp.test.ts +869 -2
- package/src/consentApp.ts +438 -36
- package/src/consentStatus.test.ts +226 -0
- package/src/consentStatus.ts +171 -0
- package/src/errors.test.ts +81 -0
- package/src/errors.ts +50 -1
- package/src/expressServer.test.ts +29 -0
- package/src/expressServer.ts +3 -2
- package/src/frameworkModelNames.test.ts +8 -0
- package/src/frameworkModelNames.ts +4 -0
- package/src/githubAuth.test.ts +11 -11
- package/src/index.ts +38 -0
- package/src/isolated/migrateCliConnect.isolated.ts +3 -2
- package/src/mcp/actionTools.test.ts +11 -5
- package/src/mcp/adminTracking.test.ts +272 -0
- package/src/mcp/adminTracking.ts +104 -0
- package/src/mcp/auth.ts +18 -2
- package/src/mcp/oauth.test.ts +463 -2
- package/src/mcp/oauth.ts +184 -13
- package/src/mcp/oauthMetadata.ts +5 -2
- package/src/mcp/server.ts +67 -4
- package/src/mcp/serviceTokens.test.ts +2 -1
- package/src/mcp/toolGenerator.test.ts +9 -5
- package/src/migrations/cli.test.ts +15 -14
- package/src/migrations/cli.ts +1 -1
- package/src/migrations/generate.test.ts +2 -2
- package/src/migrations/load.test.ts +1 -1
- package/src/migrations/lock.test.ts +8 -3
- package/src/migrations/runner.test.ts +16 -5
- package/src/migrations/schemaCatalog.test.ts +4 -1
- package/src/models/consentResponse.ts +53 -0
- package/src/models/mcpOAuthClient.ts +100 -3
- package/src/models/mcpOAuthToken.test.ts +42 -0
- package/src/models/mcpOAuthToken.ts +62 -5
- package/src/models/mcpRequestLog.ts +81 -0
- package/src/models/mcpServiceToken.test.ts +23 -0
- package/src/models/mcpServiceToken.ts +10 -0
- package/src/models/mcpToolSetting.test.ts +69 -0
- package/src/models/mcpToolSetting.ts +138 -0
- package/src/models/versionConfig.ts +2 -0
- package/src/notifications/notificationsApp.test.ts +5 -8
- package/src/notifiers/slackWebApi.test.ts +30 -8
- package/src/openApi.test.ts +4 -4
- package/src/openApiValidator.test.ts +3 -3
- package/src/orgs/membershipGuards.ts +39 -0
- package/src/orgs/orgPermissions.test.ts +2 -2
- package/src/orgs/orgPlugin.test.ts +4 -3
- package/src/orgs/orgRbac.test.ts +1 -1
- package/src/orgs/orgSecurityDefects.test.ts +3 -1
- package/src/orgs/organizationSettings.test.ts +1 -1
- package/src/orgs/orgsApp.test.ts +104 -3
- package/src/orgs/orgsApp.ts +69 -28
- package/src/permissions.test.ts +2 -2
- package/src/rateLimit/policies.test.ts +53 -0
- package/src/rateLimit/policies.ts +8 -0
- package/src/rateLimit/redisStore.ioredis.test.ts +3 -2
- package/src/rbac/access.ts +4 -1
- package/src/rbac/assertAllowed.test.ts +1 -1
- package/src/rbac/auditModel.ts +10 -2
- package/src/rbac/realtimeAccess.test.ts +3 -2
- package/src/rbac/resolve.test.ts +65 -0
- package/src/rbac/resolve.ts +37 -17
- package/src/rbac/roleManager.test.ts +64 -0
- package/src/rbac/roleManager.ts +15 -6
- package/src/rbac/roleModel.test.ts +174 -1
- package/src/rbac/roleModel.ts +66 -3
- package/src/rbac/routes.test.ts +58 -0
- package/src/rbac/statements.test.ts +4 -1
- package/src/rbac/statements.ts +11 -1
- package/src/rbac/types.ts +6 -1
- package/src/rbac/userWriteGuards.test.ts +56 -5
- package/src/rbac/userWriteGuards.ts +5 -2
- package/src/realtime/realtime.test.ts +35 -31
- package/src/schemaMetadata.test.ts +39 -0
- package/src/schemaMetadata.ts +11 -1
- package/src/scrubAdminFields.test.ts +1 -1
- package/src/seedRunner.test.ts +56 -0
- package/src/seedRunner.ts +7 -2
- package/src/sync/adminWindowMutation.test.ts +4 -3
- package/src/sync/executors.test.ts +1 -1
- package/src/sync/scripts/compactTombstones.test.ts +4 -3
- package/src/sync/sync.test.ts +1 -1
- package/src/sync/syncPhaseC.test.ts +14 -11
- package/src/sync/syncRoutes.test.ts +8 -8
- package/src/sync/syncSeqPlugin.test.ts +1 -2
- package/src/sync/syncSocket.test.ts +5 -4
- package/src/terrenoApp.mcpServiceTokens.test.ts +2 -2
- package/src/terrenoApp.migrations.test.ts +8 -7
- package/src/terrenoApp.ts +34 -0
- package/src/tests/accountSecurityTestApp.ts +290 -0
- package/src/tests/betterAuthStubs.ts +189 -0
- package/src/tests/bunSetup.ts +1 -1
- package/src/tests/mockOidcProvider.ts +105 -0
- package/src/tests/models.ts +23 -0
- package/src/tests/softwareAuthenticator.ts +183 -0
- package/src/tests/testEnv.ts +7 -0
- package/src/tests.ts +1 -0
- package/src/types/consentResponse.ts +8 -0
- package/src/types/mcpAdmin.ts +80 -0
- package/src/types/mcpOAuth.ts +44 -3
- package/src/types/mcpServiceToken.ts +5 -0
- package/src/webhooks/verifiers/hmac.test.ts +1 -1
- 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
|
|
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(
|
|
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: {
|
|
@@ -417,3 +417,42 @@ describe("fieldDescriptionToZodType", () => {
|
|
|
417
417
|
).toEqual({note: "hello"});
|
|
418
418
|
});
|
|
419
419
|
});
|
|
420
|
+
|
|
421
|
+
const conditionalRequiredSchema = new Schema({
|
|
422
|
+
flagged: {default: false, description: "Whether the record is flagged", type: Boolean},
|
|
423
|
+
kind: {description: "Record kind", required: true, type: String},
|
|
424
|
+
note: {
|
|
425
|
+
description: "Only required for flagged records",
|
|
426
|
+
required: [
|
|
427
|
+
function (this: {flagged?: boolean}): boolean {
|
|
428
|
+
return this.flagged === true;
|
|
429
|
+
},
|
|
430
|
+
"note is required when flagged",
|
|
431
|
+
],
|
|
432
|
+
type: String,
|
|
433
|
+
},
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
const ConditionalRequiredModel =
|
|
437
|
+
mongoose.models.SchemaMetadataConditionalRequired ??
|
|
438
|
+
mongoose.model("SchemaMetadataConditionalRequired", conditionalRequiredSchema);
|
|
439
|
+
|
|
440
|
+
describe("conditionally required fields", () => {
|
|
441
|
+
it("are not marked required, so clients do not expect them on every document", () => {
|
|
442
|
+
const description = describeModel(ConditionalRequiredModel);
|
|
443
|
+
expect(description.fields.kind?.required).toBe(true);
|
|
444
|
+
expect(description.fields.note?.required).toBe(false);
|
|
445
|
+
|
|
446
|
+
const {required} = modelDescriptionToOpenApiSpec(description);
|
|
447
|
+
expect(required).toContain("kind");
|
|
448
|
+
expect(required).not.toContain("note");
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("still enforce the requirement when saving", async () => {
|
|
452
|
+
const doc = new ConditionalRequiredModel({flagged: true, kind: "alert"});
|
|
453
|
+
const error = await doc.validate().catch((validationError: unknown) => validationError);
|
|
454
|
+
expect((error as mongoose.Error.ValidationError).errors.note?.message).toBe(
|
|
455
|
+
"note is required when flagged"
|
|
456
|
+
);
|
|
457
|
+
});
|
|
458
|
+
});
|
package/src/schemaMetadata.ts
CHANGED
|
@@ -55,6 +55,8 @@ interface MongooseSchemaPath {
|
|
|
55
55
|
getEmbeddedSchemaType?: () => MongooseSchemaPath | undefined;
|
|
56
56
|
instance?: string;
|
|
57
57
|
isRequired?: boolean;
|
|
58
|
+
/** What the schema passed as `required`; a function means the field is only sometimes required. */
|
|
59
|
+
originalRequiredValue?: unknown;
|
|
58
60
|
options?: {
|
|
59
61
|
default?: unknown;
|
|
60
62
|
description?: string;
|
|
@@ -143,6 +145,14 @@ const describeCaster = (caster: MongooseSchemaPath): FieldDescription => {
|
|
|
143
145
|
};
|
|
144
146
|
};
|
|
145
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Whether a path is required on every document. A conditional `required` (a function) only
|
|
150
|
+
* applies to some documents, so clients must not treat the field as always present.
|
|
151
|
+
*/
|
|
152
|
+
const isAlwaysRequired = (schemaPath: MongooseSchemaPath): boolean => {
|
|
153
|
+
return Boolean(schemaPath.isRequired) && typeof schemaPath.originalRequiredValue !== "function";
|
|
154
|
+
};
|
|
155
|
+
|
|
146
156
|
const describeSchemaPath = (path: string, schemaPath: MongooseSchemaPath): FieldDescription => {
|
|
147
157
|
const enumValues = schemaPath.enumValues?.length
|
|
148
158
|
? (schemaPath.enumValues as string[])
|
|
@@ -153,7 +163,7 @@ const describeSchemaPath = (path: string, schemaPath: MongooseSchemaPath): Field
|
|
|
153
163
|
enum: enumValues?.length ? enumValues : undefined,
|
|
154
164
|
kind: normalizeKind(schemaPath.instance),
|
|
155
165
|
ref: schemaPath.options?.ref,
|
|
156
|
-
required:
|
|
166
|
+
required: isAlwaysRequired(schemaPath),
|
|
157
167
|
system: isSystemField(path),
|
|
158
168
|
};
|
|
159
169
|
|
|
@@ -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", () => {
|
package/src/seedRunner.test.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import {afterEach, describe, it} from "bun:test";
|
|
2
|
+
import {randomUUID} from "node:crypto";
|
|
2
3
|
import {assert} from "chai";
|
|
3
4
|
import mongoose, {Schema} from "mongoose";
|
|
5
|
+
import passportLocalMongoose from "passport-local-mongoose";
|
|
4
6
|
|
|
7
|
+
import {type HasSetPassword, setPasswordForUser} from "./auth";
|
|
8
|
+
import {createBetterAuth, getMongoClientFromMongoose} from "./betterAuthSetup";
|
|
5
9
|
import {APIError} from "./errors";
|
|
6
10
|
import {isDeletedPlugin} from "./plugins";
|
|
7
11
|
import {runSeedCli, runSeeds, type SeedStep, seedBetterAuthUser} from "./seedRunner";
|
|
@@ -610,3 +614,55 @@ describe("seedBetterAuthUser", () => {
|
|
|
610
614
|
assert.equal((thrown as APIError).title, "Better Auth seed returned no user");
|
|
611
615
|
});
|
|
612
616
|
});
|
|
617
|
+
|
|
618
|
+
const legacySeedUserSchema = new Schema<SeedAuthUserDocument>({
|
|
619
|
+
betterAuthId: {description: "Better Auth id", type: String},
|
|
620
|
+
email: {description: "Email", required: true, type: String},
|
|
621
|
+
name: {description: "Name", type: String},
|
|
622
|
+
});
|
|
623
|
+
legacySeedUserSchema.plugin(
|
|
624
|
+
passportLocalMongoose as unknown as (schema: Schema, options?: Record<string, unknown>) => void,
|
|
625
|
+
{usernameField: "email"}
|
|
626
|
+
);
|
|
627
|
+
const LegacySeedUser =
|
|
628
|
+
(mongoose.models.SeedRunnerLegacyUser as mongoose.Model<SeedAuthUserDocument> | undefined) ??
|
|
629
|
+
mongoose.model<SeedAuthUserDocument>("SeedRunnerLegacyUser", legacySeedUserSchema);
|
|
630
|
+
|
|
631
|
+
describe("seedBetterAuthUser with an existing passport User", () => {
|
|
632
|
+
afterEach(async () => {
|
|
633
|
+
await LegacySeedUser.deleteMany({});
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
for (const withUserModel of [true, false]) {
|
|
637
|
+
it(`links the User when the seed password matches (auth userModel: ${withUserModel})`, async () => {
|
|
638
|
+
const seedUser = {
|
|
639
|
+
email: `legacy-seed-${randomUUID()}@example.com`,
|
|
640
|
+
name: "Legacy Seed",
|
|
641
|
+
password: "testpassword123",
|
|
642
|
+
};
|
|
643
|
+
const legacy = new LegacySeedUser({email: seedUser.email, name: "Legacy"});
|
|
644
|
+
await setPasswordForUser(legacy as unknown as HasSetPassword, seedUser.password);
|
|
645
|
+
await legacy.save();
|
|
646
|
+
const auth = createBetterAuth({
|
|
647
|
+
config: {
|
|
648
|
+
baseURL: "http://localhost:3000",
|
|
649
|
+
enabled: true,
|
|
650
|
+
secret: "test-secret-at-least-32-characters-long",
|
|
651
|
+
},
|
|
652
|
+
mongoClient: getMongoClientFromMongoose(),
|
|
653
|
+
...(withUserModel ? {userModel: LegacySeedUser as never} : {}),
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
const user = await seedBetterAuthUser({
|
|
657
|
+
auth,
|
|
658
|
+
user: seedUser,
|
|
659
|
+
userModel: LegacySeedUser as never,
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
assert.equal(String((user as {_id?: unknown})._id), String(legacy._id));
|
|
663
|
+
assert.equal(await LegacySeedUser.countDocuments({email: seedUser.email}), 1);
|
|
664
|
+
const stored = await LegacySeedUser.findById(legacy._id).lean();
|
|
665
|
+
assert.isString(stored?.betterAuthId);
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
});
|
package/src/seedRunner.ts
CHANGED
|
@@ -172,8 +172,13 @@ export const seedBetterAuthUser = async ({
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
// The seed created or signed in to this Better Auth account itself, so its email is trusted
|
|
175
|
-
// for linking an existing app user (for example one seeded under the legacy JWT flow).
|
|
176
|
-
|
|
175
|
+
// for linking an existing app user (for example one seeded under the legacy JWT flow). With a
|
|
176
|
+
// `userModel` on `auth`, the sign-up itself is refused for a legacy User unless the seed
|
|
177
|
+
// password matches its passport hash, the same way a real sign-up is.
|
|
178
|
+
return syncBetterAuthUser(userModel, authUser, undefined, {
|
|
179
|
+
password: user.password,
|
|
180
|
+
trustEmail: true,
|
|
181
|
+
});
|
|
177
182
|
};
|
|
178
183
|
|
|
179
184
|
const selectSteps = (steps: SeedStep[], only?: string[]): SeedStep[] => {
|
|
@@ -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
|
|
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
|
-
|
|
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
|
};
|
package/src/sync/sync.test.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
]
|
|
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
|
-
]
|
|
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
|
-
|
|
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
|
-
}))
|
|
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
|
-
]
|
|
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
|
|
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
|
|
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));
|