@terreno/api 57.2.0 → 57.4.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/.ai/skills/mongoose-schema-safety/SKILL.md +23 -10
- package/README.md +23 -7
- package/dist/actions.js +19 -7
- package/dist/adminTypes.d.ts +7 -0
- package/dist/adminTypes.js +6 -1
- package/dist/api.d.ts +14 -0
- package/dist/api.js +111 -60
- package/dist/audit/auditApp.d.ts +30 -0
- package/dist/audit/auditApp.js +155 -0
- package/dist/audit/auditEventModel.d.ts +29 -0
- package/dist/audit/auditEventModel.js +102 -0
- package/dist/audit/cloudTasksEnqueue.d.ts +32 -0
- package/dist/audit/cloudTasksEnqueue.js +162 -0
- package/dist/audit/diff.d.ts +10 -0
- package/dist/audit/diff.js +230 -0
- package/dist/audit/processQueue.d.ts +6 -0
- package/dist/audit/processQueue.js +101 -0
- package/dist/audit/rbacSink.d.ts +2 -0
- package/dist/audit/rbacSink.js +82 -0
- package/dist/audit/record.d.ts +56 -0
- package/dist/audit/record.js +373 -0
- package/dist/auth.d.ts +23 -10
- package/dist/auth.js +97 -32
- package/dist/authRecovery.d.ts +5 -0
- package/dist/authRecovery.js +350 -0
- package/dist/authTokens.d.ts +8 -0
- package/dist/authTokens.js +162 -0
- package/dist/betterAuth.d.ts +39 -0
- package/dist/betterAuthApp.d.ts +4 -0
- package/dist/betterAuthApp.js +26 -8
- package/dist/betterAuthSetup.d.ts +44 -2
- package/dist/betterAuthSetup.js +288 -18
- package/dist/collectionRegistry.d.ts +40 -0
- package/dist/collectionRegistry.js +97 -0
- package/dist/configurationApp.d.ts +11 -2
- package/dist/configurationApp.js +2 -4
- package/dist/docLoader.js +35 -6
- package/dist/expressServer.d.ts +26 -3
- package/dist/expressServer.js +79 -11
- package/dist/index.d.ts +42 -1
- package/dist/index.js +84 -2
- package/dist/mcp/auth.d.ts +1 -0
- package/dist/mcp/auth.js +47 -25
- package/dist/mcp/handlers.d.ts +1 -1
- package/dist/mcp/handlers.js +67 -233
- package/dist/mcp/query.d.ts +2 -15
- package/dist/mcp/query.js +8 -8
- package/dist/mcp/registry.d.ts +1 -5
- package/dist/mcp/registry.js +31 -20
- package/dist/mcp/schemaGenerator.d.ts +2 -7
- package/dist/mcp/schemaGenerator.js +41 -116
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +1 -0
- package/dist/mcp/serviceTokens.d.ts +16 -0
- package/dist/mcp/serviceTokens.js +345 -0
- package/dist/mcp/types.d.ts +2 -2
- package/dist/migrations/fixtures/all-down/20260910120000-one.d.ts +4 -0
- package/dist/migrations/fixtures/all-down/20260910120000-one.js +49 -0
- package/dist/migrations/fixtures/all-down/20260910120001-two.d.ts +4 -0
- package/dist/migrations/fixtures/all-down/20260910120001-two.js +49 -0
- package/dist/migrations/fixtures/bad-id/20260910120000-mismatch.d.ts +3 -0
- package/dist/migrations/fixtures/bad-id/20260910120000-mismatch.js +45 -0
- package/dist/migrations/fixtures/bad-name/not-a-migration.d.ts +3 -0
- package/dist/migrations/fixtures/bad-name/not-a-migration.js +45 -0
- package/dist/migrations/fixtures/missing-up/20260910120000-noup.d.ts +2 -0
- package/dist/migrations/fixtures/missing-up/20260910120000-noup.js +5 -0
- package/dist/migrations/fixtures/valid/20260910120000-alpha.d.ts +3 -0
- package/dist/migrations/fixtures/valid/20260910120000-alpha.js +45 -0
- package/dist/migrations/fixtures/valid/20260910120001-beta.d.ts +4 -0
- package/dist/migrations/fixtures/valid/20260910120001-beta.js +49 -0
- package/dist/migrations/generate.d.ts +17 -0
- package/dist/migrations/generate.js +277 -0
- package/dist/migrations/load.d.ts +20 -0
- package/dist/migrations/load.js +236 -0
- package/dist/migrations/lock.d.ts +13 -0
- package/dist/migrations/lock.js +145 -0
- package/dist/migrations/runner.d.ts +42 -0
- package/dist/migrations/runner.js +503 -0
- package/dist/migrations/schemaCatalog.d.ts +44 -0
- package/dist/migrations/schemaCatalog.js +326 -0
- package/dist/migrations/types.d.ts +87 -0
- package/dist/migrations/types.js +7 -0
- package/dist/models/mcpServiceToken.d.ts +3 -0
- package/dist/models/mcpServiceToken.js +208 -0
- package/dist/models/notification.d.ts +2 -0
- package/dist/models/notification.js +62 -0
- package/dist/models/notificationPreference.d.ts +2 -0
- package/dist/models/notificationPreference.js +49 -0
- package/dist/notifications/notificationService.d.ts +40 -0
- package/dist/notifications/notificationService.js +323 -0
- package/dist/notifications/notificationsApp.d.ts +18 -0
- package/dist/notifications/notificationsApp.js +250 -0
- package/dist/notifications/notificationsBeforeSend.d.ts +14 -0
- package/dist/notifications/notificationsBeforeSend.js +77 -0
- package/dist/openApi.d.ts +1 -7
- package/dist/openApi.js +7 -6
- package/dist/openApiBuilder.d.ts +19 -7
- package/dist/openApiBuilder.js +61 -8
- package/dist/openApiCompat.js +1 -1
- package/dist/openApiValidator.d.ts +13 -1
- package/dist/openApiValidator.js +200 -38
- package/dist/orgs/orgContext.d.ts +23 -0
- package/dist/orgs/orgContext.js +198 -0
- package/dist/orgs/orgPermissions.d.ts +4 -0
- package/dist/orgs/orgPermissions.js +77 -0
- package/dist/orgs/orgPlugin.d.ts +13 -0
- package/dist/orgs/orgPlugin.js +84 -0
- package/dist/orgs/organizationModel.d.ts +13 -0
- package/dist/orgs/organizationModel.js +301 -0
- package/dist/orgs/organizationSettings.d.ts +19 -0
- package/dist/orgs/organizationSettings.js +120 -0
- package/dist/orgs/orgsApp.d.ts +28 -0
- package/dist/orgs/orgsApp.js +678 -0
- package/dist/permissions.d.ts +7 -13
- package/dist/permissions.js +8 -31
- package/dist/plugins.d.ts +14 -1
- package/dist/plugins.js +17 -6
- package/dist/populate.d.ts +2 -2
- package/dist/populate.js +47 -42
- package/dist/rateLimit/applyTrustProxy.d.ts +3 -0
- package/dist/rateLimit/applyTrustProxy.js +17 -0
- package/dist/rateLimit/createStore.d.ts +2 -0
- package/dist/rateLimit/createStore.js +28 -0
- package/dist/rateLimit/memoryStore.d.ts +2 -0
- package/dist/rateLimit/memoryStore.js +108 -0
- package/dist/rateLimit/middleware.d.ts +3 -0
- package/dist/rateLimit/middleware.js +109 -0
- package/dist/rateLimit/mongoStore.d.ts +4 -0
- package/dist/rateLimit/mongoStore.js +123 -0
- package/dist/rateLimit/policies.d.ts +10 -0
- package/dist/rateLimit/policies.js +149 -0
- package/dist/rateLimit/redisStore.d.ts +4 -0
- package/dist/rateLimit/redisStore.js +156 -0
- package/dist/rateLimit/types.d.ts +54 -0
- package/dist/rateLimit/types.js +9 -0
- package/dist/rbac/access.js +35 -14
- package/dist/rbac/assertAllowed.d.ts +9 -0
- package/dist/rbac/assertAllowed.js +182 -0
- package/dist/rbac/membershipOrgAdminSource.d.ts +6 -0
- package/dist/rbac/membershipOrgAdminSource.js +122 -0
- package/dist/rbac/modelRouterAccess.d.ts +4 -0
- package/dist/rbac/modelRouterAccess.js +11 -4
- package/dist/rbac/permissionUtils.js +3 -2
- package/dist/rbac/resolve.js +65 -35
- package/dist/rbac/roleModel.d.ts +2 -5
- package/dist/rbac/roleModel.js +18 -4
- package/dist/rbac/routes.js +15 -6
- package/dist/rbac/statements.d.ts +10 -1
- package/dist/rbac/statements.js +19 -2
- package/dist/rbac/types.d.ts +5 -0
- package/dist/realtime/changeStreamWatcher.d.ts +10 -4
- package/dist/realtime/changeStreamWatcher.js +110 -64
- package/dist/realtime/deprecation.d.ts +13 -0
- package/dist/realtime/deprecation.js +33 -0
- package/dist/realtime/realtimeApp.d.ts +2 -1
- package/dist/realtime/realtimeApp.js +11 -11
- package/dist/realtime/registry.d.ts +0 -31
- package/dist/realtime/registry.js +44 -31
- package/dist/realtime/socketAuth.d.ts +5 -5
- package/dist/realtime/socketAuth.js +11 -1
- package/dist/realtime/socketUser.d.ts +5 -1
- package/dist/realtime/types.d.ts +14 -4
- package/dist/schemaMetadata.d.ts +56 -0
- package/dist/schemaMetadata.js +524 -0
- package/dist/seedRunner.d.ts +88 -0
- package/dist/seedRunner.js +627 -0
- package/dist/sync/adminBroadcastScope.d.ts +40 -0
- package/dist/sync/adminBroadcastScope.js +194 -0
- package/dist/sync/adminWindowAccess.d.ts +13 -0
- package/dist/sync/adminWindowAccess.js +96 -0
- package/dist/sync/adminWindowMutation.d.ts +88 -0
- package/dist/sync/adminWindowMutation.js +247 -0
- package/dist/sync/executors.d.ts +19 -3
- package/dist/sync/executors.js +194 -165
- package/dist/sync/loadHarness.js +28 -19
- package/dist/sync/models.js +26 -24
- package/dist/sync/mutationHandler.d.ts +14 -2
- package/dist/sync/mutationHandler.js +201 -76
- package/dist/sync/registrationSideEffects.d.ts +35 -0
- package/dist/sync/registrationSideEffects.js +151 -0
- package/dist/sync/registry.d.ts +2 -52
- package/dist/sync/registry.js +42 -187
- package/dist/sync/routes.d.ts +13 -0
- package/dist/sync/routes.js +116 -58
- package/dist/sync/scripts/compactTombstones.js +0 -2
- package/dist/sync/socketHandlers.d.ts +8 -2
- package/dist/sync/socketHandlers.js +144 -50
- package/dist/sync/streams.d.ts +2 -0
- package/dist/sync/streams.js +7 -1
- package/dist/sync/syncApp.d.ts +4 -3
- package/dist/sync/syncApp.js +5 -4
- package/dist/sync/syncBatch.d.ts +5 -2
- package/dist/sync/syncBatch.js +7 -6
- package/dist/sync/syncSeqPlugin.d.ts +1 -1
- package/dist/sync/syncSeqPlugin.js +20 -16
- package/dist/sync/types.d.ts +18 -0
- package/dist/terrenoApp.d.ts +48 -5
- package/dist/terrenoApp.js +157 -72
- package/dist/tests/createTestData.d.ts +1 -3
- package/dist/tests/createTestData.js +3 -5
- package/dist/tests/models.d.ts +3 -0
- package/dist/tests/models.js +15 -2
- package/dist/tests/testHelper.d.ts +0 -5
- package/dist/tests/testHelper.js +2 -9
- package/dist/types/authToken.d.ts +33 -0
- package/dist/types/authToken.js +2 -0
- package/dist/types/mcpServiceToken.d.ts +41 -0
- package/dist/types/mcpServiceToken.js +2 -0
- package/dist/types/membership.d.ts +23 -0
- package/dist/types/membership.js +2 -0
- package/dist/types/notification.d.ts +28 -0
- package/dist/types/notification.js +2 -0
- package/dist/types/notificationPreference.d.ts +20 -0
- package/dist/types/notificationPreference.js +2 -0
- package/dist/types/organization.d.ts +36 -0
- package/dist/types/organization.js +2 -0
- package/dist/webhooks/headerValue.d.ts +2 -0
- package/dist/webhooks/headerValue.js +14 -0
- package/dist/webhooks/idempotency/memoryStore.d.ts +10 -0
- package/dist/webhooks/idempotency/memoryStore.js +65 -0
- package/dist/webhooks/idempotency/mongoStore.d.ts +4 -0
- package/dist/webhooks/idempotency/mongoStore.js +150 -0
- package/dist/webhooks/idempotency/webhookReceipt.d.ts +17 -0
- package/dist/webhooks/idempotency/webhookReceipt.js +39 -0
- package/dist/webhooks/rawBody.d.ts +15 -0
- package/dist/webhooks/rawBody.js +23 -0
- package/dist/webhooks/timingSafeEqual.d.ts +4 -0
- package/dist/webhooks/timingSafeEqual.js +17 -0
- package/dist/webhooks/verifiers/hmac.d.ts +15 -0
- package/dist/webhooks/verifiers/hmac.js +49 -0
- package/dist/webhooks/verifiers/sendgrid.d.ts +10 -0
- package/dist/webhooks/verifiers/sendgrid.js +56 -0
- package/dist/webhooks/verifiers/stripe.d.ts +9 -0
- package/dist/webhooks/verifiers/stripe.js +99 -0
- package/dist/webhooks/verifiers/twilio.d.ts +9 -0
- package/dist/webhooks/verifiers/twilio.js +112 -0
- package/dist/webhooks/webhooksApp.d.ts +33 -0
- package/dist/webhooks/webhooksApp.js +195 -0
- package/package.json +32 -27
- package/src/__snapshots__/openApi.test.ts.snap +444 -36
- package/src/__snapshots__/openApiBuilder.test.ts.snap +24 -24
- package/src/__snapshots__/schemaMetadata.test.ts.snap +196 -0
- package/src/actions.ts +20 -13
- package/src/adminModelRouter.test.ts +133 -0
- package/src/adminTypes.ts +8 -0
- package/src/api.arrayOperations.test.ts +43 -31
- package/src/api.hooks.test.ts +38 -29
- package/src/api.query.test.ts +31 -31
- package/src/api.test.ts +133 -97
- package/src/api.ts +84 -27
- package/src/audit/auditApp.test.ts +243 -0
- package/src/audit/auditApp.ts +139 -0
- package/src/audit/auditEventModel.ts +156 -0
- package/src/audit/auditRouter.test.ts +456 -0
- package/src/audit/cloudTasksEnqueue.test.ts +124 -0
- package/src/audit/cloudTasksEnqueue.ts +104 -0
- package/src/audit/diff.ts +163 -0
- package/src/audit/processQueue.ts +69 -0
- package/src/audit/rbacSink.test.ts +86 -0
- package/src/audit/rbacSink.ts +42 -0
- package/src/audit/record.test.ts +402 -0
- package/src/audit/record.ts +328 -0
- package/src/auth.test.ts +108 -52
- package/src/auth.ts +98 -29
- package/src/authRecovery.test.ts +281 -0
- package/src/authRecovery.ts +279 -0
- package/src/authTokens.test.ts +94 -0
- package/src/authTokens.ts +118 -0
- package/src/authVerification.test.ts +293 -0
- package/src/betterAuth.ts +31 -0
- package/src/betterAuthApp.test.ts +1 -0
- package/src/betterAuthApp.ts +27 -9
- package/src/betterAuthSetup.test.ts +595 -38
- package/src/betterAuthSetup.ts +261 -5
- package/src/collectionRegistry.test.ts +164 -0
- package/src/collectionRegistry.ts +135 -0
- package/src/configurationApp.ts +13 -7
- package/src/docLoader.test.ts +45 -1
- package/src/docLoader.ts +37 -6
- package/src/express.d.ts +3 -0
- package/src/expressServer.test.ts +180 -68
- package/src/expressServer.ts +75 -19
- package/src/githubAuth.test.ts +60 -55
- package/src/index.ts +127 -0
- package/src/mcp/auth.test.ts +47 -0
- package/src/mcp/auth.ts +32 -11
- package/src/mcp/handlers.test.ts +275 -0
- package/src/mcp/handlers.ts +45 -172
- package/src/mcp/integration.test.ts +59 -9
- package/src/mcp/query.ts +5 -7
- package/src/mcp/registry.ts +29 -20
- package/src/mcp/schemaGenerator.test.ts +8 -0
- package/src/mcp/schemaGenerator.ts +49 -131
- package/src/mcp/server.ts +2 -0
- package/src/mcp/serviceTokens.test.ts +330 -0
- package/src/mcp/serviceTokens.ts +307 -0
- package/src/mcp/toolGenerator.test.ts +82 -1
- package/src/mcp/types.ts +2 -6
- package/src/migrations/cli.test.ts +376 -0
- package/src/migrations/cli.ts +283 -0
- package/src/migrations/fixtures/all-down/20260910120000-one.ts +6 -0
- package/src/migrations/fixtures/all-down/20260910120001-two.ts +6 -0
- package/src/migrations/fixtures/bad-id/20260910120000-mismatch.ts +4 -0
- package/src/migrations/fixtures/bad-name/not-a-migration.ts +4 -0
- package/src/migrations/fixtures/missing-up/20260910120000-noup.ts +2 -0
- package/src/migrations/fixtures/valid/20260910120000-alpha.ts +4 -0
- package/src/migrations/fixtures/valid/20260910120001-beta.ts +6 -0
- package/src/migrations/generate.test.ts +333 -0
- package/src/migrations/generate.ts +216 -0
- package/src/migrations/load.test.ts +103 -0
- package/src/migrations/load.ts +124 -0
- package/src/migrations/lock.test.ts +133 -0
- package/src/migrations/lock.ts +118 -0
- package/src/migrations/runner.test.ts +504 -0
- package/src/migrations/runner.ts +358 -0
- package/src/migrations/schemaCatalog.test.ts +159 -0
- package/src/migrations/schemaCatalog.ts +262 -0
- package/src/migrations/types.ts +94 -0
- package/src/models/mcpServiceToken.test.ts +129 -0
- package/src/models/mcpServiceToken.ts +158 -0
- package/src/models/notification.ts +68 -0
- package/src/models/notificationPreference.ts +62 -0
- package/src/notifications/notificationService.ts +254 -0
- package/src/notifications/notificationsApp.test.ts +505 -0
- package/src/notifications/notificationsApp.ts +200 -0
- package/src/notifications/notificationsBeforeSend.ts +51 -0
- package/src/openApi.test.ts +80 -65
- package/src/openApi.ts +2 -1
- package/src/openApiBuilder.test.ts +95 -7
- package/src/openApiBuilder.ts +60 -12
- package/src/openApiCompat.ts +1 -1
- package/src/openApiValidator.test.ts +270 -56
- package/src/openApiValidator.ts +219 -36
- package/src/orgs/orgAccessOptIn.test.ts +87 -0
- package/src/orgs/orgContext.test.ts +259 -0
- package/src/orgs/orgContext.ts +151 -0
- package/src/orgs/orgPermissions.test.ts +105 -0
- package/src/orgs/orgPermissions.ts +40 -0
- package/src/orgs/orgPlugin.test.ts +130 -0
- package/src/orgs/orgPlugin.ts +70 -0
- package/src/orgs/orgRbac.test.ts +267 -0
- package/src/orgs/orgSecurityDefects.test.ts +415 -0
- package/src/orgs/organizationModel.test.ts +205 -0
- package/src/orgs/organizationModel.ts +257 -0
- package/src/orgs/organizationSettings.test.ts +113 -0
- package/src/orgs/organizationSettings.ts +126 -0
- package/src/orgs/orgsApp.test.ts +382 -0
- package/src/orgs/orgsApp.ts +563 -0
- package/src/permissions.test.ts +62 -36
- package/src/permissions.ts +8 -30
- package/src/plugins.test.ts +14 -0
- package/src/plugins.ts +34 -9
- package/src/populate.test.ts +34 -0
- package/src/populate.ts +40 -29
- package/src/rateLimit/applyTrustProxy.ts +17 -0
- package/src/rateLimit/createStore.ts +25 -0
- package/src/rateLimit/memoryStore.ts +40 -0
- package/src/rateLimit/middleware.ts +79 -0
- package/src/rateLimit/mongoStore.test.ts +80 -0
- package/src/rateLimit/mongoStore.ts +77 -0
- package/src/rateLimit/policies.ts +130 -0
- package/src/rateLimit/rateLimit.test.ts +328 -0
- package/src/rateLimit/redisStore.ioredis.test.ts +29 -0
- package/src/rateLimit/redisStore.test.ts +114 -0
- package/src/rateLimit/redisStore.ts +86 -0
- package/src/rateLimit/types.ts +64 -0
- package/src/rbac/access.ts +16 -4
- package/src/rbac/assertAllowed.test.ts +325 -0
- package/src/rbac/assertAllowed.ts +157 -0
- package/src/rbac/backfillAdmins.test.ts +124 -0
- package/src/rbac/fieldViews.test.ts +89 -0
- package/src/rbac/membershipOrgAdminSource.ts +59 -0
- package/src/rbac/modelRouterAccess.test.ts +126 -0
- package/src/rbac/modelRouterAccess.ts +8 -2
- package/src/rbac/permissionUtils.test.ts +26 -5
- package/src/rbac/permissionUtils.ts +3 -2
- package/src/rbac/realtimeAccess.test.ts +109 -1
- package/src/rbac/resolve.test.ts +34 -2
- package/src/rbac/resolve.ts +31 -11
- package/src/rbac/roleManager.test.ts +169 -0
- package/src/rbac/roleModel.test.ts +34 -1
- package/src/rbac/roleModel.ts +17 -1
- package/src/rbac/routes.test.ts +233 -0
- package/src/rbac/routes.ts +16 -6
- package/src/rbac/statements.test.ts +19 -0
- package/src/rbac/statements.ts +19 -1
- package/src/rbac/types.ts +5 -0
- package/src/realtime/changeStreamWatcher.ts +73 -33
- package/src/realtime/deprecation.test.ts +60 -0
- package/src/realtime/deprecation.ts +33 -0
- package/src/realtime/realtime.test.ts +365 -189
- package/src/realtime/realtimeApp.ts +11 -11
- package/src/realtime/realtimeAppSetup.test.ts +32 -5
- package/src/realtime/registry.ts +48 -42
- package/src/realtime/sessionRevalidation.test.ts +57 -44
- package/src/realtime/socketAuth.test.ts +75 -23
- package/src/realtime/socketAuth.ts +17 -6
- package/src/realtime/socketUser.ts +5 -3
- package/src/realtime/types.ts +14 -4
- package/src/schemaMetadata.test.ts +419 -0
- package/src/schemaMetadata.ts +593 -0
- package/src/scrubAdminFields.test.ts +105 -0
- package/src/seedRunner.test.ts +591 -0
- package/src/seedRunner.ts +464 -0
- package/src/sync/adminBroadcastConfig.test.ts +96 -0
- package/src/sync/adminBroadcastScope.test.ts +155 -0
- package/src/sync/adminBroadcastScope.ts +123 -0
- package/src/sync/adminWindowAccess.test.ts +57 -0
- package/src/sync/adminWindowAccess.ts +32 -0
- package/src/sync/adminWindowMutation.test.ts +450 -0
- package/src/sync/adminWindowMutation.ts +283 -0
- package/src/sync/docMatchesMutationData.test.ts +16 -0
- package/src/sync/ensureSyncIndexes.test.ts +54 -15
- package/src/sync/executors.test.ts +40 -0
- package/src/sync/executors.ts +57 -18
- package/src/sync/integration.test.ts +15 -7
- package/src/sync/loadHarness.ts +28 -19
- package/src/sync/models.ts +32 -18
- package/src/sync/mutationHandler.test.ts +293 -17
- package/src/sync/mutationHandler.ts +180 -36
- package/src/sync/registrationSideEffects.test.ts +126 -0
- package/src/sync/registrationSideEffects.ts +131 -0
- package/src/sync/registry.ts +49 -171
- package/src/sync/routes.ts +55 -10
- package/src/sync/scripts/compactTombstones.ts +0 -2
- package/src/sync/sessionRevalidationIntegration.test.ts +12 -11
- package/src/sync/socketHandlers.ts +154 -58
- package/src/sync/streams.ts +6 -0
- package/src/sync/sync.test.ts +28 -25
- package/src/sync/syncApp.ts +5 -4
- package/src/sync/syncBatch.ts +10 -4
- package/src/sync/syncFrontier.test.ts +17 -15
- package/src/sync/syncPhaseC.test.ts +54 -43
- package/src/sync/syncRoutes.test.ts +347 -38
- package/src/sync/syncSeqPlugin.ts +66 -44
- package/src/sync/syncSocket.test.ts +341 -81
- package/src/sync/types.ts +20 -0
- package/src/terrenoApp.mcpServiceTokens.test.ts +173 -0
- package/src/terrenoApp.migrations.test.ts +114 -0
- package/src/terrenoApp.test.ts +41 -0
- package/src/terrenoApp.ts +181 -46
- package/src/tests/createTestData.ts +2 -2
- package/src/tests/models.ts +24 -3
- package/src/tests/testHelper.ts +1 -7
- package/src/types/authToken.ts +41 -0
- package/src/types/mcpServiceToken.ts +48 -0
- package/src/types/membership.ts +48 -0
- package/src/types/notification.ts +34 -0
- package/src/types/notificationPreference.ts +28 -0
- package/src/types/organization.ts +49 -0
- package/src/webhooks/headerValue.test.ts +22 -0
- package/src/webhooks/headerValue.ts +12 -0
- package/src/webhooks/idempotency/memoryStore.ts +34 -0
- package/src/webhooks/idempotency/mongoStore.test.ts +274 -0
- package/src/webhooks/idempotency/mongoStore.ts +83 -0
- package/src/webhooks/idempotency/webhookReceipt.ts +67 -0
- package/src/webhooks/rawBody.test.ts +107 -0
- package/src/webhooks/rawBody.ts +24 -0
- package/src/webhooks/timingSafeEqual.ts +16 -0
- package/src/webhooks/verifiers/hmac.test.ts +110 -0
- package/src/webhooks/verifiers/hmac.ts +54 -0
- package/src/webhooks/verifiers/providerVerifiers.test.ts +388 -0
- package/src/webhooks/verifiers/sendgrid.ts +59 -0
- package/src/webhooks/verifiers/stripe.ts +67 -0
- package/src/webhooks/verifiers/twilio.ts +69 -0
- package/src/webhooks/webhooksApp.test.ts +221 -0
- package/src/webhooks/webhooksApp.ts +144 -0
- package/tsconfig.json +1 -1
- package/tsconfig.typedoc.json +2 -1
- package/dist/vendor/wesleytodd-openapi/lib/convert-yaml.d.ts +0 -2
- package/dist/vendor/wesleytodd-openapi/lib/convert-yaml.js +0 -13
- package/src/vendor/wesleytodd-openapi/lib/convert-yaml.js +0 -13
package/src/expressServer.ts
CHANGED
|
@@ -7,6 +7,7 @@ import cloneDeep from "lodash/cloneDeep";
|
|
|
7
7
|
import onFinished from "on-finished";
|
|
8
8
|
import passport from "passport";
|
|
9
9
|
import type {ModelRouterOptions} from "./api";
|
|
10
|
+
import type {User} from "./auth";
|
|
10
11
|
import {APIError} from "./errors";
|
|
11
12
|
import {type LoggingOptions, logger} from "./logger";
|
|
12
13
|
import {sendToSlack} from "./notifiers/slackNotifier";
|
|
@@ -14,6 +15,47 @@ import {sendToSlack} from "./notifiers/slackNotifier";
|
|
|
14
15
|
const SLOW_READ_MAX = 200;
|
|
15
16
|
const SLOW_WRITE_MAX = 500;
|
|
16
17
|
const IS_JEST = process.env.JEST_WORKER_ID !== undefined;
|
|
18
|
+
const SENSITIVE_REQUEST_BODY_KEYS = [
|
|
19
|
+
"newPassword",
|
|
20
|
+
"oldPassword",
|
|
21
|
+
"password",
|
|
22
|
+
"refreshToken",
|
|
23
|
+
"token",
|
|
24
|
+
] as const;
|
|
25
|
+
|
|
26
|
+
const redactSensitiveRequestBody = (body: Record<string, unknown>): Record<string, unknown> => {
|
|
27
|
+
const bodyCopy = cloneDeep(body);
|
|
28
|
+
for (const key of SENSITIVE_REQUEST_BODY_KEYS) {
|
|
29
|
+
if (key in bodyCopy && bodyCopy[key] !== undefined) {
|
|
30
|
+
bodyCopy[key] = "<REDACTED>";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return bodyCopy;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const sensitiveQueryKeySet = new Set<string>(SENSITIVE_REQUEST_BODY_KEYS);
|
|
37
|
+
|
|
38
|
+
export const redactSensitiveRequestUrl = (url: string | undefined): string => {
|
|
39
|
+
if (!url) {
|
|
40
|
+
return "";
|
|
41
|
+
}
|
|
42
|
+
const isAbsolute = /^[a-z][a-z0-9+.-]*:/i.test(url);
|
|
43
|
+
const parsed = new URL(url, "http://terreno.invalid");
|
|
44
|
+
let didRedact = false;
|
|
45
|
+
for (const key of parsed.searchParams.keys()) {
|
|
46
|
+
if (sensitiveQueryKeySet.has(key)) {
|
|
47
|
+
parsed.searchParams.set(key, "<REDACTED>");
|
|
48
|
+
didRedact = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!didRedact) {
|
|
52
|
+
return url;
|
|
53
|
+
}
|
|
54
|
+
if (isAbsolute) {
|
|
55
|
+
return parsed.toString();
|
|
56
|
+
}
|
|
57
|
+
return `${parsed.pathname}${parsed.search}${parsed.hash}`;
|
|
58
|
+
};
|
|
17
59
|
|
|
18
60
|
export const setupEnvironment = (): void => {
|
|
19
61
|
if (!process.env.TOKEN_ISSUER) {
|
|
@@ -72,10 +114,12 @@ const logRequestsFinished = (req: LoggableRequest, res: LoggableResponse, startT
|
|
|
72
114
|
} else if (req.route) {
|
|
73
115
|
pathName = req.route.path;
|
|
74
116
|
} else if (res.statusCode != null && res.statusCode < 400) {
|
|
75
|
-
logger.warn(`Request without route: ${req.originalUrl}`);
|
|
117
|
+
logger.warn(`Request without route: ${redactSensitiveRequestUrl(req.originalUrl)}`);
|
|
76
118
|
}
|
|
77
119
|
if (process.env.DISABLE_LOG_ALL_REQUESTS !== "true") {
|
|
78
|
-
logger.debug(
|
|
120
|
+
logger.debug(
|
|
121
|
+
`${req.method} -> ${redactSensitiveRequestUrl(req.originalUrl)} ${res.statusCode} ${`${diffInMs}ms`}`
|
|
122
|
+
);
|
|
79
123
|
}
|
|
80
124
|
if (options.logSlowRequests) {
|
|
81
125
|
if (diffInMs > slowReadMs && req.method === "GET") {
|
|
@@ -83,7 +127,7 @@ const logRequestsFinished = (req: LoggableRequest, res: LoggableResponse, startT
|
|
|
83
127
|
`Slow GET request, ${JSON.stringify({
|
|
84
128
|
pathName,
|
|
85
129
|
requestTime: diffInMs,
|
|
86
|
-
url: req.originalUrl,
|
|
130
|
+
url: redactSensitiveRequestUrl(req.originalUrl),
|
|
87
131
|
})}`
|
|
88
132
|
);
|
|
89
133
|
} else if (diffInMs > slowWriteMs) {
|
|
@@ -91,7 +135,7 @@ const logRequestsFinished = (req: LoggableRequest, res: LoggableResponse, startT
|
|
|
91
135
|
`Slow write request ${JSON.stringify({
|
|
92
136
|
pathName,
|
|
93
137
|
requestTime: diffInMs,
|
|
94
|
-
url: req.originalUrl,
|
|
138
|
+
url: redactSensitiveRequestUrl(req.originalUrl),
|
|
95
139
|
})}`
|
|
96
140
|
);
|
|
97
141
|
}
|
|
@@ -120,15 +164,11 @@ export const logRequests = (
|
|
|
120
164
|
|
|
121
165
|
let body = "";
|
|
122
166
|
if (req.body && Object.keys(req.body).length > 0) {
|
|
123
|
-
|
|
124
|
-
if (bodyCopy.password) {
|
|
125
|
-
bodyCopy.password = "<PASSWORD>";
|
|
126
|
-
}
|
|
127
|
-
body = ` Body: ${JSON.stringify(bodyCopy)}`;
|
|
167
|
+
body = ` Body: ${JSON.stringify(redactSensitiveRequestBody(req.body))}`;
|
|
128
168
|
}
|
|
129
169
|
|
|
130
170
|
if (process.env.DISABLE_LOG_ALL_REQUESTS !== "true") {
|
|
131
|
-
logger.debug(`${req.method} <- ${req.url}${userString}${body}`);
|
|
171
|
+
logger.debug(`${req.method} <- ${redactSensitiveRequestUrl(req.url)}${userString}${body}`);
|
|
132
172
|
}
|
|
133
173
|
onFinished(res as unknown as OutgoingMessage, () => logRequestsFinished(req, res, startTime));
|
|
134
174
|
next();
|
|
@@ -168,16 +208,32 @@ export const createRouterWithAuth = (
|
|
|
168
208
|
]);
|
|
169
209
|
};
|
|
170
210
|
|
|
211
|
+
export interface AuthRecoveryMail {
|
|
212
|
+
html?: string;
|
|
213
|
+
subject: string;
|
|
214
|
+
text: string;
|
|
215
|
+
to: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
171
218
|
export interface AuthOptions {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
219
|
+
generateJWTPayload?: (user: User) => Record<string, unknown>;
|
|
220
|
+
generateTokenExpiration?: (user: User) => number | jwt.SignOptions["expiresIn"];
|
|
221
|
+
generateRefreshTokenExpiration?: (user: User) => number | jwt.SignOptions["expiresIn"];
|
|
222
|
+
/** Public web/app origin used in password-reset and verification links. */
|
|
223
|
+
publicAppUrl?: string;
|
|
224
|
+
/**
|
|
225
|
+
* Deliver recovery mail (forgot password / verify email). Wire to
|
|
226
|
+
* `getCommsService().sendMail` when `@terreno/comms` is registered.
|
|
227
|
+
*/
|
|
228
|
+
sendMail?: (message: AuthRecoveryMail) => Promise<void>;
|
|
229
|
+
/** When true, unverified users receive 403 `email-not-verified` on login. Default false. */
|
|
230
|
+
requireEmailVerification?: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* After a successful JWT password reset, update the Better Auth credential hash
|
|
233
|
+
* and delete that user's Better Auth sessions. TerrenoApp wires this when
|
|
234
|
+
* BetterAuthApp is registered.
|
|
235
|
+
*/
|
|
236
|
+
syncPasswordResetToBetterAuth?: (user: User, password: string) => Promise<void>;
|
|
181
237
|
}
|
|
182
238
|
|
|
183
239
|
export const cronjob = (
|
package/src/githubAuth.test.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
// noExplicitAny: test mock typing
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
1
|
import {afterEach, beforeEach, describe, expect, it, setSystemTime} from "bun:test";
|
|
4
2
|
import type express from "express";
|
|
5
|
-
import mongoose, {model, Schema} from "mongoose";
|
|
3
|
+
import mongoose, {type Model, model, Schema} from "mongoose";
|
|
6
4
|
import passport from "passport";
|
|
7
5
|
import passportLocalMongoose from "passport-local-mongoose";
|
|
8
6
|
import supertest from "supertest";
|
|
@@ -72,22 +70,26 @@ const testUserSchema = new Schema<TestUser>({
|
|
|
72
70
|
username: {description: "The user's username", type: String},
|
|
73
71
|
});
|
|
74
72
|
|
|
75
|
-
testUserSchema.plugin(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
testUserSchema.plugin(
|
|
74
|
+
passportLocalMongoose as unknown as (schema: Schema, options?: Record<string, unknown>) => void,
|
|
75
|
+
{
|
|
76
|
+
attemptsField: "attempts",
|
|
77
|
+
interval: 1,
|
|
78
|
+
limitAttempts: true,
|
|
79
|
+
maxAttempts: 3,
|
|
80
|
+
maxInterval: 1,
|
|
81
|
+
usernameCaseInsensitive: true,
|
|
82
|
+
usernameField: "email",
|
|
83
|
+
}
|
|
84
|
+
);
|
|
84
85
|
testUserSchema.plugin(createdUpdatedPlugin);
|
|
85
86
|
testUserSchema.plugin(isDisabledPlugin);
|
|
86
87
|
testUserSchema.plugin(githubUserPlugin);
|
|
87
88
|
|
|
88
89
|
// Get or create model to avoid model redefinition errors
|
|
89
90
|
const GitHubTestUserModel =
|
|
90
|
-
mongoose.models.GitHubTestUser
|
|
91
|
+
(mongoose.models.GitHubTestUser as Model<TestUser> | undefined) ??
|
|
92
|
+
model<TestUser>("GitHubTestUser", testUserSchema);
|
|
91
93
|
|
|
92
94
|
// Connect to database before tests
|
|
93
95
|
const connectDb = async () => {
|
|
@@ -114,9 +116,9 @@ describe("githubUserPlugin", () => {
|
|
|
114
116
|
|
|
115
117
|
it("githubId is indexed and sparse", () => {
|
|
116
118
|
const githubIdPath = testUserSchema.path("githubId");
|
|
117
|
-
expect(
|
|
118
|
-
expect(
|
|
119
|
-
expect(
|
|
119
|
+
expect(githubIdPath.options.index).toBe(true);
|
|
120
|
+
expect(githubIdPath.options.sparse).toBe(true);
|
|
121
|
+
expect(githubIdPath.options.unique).toBe(true);
|
|
120
122
|
});
|
|
121
123
|
});
|
|
122
124
|
|
|
@@ -136,7 +138,7 @@ describe("GitHub auth routes", () => {
|
|
|
136
138
|
email: "test@example.com",
|
|
137
139
|
name: "Test User",
|
|
138
140
|
});
|
|
139
|
-
await (testUser as
|
|
141
|
+
await (testUser as unknown as PasswordedDocument).setPassword("password123");
|
|
140
142
|
await testUser.save();
|
|
141
143
|
|
|
142
144
|
function addRoutes(router: express.Router): void {
|
|
@@ -152,7 +154,7 @@ describe("GitHub auth routes", () => {
|
|
|
152
154
|
clientSecret: "test-client-secret",
|
|
153
155
|
},
|
|
154
156
|
skipListen: true,
|
|
155
|
-
userModel: GitHubTestUserModel as
|
|
157
|
+
userModel: GitHubTestUserModel as unknown as UserModel,
|
|
156
158
|
}).build();
|
|
157
159
|
agent = supertest.agent(app);
|
|
158
160
|
});
|
|
@@ -187,8 +189,8 @@ describe("GitHub auth routes", () => {
|
|
|
187
189
|
// Link github to this user
|
|
188
190
|
const user = await GitHubTestUserModel.findOne({email: "test@example.com"});
|
|
189
191
|
if (user) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
+
user.githubId = "99999";
|
|
193
|
+
user.githubUsername = "testghuser";
|
|
192
194
|
await user.save();
|
|
193
195
|
}
|
|
194
196
|
|
|
@@ -202,8 +204,8 @@ describe("GitHub auth routes", () => {
|
|
|
202
204
|
|
|
203
205
|
// Verify github fields are cleared
|
|
204
206
|
const updatedUser = await GitHubTestUserModel.findOne({email: "test@example.com"});
|
|
205
|
-
expect(
|
|
206
|
-
expect(
|
|
207
|
+
expect(updatedUser?.githubId).toBeUndefined();
|
|
208
|
+
expect(updatedUser?.githubUsername).toBeUndefined();
|
|
207
209
|
});
|
|
208
210
|
|
|
209
211
|
it("user can have both password and GitHub auth", async () => {
|
|
@@ -214,8 +216,8 @@ describe("GitHub auth routes", () => {
|
|
|
214
216
|
}
|
|
215
217
|
|
|
216
218
|
// Link GitHub
|
|
217
|
-
|
|
218
|
-
|
|
219
|
+
user.githubId = "88888";
|
|
220
|
+
user.githubUsername = "linkeduser";
|
|
219
221
|
await user.save();
|
|
220
222
|
|
|
221
223
|
// Can still login with password
|
|
@@ -230,8 +232,8 @@ describe("GitHub auth routes", () => {
|
|
|
230
232
|
// and we verify GitHub fields are set
|
|
231
233
|
const updatedUser = await GitHubTestUserModel.findOne({email: "test@example.com"});
|
|
232
234
|
expect(updatedUser).toBeDefined();
|
|
233
|
-
expect(
|
|
234
|
-
expect(
|
|
235
|
+
expect(updatedUser?.githubId).toBe("88888");
|
|
236
|
+
expect(updatedUser?.githubUsername).toBe("linkeduser");
|
|
235
237
|
});
|
|
236
238
|
});
|
|
237
239
|
|
|
@@ -253,7 +255,7 @@ describe("GitHub auth disabled", () => {
|
|
|
253
255
|
app = new TerrenoApp({
|
|
254
256
|
configureApp: addRoutes,
|
|
255
257
|
skipListen: true,
|
|
256
|
-
userModel: GitHubTestUserModel as
|
|
258
|
+
userModel: GitHubTestUserModel as unknown as UserModel,
|
|
257
259
|
}).build();
|
|
258
260
|
agent = supertest.agent(app);
|
|
259
261
|
});
|
|
@@ -282,7 +284,10 @@ interface VerifyError {
|
|
|
282
284
|
message?: string;
|
|
283
285
|
}
|
|
284
286
|
|
|
285
|
-
type VerifiedUser =
|
|
287
|
+
type VerifiedUser = {
|
|
288
|
+
_id: mongoose.Types.ObjectId | string;
|
|
289
|
+
email?: string;
|
|
290
|
+
} & Partial<GitHubUserFields>;
|
|
286
291
|
|
|
287
292
|
interface VerifyStrategy {
|
|
288
293
|
_verify: (
|
|
@@ -316,7 +321,7 @@ const invokeGitHubVerify = (
|
|
|
316
321
|
};
|
|
317
322
|
|
|
318
323
|
describe("GitHub strategy verify callback", () => {
|
|
319
|
-
const testApp = {get: () => {}, use: () => {}} as
|
|
324
|
+
const testApp = {get: () => {}, use: () => {}} as unknown as express.Application;
|
|
320
325
|
|
|
321
326
|
beforeEach(async () => {
|
|
322
327
|
await connectDb();
|
|
@@ -325,7 +330,7 @@ describe("GitHub strategy verify callback", () => {
|
|
|
325
330
|
|
|
326
331
|
it("uses custom findOrCreateUser when provided", async () => {
|
|
327
332
|
const customUser = {_id: "custom-user-id", email: "custom@example.com"};
|
|
328
|
-
setupGitHubAuth(testApp, GitHubTestUserModel as
|
|
333
|
+
setupGitHubAuth(testApp, GitHubTestUserModel as unknown as UserModel, {
|
|
329
334
|
callbackURL: "http://localhost:9000/auth/github/callback",
|
|
330
335
|
clientId: "id",
|
|
331
336
|
clientSecret: "secret",
|
|
@@ -338,7 +343,7 @@ describe("GitHub strategy verify callback", () => {
|
|
|
338
343
|
});
|
|
339
344
|
|
|
340
345
|
it("creates a new user when no existing GitHub or email user", async () => {
|
|
341
|
-
setupGitHubAuth(testApp, GitHubTestUserModel as
|
|
346
|
+
setupGitHubAuth(testApp, GitHubTestUserModel as unknown as UserModel, {
|
|
342
347
|
callbackURL: "http://localhost:9000/auth/github/callback",
|
|
343
348
|
clientId: "id",
|
|
344
349
|
clientSecret: "secret",
|
|
@@ -366,9 +371,9 @@ describe("GitHub strategy verify callback", () => {
|
|
|
366
371
|
githubId: "gh-existing-1",
|
|
367
372
|
githubUsername: "ghuser",
|
|
368
373
|
name: "GH User",
|
|
369
|
-
}
|
|
374
|
+
});
|
|
370
375
|
|
|
371
|
-
setupGitHubAuth(testApp, GitHubTestUserModel as
|
|
376
|
+
setupGitHubAuth(testApp, GitHubTestUserModel as unknown as UserModel, {
|
|
372
377
|
callbackURL: "http://localhost:9000/auth/github/callback",
|
|
373
378
|
clientId: "id",
|
|
374
379
|
clientSecret: "secret",
|
|
@@ -379,16 +384,16 @@ describe("GitHub strategy verify callback", () => {
|
|
|
379
384
|
username: "ghuser",
|
|
380
385
|
});
|
|
381
386
|
expect(result.err).toBeNull();
|
|
382
|
-
expect(result.user._id.toString()).toBe(
|
|
387
|
+
expect(result.user._id.toString()).toBe(existingUser._id.toString());
|
|
383
388
|
});
|
|
384
389
|
|
|
385
390
|
it("links GitHub to authenticated user when allowAccountLinking=true", async () => {
|
|
386
391
|
const existingUser = await GitHubTestUserModel.create({
|
|
387
392
|
email: "link@example.com",
|
|
388
393
|
name: "Link User",
|
|
389
|
-
}
|
|
394
|
+
});
|
|
390
395
|
|
|
391
|
-
setupGitHubAuth(testApp, GitHubTestUserModel as
|
|
396
|
+
setupGitHubAuth(testApp, GitHubTestUserModel as unknown as UserModel, {
|
|
392
397
|
allowAccountLinking: true,
|
|
393
398
|
callbackURL: "http://localhost:9000/auth/github/callback",
|
|
394
399
|
clientId: "id",
|
|
@@ -410,9 +415,9 @@ describe("GitHub strategy verify callback", () => {
|
|
|
410
415
|
it("rejects linking when allowAccountLinking=false", async () => {
|
|
411
416
|
const existingUser = await GitHubTestUserModel.create({
|
|
412
417
|
email: "nolink@example.com",
|
|
413
|
-
}
|
|
418
|
+
});
|
|
414
419
|
|
|
415
|
-
setupGitHubAuth(testApp, GitHubTestUserModel as
|
|
420
|
+
setupGitHubAuth(testApp, GitHubTestUserModel as unknown as UserModel, {
|
|
416
421
|
allowAccountLinking: false,
|
|
417
422
|
callbackURL: "http://localhost:9000/auth/github/callback",
|
|
418
423
|
clientId: "id",
|
|
@@ -422,19 +427,19 @@ describe("GitHub strategy verify callback", () => {
|
|
|
422
427
|
const req = {user: existingUser};
|
|
423
428
|
const result = await invokeGitHubVerify(req, "access", "refresh", {id: "gh-nolink-1"});
|
|
424
429
|
expect(result.err).toBeDefined();
|
|
425
|
-
expect(
|
|
430
|
+
expect(result.err?.status).toBe(400);
|
|
426
431
|
});
|
|
427
432
|
|
|
428
433
|
it("rejects linking when GitHub account belongs to another user", async () => {
|
|
429
434
|
const userA = await GitHubTestUserModel.create({
|
|
430
435
|
email: "a@example.com",
|
|
431
|
-
}
|
|
436
|
+
});
|
|
432
437
|
await GitHubTestUserModel.create({
|
|
433
438
|
email: "b@example.com",
|
|
434
439
|
githubId: "gh-other-1",
|
|
435
|
-
}
|
|
440
|
+
});
|
|
436
441
|
|
|
437
|
-
setupGitHubAuth(testApp, GitHubTestUserModel as
|
|
442
|
+
setupGitHubAuth(testApp, GitHubTestUserModel as unknown as UserModel, {
|
|
438
443
|
allowAccountLinking: true,
|
|
439
444
|
callbackURL: "http://localhost:9000/auth/github/callback",
|
|
440
445
|
clientId: "id",
|
|
@@ -444,15 +449,15 @@ describe("GitHub strategy verify callback", () => {
|
|
|
444
449
|
const req = {user: userA};
|
|
445
450
|
const result = await invokeGitHubVerify(req, "access", "refresh", {id: "gh-other-1"});
|
|
446
451
|
expect(result.err).toBeDefined();
|
|
447
|
-
expect(
|
|
452
|
+
expect(result.err?.status).toBe(400);
|
|
448
453
|
});
|
|
449
454
|
|
|
450
455
|
it("links GitHub to existing email user when allowAccountLinking is not false", async () => {
|
|
451
456
|
await GitHubTestUserModel.create({
|
|
452
457
|
email: "emailuser@example.com",
|
|
453
|
-
}
|
|
458
|
+
});
|
|
454
459
|
|
|
455
|
-
setupGitHubAuth(testApp, GitHubTestUserModel as
|
|
460
|
+
setupGitHubAuth(testApp, GitHubTestUserModel as unknown as UserModel, {
|
|
456
461
|
callbackURL: "http://localhost:9000/auth/github/callback",
|
|
457
462
|
clientId: "id",
|
|
458
463
|
clientSecret: "secret",
|
|
@@ -471,9 +476,9 @@ describe("GitHub strategy verify callback", () => {
|
|
|
471
476
|
it("rejects email-link when allowAccountLinking=false", async () => {
|
|
472
477
|
await GitHubTestUserModel.create({
|
|
473
478
|
email: "emailnolink@example.com",
|
|
474
|
-
}
|
|
479
|
+
});
|
|
475
480
|
|
|
476
|
-
setupGitHubAuth(testApp, GitHubTestUserModel as
|
|
481
|
+
setupGitHubAuth(testApp, GitHubTestUserModel as unknown as UserModel, {
|
|
477
482
|
allowAccountLinking: false,
|
|
478
483
|
callbackURL: "http://localhost:9000/auth/github/callback",
|
|
479
484
|
clientId: "id",
|
|
@@ -485,12 +490,12 @@ describe("GitHub strategy verify callback", () => {
|
|
|
485
490
|
id: "gh-email-nolink-1",
|
|
486
491
|
});
|
|
487
492
|
expect(result.err).toBeDefined();
|
|
488
|
-
expect(
|
|
493
|
+
expect(result.err?.status).toBe(400);
|
|
489
494
|
});
|
|
490
495
|
|
|
491
496
|
it("returns error when thrown during lookup", async () => {
|
|
492
497
|
// Set up strategy with findOrCreateUser that throws
|
|
493
|
-
setupGitHubAuth(testApp, GitHubTestUserModel as
|
|
498
|
+
setupGitHubAuth(testApp, GitHubTestUserModel as unknown as UserModel, {
|
|
494
499
|
callbackURL: "http://localhost:9000/auth/github/callback",
|
|
495
500
|
clientId: "id",
|
|
496
501
|
clientSecret: "secret",
|
|
@@ -527,7 +532,7 @@ describe("addGitHubAuthRoutes link endpoints", () => {
|
|
|
527
532
|
clientSecret: "test-client-secret",
|
|
528
533
|
},
|
|
529
534
|
skipListen: true,
|
|
530
|
-
userModel: GitHubTestUserModel as
|
|
535
|
+
userModel: GitHubTestUserModel as unknown as UserModel,
|
|
531
536
|
}).build();
|
|
532
537
|
agent = supertest.agent(app);
|
|
533
538
|
});
|
|
@@ -553,8 +558,8 @@ describe("addGitHubAuthRoutes link endpoints", () => {
|
|
|
553
558
|
githubId: "77777",
|
|
554
559
|
githubProfileUrl: "http://profile",
|
|
555
560
|
githubUsername: "ghunlink",
|
|
556
|
-
}
|
|
557
|
-
await (user as
|
|
561
|
+
});
|
|
562
|
+
await (user as unknown as PasswordedDocument).setPassword("password123");
|
|
558
563
|
await user.save();
|
|
559
564
|
|
|
560
565
|
const loginRes = await agent
|
|
@@ -568,9 +573,9 @@ describe("addGitHubAuthRoutes link endpoints", () => {
|
|
|
568
573
|
.expect(200);
|
|
569
574
|
|
|
570
575
|
const updatedUser = await GitHubTestUserModel.findOne({email: "unlinkme@example.com"});
|
|
571
|
-
expect(
|
|
572
|
-
expect(
|
|
573
|
-
expect(
|
|
576
|
+
expect(updatedUser?.githubId).toBeUndefined();
|
|
577
|
+
expect(updatedUser?.githubAvatarUrl).toBeUndefined();
|
|
578
|
+
expect(updatedUser?.githubProfileUrl).toBeUndefined();
|
|
574
579
|
});
|
|
575
580
|
});
|
|
576
581
|
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
export * from "./actions";
|
|
2
2
|
export * from "./adminTypes";
|
|
3
3
|
export * from "./api";
|
|
4
|
+
export {AuditApp, type AuditAppOptions} from "./audit/auditApp";
|
|
5
|
+
export {
|
|
6
|
+
type AuditEventDocument,
|
|
7
|
+
type AuditEventModel,
|
|
8
|
+
type AuditEventOperation,
|
|
9
|
+
type AuditEventSource,
|
|
10
|
+
type AuditEventVerb,
|
|
11
|
+
createAuditEventModel,
|
|
12
|
+
} from "./audit/auditEventModel";
|
|
13
|
+
export {
|
|
14
|
+
AUDIT_SECRET_HEADER,
|
|
15
|
+
auditEnqueueFromEnv,
|
|
16
|
+
type CloudTasksAuditEnqueueOptions,
|
|
17
|
+
createCloudTasksAuditEnqueue,
|
|
18
|
+
} from "./audit/cloudTasksEnqueue";
|
|
19
|
+
export {persistRbacAuditToAuditEvent} from "./audit/rbacSink";
|
|
20
|
+
export {
|
|
21
|
+
type AuditEnqueue,
|
|
22
|
+
type AuditEventWrite,
|
|
23
|
+
type AuditRecorderOptions,
|
|
24
|
+
flushAuditRecorderForTests,
|
|
25
|
+
isAuditRecorderInstalled,
|
|
26
|
+
type ModelRouterAuditConfig,
|
|
27
|
+
type ModelRouterAuditOptions,
|
|
28
|
+
maybeRecordAdminAudit,
|
|
29
|
+
persistEnqueuedAuditEvent,
|
|
30
|
+
recordAuditEvent,
|
|
31
|
+
resetAuditRecorderForTests,
|
|
32
|
+
} from "./audit/record";
|
|
4
33
|
export * from "./auth";
|
|
34
|
+
export * from "./authRecovery";
|
|
35
|
+
export * from "./authTokens";
|
|
5
36
|
export * from "./betterAuth";
|
|
6
37
|
export * from "./betterAuthApp";
|
|
7
38
|
export * from "./betterAuthSetup";
|
|
@@ -26,6 +57,13 @@ export {
|
|
|
26
57
|
} from "./mcp/registry";
|
|
27
58
|
export {generateInputSchema, generateToolDescription} from "./mcp/schemaGenerator";
|
|
28
59
|
export {type MCPServerOptions, mountMCPServer} from "./mcp/server";
|
|
60
|
+
export {
|
|
61
|
+
addMcpServiceTokenRoutes,
|
|
62
|
+
MAX_ACTIVE_MCP_SERVICE_TOKENS,
|
|
63
|
+
type McpServiceTokenRoutesOptions,
|
|
64
|
+
type McpServiceTokensAppOption,
|
|
65
|
+
resolveMcpServiceTokensOption,
|
|
66
|
+
} from "./mcp/serviceTokens";
|
|
29
67
|
export {
|
|
30
68
|
generateAllTools,
|
|
31
69
|
generateToolsForEntry,
|
|
@@ -41,9 +79,36 @@ export type {
|
|
|
41
79
|
MCPToolResult,
|
|
42
80
|
} from "./mcp/types";
|
|
43
81
|
export * from "./middleware";
|
|
82
|
+
export * from "./migrations/generate";
|
|
83
|
+
export * from "./migrations/load";
|
|
84
|
+
export * from "./migrations/lock";
|
|
85
|
+
export * from "./migrations/runner";
|
|
86
|
+
export * from "./migrations/schemaCatalog";
|
|
87
|
+
export * from "./migrations/types";
|
|
44
88
|
export * from "./models/consentForm";
|
|
45
89
|
export * from "./models/consentResponse";
|
|
90
|
+
export * from "./models/mcpServiceToken";
|
|
91
|
+
export * from "./models/notification";
|
|
92
|
+
export * from "./models/notificationPreference";
|
|
46
93
|
export * from "./models/versionConfig";
|
|
94
|
+
export {
|
|
95
|
+
configureNotificationService,
|
|
96
|
+
createNotificationService,
|
|
97
|
+
getNotificationService,
|
|
98
|
+
type NotificationService,
|
|
99
|
+
type NotificationServiceOptions,
|
|
100
|
+
type NotificationsCommsService,
|
|
101
|
+
} from "./notifications/notificationService";
|
|
102
|
+
export {
|
|
103
|
+
NotificationsApp,
|
|
104
|
+
type NotificationsAppOptions,
|
|
105
|
+
} from "./notifications/notificationsApp";
|
|
106
|
+
export {
|
|
107
|
+
type NotificationsBeforeSendChannel,
|
|
108
|
+
type NotificationsBeforeSendContext,
|
|
109
|
+
type NotificationsBeforeSendResult,
|
|
110
|
+
notificationsBeforeSend,
|
|
111
|
+
} from "./notifications/notificationsBeforeSend";
|
|
47
112
|
export * from "./notifiers/googleChatNotifier";
|
|
48
113
|
export * from "./notifiers/slackNotifier";
|
|
49
114
|
export * from "./notifiers/zoomNotifier";
|
|
@@ -51,10 +116,28 @@ export * from "./openApiBuilder";
|
|
|
51
116
|
export * from "./openApiCompat";
|
|
52
117
|
export * from "./openApiEtag";
|
|
53
118
|
export * from "./openApiValidator";
|
|
119
|
+
export * from "./orgs/organizationModel";
|
|
120
|
+
export * from "./orgs/organizationSettings";
|
|
121
|
+
export * from "./orgs/orgContext";
|
|
122
|
+
export * from "./orgs/orgPermissions";
|
|
123
|
+
export * from "./orgs/orgPlugin";
|
|
124
|
+
export * from "./orgs/orgsApp";
|
|
54
125
|
export * from "./permissions";
|
|
55
126
|
export * from "./plugins";
|
|
56
127
|
export * from "./populate";
|
|
128
|
+
export type {
|
|
129
|
+
RateLimitLimits,
|
|
130
|
+
RateLimitOptions,
|
|
131
|
+
RateLimitRedisClient,
|
|
132
|
+
RateLimitStore,
|
|
133
|
+
} from "./rateLimit/types";
|
|
134
|
+
export {
|
|
135
|
+
DEFAULT_API_MAX,
|
|
136
|
+
DEFAULT_AUTH_MAX,
|
|
137
|
+
DEFAULT_WINDOW_MS,
|
|
138
|
+
} from "./rateLimit/types";
|
|
57
139
|
export * from "./rbac/access";
|
|
140
|
+
export {assertAllowed} from "./rbac/assertAllowed";
|
|
58
141
|
export {
|
|
59
142
|
createRbacAuditModel,
|
|
60
143
|
type RbacAuditDocument,
|
|
@@ -66,11 +149,17 @@ export {
|
|
|
66
149
|
backfillAdmins,
|
|
67
150
|
} from "./rbac/backfillAdmins";
|
|
68
151
|
export * from "./rbac/fieldViews";
|
|
152
|
+
export {
|
|
153
|
+
MEMBERSHIP_ORG_ADMIN_PERMISSION_SOURCE_NAME,
|
|
154
|
+
membershipOrgAdminPermissionSource,
|
|
155
|
+
ORG_ADMIN_PERMISSION_BUNDLE,
|
|
156
|
+
} from "./rbac/membershipOrgAdminSource";
|
|
69
157
|
export * from "./rbac/middleware";
|
|
70
158
|
export * from "./rbac/permissionUtils";
|
|
71
159
|
export {
|
|
72
160
|
createRbacRoleModel,
|
|
73
161
|
expandRolePermissions,
|
|
162
|
+
organizationOperatorRole,
|
|
74
163
|
type RbacRoleDocument,
|
|
75
164
|
type RbacRoleModel,
|
|
76
165
|
READ_ONLY_ROLE_PERMISSIONS,
|
|
@@ -150,9 +239,28 @@ export type {
|
|
|
150
239
|
RealtimeEvent,
|
|
151
240
|
} from "./realtime/types";
|
|
152
241
|
export * from "./requestContext";
|
|
242
|
+
export {
|
|
243
|
+
type DescribeModelForRouterOptions,
|
|
244
|
+
type DescribeModelOptions,
|
|
245
|
+
describeModel,
|
|
246
|
+
describeModelForRouter,
|
|
247
|
+
type FieldDescription,
|
|
248
|
+
type FieldKind,
|
|
249
|
+
fieldDescriptionToAdminMeta,
|
|
250
|
+
fieldDescriptionToOpenApiProperty,
|
|
251
|
+
fieldDescriptionToZodType,
|
|
252
|
+
type ModelDescription,
|
|
253
|
+
modelDescriptionToAdminFields,
|
|
254
|
+
modelDescriptionToOpenApiSpec,
|
|
255
|
+
nestDottedFieldDescriptions,
|
|
256
|
+
SYSTEM_FIELD_PATHS,
|
|
257
|
+
} from "./schemaMetadata";
|
|
153
258
|
export * from "./scriptRunner";
|
|
154
259
|
export {adminBodyFieldsToStrip, scrubAdminFields, stripAdminBodyFields} from "./scrubAdminFields";
|
|
155
260
|
export * from "./secretProviders";
|
|
261
|
+
export * from "./seedRunner";
|
|
262
|
+
export * from "./sync/adminBroadcastScope";
|
|
263
|
+
export * from "./sync/adminWindowMutation";
|
|
156
264
|
export * from "./sync/executors";
|
|
157
265
|
export * from "./sync/models";
|
|
158
266
|
export * from "./sync/mutationHandler";
|
|
@@ -174,4 +282,23 @@ export * from "./types/consentForm";
|
|
|
174
282
|
export * from "./types/consentResponse";
|
|
175
283
|
export * from "./utils";
|
|
176
284
|
export * from "./versionCheckPlugin";
|
|
285
|
+
export type {
|
|
286
|
+
WebhookClaimArgs,
|
|
287
|
+
WebhookClaimResult,
|
|
288
|
+
WebhookIdempotencyStore,
|
|
289
|
+
} from "./webhooks/idempotency/memoryStore";
|
|
290
|
+
export {createMemoryIdempotencyStore} from "./webhooks/idempotency/memoryStore";
|
|
291
|
+
export {type HmacSignatureOptions, hmacSignature} from "./webhooks/verifiers/hmac";
|
|
292
|
+
export {
|
|
293
|
+
type SendgridEventSignatureOptions,
|
|
294
|
+
sendgridEventSignature,
|
|
295
|
+
} from "./webhooks/verifiers/sendgrid";
|
|
296
|
+
export {type StripeSignatureOptions, stripeSignature} from "./webhooks/verifiers/stripe";
|
|
297
|
+
export {type TwilioSignatureOptions, twilioSignature} from "./webhooks/verifiers/twilio";
|
|
298
|
+
export {
|
|
299
|
+
type WebhookHandlerContext,
|
|
300
|
+
type WebhookRouteOptions,
|
|
301
|
+
WebhooksApp,
|
|
302
|
+
type WebhooksAppOptions,
|
|
303
|
+
} from "./webhooks/webhooksApp";
|
|
177
304
|
export {z} from "./zodOpenApi";
|