@terreno/api 57.1.0 → 57.3.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/README.md +17 -7
- package/dist/actions.js +19 -7
- package/dist/adminTypes.d.ts +26 -0
- package/dist/api.d.ts +4 -0
- package/dist/api.js +12 -24
- 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 +33 -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 +38 -0
- package/dist/collectionRegistry.js +72 -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 +16 -0
- package/dist/index.js +38 -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 -2
- 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/models/mcpServiceToken.d.ts +3 -0
- package/dist/models/mcpServiceToken.js +208 -0
- package/dist/openApiBuilder.d.ts +5 -4
- package/dist/openApiBuilder.js +61 -8
- package/dist/openApiCompat.js +1 -1
- package/dist/openApiValidator.js +0 -2
- 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 +11 -0
- package/dist/rateLimit/middleware.js +110 -0
- package/dist/rateLimit/mongoStore.d.ts +3 -0
- package/dist/rateLimit/mongoStore.js +122 -0
- package/dist/rateLimit/policies.d.ts +14 -0
- package/dist/rateLimit/policies.js +151 -0
- package/dist/rateLimit/redisStore.d.ts +3 -0
- package/dist/rateLimit/redisStore.js +155 -0
- package/dist/rateLimit/types.d.ts +54 -0
- package/dist/rateLimit/types.js +9 -0
- package/dist/rbac/access.js +5 -1
- package/dist/rbac/assertAllowed.d.ts +9 -0
- package/dist/rbac/assertAllowed.js +182 -0
- package/dist/rbac/modelRouterAccess.d.ts +1 -0
- package/dist/rbac/modelRouterAccess.js +8 -4
- package/dist/rbac/permissionUtils.js +3 -2
- package/dist/rbac/resolve.js +5 -4
- package/dist/rbac/routes.js +15 -6
- package/dist/rbac/statements.d.ts +10 -0
- package/dist/rbac/statements.js +13 -2
- package/dist/realtime/deprecation.d.ts +12 -0
- package/dist/realtime/deprecation.js +32 -0
- package/dist/realtime/realtimeApp.d.ts +1 -1
- package/dist/realtime/realtimeApp.js +10 -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 +513 -0
- package/dist/seedRunner.d.ts +88 -0
- package/dist/seedRunner.js +627 -0
- package/dist/sync/executors.d.ts +12 -2
- package/dist/sync/executors.js +8 -10
- package/dist/sync/loadHarness.js +28 -19
- package/dist/sync/models.js +26 -24
- package/dist/sync/mutationHandler.d.ts +9 -0
- package/dist/sync/mutationHandler.js +11 -6
- 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 +38 -187
- package/dist/sync/routes.js +3 -2
- package/dist/sync/scripts/compactTombstones.js +0 -2
- package/dist/sync/syncApp.d.ts +3 -3
- package/dist/sync/syncApp.js +4 -4
- package/dist/sync/syncBatch.js +3 -2
- package/dist/sync/syncSeqPlugin.d.ts +1 -1
- package/dist/sync/syncSeqPlugin.js +20 -16
- package/dist/terrenoApp.d.ts +19 -5
- package/dist/terrenoApp.js +66 -18
- package/dist/tests/models.d.ts +2 -0
- package/dist/tests/models.js +6 -0
- 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/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 +62 -0
- package/dist/webhooks/idempotency/webhookReceipt.js +39 -0
- package/dist/webhooks/rawBody.d.ts +14 -0
- package/dist/webhooks/rawBody.js +22 -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 +5 -6
- package/src/__snapshots__/openApi.test.ts.snap +270 -0
- package/src/__snapshots__/openApiBuilder.test.ts.snap +30 -12
- package/src/__snapshots__/schemaMetadata.test.ts.snap +197 -0
- package/src/actions.ts +20 -13
- package/src/adminModelRouter.test.ts +133 -0
- package/src/adminTypes.ts +23 -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 +95 -96
- package/src/api.ts +16 -27
- package/src/auth.test.ts +107 -51
- 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 +24 -0
- package/src/betterAuthApp.test.ts +1 -0
- package/src/betterAuthApp.ts +27 -9
- package/src/betterAuthSetup.test.ts +568 -38
- package/src/betterAuthSetup.ts +260 -5
- package/src/collectionRegistry.test.ts +165 -0
- package/src/collectionRegistry.ts +115 -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 +1 -0
- package/src/expressServer.test.ts +130 -66
- package/src/expressServer.ts +75 -19
- package/src/githubAuth.test.ts +60 -55
- package/src/index.ts +58 -0
- package/src/mcp/auth.test.ts +47 -0
- package/src/mcp/auth.ts +32 -11
- package/src/mcp/handlers.ts +45 -172
- package/src/mcp/integration.test.ts +59 -9
- package/src/mcp/query.ts +2 -4
- 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 +1 -1
- package/src/mcp/types.ts +2 -6
- package/src/models/mcpServiceToken.test.ts +129 -0
- package/src/models/mcpServiceToken.ts +158 -0
- package/src/openApi.test.ts +80 -64
- package/src/openApiBuilder.test.ts +95 -7
- package/src/openApiBuilder.ts +46 -9
- package/src/openApiCompat.ts +1 -1
- package/src/openApiValidator.test.ts +49 -54
- package/src/openApiValidator.ts +1 -3
- 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 +76 -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 +85 -0
- package/src/rateLimit/types.ts +64 -0
- package/src/rbac/access.ts +5 -1
- 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/modelRouterAccess.test.ts +126 -0
- package/src/rbac/modelRouterAccess.ts +5 -2
- package/src/rbac/permissionUtils.ts +3 -2
- package/src/rbac/realtimeAccess.test.ts +109 -1
- package/src/rbac/resolve.ts +5 -4
- package/src/rbac/roleManager.test.ts +169 -0
- package/src/rbac/routes.test.ts +233 -0
- package/src/rbac/routes.ts +16 -6
- package/src/rbac/statements.test.ts +2 -0
- package/src/rbac/statements.ts +12 -1
- package/src/realtime/deprecation.test.ts +60 -0
- package/src/realtime/deprecation.ts +32 -0
- package/src/realtime/realtime.test.ts +8 -4
- package/src/realtime/realtimeApp.ts +10 -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 +405 -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/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 +24 -12
- 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 +16 -16
- package/src/sync/mutationHandler.ts +9 -7
- package/src/sync/registrationSideEffects.test.ts +126 -0
- package/src/sync/registrationSideEffects.ts +131 -0
- package/src/sync/registry.ts +45 -171
- package/src/sync/routes.ts +3 -2
- package/src/sync/scripts/compactTombstones.ts +0 -2
- package/src/sync/sessionRevalidationIntegration.test.ts +12 -11
- package/src/sync/sync.test.ts +25 -23
- package/src/sync/syncApp.ts +4 -4
- package/src/sync/syncBatch.ts +3 -2
- package/src/sync/syncFrontier.test.ts +17 -15
- package/src/sync/syncPhaseC.test.ts +54 -43
- package/src/sync/syncRoutes.test.ts +51 -36
- package/src/sync/syncSeqPlugin.ts +66 -44
- package/src/sync/syncSocket.test.ts +112 -81
- package/src/terrenoApp.mcpServiceTokens.test.ts +173 -0
- package/src/terrenoApp.ts +87 -15
- package/src/tests/models.ts +14 -1
- package/src/types/authToken.ts +43 -0
- package/src/types/mcpServiceToken.ts +54 -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 +70 -0
- package/src/webhooks/rawBody.test.ts +74 -0
- package/src/webhooks/rawBody.ts +23 -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
|
@@ -168,8 +168,8 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
168
168
|
"eatenBy": {
|
|
169
169
|
"items": {
|
|
170
170
|
"description": "Users who have eaten this food",
|
|
171
|
-
"
|
|
172
|
-
"type": "
|
|
171
|
+
"format": "objectid",
|
|
172
|
+
"type": "string",
|
|
173
173
|
},
|
|
174
174
|
"type": "array",
|
|
175
175
|
},
|
|
@@ -202,6 +202,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
202
202
|
},
|
|
203
203
|
"userId": {
|
|
204
204
|
"description": "The user who liked the item",
|
|
205
|
+
"format": "objectid",
|
|
205
206
|
"type": "string",
|
|
206
207
|
},
|
|
207
208
|
},
|
|
@@ -216,6 +217,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
216
217
|
},
|
|
217
218
|
"ownerId": {
|
|
218
219
|
"description": "The user who owns this food entry",
|
|
220
|
+
"format": "objectid",
|
|
219
221
|
"type": "string",
|
|
220
222
|
},
|
|
221
223
|
"source": {
|
|
@@ -233,6 +235,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
233
235
|
"type": "string",
|
|
234
236
|
},
|
|
235
237
|
},
|
|
238
|
+
"required": [],
|
|
236
239
|
"type": "object",
|
|
237
240
|
},
|
|
238
241
|
"tags": {
|
|
@@ -373,8 +376,8 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
373
376
|
"eatenBy": {
|
|
374
377
|
"items": {
|
|
375
378
|
"description": "Users who have eaten this food",
|
|
376
|
-
"
|
|
377
|
-
"type": "
|
|
379
|
+
"format": "objectid",
|
|
380
|
+
"type": "string",
|
|
378
381
|
},
|
|
379
382
|
"type": "array",
|
|
380
383
|
},
|
|
@@ -407,6 +410,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
407
410
|
},
|
|
408
411
|
"userId": {
|
|
409
412
|
"description": "The user who liked the item",
|
|
413
|
+
"format": "objectid",
|
|
410
414
|
"type": "string",
|
|
411
415
|
},
|
|
412
416
|
},
|
|
@@ -421,6 +425,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
421
425
|
},
|
|
422
426
|
"ownerId": {
|
|
423
427
|
"description": "The user who owns this food entry",
|
|
428
|
+
"format": "objectid",
|
|
424
429
|
"type": "string",
|
|
425
430
|
},
|
|
426
431
|
"source": {
|
|
@@ -438,6 +443,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
438
443
|
"type": "string",
|
|
439
444
|
},
|
|
440
445
|
},
|
|
446
|
+
"required": [],
|
|
441
447
|
"type": "object",
|
|
442
448
|
},
|
|
443
449
|
"tags": {
|
|
@@ -507,8 +513,8 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
507
513
|
"eatenBy": {
|
|
508
514
|
"items": {
|
|
509
515
|
"description": "Users who have eaten this food",
|
|
510
|
-
"
|
|
511
|
-
"type": "
|
|
516
|
+
"format": "objectid",
|
|
517
|
+
"type": "string",
|
|
512
518
|
},
|
|
513
519
|
"type": "array",
|
|
514
520
|
},
|
|
@@ -541,6 +547,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
541
547
|
},
|
|
542
548
|
"userId": {
|
|
543
549
|
"description": "The user who liked the item",
|
|
550
|
+
"format": "objectid",
|
|
544
551
|
"type": "string",
|
|
545
552
|
},
|
|
546
553
|
},
|
|
@@ -555,6 +562,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
555
562
|
},
|
|
556
563
|
"ownerId": {
|
|
557
564
|
"description": "The user who owns this food entry",
|
|
565
|
+
"format": "objectid",
|
|
558
566
|
"type": "string",
|
|
559
567
|
},
|
|
560
568
|
"source": {
|
|
@@ -572,6 +580,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
572
580
|
"type": "string",
|
|
573
581
|
},
|
|
574
582
|
},
|
|
583
|
+
"required": [],
|
|
575
584
|
"type": "object",
|
|
576
585
|
},
|
|
577
586
|
"tags": {
|
|
@@ -1121,8 +1130,8 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1121
1130
|
"eatenBy": {
|
|
1122
1131
|
"items": {
|
|
1123
1132
|
"description": "Users who have eaten this food",
|
|
1124
|
-
"
|
|
1125
|
-
"type": "
|
|
1133
|
+
"format": "objectid",
|
|
1134
|
+
"type": "string",
|
|
1126
1135
|
},
|
|
1127
1136
|
"type": "array",
|
|
1128
1137
|
},
|
|
@@ -1155,6 +1164,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1155
1164
|
},
|
|
1156
1165
|
"userId": {
|
|
1157
1166
|
"description": "The user who liked the item",
|
|
1167
|
+
"format": "objectid",
|
|
1158
1168
|
"type": "string",
|
|
1159
1169
|
},
|
|
1160
1170
|
},
|
|
@@ -1169,6 +1179,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1169
1179
|
},
|
|
1170
1180
|
"ownerId": {
|
|
1171
1181
|
"description": "The user who owns this food entry",
|
|
1182
|
+
"format": "objectid",
|
|
1172
1183
|
"type": "string",
|
|
1173
1184
|
},
|
|
1174
1185
|
"source": {
|
|
@@ -1186,6 +1197,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1186
1197
|
"type": "string",
|
|
1187
1198
|
},
|
|
1188
1199
|
},
|
|
1200
|
+
"required": [],
|
|
1189
1201
|
"type": "object",
|
|
1190
1202
|
},
|
|
1191
1203
|
"tags": {
|
|
@@ -1319,8 +1331,8 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1319
1331
|
"eatenBy": {
|
|
1320
1332
|
"items": {
|
|
1321
1333
|
"description": "Users who have eaten this food",
|
|
1322
|
-
"
|
|
1323
|
-
"type": "
|
|
1334
|
+
"format": "objectid",
|
|
1335
|
+
"type": "string",
|
|
1324
1336
|
},
|
|
1325
1337
|
"type": "array",
|
|
1326
1338
|
},
|
|
@@ -1353,6 +1365,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1353
1365
|
},
|
|
1354
1366
|
"userId": {
|
|
1355
1367
|
"description": "The user who liked the item",
|
|
1368
|
+
"format": "objectid",
|
|
1356
1369
|
"type": "string",
|
|
1357
1370
|
},
|
|
1358
1371
|
},
|
|
@@ -1367,6 +1380,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1367
1380
|
},
|
|
1368
1381
|
"ownerId": {
|
|
1369
1382
|
"description": "The user who owns this food entry",
|
|
1383
|
+
"format": "objectid",
|
|
1370
1384
|
"type": "string",
|
|
1371
1385
|
},
|
|
1372
1386
|
"source": {
|
|
@@ -1384,6 +1398,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1384
1398
|
"type": "string",
|
|
1385
1399
|
},
|
|
1386
1400
|
},
|
|
1401
|
+
"required": [],
|
|
1387
1402
|
"type": "object",
|
|
1388
1403
|
},
|
|
1389
1404
|
"tags": {
|
|
@@ -1453,8 +1468,8 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1453
1468
|
"eatenBy": {
|
|
1454
1469
|
"items": {
|
|
1455
1470
|
"description": "Users who have eaten this food",
|
|
1456
|
-
"
|
|
1457
|
-
"type": "
|
|
1471
|
+
"format": "objectid",
|
|
1472
|
+
"type": "string",
|
|
1458
1473
|
},
|
|
1459
1474
|
"type": "array",
|
|
1460
1475
|
},
|
|
@@ -1487,6 +1502,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1487
1502
|
},
|
|
1488
1503
|
"userId": {
|
|
1489
1504
|
"description": "The user who liked the item",
|
|
1505
|
+
"format": "objectid",
|
|
1490
1506
|
"type": "string",
|
|
1491
1507
|
},
|
|
1492
1508
|
},
|
|
@@ -1501,6 +1517,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1501
1517
|
},
|
|
1502
1518
|
"ownerId": {
|
|
1503
1519
|
"description": "The user who owns this food entry",
|
|
1520
|
+
"format": "objectid",
|
|
1504
1521
|
"type": "string",
|
|
1505
1522
|
},
|
|
1506
1523
|
"source": {
|
|
@@ -1518,6 +1535,7 @@ exports[`OpenApiMiddlewareBuilder snapshot tests matches OpenAPI spec snapshot 1
|
|
|
1518
1535
|
"type": "string",
|
|
1519
1536
|
},
|
|
1520
1537
|
},
|
|
1538
|
+
"required": [],
|
|
1521
1539
|
"type": "object",
|
|
1522
1540
|
},
|
|
1523
1541
|
"tags": {
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
|
|
2
|
+
|
|
3
|
+
exports[`describeModel returns a field graph snapshot for the fixture schema 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"__v": {
|
|
6
|
+
"default": undefined,
|
|
7
|
+
"description": undefined,
|
|
8
|
+
"enum": undefined,
|
|
9
|
+
"kind": "number",
|
|
10
|
+
"ref": undefined,
|
|
11
|
+
"required": false,
|
|
12
|
+
"system": true,
|
|
13
|
+
},
|
|
14
|
+
"_id": {
|
|
15
|
+
"default": undefined,
|
|
16
|
+
"description": undefined,
|
|
17
|
+
"enum": undefined,
|
|
18
|
+
"kind": "objectId",
|
|
19
|
+
"ref": undefined,
|
|
20
|
+
"required": false,
|
|
21
|
+
"system": true,
|
|
22
|
+
},
|
|
23
|
+
"completed": {
|
|
24
|
+
"default": false,
|
|
25
|
+
"description": "Whether the item is done",
|
|
26
|
+
"enum": undefined,
|
|
27
|
+
"kind": "boolean",
|
|
28
|
+
"ref": undefined,
|
|
29
|
+
"required": false,
|
|
30
|
+
"system": false,
|
|
31
|
+
},
|
|
32
|
+
"created": {
|
|
33
|
+
"default": undefined,
|
|
34
|
+
"description": "Created timestamp",
|
|
35
|
+
"enum": undefined,
|
|
36
|
+
"kind": "date",
|
|
37
|
+
"ref": undefined,
|
|
38
|
+
"required": false,
|
|
39
|
+
"system": true,
|
|
40
|
+
},
|
|
41
|
+
"createdAt": {
|
|
42
|
+
"default": undefined,
|
|
43
|
+
"description": "When the record was created",
|
|
44
|
+
"enum": undefined,
|
|
45
|
+
"kind": "date",
|
|
46
|
+
"ref": undefined,
|
|
47
|
+
"required": false,
|
|
48
|
+
"system": false,
|
|
49
|
+
},
|
|
50
|
+
"deleted": {
|
|
51
|
+
"default": false,
|
|
52
|
+
"description": "Soft delete flag",
|
|
53
|
+
"enum": undefined,
|
|
54
|
+
"kind": "boolean",
|
|
55
|
+
"ref": undefined,
|
|
56
|
+
"required": false,
|
|
57
|
+
"system": true,
|
|
58
|
+
},
|
|
59
|
+
"label": {
|
|
60
|
+
"default": undefined,
|
|
61
|
+
"description": "Display label",
|
|
62
|
+
"enum": undefined,
|
|
63
|
+
"kind": "string",
|
|
64
|
+
"ref": undefined,
|
|
65
|
+
"required": true,
|
|
66
|
+
"system": false,
|
|
67
|
+
},
|
|
68
|
+
"metadata": {
|
|
69
|
+
"default": undefined,
|
|
70
|
+
"description": "Arbitrary metadata",
|
|
71
|
+
"enum": undefined,
|
|
72
|
+
"kind": "mixed",
|
|
73
|
+
"ref": undefined,
|
|
74
|
+
"required": false,
|
|
75
|
+
"system": false,
|
|
76
|
+
},
|
|
77
|
+
"ownerId": {
|
|
78
|
+
"default": undefined,
|
|
79
|
+
"description": "Owning user",
|
|
80
|
+
"enum": undefined,
|
|
81
|
+
"kind": "objectId",
|
|
82
|
+
"ref": "User",
|
|
83
|
+
"required": true,
|
|
84
|
+
"system": false,
|
|
85
|
+
},
|
|
86
|
+
"status": {
|
|
87
|
+
"default": undefined,
|
|
88
|
+
"description": "Workflow status",
|
|
89
|
+
"enum": [
|
|
90
|
+
"draft",
|
|
91
|
+
"published",
|
|
92
|
+
],
|
|
93
|
+
"kind": "string",
|
|
94
|
+
"ref": undefined,
|
|
95
|
+
"required": false,
|
|
96
|
+
"system": false,
|
|
97
|
+
},
|
|
98
|
+
"tags": {
|
|
99
|
+
"default": undefined,
|
|
100
|
+
"description": "Search tags",
|
|
101
|
+
"enum": undefined,
|
|
102
|
+
"isArray": true,
|
|
103
|
+
"item": {
|
|
104
|
+
"description": undefined,
|
|
105
|
+
"enum": undefined,
|
|
106
|
+
"kind": "string",
|
|
107
|
+
"ref": undefined,
|
|
108
|
+
"required": false,
|
|
109
|
+
},
|
|
110
|
+
"kind": "string",
|
|
111
|
+
"ref": undefined,
|
|
112
|
+
"required": false,
|
|
113
|
+
"system": false,
|
|
114
|
+
},
|
|
115
|
+
"tasks": {
|
|
116
|
+
"default": undefined,
|
|
117
|
+
"description": "Nested tasks",
|
|
118
|
+
"enum": undefined,
|
|
119
|
+
"fields": {
|
|
120
|
+
"_id": {
|
|
121
|
+
"default": undefined,
|
|
122
|
+
"description": undefined,
|
|
123
|
+
"enum": undefined,
|
|
124
|
+
"kind": "objectId",
|
|
125
|
+
"ref": undefined,
|
|
126
|
+
"required": false,
|
|
127
|
+
"system": true,
|
|
128
|
+
},
|
|
129
|
+
"done": {
|
|
130
|
+
"default": undefined,
|
|
131
|
+
"description": "Whether the task is done",
|
|
132
|
+
"enum": undefined,
|
|
133
|
+
"kind": "boolean",
|
|
134
|
+
"ref": undefined,
|
|
135
|
+
"required": false,
|
|
136
|
+
"system": false,
|
|
137
|
+
},
|
|
138
|
+
"title": {
|
|
139
|
+
"default": undefined,
|
|
140
|
+
"description": "Task title",
|
|
141
|
+
"enum": undefined,
|
|
142
|
+
"kind": "string",
|
|
143
|
+
"ref": undefined,
|
|
144
|
+
"required": true,
|
|
145
|
+
"system": false,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
"isArray": true,
|
|
149
|
+
"item": {
|
|
150
|
+
"fields": {
|
|
151
|
+
"_id": {
|
|
152
|
+
"default": undefined,
|
|
153
|
+
"description": undefined,
|
|
154
|
+
"enum": undefined,
|
|
155
|
+
"kind": "objectId",
|
|
156
|
+
"ref": undefined,
|
|
157
|
+
"required": false,
|
|
158
|
+
"system": true,
|
|
159
|
+
},
|
|
160
|
+
"done": {
|
|
161
|
+
"default": undefined,
|
|
162
|
+
"description": "Whether the task is done",
|
|
163
|
+
"enum": undefined,
|
|
164
|
+
"kind": "boolean",
|
|
165
|
+
"ref": undefined,
|
|
166
|
+
"required": false,
|
|
167
|
+
"system": false,
|
|
168
|
+
},
|
|
169
|
+
"title": {
|
|
170
|
+
"default": undefined,
|
|
171
|
+
"description": "Task title",
|
|
172
|
+
"enum": undefined,
|
|
173
|
+
"kind": "string",
|
|
174
|
+
"ref": undefined,
|
|
175
|
+
"required": true,
|
|
176
|
+
"system": false,
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
"kind": "embedded",
|
|
180
|
+
"required": false,
|
|
181
|
+
},
|
|
182
|
+
"kind": "embedded",
|
|
183
|
+
"ref": undefined,
|
|
184
|
+
"required": false,
|
|
185
|
+
"system": false,
|
|
186
|
+
},
|
|
187
|
+
"updated": {
|
|
188
|
+
"default": undefined,
|
|
189
|
+
"description": "Updated timestamp",
|
|
190
|
+
"enum": undefined,
|
|
191
|
+
"kind": "date",
|
|
192
|
+
"ref": undefined,
|
|
193
|
+
"required": false,
|
|
194
|
+
"system": true,
|
|
195
|
+
},
|
|
196
|
+
}
|
|
197
|
+
`;
|
package/src/actions.ts
CHANGED
|
@@ -325,31 +325,37 @@ const getArrayFieldNames = <T>(model: Model<T>): string[] => {
|
|
|
325
325
|
.map((config) => config.path);
|
|
326
326
|
};
|
|
327
327
|
|
|
328
|
-
// Registration-time validation throws
|
|
328
|
+
// Registration-time validation throws APIError so misconfiguration fails at app boot.
|
|
329
329
|
const validateActionConfig = (
|
|
330
330
|
scope: ActionScope,
|
|
331
331
|
name: string,
|
|
332
332
|
config: BaseActionConfig<unknown, unknown, unknown>
|
|
333
333
|
): void => {
|
|
334
334
|
if (!name) {
|
|
335
|
-
throw new
|
|
335
|
+
throw new APIError({status: 500, title: "Action name cannot be empty"});
|
|
336
336
|
}
|
|
337
337
|
if (!ACTION_NAME_PATTERN.test(name)) {
|
|
338
|
-
throw new
|
|
339
|
-
|
|
340
|
-
|
|
338
|
+
throw new APIError({
|
|
339
|
+
status: 500,
|
|
340
|
+
title: `Invalid action name "${name}". Action names must match ${ACTION_NAME_PATTERN.toString()}`,
|
|
341
|
+
});
|
|
341
342
|
}
|
|
342
343
|
if (config.permissions === undefined && !config.access) {
|
|
343
|
-
throw new
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
344
|
+
throw new APIError({
|
|
345
|
+
status: 500,
|
|
346
|
+
title:
|
|
347
|
+
`Action "${name}" (${scope}) is missing required "permissions" or "access". ` +
|
|
348
|
+
"Provide at least one permission function, an access descriptor, or [] to disable the action.",
|
|
349
|
+
});
|
|
347
350
|
}
|
|
348
351
|
if (config.permissions !== undefined && config.permissions.length === 0 && !config.access) {
|
|
349
352
|
return;
|
|
350
353
|
}
|
|
351
354
|
if (config.method !== "GET" && config.method !== "POST") {
|
|
352
|
-
throw new
|
|
355
|
+
throw new APIError({
|
|
356
|
+
status: 500,
|
|
357
|
+
title: `Action "${name}" (${scope}) only supports GET and POST methods`,
|
|
358
|
+
});
|
|
353
359
|
}
|
|
354
360
|
};
|
|
355
361
|
|
|
@@ -372,9 +378,10 @@ export const assertNoActionCollisions = <T>(
|
|
|
372
378
|
for (const [name, config] of Object.entries(actions)) {
|
|
373
379
|
validateActionConfig(scope, name, config);
|
|
374
380
|
if (scope === "instance" && arrayFields.has(name)) {
|
|
375
|
-
throw new
|
|
376
|
-
|
|
377
|
-
|
|
381
|
+
throw new APIError({
|
|
382
|
+
status: 500,
|
|
383
|
+
title: `instanceAction '${name}' collides with array field operations on /:id/${name}`,
|
|
384
|
+
});
|
|
378
385
|
}
|
|
379
386
|
}
|
|
380
387
|
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import mongoose from "mongoose";
|
|
3
|
+
|
|
4
|
+
import {enrichModelRouterOptions} from "./adminModelRouter";
|
|
5
|
+
import type {ModelRouterOptions} from "./api";
|
|
6
|
+
|
|
7
|
+
interface Widget {
|
|
8
|
+
secret?: string;
|
|
9
|
+
title: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const widgetSchema = new mongoose.Schema<Widget>(
|
|
13
|
+
{
|
|
14
|
+
secret: {description: "Hidden", type: String},
|
|
15
|
+
title: {description: "Title", type: String},
|
|
16
|
+
},
|
|
17
|
+
{strict: "throw"}
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const WidgetModel =
|
|
21
|
+
(mongoose.models.CoverageWidget as mongoose.Model<Widget>) ??
|
|
22
|
+
mongoose.model<Widget>("CoverageWidget", widgetSchema);
|
|
23
|
+
|
|
24
|
+
describe("enrichModelRouterOptions", () => {
|
|
25
|
+
it("returns options unchanged when admin is omitted", () => {
|
|
26
|
+
const options: ModelRouterOptions<Widget> = {
|
|
27
|
+
permissions: {create: [], delete: [], list: [], read: [], update: []},
|
|
28
|
+
};
|
|
29
|
+
const enriched = enrichModelRouterOptions(WidgetModel, options, {});
|
|
30
|
+
expect(enriched).toBe(options);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("merges openApi from context when admin is omitted", () => {
|
|
34
|
+
const options: ModelRouterOptions<Widget> = {
|
|
35
|
+
permissions: {create: [], delete: [], list: [], read: [], update: []},
|
|
36
|
+
};
|
|
37
|
+
const enriched = enrichModelRouterOptions(WidgetModel, options, {
|
|
38
|
+
openApi: {enabled: true} as never,
|
|
39
|
+
});
|
|
40
|
+
expect(enriched.openApi).toEqual({enabled: true});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("scrubs admin fields in preCreate/preUpdate and honors user hooks", async () => {
|
|
44
|
+
const options: ModelRouterOptions<Widget> = {
|
|
45
|
+
admin: {
|
|
46
|
+
displayName: "Widgets",
|
|
47
|
+
excludeFields: ["secret"],
|
|
48
|
+
hiddenFields: [],
|
|
49
|
+
listFields: ["title"],
|
|
50
|
+
},
|
|
51
|
+
permissions: {create: [], delete: [], list: [], read: [], update: []},
|
|
52
|
+
preCreate: async (body) => ({...body, title: `${body.title}-created`}),
|
|
53
|
+
preUpdate: async () => null,
|
|
54
|
+
};
|
|
55
|
+
const enriched = enrichModelRouterOptions(WidgetModel, options, {});
|
|
56
|
+
const created = await enriched.preCreate?.({secret: "x", title: "Hi"}, {} as never);
|
|
57
|
+
expect(created).toEqual({title: "Hi-created"});
|
|
58
|
+
const updated = await enriched.preUpdate?.({secret: "x", title: "Hi"}, {} as never);
|
|
59
|
+
expect(updated).toBeNull();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("returns the user preUpdate body when it is not null", async () => {
|
|
63
|
+
const enriched = enrichModelRouterOptions(
|
|
64
|
+
WidgetModel,
|
|
65
|
+
{
|
|
66
|
+
admin: {
|
|
67
|
+
displayName: "Widgets",
|
|
68
|
+
excludeFields: ["secret"],
|
|
69
|
+
hiddenFields: [],
|
|
70
|
+
listFields: ["title"],
|
|
71
|
+
},
|
|
72
|
+
permissions: {create: [], delete: [], list: [], read: [], update: []},
|
|
73
|
+
preUpdate: async (body) => ({...body, title: "next"}),
|
|
74
|
+
},
|
|
75
|
+
{}
|
|
76
|
+
);
|
|
77
|
+
const patched = await enriched.preUpdate?.({secret: "x", title: "Hi"}, {} as never);
|
|
78
|
+
expect(patched).toEqual({title: "next"});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("emits realtime admin events after create/update/delete", async () => {
|
|
82
|
+
const events: unknown[] = [];
|
|
83
|
+
const terrenoApp = {
|
|
84
|
+
emitAdminModelChanged: (event: unknown) => {
|
|
85
|
+
events.push(event);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
const options: ModelRouterOptions<Widget> = {
|
|
89
|
+
admin: {
|
|
90
|
+
displayName: "Widgets",
|
|
91
|
+
excludeFields: ["secret"],
|
|
92
|
+
hiddenFields: [],
|
|
93
|
+
listFields: ["title"],
|
|
94
|
+
realtime: true,
|
|
95
|
+
},
|
|
96
|
+
permissions: {create: [], delete: [], list: [], read: [], update: []},
|
|
97
|
+
postCreate: async () => {},
|
|
98
|
+
postDelete: async () => {},
|
|
99
|
+
postUpdate: async () => {},
|
|
100
|
+
};
|
|
101
|
+
const enriched = enrichModelRouterOptions(WidgetModel, options, {
|
|
102
|
+
routePath: "/widgets",
|
|
103
|
+
terrenoApp: terrenoApp as never,
|
|
104
|
+
});
|
|
105
|
+
const doc = {_id: "abc", secret: "x", title: "Hi", toObject: () => ({_id: "abc", title: "Hi"})};
|
|
106
|
+
const req = {user: {_id: "user-1"}} as never;
|
|
107
|
+
await enriched.postCreate?.(doc as never, req);
|
|
108
|
+
await enriched.postUpdate?.(doc as never, {}, req, doc as never);
|
|
109
|
+
await enriched.postDelete?.(req, doc as never);
|
|
110
|
+
expect(events).toHaveLength(3);
|
|
111
|
+
expect((events[0] as {type: string}).type).toBe("create");
|
|
112
|
+
expect((events[2] as {type: string; document?: unknown}).type).toBe("delete");
|
|
113
|
+
expect((events[2] as {document?: unknown}).document).toBeUndefined();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("skips realtime emit when the request has no user id", async () => {
|
|
117
|
+
const events: unknown[] = [];
|
|
118
|
+
const options: ModelRouterOptions<Widget> = {
|
|
119
|
+
admin: {
|
|
120
|
+
displayName: "Widgets",
|
|
121
|
+
listFields: ["title"],
|
|
122
|
+
realtime: true,
|
|
123
|
+
},
|
|
124
|
+
permissions: {create: [], delete: [], list: [], read: [], update: []},
|
|
125
|
+
};
|
|
126
|
+
const enriched = enrichModelRouterOptions(WidgetModel, options, {
|
|
127
|
+
routePath: "/widgets",
|
|
128
|
+
terrenoApp: {emitAdminModelChanged: (event: unknown) => events.push(event)} as never,
|
|
129
|
+
});
|
|
130
|
+
await enriched.postCreate?.({_id: "abc", title: "Hi"} as never, {user: {}} as never);
|
|
131
|
+
expect(events).toHaveLength(0);
|
|
132
|
+
});
|
|
133
|
+
});
|
package/src/adminTypes.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type express from "express";
|
|
2
2
|
import type {Model} from "mongoose";
|
|
3
3
|
|
|
4
|
+
import type {User} from "./auth";
|
|
4
5
|
import type {PermissionMethod, RESTPermissions} from "./permissions";
|
|
5
6
|
import type {PopulatePath} from "./populate";
|
|
6
7
|
import type {ScriptArgDef, ScriptRunner} from "./scriptRunner";
|
|
@@ -78,6 +79,24 @@ export interface AdminModelPermissions {
|
|
|
78
79
|
update?: boolean;
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
export interface AdminAccessContext {
|
|
83
|
+
action: string;
|
|
84
|
+
instance?: unknown;
|
|
85
|
+
user?: User;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface AdminAccessConfig {
|
|
89
|
+
/**
|
|
90
|
+
* RBAC resource for the standard read/write/writeOwned controls. Defaults to
|
|
91
|
+
* `admin<ModelName>` when that statement exists, then the legacy camel-cased model name.
|
|
92
|
+
*/
|
|
93
|
+
resource?: string;
|
|
94
|
+
/** Determines whether the current user owns an instance for writeOwned access. */
|
|
95
|
+
isOwned?: (args: {instance: unknown; user: User}) => boolean | Promise<boolean>;
|
|
96
|
+
/** Completely replaces the standard RBAC decision for this model. */
|
|
97
|
+
authorize?: (args: AdminAccessContext) => boolean | Promise<boolean>;
|
|
98
|
+
}
|
|
99
|
+
|
|
81
100
|
export interface AdminConfig {
|
|
82
101
|
displayName: string;
|
|
83
102
|
group?: string;
|
|
@@ -104,6 +123,8 @@ export interface AdminConfig {
|
|
|
104
123
|
read: PermissionMethod<unknown>[];
|
|
105
124
|
update: PermissionMethod<unknown>[];
|
|
106
125
|
}>;
|
|
126
|
+
/** Fine-grained admin RBAC and optional ownership/custom authorization. */
|
|
127
|
+
adminAccess?: AdminAccessConfig;
|
|
107
128
|
adminFilter?: (
|
|
108
129
|
req: express.Request
|
|
109
130
|
) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
@@ -128,6 +149,8 @@ export interface AdminCustomScreen {
|
|
|
128
149
|
group?: string;
|
|
129
150
|
icon?: string;
|
|
130
151
|
name: string;
|
|
152
|
+
/** RBAC or custom authorization for exposing this screen in admin metadata/navigation. */
|
|
153
|
+
adminAccess?: Pick<AdminAccessConfig, "authorize" | "resource"> & {action?: string};
|
|
131
154
|
}
|
|
132
155
|
|
|
133
156
|
export interface AdminHomeSlots {
|